glass-easel-miniprogram-adapter 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +4 -0
- package/dist/glass_easel_miniprogram_adapter.d.ts +872 -1
- package/dist/glass_easel_miniprogram_adapter.es.js +2 -0
- package/dist/glass_easel_miniprogram_adapter.es.js.map +1 -0
- package/dist/glass_easel_miniprogram_adapter.js +2 -2
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/jest.config.js +7 -4
- package/package.json +8 -6
- package/rollup.config.ts +83 -0
- package/src/backend.ts +7 -3
- package/src/behavior.ts +8 -2
- package/src/builder/base_behavior_builder.ts +437 -0
- package/src/builder/behavior_builder.ts +265 -0
- package/src/builder/component_builder.ts +337 -0
- package/src/builder/index.ts +2 -0
- package/src/builder/type_utils.ts +98 -0
- package/src/component.ts +10 -7
- package/src/env.ts +73 -0
- package/src/index.ts +3 -77
- package/src/intersection.ts +2 -2
- package/src/media_query.ts +4 -6
- package/src/selector_query.ts +3 -3
- package/src/space.ts +11 -1030
- package/src/types.ts +7 -5
- package/tests/base/env.ts +1 -1
- package/tests/env.test.ts +3 -3
- package/tests/selector.test.ts +137 -14
- package/tests/space.test.ts +8 -14
- package/tsconfig.json +1 -3
- package/dist/types/src/backend.d.ts +0 -59
- package/dist/types/src/backend.d.ts.map +0 -1
- package/dist/types/src/behavior.d.ts +0 -35
- package/dist/types/src/behavior.d.ts.map +0 -1
- package/dist/types/src/component.d.ts +0 -170
- package/dist/types/src/component.d.ts.map +0 -1
- package/dist/types/src/index.d.ts +0 -58
- package/dist/types/src/index.d.ts.map +0 -1
- package/dist/types/src/intersection.d.ts +0 -24
- package/dist/types/src/intersection.d.ts.map +0 -1
- package/dist/types/src/media_query.d.ts +0 -13
- package/dist/types/src/media_query.d.ts.map +0 -1
- package/dist/types/src/selector_query.d.ts +0 -98
- package/dist/types/src/selector_query.d.ts.map +0 -1
- package/dist/types/src/space.d.ts +0 -369
- package/dist/types/src/space.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -77
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/utils.d.ts +0 -2
- package/dist/types/src/utils.d.ts.map +0 -1
- package/dist/types/tests/base/env.d.ts +0 -3
- package/dist/types/tests/base/env.d.ts.map +0 -1
- package/dist/types/tests/data_update.test.d.ts +0 -2
- package/dist/types/tests/data_update.test.d.ts.map +0 -1
- package/dist/types/tests/env.test.d.ts +0 -2
- package/dist/types/tests/env.test.d.ts.map +0 -1
- package/dist/types/tests/selector.test.d.ts +0 -2
- package/dist/types/tests/selector.test.d.ts.map +0 -1
- package/dist/types/tests/space.test.d.ts +0 -2
- package/dist/types/tests/space.test.d.ts.map +0 -1
- package/dist/types/tests/trait_behavior.test.d.ts +0 -2
- package/dist/types/tests/trait_behavior.test.d.ts.map +0 -1
- package/webpack.config.js +0 -79
package/src/component.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as glassEasel from 'glass-easel'
|
|
2
|
-
import { utils as typeUtils } from './types'
|
|
3
|
-
import { ComponentType, GeneralBehavior, TraitBehavior } from './behavior'
|
|
2
|
+
import { type utils as typeUtils } from './types'
|
|
3
|
+
import { type ComponentType, type GeneralBehavior, type TraitBehavior } from './behavior'
|
|
4
4
|
import { SelectorQuery } from './selector_query'
|
|
5
5
|
import { IntersectionObserver } from './intersection'
|
|
6
6
|
import { MediaQueryObserver } from './media_query'
|
|
@@ -18,7 +18,7 @@ type ExportType<
|
|
|
18
18
|
UProperty extends PropertyList,
|
|
19
19
|
UMethod extends MethodList,
|
|
20
20
|
UComponentExport,
|
|
21
|
-
> = UComponentExport extends
|
|
21
|
+
> = [UComponentExport] extends [never]
|
|
22
22
|
? Component<UData, UProperty, UMethod, UComponentExport>
|
|
23
23
|
: UComponentExport
|
|
24
24
|
|
|
@@ -52,7 +52,7 @@ const filterComponentExport = (
|
|
|
52
52
|
source: ComponentCaller<any, any, any, any>,
|
|
53
53
|
elem: glassEasel.Element,
|
|
54
54
|
): any => {
|
|
55
|
-
if (
|
|
55
|
+
if (glassEasel.Component.isComponent(elem)) {
|
|
56
56
|
const selectedSpace = elem.getRootBehavior().ownerSpace
|
|
57
57
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
58
58
|
const uncheckedCaller = elem.getMethodCaller()
|
|
@@ -131,7 +131,7 @@ export class ComponentCaller<
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/** The component data and property values */
|
|
134
|
-
get data(): AllData<TData, TProperty
|
|
134
|
+
get data(): typeUtils.Merge<AllData<TData, TProperty>> {
|
|
135
135
|
return this._$.data
|
|
136
136
|
}
|
|
137
137
|
set data(value: AllData<TData, TProperty>) {
|
|
@@ -144,7 +144,7 @@ export class ComponentCaller<
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/** The component data and property values (same as `data` ) */
|
|
147
|
-
get properties(): AllData<TData, TProperty
|
|
147
|
+
get properties(): typeUtils.Merge<AllData<TData, TProperty>> {
|
|
148
148
|
return this._$.data
|
|
149
149
|
}
|
|
150
150
|
set properties(value: AllData<TData, TProperty>) {
|
|
@@ -477,7 +477,10 @@ export class ComponentProto<
|
|
|
477
477
|
> {
|
|
478
478
|
private proto: Component<TData, TProperty, TMethod, TComponentExport>
|
|
479
479
|
|
|
480
|
-
constructor(
|
|
480
|
+
constructor(
|
|
481
|
+
methods: TMethod,
|
|
482
|
+
componentExport?: (source: GeneralComponent | null) => TComponentExport,
|
|
483
|
+
) {
|
|
481
484
|
this.proto = Object.create(ComponentCaller.prototype) as Component<
|
|
482
485
|
TData,
|
|
483
486
|
TProperty,
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as glassEasel from 'glass-easel'
|
|
2
|
+
import { AssociatedBackend } from './backend'
|
|
3
|
+
import { CodeSpace } from './space'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A mini-program API environment
|
|
7
|
+
*
|
|
8
|
+
* Each environment manages multiple backend contexts.
|
|
9
|
+
* However, a backend context should be exclusively managed by a single environment
|
|
10
|
+
* (to avoid `StyleScopeId` confliction).
|
|
11
|
+
* It is able to create multiple `CodeSpace` within the environment.
|
|
12
|
+
*/
|
|
13
|
+
export class MiniProgramEnv {
|
|
14
|
+
private codeSpaceMap: { [id: string]: CodeSpace }
|
|
15
|
+
private globalCodeSpace: CodeSpace
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create an empty mini-program API environment
|
|
19
|
+
*/
|
|
20
|
+
constructor() {
|
|
21
|
+
this.codeSpaceMap = Object.create(null) as { [id: string]: CodeSpace }
|
|
22
|
+
this.globalCodeSpace = new CodeSpace(this, false, {})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get a global code space in which global components can be defined
|
|
27
|
+
*
|
|
28
|
+
* External glass-easel based components can be defined in this code space.
|
|
29
|
+
* All global components should be defined before any other `CodeSpace` created!
|
|
30
|
+
*/
|
|
31
|
+
getGlobalCodeSpace(): CodeSpace {
|
|
32
|
+
return this.globalCodeSpace
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Associate a backend context
|
|
37
|
+
*
|
|
38
|
+
* If `backendContext` is not given, the DOM-based backend is used
|
|
39
|
+
* (causes failure if running outside browsers).
|
|
40
|
+
* The backend context SHOULD NOT be associated by other environments!
|
|
41
|
+
*/
|
|
42
|
+
associateBackend(backendContent?: glassEasel.GeneralBackendContext): AssociatedBackend {
|
|
43
|
+
const ctx = backendContent ?? new glassEasel.CurrentWindowBackendContext()
|
|
44
|
+
return new AssociatedBackend(this, ctx)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a component space that can manage WXML, WXSS, JS and static JSON config files
|
|
49
|
+
*
|
|
50
|
+
* The space can be specified as a *main* space.
|
|
51
|
+
* This makes some features available:
|
|
52
|
+
* * the `app.wxss` will be used as a style sheet for all root components in the space;
|
|
53
|
+
* * the `StyleIsolation.Shared` is accepted for components in the space.
|
|
54
|
+
* Non-main spaces usually act as plugins.
|
|
55
|
+
* `publicComponents` is a map for specifying a map of aliases and component paths.
|
|
56
|
+
*/
|
|
57
|
+
createCodeSpace(
|
|
58
|
+
id: string,
|
|
59
|
+
isMainSpace: boolean,
|
|
60
|
+
publicComponents = Object.create(null) as { [alias: string]: string },
|
|
61
|
+
): CodeSpace {
|
|
62
|
+
const cs = new CodeSpace(this, isMainSpace, publicComponents, this.globalCodeSpace)
|
|
63
|
+
this.codeSpaceMap[id] = cs
|
|
64
|
+
return cs
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get a component space by the `id` specified when created
|
|
69
|
+
*/
|
|
70
|
+
getCodeSpace(id: string): CodeSpace | undefined {
|
|
71
|
+
return this.codeSpaceMap[id]
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,80 +1,6 @@
|
|
|
1
|
-
import * as glassEasel from 'glass-easel'
|
|
2
|
-
import { AssociatedBackend } from './backend'
|
|
3
|
-
import { CodeSpace } from './space'
|
|
4
|
-
|
|
5
1
|
export * as glassEasel from 'glass-easel'
|
|
6
|
-
export * as types from './types'
|
|
7
|
-
export { StyleIsolation } from './types'
|
|
8
|
-
export * from './space'
|
|
9
2
|
export { AssociatedBackend, Root } from './backend'
|
|
10
3
|
export * as component from './component'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Each environment manages multiple backend contexts.
|
|
16
|
-
* However, a backend context should be exclusively managed by a single environment
|
|
17
|
-
* (to avoid `StyleScopeId` confliction).
|
|
18
|
-
* It is able to create multiple `CodeSpace` within the environment.
|
|
19
|
-
*/
|
|
20
|
-
export class MiniProgramEnv {
|
|
21
|
-
private codeSpaceMap: { [id: string]: CodeSpace }
|
|
22
|
-
private globalCodeSpace: CodeSpace
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Create an empty mini-program API environment
|
|
26
|
-
*/
|
|
27
|
-
constructor() {
|
|
28
|
-
this.codeSpaceMap = Object.create(null) as { [id: string]: CodeSpace }
|
|
29
|
-
this.globalCodeSpace = new CodeSpace(this, false, {})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get a global code space in which global components can be defined
|
|
34
|
-
*
|
|
35
|
-
* External glass-easel based components can be defined in this code space.
|
|
36
|
-
* All global components should be defined before any other `CodeSpace` created!
|
|
37
|
-
*/
|
|
38
|
-
getGlobalCodeSpace(): CodeSpace {
|
|
39
|
-
return this.globalCodeSpace
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Associate a backend context
|
|
44
|
-
*
|
|
45
|
-
* If `backendContext` is not given, the DOM-based backend is used
|
|
46
|
-
* (causes failure if running outside browsers).
|
|
47
|
-
* The backend context SHOULD NOT be associated by other environments!
|
|
48
|
-
*/
|
|
49
|
-
associateBackend(backendContent?: glassEasel.GeneralBackendContext): AssociatedBackend {
|
|
50
|
-
const ctx = backendContent ?? new glassEasel.domlikeBackend.CurrentWindowBackendContext()
|
|
51
|
-
return new AssociatedBackend(this, ctx)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Create a component space that can manage WXML, WXSS, JS and static JSON config files
|
|
56
|
-
*
|
|
57
|
-
* The space can be specified as a *main* space.
|
|
58
|
-
* This makes some features available:
|
|
59
|
-
* * the `app.wxss` will be used as a style sheet for all root components in the space;
|
|
60
|
-
* * the `StyleIsolation.Shared` is accepted for components in the space.
|
|
61
|
-
* Non-main spaces usually act as plugins.
|
|
62
|
-
* `publicComponents` is a map for specifying a map of aliases and component paths.
|
|
63
|
-
*/
|
|
64
|
-
createCodeSpace(
|
|
65
|
-
id: string,
|
|
66
|
-
isMainSpace: boolean,
|
|
67
|
-
publicComponents = Object.create(null) as { [alias: string]: string },
|
|
68
|
-
): CodeSpace {
|
|
69
|
-
const cs = new CodeSpace(this, isMainSpace, publicComponents, this.globalCodeSpace)
|
|
70
|
-
this.codeSpaceMap[id] = cs
|
|
71
|
-
return cs
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Get a component space by the `id` specified when created
|
|
76
|
-
*/
|
|
77
|
-
getCodeSpace(id: string): CodeSpace | undefined {
|
|
78
|
-
return this.codeSpaceMap[id]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
4
|
+
export { MiniProgramEnv } from './env'
|
|
5
|
+
export * from './space'
|
|
6
|
+
export * as types from './types'
|
package/src/intersection.ts
CHANGED
package/src/media_query.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as glassEasel from 'glass-easel'
|
|
2
|
-
import { GeneralComponent } from './component'
|
|
1
|
+
import type * as glassEasel from 'glass-easel'
|
|
2
|
+
import { type GeneralComponent } from './component'
|
|
3
3
|
|
|
4
4
|
export class MediaQueryObserver {
|
|
5
5
|
private _$comp: GeneralComponent
|
|
@@ -15,10 +15,8 @@ export class MediaQueryObserver {
|
|
|
15
15
|
listener: (status: { matches: boolean }) => void,
|
|
16
16
|
) {
|
|
17
17
|
if (this._$observer) this._$observer.disconnect()
|
|
18
|
-
this._$observer =
|
|
19
|
-
descriptor,
|
|
20
|
-
listener,
|
|
21
|
-
)
|
|
18
|
+
this._$observer =
|
|
19
|
+
this._$comp._$.getBackendContext()?.createMediaQueryObserver?.(descriptor, listener) || null
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
disconnect() {
|
package/src/selector_query.ts
CHANGED
|
@@ -220,8 +220,8 @@ export class SelectorQuery {
|
|
|
220
220
|
[
|
|
221
221
|
(done) => {
|
|
222
222
|
const ctx = component._$.getBackendContext()
|
|
223
|
-
const width = ctx.getWindowWidth()
|
|
224
|
-
const height = ctx.getWindowHeight()
|
|
223
|
+
const width = ctx ? ctx.getWindowWidth() : 0
|
|
224
|
+
const height = ctx ? ctx.getWindowHeight() : 0
|
|
225
225
|
if (fields.id) res.id = ''
|
|
226
226
|
if (fields.dataset) res.dataset = {}
|
|
227
227
|
if (fields.mark) res.mark = {}
|
|
@@ -301,7 +301,7 @@ export class SelectorQuery {
|
|
|
301
301
|
],
|
|
302
302
|
() => {
|
|
303
303
|
if (fields.properties) {
|
|
304
|
-
if (
|
|
304
|
+
if (glassEasel.Component.isComponent(elem)) {
|
|
305
305
|
fields.properties.forEach((propName) => {
|
|
306
306
|
if (glassEasel.Component.hasProperty(elem, propName)) {
|
|
307
307
|
const ds = elem.getComponentOptions().propertyPassingDeepCopy
|