glass-easel 0.1.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/README.md +40 -0
- package/dist/glass_easel.all.d.ts +1 -0
- package/dist/glass_easel.all.js +2 -0
- package/dist/glass_easel.all.js.map +1 -0
- package/dist/glass_easel.domlike.global.d.ts +1 -0
- package/dist/glass_easel.domlike.global.js +2 -0
- package/dist/glass_easel.domlike.global.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/src/backend/backend_protocol.d.ts +119 -0
- package/dist/types/src/backend/backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/composed_backend_protocol.d.ts +90 -0
- package/dist/types/src/backend/composed_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/domlike_backend_protocol.d.ts +76 -0
- package/dist/types/src/backend/domlike_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/mode.d.ts +46 -0
- package/dist/types/src/backend/mode.d.ts.map +1 -0
- package/dist/types/src/backend/suggested_backend_protocol.d.ts +30 -0
- package/dist/types/src/backend/suggested_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/behavior.d.ts +428 -0
- package/dist/types/src/behavior.d.ts.map +1 -0
- package/dist/types/src/class_list.d.ts +79 -0
- package/dist/types/src/class_list.d.ts.map +1 -0
- package/dist/types/src/component.d.ts +291 -0
- package/dist/types/src/component.d.ts.map +1 -0
- package/dist/types/src/component_params.d.ts +239 -0
- package/dist/types/src/component_params.d.ts.map +1 -0
- package/dist/types/src/component_space.d.ts +164 -0
- package/dist/types/src/component_space.d.ts.map +1 -0
- package/dist/types/src/data_path.d.ts +5 -0
- package/dist/types/src/data_path.d.ts.map +1 -0
- package/dist/types/src/data_proxy.d.ts +107 -0
- package/dist/types/src/data_proxy.d.ts.map +1 -0
- package/dist/types/src/data_utils.d.ts +3 -0
- package/dist/types/src/data_utils.d.ts.map +1 -0
- package/dist/types/src/element.d.ts +275 -0
- package/dist/types/src/element.d.ts.map +1 -0
- package/dist/types/src/element_iterator.d.ts +43 -0
- package/dist/types/src/element_iterator.d.ts.map +1 -0
- package/dist/types/src/event.d.ts +104 -0
- package/dist/types/src/event.d.ts.map +1 -0
- package/dist/types/src/external_shadow_tree.d.ts +20 -0
- package/dist/types/src/external_shadow_tree.d.ts.map +1 -0
- package/dist/types/src/func_arr.d.ts +39 -0
- package/dist/types/src/func_arr.d.ts.map +1 -0
- package/dist/types/src/global_options.d.ts +111 -0
- package/dist/types/src/global_options.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +43 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/mutation_observer.d.ts +79 -0
- package/dist/types/src/mutation_observer.d.ts.map +1 -0
- package/dist/types/src/native_node.d.ts +8 -0
- package/dist/types/src/native_node.d.ts.map +1 -0
- package/dist/types/src/node.d.ts +49 -0
- package/dist/types/src/node.d.ts.map +1 -0
- package/dist/types/src/relation.d.ts +47 -0
- package/dist/types/src/relation.d.ts.map +1 -0
- package/dist/types/src/render.d.ts +3 -0
- package/dist/types/src/render.d.ts.map +1 -0
- package/dist/types/src/selector.d.ts +32 -0
- package/dist/types/src/selector.d.ts.map +1 -0
- package/dist/types/src/shadow_root.d.ts +136 -0
- package/dist/types/src/shadow_root.d.ts.map +1 -0
- package/dist/types/src/template_engine.d.ts +18 -0
- package/dist/types/src/template_engine.d.ts.map +1 -0
- package/dist/types/src/text_node.d.ts +32 -0
- package/dist/types/src/text_node.d.ts.map +1 -0
- package/dist/types/src/tmpl/index.d.ts +18 -0
- package/dist/types/src/tmpl/index.d.ts.map +1 -0
- package/dist/types/src/tmpl/native_rendering.d.ts +45 -0
- package/dist/types/src/tmpl/native_rendering.d.ts.map +1 -0
- package/dist/types/src/tmpl/proc_gen_wrapper.d.ts +80 -0
- package/dist/types/src/tmpl/proc_gen_wrapper.d.ts.map +1 -0
- package/dist/types/src/tmpl/proc_gen_wrapper_dom.d.ts +50 -0
- package/dist/types/src/tmpl/proc_gen_wrapper_dom.d.ts.map +1 -0
- package/dist/types/src/tmpl/range_list_diff.d.ts +19 -0
- package/dist/types/src/tmpl/range_list_diff.d.ts.map +1 -0
- package/dist/types/src/trait_behaviors.d.ts +38 -0
- package/dist/types/src/trait_behaviors.d.ts.map +1 -0
- package/dist/types/src/virtual_node.d.ts +10 -0
- package/dist/types/src/virtual_node.d.ts.map +1 -0
- package/dist/types/tests/backend/domlike.test.d.ts +2 -0
- package/dist/types/tests/backend/domlike.test.d.ts.map +1 -0
- package/dist/types/tests/base/env.d.ts +29 -0
- package/dist/types/tests/base/env.d.ts.map +1 -0
- package/dist/types/tests/base/match.d.ts +9 -0
- package/dist/types/tests/base/match.d.ts.map +1 -0
- package/dist/types/tests/core/backend.test.d.ts +2 -0
- package/dist/types/tests/core/backend.test.d.ts.map +1 -0
- package/dist/types/tests/core/behavior.test.d.ts +2 -0
- package/dist/types/tests/core/behavior.test.d.ts.map +1 -0
- package/dist/types/tests/core/component_space.test.d.ts +2 -0
- package/dist/types/tests/core/component_space.test.d.ts.map +1 -0
- package/dist/types/tests/core/data_update.test.d.ts +2 -0
- package/dist/types/tests/core/data_update.test.d.ts.map +1 -0
- package/dist/types/tests/core/misc.test.d.ts +2 -0
- package/dist/types/tests/core/misc.test.d.ts.map +1 -0
- package/dist/types/tests/core/placeholder.test.d.ts +2 -0
- package/dist/types/tests/core/placeholder.test.d.ts.map +1 -0
- package/dist/types/tests/core/slot.test.d.ts +2 -0
- package/dist/types/tests/core/slot.test.d.ts.map +1 -0
- package/dist/types/tests/core/trait_behaviors.test.d.ts +2 -0
- package/dist/types/tests/core/trait_behaviors.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/binding_map.test.d.ts +2 -0
- package/dist/types/tests/tmpl/binding_map.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/event.test.d.ts +2 -0
- package/dist/types/tests/tmpl/event.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/expression.test.d.ts +2 -0
- package/dist/types/tests/tmpl/expression.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/lvalue.test.d.ts +2 -0
- package/dist/types/tests/tmpl/lvalue.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/native_rendering.test.d.ts +2 -0
- package/dist/types/tests/tmpl/native_rendering.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/structure.test.d.ts +2 -0
- package/dist/types/tests/tmpl/structure.test.d.ts.map +1 -0
- package/dist/types/tests/types/chaining.test.d.ts +2 -0
- package/dist/types/tests/types/chaining.test.d.ts.map +1 -0
- package/dist/types/tests/types/createElement.test.d.ts +2 -0
- package/dist/types/tests/types/createElement.test.d.ts.map +1 -0
- package/dist/types/tests/types/definition.test.d.ts +2 -0
- package/dist/types/tests/types/definition.test.d.ts.map +1 -0
- package/guide/zh_CN/advanced/binding_map_update.md +32 -0
- package/guide/zh_CN/advanced/build_args.md +28 -0
- package/guide/zh_CN/advanced/component_filter.md +70 -0
- package/guide/zh_CN/advanced/component_space.md +124 -0
- package/guide/zh_CN/advanced/custom_backend.md +53 -0
- package/guide/zh_CN/advanced/error_listener.md +32 -0
- package/guide/zh_CN/advanced/external_component.md +73 -0
- package/guide/zh_CN/advanced/template_engine.md +61 -0
- package/guide/zh_CN/appendix/backend_protocol.md +501 -0
- package/guide/zh_CN/appendix/list_diff_algorithm.md +406 -0
- package/guide/zh_CN/basic/beginning.md +94 -0
- package/guide/zh_CN/basic/component.md +156 -0
- package/guide/zh_CN/basic/event.md +169 -0
- package/guide/zh_CN/basic/lifetime.md +66 -0
- package/guide/zh_CN/basic/method.md +62 -0
- package/guide/zh_CN/basic/template.md +135 -0
- package/guide/zh_CN/data_management/advanced_update.md +170 -0
- package/guide/zh_CN/data_management/data_deep_copy.md +157 -0
- package/guide/zh_CN/data_management/data_observer.md +154 -0
- package/guide/zh_CN/data_management/property_early_init.md +31 -0
- package/guide/zh_CN/data_management/pure_data_pattern.md +21 -0
- package/guide/zh_CN/index.md +93 -0
- package/guide/zh_CN/interaction/behavior.md +52 -0
- package/guide/zh_CN/interaction/component_path.md +37 -0
- package/guide/zh_CN/interaction/generic.md +73 -0
- package/guide/zh_CN/interaction/placeholder.md +40 -0
- package/guide/zh_CN/interaction/relation.md +151 -0
- package/guide/zh_CN/interaction/slot.md +137 -0
- package/guide/zh_CN/interaction/template_import.md +94 -0
- package/guide/zh_CN/interaction/trait_behavior.md +117 -0
- package/guide/zh_CN/styling/external_class.md +46 -0
- package/guide/zh_CN/styling/style_isolation.md +54 -0
- package/guide/zh_CN/styling/virtual_host.md +52 -0
- package/guide/zh_CN/tree/element_iterator.md +54 -0
- package/guide/zh_CN/tree/mutation_observer.md +52 -0
- package/guide/zh_CN/tree/node_tree.md +142 -0
- package/guide/zh_CN/tree/node_tree_modification.md +78 -0
- package/guide/zh_CN/tree/selector.md +66 -0
- package/jest.config.js +6 -0
- package/jest.dts.config.js +9 -0
- package/jest.unit.config.js +14 -0
- package/package.json +28 -0
- package/src/backend/backend_protocol.ts +313 -0
- package/src/backend/composed_backend_protocol.ts +252 -0
- package/src/backend/domlike_backend_protocol.ts +370 -0
- package/src/backend/mode.ts +51 -0
- package/src/backend/suggested_backend_protocol.ts +83 -0
- package/src/behavior.ts +1655 -0
- package/src/bootstrap_dom_dev.js +22 -0
- package/src/class_list.ts +376 -0
- package/src/component.ts +1309 -0
- package/src/component_params.ts +461 -0
- package/src/component_space.ts +547 -0
- package/src/data_path.ts +225 -0
- package/src/data_proxy.ts +670 -0
- package/src/data_utils.ts +50 -0
- package/src/element.ts +1966 -0
- package/src/element_iterator.ts +158 -0
- package/src/event.ts +401 -0
- package/src/external_shadow_tree.ts +27 -0
- package/src/func_arr.ts +198 -0
- package/src/global_options.ts +242 -0
- package/src/index.ts +187 -0
- package/src/mutation_observer.ts +252 -0
- package/src/native_node.ts +74 -0
- package/src/node.ts +174 -0
- package/src/relation.ts +380 -0
- package/src/render.ts +25 -0
- package/src/selector.ts +218 -0
- package/src/shadow_root.ts +766 -0
- package/src/template_engine.ts +45 -0
- package/src/text_node.ts +149 -0
- package/src/tmpl/index.ts +199 -0
- package/src/tmpl/native_rendering.ts +175 -0
- package/src/tmpl/proc_gen_wrapper.ts +954 -0
- package/src/tmpl/proc_gen_wrapper_dom.ts +230 -0
- package/src/tmpl/range_list_diff.ts +443 -0
- package/src/trait_behaviors.ts +51 -0
- package/src/virtual_node.ts +51 -0
- package/tests/backend/domlike.test.ts +254 -0
- package/tests/base/env.ts +78 -0
- package/tests/base/match.ts +185 -0
- package/tests/core/backend.test.ts +144 -0
- package/tests/core/behavior.test.ts +546 -0
- package/tests/core/component_space.test.ts +212 -0
- package/tests/core/data_update.test.ts +461 -0
- package/tests/core/misc.test.ts +339 -0
- package/tests/core/placeholder.test.ts +180 -0
- package/tests/core/slot.test.ts +1495 -0
- package/tests/core/trait_behaviors.test.ts +153 -0
- package/tests/legacy/README.md +3 -0
- package/tests/legacy/behavior.test.js +293 -0
- package/tests/legacy/component.test.js +1247 -0
- package/tests/legacy/data_path.test.js +149 -0
- package/tests/legacy/data_proxy.test.js +759 -0
- package/tests/legacy/element_iterator.test.js +148 -0
- package/tests/legacy/event.test.js +849 -0
- package/tests/legacy/external.test.js +510 -0
- package/tests/legacy/extra_info.test.js +109 -0
- package/tests/legacy/generics.test.js +176 -0
- package/tests/legacy/mutation_observer.test.js +210 -0
- package/tests/legacy/relation.test.js +517 -0
- package/tests/legacy/selector.test.js +263 -0
- package/tests/legacy/slot.test.js +915 -0
- package/tests/legacy/virtual.test.js +394 -0
- package/tests/tmpl/binding_map.test.ts +208 -0
- package/tests/tmpl/event.test.ts +206 -0
- package/tests/tmpl/expression.test.ts +429 -0
- package/tests/tmpl/lvalue.test.ts +160 -0
- package/tests/tmpl/native_rendering.test.ts +155 -0
- package/tests/tmpl/structure.test.ts +998 -0
- package/tests/types/chaining.test.ts +614 -0
- package/tests/types/createElement.test.ts +82 -0
- package/tests/types/definition.test.ts +442 -0
- package/tsconfig.json +11 -0
- package/webpack.config.js +270 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
4
|
+
import { expectType } from 'tsd'
|
|
5
|
+
import * as glassEasel from '../../src'
|
|
6
|
+
|
|
7
|
+
const componentSpace = glassEasel.getDefaultComponentSpace()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Properties
|
|
11
|
+
*/
|
|
12
|
+
componentSpace
|
|
13
|
+
.define()
|
|
14
|
+
.property('propStr', String)
|
|
15
|
+
.property('propNum', Number)
|
|
16
|
+
.property('propBool', Boolean)
|
|
17
|
+
.property('propObj', Object)
|
|
18
|
+
.property('propObjFoo', {
|
|
19
|
+
type: Object,
|
|
20
|
+
value: { foo: 'foo' },
|
|
21
|
+
observer: (newProp, oldProp) => {
|
|
22
|
+
expectType<{ readonly foo: string }>(newProp)
|
|
23
|
+
expectType<string>(newProp.foo)
|
|
24
|
+
expectType<{ readonly foo: string }>(oldProp)
|
|
25
|
+
expectType<string>(oldProp.foo)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.property('propObjBar', {
|
|
29
|
+
default: () => ({ bar: 'bar' }),
|
|
30
|
+
})
|
|
31
|
+
.property('propFunc', Function)
|
|
32
|
+
.property('propFuncFoo', {
|
|
33
|
+
value: () => 'foo',
|
|
34
|
+
})
|
|
35
|
+
.property('propArr', Array)
|
|
36
|
+
.property('propArrBooks', {
|
|
37
|
+
value: [] as { name: string }[],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
.property('propOptional', {
|
|
41
|
+
optionalTypes: [String, Number, Boolean],
|
|
42
|
+
})
|
|
43
|
+
.property('propOptionalFoo', {
|
|
44
|
+
optionalTypes: [String, Number, Boolean],
|
|
45
|
+
value: 'foo' as const,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
.property('propNull', null)
|
|
49
|
+
.init(({ data }) => {
|
|
50
|
+
expectType<string>(data.propStr)
|
|
51
|
+
expectType<number>(data.propNum)
|
|
52
|
+
expectType<boolean>(data.propBool)
|
|
53
|
+
expectType<Readonly<Record<string, any>> | null>(data.propObj)
|
|
54
|
+
expectType<{ readonly foo: string }>(data.propObjFoo)
|
|
55
|
+
expectType<string>(data.propObjFoo.foo)
|
|
56
|
+
expectType<{ readonly bar: string }>(data.propObjBar)
|
|
57
|
+
expectType<string>(data.propObjBar.bar)
|
|
58
|
+
expectType<(...args: any[]) => any>(data.propFunc)
|
|
59
|
+
expectType<() => 'foo'>(data.propFuncFoo)
|
|
60
|
+
expectType<readonly any[]>(data.propArr)
|
|
61
|
+
expectType<readonly { readonly name: string }[]>(data.propArrBooks)
|
|
62
|
+
|
|
63
|
+
expectType<string | number | boolean>(data.propOptional)
|
|
64
|
+
expectType<number | boolean | 'foo'>(data.propOptionalFoo)
|
|
65
|
+
|
|
66
|
+
expectType<any>(data.propNull)
|
|
67
|
+
|
|
68
|
+
// @ts-expect-error
|
|
69
|
+
expectType<any>(data.nonExists)
|
|
70
|
+
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
data.propStr = '123'
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
data.propObjFoo.foo = '123'
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
componentSpace.define().property('invalid', {
|
|
78
|
+
type: String,
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
value: 123,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
componentSpace
|
|
84
|
+
.define()
|
|
85
|
+
.property('duplicate', String)
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
.property('duplicate', String)
|
|
88
|
+
|
|
89
|
+
componentSpace.define().property('invalid', {
|
|
90
|
+
// @ts-expect-error
|
|
91
|
+
type: '123',
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
optionalTypes: {},
|
|
94
|
+
// @ts-expect-error
|
|
95
|
+
observer: true,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
componentSpace.define().init(({ data }) => {
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
expectType<any>(data.non_exists)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Data
|
|
105
|
+
*/
|
|
106
|
+
componentSpace
|
|
107
|
+
.define()
|
|
108
|
+
.data(() => ({
|
|
109
|
+
str: '123',
|
|
110
|
+
num: 123,
|
|
111
|
+
bool: true,
|
|
112
|
+
foo: {
|
|
113
|
+
foo: 'foo',
|
|
114
|
+
},
|
|
115
|
+
func: () => 'foo',
|
|
116
|
+
arr: [1],
|
|
117
|
+
books: [{ name: 'book' }],
|
|
118
|
+
}))
|
|
119
|
+
.init(({ data }) => {
|
|
120
|
+
expectType<string>(data.str)
|
|
121
|
+
expectType<number>(data.num)
|
|
122
|
+
expectType<boolean>(data.bool)
|
|
123
|
+
expectType<{ readonly foo: string }>(data.foo)
|
|
124
|
+
expectType<() => 'foo'>(data.func)
|
|
125
|
+
expectType<readonly number[]>(data.arr)
|
|
126
|
+
expectType<readonly { readonly name: string }[]>(data.books)
|
|
127
|
+
|
|
128
|
+
// @ts-expect-error
|
|
129
|
+
expectType<any>(data.nonExists)
|
|
130
|
+
|
|
131
|
+
// @ts-expect-error
|
|
132
|
+
data.str = '123'
|
|
133
|
+
// @ts-expect-error
|
|
134
|
+
data.foo.foo = '123'
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
componentSpace
|
|
138
|
+
.define()
|
|
139
|
+
.property('prop', String)
|
|
140
|
+
.data(function () {
|
|
141
|
+
// @ts-expect-error
|
|
142
|
+
expectType<any>(this.prop)
|
|
143
|
+
return {}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* SetData
|
|
148
|
+
*/
|
|
149
|
+
componentSpace
|
|
150
|
+
.define()
|
|
151
|
+
.data(() => ({
|
|
152
|
+
str: '123',
|
|
153
|
+
}))
|
|
154
|
+
.init(({ setData }) => {
|
|
155
|
+
setData({ str: '123' })
|
|
156
|
+
|
|
157
|
+
// @ts-expect-error
|
|
158
|
+
setData({ str: 123 })
|
|
159
|
+
// @ts-expect-error
|
|
160
|
+
setData({ str: null })
|
|
161
|
+
// @ts-expect-error
|
|
162
|
+
setData({ 'str.length': 123 })
|
|
163
|
+
// @ts-expect-error
|
|
164
|
+
setData({ 'str[0]': 123 })
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
componentSpace
|
|
168
|
+
.define()
|
|
169
|
+
.data(() => ({
|
|
170
|
+
num: 123,
|
|
171
|
+
}))
|
|
172
|
+
.init(({ setData }) => {
|
|
173
|
+
setData({ num: 123 })
|
|
174
|
+
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
setData({ num: '123' })
|
|
177
|
+
// @ts-expect-error
|
|
178
|
+
setData({ num: null })
|
|
179
|
+
// @ts-expect-error
|
|
180
|
+
setData({ 'num.length': 123 })
|
|
181
|
+
// @ts-expect-error
|
|
182
|
+
setData({ 'num[0]': 123 })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
componentSpace
|
|
186
|
+
.define()
|
|
187
|
+
.data(() => ({
|
|
188
|
+
bool: true,
|
|
189
|
+
}))
|
|
190
|
+
.init(({ setData }) => {
|
|
191
|
+
setData({ bool: true })
|
|
192
|
+
|
|
193
|
+
// @ts-expect-error
|
|
194
|
+
setData({ bool: 0 })
|
|
195
|
+
// @ts-expect-error
|
|
196
|
+
setData({ bool: null })
|
|
197
|
+
// @ts-expect-error
|
|
198
|
+
setData({ 'bool.length': 123 })
|
|
199
|
+
// @ts-expect-error
|
|
200
|
+
setData({ 'bool[0]': 123 })
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
componentSpace
|
|
204
|
+
.define()
|
|
205
|
+
.data(() => ({
|
|
206
|
+
obj: {} as Record<string, any> | null,
|
|
207
|
+
}))
|
|
208
|
+
.init(({ setData }) => {
|
|
209
|
+
setData({ obj: {} })
|
|
210
|
+
setData({ obj: null })
|
|
211
|
+
setData({ 'obj.foo': 123 })
|
|
212
|
+
|
|
213
|
+
// @ts-expect-error
|
|
214
|
+
setData({ obj: 0 })
|
|
215
|
+
// @ts-expect-error
|
|
216
|
+
setData({ 'obj[0]': 123 })
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
componentSpace
|
|
220
|
+
.define()
|
|
221
|
+
.data(() => ({
|
|
222
|
+
foo: { foo: 'foo' },
|
|
223
|
+
}))
|
|
224
|
+
.init(({ setData }) => {
|
|
225
|
+
setData({ foo: { foo: 'foo' } })
|
|
226
|
+
setData({ 'foo.foo': '123' })
|
|
227
|
+
|
|
228
|
+
// @ts-expect-error
|
|
229
|
+
setData({ foo: null })
|
|
230
|
+
// @ts-expect-error
|
|
231
|
+
setData({ foo: 0 })
|
|
232
|
+
// @ts-expect-error
|
|
233
|
+
setData({ foo: { foo: 'foo', bar: 'bar' } })
|
|
234
|
+
// @ts-expect-error
|
|
235
|
+
setData({ 'foo[0]': 123 })
|
|
236
|
+
// @ts-expect-error
|
|
237
|
+
setData({ 'foo.foo': 123 })
|
|
238
|
+
// @ts-expect-error
|
|
239
|
+
setData({ 'foo.nonExists': 123 })
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
componentSpace
|
|
243
|
+
.define()
|
|
244
|
+
.data(() => ({
|
|
245
|
+
func: () => 'foo',
|
|
246
|
+
}))
|
|
247
|
+
.init(({ setData }) => {
|
|
248
|
+
setData({ func: () => 'foo' })
|
|
249
|
+
|
|
250
|
+
// @ts-expect-error
|
|
251
|
+
setData({ func: null })
|
|
252
|
+
// @ts-expect-error
|
|
253
|
+
setData({ func: 0 })
|
|
254
|
+
// @ts-expect-error
|
|
255
|
+
setData({ func: (_: any) => 'foo' })
|
|
256
|
+
// @ts-expect-error
|
|
257
|
+
setData({ 'func[0]': 123 })
|
|
258
|
+
// @ts-expect-error
|
|
259
|
+
setData({ 'func.foo': 123 })
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
componentSpace
|
|
263
|
+
.define()
|
|
264
|
+
.data(() => ({
|
|
265
|
+
arr: [] as any[],
|
|
266
|
+
}))
|
|
267
|
+
.init(({ setData }) => {
|
|
268
|
+
setData({ arr: [] })
|
|
269
|
+
setData({ arr: [1, 'foo', true, {}, null, undefined] })
|
|
270
|
+
setData({ 'arr[0]': 123 })
|
|
271
|
+
setData({ 'arr[0].foo': 'foo' })
|
|
272
|
+
|
|
273
|
+
// @ts-expect-error
|
|
274
|
+
setData({ arr: null })
|
|
275
|
+
// @ts-expect-error
|
|
276
|
+
setData({ arr: 0 })
|
|
277
|
+
// @ts-expect-error
|
|
278
|
+
setData({ 'arr.foo': 123 })
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
componentSpace
|
|
282
|
+
.define()
|
|
283
|
+
.data(() => ({
|
|
284
|
+
arrObj: [{ name: 'book' }],
|
|
285
|
+
}))
|
|
286
|
+
.init(({ setData }) => {
|
|
287
|
+
setData({ arrObj: [] })
|
|
288
|
+
setData({ arrObj: [{ name: '123' }, { name: '233' }] })
|
|
289
|
+
setData({ 'arrObj[0]': { name: 'foo' } })
|
|
290
|
+
setData({ 'arrObj[0].name': 'foo' })
|
|
291
|
+
|
|
292
|
+
// @ts-expect-error
|
|
293
|
+
setData({ arrObj: null })
|
|
294
|
+
// @ts-expect-error
|
|
295
|
+
setData({ arrObj: 0 })
|
|
296
|
+
// @ts-expect-error
|
|
297
|
+
setData({ 'arrObj.foo': 123 })
|
|
298
|
+
// @ts-expect-error
|
|
299
|
+
setData({ 'arrObj[0].name': 123 })
|
|
300
|
+
// @ts-expect-error
|
|
301
|
+
setData({ 'arrObj[0].nonExists': 'foo' })
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Observer
|
|
306
|
+
*/
|
|
307
|
+
componentSpace
|
|
308
|
+
.define()
|
|
309
|
+
.data(() => ({
|
|
310
|
+
str: 'foo',
|
|
311
|
+
objFoo: { foo: 'foo' },
|
|
312
|
+
}))
|
|
313
|
+
.init(({ observer }) => {
|
|
314
|
+
observer('str', (newValue) => {
|
|
315
|
+
expectType<string>(newValue)
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
observer('objFoo', (newValue) => {
|
|
319
|
+
expectType<{ readonly foo: string }>(newValue)
|
|
320
|
+
expectType<string>(newValue.foo)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
observer('objFoo.foo', (newValue) => {
|
|
324
|
+
expectType<string>(newValue)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
observer('objFoo.**', (newValue) => {
|
|
328
|
+
expectType<{ readonly foo: string }>(newValue)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
observer(['str', 'objFoo'], (str, objFoo) => {
|
|
332
|
+
expectType<string>(str)
|
|
333
|
+
expectType<{ readonly foo: string }>(objFoo)
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
observer(['str', 'objFoo.**'], (str, objFoo) => {
|
|
337
|
+
expectType<string>(str)
|
|
338
|
+
expectType<{ readonly foo: string }>(objFoo)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
observer('**', (newValue) => {
|
|
342
|
+
expectType<{
|
|
343
|
+
readonly str: string;
|
|
344
|
+
readonly objFoo: {
|
|
345
|
+
readonly foo: string;
|
|
346
|
+
};
|
|
347
|
+
}>(newValue)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
// @ts-expect-error
|
|
351
|
+
observer('nonExists', () => {
|
|
352
|
+
/* */
|
|
353
|
+
})
|
|
354
|
+
// @ts-expect-error
|
|
355
|
+
observer(['str', 'nonExists'], () => {
|
|
356
|
+
/* */
|
|
357
|
+
})
|
|
358
|
+
// @ts-expect-error
|
|
359
|
+
observer('objFoo.**.**', () => {
|
|
360
|
+
/* */
|
|
361
|
+
})
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
componentSpace
|
|
365
|
+
.define()
|
|
366
|
+
.data(() => ({
|
|
367
|
+
str: 'foo',
|
|
368
|
+
objFoo: { foo: 'foo' },
|
|
369
|
+
}))
|
|
370
|
+
.observer('str', (newValue) => {
|
|
371
|
+
expectType<string>(newValue)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
.observer('objFoo', (newValue) => {
|
|
375
|
+
expectType<{ readonly foo: string }>(newValue)
|
|
376
|
+
expectType<string>(newValue.foo)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
.observer('objFoo.foo', (newValue) => {
|
|
380
|
+
expectType<string>(newValue)
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
.observer('objFoo.**', (newValue) => {
|
|
384
|
+
expectType<{ readonly foo: string }>(newValue)
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
.observer(['str', 'objFoo'], (str, objFoo) => {
|
|
388
|
+
expectType<string>(str)
|
|
389
|
+
expectType<{ readonly foo: string }>(objFoo)
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
.observer(['str', 'objFoo.**'], (str, objFoo) => {
|
|
393
|
+
expectType<string>(str)
|
|
394
|
+
expectType<{ readonly foo: string }>(objFoo)
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
.observer('**', (newValue) => {
|
|
398
|
+
expectType<{
|
|
399
|
+
readonly str: string;
|
|
400
|
+
readonly objFoo: {
|
|
401
|
+
readonly foo: string;
|
|
402
|
+
};
|
|
403
|
+
}>(newValue)
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
componentSpace
|
|
407
|
+
.define()
|
|
408
|
+
// @ts-expect-error
|
|
409
|
+
.observer('nonExists', () => {
|
|
410
|
+
/* */
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
// @ts-expect-error
|
|
414
|
+
componentSpace
|
|
415
|
+
.define()
|
|
416
|
+
.data(() => ({
|
|
417
|
+
str: 'foo',
|
|
418
|
+
objFoo: { foo: 'foo' },
|
|
419
|
+
}))
|
|
420
|
+
.observer(['str', 'nonExists'], () => {
|
|
421
|
+
/* */
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
componentSpace
|
|
425
|
+
.define()
|
|
426
|
+
.data(() => ({
|
|
427
|
+
str: 'foo',
|
|
428
|
+
objFoo: { foo: 'foo' },
|
|
429
|
+
}))
|
|
430
|
+
// @ts-expect-errors
|
|
431
|
+
.observer('objFoo.**.**', () => {
|
|
432
|
+
/* */
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Trait
|
|
437
|
+
*/
|
|
438
|
+
interface SimpleFormControlInterface {
|
|
439
|
+
getName(): string;
|
|
440
|
+
getValue(): { foo: string };
|
|
441
|
+
}
|
|
442
|
+
const FormControl = componentSpace.defineTraitBehavior<SimpleFormControlInterface>()
|
|
443
|
+
|
|
444
|
+
componentSpace.define().init(({ relation }) => {
|
|
445
|
+
const rel = relation({
|
|
446
|
+
type: 'descendant',
|
|
447
|
+
target: FormControl,
|
|
448
|
+
linked(target) {
|
|
449
|
+
const impl = target.traitBehavior(FormControl)!
|
|
450
|
+
expectType<string>(impl.getName())
|
|
451
|
+
expectType<{ foo: string }>(impl.getValue())
|
|
452
|
+
},
|
|
453
|
+
})
|
|
454
|
+
expectType<any[]>(rel.list())
|
|
455
|
+
expectType<SimpleFormControlInterface[]>(rel.listAsTrait())
|
|
456
|
+
})
|
|
457
|
+
|
|
458
|
+
componentSpace.define().init(({ implement, relation }) => {
|
|
459
|
+
implement(FormControl, {
|
|
460
|
+
getName: () => '...',
|
|
461
|
+
getValue: () => ({ foo: '...' }),
|
|
462
|
+
})
|
|
463
|
+
const rel = relation({
|
|
464
|
+
type: 'ancestor',
|
|
465
|
+
target: FormControl,
|
|
466
|
+
})
|
|
467
|
+
expectType<any[]>(rel.list())
|
|
468
|
+
expectType<SimpleFormControlInterface[]>(rel.listAsTrait())
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Behavior
|
|
473
|
+
*/
|
|
474
|
+
const beh = componentSpace
|
|
475
|
+
.define()
|
|
476
|
+
.property('propA', {
|
|
477
|
+
type: Number,
|
|
478
|
+
value: 123,
|
|
479
|
+
default: () => 456,
|
|
480
|
+
})
|
|
481
|
+
.data(() => ({
|
|
482
|
+
behaviorData: 'fpp',
|
|
483
|
+
}))
|
|
484
|
+
.registerBehavior()
|
|
485
|
+
|
|
486
|
+
componentSpace
|
|
487
|
+
.define()
|
|
488
|
+
.behavior(beh)
|
|
489
|
+
.property('propB', String)
|
|
490
|
+
.init(({ data }) => {
|
|
491
|
+
expectType<number>(data.propA)
|
|
492
|
+
expectType<string>(data.propB)
|
|
493
|
+
|
|
494
|
+
// @ts-expect-error
|
|
495
|
+
expectType<any>(data.behaviorData)
|
|
496
|
+
|
|
497
|
+
// @ts-expect-error
|
|
498
|
+
expectType<any>(data.nonExists)
|
|
499
|
+
})
|
|
500
|
+
.registerComponent()
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Chaining Filter
|
|
504
|
+
*/
|
|
505
|
+
const propCheck = componentSpace
|
|
506
|
+
.define()
|
|
507
|
+
.chainingFilter<
|
|
508
|
+
{
|
|
509
|
+
myInit<T>(
|
|
510
|
+
this: T,
|
|
511
|
+
name: string,
|
|
512
|
+
fn: T extends { init: (fn: infer Fn) => any } ? Fn : never
|
|
513
|
+
): T;
|
|
514
|
+
},
|
|
515
|
+
never
|
|
516
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
517
|
+
>((chain) => chain as any,
|
|
518
|
+
)
|
|
519
|
+
.registerBehavior()
|
|
520
|
+
|
|
521
|
+
componentSpace
|
|
522
|
+
.define()
|
|
523
|
+
.property('prop1', String)
|
|
524
|
+
.behavior(propCheck)
|
|
525
|
+
.property('prop2', String)
|
|
526
|
+
.myInit('foo', ({ data }) => {
|
|
527
|
+
expectType<{
|
|
528
|
+
readonly prop1: string;
|
|
529
|
+
readonly prop2: string;
|
|
530
|
+
}>(data)
|
|
531
|
+
})
|
|
532
|
+
.registerComponent()
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Methods
|
|
536
|
+
*/
|
|
537
|
+
componentSpace
|
|
538
|
+
.define()
|
|
539
|
+
.property('prop', String)
|
|
540
|
+
.data(() => ({
|
|
541
|
+
num: 123,
|
|
542
|
+
}))
|
|
543
|
+
.init(({ data, method, listener }) => {
|
|
544
|
+
const foo = method(() => data.num)
|
|
545
|
+
|
|
546
|
+
const bar = listener<{ bar: string }>((e) => {
|
|
547
|
+
expectType<{ bar: string }>(e.detail)
|
|
548
|
+
return false
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
expectType<number>(foo())
|
|
552
|
+
|
|
553
|
+
return {
|
|
554
|
+
foo,
|
|
555
|
+
bar,
|
|
556
|
+
}
|
|
557
|
+
})
|
|
558
|
+
.lifetime('created', function () {
|
|
559
|
+
expectType<number>(this.foo())
|
|
560
|
+
})
|
|
561
|
+
.registerComponent()
|
|
562
|
+
|
|
563
|
+
componentSpace
|
|
564
|
+
.define()
|
|
565
|
+
// @ts-expect-error
|
|
566
|
+
.init(() => {
|
|
567
|
+
const foo = () => {
|
|
568
|
+
/* */
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
foo,
|
|
572
|
+
}
|
|
573
|
+
})
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Share Code
|
|
577
|
+
*/
|
|
578
|
+
declare function onThemeChanged(
|
|
579
|
+
callback: (res: { theme: string }) => void
|
|
580
|
+
): void;
|
|
581
|
+
declare function offThemeChanged(
|
|
582
|
+
callback: (res: { theme: string }) => void
|
|
583
|
+
): void;
|
|
584
|
+
|
|
585
|
+
const useTheme = (
|
|
586
|
+
{ lifetime }: glassEasel.BuilderContext<any, any, any>,
|
|
587
|
+
setTheme: (theme: string) => void,
|
|
588
|
+
) => {
|
|
589
|
+
const onThemeChange = ({ theme }: { theme: string }) => {
|
|
590
|
+
setTheme(theme)
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
lifetime('attached', () => {
|
|
594
|
+
onThemeChanged(onThemeChange)
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
lifetime('detached', () => {
|
|
598
|
+
offThemeChanged(onThemeChange)
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
onThemeChange({ theme: 'light' })
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
componentSpace
|
|
605
|
+
.define()
|
|
606
|
+
.data(() => ({
|
|
607
|
+
theme: 'light',
|
|
608
|
+
}))
|
|
609
|
+
.init((ctx) => {
|
|
610
|
+
const { setData } = ctx
|
|
611
|
+
|
|
612
|
+
useTheme(ctx, (theme) => setData({ theme }))
|
|
613
|
+
})
|
|
614
|
+
.registerComponent()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
4
|
+
import { expectType } from 'tsd'
|
|
5
|
+
import * as glassEasel from '../../src'
|
|
6
|
+
|
|
7
|
+
const componentSpace = glassEasel.getDefaultComponentSpace()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Definition createElement
|
|
11
|
+
*/
|
|
12
|
+
const definitionInstance = glassEasel.createElement(
|
|
13
|
+
'comp',
|
|
14
|
+
glassEasel.registerElement({
|
|
15
|
+
properties: {
|
|
16
|
+
propStr: String,
|
|
17
|
+
},
|
|
18
|
+
data: {
|
|
19
|
+
foo: { foo: 'foo' },
|
|
20
|
+
},
|
|
21
|
+
methods: {
|
|
22
|
+
func() {
|
|
23
|
+
return this.data.propStr + this.data.foo.foo
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
expectType<string>(definitionInstance.data.propStr)
|
|
30
|
+
expectType<{ readonly foo: string }>(definitionInstance.data.foo)
|
|
31
|
+
expectType<string>(definitionInstance.func())
|
|
32
|
+
|
|
33
|
+
const definitionGeneralInstance = glassEasel.createElement(
|
|
34
|
+
'comp',
|
|
35
|
+
glassEasel.registerElement({
|
|
36
|
+
properties: {
|
|
37
|
+
propStr: String,
|
|
38
|
+
},
|
|
39
|
+
data: {
|
|
40
|
+
foo: { foo: 'foo' },
|
|
41
|
+
},
|
|
42
|
+
}).general(),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
expectType<{ readonly [x: string]: any }>(definitionGeneralInstance.data)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Chaining createElement
|
|
49
|
+
*/
|
|
50
|
+
const chainingInstance = glassEasel.createElement(
|
|
51
|
+
'comp',
|
|
52
|
+
componentSpace
|
|
53
|
+
.define()
|
|
54
|
+
.property('propStr', String)
|
|
55
|
+
.data(() => ({
|
|
56
|
+
foo: { foo: 'foo' },
|
|
57
|
+
}))
|
|
58
|
+
.init(({ data, method }) => {
|
|
59
|
+
const func = method(() => data.propStr + data.foo.foo)
|
|
60
|
+
|
|
61
|
+
return { func }
|
|
62
|
+
})
|
|
63
|
+
.registerComponent(),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
expectType<string>(chainingInstance.data.propStr)
|
|
67
|
+
expectType<{ readonly foo: string }>(chainingInstance.data.foo)
|
|
68
|
+
expectType<string>(chainingInstance.func())
|
|
69
|
+
|
|
70
|
+
const chainingGeneralInstance = glassEasel.createElement(
|
|
71
|
+
'comp',
|
|
72
|
+
componentSpace
|
|
73
|
+
.define()
|
|
74
|
+
.property('propStr', String)
|
|
75
|
+
.data(() => ({
|
|
76
|
+
foo: { foo: 'foo' },
|
|
77
|
+
}))
|
|
78
|
+
.registerComponent()
|
|
79
|
+
.general(),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
expectType<{ readonly [x: string]: any }>(chainingGeneralInstance.data)
|