@webqit/oohtml 2.1.34 → 2.1.35
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/.gitignore +3 -3
- package/LICENSE +20 -20
- package/README.md +733 -67
- package/dist/bindings-api.js +1 -1
- package/dist/bindings-api.js.map +3 -3
- package/dist/context-api.js +1 -1
- package/dist/context-api.js.map +3 -3
- package/dist/html-imports.js +1 -1
- package/dist/html-imports.js.map +3 -3
- package/dist/main.js +12 -12
- package/dist/main.js.map +3 -3
- package/dist/namespace-api.js +1 -1
- package/dist/namespace-api.js.map +3 -3
- package/dist/scoped-css.js +2 -2
- package/dist/scoped-css.js.map +3 -3
- package/dist/scoped-js.js +7 -7
- package/dist/scoped-js.js.map +3 -3
- package/package.json +76 -76
- package/src/bindings-api/index.js +83 -83
- package/src/bindings-api/targets.browser.js +10 -10
- package/src/context-api/HTMLContext.js +76 -157
- package/src/context-api/HTMLContextProvider.js +158 -0
- package/src/context-api/_ContextRequestEvent.js +25 -25
- package/src/context-api/index.js +51 -51
- package/src/context-api/targets.browser.js +9 -9
- package/src/{html-modules/HTMLExportsManager.js → html-imports/_HTMLExportsManager.js} +185 -199
- package/src/html-imports/_HTMLImportElement.js +211 -213
- package/src/{html-modules/_HTMLImportsContext.js → html-imports/_HTMLImportsProvider.js} +122 -114
- package/src/html-imports/index.js +197 -88
- package/src/html-imports/targets.browser.js +9 -9
- package/src/index.js +30 -32
- package/src/namespace-api/index.js +144 -144
- package/src/namespace-api/targets.browser.js +10 -10
- package/src/scoped-css/index.js +45 -45
- package/src/scoped-css/targets.browser.js +10 -10
- package/src/scoped-js/Compiler.js +297 -297
- package/src/scoped-js/index.js +112 -112
- package/src/scoped-js/targets.browser.js +10 -10
- package/src/targets.browser.js +9 -9
- package/src/util.js +34 -34
- package/test/bindings-api.test.js +42 -42
- package/test/imports.test.js +221 -221
- package/test/index.js +50 -50
- package/test/modules.test.js +200 -200
- package/test/namespace-api.test.js +51 -51
- package/test/scoped-css.test.js +31 -31
- package/test/scoped-js.test.js +29 -29
- package/dist/html-modules.js +0 -2
- package/dist/html-modules.js.map +0 -7
- package/src/context-api/HTMLContextManager.js +0 -77
- package/src/html-modules/index.js +0 -131
- package/src/html-modules/targets.browser.js +0 -10
package/test/imports.test.js
CHANGED
|
@@ -1,221 +1,221 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import { createDocument, mockRemoteFetch, delay } from './index.js';
|
|
7
|
-
|
|
8
|
-
describe(`HTML Imports`, function() {
|
|
9
|
-
|
|
10
|
-
describe( `Basic...`, function() {
|
|
11
|
-
|
|
12
|
-
const head = `
|
|
13
|
-
<template exportid="temp0">
|
|
14
|
-
<p>Hello world Export</p>
|
|
15
|
-
<p>Hellort</p>
|
|
16
|
-
</template>`;
|
|
17
|
-
const body = `
|
|
18
|
-
<import module="temp0"></import>`;
|
|
19
|
-
const { document } = createDocument( head, body );
|
|
20
|
-
|
|
21
|
-
it ( `The document object and <template> elements should expose a "modules" property`, async function() {
|
|
22
|
-
expect( document ).to.have.property( 'modules' );
|
|
23
|
-
expect( document.modules.temp0 ).to.have.property( 'modules' );
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
it ( `<import> element be automatically resolved: import default export...`, async function() {
|
|
27
|
-
expect( document.body.children ).to.have.length( 2 );
|
|
28
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
it( `<import> element be resolved again: after having mutated an export right at its module.`, async function() {
|
|
32
|
-
const templateEl = document.querySelector( 'template' );
|
|
33
|
-
let added = document.createElement( 'div' );
|
|
34
|
-
templateEl.content.appendChild( added );
|
|
35
|
-
expect( document.body.children ).to.have.length( 3 );
|
|
36
|
-
} );
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
describe( `Dynamic...`, function() {
|
|
40
|
-
|
|
41
|
-
const head = `
|
|
42
|
-
<template exportid="temp0">
|
|
43
|
-
<!-- ------- -->
|
|
44
|
-
<p>Hello world Export</p>
|
|
45
|
-
<p>Hellort</p>
|
|
46
|
-
<input exportid="#input" />
|
|
47
|
-
<template exportid="temp1">
|
|
48
|
-
<textarea exportid="#input"></textarea>
|
|
49
|
-
<template exportid="temp2">
|
|
50
|
-
<select exportid="#input"></select>
|
|
51
|
-
</template>
|
|
52
|
-
</template>
|
|
53
|
-
<!-- ------- -->
|
|
54
|
-
<template exportid="_landing1">
|
|
55
|
-
<div exportid="#main.html">a</div>
|
|
56
|
-
<template exportid="_landing2">
|
|
57
|
-
<div exportid="#main.html">b</div>
|
|
58
|
-
<template exportid="_docs">
|
|
59
|
-
<div exportid="#main.html">c</div>
|
|
60
|
-
</template>
|
|
61
|
-
</template>
|
|
62
|
-
</template>
|
|
63
|
-
<!-- ------- -->
|
|
64
|
-
<template exportid="landing1" extends="_landing1">
|
|
65
|
-
<div exportid="#README.md">1</div>
|
|
66
|
-
<template exportid="landing2" extends="_landing2">
|
|
67
|
-
<div exportid="#README.md">2</div>
|
|
68
|
-
<template exportid="docs" extends="_docs">
|
|
69
|
-
<div exportid="#README.md">3</div>
|
|
70
|
-
</template>
|
|
71
|
-
</template>
|
|
72
|
-
</template>
|
|
73
|
-
<!-- ------- -->
|
|
74
|
-
</template>`;
|
|
75
|
-
const body = `
|
|
76
|
-
<import module="temp0/uuu"></import>`;
|
|
77
|
-
const { document } = createDocument( head, body );
|
|
78
|
-
const importEl = document.querySelector( 'import' );
|
|
79
|
-
|
|
80
|
-
it ( `<import> element should not be resolved: no match for given import ID...`, async function() {
|
|
81
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
it ( `<import> element should be automatically resolved: new import ID is set...`, async function() {
|
|
85
|
-
importEl.setAttribute( 'module', 'temp0#input' );
|
|
86
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
87
|
-
} );
|
|
88
|
-
|
|
89
|
-
it ( `<import> element should be automatically resolved: new moduleref is set - nested...`, async function() {
|
|
90
|
-
importEl.setAttribute( 'module', 'temp0/temp1#input' );
|
|
91
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
92
|
-
} );
|
|
93
|
-
|
|
94
|
-
it ( `<import> element should be automatically resolved: moduleref is unset - should now be inherited from <body>...`, async function() {
|
|
95
|
-
importEl.setAttribute( 'module', '#input' );
|
|
96
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
97
|
-
document.body.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
|
|
98
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'SELECT' );
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
it ( `<import> element should be automatically resolved: moduleref at <body> is changed...`, async function() {
|
|
102
|
-
document.body.setAttribute( 'importscontext', 'temp0' );
|
|
103
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
104
|
-
} );
|
|
105
|
-
|
|
106
|
-
it ( `<import> element should be automatically RESTORED: slotted element is removed from DOM...`, async function() {
|
|
107
|
-
document.body.querySelector( 'input' ).remove();
|
|
108
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
109
|
-
} );
|
|
110
|
-
|
|
111
|
-
/*
|
|
112
|
-
it ( ``, async function() {
|
|
113
|
-
console.log('"""""""""""""""""""""""""""""""""""""""""""""', document.modules.temp0.modules.landing1.modules.landing2.modules.docs.modules);
|
|
114
|
-
} );
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
} );
|
|
118
|
-
|
|
119
|
-
describe( `Remote...`, function() {
|
|
120
|
-
|
|
121
|
-
it( `<import> element from nested remote modules.`, async function() {
|
|
122
|
-
this.timeout( 10000 );
|
|
123
|
-
|
|
124
|
-
const head = ``, body = ``, timeout = 2000;
|
|
125
|
-
const window = createDocument( head, body, window => {
|
|
126
|
-
// Define a remote response
|
|
127
|
-
const temp0 = `
|
|
128
|
-
<template exportid="temp1" src="/temp1.html" loading="lazy"></template>`;
|
|
129
|
-
const temp1 = `
|
|
130
|
-
<p>Hello world Export</p>
|
|
131
|
-
<p>Hellort</p>
|
|
132
|
-
<template exportid="temp22">
|
|
133
|
-
</template>`;
|
|
134
|
-
mockRemoteFetch( window, { '/temp0.html': temp0, '/temp1.html': temp1 }, timeout );
|
|
135
|
-
} ), document = window.document;
|
|
136
|
-
|
|
137
|
-
// Add a remote module
|
|
138
|
-
const templateEl = document.createElement( 'template' );
|
|
139
|
-
templateEl.setAttribute( 'exportid', 'temp0' );
|
|
140
|
-
templateEl.setAttribute( 'src', '/temp0.html' );
|
|
141
|
-
document.head.appendChild( templateEl );
|
|
142
|
-
// Add the import element to with a view to waiting for the remote module
|
|
143
|
-
const importEl = document.createElement( 'import' );
|
|
144
|
-
importEl.setAttribute( 'module', 'temp0/temp1' );
|
|
145
|
-
document.body.appendChild( importEl );
|
|
146
|
-
// Should stil be waiting...
|
|
147
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
148
|
-
// When remote request must have completed
|
|
149
|
-
await delay( ( timeout * 2 ) + 150 );
|
|
150
|
-
expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
|
|
151
|
-
expect( document.body.lastElementChild.nodeName ).to.eq( 'P' );
|
|
152
|
-
} );
|
|
153
|
-
} );
|
|
154
|
-
|
|
155
|
-
describe( `Hydration...`, function() {
|
|
156
|
-
|
|
157
|
-
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
158
|
-
|
|
159
|
-
const head = `
|
|
160
|
-
<template exportid="temp0">
|
|
161
|
-
<input exportid="#input" />
|
|
162
|
-
<template exportid="temp1">
|
|
163
|
-
<textarea exportid="#input"></textarea>
|
|
164
|
-
<template exportid="temp2">
|
|
165
|
-
<select exportid="#input"></select>
|
|
166
|
-
</template>
|
|
167
|
-
</template>
|
|
168
|
-
</template>`;
|
|
169
|
-
const body = `
|
|
170
|
-
<div importscontext="temp0/temp1">
|
|
171
|
-
<textarea exportid="#input"></textarea>
|
|
172
|
-
<!--<import module="#input"></import>-->
|
|
173
|
-
</div>`;
|
|
174
|
-
const { document } = createDocument( head, body );
|
|
175
|
-
await delay( 20 );
|
|
176
|
-
|
|
177
|
-
const routingElement = document.body.firstElementChild;
|
|
178
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
179
|
-
const temp1 = document.modules.temp0.modules.temp1;
|
|
180
|
-
const textarea = [ ...temp1.modules[ '#input' ] ][ 0 ];
|
|
181
|
-
textarea.remove();
|
|
182
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
183
|
-
temp1.content.prepend( textarea );
|
|
184
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
185
|
-
routingElement.firstElementChild.remove();
|
|
186
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
187
|
-
} );
|
|
188
|
-
|
|
189
|
-
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
190
|
-
|
|
191
|
-
const head = `
|
|
192
|
-
<template exportid="temp0">
|
|
193
|
-
<input exportid="#input" />
|
|
194
|
-
<template exportid="temp1">
|
|
195
|
-
<textarea exportid="#input"></textarea>
|
|
196
|
-
<template exportid="temp2">
|
|
197
|
-
<select exportid="#input"></select>
|
|
198
|
-
</template>
|
|
199
|
-
</template>
|
|
200
|
-
</template>`;
|
|
201
|
-
const body = `
|
|
202
|
-
<div importscontext="temp0/temp1">
|
|
203
|
-
<textarea exportid="#input"></textarea>
|
|
204
|
-
<!--<import module="#input"></import>-->
|
|
205
|
-
</div>`;
|
|
206
|
-
const { document } = createDocument( head, body );
|
|
207
|
-
await delay( 20 );
|
|
208
|
-
|
|
209
|
-
const routingElement = document.body.firstElementChild;
|
|
210
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
211
|
-
routingElement.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
|
|
212
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'SELECT' );
|
|
213
|
-
routingElement.removeChild( routingElement.firstElementChild );
|
|
214
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
215
|
-
routingElement.setAttribute( 'importscontext', 'temp0' );
|
|
216
|
-
expect( routingElement.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
217
|
-
} );
|
|
218
|
-
|
|
219
|
-
} );
|
|
220
|
-
|
|
221
|
-
} );
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import { createDocument, mockRemoteFetch, delay } from './index.js';
|
|
7
|
+
|
|
8
|
+
describe(`HTML Imports`, function() {
|
|
9
|
+
|
|
10
|
+
describe( `Basic...`, function() {
|
|
11
|
+
|
|
12
|
+
const head = `
|
|
13
|
+
<template exportid="temp0">
|
|
14
|
+
<p>Hello world Export</p>
|
|
15
|
+
<p>Hellort</p>
|
|
16
|
+
</template>`;
|
|
17
|
+
const body = `
|
|
18
|
+
<import module="temp0"></import>`;
|
|
19
|
+
const { document } = createDocument( head, body );
|
|
20
|
+
|
|
21
|
+
it ( `The document object and <template> elements should expose a "modules" property`, async function() {
|
|
22
|
+
expect( document ).to.have.property( 'modules' );
|
|
23
|
+
expect( document.modules.temp0 ).to.have.property( 'modules' );
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
it ( `<import> element be automatically resolved: import default export...`, async function() {
|
|
27
|
+
expect( document.body.children ).to.have.length( 2 );
|
|
28
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
it( `<import> element be resolved again: after having mutated an export right at its module.`, async function() {
|
|
32
|
+
const templateEl = document.querySelector( 'template' );
|
|
33
|
+
let added = document.createElement( 'div' );
|
|
34
|
+
templateEl.content.appendChild( added );
|
|
35
|
+
expect( document.body.children ).to.have.length( 3 );
|
|
36
|
+
} );
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
describe( `Dynamic...`, function() {
|
|
40
|
+
|
|
41
|
+
const head = `
|
|
42
|
+
<template exportid="temp0">
|
|
43
|
+
<!-- ------- -->
|
|
44
|
+
<p>Hello world Export</p>
|
|
45
|
+
<p>Hellort</p>
|
|
46
|
+
<input exportid="#input" />
|
|
47
|
+
<template exportid="temp1">
|
|
48
|
+
<textarea exportid="#input"></textarea>
|
|
49
|
+
<template exportid="temp2">
|
|
50
|
+
<select exportid="#input"></select>
|
|
51
|
+
</template>
|
|
52
|
+
</template>
|
|
53
|
+
<!-- ------- -->
|
|
54
|
+
<template exportid="_landing1">
|
|
55
|
+
<div exportid="#main.html">a</div>
|
|
56
|
+
<template exportid="_landing2">
|
|
57
|
+
<div exportid="#main.html">b</div>
|
|
58
|
+
<template exportid="_docs">
|
|
59
|
+
<div exportid="#main.html">c</div>
|
|
60
|
+
</template>
|
|
61
|
+
</template>
|
|
62
|
+
</template>
|
|
63
|
+
<!-- ------- -->
|
|
64
|
+
<template exportid="landing1" extends="_landing1">
|
|
65
|
+
<div exportid="#README.md">1</div>
|
|
66
|
+
<template exportid="landing2" extends="_landing2">
|
|
67
|
+
<div exportid="#README.md">2</div>
|
|
68
|
+
<template exportid="docs" extends="_docs">
|
|
69
|
+
<div exportid="#README.md">3</div>
|
|
70
|
+
</template>
|
|
71
|
+
</template>
|
|
72
|
+
</template>
|
|
73
|
+
<!-- ------- -->
|
|
74
|
+
</template>`;
|
|
75
|
+
const body = `
|
|
76
|
+
<import module="temp0/uuu"></import>`;
|
|
77
|
+
const { document } = createDocument( head, body );
|
|
78
|
+
const importEl = document.querySelector( 'import' );
|
|
79
|
+
|
|
80
|
+
it ( `<import> element should not be resolved: no match for given import ID...`, async function() {
|
|
81
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
82
|
+
} );
|
|
83
|
+
|
|
84
|
+
it ( `<import> element should be automatically resolved: new import ID is set...`, async function() {
|
|
85
|
+
importEl.setAttribute( 'module', 'temp0#input' );
|
|
86
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
it ( `<import> element should be automatically resolved: new moduleref is set - nested...`, async function() {
|
|
90
|
+
importEl.setAttribute( 'module', 'temp0/temp1#input' );
|
|
91
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
92
|
+
} );
|
|
93
|
+
|
|
94
|
+
it ( `<import> element should be automatically resolved: moduleref is unset - should now be inherited from <body>...`, async function() {
|
|
95
|
+
importEl.setAttribute( 'module', '#input' );
|
|
96
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
97
|
+
document.body.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
|
|
98
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'SELECT' );
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
it ( `<import> element should be automatically resolved: moduleref at <body> is changed...`, async function() {
|
|
102
|
+
document.body.setAttribute( 'importscontext', 'temp0' );
|
|
103
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
it ( `<import> element should be automatically RESTORED: slotted element is removed from DOM...`, async function() {
|
|
107
|
+
document.body.querySelector( 'input' ).remove();
|
|
108
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
109
|
+
} );
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
it ( ``, async function() {
|
|
113
|
+
console.log('"""""""""""""""""""""""""""""""""""""""""""""', document.modules.temp0.modules.landing1.modules.landing2.modules.docs.modules);
|
|
114
|
+
} );
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
} );
|
|
118
|
+
|
|
119
|
+
describe( `Remote...`, function() {
|
|
120
|
+
|
|
121
|
+
it( `<import> element from nested remote modules.`, async function() {
|
|
122
|
+
this.timeout( 10000 );
|
|
123
|
+
|
|
124
|
+
const head = ``, body = ``, timeout = 2000;
|
|
125
|
+
const window = createDocument( head, body, window => {
|
|
126
|
+
// Define a remote response
|
|
127
|
+
const temp0 = `
|
|
128
|
+
<template exportid="temp1" src="/temp1.html" loading="lazy"></template>`;
|
|
129
|
+
const temp1 = `
|
|
130
|
+
<p>Hello world Export</p>
|
|
131
|
+
<p>Hellort</p>
|
|
132
|
+
<template exportid="temp22">
|
|
133
|
+
</template>`;
|
|
134
|
+
mockRemoteFetch( window, { '/temp0.html': temp0, '/temp1.html': temp1 }, timeout );
|
|
135
|
+
} ), document = window.document;
|
|
136
|
+
|
|
137
|
+
// Add a remote module
|
|
138
|
+
const templateEl = document.createElement( 'template' );
|
|
139
|
+
templateEl.setAttribute( 'exportid', 'temp0' );
|
|
140
|
+
templateEl.setAttribute( 'src', '/temp0.html' );
|
|
141
|
+
document.head.appendChild( templateEl );
|
|
142
|
+
// Add the import element to with a view to waiting for the remote module
|
|
143
|
+
const importEl = document.createElement( 'import' );
|
|
144
|
+
importEl.setAttribute( 'module', 'temp0/temp1' );
|
|
145
|
+
document.body.appendChild( importEl );
|
|
146
|
+
// Should stil be waiting...
|
|
147
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
148
|
+
// When remote request must have completed
|
|
149
|
+
await delay( ( timeout * 2 ) + 150 );
|
|
150
|
+
expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
|
|
151
|
+
expect( document.body.lastElementChild.nodeName ).to.eq( 'P' );
|
|
152
|
+
} );
|
|
153
|
+
} );
|
|
154
|
+
|
|
155
|
+
describe( `Hydration...`, function() {
|
|
156
|
+
|
|
157
|
+
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
158
|
+
|
|
159
|
+
const head = `
|
|
160
|
+
<template exportid="temp0">
|
|
161
|
+
<input exportid="#input" />
|
|
162
|
+
<template exportid="temp1">
|
|
163
|
+
<textarea exportid="#input"></textarea>
|
|
164
|
+
<template exportid="temp2">
|
|
165
|
+
<select exportid="#input"></select>
|
|
166
|
+
</template>
|
|
167
|
+
</template>
|
|
168
|
+
</template>`;
|
|
169
|
+
const body = `
|
|
170
|
+
<div importscontext="temp0/temp1">
|
|
171
|
+
<textarea exportid="#input"></textarea>
|
|
172
|
+
<!--<import module="#input"></import>-->
|
|
173
|
+
</div>`;
|
|
174
|
+
const { document } = createDocument( head, body );
|
|
175
|
+
await delay( 20 );
|
|
176
|
+
|
|
177
|
+
const routingElement = document.body.firstElementChild;
|
|
178
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
179
|
+
const temp1 = document.modules.temp0.modules.temp1;
|
|
180
|
+
const textarea = [ ...temp1.modules[ '#input' ] ][ 0 ];
|
|
181
|
+
textarea.remove();
|
|
182
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
183
|
+
temp1.content.prepend( textarea );
|
|
184
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
185
|
+
routingElement.firstElementChild.remove();
|
|
186
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
187
|
+
} );
|
|
188
|
+
|
|
189
|
+
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
190
|
+
|
|
191
|
+
const head = `
|
|
192
|
+
<template exportid="temp0">
|
|
193
|
+
<input exportid="#input" />
|
|
194
|
+
<template exportid="temp1">
|
|
195
|
+
<textarea exportid="#input"></textarea>
|
|
196
|
+
<template exportid="temp2">
|
|
197
|
+
<select exportid="#input"></select>
|
|
198
|
+
</template>
|
|
199
|
+
</template>
|
|
200
|
+
</template>`;
|
|
201
|
+
const body = `
|
|
202
|
+
<div importscontext="temp0/temp1">
|
|
203
|
+
<textarea exportid="#input"></textarea>
|
|
204
|
+
<!--<import module="#input"></import>-->
|
|
205
|
+
</div>`;
|
|
206
|
+
const { document } = createDocument( head, body );
|
|
207
|
+
await delay( 20 );
|
|
208
|
+
|
|
209
|
+
const routingElement = document.body.firstElementChild;
|
|
210
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
211
|
+
routingElement.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
|
|
212
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'SELECT' );
|
|
213
|
+
routingElement.removeChild( routingElement.firstElementChild );
|
|
214
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
215
|
+
routingElement.setAttribute( 'importscontext', 'temp0' );
|
|
216
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
217
|
+
} );
|
|
218
|
+
|
|
219
|
+
} );
|
|
220
|
+
|
|
221
|
+
} );
|
package/test/index.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { createWindow } from '@webqit/oohtml-ssr';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* -------
|
|
9
|
-
* HELPERS
|
|
10
|
-
* -------
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export function delay( duration, callback = undefined ) {
|
|
14
|
-
return new Promise( res => {
|
|
15
|
-
setTimeout( () => res( callback && callback() ), duration );
|
|
16
|
-
} );
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function createDocument( head = '', body = '', callback = null, ) {
|
|
20
|
-
const skeletonDoc = `
|
|
21
|
-
<!DOCTYPE html>
|
|
22
|
-
<html>
|
|
23
|
-
<head>
|
|
24
|
-
<meta name="subscript-compiler-url" content="../subscript/dist/compiler.js">
|
|
25
|
-
<script ssr src="/dist/main.js"></script>
|
|
26
|
-
${ head }
|
|
27
|
-
</head>
|
|
28
|
-
<body>${ body }</body>
|
|
29
|
-
</html>`;
|
|
30
|
-
return createWindow( skeletonDoc, {
|
|
31
|
-
// Notice we do not want to use the Path utility here.
|
|
32
|
-
// Destroys the file:/// url convention especially in windows
|
|
33
|
-
url: import.meta.url.substring( 0, import.meta.url.lastIndexOf( '/test/index.js' ) ),
|
|
34
|
-
beforeParse( window ) {
|
|
35
|
-
if ( callback ) callback( window );
|
|
36
|
-
}
|
|
37
|
-
} );
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function mockRemoteFetch( window, contents, delay = 1000 ) {
|
|
41
|
-
window.fetch = url => {
|
|
42
|
-
console.info( 'Fetching .......... ', url );
|
|
43
|
-
const successResponse = () => ( { ok: true, text: () => Promise.resolve( contents[ url ] ), } );
|
|
44
|
-
return new Promise( ( res, rej ) => {
|
|
45
|
-
setTimeout( () => {
|
|
46
|
-
if ( contents[ url ] ) res( successResponse() )
|
|
47
|
-
else rej( { message: 'Not found.' } );
|
|
48
|
-
}, delay );
|
|
49
|
-
} );
|
|
50
|
-
};
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { createWindow } from '@webqit/oohtml-ssr';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* -------
|
|
9
|
+
* HELPERS
|
|
10
|
+
* -------
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function delay( duration, callback = undefined ) {
|
|
14
|
+
return new Promise( res => {
|
|
15
|
+
setTimeout( () => res( callback && callback() ), duration );
|
|
16
|
+
} );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createDocument( head = '', body = '', callback = null, ) {
|
|
20
|
+
const skeletonDoc = `
|
|
21
|
+
<!DOCTYPE html>
|
|
22
|
+
<html>
|
|
23
|
+
<head>
|
|
24
|
+
<meta name="subscript-compiler-url" content="../subscript/dist/compiler.js">
|
|
25
|
+
<script ssr src="/dist/main.js"></script>
|
|
26
|
+
${ head }
|
|
27
|
+
</head>
|
|
28
|
+
<body>${ body }</body>
|
|
29
|
+
</html>`;
|
|
30
|
+
return createWindow( skeletonDoc, {
|
|
31
|
+
// Notice we do not want to use the Path utility here.
|
|
32
|
+
// Destroys the file:/// url convention especially in windows
|
|
33
|
+
url: import.meta.url.substring( 0, import.meta.url.lastIndexOf( '/test/index.js' ) ),
|
|
34
|
+
beforeParse( window ) {
|
|
35
|
+
if ( callback ) callback( window );
|
|
36
|
+
}
|
|
37
|
+
} );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function mockRemoteFetch( window, contents, delay = 1000 ) {
|
|
41
|
+
window.fetch = url => {
|
|
42
|
+
console.info( 'Fetching .......... ', url );
|
|
43
|
+
const successResponse = () => ( { ok: true, text: () => Promise.resolve( contents[ url ] ), } );
|
|
44
|
+
return new Promise( ( res, rej ) => {
|
|
45
|
+
setTimeout( () => {
|
|
46
|
+
if ( contents[ url ] ) res( successResponse() )
|
|
47
|
+
else rej( { message: 'Not found.' } );
|
|
48
|
+
}, delay );
|
|
49
|
+
} );
|
|
50
|
+
};
|
|
51
51
|
}
|