import { IMountObserver } from '../../mount-observer/types'; import { Scope} from '../lib/types'; import { WrapperConfig } from '../XV/types'; import {CSSQuery, XForm} from '../types'; export interface IEventConfig{ on?: string, of?: 'tbd' | EventTarget, doInit?: boolean, options?: AddEventListenerOptions, abort?: { origMethName: string & keyof MCActions, //destMethName: string & keyof MCActions, of: 'tbd' | EventTarget, on: string, }, composedPathMatches?: string, } //Is anything using this anymore? export type ActionOnEventConfigs = Partial<{[key in keyof MCActions]: IEventConfig}> export interface IAttrChgCB{ instance: HTMLElement, // name: string, // oldVal: string, // newVal: string, newAttrs: {[key: string]: {oldVal: string | null, newVal: string | null}}, filteredAttrs: {[key: string]: string} } export interface IPropChg{ key: string, oldVal: any, newVal: any, } export interface DynamicTransform { scope?: Scope, noCache?: boolean, } export interface DefineArgs>{ superclass?: {new(): HTMLElement} | string, mixins?: any[], mainTemplate?: HTMLTemplateElement; /** use this only for defaults that can't be JSON serialized in config */ complexPropDefaults?: Partial; /** Config should be 100% JSON serializable, or a JSON import, or an id of an be-exportable script tag */ config: WCConfig | (() => Promise<{default: WCConfig}>) | string; // /** // * Side effects tied to actions, mostly used to load enhancement dependencies tied to // * enhancements // */ // asides?: Partial<{[key in keyof MixinCompositeActions & string]: (instance: EventTarget, methodName: string, key: string) => Promise }> } export interface WCConfig{ tagName?: string; isEnh?: boolean; propDefaults?: Partial<{[key in keyof TProps]: TProps[key]}>; propInfo?: Partial<{[key in keyof TProps]: TPropInfo}>; wrappers?: Partial<{[key in keyof TProps]: WrapperConfig}>; derivedProps?: (keyof TProps & string)[]; // actions?: // Partial<{[key in keyof MCActions & string]: TAction | keyof MCProps}> actions?: Actions; propChangeMethod?: keyof TActions; style?: Partial; /** * Used for providing hints to server side processing what css queries should be observed if using HTMLRewriter. */ keyQueries?: string[]; formAss?: boolean; compacts?: Compacts; } export type PropLookup = Partial<{[key in keyof TProps]: PropInfo}>; export type IshPropLookup = Partial<{[key in keyof TProps]: IshPropInfo}>; export interface IshConfig{ propDefaults?: Partial<{[key in keyof TProps]: TProps[key]}>; propInfo?: Partial<{[key in keyof TProps]: PropInfo}>; wrappers?: Partial<{[key in keyof TProps]: WrapperConfig}>; actions?: Actions; /** * inferred actions */ infractions?: Infractions, compacts?: Compacts; hitch?: Hitches; handlers?: Handlers; extHandlers?: ExtHandlers; positractions?: Positractions; isSleepless?: boolean; xform?: XForm; inScopeXForms?: {[key: CSSQuery]: XForm}; ishListCountProp?: keyof TProps & string; defaultIshList?: any[]; mapParentScopeRefTo?: keyof TProps & string; mapElTo?: keyof TProps & string; ignoreItemProp?: boolean; } export interface OConfig extends IshConfig{ mainTemplate?: string | HTMLTemplateElement; } export type Positractions = | Array>; export interface Positraction extends LogicOp { do: | Function | (keyof TActions & string) | PropsToProps ifKeyIn?: Array, ifAllOf?: Array, //ifNoneOf: Array, pass?: Array<(keyof TProps & string) | number | boolean | '$0' | '$0+' | `\`${string}\``>, assignTo?: Array } export type Compacts = //| Partial<{[key in `${keyof TProps & string}_to_${keyof TProps & string}` & string]: Operation }> | Partial<{[key in `negate_${keyof TProps & string}_to_${keyof TProps & string}`]: number}> | Partial<{[key in `pass_length_of_${keyof TProps & string}_to_${keyof TProps & string}`]: number}> | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}`]: number}> | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}_after`]: keyof TProps}> | Partial<{[key in `when_${keyof TProps & string}_changes_call_${keyof TActions & string}`]: number}> | Partial<{[key in `when_${keyof TProps & string}_changes_toggle_${keyof TProps & string}`]: number}> | Partial<{[key in `when_${keyof TProps & string}_changes_inc_${keyof TProps & string}_by`]: number}> | Partial<{[key in `when_${keyof TProps & string}_changes_dispatch`]: string}> //TODO ; export type Hitches = | Partial<{[key in `when_${keyof TProps & string}_emits_${keyof TProps & string}_inc_${keyof TProps & string}_by`]: number}> ; export interface ExtHandlerOptions { on: string, stopPropagation?: boolean, } export type ExtHandlers = | Partial<{[key in `inc_${keyof ETProps & string}` & string]: ExtHandlerOptions}> ; export type Handlers = | Partial<{[key in `${keyof ETProps & string}_to_${keyof TActions & string}_on` & string]: string }>; export type ListOfLogicalExpressions = (keyof MCProps | LogicOp)[]; export type LogicOpProp = |LogicOp | (keyof MCProps & string)[]; type PropsToProps = (x: Props) => (Promise> | Partial) export interface LogicOp{ /** * Supported by trans-render */ ifAllOf?: Keysh, ifKeyIn?: Keysh, ifNoneOf?: Keysh, ifEquals?: Array>, ifAtLeastOneOf?: Keysh, ifNotAllOf?: Keysh, debug?: boolean, delay?: number, do?: | Function | (keyof TActions & string) | PropsToProps } export interface SetLogicOps{ a?: boolean, ifAllOf?: Set>, ifKeyIn?: Set>, ifNoneOf?: Set>, ifEquals?: Set>, ifAtLeastOneOf?: Set>, ifNotAllOf?: Set>, debug?: boolean, delay?: number, do?: (x: Props) => (Promise> | Partial), } export interface Action extends LogicOp{ target?: keyof MCProps; debug?: boolean; secondArg?: any; //setFree?: (keyof MCProps & string)[], } export interface IActionProcessor{ doActions(self: IActionProcessor, actions: {[methodName: string]: Action}, target: any, proxy?: any): void; postHoc(self: this, action: Action, target: any, returnVal: any, proxy?: any): void; } type PropInfoTypes = "String" | "Number" | "Boolean" | "Object" | "RegExp"; export interface IshPropInfo{ type?: PropInfoTypes; dry?: boolean; ro?: boolean; propName?: string; /** * Allow for discarding what is passed in favor of a modified value such as a formatted value * or filtered list */ adjuster?: |keyof TActions & string |((nv: any) => any) } export interface PropInfo extends IshPropInfo{ parse?: boolean; def?: any; attrName?: string; reflect?: boolean; /** * form associated read only property * https://web.dev/articles/more-capable-form-controls#:~:text=Form-associated%20custom%20elements%20aim%20to%20bridge%20the%20gap,associated%20with%20the%20form%2C%20like%20a%20browser-provided%20control. * examples: form, validity, validityMessage, willValidate */ farop?: boolean; /** * form associated read only method * examples: checkValidity, reportValidity */ farom?: 'checkValidity' | 'reportValidity'; /** * form associated write method */ fawm?: 'setValidity' | 'setFormValue' /** * internals pass through property * examples: role, ariaRole */ ip?: boolean; } export type ConstString = string; export type NameOfProp = string; export type StringOrProp = ConstString | [NameOfProp, PropInfo]; export type Parts = Array; export interface PropChangeInfo { key: string, ov: any, nv: any, prop: TPropInfo, pcm: PropChangeMethod | undefined; } //are these still really used? export type PropChangeMoment = 'v' | '-a' | '+a' | '+qr' | '+qm'; export type PropChangeMethod = (self: EventTarget, pci: PropChangeInfo, moment: PropChangeMoment) => boolean; export type Actions = Partial<{[key in keyof TActions & string]: LogicOp}> //& Partial<{[key in `do_${keyof TActions & string}_on`]: Key | Array> }> ; export type Checks = Partial<{[key in keyof TActions & string]: SetLogicOps}> export type roundaboutOptions = { vm?: TProps & TActions & RoundaboutReady, //for enhanced elements, pass in the container, referenced via $0. container?: EventTarget, propagate?: keyof TProps & string | Array, actions?: Actions, compacts?: Compacts, //onsets?: Onsets, handlers?: Handlers, hitch?: Hitches, positractions?: Positractions, mountObservers?: Set } export type PropsToPartialProps = | ((self: TProps, a: any, b: any) => Promise>) | ((self: TProps) => Partial); export type Infractions = //| PropsToPartialProps | Array> export type Busses = {[key: string]: Set}; export type Routers = {[key: string]: Array<{ on: string, do: string, full: string, }>} export type Key = keyof T & string; export type Keysh = Key | Array>; export interface RoundaboutReady{ /** * Allow for assigning to read only props via the "backdoor" * Bypasses getters / setters, sets directly to (private) memory slots * Doesn't do any notification * Allows for nested property setting */ covertAssignment(obj: any): Promise; /** * fires event with name matching the name of the property when the value changes (but not via covertAssignment) * when property is set via public interface, not (immediately) via an action method's return object */ readonly propagator : EventTarget | undefined; /** * * https://github.com/whatwg/dom/issues/1296 */ //readonly disconnectedSignal: AbortSignal RAController: AbortController; /** * During this time, queues/buses continue to perform "bookkeeping" * but doesn't process the queue until sleep property becomes falsy. * If truthy, can call await awake() before processing should resume * [TODO] */ readonly sleep?: number | undefined; awake(): Promise; nudge(): void; rock(): void; } export interface BaseProps{ proppedUp: boolean, sleep?: number; } export interface ICompact{ compacts: Compacts, } interface CompactStatement { srcKey: string, destKey: string, op: 'toggle' | 'negate' | 'call' | 'pass_length' | 'echo' | 'inc' | 'dispatch', rhsIsDynamic: boolean } interface HitchStatement { leftKey: string, middleKey: string, rightKey: string, lOp: 'when' lmOp: 'emits', mrOp: 'inc', rOp: 'by' } export type CommandMethod = (self: T, evt: Event) => Partial | Promise> export type HookupConfig = {[key: string]: CommandMethod | [string, CommandMethod]};