glass-easel-miniprogram-adapter 0.1.0 → 0.2.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.
- package/dist/glass_easel_miniprogram_adapter.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/dist/types/src/backend.d.ts +8 -0
- package/dist/types/src/backend.d.ts.map +1 -1
- package/dist/types/src/behavior.d.ts +1 -1
- package/dist/types/src/behavior.d.ts.map +1 -1
- package/dist/types/src/component.d.ts +12 -2
- package/dist/types/src/component.d.ts.map +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/intersection.d.ts +24 -0
- package/dist/types/src/intersection.d.ts.map +1 -0
- package/dist/types/src/media_query.d.ts +13 -0
- package/dist/types/src/media_query.d.ts.map +1 -0
- package/dist/types/src/selector_query.d.ts.map +1 -1
- package/dist/types/src/space.d.ts +3 -3
- package/dist/types/src/space.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +4 -4
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tests/base/env.d.ts.map +1 -1
- package/jest.config.js +1 -3
- package/package.json +2 -2
- package/src/backend.ts +20 -10
- package/src/behavior.ts +7 -29
- package/src/component.ts +56 -38
- package/src/index.ts +1 -3
- package/src/intersection.ts +119 -0
- package/src/media_query.ts +28 -0
- package/src/selector_query.ts +176 -174
- package/src/space.ts +154 -238
- package/src/types.ts +33 -33
- package/src/utils.ts +4 -3
- package/tests/base/env.ts +1 -2
- package/tests/data_update.test.ts +43 -37
- package/tests/env.test.ts +37 -37
- package/tests/selector.test.ts +295 -189
- package/tests/space.test.ts +216 -91
- package/tests/trait_behavior.test.ts +26 -23
- package/webpack.config.js +14 -13
package/src/space.ts
CHANGED
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
PageDefinition,
|
|
12
12
|
utils as typeUtils,
|
|
13
13
|
} from './types'
|
|
14
|
-
import {
|
|
15
|
-
guid,
|
|
16
|
-
} from './utils'
|
|
14
|
+
import { guid } from './utils'
|
|
17
15
|
import {
|
|
18
16
|
Behavior,
|
|
19
17
|
ComponentType,
|
|
@@ -21,23 +19,13 @@ import {
|
|
|
21
19
|
GeneralBehavior,
|
|
22
20
|
TraitBehavior,
|
|
23
21
|
} from './behavior'
|
|
24
|
-
import {
|
|
25
|
-
AllData,
|
|
26
|
-
Component,
|
|
27
|
-
ComponentProto,
|
|
28
|
-
GeneralComponent,
|
|
29
|
-
} from './component'
|
|
22
|
+
import { AllData, Component, ComponentProto, GeneralComponent } from './component'
|
|
30
23
|
|
|
31
24
|
// The page constructor
|
|
32
25
|
export interface PageConstructor {
|
|
33
|
-
<
|
|
34
|
-
TData
|
|
35
|
-
|
|
36
|
-
>(
|
|
37
|
-
definition: PageDefinition<
|
|
38
|
-
TData,
|
|
39
|
-
TNewExtraFields
|
|
40
|
-
> & ThisType<Component<TData, Empty, TNewExtraFields, undefined>>,
|
|
26
|
+
<TData extends DataList, TNewExtraFields extends { [k: PropertyKey]: any }>(
|
|
27
|
+
definition: PageDefinition<TData, TNewExtraFields> &
|
|
28
|
+
ThisType<Component<TData, Empty, TNewExtraFields, undefined>>,
|
|
41
29
|
): void
|
|
42
30
|
}
|
|
43
31
|
|
|
@@ -50,12 +38,8 @@ export interface ComponentConstructor {
|
|
|
50
38
|
TMethod extends MethodList,
|
|
51
39
|
TComponentExport,
|
|
52
40
|
>(
|
|
53
|
-
definition: ComponentDefinition<
|
|
54
|
-
TData,
|
|
55
|
-
TProperty,
|
|
56
|
-
TMethod,
|
|
57
|
-
TComponentExport
|
|
58
|
-
> & ThisType<Component<TData, TProperty, TMethod, TComponentExport>>,
|
|
41
|
+
definition: ComponentDefinition<TData, TProperty, TMethod, TComponentExport> &
|
|
42
|
+
ThisType<Component<TData, TProperty, TMethod, TComponentExport>>,
|
|
59
43
|
): void
|
|
60
44
|
}
|
|
61
45
|
|
|
@@ -69,24 +53,19 @@ export interface BehaviorConstructor {
|
|
|
69
53
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
54
|
TComponentExport,
|
|
71
55
|
>(
|
|
72
|
-
definition: BehaviorDefinition<
|
|
73
|
-
TData,
|
|
74
|
-
TProperty,
|
|
75
|
-
TMethod
|
|
76
|
-
>,
|
|
56
|
+
definition: BehaviorDefinition<TData, TProperty, TMethod>,
|
|
77
57
|
): Behavior<TData, TProperty, TMethod, never>
|
|
78
58
|
trait<TIn extends { [key: string]: any }>(): TraitBehavior<TIn, TIn>
|
|
79
|
-
trait<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
>(trans: (impl: TIn) => TOut): TraitBehavior<TIn, TOut>
|
|
59
|
+
trait<TIn extends { [key: string]: any }, TOut extends { [key: string]: any }>(
|
|
60
|
+
trans: (impl: TIn) => TOut,
|
|
61
|
+
): TraitBehavior<TIn, TOut>
|
|
83
62
|
}
|
|
84
63
|
|
|
85
64
|
/* The component registration environment */
|
|
86
65
|
export interface ComponentEnv {
|
|
87
|
-
Page: PageConstructor
|
|
88
|
-
Component: ComponentConstructor
|
|
89
|
-
Behavior: BehaviorConstructor
|
|
66
|
+
Page: PageConstructor
|
|
67
|
+
Component: ComponentConstructor
|
|
68
|
+
Behavior: BehaviorConstructor
|
|
90
69
|
}
|
|
91
70
|
|
|
92
71
|
type Empty = typeUtils.Empty
|
|
@@ -100,76 +79,67 @@ type ComponentMethod = typeUtils.ComponentMethod
|
|
|
100
79
|
type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
101
80
|
type ChainingFilterFunc<
|
|
102
81
|
TAddedFields extends { [key: string]: any },
|
|
103
|
-
TRemovedFields extends string = never
|
|
82
|
+
TRemovedFields extends string = never,
|
|
104
83
|
> = typeUtils.ChainingFilterFunc<TAddedFields, TRemovedFields>
|
|
105
84
|
|
|
106
85
|
export interface RelationHandler<TTarget, TOut> {
|
|
107
86
|
list(): TTarget[]
|
|
108
|
-
listAsTrait: TOut extends never
|
|
109
|
-
? undefined
|
|
110
|
-
: () => TOut[]
|
|
87
|
+
listAsTrait: TOut extends never ? undefined : () => TOut[]
|
|
111
88
|
}
|
|
112
89
|
|
|
113
90
|
export type TraitRelationParams<TOut extends { [key: string]: any }> = {
|
|
114
|
-
target: TraitBehavior<any, TOut
|
|
115
|
-
type:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
| 'parent-common-node'
|
|
121
|
-
| 'child-common-node';
|
|
122
|
-
linked?: (target: GeneralComponent) => void;
|
|
123
|
-
linkChanged?: (target: GeneralComponent) => void;
|
|
124
|
-
unlinked?: (target: GeneralComponent) => void;
|
|
125
|
-
linkFailed?: (target: GeneralComponent) => void;
|
|
91
|
+
target: TraitBehavior<any, TOut>
|
|
92
|
+
type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node'
|
|
93
|
+
linked?: (target: GeneralComponent) => void
|
|
94
|
+
linkChanged?: (target: GeneralComponent) => void
|
|
95
|
+
unlinked?: (target: GeneralComponent) => void
|
|
96
|
+
linkFailed?: (target: GeneralComponent) => void
|
|
126
97
|
}
|
|
127
98
|
|
|
128
99
|
export type RelationParams = {
|
|
129
|
-
target?: string | ComponentType<any, any, any, any> | GeneralBehavior | TraitBehavior<any
|
|
130
|
-
type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node'
|
|
131
|
-
linked?: (target: GeneralComponent) => void
|
|
132
|
-
linkChanged?: (target: GeneralComponent) => void
|
|
133
|
-
unlinked?: (target: GeneralComponent) => void
|
|
134
|
-
linkFailed?: (target: GeneralComponent) => void
|
|
100
|
+
target?: string | ComponentType<any, any, any, any> | GeneralBehavior | TraitBehavior<any>
|
|
101
|
+
type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node'
|
|
102
|
+
linked?: (target: GeneralComponent) => void
|
|
103
|
+
linkChanged?: (target: GeneralComponent) => void
|
|
104
|
+
unlinked?: (target: GeneralComponent) => void
|
|
105
|
+
linkFailed?: (target: GeneralComponent) => void
|
|
135
106
|
}
|
|
136
107
|
|
|
137
108
|
export type Lifetimes = {
|
|
138
|
-
created: () => void
|
|
139
|
-
attached: () => void
|
|
140
|
-
moved: () => void
|
|
141
|
-
detached: () => void
|
|
142
|
-
ready: () => void
|
|
109
|
+
created: () => void
|
|
110
|
+
attached: () => void
|
|
111
|
+
moved: () => void
|
|
112
|
+
detached: () => void
|
|
113
|
+
ready: () => void
|
|
143
114
|
}
|
|
144
115
|
|
|
145
116
|
export interface BuilderContext<
|
|
146
117
|
TPrevData extends DataList,
|
|
147
118
|
TProperty extends PropertyList,
|
|
148
|
-
TMethodCaller
|
|
119
|
+
TMethodCaller,
|
|
149
120
|
> extends ThisType<TMethodCaller> {
|
|
150
|
-
self: TMethodCaller
|
|
151
|
-
data: typeUtils.DeepReadonly<typeUtils.DataWithPropertyValues<TPrevData, TProperty
|
|
152
|
-
setData: (
|
|
153
|
-
newData: Partial<typeUtils.SetDataSetter<TPrevData>>, callback?: () => void,
|
|
154
|
-
) => void;
|
|
121
|
+
self: TMethodCaller
|
|
122
|
+
data: typeUtils.DeepReadonly<typeUtils.DataWithPropertyValues<TPrevData, TProperty>>
|
|
123
|
+
setData: (newData: Partial<typeUtils.SetDataSetter<TPrevData>>, callback?: () => void) => void
|
|
155
124
|
implement: <TIn extends { [x: string]: any }>(
|
|
156
125
|
traitBehavior: TraitBehavior<TIn, any>,
|
|
157
|
-
impl: TIn
|
|
158
|
-
) => void
|
|
159
|
-
relation<TOut extends { [key: string]: any }>
|
|
160
|
-
|
|
126
|
+
impl: TIn,
|
|
127
|
+
) => void
|
|
128
|
+
relation<TOut extends { [key: string]: any }>(
|
|
129
|
+
def: TraitRelationParams<TOut> & ThisType<TMethodCaller>,
|
|
130
|
+
): RelationHandler<any, TOut>
|
|
161
131
|
relation(def: RelationParams & ThisType<TMethodCaller>): RelationHandler<any, never>
|
|
162
132
|
observer<
|
|
163
133
|
P extends typeUtils.ObserverDataPathStrings<
|
|
164
134
|
typeUtils.DataWithPropertyValues<TPrevData, TProperty>
|
|
165
135
|
>,
|
|
166
136
|
V = typeUtils.DeepReadonly<
|
|
167
|
-
|
|
168
|
-
|
|
137
|
+
typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P>
|
|
138
|
+
>,
|
|
169
139
|
>(
|
|
170
140
|
paths: P,
|
|
171
141
|
func: (newValue: V) => void,
|
|
172
|
-
): void
|
|
142
|
+
): void
|
|
173
143
|
observer<
|
|
174
144
|
P extends typeUtils.ObserverDataPathStrings<
|
|
175
145
|
typeUtils.DataWithPropertyValues<TPrevData, TProperty>
|
|
@@ -181,14 +151,14 @@ export interface BuilderContext<
|
|
|
181
151
|
P[K]
|
|
182
152
|
>
|
|
183
153
|
>
|
|
184
|
-
}
|
|
154
|
+
},
|
|
185
155
|
>(
|
|
186
156
|
paths: readonly [...P],
|
|
187
157
|
func: (...newValues: V extends any[] ? V : never) => void,
|
|
188
|
-
): void
|
|
189
|
-
lifetime: <L extends keyof Lifetimes>(name: L, func: Lifetimes[L]) => void
|
|
190
|
-
pageLifetime: (name: string, func: (...args: any[]) => void) => void
|
|
191
|
-
method: <Fn extends ComponentMethod>(func: Fn) => TaggedMethod<Fn
|
|
158
|
+
): void
|
|
159
|
+
lifetime: <L extends keyof Lifetimes>(name: L, func: Lifetimes[L]) => void
|
|
160
|
+
pageLifetime: (name: string, func: (...args: any[]) => void) => void
|
|
161
|
+
method: <Fn extends ComponentMethod>(func: Fn) => TaggedMethod<Fn>
|
|
192
162
|
}
|
|
193
163
|
|
|
194
164
|
/**
|
|
@@ -201,7 +171,7 @@ export class CodeSpace {
|
|
|
201
171
|
private space: glassEasel.ComponentSpace
|
|
202
172
|
private styleScopeManager: glassEasel.StyleScopeManager
|
|
203
173
|
private staticConfigMap: { [path: string]: ComponentStaticConfig }
|
|
204
|
-
private styleSheetMap: { [path: string]: { url: string
|
|
174
|
+
private styleSheetMap: { [path: string]: { url: string; styleScopeName: string | undefined } }
|
|
205
175
|
private compiledTemplateMap: { [path: string]: glassEasel.template.ComponentTemplate }
|
|
206
176
|
private waitingAliasMap: { [is: string]: string[] }
|
|
207
177
|
/** @internal */
|
|
@@ -227,10 +197,12 @@ export class CodeSpace {
|
|
|
227
197
|
)
|
|
228
198
|
this.styleScopeManager = this.space.styleScopeManager
|
|
229
199
|
this.staticConfigMap = Object.create(null) as { [path: string]: ComponentStaticConfig }
|
|
230
|
-
this.styleSheetMap = Object.create(null) as
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
200
|
+
this.styleSheetMap = Object.create(null) as {
|
|
201
|
+
[path: string]: { url: string; styleScopeName: string }
|
|
202
|
+
}
|
|
203
|
+
this.compiledTemplateMap = Object.create(null) as {
|
|
204
|
+
[path: string]: glassEasel.template.ComponentTemplate
|
|
205
|
+
}
|
|
234
206
|
this.waitingAliasMap = Object.create(null) as { [path: string]: string[] }
|
|
235
207
|
Object.keys(publicComponents).forEach((alias) => {
|
|
236
208
|
const is = publicComponents[alias]!
|
|
@@ -365,14 +337,14 @@ export class CodeSpace {
|
|
|
365
337
|
let styleScope: glassEasel.StyleScopeId | undefined
|
|
366
338
|
let extraStyleScope: glassEasel.StyleScopeId | undefined
|
|
367
339
|
if (
|
|
368
|
-
styleIsolation === StyleIsolation.ApplyShared
|
|
369
|
-
|
|
340
|
+
styleIsolation === StyleIsolation.ApplyShared ||
|
|
341
|
+
styleIsolation === StyleIsolation.PageApplyShared
|
|
370
342
|
) {
|
|
371
343
|
styleScope = this.styleScopeManager.register(this.getStyleScopeName(is) || `__${guid()}`)
|
|
372
344
|
extraStyleScope = this._$sharedStyleScope
|
|
373
345
|
} else if (
|
|
374
|
-
(styleIsolation === StyleIsolation.Shared || styleIsolation === StyleIsolation.PageShared)
|
|
375
|
-
|
|
346
|
+
(styleIsolation === StyleIsolation.Shared || styleIsolation === StyleIsolation.PageShared) &&
|
|
347
|
+
this._$isMainSpace
|
|
376
348
|
) {
|
|
377
349
|
styleScope = this._$sharedStyleScope
|
|
378
350
|
} else {
|
|
@@ -437,10 +409,8 @@ export class CodeSpace {
|
|
|
437
409
|
TData extends DataList,
|
|
438
410
|
TNewExtraFields extends { [k: PropertyKey]: any },
|
|
439
411
|
>(
|
|
440
|
-
definition: PageDefinition<
|
|
441
|
-
TData,
|
|
442
|
-
TNewExtraFields
|
|
443
|
-
> & ThisType<Component<TData, Empty, TNewExtraFields, undefined>>,
|
|
412
|
+
definition: PageDefinition<TData, TNewExtraFields> &
|
|
413
|
+
ThisType<Component<TData, Empty, TNewExtraFields, undefined>>,
|
|
444
414
|
) {
|
|
445
415
|
return self.component(path).pageDefinition(definition).register()
|
|
446
416
|
}
|
|
@@ -452,27 +422,13 @@ export class CodeSpace {
|
|
|
452
422
|
TProperty extends PropertyList,
|
|
453
423
|
TMethod extends MethodList,
|
|
454
424
|
TComponentExport,
|
|
455
|
-
>(
|
|
456
|
-
definition: ComponentDefinition<
|
|
457
|
-
TData,
|
|
458
|
-
TProperty,
|
|
459
|
-
TMethod,
|
|
460
|
-
TComponentExport
|
|
461
|
-
>,
|
|
462
|
-
): void
|
|
425
|
+
>(definition: ComponentDefinition<TData, TProperty, TMethod, TComponentExport>): void
|
|
463
426
|
function componentConstructor<
|
|
464
427
|
TData extends DataList,
|
|
465
428
|
TProperty extends PropertyList,
|
|
466
429
|
TMethod extends MethodList,
|
|
467
430
|
TComponentExport,
|
|
468
|
-
>(
|
|
469
|
-
definition?: ComponentDefinition<
|
|
470
|
-
TData,
|
|
471
|
-
TProperty,
|
|
472
|
-
TMethod,
|
|
473
|
-
TComponentExport
|
|
474
|
-
>,
|
|
475
|
-
) {
|
|
431
|
+
>(definition?: ComponentDefinition<TData, TProperty, TMethod, TComponentExport>) {
|
|
476
432
|
if (definition !== undefined) {
|
|
477
433
|
return self.component(path).definition(definition).register()
|
|
478
434
|
}
|
|
@@ -488,11 +444,7 @@ export class CodeSpace {
|
|
|
488
444
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
489
445
|
TComponentExport,
|
|
490
446
|
>(
|
|
491
|
-
definition: BehaviorDefinition<
|
|
492
|
-
TData,
|
|
493
|
-
TProperty,
|
|
494
|
-
TMethod
|
|
495
|
-
>,
|
|
447
|
+
definition: BehaviorDefinition<TData, TProperty, TMethod>,
|
|
496
448
|
): Behavior<TData, TProperty, TMethod, never>
|
|
497
449
|
function behaviorConstructor<
|
|
498
450
|
TData extends DataList,
|
|
@@ -500,13 +452,7 @@ export class CodeSpace {
|
|
|
500
452
|
TMethod extends MethodList,
|
|
501
453
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
502
454
|
TComponentExport,
|
|
503
|
-
>(
|
|
504
|
-
definition?: BehaviorDefinition<
|
|
505
|
-
TData,
|
|
506
|
-
TProperty,
|
|
507
|
-
TMethod
|
|
508
|
-
>,
|
|
509
|
-
) {
|
|
455
|
+
>(definition?: BehaviorDefinition<TData, TProperty, TMethod>) {
|
|
510
456
|
if (definition !== undefined) {
|
|
511
457
|
return self.behavior().definition(definition).register()
|
|
512
458
|
}
|
|
@@ -546,14 +492,12 @@ export class CodeSpace {
|
|
|
546
492
|
* Define a trait behavior
|
|
547
493
|
*/
|
|
548
494
|
traitBehavior<TIn extends { [key: string]: any }>(): TraitBehavior<TIn, TIn>
|
|
549
|
-
traitBehavior<
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
TOut extends { [key: string]: any }
|
|
556
|
-
>(trans?: (impl: TIn) => TOut): TraitBehavior<TIn, TOut> {
|
|
495
|
+
traitBehavior<TIn extends { [key: string]: any }, TOut extends { [key: string]: any }>(
|
|
496
|
+
trans: (impl: TIn) => TOut,
|
|
497
|
+
): TraitBehavior<TIn, TOut>
|
|
498
|
+
traitBehavior<TIn extends { [key: string]: any }, TOut extends { [key: string]: any }>(
|
|
499
|
+
trans?: (impl: TIn) => TOut,
|
|
500
|
+
): TraitBehavior<TIn, TOut> {
|
|
557
501
|
if (trans === undefined) {
|
|
558
502
|
return new TraitBehavior(this.space.defineTraitBehavior<TIn>())
|
|
559
503
|
}
|
|
@@ -561,8 +505,10 @@ export class CodeSpace {
|
|
|
561
505
|
}
|
|
562
506
|
}
|
|
563
507
|
|
|
564
|
-
type ResolveBehaviorBuilder<
|
|
565
|
-
|
|
508
|
+
type ResolveBehaviorBuilder<
|
|
509
|
+
B,
|
|
510
|
+
TChainingFilter extends ChainingFilterType,
|
|
511
|
+
> = typeUtils.IsNever<TChainingFilter> extends false
|
|
566
512
|
? TChainingFilter extends ChainingFilterType
|
|
567
513
|
? Omit<B, TChainingFilter['remove']> & TChainingFilter['add']
|
|
568
514
|
: B
|
|
@@ -604,7 +550,7 @@ export class BaseBehaviorBuilder<
|
|
|
604
550
|
}
|
|
605
551
|
|
|
606
552
|
data<T extends DataList>(
|
|
607
|
-
gen: (
|
|
553
|
+
gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>,
|
|
608
554
|
): ResolveBehaviorBuilder<
|
|
609
555
|
BaseBehaviorBuilder<
|
|
610
556
|
T,
|
|
@@ -621,11 +567,7 @@ export class BaseBehaviorBuilder<
|
|
|
621
567
|
return this as any
|
|
622
568
|
}
|
|
623
569
|
|
|
624
|
-
property<
|
|
625
|
-
N extends string,
|
|
626
|
-
T extends PropertyType,
|
|
627
|
-
V extends PropertyTypeToValueType<T>,
|
|
628
|
-
>(
|
|
570
|
+
property<N extends string, T extends PropertyType, V extends PropertyTypeToValueType<T>>(
|
|
629
571
|
name: N,
|
|
630
572
|
def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>,
|
|
631
573
|
): ResolveBehaviorBuilder<
|
|
@@ -649,9 +591,7 @@ export class BaseBehaviorBuilder<
|
|
|
649
591
|
*
|
|
650
592
|
* The public method can be used as an event handler, and can be visited in component instance.
|
|
651
593
|
*/
|
|
652
|
-
methods<
|
|
653
|
-
T extends MethodList,
|
|
654
|
-
>(
|
|
594
|
+
methods<T extends MethodList>(
|
|
655
595
|
funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>,
|
|
656
596
|
): ResolveBehaviorBuilder<
|
|
657
597
|
BaseBehaviorBuilder<
|
|
@@ -678,12 +618,12 @@ export class BaseBehaviorBuilder<
|
|
|
678
618
|
>,
|
|
679
619
|
V = typeUtils.DeepReadonly<
|
|
680
620
|
typeUtils.GetFromObserverPathString<typeUtils.DataWithPropertyValues<TPrevData, TProperty>, P>
|
|
681
|
-
|
|
621
|
+
>,
|
|
682
622
|
>(
|
|
683
623
|
paths: P,
|
|
684
624
|
func: (this: Component<TData, TProperty, TMethod, any>, newValue: V) => void,
|
|
685
625
|
once?: boolean,
|
|
686
|
-
): ResolveBehaviorBuilder<this, TChainingFilter
|
|
626
|
+
): ResolveBehaviorBuilder<this, TChainingFilter>
|
|
687
627
|
observer<
|
|
688
628
|
P extends typeUtils.ObserverDataPathStrings<
|
|
689
629
|
typeUtils.DataWithPropertyValues<TPrevData, TProperty>
|
|
@@ -695,7 +635,7 @@ export class BaseBehaviorBuilder<
|
|
|
695
635
|
P[K]
|
|
696
636
|
>
|
|
697
637
|
>
|
|
698
|
-
}
|
|
638
|
+
},
|
|
699
639
|
>(
|
|
700
640
|
paths: readonly [...P],
|
|
701
641
|
func: (
|
|
@@ -703,7 +643,7 @@ export class BaseBehaviorBuilder<
|
|
|
703
643
|
...newValues: V extends any[] ? V : never
|
|
704
644
|
) => void,
|
|
705
645
|
once?: boolean,
|
|
706
|
-
): ResolveBehaviorBuilder<this, TChainingFilter
|
|
646
|
+
): ResolveBehaviorBuilder<this, TChainingFilter>
|
|
707
647
|
observer(
|
|
708
648
|
paths: string | readonly string[],
|
|
709
649
|
func: (this: Component<TData, TProperty, TMethod, any>, ...args: any[]) => any,
|
|
@@ -747,9 +687,10 @@ export class BaseBehaviorBuilder<
|
|
|
747
687
|
name: string,
|
|
748
688
|
rel: RelationParams & ThisType<Component<TData, TProperty, TMethod, TComponentExport>>,
|
|
749
689
|
): ResolveBehaviorBuilder<this, TChainingFilter> {
|
|
750
|
-
const target =
|
|
751
|
-
|
|
752
|
-
|
|
690
|
+
const target =
|
|
691
|
+
rel.target instanceof Behavior || rel.target instanceof ComponentType
|
|
692
|
+
? rel.target._$
|
|
693
|
+
: rel.target
|
|
753
694
|
this._$.relation(name, {
|
|
754
695
|
target,
|
|
755
696
|
type: rel.type,
|
|
@@ -770,7 +711,7 @@ export class BaseBehaviorBuilder<
|
|
|
770
711
|
Component<TData, TProperty, TMethod, TComponentExport>
|
|
771
712
|
>,
|
|
772
713
|
) => TExport,
|
|
773
|
-
|
|
714
|
+
// eslint-disable-next-line function-paren-newline
|
|
774
715
|
): ResolveBehaviorBuilder<
|
|
775
716
|
BaseBehaviorBuilder<
|
|
776
717
|
TPrevData,
|
|
@@ -804,9 +745,10 @@ export class BaseBehaviorBuilder<
|
|
|
804
745
|
linkFailed: rel.linkFailed,
|
|
805
746
|
} as any)
|
|
806
747
|
}
|
|
807
|
-
const target =
|
|
808
|
-
|
|
809
|
-
|
|
748
|
+
const target =
|
|
749
|
+
rel.target instanceof Behavior || rel.target instanceof ComponentType
|
|
750
|
+
? rel.target._$
|
|
751
|
+
: rel.target
|
|
810
752
|
return relation({
|
|
811
753
|
target,
|
|
812
754
|
type: rel.type,
|
|
@@ -850,18 +792,15 @@ export class BaseBehaviorBuilder<
|
|
|
850
792
|
TNewProperty extends PropertyList = Empty,
|
|
851
793
|
TNewMethod extends MethodList = Empty,
|
|
852
794
|
>(
|
|
853
|
-
def: BehaviorDefinition<
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
TComponentExport
|
|
863
|
-
>
|
|
864
|
-
>,
|
|
795
|
+
def: BehaviorDefinition<TNewData, TNewProperty, TNewMethod> &
|
|
796
|
+
ThisType<
|
|
797
|
+
Component<
|
|
798
|
+
TData & TNewData,
|
|
799
|
+
TProperty & TNewProperty,
|
|
800
|
+
TMethod & TNewMethod,
|
|
801
|
+
TComponentExport
|
|
802
|
+
>
|
|
803
|
+
>,
|
|
865
804
|
): ResolveBehaviorBuilder<
|
|
866
805
|
BaseBehaviorBuilder<
|
|
867
806
|
TPrevData,
|
|
@@ -907,14 +846,15 @@ export class BaseBehaviorBuilder<
|
|
|
907
846
|
const keys = Object.keys(rawProperties)
|
|
908
847
|
for (let i = 0; i < keys.length; i += 1) {
|
|
909
848
|
const name = keys[i]!
|
|
910
|
-
|
|
849
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
850
|
+
inner.property(name, rawProperties[name] as any)
|
|
911
851
|
}
|
|
912
852
|
}
|
|
913
853
|
if (rawObservers !== undefined) {
|
|
914
854
|
if (Array.isArray(rawObservers)) {
|
|
915
855
|
for (let i = 0; i < rawObservers.length; i += 1) {
|
|
916
856
|
const { fields, observer } = rawObservers[i]!
|
|
917
|
-
inner.observer(fields || '**' as any, observer)
|
|
857
|
+
inner.observer(fields || ('**' as any), observer)
|
|
918
858
|
}
|
|
919
859
|
} else {
|
|
920
860
|
const keys = Object.keys(rawObservers)
|
|
@@ -983,8 +923,7 @@ export class BehaviorBuilder<
|
|
|
983
923
|
static create(codeSpace: CodeSpace): BehaviorBuilder {
|
|
984
924
|
const ret = new BehaviorBuilder()
|
|
985
925
|
ret._$codeSpace = codeSpace
|
|
986
|
-
ret._$ = codeSpace.getComponentSpace()
|
|
987
|
-
.defineWithMethodCaller()
|
|
926
|
+
ret._$ = codeSpace.getComponentSpace().defineWithMethodCaller()
|
|
988
927
|
return ret
|
|
989
928
|
}
|
|
990
929
|
|
|
@@ -995,10 +934,18 @@ export class BehaviorBuilder<
|
|
|
995
934
|
>(
|
|
996
935
|
func: ChainingFilterFunc<TAddedFields, TRemovedFields>,
|
|
997
936
|
): ResolveBehaviorBuilder<
|
|
998
|
-
BehaviorBuilder<
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
937
|
+
BehaviorBuilder<
|
|
938
|
+
TPrevData,
|
|
939
|
+
TData,
|
|
940
|
+
TProperty,
|
|
941
|
+
TMethod,
|
|
942
|
+
TChainingFilter,
|
|
943
|
+
{
|
|
944
|
+
add: TAddedFields
|
|
945
|
+
remove: TRemovedFields
|
|
946
|
+
},
|
|
947
|
+
TComponentExport
|
|
948
|
+
>,
|
|
1002
949
|
TChainingFilter
|
|
1003
950
|
> {
|
|
1004
951
|
this._$.chainingFilter(func as any)
|
|
@@ -1038,7 +985,7 @@ export class BehaviorBuilder<
|
|
|
1038
985
|
* The `gen` function executes once during component creation.
|
|
1039
986
|
*/
|
|
1040
987
|
override data<T extends DataList>(
|
|
1041
|
-
gen: (
|
|
988
|
+
gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>,
|
|
1042
989
|
): ResolveBehaviorBuilder<
|
|
1043
990
|
BehaviorBuilder<
|
|
1044
991
|
T,
|
|
@@ -1059,11 +1006,7 @@ export class BehaviorBuilder<
|
|
|
1059
1006
|
*
|
|
1060
1007
|
* The property name should be different from other properties.
|
|
1061
1008
|
*/
|
|
1062
|
-
override property<
|
|
1063
|
-
N extends string,
|
|
1064
|
-
T extends PropertyType,
|
|
1065
|
-
V extends PropertyTypeToValueType<T>,
|
|
1066
|
-
>(
|
|
1009
|
+
override property<N extends string, T extends PropertyType, V extends PropertyTypeToValueType<T>>(
|
|
1067
1010
|
name: N,
|
|
1068
1011
|
def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>,
|
|
1069
1012
|
): ResolveBehaviorBuilder<
|
|
@@ -1086,9 +1029,7 @@ export class BehaviorBuilder<
|
|
|
1086
1029
|
*
|
|
1087
1030
|
* The public method can be used as an event handler, and can be visited in component instance.
|
|
1088
1031
|
*/
|
|
1089
|
-
override methods<
|
|
1090
|
-
T extends MethodList,
|
|
1091
|
-
>(
|
|
1032
|
+
override methods<T extends MethodList>(
|
|
1092
1033
|
funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>,
|
|
1093
1034
|
): ResolveBehaviorBuilder<
|
|
1094
1035
|
BehaviorBuilder<
|
|
@@ -1121,7 +1062,7 @@ export class BehaviorBuilder<
|
|
|
1121
1062
|
Component<TData, TProperty, TMethod, TComponentExport>
|
|
1122
1063
|
>,
|
|
1123
1064
|
) => TExport,
|
|
1124
|
-
|
|
1065
|
+
// eslint-disable-next-line function-paren-newline
|
|
1125
1066
|
): ResolveBehaviorBuilder<
|
|
1126
1067
|
BehaviorBuilder<
|
|
1127
1068
|
TPrevData,
|
|
@@ -1143,18 +1084,15 @@ export class BehaviorBuilder<
|
|
|
1143
1084
|
TNewProperty extends PropertyList = Empty,
|
|
1144
1085
|
TNewMethod extends MethodList = Empty,
|
|
1145
1086
|
>(
|
|
1146
|
-
def: BehaviorDefinition<
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
TComponentExport
|
|
1156
|
-
>
|
|
1157
|
-
>,
|
|
1087
|
+
def: BehaviorDefinition<TNewData, TNewProperty, TNewMethod> &
|
|
1088
|
+
ThisType<
|
|
1089
|
+
Component<
|
|
1090
|
+
TData & TNewData,
|
|
1091
|
+
TProperty & TNewProperty,
|
|
1092
|
+
TMethod & TNewMethod,
|
|
1093
|
+
TComponentExport
|
|
1094
|
+
>
|
|
1095
|
+
>,
|
|
1158
1096
|
): ResolveBehaviorBuilder<
|
|
1159
1097
|
BehaviorBuilder<
|
|
1160
1098
|
TPrevData,
|
|
@@ -1176,11 +1114,7 @@ export class BehaviorBuilder<
|
|
|
1176
1114
|
* Finish the behavior definition process
|
|
1177
1115
|
*/
|
|
1178
1116
|
register(): Behavior<TData, TProperty, TMethod, TPendingChainingFilter> {
|
|
1179
|
-
return new Behavior(
|
|
1180
|
-
this._$.registerBehavior(),
|
|
1181
|
-
this._$parents,
|
|
1182
|
-
this._$definitionFilter,
|
|
1183
|
-
)
|
|
1117
|
+
return new Behavior(this._$.registerBehavior(), this._$parents, this._$definitionFilter)
|
|
1184
1118
|
}
|
|
1185
1119
|
}
|
|
1186
1120
|
|
|
@@ -1215,8 +1149,7 @@ export class ComponentBuilder<
|
|
|
1215
1149
|
const ret = new ComponentBuilder()
|
|
1216
1150
|
const overallBehavior = codeSpace._$overallBehavior
|
|
1217
1151
|
ret._$codeSpace = codeSpace
|
|
1218
|
-
ret._$ = codeSpace.getComponentSpace()
|
|
1219
|
-
.defineWithMethodCaller(is || '')
|
|
1152
|
+
ret._$ = codeSpace.getComponentSpace().defineWithMethodCaller(is || '')
|
|
1220
1153
|
ret._$is = is || ''
|
|
1221
1154
|
ret._$alias = alias
|
|
1222
1155
|
ret._$.methodCallerInit(function () {
|
|
@@ -1242,9 +1175,7 @@ export class ComponentBuilder<
|
|
|
1242
1175
|
*
|
|
1243
1176
|
* If called multiple times, only the latest call is valid.
|
|
1244
1177
|
*/
|
|
1245
|
-
options(
|
|
1246
|
-
options: ComponentDefinitionOptions,
|
|
1247
|
-
): ResolveBehaviorBuilder<this, TChainingFilter> {
|
|
1178
|
+
options(options: ComponentDefinitionOptions): ResolveBehaviorBuilder<this, TChainingFilter> {
|
|
1248
1179
|
this._$options = options
|
|
1249
1180
|
return this as any
|
|
1250
1181
|
}
|
|
@@ -1305,7 +1236,7 @@ export class ComponentBuilder<
|
|
|
1305
1236
|
* The `gen` function executes once during component creation.
|
|
1306
1237
|
*/
|
|
1307
1238
|
override data<T extends DataList>(
|
|
1308
|
-
gen: (
|
|
1239
|
+
gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>,
|
|
1309
1240
|
): ResolveBehaviorBuilder<
|
|
1310
1241
|
ComponentBuilder<
|
|
1311
1242
|
T,
|
|
@@ -1326,11 +1257,7 @@ export class ComponentBuilder<
|
|
|
1326
1257
|
*
|
|
1327
1258
|
* The property name should be different from other properties.
|
|
1328
1259
|
*/
|
|
1329
|
-
override property<
|
|
1330
|
-
N extends string,
|
|
1331
|
-
T extends PropertyType,
|
|
1332
|
-
V extends PropertyTypeToValueType<T>,
|
|
1333
|
-
>(
|
|
1260
|
+
override property<N extends string, T extends PropertyType, V extends PropertyTypeToValueType<T>>(
|
|
1334
1261
|
name: N,
|
|
1335
1262
|
def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>,
|
|
1336
1263
|
): ResolveBehaviorBuilder<
|
|
@@ -1353,9 +1280,7 @@ export class ComponentBuilder<
|
|
|
1353
1280
|
*
|
|
1354
1281
|
* The public method can be used as an event handler, and can be visited in component instance.
|
|
1355
1282
|
*/
|
|
1356
|
-
override methods<
|
|
1357
|
-
T extends MethodList,
|
|
1358
|
-
>(
|
|
1283
|
+
override methods<T extends MethodList>(
|
|
1359
1284
|
funcs: T & ThisType<Component<TData, TProperty, TMethod & T, any>>,
|
|
1360
1285
|
): ResolveBehaviorBuilder<
|
|
1361
1286
|
ComponentBuilder<
|
|
@@ -1388,7 +1313,7 @@ export class ComponentBuilder<
|
|
|
1388
1313
|
Component<TData, TProperty, TMethod, TComponentExport>
|
|
1389
1314
|
>,
|
|
1390
1315
|
) => TExport,
|
|
1391
|
-
|
|
1316
|
+
// eslint-disable-next-line function-paren-newline
|
|
1392
1317
|
): ResolveBehaviorBuilder<
|
|
1393
1318
|
ComponentBuilder<
|
|
1394
1319
|
TPrevData,
|
|
@@ -1411,19 +1336,15 @@ export class ComponentBuilder<
|
|
|
1411
1336
|
TNewMethod extends MethodList = Empty,
|
|
1412
1337
|
TNewComponentExport = undefined,
|
|
1413
1338
|
>(
|
|
1414
|
-
def: ComponentDefinition<
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
TMethod & TNewMethod,
|
|
1424
|
-
TNewComponentExport
|
|
1425
|
-
>
|
|
1426
|
-
>,
|
|
1339
|
+
def: ComponentDefinition<TNewData, TNewProperty, TNewMethod, TNewComponentExport> &
|
|
1340
|
+
ThisType<
|
|
1341
|
+
Component<
|
|
1342
|
+
TData & TNewData,
|
|
1343
|
+
TProperty & TNewProperty,
|
|
1344
|
+
TMethod & TNewMethod,
|
|
1345
|
+
TNewComponentExport
|
|
1346
|
+
>
|
|
1347
|
+
>,
|
|
1427
1348
|
): ResolveBehaviorBuilder<
|
|
1428
1349
|
ComponentBuilder<
|
|
1429
1350
|
TPrevData,
|
|
@@ -1441,14 +1362,9 @@ export class ComponentBuilder<
|
|
|
1441
1362
|
return this as any
|
|
1442
1363
|
}
|
|
1443
1364
|
|
|
1444
|
-
pageDefinition<
|
|
1445
|
-
TNewData
|
|
1446
|
-
|
|
1447
|
-
>(
|
|
1448
|
-
def: PageDefinition<
|
|
1449
|
-
TNewData,
|
|
1450
|
-
TNewExtraFields
|
|
1451
|
-
> & ThisType<Component<TData & TNewData, TProperty, TMethod & TNewExtraFields, undefined>>,
|
|
1365
|
+
pageDefinition<TNewData extends DataList, TNewExtraFields extends { [k: PropertyKey]: any }>(
|
|
1366
|
+
def: PageDefinition<TNewData, TNewExtraFields> &
|
|
1367
|
+
ThisType<Component<TData & TNewData, TProperty, TMethod & TNewExtraFields, undefined>>,
|
|
1452
1368
|
): ResolveBehaviorBuilder<
|
|
1453
1369
|
ComponentBuilder<
|
|
1454
1370
|
TPrevData,
|
|
@@ -1471,9 +1387,9 @@ export class ComponentBuilder<
|
|
|
1471
1387
|
if (k === 'data' || k === 'options' || k === 'behaviors') {
|
|
1472
1388
|
compDef[k] = def[k]
|
|
1473
1389
|
} else if (typeof def[k] === 'function') {
|
|
1474
|
-
(compDef.methods as { [k: string]: unknown })[k] = def[k] as unknown
|
|
1390
|
+
;(compDef.methods as { [k: string]: unknown })[k] = def[k] as unknown
|
|
1475
1391
|
} else {
|
|
1476
|
-
(freeData as { [k: string]: unknown })[k] = def[k]
|
|
1392
|
+
;(freeData as { [k: string]: unknown })[k] = def[k]
|
|
1477
1393
|
}
|
|
1478
1394
|
}
|
|
1479
1395
|
this.definition(compDef)
|
|
@@ -1495,8 +1411,8 @@ export class ComponentBuilder<
|
|
|
1495
1411
|
this._$.options(options)
|
|
1496
1412
|
const staticConfig = codeSpace.getComponentStaticConfig(is)
|
|
1497
1413
|
const using = staticConfig?.usingComponents
|
|
1498
|
-
const generics = staticConfig?.
|
|
1499
|
-
const placeholder = staticConfig?.
|
|
1414
|
+
const generics = staticConfig?.componentGenerics
|
|
1415
|
+
const placeholder = staticConfig?.componentPlaceholder
|
|
1500
1416
|
if (using) this._$.usingComponents(using)
|
|
1501
1417
|
if (generics) this._$.generics(generics)
|
|
1502
1418
|
if (placeholder) this._$.placeholders(placeholder)
|