glass-easel-miniprogram-adapter 0.2.0 → 0.3.0

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.
Files changed (62) hide show
  1. package/.eslintignore +4 -0
  2. package/dist/glass_easel_miniprogram_adapter.d.ts +872 -1
  3. package/dist/glass_easel_miniprogram_adapter.es.js +2 -0
  4. package/dist/glass_easel_miniprogram_adapter.es.js.map +1 -0
  5. package/dist/glass_easel_miniprogram_adapter.js +2 -2
  6. package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
  7. package/jest.config.js +7 -4
  8. package/package.json +8 -6
  9. package/rollup.config.ts +83 -0
  10. package/src/backend.ts +7 -3
  11. package/src/behavior.ts +8 -2
  12. package/src/builder/base_behavior_builder.ts +437 -0
  13. package/src/builder/behavior_builder.ts +265 -0
  14. package/src/builder/component_builder.ts +337 -0
  15. package/src/builder/index.ts +2 -0
  16. package/src/builder/type_utils.ts +98 -0
  17. package/src/component.ts +10 -7
  18. package/src/env.ts +73 -0
  19. package/src/index.ts +3 -77
  20. package/src/intersection.ts +2 -2
  21. package/src/media_query.ts +4 -6
  22. package/src/selector_query.ts +3 -3
  23. package/src/space.ts +11 -1030
  24. package/src/types.ts +7 -5
  25. package/tests/base/env.ts +1 -1
  26. package/tests/env.test.ts +3 -3
  27. package/tests/selector.test.ts +137 -14
  28. package/tests/space.test.ts +8 -14
  29. package/tsconfig.json +1 -3
  30. package/dist/types/src/backend.d.ts +0 -59
  31. package/dist/types/src/backend.d.ts.map +0 -1
  32. package/dist/types/src/behavior.d.ts +0 -35
  33. package/dist/types/src/behavior.d.ts.map +0 -1
  34. package/dist/types/src/component.d.ts +0 -170
  35. package/dist/types/src/component.d.ts.map +0 -1
  36. package/dist/types/src/index.d.ts +0 -58
  37. package/dist/types/src/index.d.ts.map +0 -1
  38. package/dist/types/src/intersection.d.ts +0 -24
  39. package/dist/types/src/intersection.d.ts.map +0 -1
  40. package/dist/types/src/media_query.d.ts +0 -13
  41. package/dist/types/src/media_query.d.ts.map +0 -1
  42. package/dist/types/src/selector_query.d.ts +0 -98
  43. package/dist/types/src/selector_query.d.ts.map +0 -1
  44. package/dist/types/src/space.d.ts +0 -369
  45. package/dist/types/src/space.d.ts.map +0 -1
  46. package/dist/types/src/types.d.ts +0 -77
  47. package/dist/types/src/types.d.ts.map +0 -1
  48. package/dist/types/src/utils.d.ts +0 -2
  49. package/dist/types/src/utils.d.ts.map +0 -1
  50. package/dist/types/tests/base/env.d.ts +0 -3
  51. package/dist/types/tests/base/env.d.ts.map +0 -1
  52. package/dist/types/tests/data_update.test.d.ts +0 -2
  53. package/dist/types/tests/data_update.test.d.ts.map +0 -1
  54. package/dist/types/tests/env.test.d.ts +0 -2
  55. package/dist/types/tests/env.test.d.ts.map +0 -1
  56. package/dist/types/tests/selector.test.d.ts +0 -2
  57. package/dist/types/tests/selector.test.d.ts.map +0 -1
  58. package/dist/types/tests/space.test.d.ts +0 -2
  59. package/dist/types/tests/space.test.d.ts.map +0 -1
  60. package/dist/types/tests/trait_behavior.test.d.ts +0 -2
  61. package/dist/types/tests/trait_behavior.test.d.ts.map +0 -1
  62. package/webpack.config.js +0 -79
@@ -1 +1,872 @@
1
- export * from "./types/src/index"
1
+ import * as glassEasel from 'glass-easel';
2
+ import { typeUtils, DeepCopyKind } from 'glass-easel';
3
+ export { glassEasel };
4
+
5
+ type SelectorQueryFields = {
6
+ id?: boolean;
7
+ dataset?: boolean;
8
+ mark?: boolean;
9
+ rect?: boolean;
10
+ size?: boolean;
11
+ scrollOffset?: boolean;
12
+ properties?: string[];
13
+ };
14
+ type SelectorQueryResult<T extends SelectorQueryFields> = {
15
+ id: T['id'] extends true ? string : undefined;
16
+ dataset: T['dataset'] extends true ? {
17
+ [k: string]: any;
18
+ } : undefined;
19
+ mark: T['mark'] extends true ? {
20
+ [k: string]: any;
21
+ } : undefined;
22
+ left: T['rect'] extends true ? number : undefined;
23
+ top: T['rect'] extends true ? number : undefined;
24
+ right: T['rect'] extends true ? number : undefined;
25
+ bottom: T['rect'] extends true ? number : undefined;
26
+ width: T['size'] extends true ? number : undefined;
27
+ height: T['size'] extends true ? number : undefined;
28
+ scrollLeft: T['scrollOffset'] extends true ? number : undefined;
29
+ scrollTop: T['scrollOffset'] extends true ? number : undefined;
30
+ scrollWidth: T['scrollOffset'] extends true ? number : undefined;
31
+ scrollHeight: T['scrollOffset'] extends true ? number : undefined;
32
+ } & {
33
+ [K in T['properties'] extends (infer I extends string)[] ? I : never]: any;
34
+ };
35
+ type BoundingClientRect = {
36
+ id: string;
37
+ dataset: {
38
+ [k: string]: any;
39
+ };
40
+ left: number;
41
+ top: number;
42
+ right: number;
43
+ bottom: number;
44
+ width: number;
45
+ height: number;
46
+ };
47
+ type ScrollOffset = {
48
+ id: string;
49
+ dataset: {
50
+ [k: string]: any;
51
+ };
52
+ scrollLeft: number;
53
+ scrollTop: number;
54
+ scrollWidth: number;
55
+ scrollHeight: number;
56
+ };
57
+ declare class NodesRef<S extends boolean> {
58
+ private _$sq;
59
+ private _$comp;
60
+ private _$sel;
61
+ private _$single;
62
+ constructor(selectorQuery: SelectorQuery, component: GeneralComponent, selector: string | null, selectSingle: S);
63
+ fields<T extends SelectorQueryFields>(fields: T, cb?: (res: S extends true ? SelectorQueryResult<T> : SelectorQueryResult<T>[]) => void): SelectorQuery;
64
+ boundingClientRect(cb?: (res: S extends true ? BoundingClientRect : BoundingClientRect[]) => void): SelectorQuery;
65
+ scrollOffset(cb?: (res: S extends true ? ScrollOffset : ScrollOffset[]) => void): SelectorQuery;
66
+ }
67
+ declare class SelectorQuery {
68
+ private _$comp;
69
+ /** Change where the node should be selected from */
70
+ in(component: GeneralComponent): this;
71
+ /** Select the first node that matches the selector */
72
+ select(selector: string): NodesRef<true>;
73
+ /** Select all nodes that match the selector */
74
+ selectAll(selector: string): NodesRef<false>;
75
+ /**
76
+ * Select the viewport of the component
77
+ *
78
+ * Only the size and the scroll position is meaningful when the viewport is selected.
79
+ */
80
+ selectViewport(): NodesRef<true>;
81
+ /**
82
+ * Execute all queries
83
+ *
84
+ * The `cb` is called after all queries done.
85
+ */
86
+ exec(cb?: (resList: any[]) => void): void;
87
+ }
88
+
89
+ type IntersectionObserverMargins = {
90
+ left: number;
91
+ top: number;
92
+ right: number;
93
+ bottom: number;
94
+ };
95
+ declare class IntersectionObserver {
96
+ private _$comp;
97
+ private _$thresholds;
98
+ private _$initialRatio;
99
+ private _$observeAll;
100
+ private _$selector;
101
+ private _$margins;
102
+ private _$observers;
103
+ relativeTo(selector: string, margins?: IntersectionObserverMargins): this;
104
+ relativeToViewport(margins?: IntersectionObserverMargins): this;
105
+ observe(targetSelector: string, listener: (status: glassEasel.backend.IntersectionStatus) => void): void;
106
+ disconnect(): void;
107
+ }
108
+
109
+ declare class MediaQueryObserver {
110
+ private _$comp;
111
+ private _$observer;
112
+ observe(descriptor: glassEasel.backend.MediaQueryStatus, listener: (status: {
113
+ matches: boolean;
114
+ }) => void): void;
115
+ disconnect(): void;
116
+ }
117
+
118
+ type DataList$6 = typeUtils.DataList;
119
+ type PropertyList$6 = typeUtils.PropertyList;
120
+ type MethodList$5 = typeUtils.MethodList;
121
+ type AllData<TData extends DataList$6, TProperty extends PropertyList$6> = typeUtils.DataWithPropertyValues<TData, TProperty>;
122
+ type ExportType<UData extends DataList$6, UProperty extends PropertyList$6, UMethod extends MethodList$5, UComponentExport> = [UComponentExport] extends [never] ? Component<UData, UProperty, UMethod, UComponentExport> : UComponentExport;
123
+ type GeneralComponent = Component<any, any, any, any>;
124
+ type Component<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> = ComponentCaller<TData, TProperty, TMethod, TComponentExport> & {
125
+ [k in keyof TMethod]: TMethod[k];
126
+ };
127
+ declare class ComponentCaller<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> {
128
+ /** The corresponding `Component` */
129
+ _$: glassEasel.Component<TData, TProperty, TMethod>;
130
+ /** The component path in the code space */
131
+ get is(): string;
132
+ set is(value: string);
133
+ /** The `id` field in the template */
134
+ get id(): string;
135
+ set id(value: string);
136
+ /** The `data-*` field in the template */
137
+ get dataset(): {
138
+ [key: string]: any;
139
+ } | null;
140
+ set dataset(value: {
141
+ [key: string]: any;
142
+ } | null);
143
+ /** The component data and property values */
144
+ get data(): typeUtils.Merge<AllData<TData, TProperty>>;
145
+ set data(value: AllData<TData, TProperty>);
146
+ /** The component data and property values (same as `data` ) */
147
+ get properties(): typeUtils.Merge<AllData<TData, TProperty>>;
148
+ set properties(value: AllData<TData, TProperty>);
149
+ /**
150
+ * Group several data update calls
151
+ *
152
+ * This method is designed for hinting the backend that some updates should be handled together.
153
+ * However, this is done automatically now,
154
+ * so this method is just for backward compatibilities.
155
+ */
156
+ groupSetData(callback: () => void): void;
157
+ /**
158
+ * Do a classic data update
159
+ *
160
+ * The `callback` is called after the update applies in the backend.
161
+ * In most cases, you SHOULD NOT wait the backend update (that might be very slow),
162
+ * and most calls, including read calls such as `selectComponent` , simply works immediately.
163
+ * However, when called inside observers,
164
+ * the data update will not be applied to templates immediately
165
+ * (it is recommanded to use `updateData` instead in observers).
166
+ */
167
+ setData(newData: Partial<typeUtils.SetDataSetter<typeUtils.DataWithPropertyValues<TData, TProperty>>>, callback?: () => void): void;
168
+ /**
169
+ * Schedule a classic data updates
170
+ *
171
+ * The data update will not be applied until next `setData` or `applyDataUpdates` call.
172
+ * When called inside observers, the data update will be applied when observer ends.
173
+ * All data observers will not be triggered immediately before applied.
174
+ * Reads of the data will get the unchanged value before applied.
175
+ */
176
+ updateData(newData: Partial<typeUtils.SetDataSetter<typeUtils.DataWithPropertyValues<TData, TProperty>>>): void;
177
+ /**
178
+ * Schedule a data update on a single specified path
179
+ *
180
+ * The data update will not be applied until next `setData` or `applyDataUpdates` call.
181
+ * All data observers will not be triggered immediately before applied.
182
+ * Reads of the data will get the unchanged value before applied.
183
+ */
184
+ replaceDataOnPath<T extends (string | number)[]>(path: readonly [...T], data: typeUtils.GetFromDataPath<typeUtils.DataWithPropertyValues<TData, TProperty>, T>): void;
185
+ /**
186
+ * Schedule an array update
187
+ *
188
+ * The behavior is like `Array.prototype.slice` .
189
+ * Break the array before the `index`-th item, delete `del` items, and insert some items here.
190
+ * If `index` is undefined, negative, or larger than the length of the array,
191
+ * no items will be deleted and new items will be appended to the end of the array.
192
+ * The data update will not be applied until next `setData` or `applyDataUpdates` call.
193
+ * All data observers will not be triggered immediately before applied.
194
+ * Reads of the data will get the unchanged value before applied.
195
+ */
196
+ spliceArrayDataOnPath<T extends (string | number)[]>(path: readonly [...T], index: typeUtils.GetFromDataPath<typeUtils.DataWithPropertyValues<TData, TProperty>, T> extends any[] ? number | undefined : never, del: typeUtils.GetFromDataPath<typeUtils.DataWithPropertyValues<TData, TProperty>, T> extends any[] ? number | undefined : never, inserts: typeUtils.GetFromDataPath<typeUtils.DataWithPropertyValues<TData, TProperty>, T> extends (infer I)[] ? I[] : never): void;
197
+ /**
198
+ * Apply all scheduled updates immediately
199
+ *
200
+ * Inside observers, it is generally not .
201
+ */
202
+ applyDataUpdates(): void;
203
+ /**
204
+ * Pending all data updates in the callback, and apply updates after callback returns
205
+ *
206
+ * This function helps grouping several `replaceDataOnPath` or `spliceArrayDataOnPath` calls,
207
+ * and then apply them at the end of the callback.
208
+ * `setData` and `applyDataUpdates` calls inside the callback still apply updates immediately.
209
+ */
210
+ groupUpdates<T>(callback: () => T): T;
211
+ /**
212
+ * Check whether the `other` behavior is a dependent behavior or a implemented trait behavior
213
+ */
214
+ hasBehavior(behavior: GeneralBehavior | TraitBehavior<any, any>): boolean;
215
+ /**
216
+ * Get the trait behavior implementation of the component
217
+ *
218
+ * Returns `undefined` if the specified trait behavior is not implemented.
219
+ */
220
+ traitBehavior<TOut extends {
221
+ [key: string]: any;
222
+ }>(traitBehavior: TraitBehavior<any, TOut>): TOut | undefined;
223
+ /** Trigger an event */
224
+ triggerEvent(name: string, detail: any, options: {
225
+ bubbles?: boolean;
226
+ composed?: boolean;
227
+ capturePhase?: boolean;
228
+ }): void;
229
+ /** Create a selector query for searching element inside the component */
230
+ createSelectorQuery(): SelectorQuery;
231
+ /** Create an intersection observer */
232
+ createIntersectionObserver(options?: {
233
+ thresholds?: number[];
234
+ initialRatio?: number;
235
+ observeAll?: boolean;
236
+ }): IntersectionObserver;
237
+ /** Create an media query observer */
238
+ createMediaQueryObserver(): MediaQueryObserver;
239
+ /**
240
+ * Query an element inside the component
241
+ *
242
+ * If `componentType` is provided, this method will check the selected component type.
243
+ * If the component type does not match, `null` is returned.
244
+ */
245
+ selectComponent(selector: string): any;
246
+ selectComponent<UData extends DataList$6, UProperty extends PropertyList$6, UMethod extends MethodList$5, UComponentExport>(selector: string, componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>): ExportType<UData, UProperty, UMethod, UComponentExport> | null;
247
+ /**
248
+ * Query all elements inside the component
249
+ *
250
+ * If `componentType` is provided, this method will check the selected component type.
251
+ * If a component type does not match, it is not returned.
252
+ */
253
+ selectAllComponents(selector: string): GeneralComponent[];
254
+ selectAllComponents<UData extends DataList$6, UProperty extends PropertyList$6, UMethod extends MethodList$5, UComponentExport>(selector: string, componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>): ExportType<UData, UProperty, UMethod, UComponentExport>[];
255
+ /**
256
+ * Get the owner component
257
+ *
258
+ * If `componentType` is provided, this method will check the selected component type.
259
+ * If a component type does not match, `null` is returned.
260
+ */
261
+ selectOwnerComponent(): any;
262
+ selectOwnerComponent<UData extends DataList$6, UProperty extends PropertyList$6, UMethod extends MethodList$5, UComponentExport>(componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>): ExportType<UData, UProperty, UMethod, UComponentExport> | null;
263
+ getRelationNodes(relationKey: string): GeneralComponent[];
264
+ /** Cast the component into a general-typed one */
265
+ general(): GeneralComponent;
266
+ /**
267
+ * Cast the component into the specified type
268
+ *
269
+ * Returns `null` if the component node is not the instance of the specified component.
270
+ */
271
+ asInstanceOf<UData extends DataList$6, UProperty extends PropertyList$6, UMethod extends MethodList$5, UComponentExport>(componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>): Component<UData, UProperty, UMethod, UComponentExport> | null;
272
+ }
273
+ declare class ComponentProto<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> {
274
+ private proto;
275
+ constructor(methods: TMethod, componentExport?: (source: GeneralComponent | null) => TComponentExport);
276
+ derive(): Component<TData, TProperty, TMethod, TComponentExport>;
277
+ }
278
+
279
+ type component_AllData<TData extends DataList$6, TProperty extends PropertyList$6> = AllData<TData, TProperty>;
280
+ type component_Component<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> = Component<TData, TProperty, TMethod, TComponentExport>;
281
+ type component_ComponentCaller<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> = ComponentCaller<TData, TProperty, TMethod, TComponentExport>;
282
+ declare const component_ComponentCaller: typeof ComponentCaller;
283
+ type component_ComponentProto<TData extends DataList$6, TProperty extends PropertyList$6, TMethod extends MethodList$5, TComponentExport> = ComponentProto<TData, TProperty, TMethod, TComponentExport>;
284
+ declare const component_ComponentProto: typeof ComponentProto;
285
+ type component_GeneralComponent = GeneralComponent;
286
+ declare namespace component {
287
+ export { type component_AllData as AllData, type component_Component as Component, component_ComponentCaller as ComponentCaller, component_ComponentProto as ComponentProto, type component_GeneralComponent as GeneralComponent };
288
+ }
289
+
290
+ declare const enum StyleIsolation {
291
+ Isolated = "isolated",
292
+ ApplyShared = "apply-shared",
293
+ Shared = "shared",
294
+ PageIsolated = "page-isolated",
295
+ PageApplyShared = "page-apply-shared",
296
+ PageShared = "page-shared"
297
+ }
298
+ type ComponentStaticConfig = {
299
+ component?: boolean;
300
+ usingComponents?: {
301
+ [name: string]: string;
302
+ };
303
+ componentGenerics?: {
304
+ [name: string]: true | {
305
+ default?: string;
306
+ };
307
+ };
308
+ componentPlaceholder?: {
309
+ [name: string]: string;
310
+ };
311
+ styleIsolation?: StyleIsolation;
312
+ /** @obsolete */
313
+ addGlobalClass?: boolean;
314
+ pureDataPattern?: string;
315
+ };
316
+ type ComponentDefinitionOptions = {
317
+ multipleSlots?: boolean;
318
+ pureDataPattern?: RegExp;
319
+ virtualHost?: boolean;
320
+ dataDeepCopy?: DeepCopyKind;
321
+ propertyPassingDeepCopy?: DeepCopyKind;
322
+ propertyEarlyInit?: boolean;
323
+ };
324
+ type ComponentMethod$4 = typeUtils.ComponentMethod;
325
+ type BehaviorDefinition<TData extends typeUtils.DataList, TProperty extends typeUtils.PropertyList, TMethod extends typeUtils.MethodList, TComponentExport> = {
326
+ behaviors?: Behavior<any, any, any, any, any>[];
327
+ properties?: TProperty;
328
+ data?: TData | (() => TData);
329
+ observers?: {
330
+ fields?: string;
331
+ observer: ComponentMethod$4;
332
+ }[] | {
333
+ [fields: string]: ComponentMethod$4;
334
+ };
335
+ methods?: TMethod;
336
+ created?: ComponentMethod$4;
337
+ attached?: ComponentMethod$4;
338
+ ready?: ComponentMethod$4;
339
+ moved?: ComponentMethod$4;
340
+ detached?: ComponentMethod$4;
341
+ lifetimes?: {
342
+ [name: string]: ComponentMethod$4;
343
+ };
344
+ pageLifetimes?: {
345
+ [name: string]: ComponentMethod$4;
346
+ };
347
+ relations?: typeUtils.RelationParamsWithKey;
348
+ externalClasses?: string[];
349
+ definitionFilter?: DefinitionFilter;
350
+ export?: (source: GeneralComponent | null) => TComponentExport;
351
+ };
352
+ type ComponentDefinition<TData extends typeUtils.DataList, TProperty extends typeUtils.PropertyList, TMethod extends typeUtils.MethodList, TComponentExport> = {
353
+ options?: ComponentDefinitionOptions;
354
+ } & BehaviorDefinition<TData, TProperty, TMethod, TComponentExport>;
355
+ type GeneralComponentDefinition = ComponentDefinition<any, any, any, any>;
356
+ type PageDefinition<TData extends typeUtils.DataList, TExtraFields extends {
357
+ [k: PropertyKey]: any;
358
+ }> = TExtraFields & {
359
+ options?: ComponentDefinitionOptions;
360
+ behaviors?: GeneralBehavior[];
361
+ data?: TData;
362
+ };
363
+
364
+ type types_BehaviorDefinition<TData extends typeUtils.DataList, TProperty extends typeUtils.PropertyList, TMethod extends typeUtils.MethodList, TComponentExport> = BehaviorDefinition<TData, TProperty, TMethod, TComponentExport>;
365
+ type types_ComponentDefinition<TData extends typeUtils.DataList, TProperty extends typeUtils.PropertyList, TMethod extends typeUtils.MethodList, TComponentExport> = ComponentDefinition<TData, TProperty, TMethod, TComponentExport>;
366
+ type types_ComponentDefinitionOptions = ComponentDefinitionOptions;
367
+ type types_ComponentStaticConfig = ComponentStaticConfig;
368
+ type types_GeneralComponentDefinition = GeneralComponentDefinition;
369
+ type types_PageDefinition<TData extends typeUtils.DataList, TExtraFields extends {
370
+ [k: PropertyKey]: any;
371
+ }> = PageDefinition<TData, TExtraFields>;
372
+ type types_StyleIsolation = StyleIsolation;
373
+ declare const types_StyleIsolation: typeof StyleIsolation;
374
+ declare namespace types {
375
+ export { type types_BehaviorDefinition as BehaviorDefinition, type types_ComponentDefinition as ComponentDefinition, type types_ComponentDefinitionOptions as ComponentDefinitionOptions, type types_ComponentStaticConfig as ComponentStaticConfig, type types_GeneralComponentDefinition as GeneralComponentDefinition, type types_PageDefinition as PageDefinition, types_StyleIsolation as StyleIsolation, typeUtils as utils };
376
+ }
377
+
378
+ type DataList$5 = typeUtils.DataList;
379
+ type PropertyList$5 = typeUtils.PropertyList;
380
+ type MethodList$4 = typeUtils.MethodList;
381
+ type ChainingFilterType$4 = typeUtils.ChainingFilterType;
382
+ type DefinitionFilter = (target: GeneralComponentDefinition, childFilters: (((target: GeneralComponentDefinition) => void) | null)[]) => void;
383
+ type GeneralBehavior = Behavior<Record<string, any>, Record<string, any>, Record<string, any>, any>;
384
+ declare class Behavior<TData extends DataList$5, TProperty extends PropertyList$5, TMethod extends MethodList$4, TChainingFilter extends ChainingFilterType$4, TComponentExport = never> {
385
+ }
386
+ declare class ComponentType<TData extends DataList$5, TProperty extends PropertyList$5, TMethod extends MethodList$4, TComponentExport> {
387
+ }
388
+ declare class TraitBehavior<TIn extends {
389
+ [key: string]: any;
390
+ }, TOut extends {
391
+ [key: string]: any;
392
+ } = TIn> {
393
+ constructor(inner: glassEasel.TraitBehavior<TIn, TOut>);
394
+ }
395
+
396
+ type ResolveBehaviorBuilder<B, TChainingFilter extends ChainingFilterType$3> = typeUtils.IsNever<TChainingFilter> extends false ? TChainingFilter extends ChainingFilterType$3 ? Omit<B, TChainingFilter['remove']> & TChainingFilter['add'] : B : B;
397
+ type DataList$4 = typeUtils.DataList;
398
+ type PropertyList$4 = typeUtils.PropertyList;
399
+ type ChainingFilterType$3 = typeUtils.ChainingFilterType;
400
+ type ComponentMethod$3 = typeUtils.ComponentMethod;
401
+ type TaggedMethod$3<Fn extends ComponentMethod$3> = typeUtils.TaggedMethod<Fn>;
402
+ interface RelationHandler<TTarget, TOut> {
403
+ list(): TTarget[];
404
+ listAsTrait: TOut extends never ? undefined : () => TOut[];
405
+ }
406
+ type TraitRelationParams<TOut extends {
407
+ [key: string]: any;
408
+ }> = {
409
+ target: TraitBehavior<any, TOut>;
410
+ type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node';
411
+ linked?: (target: GeneralComponent) => void;
412
+ linkChanged?: (target: GeneralComponent) => void;
413
+ unlinked?: (target: GeneralComponent) => void;
414
+ linkFailed?: (target: GeneralComponent) => void;
415
+ };
416
+ type RelationParams = {
417
+ target?: string | ComponentType<any, any, any, any> | GeneralBehavior | TraitBehavior<any>;
418
+ type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node';
419
+ linked?: (target: GeneralComponent) => void;
420
+ linkChanged?: (target: GeneralComponent) => void;
421
+ unlinked?: (target: GeneralComponent) => void;
422
+ linkFailed?: (target: GeneralComponent) => void;
423
+ };
424
+ type Lifetimes = {
425
+ created: () => void;
426
+ attached: () => void;
427
+ moved: () => void;
428
+ detached: () => void;
429
+ ready: () => void;
430
+ };
431
+ interface BuilderContext<TPrevData extends DataList$4, TProperty extends PropertyList$4, TMethodCaller> extends ThisType<TMethodCaller> {
432
+ self: TMethodCaller;
433
+ data: typeUtils.Merge<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>;
434
+ setData: (newData: Partial<typeUtils.SetDataSetter<TPrevData>>, callback?: () => void) => void;
435
+ implement: <TIn extends {
436
+ [x: string]: any;
437
+ }>(traitBehavior: TraitBehavior<TIn, any>, impl: TIn) => void;
438
+ relation<TOut extends {
439
+ [key: string]: any;
440
+ }>(def: TraitRelationParams<TOut> & ThisType<TMethodCaller>): RelationHandler<any, TOut>;
441
+ relation(def: RelationParams & ThisType<TMethodCaller>): RelationHandler<any, never>;
442
+ observer<P extends typeUtils.ObserverDataPathStrings<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>, V = typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P>>(paths: P, func: (newValue: V) => void): void;
443
+ observer<P extends typeUtils.ObserverDataPathStrings<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>[], V = {
444
+ [K in keyof P]: typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P[K]>;
445
+ }>(paths: readonly [...P], func: (...newValues: V extends any[] ? V : never) => void): void;
446
+ lifetime: <L extends keyof Lifetimes>(name: L, func: Lifetimes[L]) => void;
447
+ pageLifetime: (name: string, func: (...args: any[]) => void) => void;
448
+ method: <Fn extends ComponentMethod$3>(func: Fn) => TaggedMethod$3<Fn>;
449
+ listener: <T>(func: glassEasel.EventListener<T>) => TaggedMethod$3<glassEasel.EventListener<T>>;
450
+ }
451
+
452
+ type Empty$3 = typeUtils.Empty;
453
+ type DataList$3 = typeUtils.DataList;
454
+ type PropertyList$3 = typeUtils.PropertyList;
455
+ type PropertyType$2 = typeUtils.PropertyType;
456
+ type PropertyTypeToValueType$2<T extends PropertyType$2> = typeUtils.PropertyTypeToValueType<T>;
457
+ type MethodList$3 = typeUtils.MethodList;
458
+ type ChainingFilterType$2 = typeUtils.ChainingFilterType;
459
+ type ComponentMethod$2 = typeUtils.ComponentMethod;
460
+ type TaggedMethod$2<Fn extends ComponentMethod$2> = typeUtils.TaggedMethod<Fn>;
461
+ declare class BaseBehaviorBuilder<TPrevData extends DataList$3 = Empty$3, TData extends DataList$3 = Empty$3, TProperty extends PropertyList$3 = Empty$3, TMethod extends MethodList$3 = Empty$3, TChainingFilter extends ChainingFilterType$2 = never, TPendingChainingFilter extends ChainingFilterType$2 = never, TComponentExport = never> {
462
+ protected _$codeSpace: CodeSpace;
463
+ protected _$: glassEasel.BehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter>;
464
+ protected _$parents: GeneralBehavior[];
465
+ protected _$export?: (source: GeneralComponent | null) => TComponentExport;
466
+ /** Implement a trait behavior */
467
+ implement<TIn extends {
468
+ [key: string]: any;
469
+ }>(traitBehavior: TraitBehavior<TIn, any>, impl: TIn): ResolveBehaviorBuilder<this, TChainingFilter>;
470
+ /** Add external classes */
471
+ externalClasses(list: string[]): this;
472
+ /** Set the export value when the component is being selected */
473
+ export<TNewComponentExport>(f: (this: GeneralComponent, source: GeneralComponent | null) => TNewComponentExport): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
474
+ data<T extends DataList$3>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BaseBehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
475
+ property<N extends string, T extends PropertyType$2, V extends PropertyTypeToValueType$2<T>>(name: N, def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty & Record<N, unknown extends V ? T : typeUtils.PropertyOption<T, V>>, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
476
+ /**
477
+ * Add some public methods
478
+ *
479
+ * The public method can be used as an event handler, and can be visited in component instance.
480
+ */
481
+ methods<T extends MethodList$3>(funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod & T, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
482
+ /**
483
+ * Add a data observer
484
+ */
485
+ observer<P extends typeUtils.ObserverDataPathStrings<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>, V = typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P>>(paths: P, func: (this: Component<TData, TProperty, TMethod, any>, newValue: V) => void, once?: boolean): ResolveBehaviorBuilder<this, TChainingFilter>;
486
+ observer<P extends typeUtils.ObserverDataPathStrings<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>[], V = {
487
+ [K in keyof P]: typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P[K]>;
488
+ }>(paths: readonly [...P], func: (this: Component<TData, TProperty, TMethod, any>, ...newValues: V extends any[] ? V : never) => void, once?: boolean): ResolveBehaviorBuilder<this, TChainingFilter>;
489
+ /**
490
+ * Add a lifetime callback
491
+ */
492
+ lifetime<L extends keyof Lifetimes>(name: L, func: (this: Component<TData, TProperty, TMethod, any>, ...args: Parameters<Lifetimes[L]>) => ReturnType<Lifetimes[L]>, once?: boolean): ResolveBehaviorBuilder<this, TChainingFilter>;
493
+ /**
494
+ * Add a page-lifetime callback
495
+ */
496
+ pageLifetime(name: string, func: (this: Component<TData, TProperty, TMethod, any>, ...args: any[]) => any, once?: boolean): ResolveBehaviorBuilder<this, TChainingFilter>;
497
+ /**
498
+ * Add a relation
499
+ */
500
+ relation(name: string, rel: RelationParams & ThisType<Component<TData, TProperty, TMethod, TComponentExport>>): ResolveBehaviorBuilder<this, TChainingFilter>;
501
+ init<TExport extends Record<string, TaggedMethod$2<(...args: any[]) => any>> | void>(func: (this: Component<TData, TProperty, TMethod, TComponentExport>, builderContext: BuilderContext<TPrevData, TProperty, Component<TData, TProperty, TMethod, TComponentExport>>) => TExport): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
502
+ definition<TNewData extends DataList$3 = Empty$3, TNewProperty extends PropertyList$3 = Empty$3, TNewMethod extends MethodList$3 = Empty$3, TNewComponentExport = never>(def: BehaviorDefinition<TNewData, TNewProperty, TNewMethod, TNewComponentExport> & ThisType<Component<TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TNewComponentExport>>): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
503
+ }
504
+
505
+ type Empty$2 = typeUtils.Empty;
506
+ type DataList$2 = typeUtils.DataList;
507
+ type PropertyList$2 = typeUtils.PropertyList;
508
+ type PropertyType$1 = typeUtils.PropertyType;
509
+ type PropertyTypeToValueType$1<T extends PropertyType$1> = typeUtils.PropertyTypeToValueType<T>;
510
+ type MethodList$2 = typeUtils.MethodList;
511
+ type ChainingFilterType$1 = typeUtils.ChainingFilterType;
512
+ type ComponentMethod$1 = typeUtils.ComponentMethod;
513
+ type TaggedMethod$1<Fn extends ComponentMethod$1> = typeUtils.TaggedMethod<Fn>;
514
+ type ChainingFilterFunc<TAddedFields extends {
515
+ [key: string]: any;
516
+ }, TRemovedFields extends string = never> = typeUtils.ChainingFilterFunc<TAddedFields, TRemovedFields>;
517
+ declare class BehaviorBuilder<TPrevData extends DataList$2 = Empty$2, TData extends DataList$2 = Empty$2, TProperty extends PropertyList$2 = Empty$2, TMethod extends MethodList$2 = Empty$2, TChainingFilter extends ChainingFilterType$1 = never, TPendingChainingFilter extends ChainingFilterType$1 = never, TComponentExport = never> extends BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport> {
518
+ private _$definitionFilter;
519
+ /** Define a chaining filter */
520
+ chainingFilter<TAddedFields extends {
521
+ [key: string]: any;
522
+ }, TRemovedFields extends string = never>(func: ChainingFilterFunc<TAddedFields, TRemovedFields>): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, {
523
+ add: TAddedFields;
524
+ remove: TRemovedFields;
525
+ }, TComponentExport>, TChainingFilter>;
526
+ /** Use another behavior */
527
+ behavior<UData extends DataList$2, UProperty extends PropertyList$2, UMethod extends MethodList$2, UChainingFilter extends ChainingFilterType$1>(behavior: Behavior<UData, UProperty, UMethod, UChainingFilter>): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData & UData, TProperty & UProperty, TMethod & UMethod, UChainingFilter, TPendingChainingFilter, TComponentExport>, UChainingFilter>;
528
+ /** Set the export value when the component is being selected */
529
+ export<TNewComponentExport>(f: (this: GeneralComponent, source: GeneralComponent | null) => TNewComponentExport): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
530
+ /**
531
+ * Add some template data fields
532
+ *
533
+ * It does not support raw data, but a `gen` function which returns the new data fields.
534
+ * The `gen` function executes once during component creation.
535
+ */
536
+ data<T extends DataList$2>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
537
+ /**
538
+ * Add a single property
539
+ *
540
+ * The property name should be different from other properties.
541
+ */
542
+ property<N extends string, T extends PropertyType$1, V extends PropertyTypeToValueType$1<T>>(name: N, def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty & Record<N, unknown extends V ? T : typeUtils.PropertyOption<T, V>>, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
543
+ /**
544
+ * Add some public methods
545
+ *
546
+ * The public method can be used as an event handler, and can be visited in component instance.
547
+ */
548
+ methods<T extends MethodList$2>(funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty, TMethod & T, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
549
+ /**
550
+ * Execute a function while component instance creation
551
+ *
552
+ * A `BuilderContext` is provided to tweak the component creation progress.
553
+ * The return value is used as the "export" value of the behavior,
554
+ * which can be imported by other behaviors.
555
+ */
556
+ init<TExport extends Record<string, TaggedMethod$1<(...args: any[]) => any>> | void>(func: (this: Component<TData, TProperty, TMethod, TComponentExport>, builderContext: BuilderContext<TPrevData, TProperty, Component<TData, TProperty, TMethod, TComponentExport>>) => TExport): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
557
+ /** Apply a classic definition object */
558
+ definition<TNewData extends DataList$2 = Empty$2, TNewProperty extends PropertyList$2 = Empty$2, TNewMethod extends MethodList$2 = Empty$2, TNewComponentExport = never>(def: BehaviorDefinition<TNewData, TNewProperty, TNewMethod, TNewComponentExport> & ThisType<Component<TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TNewComponentExport>>): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
559
+ /**
560
+ * Finish the behavior definition process
561
+ */
562
+ register(): Behavior<TData, TProperty, TMethod, TPendingChainingFilter, TComponentExport>;
563
+ }
564
+
565
+ type Empty$1 = typeUtils.Empty;
566
+ type DataList$1 = typeUtils.DataList;
567
+ type PropertyList$1 = typeUtils.PropertyList;
568
+ type PropertyType = typeUtils.PropertyType;
569
+ type PropertyTypeToValueType<T extends PropertyType> = typeUtils.PropertyTypeToValueType<T>;
570
+ type MethodList$1 = typeUtils.MethodList;
571
+ type ChainingFilterType = typeUtils.ChainingFilterType;
572
+ type ComponentMethod = typeUtils.ComponentMethod;
573
+ type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>;
574
+ /**
575
+ * A direct way to create a component
576
+ */
577
+ declare class ComponentBuilder<TPrevData extends DataList$1 = Empty$1, TData extends DataList$1 = Empty$1, TProperty extends PropertyList$1 = Empty$1, TMethod extends MethodList$1 = Empty$1, TChainingFilter extends ChainingFilterType = never, TPendingChainingFilter extends ChainingFilterType = never, TComponentExport = never> extends BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport> {
578
+ private _$is;
579
+ private _$alias?;
580
+ private _$options?;
581
+ private _$proto?;
582
+ /**
583
+ * Set the component options
584
+ *
585
+ * If called multiple times, only the latest call is valid.
586
+ */
587
+ options(options: ComponentDefinitionOptions): ResolveBehaviorBuilder<this, TChainingFilter>;
588
+ /** Use another behavior */
589
+ behavior<UData extends DataList$1, UProperty extends PropertyList$1, UMethod extends MethodList$1, UChainingFilter extends ChainingFilterType, UComponentExport>(behavior: Behavior<UData, UProperty, UMethod, UChainingFilter, UComponentExport>): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData & UData, TProperty & UProperty, TMethod & UMethod, UChainingFilter, TPendingChainingFilter, UComponentExport>, UChainingFilter>;
590
+ /** Set the export value when the component is being selected */
591
+ export<TNewComponentExport>(f: (this: GeneralComponent, source: GeneralComponent | null) => TNewComponentExport): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
592
+ /**
593
+ * Add some template data fields
594
+ *
595
+ * It does not support raw data, but a `gen` function which returns the new data fields.
596
+ * The `gen` function executes once during component creation.
597
+ */
598
+ data<T extends DataList$1>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<ComponentBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
599
+ /**
600
+ * Add a single property
601
+ *
602
+ * The property name should be different from other properties.
603
+ */
604
+ property<N extends string, T extends PropertyType, V extends PropertyTypeToValueType<T>>(name: N, def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData, TProperty & Record<N, unknown extends V ? T : typeUtils.PropertyOption<T, V>>, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
605
+ /**
606
+ * Add some public methods
607
+ *
608
+ * The public method can be used as an event handler, and can be visited in component instance.
609
+ */
610
+ methods<T extends MethodList$1>(funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData, TProperty, TMethod & T, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
611
+ /**
612
+ * Execute a function while component instance creation
613
+ *
614
+ * A `BuilderContext` is provided to tweak the component creation progress.
615
+ * The return value is used as the "export" value of the behavior,
616
+ * which can be imported by other behaviors.
617
+ */
618
+ init<TExport extends Record<string, TaggedMethod<(...args: any[]) => any>> | void>(func: (this: Component<TData, TProperty, TMethod, TComponentExport>, builderContext: BuilderContext<TPrevData, TProperty, Component<TData, TProperty, TMethod, TComponentExport>>) => TExport): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
619
+ /** Apply a classic definition object */
620
+ definition<TNewData extends DataList$1 = Empty$1, TNewProperty extends PropertyList$1 = Empty$1, TNewMethod extends MethodList$1 = Empty$1, TNewComponentExport = never>(def: ComponentDefinition<TNewData, TNewProperty, TNewMethod, TNewComponentExport> & ThisType<Component<TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TNewComponentExport>>): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData & TNewData, TProperty & TNewProperty, TMethod & TNewMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport>, TChainingFilter>;
621
+ pageDefinition<TNewData extends DataList$1, TNewExtraFields extends {
622
+ [k: PropertyKey]: any;
623
+ }>(def: PageDefinition<TNewData, TNewExtraFields> & ThisType<Component<TData & TNewData, TProperty, TMethod & TNewExtraFields, undefined>>): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData & TNewData, TProperty, TMethod & TNewExtraFields, TChainingFilter, TPendingChainingFilter, TComponentExport>, TChainingFilter>;
624
+ /**
625
+ * Finish the component definition process
626
+ */
627
+ register(): ComponentType<TData, TProperty, TMethod, TComponentExport>;
628
+ }
629
+
630
+ interface PageConstructor {
631
+ <TData extends DataList, TNewExtraFields extends {
632
+ [k: PropertyKey]: any;
633
+ }>(definition: PageDefinition<TData, TNewExtraFields> & ThisType<Component<TData, Empty, TNewExtraFields, undefined>>): void;
634
+ }
635
+ interface ComponentConstructor {
636
+ (): ComponentBuilder;
637
+ <TData extends DataList, TProperty extends PropertyList, TMethod extends MethodList, TComponentExport>(definition: ComponentDefinition<TData, TProperty, TMethod, TComponentExport> & ThisType<Component<TData, TProperty, TMethod, TComponentExport>>): void;
638
+ }
639
+ interface BehaviorConstructor {
640
+ (): BehaviorBuilder;
641
+ <TData extends DataList, TProperty extends PropertyList, TMethod extends MethodList, TComponentExport>(definition: BehaviorDefinition<TData, TProperty, TMethod, TComponentExport>): Behavior<TData, TProperty, TMethod, never>;
642
+ trait<TIn extends {
643
+ [key: string]: any;
644
+ }>(): TraitBehavior<TIn, TIn>;
645
+ trait<TIn extends {
646
+ [key: string]: any;
647
+ }, TOut extends {
648
+ [key: string]: any;
649
+ }>(trans: (impl: TIn) => TOut): TraitBehavior<TIn, TOut>;
650
+ }
651
+ interface ComponentEnv {
652
+ Page: PageConstructor;
653
+ Component: ComponentConstructor;
654
+ Behavior: BehaviorConstructor;
655
+ }
656
+ type Empty = typeUtils.Empty;
657
+ type DataList = typeUtils.DataList;
658
+ type PropertyList = typeUtils.PropertyList;
659
+ type MethodList = typeUtils.MethodList;
660
+ /**
661
+ * A component space with mini-program code manager
662
+ */
663
+ declare class CodeSpace {
664
+ private _$isMainSpace;
665
+ private space;
666
+ private styleScopeManager;
667
+ private staticConfigMap;
668
+ private styleSheetMap;
669
+ private compiledTemplateMap;
670
+ private waitingAliasMap;
671
+ isMainSpace(): boolean;
672
+ /**
673
+ * Get the underlying component space
674
+ */
675
+ getComponentSpace(): glassEasel.ComponentSpace;
676
+ /**
677
+ * Add a behavior for all components
678
+ *
679
+ * Must be called before any component registration so that the component will use this behavior.
680
+ * Set to `null` to disable this behavior.
681
+ */
682
+ setOverallBehavior(behavior: glassEasel.GeneralBehavior): void;
683
+ /**
684
+ * Import another component space as a plugin (must be in the same environment)
685
+ *
686
+ * Components from the imported `codeSpace` can be used with URLs.
687
+ * If `domainAlias` is provided, the URL format is `plugin://DOMAIN_ALIAS/COMPONENT_SPACE_EXPORT_ALIAS` .
688
+ * If `privateImport` is enabled, another URL format is `plugin-private://DOMAIN/COMPONENT_IS` .
689
+ */
690
+ importCodeSpace(id: string, domainAlias?: string, privateImport?: boolean): void;
691
+ /**
692
+ * Add a style sheet URL with style scope name
693
+ *
694
+ * The URL should be recognized by the target backend.
695
+ * The `path` should not contain the `.wxss` suffix.
696
+ */
697
+ addStyleSheet(path: string, styleSheetUrl: string, styleScopeName?: string): void;
698
+ /**
699
+ * Get a style sheet URL
700
+ *
701
+ * The URL should be recognized by the target backend.
702
+ * The `path` should not contain the `.wxss` suffix.
703
+ */
704
+ getStyleSheet(path: string): string | undefined;
705
+ getStyleScopeName(path: string): string | undefined;
706
+ /**
707
+ * Add a compiled template
708
+ *
709
+ * The content is the execution result of the generated string of the template compiler.
710
+ * The `path` should not contain the `.wxml` suffix.
711
+ */
712
+ addCompiledTemplate(path: string, content: glassEasel.template.ComponentTemplate): void;
713
+ /**
714
+ * Get a compiled template
715
+ *
716
+ * The content is the execution result of the generated string of the template compiler.
717
+ * The `path` should not contain the `.wxml` suffix.
718
+ */
719
+ getCompiledTemplate(path: string): glassEasel.template.ComponentTemplate | undefined;
720
+ /**
721
+ * Add a static JSON config
722
+ *
723
+ * The `path` should not contain the `.json` suffix.
724
+ */
725
+ addComponentStaticConfig(path: string, content: ComponentStaticConfig): void;
726
+ /**
727
+ * Get a static JSON config
728
+ *
729
+ * The `path` should not contain the `.json` suffix.
730
+ */
731
+ getComponentStaticConfig(path: string): ComponentStaticConfig | undefined;
732
+ /**
733
+ * Create a component definition environment
734
+ *
735
+ * During the sync execution of `cb` , `Component` and `Behavior` global vars will be available.
736
+ * `globalObject` should be the JavaScript global object, a.k.a. `window` in DOM.
737
+ * Some global variables, a.k.a `Component` `Behavior` `Page` ,
738
+ * will be written into `globalObject` .
739
+ * `path` should be the component path (without ".js" extension).
740
+ */
741
+ globalComponentEnv<T>(globalObject: any, path: string, cb: () => T): T;
742
+ /**
743
+ * Create a component definition environment
744
+ *
745
+ * Like `globalComponentEnv` , but the global variables are given as callback arguments.
746
+ */
747
+ componentEnv<T>(path: string, cb: (env: ComponentEnv) => T): T;
748
+ /**
749
+ * Build a component outside of a definition environment
750
+ *
751
+ * The method do not need a definition environment, so the global object pollution is avoided.
752
+ * `path` should be the component path (without ".js" extension).
753
+ */
754
+ component(path: string): ComponentBuilder;
755
+ /**
756
+ * Build a behavior outside of a definition environment
757
+ *
758
+ * The method do not need a definition environment, so the global object pollution is avoided.
759
+ * `path` should be the component path (without ".js" extension).
760
+ */
761
+ behavior(): BehaviorBuilder;
762
+ /**
763
+ * Define a trait behavior
764
+ */
765
+ traitBehavior<TIn extends {
766
+ [key: string]: any;
767
+ }>(): TraitBehavior<TIn, TIn>;
768
+ traitBehavior<TIn extends {
769
+ [key: string]: any;
770
+ }, TOut extends {
771
+ [key: string]: any;
772
+ }>(trans: (impl: TIn) => TOut): TraitBehavior<TIn, TOut>;
773
+ }
774
+
775
+ /**
776
+ * A backend context that has been associated to an environment
777
+ */
778
+ declare class AssociatedBackend {
779
+ private _$env;
780
+ /**
781
+ * Register a style sheet resource
782
+ *
783
+ * Some backend cannot load style sheet URL.
784
+ * In this cases, the content should be registered here.
785
+ */
786
+ registerStyleSheetContent(url: string, content: any): void;
787
+ /**
788
+ * Create a root component in specified backend
789
+ *
790
+ * The component is searched in the `codeSpace` with `url` .
791
+ * If `url` contains "?" params, it will be parsed and try to set to component properties.
792
+ */
793
+ createRoot(tagName: string, codeSpace: CodeSpace, url: string, genericTargets?: {
794
+ [key: string]: string;
795
+ }): Root;
796
+ }
797
+ /**
798
+ * A root component
799
+ */
800
+ declare class Root {
801
+ private _$comp;
802
+ /**
803
+ * Get the underlying component
804
+ */
805
+ getComponent(): glassEasel.GeneralComponent;
806
+ /**
807
+ * Attach the root component to the backend
808
+ *
809
+ * This component, the `parent` and the `placeholder` MUST be in the same context.
810
+ * The `parent` MUST be a parent node of the `placeholder` .
811
+ * This also triggers `attached` lifetimes for components.
812
+ */
813
+ attach(parent: glassEasel.GeneralBackendElement, placeholder: glassEasel.GeneralBackendElement): void;
814
+ /**
815
+ * Release the root component
816
+ *
817
+ * Some backends require this explicit call to avoid memory leaks.
818
+ * This also triggers `detached` lifetimes for components.
819
+ */
820
+ release(): void;
821
+ }
822
+
823
+ /**
824
+ * A mini-program API environment
825
+ *
826
+ * Each environment manages multiple backend contexts.
827
+ * However, a backend context should be exclusively managed by a single environment
828
+ * (to avoid `StyleScopeId` confliction).
829
+ * It is able to create multiple `CodeSpace` within the environment.
830
+ */
831
+ declare class MiniProgramEnv {
832
+ private codeSpaceMap;
833
+ private globalCodeSpace;
834
+ /**
835
+ * Create an empty mini-program API environment
836
+ */
837
+ constructor();
838
+ /**
839
+ * Get a global code space in which global components can be defined
840
+ *
841
+ * External glass-easel based components can be defined in this code space.
842
+ * All global components should be defined before any other `CodeSpace` created!
843
+ */
844
+ getGlobalCodeSpace(): CodeSpace;
845
+ /**
846
+ * Associate a backend context
847
+ *
848
+ * If `backendContext` is not given, the DOM-based backend is used
849
+ * (causes failure if running outside browsers).
850
+ * The backend context SHOULD NOT be associated by other environments!
851
+ */
852
+ associateBackend(backendContent?: glassEasel.GeneralBackendContext): AssociatedBackend;
853
+ /**
854
+ * Create a component space that can manage WXML, WXSS, JS and static JSON config files
855
+ *
856
+ * The space can be specified as a *main* space.
857
+ * This makes some features available:
858
+ * * the `app.wxss` will be used as a style sheet for all root components in the space;
859
+ * * the `StyleIsolation.Shared` is accepted for components in the space.
860
+ * Non-main spaces usually act as plugins.
861
+ * `publicComponents` is a map for specifying a map of aliases and component paths.
862
+ */
863
+ createCodeSpace(id: string, isMainSpace: boolean, publicComponents?: {
864
+ [alias: string]: string;
865
+ }): CodeSpace;
866
+ /**
867
+ * Get a component space by the `id` specified when created
868
+ */
869
+ getCodeSpace(id: string): CodeSpace | undefined;
870
+ }
871
+
872
+ export { AssociatedBackend, type BehaviorConstructor, CodeSpace, type ComponentConstructor, type ComponentEnv, MiniProgramEnv, type PageConstructor, Root, component, types };