glass-easel-miniprogram-adapter 0.1.1 → 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/types.ts
CHANGED
|
@@ -15,23 +15,23 @@ export const enum StyleIsolation {
|
|
|
15
15
|
export type ComponentStaticConfig = {
|
|
16
16
|
component?: boolean
|
|
17
17
|
usingComponents?: { [name: string]: string }
|
|
18
|
-
|
|
18
|
+
componentGenerics?: {
|
|
19
19
|
[name: string]: true | { default?: string }
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
styleIsolation?: StyleIsolation
|
|
21
|
+
componentPlaceholder?: { [name: string]: string }
|
|
22
|
+
styleIsolation?: StyleIsolation
|
|
23
23
|
/** @obsolete */
|
|
24
|
-
addGlobalClass?: boolean
|
|
25
|
-
pureDataPattern?: string
|
|
24
|
+
addGlobalClass?: boolean
|
|
25
|
+
pureDataPattern?: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export type ComponentDefinitionOptions = {
|
|
29
29
|
multipleSlots?: boolean
|
|
30
|
-
pureDataPattern?: RegExp
|
|
31
|
-
virtualHost?: boolean
|
|
32
|
-
dataDeepCopy?: DeepCopyKind
|
|
33
|
-
propertyPassingDeepCopy?: DeepCopyKind
|
|
34
|
-
propertyEarlyInit?: boolean
|
|
30
|
+
pureDataPattern?: RegExp
|
|
31
|
+
virtualHost?: boolean
|
|
32
|
+
dataDeepCopy?: DeepCopyKind
|
|
33
|
+
propertyPassingDeepCopy?: DeepCopyKind
|
|
34
|
+
propertyEarlyInit?: boolean
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
type ComponentMethod = utils.ComponentMethod
|
|
@@ -41,26 +41,26 @@ export type BehaviorDefinition<
|
|
|
41
41
|
TProperty extends utils.PropertyList,
|
|
42
42
|
TMethod extends utils.MethodList,
|
|
43
43
|
> = {
|
|
44
|
-
behaviors?: Behavior<any, any, any, any>[]
|
|
45
|
-
properties?: TProperty
|
|
46
|
-
data?: TData | (() => TData)
|
|
44
|
+
behaviors?: Behavior<any, any, any, any>[]
|
|
45
|
+
properties?: TProperty
|
|
46
|
+
data?: TData | (() => TData)
|
|
47
47
|
observers?:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
| {
|
|
49
|
+
fields?: string
|
|
50
|
+
observer: ComponentMethod
|
|
51
|
+
}[]
|
|
52
52
|
| { [fields: string]: ComponentMethod }
|
|
53
|
-
methods?: TMethod
|
|
54
|
-
created?: ComponentMethod
|
|
55
|
-
attached?: ComponentMethod
|
|
56
|
-
ready?: ComponentMethod
|
|
57
|
-
moved?: ComponentMethod
|
|
58
|
-
detached?: ComponentMethod
|
|
59
|
-
lifetimes?: { [name: string]: ComponentMethod }
|
|
60
|
-
pageLifetimes?: { [name: string]: ComponentMethod }
|
|
61
|
-
relations?: utils.RelationParamsWithKey
|
|
62
|
-
externalClasses?: string[]
|
|
63
|
-
definitionFilter?: DefinitionFilter
|
|
53
|
+
methods?: TMethod
|
|
54
|
+
created?: ComponentMethod
|
|
55
|
+
attached?: ComponentMethod
|
|
56
|
+
ready?: ComponentMethod
|
|
57
|
+
moved?: ComponentMethod
|
|
58
|
+
detached?: ComponentMethod
|
|
59
|
+
lifetimes?: { [name: string]: ComponentMethod }
|
|
60
|
+
pageLifetimes?: { [name: string]: ComponentMethod }
|
|
61
|
+
relations?: utils.RelationParamsWithKey
|
|
62
|
+
externalClasses?: string[]
|
|
63
|
+
definitionFilter?: DefinitionFilter
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export type ComponentDefinition<
|
|
@@ -69,8 +69,8 @@ export type ComponentDefinition<
|
|
|
69
69
|
TMethod extends utils.MethodList,
|
|
70
70
|
TComponentExport,
|
|
71
71
|
> = {
|
|
72
|
-
options?: ComponentDefinitionOptions
|
|
73
|
-
export?: () => TComponentExport
|
|
72
|
+
options?: ComponentDefinitionOptions
|
|
73
|
+
export?: () => TComponentExport
|
|
74
74
|
} & BehaviorDefinition<TData, TProperty, TMethod>
|
|
75
75
|
|
|
76
76
|
export type GeneralComponentDefinition = ComponentDefinition<any, any, any, any>
|
|
@@ -79,7 +79,7 @@ export type PageDefinition<
|
|
|
79
79
|
TData extends utils.DataList,
|
|
80
80
|
TExtraFields extends { [k: PropertyKey]: any },
|
|
81
81
|
> = TExtraFields & {
|
|
82
|
-
options?: ComponentDefinitionOptions
|
|
83
|
-
behaviors?: GeneralBehavior[]
|
|
84
|
-
data?: TData
|
|
82
|
+
options?: ComponentDefinitionOptions
|
|
83
|
+
behaviors?: GeneralBehavior[]
|
|
84
|
+
data?: TData
|
|
85
85
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export const guid = (): string =>
|
|
2
|
-
.
|
|
3
|
-
|
|
1
|
+
export const guid = (): string =>
|
|
2
|
+
Math.floor((1 + Math.random()) * 0x100000000)
|
|
3
|
+
.toString(16)
|
|
4
|
+
.slice(1)
|
package/tests/base/env.ts
CHANGED
|
@@ -10,8 +10,7 @@ export const tmpl = (src: string): glassEasel.template.ComponentTemplate => {
|
|
|
10
10
|
const genObjectSrc = `return ${group.getTmplGenObjectGroups()}`
|
|
11
11
|
group.free()
|
|
12
12
|
// console.info(genObjectSrc)
|
|
13
|
-
const genObjectGroupList =
|
|
14
|
-
{ [key: string]: any }
|
|
13
|
+
const genObjectGroupList = new Function(genObjectSrc)() as { [key: string]: any }
|
|
15
14
|
return {
|
|
16
15
|
groupList: genObjectGroupList,
|
|
17
16
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as glassEasel from 'glass-easel'
|
|
2
2
|
import { tmpl } from './base/env'
|
|
3
|
-
import {
|
|
4
|
-
MiniProgramEnv,
|
|
5
|
-
} from '../src'
|
|
3
|
+
import { MiniProgramEnv } from '../src'
|
|
6
4
|
|
|
7
5
|
const domHtml = (elem: glassEasel.Element): string => {
|
|
8
6
|
const domElem = elem.getBackendElement() as unknown as Element
|
|
@@ -15,10 +13,13 @@ describe('data update', () => {
|
|
|
15
13
|
const codeSpace = env.createCodeSpace('', true)
|
|
16
14
|
|
|
17
15
|
codeSpace.addComponentStaticConfig('path/to/comp', {})
|
|
18
|
-
codeSpace.addCompiledTemplate(
|
|
16
|
+
codeSpace.addCompiledTemplate(
|
|
17
|
+
'path/to/comp',
|
|
18
|
+
tmpl(`
|
|
19
19
|
<div wx:for="{{arr}}">{{item}}</div>
|
|
20
20
|
<span>{{obj.sub}}</span>
|
|
21
|
-
`)
|
|
21
|
+
`),
|
|
22
|
+
)
|
|
22
23
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
23
24
|
Component()
|
|
24
25
|
.data(() => ({
|
|
@@ -33,20 +34,21 @@ describe('data update', () => {
|
|
|
33
34
|
this.replaceDataOnPath(['obj', 'sub'], true)
|
|
34
35
|
})
|
|
35
36
|
// eslint-disable-next-line no-use-before-define
|
|
36
|
-
expect(domHtml(root.getComponent()))
|
|
37
|
-
|
|
37
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
38
|
+
'<div>1</div><div>4</div><div>5</div><div>3</div><span>true</span>',
|
|
39
|
+
)
|
|
38
40
|
this.groupSetData(() => {
|
|
39
41
|
this.updateData({
|
|
40
42
|
arr: [123],
|
|
41
43
|
})
|
|
42
44
|
})
|
|
43
45
|
// eslint-disable-next-line no-use-before-define
|
|
44
|
-
expect(domHtml(root.getComponent()))
|
|
45
|
-
|
|
46
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
47
|
+
'<div>1</div><div>4</div><div>5</div><div>3</div><span>true</span>',
|
|
48
|
+
)
|
|
46
49
|
this.applyDataUpdates()
|
|
47
50
|
// eslint-disable-next-line no-use-before-define
|
|
48
|
-
expect(domHtml(root.getComponent()))
|
|
49
|
-
.toBe('<div>123</div><span>true</span>')
|
|
51
|
+
expect(domHtml(root.getComponent())).toBe('<div>123</div><span>true</span>')
|
|
50
52
|
})
|
|
51
53
|
.register()
|
|
52
54
|
})
|
|
@@ -57,36 +59,40 @@ describe('data update', () => {
|
|
|
57
59
|
expect(domHtml(root.getComponent())).toBe('<div>123</div><span>true</span>')
|
|
58
60
|
})
|
|
59
61
|
|
|
60
|
-
test('setData callback', () =>
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
test('setData callback', () =>
|
|
63
|
+
new Promise((resolve) => {
|
|
64
|
+
const env = new MiniProgramEnv()
|
|
65
|
+
const codeSpace = env.createCodeSpace('', true)
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
codeSpace.addComponentStaticConfig('path/to/comp', {})
|
|
68
|
+
codeSpace.addCompiledTemplate(
|
|
69
|
+
'path/to/comp',
|
|
70
|
+
tmpl(`
|
|
66
71
|
<span>{{a}}</span>
|
|
67
|
-
`)
|
|
68
|
-
|
|
69
|
-
Component
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
`),
|
|
73
|
+
)
|
|
74
|
+
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
75
|
+
Component()
|
|
76
|
+
.data(() => ({
|
|
77
|
+
a: 123,
|
|
78
|
+
}))
|
|
79
|
+
.init(function ({ setData, lifetime }) {
|
|
80
|
+
lifetime('attached', () => {
|
|
81
|
+
setData({ a: 789 }, () => {
|
|
82
|
+
this.setData({ a: 456 }, () => {
|
|
83
|
+
// eslint-disable-next-line no-use-before-define
|
|
84
|
+
expect(domHtml(root.getComponent())).toBe('<span>456</span>')
|
|
85
|
+
resolve(undefined)
|
|
86
|
+
})
|
|
80
87
|
})
|
|
81
88
|
})
|
|
82
89
|
})
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
90
|
+
.register()
|
|
91
|
+
})
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
const ab = env.associateBackend()
|
|
94
|
+
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
95
|
+
glassEasel.Element.pretendAttached(root.getComponent())
|
|
96
|
+
expect(domHtml(root.getComponent())).toBe('<span>789</span>')
|
|
97
|
+
}))
|
|
92
98
|
})
|
package/tests/env.test.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as glassEasel from 'glass-easel'
|
|
2
2
|
import { tmpl } from './base/env'
|
|
3
|
-
import {
|
|
4
|
-
MiniProgramEnv,
|
|
5
|
-
} from '../src'
|
|
3
|
+
import { MiniProgramEnv } from '../src'
|
|
6
4
|
|
|
7
5
|
const domHtml = (elem: glassEasel.Element): string => {
|
|
8
6
|
const domElem = elem.getBackendElement() as unknown as Element
|
|
@@ -13,16 +11,20 @@ describe('env', () => {
|
|
|
13
11
|
test('add global components', () => {
|
|
14
12
|
const env = new MiniProgramEnv()
|
|
15
13
|
const globalCodeSpace = env.getGlobalCodeSpace()
|
|
16
|
-
globalCodeSpace
|
|
14
|
+
const def = globalCodeSpace
|
|
15
|
+
.getComponentSpace()
|
|
16
|
+
.define('external')
|
|
17
17
|
.options({
|
|
18
18
|
virtualHost: true,
|
|
19
19
|
})
|
|
20
|
-
.template(
|
|
20
|
+
.template(
|
|
21
|
+
tmpl(`
|
|
21
22
|
<span class="inner" />
|
|
22
|
-
`)
|
|
23
|
+
`),
|
|
24
|
+
)
|
|
23
25
|
.registerComponent()
|
|
24
|
-
globalCodeSpace.getComponentSpace().exportComponent('external', 'external')
|
|
25
26
|
const codeSpace = env.createCodeSpace('', true)
|
|
27
|
+
codeSpace.getComponentSpace().setGlobalUsingComponent('external', def)
|
|
26
28
|
|
|
27
29
|
codeSpace.addComponentStaticConfig('path/to/comp', {
|
|
28
30
|
usingComponents: {
|
|
@@ -30,11 +32,14 @@ describe('env', () => {
|
|
|
30
32
|
},
|
|
31
33
|
})
|
|
32
34
|
|
|
33
|
-
codeSpace.addCompiledTemplate(
|
|
35
|
+
codeSpace.addCompiledTemplate(
|
|
36
|
+
'path/to/comp',
|
|
37
|
+
tmpl(`
|
|
34
38
|
<div class="outer">
|
|
35
39
|
<external />
|
|
36
40
|
</div>
|
|
37
|
-
`)
|
|
41
|
+
`),
|
|
42
|
+
)
|
|
38
43
|
|
|
39
44
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
40
45
|
Component().register()
|
|
@@ -43,43 +48,33 @@ describe('env', () => {
|
|
|
43
48
|
const backend = new glassEasel.domlikeBackend.CurrentWindowBackendContext()
|
|
44
49
|
const ab = env.associateBackend(backend)
|
|
45
50
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
46
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
51
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
52
|
+
'<div class="outer"><span class="inner"></span></div>',
|
|
53
|
+
)
|
|
47
54
|
})
|
|
48
55
|
|
|
49
|
-
test('
|
|
56
|
+
test('using behaviors', () => {
|
|
50
57
|
const env = new MiniProgramEnv()
|
|
51
|
-
const globalCodeSpace = env.getGlobalCodeSpace()
|
|
52
|
-
globalCodeSpace.getComponentSpace().define('external')
|
|
53
|
-
.options({
|
|
54
|
-
virtualHost: true,
|
|
55
|
-
})
|
|
56
|
-
.template(tmpl(`
|
|
57
|
-
<span class="inner" />
|
|
58
|
-
`))
|
|
59
|
-
.registerComponent()
|
|
60
|
-
globalCodeSpace.getComponentSpace().exportComponent('external', 'external')
|
|
61
58
|
const codeSpace = env.createCodeSpace('', true)
|
|
62
59
|
|
|
63
|
-
codeSpace.addComponentStaticConfig('path/to/comp', {
|
|
64
|
-
usingComponents: {
|
|
65
|
-
external: 'external',
|
|
66
|
-
},
|
|
67
|
-
})
|
|
60
|
+
codeSpace.addComponentStaticConfig('path/to/comp', {})
|
|
68
61
|
|
|
69
|
-
codeSpace.addCompiledTemplate(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
codeSpace.addCompiledTemplate(
|
|
63
|
+
'path/to/comp',
|
|
64
|
+
tmpl(`
|
|
65
|
+
<div>{{ num }}</div>
|
|
66
|
+
`),
|
|
67
|
+
)
|
|
74
68
|
|
|
75
|
-
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
76
|
-
|
|
69
|
+
codeSpace.componentEnv('path/to/comp', ({ Behavior, Component }) => {
|
|
70
|
+
const beh = Behavior({ data: { num: 123 } })
|
|
71
|
+
Component().behavior(beh).register()
|
|
77
72
|
})
|
|
78
73
|
|
|
79
74
|
const backend = new glassEasel.domlikeBackend.CurrentWindowBackendContext()
|
|
80
75
|
const ab = env.associateBackend(backend)
|
|
81
76
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
82
|
-
expect(domHtml(root.getComponent())).toBe('<div
|
|
77
|
+
expect(domHtml(root.getComponent())).toBe('<div>123</div>')
|
|
83
78
|
})
|
|
84
79
|
|
|
85
80
|
test('multiple code spaces', () => {
|
|
@@ -118,13 +113,16 @@ describe('env', () => {
|
|
|
118
113
|
'c-b': 'plugin-private://plugin-2-id/inner-comp-2',
|
|
119
114
|
},
|
|
120
115
|
})
|
|
121
|
-
codeSpace.addCompiledTemplate(
|
|
116
|
+
codeSpace.addCompiledTemplate(
|
|
117
|
+
'path/to/comp',
|
|
118
|
+
tmpl(`
|
|
122
119
|
<c-a />
|
|
123
120
|
<c-aa />
|
|
124
121
|
<i-a />
|
|
125
122
|
<i-b />
|
|
126
123
|
<c-b />
|
|
127
|
-
`)
|
|
124
|
+
`),
|
|
125
|
+
)
|
|
128
126
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
129
127
|
Component().register()
|
|
130
128
|
})
|
|
@@ -136,6 +134,8 @@ describe('env', () => {
|
|
|
136
134
|
const backend = new glassEasel.domlikeBackend.CurrentWindowBackendContext()
|
|
137
135
|
const ab = env.associateBackend(backend)
|
|
138
136
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
139
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
137
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
138
|
+
'<c-a>A</c-a><c-aa>A</c-aa><i-a></i-a><i-b></i-b><c-b>B</c-b>',
|
|
139
|
+
)
|
|
140
140
|
})
|
|
141
141
|
})
|