@webqit/oohtml 2.1.43 → 2.1.44
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/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 +2 -2
- package/dist/html-imports.js +1 -1
- package/dist/html-imports.js.map +3 -3
- package/dist/main.js +13 -13
- 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 +1 -1
- package/dist/scoped-css.js.map +2 -2
- package/dist/scoped-js.js +11 -11
- package/dist/scoped-js.js.map +3 -3
- package/package.json +4 -4
- package/src/html-imports/_HTMLExportsManager.js +28 -13
- package/src/html-imports/_HTMLImportElement.js +4 -2
- package/src/html-imports/_HTMLImportsProvider.js +6 -4
- package/src/scoped-js/index.js +1 -0
- package/test/imports.test.js +58 -64
- package/test/modules.test.js +81 -73
- package/test/scoped-css.test.js +1 -1
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"wicg-proposal"
|
|
15
15
|
],
|
|
16
16
|
"homepage": "https://webqit.io/tooling/oohtml",
|
|
17
|
-
"version": "2.1.
|
|
17
|
+
"version": "2.1.44",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"test": "mocha --extension .test.js --exit",
|
|
34
34
|
"test:coverage": "c8 --reporter=text-lcov npm run test | coveralls",
|
|
35
35
|
"build": "esbuild main=src/targets.browser.js bindings-api=src/bindings-api/targets.browser.js context-api=src/context-api/targets.browser.js namespace-api=src/namespace-api/targets.browser.js html-imports=src/html-imports/targets.browser.js scoped-js=src/scoped-js/targets.browser.js scoped-css=src/scoped-css/targets.browser.js --bundle --minify --sourcemap --outdir=dist",
|
|
36
|
-
"preversion": "npm run build && git add -A dist",
|
|
36
|
+
"preversion": "npm run test && npm run build && git add -A dist",
|
|
37
37
|
"postversion": "npm publish",
|
|
38
38
|
"postpublish": "git push && git push --tags"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@webqit/observer": "^2.
|
|
42
|
-
"@webqit/realdom": "^2.1.
|
|
41
|
+
"@webqit/observer": "^2.1.4",
|
|
42
|
+
"@webqit/realdom": "^2.1.11",
|
|
43
43
|
"@webqit/subscript": "^2.1.40",
|
|
44
44
|
"@webqit/util": "^0.8.11"
|
|
45
45
|
},
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
5
|
import Observer from '@webqit/observer';
|
|
6
|
+
import { _isNumeric } from '@webqit/util/js/index.js';
|
|
6
7
|
import { getModulesObject } from './index.js';
|
|
7
8
|
import { _ } from '../util.js';
|
|
8
9
|
|
|
@@ -55,7 +56,7 @@ export default class _HTMLExportsManager {
|
|
|
55
56
|
* @returns Void
|
|
56
57
|
*/
|
|
57
58
|
validateExportId( exportId ) {
|
|
58
|
-
if ( [ '@', '/', '#' ].some( token => exportId.includes( token ) ) ) {
|
|
59
|
+
if ( [ '@', '/', '*', '#' ].some( token => exportId.includes( token ) ) ) {
|
|
59
60
|
throw new Error( `The export ID "${ exportId }" contains an invalid character.` );
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -69,18 +70,32 @@ export default class _HTMLExportsManager {
|
|
|
69
70
|
* @returns Void
|
|
70
71
|
*/
|
|
71
72
|
export( entries, isConnected ) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
let dirty, allFragments = Observer.get( this.modules, '#' ) || [];
|
|
74
|
+
Observer.batch( this.modules, () => {
|
|
75
|
+
entries.forEach( entry => {
|
|
76
|
+
if ( entry.nodeType !== 1 ) return;
|
|
77
|
+
const isTemplate = entry.matches( this.config.templateSelector );
|
|
78
|
+
const exportId = ( entry.getAttribute( isTemplate ? this.config.template.attr.moduledef : this.config.template.attr.fragmentdef ) || '' ).trim();
|
|
79
|
+
if ( isConnected ) {
|
|
80
|
+
if ( isTemplate && exportId ) { new _HTMLExportsManager( this.window, entry, this.config, this.host, this.level + 1 ); }
|
|
81
|
+
else {
|
|
82
|
+
allFragments.push( entry );
|
|
83
|
+
dirty = true;
|
|
84
|
+
}
|
|
85
|
+
if ( exportId ) {
|
|
86
|
+
this.validateExportId( exportId );
|
|
87
|
+
Observer.set( this.modules, ( !isTemplate && '#' || '' ) + exportId, entry );
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
if ( isTemplate && exportId ) { _HTMLExportsManager.instance( this.window, entry ).dispose(); }
|
|
91
|
+
else {
|
|
92
|
+
allFragments = allFragments.filter( x => x !== entry );
|
|
93
|
+
dirty = true;
|
|
94
|
+
}
|
|
95
|
+
if ( exportId ) Observer.deleteProperty( this.modules, ( !isTemplate && '#' || '' ) + exportId );
|
|
96
|
+
}
|
|
97
|
+
} );
|
|
98
|
+
if ( dirty ) Observer.set( this.modules, '#', allFragments );
|
|
84
99
|
} );
|
|
85
100
|
}
|
|
86
101
|
|
|
@@ -50,9 +50,11 @@ export default function( config ) {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
priv.importRequest = ( callback, signal = null ) => {
|
|
53
|
-
const request = _HTMLImportsContext.createRequest( { detail: priv.moduleRef, live: signal && true, signal } );
|
|
53
|
+
const request = _HTMLImportsContext.createRequest( { detail: priv.moduleRef && !priv.moduleRef.includes( '#' ) ? priv.moduleRef + '#' : priv.moduleRef, live: signal && true, signal } );
|
|
54
54
|
HTMLContext.instance( this.el.isConnected ? this.el.parentNode : priv.anchorNode.parentNode ).request( request, response => {
|
|
55
|
-
callback( ( response instanceof window.HTMLTemplateElement ? [ ...response.content.children ] :
|
|
55
|
+
callback( ( response instanceof window.HTMLTemplateElement ? [ ...response.content.children ] : (
|
|
56
|
+
Array.isArray( response ) ? response : response && [ response ]
|
|
57
|
+
) ) || [] );
|
|
56
58
|
} );
|
|
57
59
|
};
|
|
58
60
|
|
|
@@ -54,14 +54,16 @@ export default class _HTMLImportsProvider extends HTMLContextProvider {
|
|
|
54
54
|
if ( !path.length ) return event.respondWith();
|
|
55
55
|
|
|
56
56
|
// We'll now fulfill request
|
|
57
|
-
const options = { live: event.request.live, descripted: true
|
|
57
|
+
const options = { live: event.request.live, descripted: true };
|
|
58
58
|
// Find a way to resolve request against two sources
|
|
59
59
|
event.request.controller = Observer.deep( this.localModules, path, Observer.get, ( result, { signal } = {} ) => {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const _result = Array.isArray( result ) ? result : result.value;
|
|
61
|
+
const _isValidResult = Array.isArray( result ) ? result.length : result.value;
|
|
62
|
+
if ( !_isValidResult && this.host.isConnected === false ) return; // Subtree is being disposed
|
|
63
|
+
if ( _isValidResult || !this.contextModules ) return event.respondWith( _result );
|
|
62
64
|
// This superModules binding is automatically aborted by the injected control.signal; see below
|
|
63
65
|
return Observer.deep( this.contextModules, path, Observer.get, result => {
|
|
64
|
-
return event.respondWith( result.value );
|
|
66
|
+
return event.respondWith( Array.isArray( result ) ? result : result.value );
|
|
65
67
|
}, { signal, ...options } );
|
|
66
68
|
}, options );
|
|
67
69
|
}
|
package/src/scoped-js/index.js
CHANGED
|
@@ -56,6 +56,7 @@ export function execute( compiledScript, thisContext, script ) {
|
|
|
56
56
|
const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
|
|
57
57
|
properties.processes = properties.dependencies.map( path => {
|
|
58
58
|
if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
|
|
59
|
+
if ( path.length === 1 ) return;
|
|
59
60
|
return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
|
|
60
61
|
script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
|
|
61
62
|
} );
|
package/test/imports.test.js
CHANGED
|
@@ -10,17 +10,16 @@ describe(`HTML Imports`, function() {
|
|
|
10
10
|
describe( `Basic...`, function() {
|
|
11
11
|
|
|
12
12
|
const head = `
|
|
13
|
-
<template
|
|
13
|
+
<template def="temp0">
|
|
14
14
|
<p>Hello world Export</p>
|
|
15
15
|
<p>Hellort</p>
|
|
16
16
|
</template>`;
|
|
17
17
|
const body = `
|
|
18
|
-
<import
|
|
18
|
+
<import ref="temp0"></import>`;
|
|
19
19
|
const { document } = createDocument( head, body );
|
|
20
20
|
|
|
21
|
-
it ( `The document object and <template> elements should expose
|
|
22
|
-
expect( document ).to.have.property( '
|
|
23
|
-
expect( document.modules.temp0 ).to.have.property( 'modules' );
|
|
21
|
+
it ( `The document object and <template> elements should expose an "import" property`, async function() {
|
|
22
|
+
expect( document ).to.have.property( 'import' );
|
|
24
23
|
} );
|
|
25
24
|
|
|
26
25
|
it ( `<import> element be automatically resolved: import default export...`, async function() {
|
|
@@ -39,41 +38,41 @@ describe(`HTML Imports`, function() {
|
|
|
39
38
|
describe( `Dynamic...`, function() {
|
|
40
39
|
|
|
41
40
|
const head = `
|
|
42
|
-
<template
|
|
41
|
+
<template def="temp0">
|
|
43
42
|
<!-- ------- -->
|
|
44
43
|
<p>Hello world Export</p>
|
|
45
44
|
<p>Hellort</p>
|
|
46
|
-
<input
|
|
47
|
-
<template
|
|
48
|
-
<textarea
|
|
49
|
-
<template
|
|
50
|
-
<select
|
|
45
|
+
<input def="input" />
|
|
46
|
+
<template def="temp1">
|
|
47
|
+
<textarea def="input"></textarea>
|
|
48
|
+
<template def="temp2">
|
|
49
|
+
<select def="input"></select>
|
|
51
50
|
</template>
|
|
52
51
|
</template>
|
|
53
52
|
<!-- ------- -->
|
|
54
|
-
<template
|
|
55
|
-
<div
|
|
56
|
-
<template
|
|
57
|
-
<div
|
|
58
|
-
<template
|
|
59
|
-
<div
|
|
53
|
+
<template def="_landing1">
|
|
54
|
+
<div def="main.html">a</div>
|
|
55
|
+
<template def="_landing2">
|
|
56
|
+
<div def="main.html">b</div>
|
|
57
|
+
<template def="_docs">
|
|
58
|
+
<div def="main.html">c</div>
|
|
60
59
|
</template>
|
|
61
60
|
</template>
|
|
62
61
|
</template>
|
|
63
62
|
<!-- ------- -->
|
|
64
|
-
<template
|
|
65
|
-
<div
|
|
66
|
-
<template
|
|
67
|
-
<div
|
|
68
|
-
<template
|
|
69
|
-
<div
|
|
63
|
+
<template def="landing1" extends="_landing1">
|
|
64
|
+
<div def="README.md">1</div>
|
|
65
|
+
<template def="landing2" extends="_landing2">
|
|
66
|
+
<div def="README.md">2</div>
|
|
67
|
+
<template def="docs" extends="_docs">
|
|
68
|
+
<div def="README.md">3</div>
|
|
70
69
|
</template>
|
|
71
70
|
</template>
|
|
72
71
|
</template>
|
|
73
72
|
<!-- ------- -->
|
|
74
73
|
</template>`;
|
|
75
74
|
const body = `
|
|
76
|
-
<import
|
|
75
|
+
<import ref="temp0/uuu"></import>`;
|
|
77
76
|
const { document } = createDocument( head, body );
|
|
78
77
|
const importEl = document.querySelector( 'import' );
|
|
79
78
|
|
|
@@ -82,17 +81,17 @@ describe(`HTML Imports`, function() {
|
|
|
82
81
|
} );
|
|
83
82
|
|
|
84
83
|
it ( `<import> element should be automatically resolved: new import ID is set...`, async function() {
|
|
85
|
-
importEl.setAttribute( '
|
|
84
|
+
importEl.setAttribute( 'ref', 'temp0#input' );
|
|
86
85
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
|
|
87
86
|
} );
|
|
88
87
|
|
|
89
88
|
it ( `<import> element should be automatically resolved: new moduleref is set - nested...`, async function() {
|
|
90
|
-
importEl.setAttribute( '
|
|
89
|
+
importEl.setAttribute( 'ref', 'temp0/temp1#input' );
|
|
91
90
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
92
91
|
} );
|
|
93
92
|
|
|
94
93
|
it ( `<import> element should be automatically resolved: moduleref is unset - should now be inherited from <body>...`, async function() {
|
|
95
|
-
importEl.setAttribute( '
|
|
94
|
+
importEl.setAttribute( 'ref', '#input' );
|
|
96
95
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
97
96
|
document.body.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
|
|
98
97
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'SELECT' );
|
|
@@ -107,12 +106,6 @@ describe(`HTML Imports`, function() {
|
|
|
107
106
|
document.body.querySelector( 'input' ).remove();
|
|
108
107
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
109
108
|
} );
|
|
110
|
-
|
|
111
|
-
/*
|
|
112
|
-
it ( ``, async function() {
|
|
113
|
-
console.log('"""""""""""""""""""""""""""""""""""""""""""""', document.modules.temp0.modules.landing1.modules.landing2.modules.docs.modules);
|
|
114
|
-
} );
|
|
115
|
-
*/
|
|
116
109
|
|
|
117
110
|
} );
|
|
118
111
|
|
|
@@ -124,24 +117,24 @@ describe(`HTML Imports`, function() {
|
|
|
124
117
|
const head = ``, body = ``, timeout = 2000;
|
|
125
118
|
const window = createDocument( head, body, window => {
|
|
126
119
|
// Define a remote response
|
|
127
|
-
const
|
|
128
|
-
<template
|
|
129
|
-
const
|
|
120
|
+
const contents0 = `
|
|
121
|
+
<template def="temp1" src="/temp1.html" loading="lazy"></template>`;
|
|
122
|
+
const contents1 = `
|
|
130
123
|
<p>Hello world Export</p>
|
|
131
124
|
<p>Hellort</p>
|
|
132
|
-
<template
|
|
125
|
+
<template def="temp22">
|
|
133
126
|
</template>`;
|
|
134
|
-
mockRemoteFetch( window, { '/temp0.html':
|
|
127
|
+
mockRemoteFetch( window, { '/temp0.html': contents0, '/temp1.html': contents1 }, timeout );
|
|
135
128
|
} ), document = window.document;
|
|
136
129
|
|
|
137
130
|
// Add a remote module
|
|
138
131
|
const templateEl = document.createElement( 'template' );
|
|
139
|
-
templateEl.setAttribute( '
|
|
132
|
+
templateEl.setAttribute( 'def', 'temp0' );
|
|
140
133
|
templateEl.setAttribute( 'src', '/temp0.html' );
|
|
141
134
|
document.head.appendChild( templateEl );
|
|
142
135
|
// Add the import element to with a view to waiting for the remote module
|
|
143
136
|
const importEl = document.createElement( 'import' );
|
|
144
|
-
importEl.setAttribute( '
|
|
137
|
+
importEl.setAttribute( 'ref', 'temp0/temp1' );
|
|
145
138
|
document.body.appendChild( importEl );
|
|
146
139
|
// Should stil be waiting...
|
|
147
140
|
expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
@@ -157,51 +150,52 @@ describe(`HTML Imports`, function() {
|
|
|
157
150
|
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
158
151
|
|
|
159
152
|
const head = `
|
|
160
|
-
<template
|
|
161
|
-
<input
|
|
162
|
-
<template
|
|
163
|
-
<textarea
|
|
164
|
-
<template
|
|
165
|
-
<select
|
|
153
|
+
<template def="temp0">
|
|
154
|
+
<input def="input" />
|
|
155
|
+
<template def="temp1">
|
|
156
|
+
<textarea def="input"></textarea>
|
|
157
|
+
<template def="temp2">
|
|
158
|
+
<select def="input"></select>
|
|
166
159
|
</template>
|
|
167
160
|
</template>
|
|
168
161
|
</template>`;
|
|
169
162
|
const body = `
|
|
170
163
|
<div importscontext="temp0/temp1">
|
|
171
|
-
<textarea
|
|
172
|
-
<!--<import
|
|
164
|
+
<textarea def="input"></textarea>
|
|
165
|
+
<!--<import ref="#input"></import>-->
|
|
173
166
|
</div>`;
|
|
174
167
|
const { document } = createDocument( head, body );
|
|
175
168
|
await delay( 20 );
|
|
176
169
|
|
|
177
170
|
const routingElement = document.body.firstElementChild;
|
|
178
171
|
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
document.import( 'temp0/temp1', temp1 => {
|
|
173
|
+
const textarea = temp1.modules[ '#input' ];
|
|
174
|
+
textarea.remove();
|
|
175
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
176
|
+
temp1.content.prepend( textarea );
|
|
177
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
|
|
178
|
+
routingElement.firstElementChild.remove();
|
|
179
|
+
expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
|
|
180
|
+
} );
|
|
187
181
|
} );
|
|
188
182
|
|
|
189
183
|
it ( `Server-resolved <import> element should maintain relationship with slotted elements...`, async function() {
|
|
190
184
|
|
|
191
185
|
const head = `
|
|
192
|
-
<template
|
|
193
|
-
<input
|
|
194
|
-
<template
|
|
195
|
-
<textarea
|
|
196
|
-
<template
|
|
197
|
-
<select
|
|
186
|
+
<template def="temp0">
|
|
187
|
+
<input def="input" />
|
|
188
|
+
<template def="temp1">
|
|
189
|
+
<textarea def="input"></textarea>
|
|
190
|
+
<template def="temp2">
|
|
191
|
+
<select def="input"></select>
|
|
198
192
|
</template>
|
|
199
193
|
</template>
|
|
200
194
|
</template>`;
|
|
201
195
|
const body = `
|
|
202
196
|
<div importscontext="temp0/temp1">
|
|
203
|
-
<textarea
|
|
204
|
-
<!--<import
|
|
197
|
+
<textarea def="input"></textarea>
|
|
198
|
+
<!--<import ref="#input"></import>-->
|
|
205
199
|
</div>`;
|
|
206
200
|
const { document } = createDocument( head, body );
|
|
207
201
|
await delay( 20 );
|
package/test/modules.test.js
CHANGED
|
@@ -13,35 +13,39 @@ describe(`HTML Modules`, function() {
|
|
|
13
13
|
it ( `The document object and <template> elements should expose a "modules" property...`, async function() {
|
|
14
14
|
|
|
15
15
|
const head = `
|
|
16
|
-
<template
|
|
16
|
+
<template def="temp0">
|
|
17
17
|
<p>Hello world Export</p>
|
|
18
18
|
<p>Hellort</p>
|
|
19
19
|
</template>`;
|
|
20
20
|
const body = `
|
|
21
|
-
<template
|
|
21
|
+
<template def="temp1" scoped>
|
|
22
22
|
<p>Hello world Export</p>
|
|
23
23
|
<p>Hellort</p>
|
|
24
24
|
</template>`;
|
|
25
25
|
const { document } = createDocument( head, body );
|
|
26
26
|
await delay( 200 );
|
|
27
27
|
// -------
|
|
28
|
-
expect( document ).to.have.property( '
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
expect( document ).to.have.property( 'import' );
|
|
29
|
+
document.import( 'temp0', temp0 => {
|
|
30
|
+
expect( temp0 ).to.have.property( 'modules' );
|
|
31
|
+
expect( temp0.def ).to.eq( 'temp0' );
|
|
32
|
+
} );
|
|
31
33
|
// -------
|
|
32
|
-
expect( document.body ).to.have.property( '
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
expect( document.body ).to.have.property( 'import' );
|
|
35
|
+
document.body.import( 'temp1', temp1 => {
|
|
36
|
+
expect( temp1 ).to.have.property( 'modules' );
|
|
37
|
+
expect( temp1.def ).to.eq( 'temp1' );
|
|
38
|
+
} );
|
|
39
|
+
} );
|
|
36
40
|
|
|
37
41
|
it ( `The document object and <template> elements should expose a "modules" property...`, async function() {
|
|
38
42
|
|
|
39
43
|
const body = '', head = `
|
|
40
|
-
<template
|
|
44
|
+
<template def="temp0">
|
|
41
45
|
<p>Hello world Export</p>
|
|
42
46
|
<p>Hellort</p>
|
|
43
|
-
<template
|
|
44
|
-
<template
|
|
47
|
+
<template def="temp1"></template>
|
|
48
|
+
<template def="temp2" inherits="temp1 temp3">
|
|
45
49
|
<p>Hello world Export</p>
|
|
46
50
|
<p>Hellort</p>
|
|
47
51
|
</template>
|
|
@@ -50,31 +54,32 @@ describe(`HTML Modules`, function() {
|
|
|
50
54
|
await delay( 20 );
|
|
51
55
|
const { webqit: { Observer } } = window;
|
|
52
56
|
// -------
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
document.import( 'temp0', temp0 => {
|
|
58
|
+
expect( temp0 ).to.have.property( 'modules' );
|
|
59
|
+
expect( temp0.modules[ '#' ] ).to.have.length( 2 );
|
|
60
|
+
const temp2 = Observer.deep( temp0.modules, getQueryPath( 'temp2' ), Observer.get );
|
|
61
|
+
expect( temp2 ).to.have.property( 'modules' );
|
|
62
|
+
// -------
|
|
63
|
+
const temp1Inherited = Observer.deep( temp0.modules, getQueryPath( 'temp2/temp1' ), Observer.get );
|
|
64
|
+
expect( temp1Inherited ).to.have.property( 'modules' );
|
|
65
|
+
// -------
|
|
66
|
+
const temp3Observed = [];
|
|
67
|
+
Observer.deep( temp0.modules, getQueryPath( 'temp2/temp3' ), Observer.observe, record => {
|
|
68
|
+
temp3Observed.push( record.value );
|
|
69
|
+
} );
|
|
70
|
+
// -------
|
|
71
|
+
const temp3 = document.createElement( 'template' );
|
|
72
|
+
temp3.setAttribute( 'def', 'temp3' );
|
|
73
|
+
temp0.content.appendChild( temp3 );
|
|
74
|
+
// -------
|
|
75
|
+
expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
|
|
76
|
+
expect( temp3Observed[ 0 ] ).to.have.property( 'modules' );
|
|
77
|
+
// -------
|
|
78
|
+
const temp3Inherited = Observer.deep( temp0.modules, getQueryPath( 'temp2/temp3' ), Observer.get );
|
|
79
|
+
expect( temp3Inherited ).to.have.property( 'modules' );
|
|
80
|
+
// -------
|
|
65
81
|
} );
|
|
66
|
-
|
|
67
|
-
const temp3 = document.createElement( 'template' );
|
|
68
|
-
temp3.setAttribute( 'exportid', 'temp3' );
|
|
69
|
-
temp0.content.appendChild( temp3 );
|
|
70
|
-
// -------
|
|
71
|
-
expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
|
|
72
|
-
expect( temp3Observed[ 0 ] ).to.have.property( 'modules' );
|
|
73
|
-
// -------
|
|
74
|
-
const temp3Inherited = Observer.deep( document.modules, getQueryPath( 'temp0/temp2/temp3' ), Observer.get );
|
|
75
|
-
expect( temp3Inherited ).to.have.property( 'modules' );
|
|
76
|
-
// -------
|
|
77
|
-
} );
|
|
82
|
+
} );
|
|
78
83
|
|
|
79
84
|
} );
|
|
80
85
|
|
|
@@ -86,49 +91,50 @@ describe(`HTML Modules`, function() {
|
|
|
86
91
|
const head = ``, body = ``;
|
|
87
92
|
const { document, window } = createDocument( head, body, window => {
|
|
88
93
|
// Define remote responses
|
|
89
|
-
const
|
|
90
|
-
<template
|
|
91
|
-
const
|
|
92
|
-
<template
|
|
93
|
-
const
|
|
94
|
-
<template
|
|
94
|
+
const contents0 = `
|
|
95
|
+
<template def="temp1" src="/temp1.html" loading="lazy"></template>`;
|
|
96
|
+
const contents1 = `
|
|
97
|
+
<template def="temp2" src="/temp2.html"></template>`;
|
|
98
|
+
const contents2 = `
|
|
99
|
+
<template def="temp3"></template>
|
|
95
100
|
<p>Hello world Export</p>
|
|
96
101
|
<p>Hellort</p>`;
|
|
97
102
|
const timeout = 1000;
|
|
98
|
-
mockRemoteFetch( window, { '/temp0.html':
|
|
103
|
+
mockRemoteFetch( window, { '/temp0.html': contents0, '/temp1.html': contents1, '/temp2.html': contents2 }, timeout );
|
|
99
104
|
} );
|
|
100
105
|
await delay( 20 );
|
|
101
106
|
const { webqit: { Observer } } = window;
|
|
102
107
|
// -------
|
|
103
108
|
// Add a remote module
|
|
104
109
|
const templateEl = document.createElement( 'template' );
|
|
105
|
-
templateEl.setAttribute( '
|
|
110
|
+
templateEl.setAttribute( 'def', 'temp0' );
|
|
106
111
|
templateEl.setAttribute( 'loading', 'lazy' );
|
|
107
112
|
templateEl.setAttribute( 'src', '/temp0.html' );
|
|
108
113
|
document.head.appendChild( templateEl );
|
|
109
114
|
// -------
|
|
110
115
|
// Add the import element to with a view to waiting for the remote module
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
document.import( 'temp0', async temp0 => {
|
|
117
|
+
expect( temp0 ).to.have.property( 'modules' );
|
|
118
|
+
await delay( 2100 );
|
|
119
|
+
// temp1 shouldn't have been automatically loaded still
|
|
120
|
+
const hasTemp1 = Observer.deep( temp0.modules, getQueryPath( 'temp1' ), Observer.has );
|
|
121
|
+
expect( hasTemp1 ).to.be.false;
|
|
122
|
+
// Try access temp1 to trigger loading and await
|
|
123
|
+
const _temp1 = await Observer.deep( temp0.modules, getQueryPath( 'temp1' ), Observer.get );
|
|
124
|
+
expect( _temp1 ).to.have.property( 'modules' );
|
|
125
|
+
// -------
|
|
126
|
+
// Receive updates
|
|
127
|
+
const temp3Observed = [];
|
|
128
|
+
Observer.deep( temp0.modules, getQueryPath( 'temp1/temp2/temp3' ), Observer.observe, ( record, lifecycle ) => {
|
|
129
|
+
temp3Observed.push( record.value );
|
|
130
|
+
} );
|
|
131
|
+
await delay( 2100 );
|
|
132
|
+
// -------
|
|
133
|
+
// temp2 should be loaded by now
|
|
134
|
+
expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
|
|
135
|
+
expect( temp3Observed[ 0 ] ).to.have.property( 'modules' );
|
|
136
|
+
expect( temp3Observed[ 0 ].getAttribute( 'def' ) ).to.eq( 'temp3' );
|
|
125
137
|
} );
|
|
126
|
-
await delay( 2100 );
|
|
127
|
-
// -------
|
|
128
|
-
// temp2 should be loaded by now
|
|
129
|
-
expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
|
|
130
|
-
expect( temp3Observed[ 0 ] ).to.have.property( 'modules' );
|
|
131
|
-
expect( temp3Observed[ 0 ].getAttribute( 'exportid' ) ).to.eq( 'temp3' );
|
|
132
138
|
} );
|
|
133
139
|
} );
|
|
134
140
|
|
|
@@ -138,8 +144,8 @@ describe(`HTML Modules`, function() {
|
|
|
138
144
|
it( `Use the context API to fire a scoped-request that is imitially resolved from the document and then from a scoped context.`, async function() {
|
|
139
145
|
|
|
140
146
|
const head = `
|
|
141
|
-
<template
|
|
142
|
-
<template
|
|
147
|
+
<template def="temp0">
|
|
148
|
+
<template def="temp-head1">
|
|
143
149
|
<p>Hello world Export</p>
|
|
144
150
|
<p>Hellort</p>
|
|
145
151
|
</template>
|
|
@@ -152,7 +158,7 @@ describe(`HTML Modules`, function() {
|
|
|
152
158
|
// -------
|
|
153
159
|
const addScopedModules = () => {
|
|
154
160
|
const templateEl = document.createElement( 'template' );
|
|
155
|
-
templateEl.setAttribute( '
|
|
161
|
+
templateEl.setAttribute( 'def', 'temp0' );
|
|
156
162
|
templateEl.toggleAttribute( 'scoped', true );
|
|
157
163
|
const scoped = document.body.appendChild( templateEl );
|
|
158
164
|
document.body.setAttribute( 'importscontext', '/' );
|
|
@@ -160,7 +166,7 @@ describe(`HTML Modules`, function() {
|
|
|
160
166
|
};
|
|
161
167
|
// -------
|
|
162
168
|
const contextRequest = ( el, params, callback ) => {
|
|
163
|
-
const request = { type: '
|
|
169
|
+
const request = { type: 'htmlimports', live: true, ...params };
|
|
164
170
|
const event = new document.context.ContextRequestEvent( request, callback, {
|
|
165
171
|
bubbles: true,
|
|
166
172
|
} );
|
|
@@ -189,11 +195,13 @@ describe(`HTML Modules`, function() {
|
|
|
189
195
|
expect( modulesObjs ).to.have.length( 5 );
|
|
190
196
|
expect( modulesObjs[ 4 ] ).to.have.property( 'scoped', true );
|
|
191
197
|
// -------
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
document.import( 'temp0', temp0 => {
|
|
199
|
+
const unscoped = temp0;
|
|
200
|
+
unscoped.remove();
|
|
201
|
+
document.head.appendChild( unscoped );
|
|
202
|
+
document.body.remove();
|
|
203
|
+
expect( modulesObjs ).to.have.length( 5 );
|
|
204
|
+
} );
|
|
197
205
|
} );
|
|
198
206
|
} );
|
|
199
207
|
|
package/test/scoped-css.test.js
CHANGED
|
@@ -10,7 +10,7 @@ describe(`Test: Scoped CSS`, function() {
|
|
|
10
10
|
describe(`Styles`, function() {
|
|
11
11
|
|
|
12
12
|
it(`Should do basic rewrite`, async function() {
|
|
13
|
-
const head = '', body = `
|
|
13
|
+
const head = '<meta name="scoped-css" content="style.strategy=@scope">', body = `
|
|
14
14
|
<div>
|
|
15
15
|
<h1>Hello World!</h1>
|
|
16
16
|
<style scoped>
|