@webqit/oohtml 2.1.56 → 2.1.57
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/README.md +86 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,18 +161,17 @@ foo.addEventListener('load', loadedCallback);
|
|
|
161
161
|
└ *The HTMLImports API for programmatic module import*:
|
|
162
162
|
|
|
163
163
|
```js
|
|
164
|
-
document.import('/foo#fragment1'
|
|
165
|
-
|
|
166
|
-
});
|
|
164
|
+
const import1 = document.import('/foo#fragment1');
|
|
165
|
+
console.log(import1); // { value: div }
|
|
167
166
|
```
|
|
168
167
|
|
|
169
168
|
```js
|
|
170
|
-
document.import('/foo/nested#fragment2'
|
|
171
|
-
|
|
172
|
-
});
|
|
169
|
+
const import2 = document.import('/foo/nested#fragment2');
|
|
170
|
+
console.log(import2); // { value: div }
|
|
173
171
|
```
|
|
174
172
|
|
|
175
173
|
└ *Scoped templates for object-scoped module system*:
|
|
174
|
+
> With an equivalent `Element.prototype.import()` API for accessing scoped modules
|
|
176
175
|
|
|
177
176
|
```html
|
|
178
177
|
<section> <!-- object with own modules -->
|
|
@@ -191,16 +190,16 @@ document.import('/foo/nested#fragment2', divElement => {
|
|
|
191
190
|
|
|
192
191
|
```js
|
|
193
192
|
// Using the HTMLImports API
|
|
194
|
-
document.querySelector('div')
|
|
195
|
-
|
|
196
|
-
|
|
193
|
+
const moduleHost = document.querySelector('div');
|
|
194
|
+
const localImport1 = moduleHost.import('foo#fragment1'); // the local module: foo#fragment1
|
|
195
|
+
console.log(localImport1); // { value: div }
|
|
197
196
|
```
|
|
198
197
|
|
|
199
198
|
```js
|
|
200
199
|
// Using the HTMLImports API
|
|
201
|
-
document.querySelector('div')
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
const moduleHost = document.querySelector('div');
|
|
201
|
+
const globalImport1 = moduleHost.import('/foo#fragment1'); // the global module: foo#fragment1
|
|
202
|
+
console.log(globalImport1); // { value: div }
|
|
204
203
|
```
|
|
205
204
|
|
|
206
205
|
<details><summary>
|
|
@@ -270,6 +269,14 @@ document.import('/foo#fragment1', divElement => {
|
|
|
270
269
|
});
|
|
271
270
|
```
|
|
272
271
|
|
|
272
|
+
```js
|
|
273
|
+
const import1 = document.import('/foo#fragment1', true);
|
|
274
|
+
console.log(import1); // { value: undefined }
|
|
275
|
+
Observer.observe(import1, 'value', divElement => {
|
|
276
|
+
console.log(divElement); // To be received after remote module has been loaded
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
273
280
|
└ *"Imports Contexts" for context-based imports resolution*:
|
|
274
281
|
|
|
275
282
|
```html
|
|
@@ -290,9 +297,9 @@ document.import('/foo#fragment1', divElement => {
|
|
|
290
297
|
|
|
291
298
|
```js
|
|
292
299
|
// Using the HTMLImports API
|
|
293
|
-
document.querySelector('section')
|
|
294
|
-
|
|
295
|
-
|
|
300
|
+
const moduleHost = document.querySelector('section');
|
|
301
|
+
const globalImport2 = moduleHost.import('#fragment2'); // module:/foo/nested#fragment2
|
|
302
|
+
console.log(globalImport2); // { value: div }
|
|
296
303
|
```
|
|
297
304
|
|
|
298
305
|
└ *"Imports Contexts" with named contexts*:
|
|
@@ -314,9 +321,9 @@ document.querySelector('section').import('#fragment2', divElement => {
|
|
|
314
321
|
|
|
315
322
|
```js
|
|
316
323
|
// Using the HTMLImports API
|
|
317
|
-
document.querySelector('div')
|
|
318
|
-
|
|
319
|
-
|
|
324
|
+
const moduleHost = document.querySelector('div');
|
|
325
|
+
const globalImport2 = moduleHost.import('@context1#fragment2'); // module:/foo/nested#fragment2
|
|
326
|
+
console.log(globalImport2); // { value: div }
|
|
320
327
|
```
|
|
321
328
|
|
|
322
329
|
└ *"Imports Contexts" with context inheritance*:
|
|
@@ -356,9 +363,9 @@ document.querySelector('div').import('@context1#fragment2', divElement => {
|
|
|
356
363
|
|
|
357
364
|
```js
|
|
358
365
|
// Using the HTMLImports API
|
|
359
|
-
document.querySelector('div')
|
|
360
|
-
|
|
361
|
-
|
|
366
|
+
const moduleHost = document.querySelector('div');
|
|
367
|
+
const localOrGlobalImport2 = moduleHost.import('#fragment2'); // the local module: foo#fragment2, and if not found, resolves from context to the module: /bar/nested#fragment2
|
|
368
|
+
console.log(localOrGlobalImport2); // { value: div }
|
|
362
369
|
```
|
|
363
370
|
|
|
364
371
|
</details>
|
|
@@ -621,6 +628,7 @@ Here are a few examples in the wide range of use cases these features cover.
|
|
|
621
628
|
+ [Example 2: *Multi-Level Namespacing*](#example-2-multi-level-namespacing)
|
|
622
629
|
+ [Example 3: *Dynamic Shadow DOM*](#example-3-dynamic-shadow-dom)
|
|
623
630
|
+ [Example 4: *List Items*](#example-4-list-items)
|
|
631
|
+
+ [Example 5: *Live List*](#example-4-live-list)
|
|
624
632
|
|
|
625
633
|
### Example 1: *Single Page Application*
|
|
626
634
|
|
|
@@ -829,25 +837,71 @@ The following is a "component" that derives its list items and other reusable sn
|
|
|
829
837
|
```html
|
|
830
838
|
<div namespace>
|
|
831
839
|
|
|
832
|
-
<import ref="other"></import>
|
|
833
840
|
<ul id="list"></ul>
|
|
834
|
-
<import ref="other"></import>
|
|
835
841
|
|
|
836
842
|
<template def="item" scoped>
|
|
837
|
-
<li>
|
|
838
|
-
<a></a>
|
|
839
|
-
</li>
|
|
843
|
+
<li><a>Item</a></li>
|
|
840
844
|
</template>
|
|
841
845
|
|
|
842
|
-
<
|
|
843
|
-
|
|
846
|
+
<script scoped>
|
|
847
|
+
// Import item template
|
|
848
|
+
let itemImport = this.import('item');
|
|
849
|
+
let itemTemplate = itemImport.value;
|
|
850
|
+
|
|
851
|
+
// Iterate
|
|
852
|
+
[ 'Item 1', 'Item 2', 'Item 3' ].forEach(entry => {
|
|
853
|
+
const currentItem = itemTemplate.content.cloneNode(true);
|
|
854
|
+
// Add to DOM
|
|
855
|
+
this.namespace.list.appendChild(currentItem);
|
|
856
|
+
// Render
|
|
857
|
+
currentItem.innerHTML = entry;
|
|
858
|
+
});
|
|
859
|
+
</script>
|
|
860
|
+
|
|
861
|
+
</div>
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
</details>
|
|
865
|
+
|
|
866
|
+
### Example 4: *Live List*
|
|
867
|
+
|
|
868
|
+
The following is the same list as above but implemented as a live list! Here, we make a few changes: the script element is Stateful; the loop itself now uses the literal `for ... of` construct, [which is capable of rendering live lists](https://github.com/webqit/stateful-js/wiki#with-control-structures), so that any additions and removals on the original list is statically reflected!
|
|
869
|
+
|
|
870
|
+
<details><summary>Code</summary>
|
|
871
|
+
|
|
872
|
+
```html
|
|
873
|
+
<div namespace>
|
|
874
|
+
|
|
875
|
+
<ul id="list"></ul>
|
|
876
|
+
|
|
877
|
+
<template def="item" scoped>
|
|
878
|
+
<li><a>Item</a></li>
|
|
844
879
|
</template>
|
|
845
880
|
|
|
846
881
|
<script scoped>
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
882
|
+
// Import item template
|
|
883
|
+
let itemImport = this.import('item');
|
|
884
|
+
let itemTemplate = itemImport.value;
|
|
885
|
+
|
|
886
|
+
// Iterate
|
|
887
|
+
let items = [ 'Item 1', 'Item 2', 'Item 3' ];
|
|
888
|
+
for (let entry of items) {
|
|
889
|
+
const currentItem = itemTemplate.content.cloneNode(true);
|
|
890
|
+
// Add to DOM
|
|
891
|
+
this.namespace.list.appendChild(currentItem);
|
|
892
|
+
// Remove from DOM whenever corresponding entry is removed
|
|
893
|
+
if (typeof entry === 'undefined') {
|
|
894
|
+
currentItem.remove();
|
|
895
|
+
continue;
|
|
896
|
+
}
|
|
897
|
+
// Render
|
|
898
|
+
currentItem.innerHTML = entry;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// Add a new entry
|
|
902
|
+
setTimeout(() => items.push('Item 4'), 1000);
|
|
903
|
+
// Remove an new entry
|
|
904
|
+
setTimeout(() => items.pop(), 2000);
|
|
851
905
|
</script>
|
|
852
906
|
|
|
853
907
|
</div>
|