@webqit/oohtml 2.1.49 → 2.1.51-0
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 +6 -7
- package/dist/html-imports.js +1 -1
- package/dist/html-imports.js.map +2 -2
- package/dist/main.js +12 -12
- package/dist/main.js.map +2 -2
- package/dist/scoped-js.js +7 -7
- package/dist/scoped-js.js.map +2 -2
- package/package.json +1 -1
- package/src/html-imports/_HTMLExportsManager.js +2 -2
- package/src/html-imports/_HTMLImportElement.js +6 -2
- package/src/scoped-js/Compiler.js +8 -4
- package/src/scoped-js/index.js +1 -0
- package/test/modules.test.js +2 -2
package/package.json
CHANGED
|
@@ -70,7 +70,7 @@ export default class _HTMLExportsManager {
|
|
|
70
70
|
* @returns Void
|
|
71
71
|
*/
|
|
72
72
|
export( entries, isConnected ) {
|
|
73
|
-
let dirty, allFragments =
|
|
73
|
+
let dirty, allFragments = this.modules[ '#' ] || [];
|
|
74
74
|
Observer.batch( this.modules, () => {
|
|
75
75
|
entries.forEach( entry => {
|
|
76
76
|
if ( entry.nodeType !== 1 ) return;
|
|
@@ -139,7 +139,7 @@ export default class _HTMLExportsManager {
|
|
|
139
139
|
const fire = ( type, detail ) => this.host.dispatchEvent( new this.window.CustomEvent( type, { detail } ) );
|
|
140
140
|
const request = this.window.fetch( src, { signal: controller.signal, element: this.host } ).then( response => {
|
|
141
141
|
return response.ok ? response.text() : Promise.reject( response.statusText );
|
|
142
|
-
}).then( content => {
|
|
142
|
+
} ).then( content => {
|
|
143
143
|
this.host.innerHTML = content.trim(); // IMPORTANT: .trim()
|
|
144
144
|
fire( 'load' );
|
|
145
145
|
return this.host;
|
|
@@ -16,7 +16,7 @@ import { _ } from '../util.js';
|
|
|
16
16
|
export default function( config ) {
|
|
17
17
|
const window = this, { realdom } = window.webqit;
|
|
18
18
|
const BaseElement = config.import.tagName.includes( '-' ) ? window.HTMLElement : class {};
|
|
19
|
-
|
|
19
|
+
class HTMLImportElement extends BaseElement {
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @instance
|
|
@@ -27,7 +27,7 @@ export default function( config ) {
|
|
|
27
27
|
*/
|
|
28
28
|
static instance( node ) {
|
|
29
29
|
if ( config.import.tagName.includes( '-' ) && ( node instanceof this ) ) return node;
|
|
30
|
-
return _( node ).get( 'import::instance' ) || new this( node )
|
|
30
|
+
return _( node ).get( 'import::instance' ) || new this( node );
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -211,4 +211,8 @@ export default function( config ) {
|
|
|
211
211
|
*/
|
|
212
212
|
get slottedElements() { return this[ '#' ].slottedElements; }
|
|
213
213
|
}
|
|
214
|
+
if ( config.import.tagName.includes( '-' ) ) {
|
|
215
|
+
customElements.define( config.import.tagName, HTMLImportElement );
|
|
216
|
+
}
|
|
217
|
+
return HTMLImportElement;
|
|
214
218
|
}
|
|
@@ -45,7 +45,10 @@ export default class Compiler {
|
|
|
45
45
|
script.textContent = `"source hidden"`;
|
|
46
46
|
break;
|
|
47
47
|
default:
|
|
48
|
-
script.textContent =
|
|
48
|
+
script.textContent = ' ';
|
|
49
|
+
setTimeout( () => {
|
|
50
|
+
//script.textContent = compiledScript.function.originalSource;
|
|
51
|
+
}, 10 );
|
|
49
52
|
}
|
|
50
53
|
return executeCallback.call( window, compiledScript, thisContext, script );
|
|
51
54
|
};
|
|
@@ -56,9 +59,10 @@ export default class Compiler {
|
|
|
56
59
|
const _static = this.constructor;
|
|
57
60
|
const { webqit: { oohtml, ReflexFunction } } = this.window;
|
|
58
61
|
const cache = oohtml.Script.compileCache[ script.reflex ? 0 : 1 ];
|
|
59
|
-
const
|
|
62
|
+
const textContent = ( script._ = script.textContent.trim() ) && script._.startsWith( '/*@oohtml*/if(false){' ) && script._.endsWith( '}/*@oohtml*/' ) ? script._.slice( 21, -12 ) : script.textContent;
|
|
63
|
+
const sourceHash = _static.toHash( textContent );
|
|
60
64
|
// Script instances are parsed only once
|
|
61
|
-
let source =
|
|
65
|
+
let source = textContent, compiledScript;
|
|
62
66
|
if ( !( compiledScript = cache.get( sourceHash ) ) ) {
|
|
63
67
|
// Are there "import" (and "await") statements? Then, we need to rewrite that
|
|
64
68
|
let imports = [], meta = {};
|
|
@@ -85,7 +89,7 @@ export default class Compiler {
|
|
|
85
89
|
? runtimeParams.compileFunction( source )
|
|
86
90
|
: new _FunctionConstructor( source );
|
|
87
91
|
}
|
|
88
|
-
Object.defineProperty( _Function, 'originalSource', { configurable: true, value:
|
|
92
|
+
Object.defineProperty( _Function, 'originalSource', { configurable: true, value: textContent } );
|
|
89
93
|
// Save material function to compile cache
|
|
90
94
|
compiledScript = Object.defineProperty( script.cloneNode(), 'function', { value: _Function } );
|
|
91
95
|
script.scoped && Object.defineProperty( compiledScript, 'scoped', Object.getOwnPropertyDescriptor( script, 'scoped') );
|
package/src/scoped-js/index.js
CHANGED
|
@@ -95,6 +95,7 @@ function realtime( config ) {
|
|
|
95
95
|
const compiler = new Compiler( window, config, execute ), handled = () => {};
|
|
96
96
|
realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( config.scriptSelector, record => {
|
|
97
97
|
record.entrants.forEach( script => {
|
|
98
|
+
if ( script.cloned ) return;
|
|
98
99
|
if ( 'reflex' in script ) return handled( script );
|
|
99
100
|
Object.defineProperty( script, 'reflex', { value: script.hasAttribute( 'reflex' ) } );
|
|
100
101
|
if ( 'scoped' in script ) return handled( script );
|
package/test/modules.test.js
CHANGED
|
@@ -102,7 +102,7 @@ describe(`HTML Modules`, function() {
|
|
|
102
102
|
const timeout = 1000;
|
|
103
103
|
mockRemoteFetch( window, { '/temp0.html': contents0, '/temp1.html': contents1, '/temp2.html': contents2 }, timeout );
|
|
104
104
|
} );
|
|
105
|
-
await delay(
|
|
105
|
+
await delay( 50 );
|
|
106
106
|
const { webqit: { Observer } } = window;
|
|
107
107
|
// -------
|
|
108
108
|
// Add a remote module
|
|
@@ -153,7 +153,7 @@ describe(`HTML Modules`, function() {
|
|
|
153
153
|
const body = `
|
|
154
154
|
<div></div>`;
|
|
155
155
|
const { document, window } = createDocument( head, body );
|
|
156
|
-
await delay(
|
|
156
|
+
await delay( 50 );
|
|
157
157
|
|
|
158
158
|
// -------
|
|
159
159
|
const addScopedModules = () => {
|