glass-easel-miniprogram-adapter 0.8.2 → 0.10.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 +3 -1
- 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/backend.ts +3 -1
- package/src/behavior.ts +4 -0
- package/src/builder/behavior_builder.ts +6 -1
- package/src/builder/component_builder.ts +3 -0
- package/src/space.ts +8 -2
- package/src/types.ts +1 -0
- package/tests/env.test.ts +3 -1
- package/tests/selector.test.ts +18 -14
- package/tests/space.test.ts +12 -5
- package/tests/trait_behavior.test.ts +4 -1
|
@@ -43,6 +43,7 @@ export class BehaviorBuilder<
|
|
|
43
43
|
TExtraThisFields
|
|
44
44
|
> {
|
|
45
45
|
private _$definitionFilter: DefinitionFilter | undefined
|
|
46
|
+
private _$chainingFilter?: ChainingFilterFunc<any, any>
|
|
46
47
|
|
|
47
48
|
/** @internal */
|
|
48
49
|
static create(codeSpace: CodeSpace): BehaviorBuilder {
|
|
@@ -74,7 +75,7 @@ export class BehaviorBuilder<
|
|
|
74
75
|
>,
|
|
75
76
|
TChainingFilter
|
|
76
77
|
> {
|
|
77
|
-
this._
|
|
78
|
+
this._$chainingFilter = func
|
|
78
79
|
return this as any
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -103,6 +104,9 @@ export class BehaviorBuilder<
|
|
|
103
104
|
this._$parents.push(behavior as GeneralBehavior)
|
|
104
105
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
105
106
|
this._$ = this._$.behavior(behavior._$)
|
|
107
|
+
if (behavior._$chainingFilter) {
|
|
108
|
+
return behavior._$chainingFilter(this as any)
|
|
109
|
+
}
|
|
106
110
|
return this as any
|
|
107
111
|
}
|
|
108
112
|
|
|
@@ -284,6 +288,7 @@ export class BehaviorBuilder<
|
|
|
284
288
|
this._$.registerBehavior(),
|
|
285
289
|
this._$parents,
|
|
286
290
|
this._$definitionFilter,
|
|
291
|
+
this._$chainingFilter,
|
|
287
292
|
this._$export,
|
|
288
293
|
)
|
|
289
294
|
}
|
|
@@ -125,6 +125,9 @@ export class ComponentBuilder<
|
|
|
125
125
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
126
126
|
this._$export = behavior._$export as any
|
|
127
127
|
}
|
|
128
|
+
if (behavior._$chainingFilter) {
|
|
129
|
+
return behavior._$chainingFilter(this as any)
|
|
130
|
+
}
|
|
128
131
|
return this as any
|
|
129
132
|
}
|
|
130
133
|
|
package/src/space.ts
CHANGED
|
@@ -78,7 +78,9 @@ export class CodeSpace {
|
|
|
78
78
|
private space: glassEasel.ComponentSpace
|
|
79
79
|
private styleScopeManager: glassEasel.StyleScopeManager
|
|
80
80
|
private staticConfigMap: { [path: string]: ComponentStaticConfig }
|
|
81
|
-
private styleSheetMap: {
|
|
81
|
+
private styleSheetMap: {
|
|
82
|
+
[path: string]: { url: string | undefined; styleScopeName: string | undefined }
|
|
83
|
+
}
|
|
82
84
|
private compiledTemplateMap: { [path: string]: glassEasel.template.ComponentTemplate }
|
|
83
85
|
private waitingAliasMap: { [is: string]: string[] }
|
|
84
86
|
/** @internal */
|
|
@@ -102,6 +104,8 @@ export class CodeSpace {
|
|
|
102
104
|
globalCodeSpace?.space,
|
|
103
105
|
globalCodeSpace?.space.styleScopeManager,
|
|
104
106
|
)
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
108
|
+
;(this.space as any).__wxCodeSpace = this
|
|
105
109
|
this.styleScopeManager = this.space.styleScopeManager
|
|
106
110
|
this.staticConfigMap = Object.create(null) as { [path: string]: ComponentStaticConfig }
|
|
107
111
|
this.styleSheetMap = Object.create(null) as {
|
|
@@ -117,6 +121,7 @@ export class CodeSpace {
|
|
|
117
121
|
else this.waitingAliasMap[is] = [alias]
|
|
118
122
|
})
|
|
119
123
|
this._$sharedStyleScope = this.styleScopeManager.register('')
|
|
124
|
+
this.space.setSharedStyleScope(this._$sharedStyleScope)
|
|
120
125
|
this._$styleIsolationMap = Object.create(null) as { [path: string]: StyleIsolation }
|
|
121
126
|
}
|
|
122
127
|
|
|
@@ -163,7 +168,7 @@ export class CodeSpace {
|
|
|
163
168
|
* The URL should be recognized by the target backend.
|
|
164
169
|
* The `path` should not contain the `.wxss` suffix.
|
|
165
170
|
*/
|
|
166
|
-
addStyleSheet(path: string, styleSheetUrl
|
|
171
|
+
addStyleSheet(path: string, styleSheetUrl?: string, styleScopeName?: string) {
|
|
167
172
|
this.styleSheetMap[path] = { url: styleSheetUrl, styleScopeName }
|
|
168
173
|
}
|
|
169
174
|
|
|
@@ -262,6 +267,7 @@ export class CodeSpace {
|
|
|
262
267
|
const ret: glassEasel.ComponentOptions = {
|
|
263
268
|
idPrefixGenerator: guid,
|
|
264
269
|
multipleSlots: options?.multipleSlots,
|
|
270
|
+
dynamicSlots: options?.dynamicSlots,
|
|
265
271
|
pureDataPattern,
|
|
266
272
|
virtualHost: options?.virtualHost,
|
|
267
273
|
styleScope,
|
package/src/types.ts
CHANGED
package/tests/env.test.ts
CHANGED
|
@@ -95,11 +95,13 @@ describe('env', () => {
|
|
|
95
95
|
expect(codeSpace.isMainSpace()).toBe(true)
|
|
96
96
|
|
|
97
97
|
pluginCodeSpace1.addCompiledTemplate('inner-comp-1', tmpl('A'))
|
|
98
|
+
pluginCodeSpace1.addStyleSheet('inner-comp-1', undefined, 'c1')
|
|
98
99
|
pluginCodeSpace1.componentEnv('inner-comp-1', ({ Component }) => {
|
|
99
100
|
Component().register()
|
|
100
101
|
})
|
|
101
102
|
|
|
102
103
|
pluginCodeSpace2.addCompiledTemplate('inner-comp-2', tmpl('B'))
|
|
104
|
+
pluginCodeSpace2.addStyleSheet('inner-comp-2', undefined, 'c2')
|
|
103
105
|
pluginCodeSpace2.componentEnv('inner-comp-2', ({ Component }) => {
|
|
104
106
|
Component().register()
|
|
105
107
|
})
|
|
@@ -135,7 +137,7 @@ describe('env', () => {
|
|
|
135
137
|
const ab = env.associateBackend(backend)
|
|
136
138
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
137
139
|
expect(domHtml(root.getComponent())).toBe(
|
|
138
|
-
'<c-a
|
|
140
|
+
'<c-a wx-host="c1">A</c-a><c-aa wx-host="c1">A</c-aa><i-a></i-a><i-b></i-b><c-b wx-host="c2">B</c-b>',
|
|
139
141
|
)
|
|
140
142
|
})
|
|
141
143
|
})
|
package/tests/selector.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as glassEasel from 'glass-easel'
|
|
2
2
|
import { tmpl } from './base/env'
|
|
3
3
|
import { MiniProgramEnv } from '../src'
|
|
4
|
+
import { StyleIsolation } from '../src/types'
|
|
4
5
|
|
|
5
6
|
const domHtml = (elem: glassEasel.Element): string => {
|
|
6
7
|
const domElem = elem.getBackendElement() as unknown as Element
|
|
@@ -14,6 +15,7 @@ describe('selector query', () => {
|
|
|
14
15
|
|
|
15
16
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
16
17
|
component: true,
|
|
18
|
+
styleIsolation: StyleIsolation.Shared,
|
|
17
19
|
})
|
|
18
20
|
codeSpace.addCompiledTemplate('child/comp', tmpl('{{a}}'))
|
|
19
21
|
// eslint-disable-next-line arrow-body-style
|
|
@@ -72,17 +74,18 @@ describe('selector query', () => {
|
|
|
72
74
|
const ab = env.associateBackend()
|
|
73
75
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
74
76
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
75
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
76
|
-
'<div><child is="child/comp">456</child><child is="child/comp">789</child></div>',
|
|
77
|
-
)
|
|
77
|
+
expect(domHtml(root.getComponent())).toBe('<div><child>456</child><child>789</child></div>')
|
|
78
78
|
})
|
|
79
79
|
|
|
80
80
|
test('select single component (with custom export)', () => {
|
|
81
81
|
const env = new MiniProgramEnv()
|
|
82
82
|
const codeSpace = env.createCodeSpace('', true)
|
|
83
83
|
|
|
84
|
-
codeSpace.addComponentStaticConfig('child1/comp', {
|
|
85
|
-
|
|
84
|
+
codeSpace.addComponentStaticConfig('child1/comp', {
|
|
85
|
+
component: true,
|
|
86
|
+
styleIsolation: StyleIsolation.Shared,
|
|
87
|
+
})
|
|
88
|
+
codeSpace.addComponentStaticConfig('child2/comp', { component: false })
|
|
86
89
|
codeSpace.addCompiledTemplate('child1/comp', tmpl('{{a}}'))
|
|
87
90
|
codeSpace.addCompiledTemplate('child2/comp', tmpl('{{a}}'))
|
|
88
91
|
|
|
@@ -161,17 +164,18 @@ describe('selector query', () => {
|
|
|
161
164
|
const ab = env.associateBackend()
|
|
162
165
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
163
166
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
164
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
165
|
-
'<div><child1 is="child1/comp">456</child1><child2 is="child2/comp">789</child2></div>',
|
|
166
|
-
)
|
|
167
|
+
expect(domHtml(root.getComponent())).toBe('<div><child1>456</child1><child2>789</child2></div>')
|
|
167
168
|
})
|
|
168
169
|
|
|
169
170
|
test('select single component (with custom export on behavior)', () => {
|
|
170
171
|
const env = new MiniProgramEnv()
|
|
171
172
|
const codeSpace = env.createCodeSpace('', true)
|
|
172
173
|
|
|
173
|
-
codeSpace.addComponentStaticConfig('child1/comp', {
|
|
174
|
-
|
|
174
|
+
codeSpace.addComponentStaticConfig('child1/comp', {
|
|
175
|
+
component: true,
|
|
176
|
+
styleIsolation: StyleIsolation.Shared,
|
|
177
|
+
})
|
|
178
|
+
codeSpace.addComponentStaticConfig('child2/comp', { component: false })
|
|
175
179
|
codeSpace.addCompiledTemplate('child1/comp', tmpl('{{a}}'))
|
|
176
180
|
codeSpace.addCompiledTemplate('child2/comp', tmpl('{{a}}'))
|
|
177
181
|
|
|
@@ -255,9 +259,7 @@ describe('selector query', () => {
|
|
|
255
259
|
const ab = env.associateBackend()
|
|
256
260
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
257
261
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
258
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
259
|
-
'<div><child1 is="child1/comp">456</child1><child2 is="child2/comp">789</child2></div>',
|
|
260
|
-
)
|
|
262
|
+
expect(domHtml(root.getComponent())).toBe('<div><child1>456</child1><child2>789</child2></div>')
|
|
261
263
|
})
|
|
262
264
|
|
|
263
265
|
test('select all components', () => {
|
|
@@ -266,6 +268,7 @@ describe('selector query', () => {
|
|
|
266
268
|
|
|
267
269
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
268
270
|
component: true,
|
|
271
|
+
styleIsolation: StyleIsolation.Shared,
|
|
269
272
|
})
|
|
270
273
|
codeSpace.addCompiledTemplate('child/comp', tmpl('{{a}}'))
|
|
271
274
|
// eslint-disable-next-line arrow-body-style
|
|
@@ -279,6 +282,7 @@ describe('selector query', () => {
|
|
|
279
282
|
|
|
280
283
|
codeSpace.addComponentStaticConfig('child/comp2', {
|
|
281
284
|
component: true,
|
|
285
|
+
styleIsolation: StyleIsolation.Shared,
|
|
282
286
|
})
|
|
283
287
|
codeSpace.addCompiledTemplate('child/comp2', tmpl('{{a}}'))
|
|
284
288
|
// eslint-disable-next-line arrow-body-style
|
|
@@ -322,7 +326,7 @@ describe('selector query', () => {
|
|
|
322
326
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
323
327
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
324
328
|
expect(domHtml(root.getComponent())).toBe(
|
|
325
|
-
'<div><child
|
|
329
|
+
'<div><child class="c">0</child><child class="c">1</child><child-b class="c">2</child-b></div>',
|
|
326
330
|
)
|
|
327
331
|
})
|
|
328
332
|
|
package/tests/space.test.ts
CHANGED
|
@@ -214,6 +214,7 @@ describe('define', () => {
|
|
|
214
214
|
<c />
|
|
215
215
|
`),
|
|
216
216
|
)
|
|
217
|
+
codeSpace.addStyleSheet('comp/a', undefined, 'A')
|
|
217
218
|
codeSpace.componentEnv('comp/a', ({ Component }) => {
|
|
218
219
|
Component().register()
|
|
219
220
|
})
|
|
@@ -227,6 +228,7 @@ describe('define', () => {
|
|
|
227
228
|
<span>B</span>
|
|
228
229
|
`),
|
|
229
230
|
)
|
|
231
|
+
codeSpace.addStyleSheet('comp/b', undefined, 'B')
|
|
230
232
|
codeSpace.componentEnv('comp/b', ({ Component }) => {
|
|
231
233
|
Component().register()
|
|
232
234
|
})
|
|
@@ -250,7 +252,7 @@ describe('define', () => {
|
|
|
250
252
|
const ab = env.associateBackend()
|
|
251
253
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
252
254
|
expect(domHtml(root.getComponent())).toBe(
|
|
253
|
-
'<a
|
|
255
|
+
'<a wx-host="A"><c wx-host="B"><span>B</span></c></a>',
|
|
254
256
|
)
|
|
255
257
|
})
|
|
256
258
|
|
|
@@ -267,6 +269,7 @@ describe('define', () => {
|
|
|
267
269
|
<div>A</div>
|
|
268
270
|
`),
|
|
269
271
|
)
|
|
272
|
+
codeSpace.addStyleSheet('comp/a', undefined, 'A')
|
|
270
273
|
codeSpace.componentEnv('comp/a', ({ Component }) => {
|
|
271
274
|
Component().register()
|
|
272
275
|
})
|
|
@@ -286,13 +289,14 @@ describe('define', () => {
|
|
|
286
289
|
<a />
|
|
287
290
|
`),
|
|
288
291
|
)
|
|
292
|
+
codeSpace.addStyleSheet('path/to/comp', undefined, 'COMP')
|
|
289
293
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
290
294
|
Component().register()
|
|
291
295
|
})
|
|
292
296
|
|
|
293
297
|
const ab = env.associateBackend()
|
|
294
298
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
295
|
-
expect(domHtml(root.getComponent())).toBe('<a
|
|
299
|
+
expect(domHtml(root.getComponent())).toBe('<a wx-host="A"><div>A</div></a>')
|
|
296
300
|
|
|
297
301
|
codeSpace.addComponentStaticConfig('comp/b', {
|
|
298
302
|
component: true,
|
|
@@ -303,11 +307,12 @@ describe('define', () => {
|
|
|
303
307
|
<span>B</span>
|
|
304
308
|
`),
|
|
305
309
|
)
|
|
310
|
+
codeSpace.addStyleSheet('comp/b', undefined, 'B')
|
|
306
311
|
codeSpace.componentEnv('comp/b', ({ Component }) => {
|
|
307
312
|
Component().register()
|
|
308
313
|
})
|
|
309
314
|
|
|
310
|
-
expect(domHtml(root.getComponent())).toBe('<a
|
|
315
|
+
expect(domHtml(root.getComponent())).toBe('<a wx-host="B"><span>B</span></a>')
|
|
311
316
|
})
|
|
312
317
|
|
|
313
318
|
test('options pureDataPattern (js)', () => {
|
|
@@ -748,7 +753,7 @@ describe('define', () => {
|
|
|
748
753
|
.chainingFilter<TAdd, TRemove>((chain) => {
|
|
749
754
|
const oldData = chain.data.bind(chain)
|
|
750
755
|
const newData = function () {
|
|
751
|
-
oldData(() => ({
|
|
756
|
+
return oldData(() => ({
|
|
752
757
|
a: 123,
|
|
753
758
|
}))
|
|
754
759
|
}
|
|
@@ -1009,6 +1014,7 @@ describe('define', () => {
|
|
|
1009
1014
|
<div>{{count}}</div><slot />
|
|
1010
1015
|
`),
|
|
1011
1016
|
)
|
|
1017
|
+
codeSpace.addStyleSheet('child/list', undefined, 'LIST')
|
|
1012
1018
|
// eslint-disable-next-line arrow-body-style
|
|
1013
1019
|
const listDef = codeSpace.componentEnv('child/list', ({ Component }) => {
|
|
1014
1020
|
return Component()
|
|
@@ -1031,6 +1037,7 @@ describe('define', () => {
|
|
|
1031
1037
|
codeSpace.addComponentStaticConfig('child/item', {
|
|
1032
1038
|
component: true,
|
|
1033
1039
|
})
|
|
1040
|
+
codeSpace.addStyleSheet('child/item', undefined, 'ITEM')
|
|
1034
1041
|
// eslint-disable-next-line arrow-body-style
|
|
1035
1042
|
const itemDef = codeSpace.componentEnv('child/item', ({ Component }) => {
|
|
1036
1043
|
return Component()
|
|
@@ -1069,7 +1076,7 @@ describe('define', () => {
|
|
|
1069
1076
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
1070
1077
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
1071
1078
|
expect(domHtml(root.getComponent())).toBe(
|
|
1072
|
-
'<list
|
|
1079
|
+
'<list wx-host="LIST"><div>2</div><item wx-host="ITEM"></item><item wx-host="ITEM"></item></list>',
|
|
1073
1080
|
)
|
|
1074
1081
|
})
|
|
1075
1082
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as glassEasel from 'glass-easel'
|
|
2
2
|
import { tmpl } from './base/env'
|
|
3
3
|
import { MiniProgramEnv } from '../src'
|
|
4
|
+
import { StyleIsolation } from '../src/types'
|
|
4
5
|
|
|
5
6
|
const domHtml = (elem: glassEasel.Element): string => {
|
|
6
7
|
const domElem = elem.getBackendElement() as unknown as Element
|
|
@@ -60,6 +61,7 @@ describe('trait behavior', () => {
|
|
|
60
61
|
|
|
61
62
|
codeSpace.addComponentStaticConfig('child/list', {
|
|
62
63
|
component: true,
|
|
64
|
+
styleIsolation: StyleIsolation.Shared,
|
|
63
65
|
})
|
|
64
66
|
codeSpace.addCompiledTemplate(
|
|
65
67
|
'child/list',
|
|
@@ -93,6 +95,7 @@ describe('trait behavior', () => {
|
|
|
93
95
|
|
|
94
96
|
codeSpace.addComponentStaticConfig('child/item', {
|
|
95
97
|
component: true,
|
|
98
|
+
styleIsolation: StyleIsolation.Shared,
|
|
96
99
|
})
|
|
97
100
|
codeSpace.addCompiledTemplate('child/item', tmpl('{{a}}'))
|
|
98
101
|
// eslint-disable-next-line arrow-body-style
|
|
@@ -138,7 +141,7 @@ describe('trait behavior', () => {
|
|
|
138
141
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
139
142
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
140
143
|
expect(domHtml(root.getComponent())).toBe(
|
|
141
|
-
'<list
|
|
144
|
+
'<list><div>2</div><item>2</item><item>3</item></list>',
|
|
142
145
|
)
|
|
143
146
|
})
|
|
144
147
|
})
|