@webqit/oohtml 3.1.7 → 3.1.9

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.
@@ -3,7 +3,7 @@
3
3
  * @imports
4
4
  */
5
5
  import { expect } from 'chai';
6
- import { createDocument, mockRemoteFetch, delay } from './index.js';
6
+ import { createDocument, createDocumentPrefixed, mockRemoteFetch, delay } from './index.js';
7
7
 
8
8
  describe(`HTML Imports`, function() {
9
9
 
@@ -38,73 +38,73 @@ describe(`HTML Imports`, function() {
38
38
  describe( `Dynamic...`, function() {
39
39
 
40
40
  const head = `
41
- <template def="temp0">
41
+ <template wq-def="temp0">
42
42
  <!-- ------- -->
43
43
  <p>Hello world Export</p>
44
44
  <p>Hellort</p>
45
- <input def="input" />
46
- <template def="temp1">
47
- <textarea def="input"></textarea>
48
- <template def="temp2">
49
- <select def="input"></select>
45
+ <input wq-def="input" />
46
+ <template wq-def="temp1">
47
+ <textarea wq-def="input"></textarea>
48
+ <template wq-def="temp2">
49
+ <select wq-def="input"></select>
50
50
  </template>
51
51
  </template>
52
52
  <!-- ------- -->
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>
53
+ <template wq-def="_landing1">
54
+ <div wq-def="main.html">a</div>
55
+ <template wq-def="_landing2">
56
+ <div wq-def="main.html">b</div>
57
+ <template wq-def="_docs">
58
+ <div wq-def="main.html">c</div>
59
59
  </template>
60
60
  </template>
61
61
  </template>
62
62
  <!-- ------- -->
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>
63
+ <template wq-def="landing1" wq-extends="_landing1">
64
+ <div wq-def="README.md">1</div>
65
+ <template wq-def="landing2" wq-extends="_landing2">
66
+ <div wq-def="README.md">2</div>
67
+ <template wq-def="docs" wq-extends="_docs">
68
+ <div wq-def="README.md">3</div>
69
69
  </template>
70
70
  </template>
71
71
  </template>
72
72
  <!-- ------- -->
73
73
  </template>`;
74
74
  const body = `
75
- <import ref="temp0/uuu"></import>`;
76
- const { document } = createDocument( head, body );
77
- const importEl = document.querySelector( 'import' );
75
+ <wq-import wq-ref="temp0/uuu"></wq-import>`;
76
+ const { document } = createDocumentPrefixed( 'wq', head, body );
77
+ const importEl = document.querySelector( 'wq-import' );
78
78
 
79
79
  it ( `<import> element should not be resolved: no match for given import ID...`, async function() {
80
- expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
80
+ expect( document.body.firstElementChild.nodeName ).to.eq( 'WQ-IMPORT' );
81
81
  } );
82
82
 
83
83
  it ( `<import> element should be automatically resolved: new import ID is set...`, async function() {
84
- importEl.setAttribute( 'ref', 'temp0#input' );
84
+ importEl.setAttribute( 'wq-ref', 'temp0#input' );
85
85
  expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
86
86
  } );
87
87
 
88
88
  it ( `<import> element should be automatically resolved: new moduleref is set - nested...`, async function() {
89
- importEl.setAttribute( 'ref', 'temp0/temp1#input' );
89
+ importEl.setAttribute( 'wq-ref', 'temp0/temp1#input' );
90
90
  expect( document.body.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
91
91
  } );
92
92
 
93
93
  it ( `<import> element should be automatically resolved: moduleref is unset - should now be inherited from <body>...`, async function() {
94
- importEl.setAttribute( 'ref', '#input' );
95
- expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
96
- document.body.setAttribute( 'importscontext', 'temp0/temp1/temp2' );
94
+ importEl.setAttribute( 'wq-ref', '#input' );
95
+ expect( document.body.firstElementChild.nodeName ).to.eq( 'WQ-IMPORT' );
96
+ document.body.setAttribute( 'wq-importscontext', 'temp0/temp1/temp2' );
97
97
  expect( document.body.firstElementChild.nodeName ).to.eq( 'SELECT' );
98
98
  } );
99
99
 
100
100
  it ( `<import> element should be automatically resolved: moduleref at <body> is changed...`, async function() {
101
- document.body.setAttribute( 'importscontext', 'temp0' );
101
+ document.body.setAttribute( 'wq-importscontext', 'temp0' );
102
102
  expect( document.body.firstElementChild.nodeName ).to.eq( 'INPUT' );
103
103
  } );
104
104
 
105
105
  it ( `<import> element should be automatically RESTORED: slotted element is removed from DOM...`, async function() {
106
106
  document.body.querySelector( 'input' ).remove();
107
- expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
107
+ expect( document.body.firstElementChild.nodeName ).to.eq( 'WQ-IMPORT' );
108
108
  } );
109
109
 
110
110
  } );
@@ -170,7 +170,7 @@ describe(`HTML Imports`, function() {
170
170
  const routingElement = document.body.firstElementChild;
171
171
  expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
172
172
  document.import( 'temp0/temp1', temp1 => {
173
- const textarea = temp1.exports[ '#input' ];
173
+ const textarea = temp1.defs[ '#input' ];
174
174
  textarea.remove();
175
175
  expect( routingElement.firstElementChild.nodeName ).to.eq( 'IMPORT' );
176
176
  temp1.content.prepend( textarea );
package/test/index.js CHANGED
@@ -17,11 +17,16 @@ export function delay( duration, callback = undefined ) {
17
17
  }
18
18
 
19
19
  export function createDocument( head = '', body = '', callback = null, ) {
20
+ return createDocumentPrefixed( '', ...arguments );
21
+ }
22
+
23
+ export function createDocumentPrefixed( prefix, head = '', body = '', callback = null, ) {
20
24
  const skeletonDoc = `
21
25
  <!DOCTYPE html>
22
26
  <html>
23
27
  <head>
24
28
  <meta name="$q-compiler-url" content="../quantum-js/dist/compiler.js">
29
+ ${ prefix ? `<meta name="webqit" content="prefix=${ prefix };">` : `` }
25
30
  <script ssr src="/dist/main.lite.js"></script>
26
31
  ${ head }
27
32
  </head>
@@ -4,13 +4,13 @@
4
4
  */
5
5
  import { expect } from 'chai';
6
6
  import { createDocument, mockRemoteFetch, delay } from './index.js';
7
- const getQueryPath = str => str.split( '/' ).join( '/exports/' ).split( '/' );
7
+ const getQueryPath = str => str.split( '/' ).join( '/defs/' ).split( '/' );
8
8
 
9
9
  describe(`HTML Modules`, function() {
10
10
 
11
11
  describe( `APIs...`, function() {
12
12
 
13
- it ( `The document object and <template> elements should expose a "exports" property...`, async function() {
13
+ it ( `The document object and <template> elements should expose a "defs" property...`, async function() {
14
14
 
15
15
  const head = `
16
16
  <template def="temp0">
@@ -27,18 +27,18 @@ describe(`HTML Modules`, function() {
27
27
  // -------
28
28
  expect( document ).to.have.property( 'import' );
29
29
  document.import( 'temp0', temp0 => {
30
- expect( temp0 ).to.have.property( 'exports' );
30
+ expect( temp0 ).to.have.property( 'defs' );
31
31
  expect( temp0.def ).to.eq( 'temp0' );
32
32
  } );
33
33
  // -------
34
34
  expect( document.body ).to.have.property( 'import' );
35
35
  document.body.import( 'temp1', temp1 => {
36
- expect( temp1 ).to.have.property( 'exports' );
36
+ expect( temp1 ).to.have.property( 'defs' );
37
37
  expect( temp1.def ).to.eq( 'temp1' );
38
38
  } );
39
39
  } );
40
40
 
41
- it ( `The document object and <template> elements should expose a "exports" property...`, async function() {
41
+ it ( `The document object and <template> elements should expose a "defs" property...`, async function() {
42
42
 
43
43
  const body = '', head = `
44
44
  <template def="temp0">
@@ -55,16 +55,16 @@ describe(`HTML Modules`, function() {
55
55
  const { webqit: { Observer } } = window;
56
56
  // -------
57
57
  document.import( 'temp0', temp0 => {
58
- expect( temp0 ).to.have.property( 'exports' );
59
- expect( temp0.exports[ '#' ] ).to.have.length( 2 );
60
- const temp2 = Observer.reduce( temp0.exports, getQueryPath( 'temp2' ), Observer.get );
61
- expect( temp2 ).to.have.property( 'exports' );
58
+ expect( temp0 ).to.have.property( 'defs' );
59
+ expect( temp0.defs[ '#' ] ).to.have.length( 2 );
60
+ const temp2 = Observer.reduce( temp0.defs, getQueryPath( 'temp2' ), Observer.get );
61
+ expect( temp2 ).to.have.property( 'defs' );
62
62
  // -------
63
- const temp1Inherited = Observer.reduce( temp0.exports, getQueryPath( 'temp2/temp1' ), Observer.get );
64
- expect( temp1Inherited ).to.have.property( 'exports' );
63
+ const temp1Inherited = Observer.reduce( temp0.defs, getQueryPath( 'temp2/temp1' ), Observer.get );
64
+ expect( temp1Inherited ).to.have.property( 'defs' );
65
65
  // -------
66
66
  const temp3Observed = [];
67
- Observer.reduce( temp0.exports, getQueryPath( 'temp2/temp3' ), Observer.observe, record => {
67
+ Observer.reduce( temp0.defs, getQueryPath( 'temp2/temp3' ), Observer.observe, record => {
68
68
  temp3Observed.push( record.value );
69
69
  } );
70
70
  // -------
@@ -73,10 +73,10 @@ describe(`HTML Modules`, function() {
73
73
  temp0.content.appendChild( temp3 );
74
74
  // -------
75
75
  expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
76
- expect( temp3Observed[ 0 ] ).to.have.property( 'exports' );
76
+ expect( temp3Observed[ 0 ] ).to.have.property( 'defs' );
77
77
  // -------
78
- const temp3Inherited = Observer.reduce( temp0.exports, getQueryPath( 'temp2/temp3' ), Observer.get );
79
- expect( temp3Inherited ).to.have.property( 'exports' );
78
+ const temp3Inherited = Observer.reduce( temp0.defs, getQueryPath( 'temp2/temp3' ), Observer.get );
79
+ expect( temp3Inherited ).to.have.property( 'defs' );
80
80
  // -------
81
81
  } );
82
82
  } );
@@ -114,25 +114,25 @@ describe(`HTML Modules`, function() {
114
114
  // -------
115
115
  // Add the import element to with a view to waiting for the remote module
116
116
  document.import( 'temp0', async temp0 => {
117
- expect( temp0 ).to.have.property( 'exports' );
117
+ expect( temp0 ).to.have.property( 'defs' );
118
118
  await delay( 2100 );
119
119
  // temp1 shouldn't have been automatically loaded still
120
- const hasTemp1 = Observer.reduce( temp0.exports, getQueryPath( 'temp1' ), Observer.has );
120
+ const hasTemp1 = Observer.reduce( temp0.defs, getQueryPath( 'temp1' ), Observer.has );
121
121
  expect( hasTemp1 ).to.be.false;
122
122
  // Try access temp1 to trigger loading and await
123
- const _temp1 = await Observer.reduce( temp0.exports, getQueryPath( 'temp1' ), Observer.get );
124
- expect( _temp1 ).to.have.property( 'exports' );
123
+ const _temp1 = await Observer.reduce( temp0.defs, getQueryPath( 'temp1' ), Observer.get );
124
+ expect( _temp1 ).to.have.property( 'defs' );
125
125
  // -------
126
126
  // Receive updates
127
127
  const temp3Observed = [];
128
- Observer.reduce( temp0.exports, getQueryPath( 'temp1/temp2/temp3' ), Observer.observe, ( record, lifecycle ) => {
128
+ Observer.reduce( temp0.defs, getQueryPath( 'temp1/temp2/temp3' ), Observer.observe, ( record, lifecycle ) => {
129
129
  temp3Observed.push( record.value );
130
130
  } );
131
131
  await delay( 2100 );
132
132
  // -------
133
133
  // temp2 should be loaded by now
134
134
  expect( temp3Observed ).to.be.an( 'array' ).with.length( 1 );
135
- expect( temp3Observed[ 0 ] ).to.have.property( 'exports' );
135
+ expect( temp3Observed[ 0 ] ).to.have.property( 'defs' );
136
136
  expect( temp3Observed[ 0 ].getAttribute( 'def' ) ).to.eq( 'temp3' );
137
137
  } );
138
138
  } );
@@ -171,33 +171,33 @@ describe(`HTML Modules`, function() {
171
171
  return el.dispatchEvent( event );
172
172
  };
173
173
  // -------
174
- await 'For some reason, the <template> element in the head needs to show up in the document exportsObj';
175
- const exportsObjs = [], div = document.querySelector( 'div' );
174
+ await 'For some reason, the <template> element in the head needs to show up in the document defsObj';
175
+ const defsObjs = [], div = document.querySelector( 'div' );
176
176
  // -------
177
177
  contextRequest( div, { detail: '/temp0', diff: false }, response => {
178
- exportsObjs.push( response );
178
+ defsObjs.push( response );
179
179
  } );
180
- expect( exportsObjs ).to.have.length( 1 );
181
- expect( exportsObjs[ 0 ] ).to.have.property( 'scoped', false );
180
+ expect( defsObjs ).to.have.length( 1 );
181
+ expect( defsObjs[ 0 ] ).to.have.property( 'scoped', false );
182
182
  // -------
183
183
  const scoped = addScopedModules();
184
- expect( exportsObjs ).to.have.length( 2 );
185
- expect( exportsObjs[ 1 ] ).to.have.property( 'scoped', true );
184
+ expect( defsObjs ).to.have.length( 2 );
185
+ expect( defsObjs[ 1 ] ).to.have.property( 'scoped', true );
186
186
  // -------
187
187
  scoped.remove();
188
- expect( exportsObjs ).to.have.length( 3 );
189
- expect( exportsObjs[ 2 ] ).to.have.property( 'scoped', false );
188
+ expect( defsObjs ).to.have.length( 3 );
189
+ expect( defsObjs[ 2 ] ).to.have.property( 'scoped', false );
190
190
  // -------
191
191
  document.body.appendChild( scoped );
192
- expect( exportsObjs ).to.have.length( 4 );
193
- expect( exportsObjs[ 3 ] ).to.have.property( 'scoped', true );
192
+ expect( defsObjs ).to.have.length( 4 );
193
+ expect( defsObjs[ 3 ] ).to.have.property( 'scoped', true );
194
194
  // -------
195
195
  document.import( 'temp0', temp0 => {
196
196
  const unscoped = temp0;
197
197
  unscoped.remove();
198
198
  document.head.appendChild( unscoped );
199
199
  document.body.remove();
200
- expect( exportsObjs ).to.have.length( 4 );
200
+ expect( defsObjs ).to.have.length( 4 );
201
201
  } );
202
202
  } );
203
203
  } );
@@ -9,8 +9,7 @@ describe(`Namespaced HTML`, function() {
9
9
 
10
10
  describe( `Basic...`, async function() {
11
11
 
12
- const head = `
13
- <meta name="oohtml" content="attr.id=id" />`;
12
+ const head = ``;
14
13
  const body = `
15
14
  <div id="main" namespace>
16
15
  <div id="child"></div>