@furystack/shades 6.1.5 → 7.0.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/component-factory.spec.js +6 -6
- package/dist/component-factory.spec.js.map +1 -1
- package/dist/components/lazy-load.js +17 -14
- package/dist/components/lazy-load.js.map +1 -1
- package/dist/components/route-link.js +7 -3
- package/dist/components/route-link.js.map +1 -1
- package/dist/components/route-link.spec.js +2 -2
- package/dist/components/route-link.spec.js.map +1 -1
- package/dist/components/router.js +25 -26
- package/dist/components/router.js.map +1 -1
- package/dist/components/router.spec.js +2 -2
- package/dist/components/router.spec.js.map +1 -1
- package/dist/models/render-options.js +23 -0
- package/dist/models/render-options.js.map +1 -1
- package/dist/services/location-service.js +16 -4
- package/dist/services/location-service.js.map +1 -1
- package/dist/services/location-service.spec.js +1 -1
- package/dist/services/location-service.spec.js.map +1 -1
- package/dist/services/resource-manager.js +48 -0
- package/dist/services/resource-manager.js.map +1 -0
- package/dist/services/resource-manager.spec.js +32 -0
- package/dist/services/resource-manager.spec.js.map +1 -0
- package/dist/shade-component.js +28 -14
- package/dist/shade-component.js.map +1 -1
- package/dist/shade-resources.integration.spec.js +7 -8
- package/dist/shade-resources.integration.spec.js.map +1 -1
- package/dist/shade.js +33 -69
- package/dist/shade.js.map +1 -1
- package/dist/shades.integration.spec.js +197 -187
- package/dist/shades.integration.spec.js.map +1 -1
- package/package.json +5 -5
- package/src/component-factory.spec.tsx +7 -7
- package/src/components/lazy-load.tsx +19 -15
- package/src/components/route-link.spec.tsx +2 -2
- package/src/components/route-link.tsx +11 -10
- package/src/components/router.spec.tsx +2 -2
- package/src/components/router.tsx +32 -32
- package/src/jsx.ts +3 -2
- package/src/models/render-options.ts +37 -9
- package/src/services/location-service.spec.ts +1 -1
- package/src/services/location-service.tsx +18 -4
- package/src/services/resource-manager.spec.ts +33 -0
- package/src/services/resource-manager.ts +60 -0
- package/src/shade-component.ts +35 -15
- package/src/shade-resources.integration.spec.tsx +8 -14
- package/src/shade.ts +34 -107
- package/src/shades.integration.spec.tsx +265 -252
- package/types/components/lazy-load.d.ts +1 -1
- package/types/components/lazy-load.d.ts.map +1 -1
- package/types/components/route-link.d.ts +1 -1
- package/types/components/route-link.d.ts.map +1 -1
- package/types/components/router.d.ts +6 -8
- package/types/components/router.d.ts.map +1 -1
- package/types/jsx.d.ts +3 -2
- package/types/jsx.d.ts.map +1 -1
- package/types/models/render-options.d.ts +7 -7
- package/types/models/render-options.d.ts.map +1 -1
- package/types/services/location-service.d.ts +12 -1
- package/types/services/location-service.d.ts.map +1 -1
- package/types/services/resource-manager.d.ts +16 -0
- package/types/services/resource-manager.d.ts.map +1 -0
- package/types/services/resource-manager.spec.d.ts +2 -0
- package/types/services/resource-manager.spec.d.ts.map +1 -0
- package/types/shade-component.d.ts +16 -5
- package/types/shade-component.d.ts.map +1 -1
- package/types/shade.d.ts +8 -27
- package/types/shade.d.ts.map +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Injector } from '@furystack/inject'
|
|
2
|
+
import { usingAsync } from '@furystack/utils'
|
|
2
3
|
|
|
3
4
|
import { TextEncoder, TextDecoder } from 'util'
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ global.TextDecoder = TextDecoder as any
|
|
|
7
8
|
|
|
8
9
|
import { initializeShadeRoot } from './initialize'
|
|
9
10
|
import { Shade } from './shade'
|
|
10
|
-
import { createComponent
|
|
11
|
+
import { createComponent } from './shade-component'
|
|
11
12
|
|
|
12
13
|
describe('Shades integration tests', () => {
|
|
13
14
|
beforeEach(() => (document.body.innerHTML = '<div id="root"></div>'))
|
|
@@ -43,289 +44,301 @@ describe('Shades integration tests', () => {
|
|
|
43
44
|
)
|
|
44
45
|
})
|
|
45
46
|
|
|
46
|
-
it('Should mount a custom component with null render result', () => {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
it('Should mount a custom component with null render result', async () => {
|
|
48
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
49
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
const ExampleComponent = Shade({ render: () => null, shadowDomName: 'shades-null-render-result' })
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
initializeShadeRoot({
|
|
54
|
+
injector,
|
|
55
|
+
rootElement,
|
|
56
|
+
jsxElement: <ExampleComponent />,
|
|
57
|
+
})
|
|
58
|
+
expect(document.body.innerHTML).toBe(
|
|
59
|
+
'<div id="root"><shades-null-render-result></shades-null-render-result></div>',
|
|
60
|
+
)
|
|
56
61
|
})
|
|
57
|
-
expect(document.body.innerHTML).toBe('<div id="root"><shades-null-render-result></shades-null-render-result></div>')
|
|
58
62
|
})
|
|
59
63
|
|
|
60
|
-
it('Should mount a custom component with a document fragment render result', () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const ExampleComponent = Shade({
|
|
65
|
-
render: () => (
|
|
66
|
-
<>
|
|
67
|
-
<p>1</p>
|
|
68
|
-
<p>2</p>
|
|
69
|
-
</>
|
|
70
|
-
),
|
|
71
|
-
shadowDomName: 'shades-fragment-render-result',
|
|
72
|
-
})
|
|
64
|
+
it('Should mount a custom component with a document fragment render result', async () => {
|
|
65
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
66
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
73
67
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
rootElement,
|
|
77
|
-
jsxElement: <ExampleComponent />,
|
|
78
|
-
})
|
|
79
|
-
expect(document.body.innerHTML).toBe(
|
|
80
|
-
'<div id="root"><shades-fragment-render-result><p>1</p><p>2</p></shades-fragment-render-result></div>',
|
|
81
|
-
)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('Should mount a custom component with a nested document fragment render result', () => {
|
|
85
|
-
const injector = new Injector()
|
|
86
|
-
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
87
|
-
|
|
88
|
-
const ExampleComponent = Shade({
|
|
89
|
-
render: () => (
|
|
90
|
-
<p>
|
|
68
|
+
const ExampleComponent = Shade({
|
|
69
|
+
render: () => (
|
|
91
70
|
<>
|
|
92
71
|
<p>1</p>
|
|
93
72
|
<p>2</p>
|
|
94
73
|
</>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
),
|
|
75
|
+
shadowDomName: 'shades-fragment-render-result',
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
initializeShadeRoot({
|
|
79
|
+
injector,
|
|
80
|
+
rootElement,
|
|
81
|
+
jsxElement: <ExampleComponent />,
|
|
82
|
+
})
|
|
83
|
+
expect(document.body.innerHTML).toBe(
|
|
84
|
+
'<div id="root"><shades-fragment-render-result><p>1</p><p>2</p></shades-fragment-render-result></div>',
|
|
85
|
+
)
|
|
98
86
|
})
|
|
99
|
-
|
|
100
|
-
initializeShadeRoot({
|
|
101
|
-
injector,
|
|
102
|
-
rootElement,
|
|
103
|
-
jsxElement: <ExampleComponent />,
|
|
104
|
-
})
|
|
105
|
-
expect(document.body.innerHTML).toBe(
|
|
106
|
-
'<div id="root"><shades-fragment-render-result-nested><p><p>1</p><p>2</p></p></shades-fragment-render-result-nested></div>',
|
|
107
|
-
)
|
|
108
87
|
})
|
|
109
88
|
|
|
110
|
-
it('Should mount a custom component with a document fragment
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
89
|
+
it('Should mount a custom component with a nested document fragment render result', async () => {
|
|
90
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
91
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
92
|
+
|
|
93
|
+
const ExampleComponent = Shade({
|
|
94
|
+
render: () => (
|
|
95
|
+
<p>
|
|
96
|
+
<>
|
|
97
|
+
<p>1</p>
|
|
98
|
+
<p>2</p>
|
|
99
|
+
</>
|
|
100
|
+
</p>
|
|
101
|
+
),
|
|
102
|
+
shadowDomName: 'shades-fragment-render-result-nested',
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
initializeShadeRoot({
|
|
106
|
+
injector,
|
|
107
|
+
rootElement,
|
|
108
|
+
jsxElement: <ExampleComponent />,
|
|
109
|
+
})
|
|
110
|
+
expect(document.body.innerHTML).toBe(
|
|
111
|
+
'<div id="root"><shades-fragment-render-result-nested><p><p>1</p><p>2</p></p></shades-fragment-render-result-nested></div>',
|
|
112
|
+
)
|
|
133
113
|
})
|
|
134
|
-
expect(document.body.innerHTML).toBe(
|
|
135
|
-
'<div id="root"><shades-fragment-render-result-2><shades-fragment-test-custom-component><p>Hello</p></shades-fragment-test-custom-component><shades-fragment-test-custom-component><p>Hello</p></shades-fragment-test-custom-component></shades-fragment-render-result-2></div>',
|
|
136
|
-
)
|
|
137
114
|
})
|
|
138
115
|
|
|
139
|
-
it('Should mount
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const ExampleComponent = Shade({
|
|
144
|
-
render: ({ children }) => <div>{children}</div>,
|
|
145
|
-
shadowDomName: 'shades-example-2',
|
|
146
|
-
})
|
|
116
|
+
it('Should mount a custom component with a document fragment that contains custom components', async () => {
|
|
117
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
118
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
147
119
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
120
|
+
const CustomComponent = Shade({
|
|
121
|
+
shadowDomName: 'shades-fragment-test-custom-component',
|
|
122
|
+
render: () => <p>Hello</p>,
|
|
123
|
+
})
|
|
152
124
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
125
|
+
const ExampleComponent = Shade({
|
|
126
|
+
render: () => (
|
|
127
|
+
<>
|
|
128
|
+
<CustomComponent />
|
|
129
|
+
<CustomComponent />
|
|
130
|
+
</>
|
|
131
|
+
),
|
|
132
|
+
shadowDomName: 'shades-fragment-render-result-2',
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
initializeShadeRoot({
|
|
136
|
+
injector,
|
|
137
|
+
rootElement,
|
|
138
|
+
jsxElement: <ExampleComponent />,
|
|
139
|
+
})
|
|
140
|
+
expect(document.body.innerHTML).toBe(
|
|
141
|
+
'<div id="root"><shades-fragment-render-result-2><shades-fragment-test-custom-component><p>Hello</p></shades-fragment-test-custom-component><shades-fragment-test-custom-component><p>Hello</p></shades-fragment-test-custom-component></shades-fragment-render-result-2></div>',
|
|
142
|
+
)
|
|
163
143
|
})
|
|
164
|
-
expect(document.body.innerHTML).toBe(
|
|
165
|
-
'<div id="root"><shades-example-2><div><shades-example-sub><div></div></shades-example-sub><shades-example-sub><div></div></shades-example-sub><shades-example-sub><div></div></shades-example-sub></div></shades-example-2></div>',
|
|
166
|
-
)
|
|
167
144
|
})
|
|
168
145
|
|
|
169
|
-
it(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
146
|
+
it('Should mount nested Shades components', async () => {
|
|
147
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
148
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
149
|
+
|
|
150
|
+
const ExampleComponent = Shade({
|
|
151
|
+
render: ({ children }) => <div>{children}</div>,
|
|
152
|
+
shadowDomName: 'shades-example-2',
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const ExampleSubs = Shade<{ no: number }>({
|
|
156
|
+
render: ({ props }) => <div>{props.no}</div>,
|
|
157
|
+
shadowDomName: 'shades-example-sub',
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
initializeShadeRoot({
|
|
161
|
+
injector,
|
|
162
|
+
rootElement,
|
|
163
|
+
jsxElement: (
|
|
164
|
+
<ExampleComponent>
|
|
165
|
+
<ExampleSubs no={1} />
|
|
166
|
+
<ExampleSubs no={2} />
|
|
167
|
+
<ExampleSubs no={3} />
|
|
168
|
+
</ExampleComponent>
|
|
169
|
+
),
|
|
170
|
+
})
|
|
171
|
+
expect(document.body.innerHTML).toBe(
|
|
172
|
+
'<div id="root"><shades-example-2><div><shades-example-sub><div>1</div></shades-example-sub><shades-example-sub><div>2</div></shades-example-sub><shades-example-sub><div>3</div></shades-example-sub></div></shades-example-2></div>',
|
|
173
|
+
)
|
|
185
174
|
})
|
|
186
|
-
expect(constructed).toBeCalled()
|
|
187
|
-
expect(cleanup).not.toBeCalled()
|
|
188
|
-
document.body.innerHTML = ''
|
|
189
|
-
expect(cleanup).toBeCalled()
|
|
190
175
|
})
|
|
191
176
|
|
|
192
|
-
it(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
177
|
+
it("Should execute the constructed and constructed's cleanup callback", async () => {
|
|
178
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
179
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
180
|
+
const cleanup = jest.fn()
|
|
181
|
+
const constructed = jest.fn(() => cleanup)
|
|
182
|
+
|
|
183
|
+
const ExampleComponent = Shade({
|
|
184
|
+
constructed,
|
|
185
|
+
shadowDomName: 'example-component-1',
|
|
186
|
+
render: () => <div>Hello</div>,
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
initializeShadeRoot({
|
|
190
|
+
injector,
|
|
191
|
+
rootElement,
|
|
192
|
+
jsxElement: <ExampleComponent />,
|
|
193
|
+
})
|
|
194
|
+
expect(constructed).toBeCalled()
|
|
195
|
+
expect(cleanup).not.toBeCalled()
|
|
196
|
+
document.body.innerHTML = ''
|
|
197
|
+
expect(cleanup).toBeCalled()
|
|
209
198
|
})
|
|
210
|
-
expect(onAttach).toBeCalled()
|
|
211
|
-
expect(onDetach).not.toBeCalled()
|
|
212
|
-
document.body.innerHTML = ''
|
|
213
|
-
expect(onDetach).toBeCalled()
|
|
214
199
|
})
|
|
215
200
|
|
|
216
|
-
it('Should
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
initializeShadeRoot({
|
|
239
|
-
injector,
|
|
240
|
-
rootElement,
|
|
241
|
-
jsxElement: <ExampleComponent />,
|
|
201
|
+
it('Should execute the onAttach and onDetach callbacks', async () => {
|
|
202
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
203
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
204
|
+
const onAttach = jest.fn()
|
|
205
|
+
const onDetach = jest.fn()
|
|
206
|
+
|
|
207
|
+
const ExampleComponent = Shade({
|
|
208
|
+
onAttach,
|
|
209
|
+
onDetach,
|
|
210
|
+
shadowDomName: 'example-component-2',
|
|
211
|
+
render: () => <div>Hello</div>,
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
initializeShadeRoot({
|
|
215
|
+
injector,
|
|
216
|
+
rootElement,
|
|
217
|
+
jsxElement: <ExampleComponent />,
|
|
218
|
+
})
|
|
219
|
+
expect(onAttach).toBeCalled()
|
|
220
|
+
expect(onDetach).not.toBeCalled()
|
|
221
|
+
document.body.innerHTML = ''
|
|
222
|
+
expect(onDetach).toBeCalled()
|
|
242
223
|
})
|
|
243
|
-
|
|
244
|
-
const plus = () => document.getElementById('plus')?.click()
|
|
245
|
-
const minus = () => document.getElementById('minus')?.click()
|
|
246
|
-
const expectCount = (count: number) => expect(document.body.innerHTML).toContain(`Count is ${count}`)
|
|
247
|
-
|
|
248
|
-
expectCount(0)
|
|
249
|
-
plus()
|
|
250
|
-
expectCount(1)
|
|
251
|
-
plus()
|
|
252
|
-
expectCount(2)
|
|
253
|
-
|
|
254
|
-
minus()
|
|
255
|
-
minus()
|
|
256
|
-
expectCount(0)
|
|
257
224
|
})
|
|
258
225
|
|
|
259
|
-
it('Should
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
226
|
+
it('Should update state', async () => {
|
|
227
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
228
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
229
|
+
|
|
230
|
+
const ExampleComponent = Shade({
|
|
231
|
+
shadowDomName: 'example-component-3',
|
|
232
|
+
render: ({ useState }) => {
|
|
233
|
+
const [count, setCount] = useState('count', 0)
|
|
234
|
+
return (
|
|
235
|
+
<div>
|
|
236
|
+
Count is {count}
|
|
237
|
+
<button id="plus" onclick={() => setCount(count + 1)}>
|
|
238
|
+
+
|
|
239
|
+
</button>
|
|
240
|
+
<button id="minus" onclick={() => setCount(count - 1)}>
|
|
241
|
+
-
|
|
242
|
+
</button>
|
|
243
|
+
</div>
|
|
244
|
+
)
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
initializeShadeRoot({
|
|
248
|
+
injector,
|
|
249
|
+
rootElement,
|
|
250
|
+
jsxElement: <ExampleComponent />,
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
const plus = () => document.getElementById('plus')?.click()
|
|
254
|
+
const minus = () => document.getElementById('minus')?.click()
|
|
255
|
+
const expectCount = (count: number) => expect(document.body.innerHTML).toContain(`Count is ${count}`)
|
|
256
|
+
|
|
257
|
+
expectCount(0)
|
|
258
|
+
plus()
|
|
259
|
+
expectCount(1)
|
|
260
|
+
plus()
|
|
261
|
+
expectCount(2)
|
|
262
|
+
|
|
263
|
+
minus()
|
|
264
|
+
minus()
|
|
265
|
+
expectCount(0)
|
|
297
266
|
})
|
|
267
|
+
})
|
|
298
268
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
rootElement
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
269
|
+
it('Should allow children update after unmount and remount', async () => {
|
|
270
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
271
|
+
const rootElement = document.getElementById('root') as HTMLDivElement
|
|
272
|
+
const Parent = Shade({
|
|
273
|
+
shadowDomName: 'shade-remount-parent',
|
|
274
|
+
render: ({ children, useState }) => {
|
|
275
|
+
const [areChildrenVisible, setAreChildrenVisible] = useState('areChildrenVisible', true)
|
|
276
|
+
return (
|
|
277
|
+
<div>
|
|
278
|
+
<button
|
|
279
|
+
id="showHideChildren"
|
|
280
|
+
onclick={() => {
|
|
281
|
+
setAreChildrenVisible(!areChildrenVisible)
|
|
282
|
+
}}
|
|
283
|
+
>
|
|
284
|
+
Toggle
|
|
285
|
+
</button>
|
|
286
|
+
{areChildrenVisible ? children : null}
|
|
287
|
+
</div>
|
|
288
|
+
)
|
|
289
|
+
},
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const Child = Shade({
|
|
293
|
+
shadowDomName: 'example-remount-child',
|
|
294
|
+
render: ({ useState }) => {
|
|
295
|
+
const [count, setCount] = useState('count', 0)
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<div>
|
|
299
|
+
Count is {`${count}`}
|
|
300
|
+
<button id="plus" onclick={() => setCount(count + 1)}>
|
|
301
|
+
+
|
|
302
|
+
</button>
|
|
303
|
+
<button id="minus" onclick={() => setCount(count - 1)}>
|
|
304
|
+
-
|
|
305
|
+
</button>
|
|
306
|
+
</div>
|
|
307
|
+
)
|
|
308
|
+
},
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
initializeShadeRoot({
|
|
312
|
+
injector,
|
|
313
|
+
rootElement,
|
|
314
|
+
jsxElement: (
|
|
315
|
+
<Parent>
|
|
316
|
+
<Child />
|
|
317
|
+
</Parent>
|
|
318
|
+
),
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
const plus = () => document.getElementById('plus')?.click()
|
|
322
|
+
const minus = () => document.getElementById('minus')?.click()
|
|
323
|
+
const expectCount = (count: number) => expect(document.body.innerHTML).toContain(`Count is ${count}`)
|
|
324
|
+
const toggleChildren = () => document.getElementById('showHideChildren')?.click()
|
|
325
|
+
|
|
326
|
+
expectCount(0)
|
|
327
|
+
plus()
|
|
328
|
+
expectCount(1)
|
|
329
|
+
|
|
330
|
+
toggleChildren()
|
|
331
|
+
|
|
332
|
+
expect(document.getElementById('plus')).toBeNull()
|
|
333
|
+
|
|
334
|
+
toggleChildren()
|
|
335
|
+
expect(document.getElementById('plus')).toBeDefined()
|
|
336
|
+
|
|
337
|
+
expectCount(0)
|
|
338
|
+
plus()
|
|
339
|
+
expectCount(1)
|
|
340
|
+
minus()
|
|
341
|
+
expectCount(0)
|
|
307
342
|
})
|
|
308
|
-
|
|
309
|
-
const plus = () => document.getElementById('plus')?.click()
|
|
310
|
-
const minus = () => document.getElementById('minus')?.click()
|
|
311
|
-
const expectCount = (count: number) => expect(document.body.innerHTML).toContain(`Count is ${count}`)
|
|
312
|
-
const toggleChildren = () => document.getElementById('showHideChildren')?.click()
|
|
313
|
-
|
|
314
|
-
expectCount(0)
|
|
315
|
-
plus()
|
|
316
|
-
expectCount(1)
|
|
317
|
-
|
|
318
|
-
toggleChildren()
|
|
319
|
-
|
|
320
|
-
expect(document.getElementById('plus')).toBeNull()
|
|
321
|
-
|
|
322
|
-
toggleChildren()
|
|
323
|
-
expect(document.getElementById('plus')).toBeDefined()
|
|
324
|
-
|
|
325
|
-
// expectCount(0)
|
|
326
|
-
plus()
|
|
327
|
-
expectCount(1)
|
|
328
|
-
minus()
|
|
329
|
-
expectCount(0)
|
|
330
343
|
})
|
|
331
344
|
})
|
|
@@ -7,5 +7,5 @@ export interface LazyLoadState {
|
|
|
7
7
|
component?: JSX.Element;
|
|
8
8
|
error?: unknown;
|
|
9
9
|
}
|
|
10
|
-
export declare const LazyLoad: (props: LazyLoadProps, children: import("..").ChildrenList) => JSX.Element<any
|
|
10
|
+
export declare const LazyLoad: (props: LazyLoadProps, children: import("..").ChildrenList) => JSX.Element<any>;
|
|
11
11
|
//# sourceMappingURL=lazy-load.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-load.d.ts","sourceRoot":"","sources":["../../src/components/lazy-load.tsx"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,OAAO,CAAA;IAC1D,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"lazy-load.d.ts","sourceRoot":"","sources":["../../src/components/lazy-load.tsx"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,OAAO,CAAA;IAC1D,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,eAAO,MAAM,QAAQ,iFAqCnB,CAAA"}
|
|
@@ -2,5 +2,5 @@ import type { PartialElement } from '../models';
|
|
|
2
2
|
export type RouteLinkProps = PartialElement<HTMLAnchorElement>;
|
|
3
3
|
export declare const RouteLink: (props: Omit<Partial<HTMLAnchorElement>, "style"> & {
|
|
4
4
|
style?: Partial<CSSStyleDeclaration> | undefined;
|
|
5
|
-
}, children: import("..").ChildrenList) => JSX.Element<any
|
|
5
|
+
}, children: import("..").ChildrenList) => JSX.Element<any>;
|
|
6
6
|
//# sourceMappingURL=route-link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-link.d.ts","sourceRoot":"","sources":["../../src/components/route-link.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAI/C,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAA;AAE9D,eAAO,MAAM,SAAS;;
|
|
1
|
+
{"version":3,"file":"route-link.d.ts","sourceRoot":"","sources":["../../src/components/route-link.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAI/C,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAA;AAE9D,eAAO,MAAM,SAAS;;2DAiBpB,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { MatchResult, TokensToRegexpOptions } from 'path-to-regexp';
|
|
2
2
|
import type { RenderOptions } from '../models';
|
|
3
|
-
import Semaphore from 'semaphore-async-await';
|
|
4
3
|
export interface Route<TMatchResult extends object> {
|
|
5
4
|
url: string;
|
|
6
5
|
component: (options: {
|
|
@@ -8,19 +7,18 @@ export interface Route<TMatchResult extends object> {
|
|
|
8
7
|
match: MatchResult<TMatchResult>;
|
|
9
8
|
}) => JSX.Element;
|
|
10
9
|
routingOptions?: TokensToRegexpOptions;
|
|
11
|
-
onVisit?: (options: RenderOptions<
|
|
12
|
-
onLeave?: (options: RenderOptions<
|
|
10
|
+
onVisit?: (options: RenderOptions<unknown>) => Promise<void>;
|
|
11
|
+
onLeave?: (options: RenderOptions<unknown>) => Promise<void>;
|
|
13
12
|
}
|
|
14
13
|
export interface RouterProps {
|
|
15
14
|
style?: CSSStyleDeclaration;
|
|
16
15
|
routes: Array<Route<any>>;
|
|
17
|
-
notFound?:
|
|
16
|
+
notFound?: JSX.Element;
|
|
18
17
|
}
|
|
19
18
|
export interface RouterState {
|
|
20
|
-
activeRoute?: Route<any
|
|
19
|
+
activeRoute?: Route<any> | null;
|
|
21
20
|
activeRouteParams?: any;
|
|
22
|
-
jsx
|
|
23
|
-
lock: Semaphore;
|
|
21
|
+
jsx: JSX.Element;
|
|
24
22
|
}
|
|
25
|
-
export declare const Router: (props: RouterProps, children: import("../models").ChildrenList) => JSX.Element<any
|
|
23
|
+
export declare const Router: (props: RouterProps, children: import("../models").ChildrenList) => JSX.Element<any>;
|
|
26
24
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/components/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/components/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAI9C,MAAM,WAAW,KAAK,CAAC,YAAY,SAAS,MAAM;IAChD,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;KAAE,KAAK,GAAG,CAAC,OAAO,CAAA;IAC7F,cAAc,CAAC,EAAE,qBAAqB,CAAA;IACtC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5D,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7D;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACzB,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAC/B,iBAAiB,CAAC,EAAE,GAAG,CAAA;IACvB,GAAG,EAAE,GAAG,CAAC,OAAO,CAAA;CACjB;AACD,eAAO,MAAM,MAAM,sFAgDjB,CAAA"}
|
package/types/jsx.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Injector } from '@furystack/inject';
|
|
2
2
|
import type { ChildrenList, PartialElement } from './models';
|
|
3
|
+
import type { ResourceManager } from './services/resource-manager';
|
|
3
4
|
declare global {
|
|
4
5
|
export namespace JSX {
|
|
5
|
-
interface Element<TProps = any
|
|
6
|
+
interface Element<TProps = any> extends HTMLElement {
|
|
6
7
|
injector: Injector;
|
|
7
|
-
state: TState;
|
|
8
8
|
props: TProps;
|
|
9
9
|
updateComponent: () => void;
|
|
10
10
|
shadeChildren?: ChildrenList;
|
|
11
11
|
callConstructed: () => void;
|
|
12
|
+
resourceManager: ResourceManager;
|
|
12
13
|
}
|
|
13
14
|
interface IntrinsicElements {
|
|
14
15
|
/**
|