glass-easel-miniprogram-adapter 0.12.0 → 0.13.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.d.ts +116 -108
- package/dist/glass_easel_miniprogram_adapter.es.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.es.js.map +1 -1
- package/dist/glass_easel_miniprogram_adapter.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior.ts +23 -13
- package/src/builder/base_behavior_builder.ts +69 -23
- package/src/builder/behavior_builder.ts +34 -21
- package/src/builder/component_builder.ts +28 -29
- package/src/builder/index.ts +2 -0
- package/src/builder/type_utils.ts +2 -2
- package/src/component.ts +74 -28
- package/src/space.ts +77 -15
- package/src/types.ts +4 -3
- package/tests/env.test.ts +8 -1
- package/tests/selector.test.ts +64 -1
- package/tests/space.test.ts +59 -7
|
@@ -26,14 +26,14 @@ type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
|
26
26
|
type UnTaggedMethod<M extends TaggedMethod<any>> = typeUtils.UnTaggedMethod<M>
|
|
27
27
|
|
|
28
28
|
export class BaseBehaviorBuilder<
|
|
29
|
-
TPrevData extends DataList
|
|
30
|
-
TData extends DataList
|
|
31
|
-
TProperty extends PropertyList
|
|
32
|
-
TMethod extends MethodList
|
|
33
|
-
TChainingFilter extends ChainingFilterType
|
|
34
|
-
TPendingChainingFilter extends ChainingFilterType
|
|
35
|
-
TComponentExport
|
|
36
|
-
TExtraThisFields extends DataList
|
|
29
|
+
TPrevData extends DataList,
|
|
30
|
+
TData extends DataList,
|
|
31
|
+
TProperty extends PropertyList,
|
|
32
|
+
TMethod extends MethodList,
|
|
33
|
+
TChainingFilter extends ChainingFilterType,
|
|
34
|
+
TPendingChainingFilter extends ChainingFilterType,
|
|
35
|
+
TComponentExport,
|
|
36
|
+
TExtraThisFields extends DataList,
|
|
37
37
|
> {
|
|
38
38
|
protected _$codeSpace!: CodeSpace
|
|
39
39
|
protected _$!: glassEasel.BehaviorBuilder<
|
|
@@ -83,6 +83,45 @@ export class BaseBehaviorBuilder<
|
|
|
83
83
|
return this as any
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Use another behavior */
|
|
87
|
+
behavior<
|
|
88
|
+
UData extends DataList,
|
|
89
|
+
UProperty extends PropertyList,
|
|
90
|
+
UMethod extends MethodList,
|
|
91
|
+
UChainingFilter extends ChainingFilterType,
|
|
92
|
+
UComponentExport,
|
|
93
|
+
UExtraThisFields extends DataList,
|
|
94
|
+
>(
|
|
95
|
+
behavior: Behavior<
|
|
96
|
+
UData,
|
|
97
|
+
UProperty,
|
|
98
|
+
UMethod,
|
|
99
|
+
UChainingFilter,
|
|
100
|
+
UComponentExport,
|
|
101
|
+
UExtraThisFields
|
|
102
|
+
>,
|
|
103
|
+
): ResolveBehaviorBuilder<
|
|
104
|
+
BaseBehaviorBuilder<
|
|
105
|
+
TPrevData,
|
|
106
|
+
TData & UData,
|
|
107
|
+
TProperty & UProperty,
|
|
108
|
+
TMethod & UMethod,
|
|
109
|
+
UChainingFilter,
|
|
110
|
+
TPendingChainingFilter,
|
|
111
|
+
UComponentExport,
|
|
112
|
+
TExtraThisFields & UExtraThisFields
|
|
113
|
+
>,
|
|
114
|
+
UChainingFilter
|
|
115
|
+
> {
|
|
116
|
+
this._$parents.push(behavior)
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
118
|
+
this._$ = this._$.behavior(behavior._$)
|
|
119
|
+
if (behavior._$chainingFilter) {
|
|
120
|
+
return behavior._$chainingFilter(this as any)
|
|
121
|
+
}
|
|
122
|
+
return this as any
|
|
123
|
+
}
|
|
124
|
+
|
|
86
125
|
data<T extends DataList>(
|
|
87
126
|
gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>,
|
|
88
127
|
): ResolveBehaviorBuilder<
|
|
@@ -250,7 +289,9 @@ export class BaseBehaviorBuilder<
|
|
|
250
289
|
ThisType<Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>>,
|
|
251
290
|
): ResolveBehaviorBuilder<this, TChainingFilter> {
|
|
252
291
|
const target =
|
|
253
|
-
rel.target instanceof Behavior ||
|
|
292
|
+
rel.target instanceof Behavior ||
|
|
293
|
+
rel.target instanceof ComponentType ||
|
|
294
|
+
rel.target instanceof TraitBehavior
|
|
254
295
|
? rel.target._$
|
|
255
296
|
: rel.target
|
|
256
297
|
this._$.relation(name, {
|
|
@@ -304,18 +345,10 @@ export class BaseBehaviorBuilder<
|
|
|
304
345
|
listener,
|
|
305
346
|
}) {
|
|
306
347
|
const relationInit = ((rel: RelationParams | TraitRelationParams<any>) => {
|
|
307
|
-
if (rel.target instanceof TraitBehavior) {
|
|
308
|
-
return relation({
|
|
309
|
-
target: rel.target._$,
|
|
310
|
-
type: rel.type,
|
|
311
|
-
linked: rel.linked,
|
|
312
|
-
linkChanged: rel.linkChanged,
|
|
313
|
-
unlinked: rel.unlinked,
|
|
314
|
-
linkFailed: rel.linkFailed,
|
|
315
|
-
} as any)
|
|
316
|
-
}
|
|
317
348
|
const target =
|
|
318
|
-
rel.target instanceof Behavior ||
|
|
349
|
+
rel.target instanceof Behavior ||
|
|
350
|
+
rel.target instanceof ComponentType ||
|
|
351
|
+
rel.target instanceof TraitBehavior
|
|
319
352
|
? rel.target._$
|
|
320
353
|
: rel.target
|
|
321
354
|
return relation({
|
|
@@ -404,7 +437,7 @@ export class BaseBehaviorBuilder<
|
|
|
404
437
|
>,
|
|
405
438
|
TChainingFilter
|
|
406
439
|
> {
|
|
407
|
-
def.behaviors?.forEach((beh) => beh._$
|
|
440
|
+
def.behaviors?.forEach((beh) => beh._$boundDefinitionFilter?.(def))
|
|
408
441
|
const inner = this._$
|
|
409
442
|
const {
|
|
410
443
|
behaviors,
|
|
@@ -424,7 +457,7 @@ export class BaseBehaviorBuilder<
|
|
|
424
457
|
export: exports,
|
|
425
458
|
} = def
|
|
426
459
|
behaviors?.forEach((beh) => {
|
|
427
|
-
this._$parents.push(beh
|
|
460
|
+
this._$parents.push(beh)
|
|
428
461
|
inner.behavior(beh._$)
|
|
429
462
|
})
|
|
430
463
|
if (rawData !== undefined) {
|
|
@@ -484,7 +517,20 @@ export class BaseBehaviorBuilder<
|
|
|
484
517
|
for (let i = 0; i < keys.length; i += 1) {
|
|
485
518
|
const name = keys[i]!
|
|
486
519
|
const rel = rawRelations[name]!
|
|
487
|
-
|
|
520
|
+
const target =
|
|
521
|
+
rel.target instanceof Behavior ||
|
|
522
|
+
rel.target instanceof ComponentType ||
|
|
523
|
+
rel.target instanceof TraitBehavior
|
|
524
|
+
? rel.target._$
|
|
525
|
+
: rel.target
|
|
526
|
+
inner.relation(name, {
|
|
527
|
+
target,
|
|
528
|
+
type: rel.type,
|
|
529
|
+
linked: rel.linked,
|
|
530
|
+
linkChanged: rel.linkChanged,
|
|
531
|
+
unlinked: rel.unlinked,
|
|
532
|
+
linkFailed: rel.linkFailed,
|
|
533
|
+
} as any)
|
|
488
534
|
}
|
|
489
535
|
}
|
|
490
536
|
if (externalClasses) inner.externalClasses(externalClasses)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { BaseBehaviorBuilder } from './base_behavior_builder'
|
|
4
4
|
import { Behavior } from '../behavior'
|
|
5
5
|
import type { BehaviorDefinition, utils as typeUtils } from '../types'
|
|
6
|
-
import type { DefinitionFilter
|
|
6
|
+
import type { DefinitionFilter } from '../behavior'
|
|
7
7
|
import type { AllData, Component, GeneralComponent } from '../component'
|
|
8
8
|
import type { CodeSpace } from '../space'
|
|
9
9
|
import type { ResolveBehaviorBuilder, BuilderContext } from './type_utils'
|
|
@@ -23,15 +23,26 @@ type ChainingFilterFunc<
|
|
|
23
23
|
TRemovedFields extends string = never,
|
|
24
24
|
> = typeUtils.ChainingFilterFunc<TAddedFields, TRemovedFields>
|
|
25
25
|
|
|
26
|
+
export type DefaultBehaviorBuilder = BehaviorBuilder<
|
|
27
|
+
/* TPrevData */ Empty,
|
|
28
|
+
/* TData */ Empty,
|
|
29
|
+
/* TProperty */ Empty,
|
|
30
|
+
/* TMethod */ Empty,
|
|
31
|
+
/* TChainingFilter */ never,
|
|
32
|
+
/* TPendingChainingFilter */ never,
|
|
33
|
+
/* TComponentExport */ never,
|
|
34
|
+
/* TExtraThisFields */ Empty
|
|
35
|
+
>
|
|
36
|
+
|
|
26
37
|
export class BehaviorBuilder<
|
|
27
|
-
TPrevData extends DataList
|
|
28
|
-
TData extends DataList
|
|
29
|
-
TProperty extends PropertyList
|
|
30
|
-
TMethod extends MethodList
|
|
31
|
-
TChainingFilter extends ChainingFilterType
|
|
32
|
-
TPendingChainingFilter extends ChainingFilterType
|
|
33
|
-
TComponentExport
|
|
34
|
-
TExtraThisFields extends DataList
|
|
38
|
+
TPrevData extends DataList,
|
|
39
|
+
TData extends DataList,
|
|
40
|
+
TProperty extends PropertyList,
|
|
41
|
+
TMethod extends MethodList,
|
|
42
|
+
TChainingFilter extends ChainingFilterType,
|
|
43
|
+
TPendingChainingFilter extends ChainingFilterType,
|
|
44
|
+
TComponentExport,
|
|
45
|
+
TExtraThisFields extends DataList,
|
|
35
46
|
> extends BaseBehaviorBuilder<
|
|
36
47
|
TPrevData,
|
|
37
48
|
TData,
|
|
@@ -46,11 +57,11 @@ export class BehaviorBuilder<
|
|
|
46
57
|
private _$chainingFilter?: ChainingFilterFunc<any, any>
|
|
47
58
|
|
|
48
59
|
/** @internal */
|
|
49
|
-
static create(codeSpace: CodeSpace):
|
|
60
|
+
static create(codeSpace: CodeSpace): DefaultBehaviorBuilder {
|
|
50
61
|
const ret = new BehaviorBuilder()
|
|
51
62
|
ret._$codeSpace = codeSpace
|
|
52
63
|
ret._$ = codeSpace.getComponentSpace().defineWithMethodCaller()
|
|
53
|
-
return ret
|
|
64
|
+
return ret as DefaultBehaviorBuilder
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
/** Define a chaining filter */
|
|
@@ -80,14 +91,22 @@ export class BehaviorBuilder<
|
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
/** Use another behavior */
|
|
83
|
-
behavior<
|
|
94
|
+
override behavior<
|
|
84
95
|
UData extends DataList,
|
|
85
96
|
UProperty extends PropertyList,
|
|
86
97
|
UMethod extends MethodList,
|
|
87
98
|
UChainingFilter extends ChainingFilterType,
|
|
99
|
+
UComponentExport,
|
|
88
100
|
UExtraThisFields extends DataList,
|
|
89
101
|
>(
|
|
90
|
-
behavior: Behavior<
|
|
102
|
+
behavior: Behavior<
|
|
103
|
+
UData,
|
|
104
|
+
UProperty,
|
|
105
|
+
UMethod,
|
|
106
|
+
UChainingFilter,
|
|
107
|
+
UComponentExport,
|
|
108
|
+
UExtraThisFields
|
|
109
|
+
>,
|
|
91
110
|
): ResolveBehaviorBuilder<
|
|
92
111
|
BehaviorBuilder<
|
|
93
112
|
TPrevData,
|
|
@@ -96,18 +115,12 @@ export class BehaviorBuilder<
|
|
|
96
115
|
TMethod & UMethod,
|
|
97
116
|
UChainingFilter,
|
|
98
117
|
TPendingChainingFilter,
|
|
99
|
-
|
|
118
|
+
UComponentExport,
|
|
100
119
|
TExtraThisFields & UExtraThisFields
|
|
101
120
|
>,
|
|
102
121
|
UChainingFilter
|
|
103
122
|
> {
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
106
|
-
this._$ = this._$.behavior(behavior._$)
|
|
107
|
-
if (behavior._$chainingFilter) {
|
|
108
|
-
return behavior._$chainingFilter(this as any)
|
|
109
|
-
}
|
|
110
|
-
return this as any
|
|
123
|
+
return super.behavior(behavior) as any
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
/** Set the export value when the component is being selected */
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
PageDefinition,
|
|
11
11
|
utils as typeUtils,
|
|
12
12
|
} from '../types'
|
|
13
|
-
import type { Behavior
|
|
13
|
+
import type { Behavior } from '../behavior'
|
|
14
14
|
import type { AllData, Component, GeneralComponent } from '../component'
|
|
15
15
|
import type { CodeSpace } from '../space'
|
|
16
16
|
import type { ResolveBehaviorBuilder, BuilderContext } from './type_utils'
|
|
@@ -26,18 +26,29 @@ type ComponentMethod = typeUtils.ComponentMethod
|
|
|
26
26
|
type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
27
27
|
type UnTaggedMethod<M extends TaggedMethod<any>> = typeUtils.UnTaggedMethod<M>
|
|
28
28
|
|
|
29
|
+
export type DefaultComponentBuilder = ComponentBuilder<
|
|
30
|
+
/* TPrevData */ Empty,
|
|
31
|
+
/* TData */ Empty,
|
|
32
|
+
/* TProperty */ Empty,
|
|
33
|
+
/* TMethod */ Empty,
|
|
34
|
+
/* TChainingFilter */ never,
|
|
35
|
+
/* TPendingChainingFilter */ never,
|
|
36
|
+
/* TComponentExport */ never,
|
|
37
|
+
/* TExtraThisFields */ Empty
|
|
38
|
+
>
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* A direct way to create a component
|
|
31
42
|
*/
|
|
32
43
|
export class ComponentBuilder<
|
|
33
|
-
TPrevData extends DataList
|
|
34
|
-
TData extends DataList
|
|
35
|
-
TProperty extends PropertyList
|
|
36
|
-
TMethod extends MethodList
|
|
37
|
-
TChainingFilter extends ChainingFilterType
|
|
38
|
-
TPendingChainingFilter extends ChainingFilterType
|
|
39
|
-
TComponentExport
|
|
40
|
-
TExtraThisFields extends DataList
|
|
44
|
+
TPrevData extends DataList,
|
|
45
|
+
TData extends DataList,
|
|
46
|
+
TProperty extends PropertyList,
|
|
47
|
+
TMethod extends MethodList,
|
|
48
|
+
TChainingFilter extends ChainingFilterType,
|
|
49
|
+
TPendingChainingFilter extends ChainingFilterType,
|
|
50
|
+
TComponentExport,
|
|
51
|
+
TExtraThisFields extends DataList,
|
|
41
52
|
> extends BaseBehaviorBuilder<
|
|
42
53
|
TPrevData,
|
|
43
54
|
TData,
|
|
@@ -51,10 +62,10 @@ export class ComponentBuilder<
|
|
|
51
62
|
private _$is!: string
|
|
52
63
|
private _$alias?: string[]
|
|
53
64
|
private _$options?: ComponentDefinitionOptions
|
|
54
|
-
private _$proto?: ComponentProto<TData, TProperty, TMethod, TComponentExport>
|
|
65
|
+
private _$proto?: ComponentProto<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>
|
|
55
66
|
|
|
56
67
|
/** @internal */
|
|
57
|
-
static create(codeSpace: CodeSpace, is: string, alias?: string[]) {
|
|
68
|
+
static create(codeSpace: CodeSpace, is: string, alias?: string[]): DefaultComponentBuilder {
|
|
58
69
|
const ret = new ComponentBuilder()
|
|
59
70
|
const overallBehavior = codeSpace._$overallBehavior
|
|
60
71
|
ret._$codeSpace = codeSpace
|
|
@@ -67,7 +78,7 @@ export class ComponentBuilder<
|
|
|
67
78
|
if (proto === undefined) {
|
|
68
79
|
const methods = originalCaller.getComponentDefinition().behavior.getMethods()
|
|
69
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
70
|
-
proto = ret._$proto = new ComponentProto(methods, ret._$export) as any
|
|
81
|
+
proto = ret._$proto = new ComponentProto(methods, ret._$parents, ret._$export) as any
|
|
71
82
|
}
|
|
72
83
|
const caller = proto!.derive()
|
|
73
84
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -75,7 +86,7 @@ export class ComponentBuilder<
|
|
|
75
86
|
return caller
|
|
76
87
|
})
|
|
77
88
|
if (overallBehavior) ret._$.behavior(overallBehavior)
|
|
78
|
-
return ret
|
|
89
|
+
return ret as DefaultComponentBuilder
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
/**
|
|
@@ -89,7 +100,7 @@ export class ComponentBuilder<
|
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
/** Use another behavior */
|
|
92
|
-
behavior<
|
|
103
|
+
override behavior<
|
|
93
104
|
UData extends DataList,
|
|
94
105
|
UProperty extends PropertyList,
|
|
95
106
|
UMethod extends MethodList,
|
|
@@ -118,17 +129,7 @@ export class ComponentBuilder<
|
|
|
118
129
|
>,
|
|
119
130
|
UChainingFilter
|
|
120
131
|
> {
|
|
121
|
-
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
123
|
-
this._$ = this._$.behavior(behavior._$)
|
|
124
|
-
if (behavior._$export) {
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
126
|
-
this._$export = behavior._$export as any
|
|
127
|
-
}
|
|
128
|
-
if (behavior._$chainingFilter) {
|
|
129
|
-
return behavior._$chainingFilter(this as any)
|
|
130
|
-
}
|
|
131
|
-
return this as any
|
|
132
|
+
return super.behavior(behavior) as any
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
/** Set the export value when the component is being selected */
|
|
@@ -147,9 +148,7 @@ export class ComponentBuilder<
|
|
|
147
148
|
>,
|
|
148
149
|
TChainingFilter
|
|
149
150
|
> {
|
|
150
|
-
|
|
151
|
-
this._$export = f as any
|
|
152
|
-
return this as any
|
|
151
|
+
return super.export(f) as any
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
/**
|
|
@@ -376,7 +375,7 @@ export class ComponentBuilder<
|
|
|
376
375
|
/**
|
|
377
376
|
* Finish the component definition process
|
|
378
377
|
*/
|
|
379
|
-
register(): ComponentType<TData, TProperty, TMethod, TComponentExport> {
|
|
378
|
+
register(): ComponentType<TData, TProperty, TMethod, TComponentExport, TExtraThisFields> {
|
|
380
379
|
const is = this._$is
|
|
381
380
|
const codeSpace = this._$codeSpace
|
|
382
381
|
|
package/src/builder/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { BehaviorBuilder } from './behavior_builder'
|
|
2
|
+
export type { DefaultBehaviorBuilder } from './behavior_builder'
|
|
2
3
|
export { ComponentBuilder } from './component_builder'
|
|
4
|
+
export type { DefaultComponentBuilder } from './component_builder'
|
|
3
5
|
export { BuilderContext } from './type_utils'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as glassEasel from 'glass-easel'
|
|
2
2
|
import type { utils as typeUtils } from '../types'
|
|
3
|
-
import type {
|
|
3
|
+
import type { GeneralComponentType, GeneralBehavior, TraitBehavior } from '../behavior'
|
|
4
4
|
import type { GeneralComponent } from '../component'
|
|
5
5
|
|
|
6
6
|
export type ResolveBehaviorBuilder<
|
|
@@ -33,7 +33,7 @@ export type TraitRelationParams<TOut extends { [key: string]: any }> = {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export type RelationParams = {
|
|
36
|
-
target?: string |
|
|
36
|
+
target?: string | GeneralComponentType | GeneralBehavior | TraitBehavior<any>
|
|
37
37
|
type: 'ancestor' | 'descendant' | 'parent' | 'child' | 'parent-common-node' | 'child-common-node'
|
|
38
38
|
linked?: (target: GeneralComponent) => void
|
|
39
39
|
linkChanged?: (target: GeneralComponent) => void
|
package/src/component.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { SelectorQuery } from './selector_query'
|
|
|
5
5
|
import { IntersectionObserver } from './intersection'
|
|
6
6
|
import { MediaQueryObserver } from './media_query'
|
|
7
7
|
|
|
8
|
-
type Empty = typeUtils.Empty
|
|
9
8
|
type DataList = typeUtils.DataList
|
|
10
9
|
type PropertyList = typeUtils.PropertyList
|
|
11
10
|
type MethodList = typeUtils.MethodList
|
|
@@ -19,8 +18,9 @@ type ExportType<
|
|
|
19
18
|
UProperty extends PropertyList,
|
|
20
19
|
UMethod extends MethodList,
|
|
21
20
|
UComponentExport,
|
|
21
|
+
UExtraThisFields extends DataList,
|
|
22
22
|
> = [UComponentExport] extends [never]
|
|
23
|
-
? Component<UData, UProperty, UMethod, UComponentExport>
|
|
23
|
+
? Component<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>
|
|
24
24
|
: UComponentExport
|
|
25
25
|
|
|
26
26
|
const filterComponentExportWithType = <
|
|
@@ -28,11 +28,12 @@ const filterComponentExportWithType = <
|
|
|
28
28
|
UProperty extends PropertyList,
|
|
29
29
|
UMethod extends MethodList,
|
|
30
30
|
UComponentExport,
|
|
31
|
+
UExtraThisFields extends DataList,
|
|
31
32
|
>(
|
|
32
|
-
source:
|
|
33
|
+
source: GeneralComponentCaller,
|
|
33
34
|
elem: glassEasel.Element,
|
|
34
|
-
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
35
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport> | undefined => {
|
|
35
|
+
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
36
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | undefined => {
|
|
36
37
|
const comp = elem.asInstanceOf(componentType._$)
|
|
37
38
|
if (comp === null) return undefined
|
|
38
39
|
const selectedSpace = comp.getRootBehavior().ownerSpace
|
|
@@ -70,18 +71,41 @@ const filterComponentExport = (
|
|
|
70
71
|
return undefined
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
export
|
|
74
|
+
export const determineComponentExports = (
|
|
75
|
+
parent: GeneralBehavior[],
|
|
76
|
+
selfExport: ((source: GeneralComponent | null) => any) | undefined,
|
|
77
|
+
) => {
|
|
78
|
+
if (selfExport !== undefined) return selfExport
|
|
79
|
+
const targetBehavior = parent.findLast((behavior) => behavior._$export !== undefined)
|
|
80
|
+
if (targetBehavior !== undefined) return targetBehavior._$export
|
|
81
|
+
return undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type GeneralComponent = Component<
|
|
85
|
+
/* TData */ Record<string, any>,
|
|
86
|
+
/* TProperty */ Record<string, any>,
|
|
87
|
+
/* TMethod */ Record<string, any>,
|
|
88
|
+
/* TComponentExport */ any,
|
|
89
|
+
/* TExtraThisFields */ Record<string, any>
|
|
90
|
+
>
|
|
74
91
|
|
|
75
92
|
export type Component<
|
|
76
93
|
TData extends DataList,
|
|
77
94
|
TProperty extends PropertyList,
|
|
78
95
|
TMethod extends MethodList,
|
|
79
96
|
TComponentExport,
|
|
80
|
-
TExtraThisFields extends DataList
|
|
97
|
+
TExtraThisFields extends DataList,
|
|
81
98
|
> = ComponentCaller<TData, TProperty, TMethod, TComponentExport> & {
|
|
82
99
|
[k in keyof TMethod]: TMethod[k]
|
|
83
100
|
} & TExtraThisFields
|
|
84
101
|
|
|
102
|
+
type GeneralComponentCaller = ComponentCaller<
|
|
103
|
+
/* TData */ Record<string, any>,
|
|
104
|
+
/* TProperty */ Record<string, any>,
|
|
105
|
+
/* TMethod */ Record<string, any>,
|
|
106
|
+
/* TComponentExport */ any
|
|
107
|
+
>
|
|
108
|
+
|
|
85
109
|
export class ComponentCaller<
|
|
86
110
|
TData extends DataList,
|
|
87
111
|
TProperty extends PropertyList,
|
|
@@ -356,19 +380,21 @@ export class ComponentCaller<
|
|
|
356
380
|
UProperty extends PropertyList,
|
|
357
381
|
UMethod extends MethodList,
|
|
358
382
|
UComponentExport,
|
|
383
|
+
UExtraThisFields extends DataList,
|
|
359
384
|
>(
|
|
360
385
|
selector: string,
|
|
361
|
-
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
362
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport> | null
|
|
386
|
+
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
387
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | null
|
|
363
388
|
selectComponent<
|
|
364
389
|
UData extends DataList,
|
|
365
390
|
UProperty extends PropertyList,
|
|
366
391
|
UMethod extends MethodList,
|
|
367
392
|
UComponentExport,
|
|
393
|
+
UExtraThisFields extends DataList,
|
|
368
394
|
>(
|
|
369
395
|
selector: string,
|
|
370
|
-
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
371
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport> | null {
|
|
396
|
+
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
397
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | null {
|
|
372
398
|
const target = this._$.getShadowRoot()!.querySelector(selector)
|
|
373
399
|
if (target === null) return null
|
|
374
400
|
return componentType
|
|
@@ -388,21 +414,23 @@ export class ComponentCaller<
|
|
|
388
414
|
UProperty extends PropertyList,
|
|
389
415
|
UMethod extends MethodList,
|
|
390
416
|
UComponentExport,
|
|
417
|
+
UExtraThisFields extends DataList,
|
|
391
418
|
>(
|
|
392
419
|
selector: string,
|
|
393
|
-
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
394
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport>[]
|
|
420
|
+
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
421
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>[]
|
|
395
422
|
selectAllComponents<
|
|
396
423
|
UData extends DataList,
|
|
397
424
|
UProperty extends PropertyList,
|
|
398
425
|
UMethod extends MethodList,
|
|
399
426
|
UComponentExport,
|
|
427
|
+
UExtraThisFields extends DataList,
|
|
400
428
|
>(
|
|
401
429
|
selector: string,
|
|
402
|
-
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
403
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport>[] {
|
|
430
|
+
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
431
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>[] {
|
|
404
432
|
const targets = this._$.getShadowRoot()!.querySelectorAll(selector)
|
|
405
|
-
const ret = [] as ExportType<UData, UProperty, UMethod, UComponentExport>[]
|
|
433
|
+
const ret = [] as ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>[]
|
|
406
434
|
targets.forEach((target) => {
|
|
407
435
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
408
436
|
const r = componentType
|
|
@@ -425,17 +453,19 @@ export class ComponentCaller<
|
|
|
425
453
|
UProperty extends PropertyList,
|
|
426
454
|
UMethod extends MethodList,
|
|
427
455
|
UComponentExport,
|
|
456
|
+
UExtraThisFields extends DataList,
|
|
428
457
|
>(
|
|
429
|
-
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
430
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport> | null
|
|
458
|
+
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
459
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | null
|
|
431
460
|
selectOwnerComponent<
|
|
432
461
|
UData extends DataList,
|
|
433
462
|
UProperty extends PropertyList,
|
|
434
463
|
UMethod extends MethodList,
|
|
435
464
|
UComponentExport,
|
|
465
|
+
UExtraThisFields extends DataList,
|
|
436
466
|
>(
|
|
437
|
-
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
438
|
-
): ExportType<UData, UProperty, UMethod, UComponentExport> | null {
|
|
467
|
+
componentType?: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
468
|
+
): ExportType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | null {
|
|
439
469
|
const target = this._$.ownerShadowRoot?.getHostNode()
|
|
440
470
|
if (target === undefined) return null
|
|
441
471
|
return componentType
|
|
@@ -464,12 +494,19 @@ export class ComponentCaller<
|
|
|
464
494
|
UProperty extends PropertyList,
|
|
465
495
|
UMethod extends MethodList,
|
|
466
496
|
UComponentExport,
|
|
497
|
+
UExtraThisFields extends DataList,
|
|
467
498
|
>(
|
|
468
|
-
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport>,
|
|
469
|
-
): Component<UData, UProperty, UMethod, UComponentExport> | null {
|
|
499
|
+
componentType: ComponentType<UData, UProperty, UMethod, UComponentExport, UExtraThisFields>,
|
|
500
|
+
): Component<UData, UProperty, UMethod, UComponentExport, UExtraThisFields> | null {
|
|
470
501
|
const inner = this._$.asInstanceOf(componentType._$)
|
|
471
502
|
if (!inner) return null
|
|
472
|
-
return this as unknown as Component<
|
|
503
|
+
return this as unknown as Component<
|
|
504
|
+
UData,
|
|
505
|
+
UProperty,
|
|
506
|
+
UMethod,
|
|
507
|
+
UComponentExport,
|
|
508
|
+
UExtraThisFields
|
|
509
|
+
>
|
|
473
510
|
}
|
|
474
511
|
}
|
|
475
512
|
|
|
@@ -478,24 +515,33 @@ export class ComponentProto<
|
|
|
478
515
|
TProperty extends PropertyList,
|
|
479
516
|
TMethod extends MethodList,
|
|
480
517
|
TComponentExport,
|
|
518
|
+
TExtraThisFields extends DataList,
|
|
481
519
|
> {
|
|
482
|
-
private proto: Component<TData, TProperty, TMethod, TComponentExport>
|
|
520
|
+
private proto: Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>
|
|
483
521
|
|
|
484
522
|
constructor(
|
|
485
523
|
methods: TMethod,
|
|
524
|
+
parents: GeneralBehavior[],
|
|
486
525
|
componentExport?: (source: GeneralComponent | null) => TComponentExport,
|
|
487
526
|
) {
|
|
488
527
|
this.proto = Object.create(ComponentCaller.prototype) as Component<
|
|
489
528
|
TData,
|
|
490
529
|
TProperty,
|
|
491
530
|
TMethod,
|
|
492
|
-
TComponentExport
|
|
531
|
+
TComponentExport,
|
|
532
|
+
TExtraThisFields
|
|
493
533
|
>
|
|
494
534
|
Object.assign(this.proto, methods)
|
|
495
|
-
this.proto._$export = componentExport
|
|
535
|
+
this.proto._$export = determineComponentExports(parents, componentExport)
|
|
496
536
|
}
|
|
497
537
|
|
|
498
|
-
derive(): Component<TData, TProperty, TMethod, TComponentExport> {
|
|
499
|
-
return Object.create(this.proto) as Component<
|
|
538
|
+
derive(): Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields> {
|
|
539
|
+
return Object.create(this.proto) as Component<
|
|
540
|
+
TData,
|
|
541
|
+
TProperty,
|
|
542
|
+
TMethod,
|
|
543
|
+
TComponentExport,
|
|
544
|
+
TExtraThisFields
|
|
545
|
+
>
|
|
500
546
|
}
|
|
501
547
|
}
|