mount-observer 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,503 @@
1
+ import { MountContext, PipelineStage } from "mount-observer/types";
2
+ import { ConvertOptions, Scope } from "./lib/types";
3
+ import { EMC} from './be/types';
4
+
5
+
6
+ export type PropAttrQueryType =
7
+ | '|' //microdata itemprop
8
+ | '@' //form element name
9
+ | '#' //id
10
+ | '%' //part
11
+ | '.' //class
12
+ //| '-' //marker
13
+ | '$' //microdata itemprop + itemscope attributes (nested)
14
+ | '-o'
15
+
16
+ export type PropAttrPair<TProps> = `${PropAttrQueryType} ${keyof TProps & string}`;
17
+
18
+ export type PropQueryExpression<TProps, TElement = {}> =
19
+
20
+ | `* ${CSSQuery}`
21
+ | `:root`
22
+ | `${keyof HTMLElementTagNameMap}`
23
+ | `${PropAttrPair<TProps>}`
24
+ | `${PropAttrPair<TProps>} -s ${keyof TElement & string}`
25
+ | `${PropAttrPair<TProps>} ${PropAttrPair<TProps>}`
26
+ | `${PropAttrPair<TProps>} ${PropAttrPair<TProps>} -s ${keyof TElement & string}`
27
+ // | `${PropAttrPair<TProps>} ${PropAttrPair<TProps>} ${PropAttrPair<TProps>}`
28
+ // | `${PropAttrPair<TProps>} ${PropAttrPair<TProps>} ${PropAttrPair<TProps>} -s ${keyof TElement & string}`
29
+ //
30
+
31
+ ;
32
+
33
+ //#region derived expressions
34
+ export type Expr0 = [string, number];
35
+ export type Expr1 = [...Expr0, string];
36
+ export type Expr2 = [...Expr1, number];
37
+ export type Expr3 = [...Expr2, string];
38
+ export type Expr4 = [...Expr3, number];
39
+ export type Expr5 = [...Expr4, string];
40
+ export type Expr6 = [...Expr5, number];
41
+ export type Expr7 = [...Expr6, string];
42
+ export type Expr8 = [...Expr7, number];
43
+ export type Expr9 = [...Expr8, string];
44
+ export type Expr10 = [...Expr9, number];
45
+ export type Expr11 = [...Expr10, string];
46
+ export type Expr12 = [...Expr11, number];
47
+
48
+ //export type Action<TProps> = (matchingElement: Element, pique: IMountOrchestrator<TProps>) => Promise<Derivative<TProps>> | Promise<void>;
49
+ export type InterpolatingExpression = Expr0 | Expr1 | Expr2 | Expr3 | Expr4 | Expr5 | Expr6 | Expr7 | Expr8 | Expr9 | Expr10 | Expr11 | Expr12;
50
+ export type NumberExpression = [number];
51
+ export type DerivationCriteria<TProps, TMethods> = {
52
+ //TODO
53
+ path: string,
54
+ from?: number,
55
+ //TODO
56
+ as?: ConvertOptions
57
+ };
58
+
59
+ export interface TransformOptions{
60
+ propagator?: MarkedUpEventTarget,
61
+ propagatorIsReady?: boolean,
62
+ skipInit?: boolean,
63
+ }
64
+
65
+ export type Derivative<TProps, TMethods, TElement = {}> =
66
+ | number
67
+ | InterpolatingExpression
68
+ | ((model: TProps & TMethods, transform: ITransformer<TProps, TMethods, TElement>, uow: UnitOfWork<TProps, TMethods, TElement>, matchingElement: Element) => any)
69
+ | NumberExpression
70
+ | DerivationCriteria<TProps, TMethods>
71
+ // only works if lhs has field/property
72
+ | keyof TMethods & string
73
+ // combined observe an 0
74
+ | keyof TProps & string
75
+ | boolean
76
+ ;
77
+ //#endregion
78
+
79
+ export interface Engagement<TMethods>{
80
+ /** Invoked when the element is encountered. */
81
+ do?: keyof TMethods & string,
82
+ /** Invoked when a previously matching element is no longer matching. */
83
+ undo?: keyof TMethods & string,
84
+ /** Invoked when a previously matching element is disconnected. */
85
+ forget?: keyof TMethods & string,
86
+ /**
87
+ * Can be used for any kind of label, but most common use is for specifying a behavior/enhancement
88
+ * to attach.
89
+ */
90
+ be?: EMC,
91
+ with?: any,
92
+ waitForResolved?: boolean,
93
+ dep?: () => void;
94
+
95
+
96
+ }
97
+
98
+
99
+ export type onMountStatusChange = 'onMount' | 'onDismount' | 'onDisconnect';
100
+
101
+ export interface EngagementCtx<TModel> {
102
+ be?: string,
103
+ with?: any,
104
+ type: onMountStatusChange,
105
+ mountContext: MountContext
106
+ }
107
+
108
+ export type EngagementOrKeyOrEMC<TMethods, TProps = TMethods> =
109
+ | (keyof TMethods & string)
110
+ | Engagement<TMethods>
111
+ | EMC<any, TProps>
112
+ ;
113
+
114
+ export type EngagementOrEMC<TMethods, TProps = TMethods> =
115
+ | Engagement<TMethods>
116
+ | EMC<any, TProps>
117
+
118
+ export type Engagements<TMethods, TProps = TMethods> =
119
+ | EngagementOrKeyOrEMC<TMethods>
120
+ | Array<EngagementOrKeyOrEMC<TMethods>>
121
+ ;
122
+
123
+ export interface IMountOrchestrator<TProps, TMethods = TProps>{
124
+ //TODO add all the methods
125
+ }
126
+
127
+ // export type OneOrMore<TProps> =
128
+ // | keyof TProps & string
129
+ // | `${keyof TProps & string} ${keyof TProps & string}`
130
+
131
+
132
+
133
+
134
+ export type LHS<TProps, TElement={}> = PropQueryExpression<TProps, TElement>;
135
+
136
+ export type CSSQuery = string;
137
+
138
+ export interface ConditionGate<TProps, TMethods, TElement = {}>{
139
+ ifAllOf?: number[],
140
+ ifNoneOf?: number[],
141
+ ifEqual?: [number, number | [number] | string],
142
+ d?: Derivative<TProps, TMethods, TElement>,
143
+
144
+ }
145
+
146
+ export type WhereConditions =
147
+ | string //css matches
148
+ | {
149
+ matches: string,
150
+ mediaMatches: string,
151
+ containerQuery: string,
152
+ }
153
+
154
+ export type IfInstructions<TProps, TMethods, TElement = {}> = string | boolean | number | [number] | ConditionGate<TProps, TMethods, TElement> ;
155
+
156
+ export interface ObservePropParams {
157
+ derivePropFrom?: string,
158
+ }
159
+ export type PropOrComputedProp<TProps, TMethods = TProps> =
160
+ | keyof TProps & string
161
+ | [keyof TProps & string, (val: any) => any]
162
+ | [keyof TProps & string, keyof TMethods & string]
163
+ | ObservePropParams
164
+ | `:${string}`
165
+
166
+ export interface CrossProduct<TProps, TMethods> {
167
+ x: string | Array<string>,
168
+ y: (keyof TProps & TMethods & string) | Array<keyof TProps & TMethods & string>
169
+ }
170
+
171
+ export interface ForEach<TProps, TMethods, TElement = {}>{
172
+ each?: 0,
173
+ clone?: string,
174
+ indexProp?: string,
175
+ xform: XForm<TProps, TMethods, TElement> & Info,
176
+ appendTo?: string,
177
+ timestampProp?: string,
178
+ outOfRangeAction?: string,
179
+ outOfRangeProp?: string,
180
+ }
181
+
182
+ export interface ForEachInterface{
183
+ init(): Promise<void>;
184
+ update(model: any[]): Promise<void>;
185
+ }
186
+ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
187
+ /**
188
+ * add event listener
189
+ */
190
+ addEventListener?: AddEventListenerType<TProps, TMethods> | Array<AddEventListenerType<TProps, TMethods>>,
191
+ /**
192
+ * abbrev. for addEventListener
193
+ */
194
+ a?: AddEventListenerType<TProps, TMethods> | Array<AddEventListenerType<TProps, TMethods>>,
195
+
196
+ /**
197
+ * Specify how the value we want to apply to the target element should be derived from the observed props.
198
+ * derived value from observed props
199
+ */
200
+ derivedValFromModel?: Derivative<TProps, TMethods, TElement>,
201
+ /**
202
+ * Specify how the value we want to apply to the target element should be derived from the observed props.
203
+ * abbrev. for derivedValSpecs
204
+ */
205
+ d?: Derivative<TProps, TMethods, TElement>,
206
+
207
+ /**
208
+ * Specify what to do when the element is encountered, and/or when it goes out of scope.
209
+ * Register the found element in some way.
210
+ * Actions not tied to observed props or user actions.
211
+ */
212
+ engage?: Engagements<TMethods>
213
+ /**
214
+ * Specify what to do when the element is encountered, and/or when it goes out of scope.
215
+ * Register the found element in some way.
216
+ * Actions not tied to observed props or user actions.
217
+ * Abbrev. for engagementActions
218
+ */
219
+ e?: Engagements<TMethods>,
220
+
221
+ forEachBinding?: ForEach<any, any, any>
222
+ /**
223
+ * for each
224
+ */
225
+ f?: ForEach<any, any, any>,
226
+
227
+ /**
228
+ * ifs ands or buts -- conditions on the model
229
+ */
230
+ ifs?: IfInstructions<TProps, TMethods, TElement>,
231
+ /**
232
+ * ifs ands or buts -- conditions on the model
233
+ * abbrev for ifs
234
+ */
235
+ i?: IfInstructions<TProps, TMethods, TElement>,
236
+
237
+ /**
238
+ * method of matching element to pass derived value into
239
+ * [TODO]
240
+ */
241
+ invoke?: string,
242
+
243
+ /**
244
+ * modify the model in a (mostly) declarative way
245
+ */
246
+ modifyModel?: ModificationUnitOfWork<TProps, TMethods, TElement> | Array<ModificationUnitOfWork<TProps, TMethods, TElement>>,
247
+ /**
248
+ * modify the model in a (mostly) declarative way
249
+ * abbreviation for modifyModel
250
+ */
251
+ m?: ModificationUnitOfWork<TProps, TMethods, TElement> | Array<ModificationUnitOfWork<TProps, TMethods, TElement>>,
252
+
253
+ /**
254
+ * List of props to observe from the model
255
+ */
256
+ observedProps?: keyof TProps & string | PropOrComputedProp<TProps, TMethods> | PropOrComputedProp<TProps, TMethods>[],
257
+ /**
258
+ * List of props to observe from the model
259
+ * abbrev. for observedProps
260
+ */
261
+ o?: keyof TProps & string | PropOrComputedProp<TProps, TMethods> | PropOrComputedProp<TProps, TMethods>[],
262
+
263
+ /**
264
+ * set specified property of the matching element to the (derived) value
265
+ */
266
+ setProp?: (keyof TElement & string) | {},
267
+ /**
268
+ * set specified property of the matching element to the (derived) value
269
+ * abbrev of setProp
270
+ */
271
+ s?: (keyof TElement & string) | {},
272
+ /**
273
+ * set specified attribute of the matching element to the (derived) value
274
+ *
275
+ */
276
+ setAttr?: string,
277
+ /**
278
+ * set specified attribute of the matching element to the (derived) value
279
+ * abbrev of setAttr
280
+ */
281
+ sa?: string,
282
+ /**
283
+ * set specified style of the matching element to the (derived) value
284
+ */
285
+ ss?: string,
286
+
287
+ /**
288
+ * negate to
289
+ */
290
+ negTo?: string,
291
+
292
+ /**
293
+ * Where condition for selecting the target elements.
294
+ */
295
+ whereConditions?: WhereConditions,
296
+ /**
297
+ * Where conditions for selecting the target elements
298
+ * abbrev. for whereConditions
299
+ */
300
+ w?: WhereConditions,
301
+
302
+ y?: number | YieldSettings<TProps>
303
+ }
304
+
305
+ export interface YieldSettings<TProps>{
306
+ to?: keyof TProps,
307
+ as?: 'date' | 'number'
308
+ }
309
+
310
+ export type ValueFromElement<TProps, TMethods, TElement = {}> =
311
+ (
312
+ matchingElement: Element,
313
+ transformer: ITransformer<TProps, TMethods, TElement>,
314
+ mod: ModificationUnitOfWork<TProps, TMethods, TElement>
315
+ ) => any
316
+
317
+ export interface ModificationUnitOfWork<TProps, TMethods, TElement = {}>{
318
+ on: string,
319
+ /**
320
+ * Increment
321
+ */
322
+ inc?: keyof TProps & string,
323
+ /**
324
+ * Increment by specified number, or by specified property coming from matching element
325
+ */
326
+ byAmt?: number | string,
327
+ /**
328
+ * Set this prop on the host
329
+ */
330
+ s?: keyof TProps & string,
331
+ /**
332
+ * [TODO] -- Set Custom State --only available for xtal-element
333
+ */
334
+ ss?: string,
335
+ /**
336
+ * [TODO] -- Set attribute
337
+ */
338
+ sa?: string,
339
+ /**
340
+ * [TODO] enhance / engage the host, or register the host in some way
341
+ * don't implement this until a good use case is found, make sure it makes sense.
342
+ */
343
+ e?: Engagements<TMethods>,
344
+ /**
345
+ * [TODO] Set hardcoded value
346
+ */
347
+ to?: any,
348
+ toValFrom?: string | ValueFromElement<TProps, TMethods, TElement>;
349
+ toggle?: keyof TProps & string,
350
+ }
351
+
352
+ export interface QuenitOfWork<TProps, TMethods, TElement = {}> extends UnitOfWork<TProps, TMethods, TElement>{
353
+ q: string,
354
+ qi?: QueryInfo,
355
+ }
356
+
357
+ export type UnitOfWorkRHS<TProps, TMethods, TElement = {}> =
358
+ | 0
359
+ | keyof TMethods & string
360
+ | keyof TProps & string
361
+ | UnitOfWork<TProps, TMethods, TElement>
362
+ | XForm<any, any, any> & Info //unclear if this is necessary
363
+ ;
364
+
365
+ export type RHS<TProps, TMethods, TElements = Element> = UnitOfWorkRHS<TProps, TMethods, TElements> | Array<UnitOfWork<TProps, TMethods, TElements>>;
366
+
367
+ export interface AttrMap{
368
+ type: PropAttrQueryType,
369
+ name: string
370
+ }
371
+
372
+ export interface QueryInfo{
373
+ isRootQry?: boolean,
374
+ localPropCamelCase?: string,
375
+ cssQuery?: string,
376
+ o?: string[],
377
+ s?: string[],
378
+ localName?: string,
379
+ //w?: WhereConditions,
380
+ css?: string,
381
+ hostPropToAttrMap?: Array<AttrMap>
382
+ }
383
+
384
+ export type TransformerTarget = Element | DocumentFragment | Element[] | ShadowRoot | Document;
385
+
386
+ export type Model = {
387
+ [key: string]: any
388
+ }
389
+
390
+ export type EventListenerAction<TProps, TMethods> = (keyof TMethods & string) | ((e: Event, t: ITransformer<TProps, TMethods>, uow: UnitOfWork<TProps, TMethods>) => void);
391
+
392
+ export type AddEventListenerType<TProps, TMethods> =
393
+ | keyof TMethods & string
394
+ | AddEventListener<TProps, TMethods>;
395
+
396
+ export interface AddEventListener<TProps, TMethods>{
397
+ on: string,
398
+ do: EventListenerAction<TProps, TMethods>,
399
+ options?: boolean | EventListenerOptions,
400
+ }
401
+
402
+ export type XForm<TProps, TMethods, TElement = {}> = Partial<{
403
+ [key in LHS<TProps, TElement>]: RHS<TProps, TMethods, TElement>;
404
+ }>;
405
+
406
+ export interface Info {
407
+ 411?: {
408
+ w?: string,
409
+ //idxFrom?: string
410
+ }
411
+ }
412
+
413
+
414
+
415
+ export interface ITransformer<TProps, TMethods, TElement = {}>{
416
+ target: TransformerTarget,
417
+ model: TProps & TMethods,
418
+ xform: XForm<TProps, TMethods, TElement> & Info,
419
+ options: TransformOptions,
420
+ initializedMods: Set<ModificationUnitOfWork<TProps, TMethods, TElement>>
421
+ //propagator?: EventTarget,
422
+ }
423
+
424
+ export type ToTransformer<TProps, TMethods, TElement = {}> = (
425
+ target: TransformerTarget,
426
+ model: TProps & TMethods,
427
+ xform: XForm<TProps, TMethods, TElement>,
428
+ propagator?: EventTarget
429
+ ) => ITransformer<TProps, TMethods>;
430
+
431
+ export interface MarkedUpEventTarget extends EventTarget{
432
+ ___props?: Set<string>;
433
+ ___nestedProps?: Map<string, any>;
434
+ }
435
+
436
+ export interface TransRenderEndUserProps<ModelProps, ModelMethods = ModelProps, TElement = {}>{
437
+ xform: XForm<ModelProps, ModelMethods, TElement>;
438
+ scope: Scope;
439
+ //model?: ModelProps & ModelMethods;
440
+ options?: TransformOptions;
441
+ }
442
+
443
+ export interface TransRenderProps<ModelProps, ModelMethods = ModelProps> extends TransRenderEndUserProps<ModelProps, ModelMethods>{
444
+
445
+ }
446
+
447
+ export interface TransRenderMethods{
448
+ getTarget(): Promise<Document | ShadowRoot | DocumentFragment | Element>,
449
+ getXForm(): Promise<XForm<any, any>>,
450
+ getModel(): Promise<any>,
451
+ skipInit: boolean,
452
+ }
453
+
454
+ import {OConfig} from './froop/types';
455
+ export interface MntCfg<TProps = any, TActions = TProps, ETProps = TProps> extends OConfig<TProps, TActions, ETProps>{
456
+ mainTemplate: string | HTMLTemplateElement,
457
+ /**
458
+ * transform within ShadowRoot if applicable
459
+ */
460
+ xform?: XForm<TProps, TActions>,
461
+ /**
462
+ * transform applied to light children, if applicable
463
+ * Use ":root" to match on the root element
464
+ */
465
+ lcXform?: XForm<TProps, TActions>,
466
+
467
+ styles?: /*CSSStyleSheet[] |*/ string | string[] | CSSStyleSheet | Array<CSSStyleSheet>;
468
+
469
+ shadowRootInit?: ShadowRootInit,
470
+
471
+ assumeCSR?: boolean
472
+ }
473
+
474
+ export interface MountProps<TProps = any, TActions = TProps, ETProps = TProps>{
475
+ readonly clonedTemplate?: DocumentFragment;
476
+ deferHydration?: boolean;
477
+ readonly hydrated?: boolean;
478
+ readonly csr?: boolean;
479
+ readonly xform?: XForm<TProps, TActions>,
480
+
481
+ }
482
+ export type PMP<TProps = any, TActions = TProps, ETProps = TProps> = Partial<MountProps<TProps, TActions, ETProps>>;
483
+ export type ProPMP<TProps = any, TActions = TProps, ETProps = TProps> = Promise<PMP<TProps, TActions, ETProps>>
484
+
485
+ export interface MountActions<TProps = any, TActions = TProps, ETProps = TProps>{
486
+ cloneMT(self: this): PMP;
487
+ // inspect(self: this): PMP
488
+ // mount(self: this): ProPMP
489
+ initCSRXform(self: this): ProPMP<TProps, TActions, ETProps>;
490
+ initSSRXform(self: this): ProPMP<TProps, TActions, ETProps>;
491
+ onNoXForm(self: this): ProPMP<TProps, TActions, ETProps>;
492
+
493
+ mountClone(self: this): Partial<MountProps<TProps, TActions, ETProps>>;
494
+ }
495
+
496
+ export interface IObject$tring{
497
+ strVal: string | undefined;
498
+ objVal: any;
499
+ arrVal: any[] | undefined;
500
+ parse(): Promise<void>;
501
+ }
502
+
503
+ export type ZeroOrMore<T> = T | Array<T> | undefined;