@webqit/oohtml 2.1.43 → 2.1.45

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/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.43",
17
+ "version": "2.1.45",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -33,14 +33,14 @@
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.0.7",
42
- "@webqit/realdom": "^2.1.10",
43
- "@webqit/subscript": "^2.1.40",
41
+ "@webqit/observer": "^2.1.4",
42
+ "@webqit/realdom": "^2.1.12",
43
+ "@webqit/subscript": "^2.1.41",
44
44
  "@webqit/util": "^0.8.11"
45
45
  },
46
46
  "devDependencies": {
@@ -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
- entries.forEach( entry => {
73
- if ( entry.nodeType !== 1 ) return;
74
- const isTemplate = entry.matches( this.config.templateSelector );
75
- const exportId = ( entry.getAttribute( isTemplate ? this.config.template.attr.moduledef : this.config.template.attr.fragmentdef ) || '' ).trim();
76
- if ( !exportId ) return;
77
- if ( isConnected ) {
78
- if ( isTemplate ) { new _HTMLExportsManager( this.window, entry, this.config, this.host, this.level + 1 ); }
79
- Observer.set( this.modules, ( !isTemplate && '#' || '' ) + exportId, entry );
80
- } else {
81
- if ( isTemplate ) { _HTMLExportsManager.instance( this.window, entry ).dispose(); }
82
- Observer.deleteProperty( this.modules, ( !isTemplate && '#' || '' ) + exportId );
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 ] : response && [ response ] ) || [] );
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, midwayResults: 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
- if ( !result.value && this.host.isConnected === false ) return; // Subtree is being disposed
61
- if ( result.value || !this.contextModules ) return event.respondWith( result.value );
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
  }
@@ -51,28 +51,28 @@ export function execute( compiledScript, thisContext, script ) {
51
51
  // Rerending processes,,,
52
52
  Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
53
53
  _await( script.properties, properties => {
54
+ const _env = { 'this': thisContext };
55
+ const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
54
56
  properties.processes = properties.dependencies.map( path => {
55
- const _env = { 'this': thisContext, 'globalThis': globalThis, 'window': globalThis.window, 'self': globalThis.self };
56
- const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
57
- properties.processes = properties.dependencies.map( path => {
58
- if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
59
- return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
60
- script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
61
- } );
62
- }
63
- return Observer.deep( globalThis, path, Observer.observe, record_s => {
64
- script.rerender( ...getPaths( [], record_s ) );
57
+ if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
58
+ if ( path.length === 1 ) return;
59
+ return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
60
+ script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
65
61
  } );
62
+ }
63
+ return Observer.deep( globalThis, path, Observer.observe, record_s => {
64
+ script.rerender( ...getPaths( [], record_s ) );
66
65
  } );
67
66
  } );
68
67
  } );
69
68
  }
70
69
  const window = this, { realdom } = window.webqit;
70
+ if ( !( thisContext instanceof window.Node ) ) return script;
71
71
  realdom.realtime( window.document ).observe( thisContext, () => {
72
72
  if ( script.contract ) {
73
73
  // Rerending processes,,,
74
74
  _await( script.properties, properties => {
75
- properties.processes.forEach( process => process.abort() );
75
+ properties.processes.forEach( process => process?.abort() );
76
76
  } );
77
77
  }
78
78
  thisContext.dispatchEvent( new window.CustomEvent( 'remove' ) );
@@ -10,17 +10,16 @@ describe(`HTML Imports`, function() {
10
10
  describe( `Basic...`, function() {
11
11
 
12
12
  const head = `
13
- <template exportid="temp0">
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 module="temp0"></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 a "modules" property`, async function() {
22
- expect( document ).to.have.property( 'modules' );
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 exportid="temp0">
41
+ <template def="temp0">
43
42
  <!-- ------- -->
44
43
  <p>Hello world Export</p>
45
44
  <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>
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 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>
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 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>
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 module="temp0/uuu"></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( 'module', 'temp0#input' );
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( 'module', 'temp0/temp1#input' );
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( 'module', '#input' );
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 temp0 = `
128
- <template exportid="temp1" src="/temp1.html" loading="lazy"></template>`;
129
- const temp1 = `
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 exportid="temp22">
125
+ <template def="temp22">
133
126
  </template>`;
134
- mockRemoteFetch( window, { '/temp0.html': temp0, '/temp1.html': temp1 }, timeout );
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( 'exportid', 'temp0' );
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( 'module', 'temp0/temp1' );
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 exportid="temp0">
161
- <input exportid="#input" />
162
- <template exportid="temp1">
163
- <textarea exportid="#input"></textarea>
164
- <template exportid="temp2">
165
- <select exportid="#input"></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 exportid="#input"></textarea>
172
- <!--<import module="#input"></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
- 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' );
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 exportid="temp0">
193
- <input exportid="#input" />
194
- <template exportid="temp1">
195
- <textarea exportid="#input"></textarea>
196
- <template exportid="temp2">
197
- <select exportid="#input"></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 exportid="#input"></textarea>
204
- <!--<import module="#input"></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 );
@@ -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 exportid="temp0">
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 exportid="temp1" scoped>
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( 'modules' );
29
- expect( document.modules[ 'temp0' ] ).to.have.property( 'modules' );
30
- expect( document.modules[ 'temp0' ].exportid ).to.eq( 'temp0' );
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( 'modules' );
33
- expect( document.body.modules[ 'temp1' ] ).to.have.property( 'modules' );
34
- expect( document.body.modules[ 'temp1' ].exportid ).to.eq( 'temp1' );
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 exportid="temp0">
44
+ <template def="temp0">
41
45
  <p>Hello world Export</p>
42
46
  <p>Hellort</p>
43
- <template exportid="temp1"></template>
44
- <template exportid="temp2" inherits="temp1 temp3">
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
- const temp0 = Observer.deep( document.modules, getQueryPath( 'temp0' ), Observer.get );
54
- expect( temp0 ).to.have.property( 'modules' );
55
- expect( temp0.modules[ '#default' ] ).to.have.length( 2 );
56
- const temp2 = Observer.deep( document.modules, getQueryPath( 'temp0/temp2' ), Observer.get );
57
- expect( temp2 ).to.have.property( 'modules' );
58
- // -------
59
- const temp1Inherited = Observer.deep( document.modules, getQueryPath( 'temp0/temp2/temp1' ), Observer.get );
60
- expect( temp1Inherited ).to.have.property( 'modules' );
61
- // -------
62
- const temp3Observed = [];
63
- Observer.deep( document.modules, getQueryPath( 'temp0/temp2/temp3' ), Observer.observe, record => {
64
- temp3Observed.push( record.value );
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 temp0 = `
90
- <template exportid="temp1" src="/temp1.html" loading="lazy"></template>`;
91
- const temp1 = `
92
- <template exportid="temp2" src="/temp2.html"></template>`;
93
- const temp2 = `
94
- <template exportid="temp3"></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': temp0, '/temp1.html': temp1, '/temp2.html': temp2 }, timeout );
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( 'exportid', 'temp0' );
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
- const temp0 = Observer.deep( document.modules, getQueryPath( 'temp0' ), Observer.get );
112
- expect( temp0 ).to.have.property( 'modules' );
113
- await delay( 2100 );
114
- // temp1 shouldn't have been automatically loaded still
115
- const hasTemp1 = Observer.deep( document.modules, getQueryPath( 'temp0/temp1' ), Observer.has );
116
- expect( hasTemp1 ).to.be.false;
117
- // Try access temp1 to trigger loading and await
118
- const _temp1 = await Observer.deep( document.modules, getQueryPath( 'temp0/temp1' ), Observer.get );
119
- expect( _temp1 ).to.have.property( 'modules' );
120
- // -------
121
- // Receive updates
122
- const temp3Observed = [];
123
- Observer.deep( document.modules, getQueryPath( 'temp0/temp1/temp2/temp3' ), Observer.observe, ( record, lifecycle ) => {
124
- temp3Observed.push( record.value );
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 exportid="temp0">
142
- <template exportid="temp-head1">
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( 'exportid', 'temp0' );
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: 'HTMLModules', live: true, ...params };
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
- const unscoped = document.modules.temp0;
193
- unscoped.remove();
194
- document.head.appendChild( unscoped );
195
- document.body.remove();
196
- expect( modulesObjs ).to.have.length( 5 );
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