@webqit/oohtml 2.1.4 → 2.1.6
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/html-imports.js +1 -1
- package/dist/html-imports.js.map +2 -2
- package/dist/html-modules.js +1 -1
- package/dist/html-modules.js.map +2 -2
- package/dist/main.js +9 -9
- package/dist/main.js.map +2 -2
- package/dist/namespaced-html.js +1 -1
- package/dist/namespaced-html.js.map +2 -2
- package/dist/scoped-js.js +9 -9
- package/dist/scoped-js.js.map +2 -2
- package/dist/state-api.js +1 -1
- package/dist/state-api.js.map +2 -2
- package/package.json +2 -2
- package/src/html-modules/index.js +1 -0
- package/src/html-modules/targets.browser.js +1 -4
- package/src/index.js +1 -2
- package/src/namespaced-html/index.js +2 -0
- package/src/namespaced-html/targets.browser.js +1 -4
- package/src/scoped-js/index.js +11 -11
- package/src/scoped-js/targets.browser.js +1 -5
- package/src/state-api/index.js +2 -0
- package/src/state-api/targets.browser.js +1 -4
- package/test/index.js +8 -32
- package/test/modules.test.js +1 -1
- package/test/{scoped-js.test2.js → scoped-js.test.js} +2 -2
- package/test/test.html +0 -71
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.6",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@webqit/dom": "^2.0.0",
|
|
42
42
|
"@webqit/observer": "^2.0.1",
|
|
43
|
-
"@webqit/subscript": "^2.1.
|
|
43
|
+
"@webqit/subscript": "^2.1.36",
|
|
44
44
|
"@webqit/util": "^0.8.9"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -18,6 +18,7 @@ import { _ } from '../util.js';
|
|
|
18
18
|
export default function init( $params = {} ) {
|
|
19
19
|
const window = this, dom = wqDom.call( window );
|
|
20
20
|
if ( !window.wq ) { window.wq = {}; }
|
|
21
|
+
window.wq.Observer = Observer;
|
|
21
22
|
window.wq.HTMLImportsContext = class extends _HTMLImportsContext {
|
|
22
23
|
static get params() { return params; }
|
|
23
24
|
};
|
package/src/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import ScopedJS from './scoped-js/index.js';
|
|
|
16
16
|
export default function init( configs = {} ) {
|
|
17
17
|
if ( !this.wq ) { this.wq = {}; }
|
|
18
18
|
if ( this.wq.oohtml ) return;
|
|
19
|
-
this.wq.
|
|
19
|
+
this.wq.oohtml = {};
|
|
20
20
|
// --------------
|
|
21
21
|
StateAPI.call(this, ( configs.StateAPI || {} ) );
|
|
22
22
|
ContextAPI.call( this, ( configs.ContextAPI || {} ) );
|
|
@@ -25,7 +25,6 @@ export default function init( configs = {} ) {
|
|
|
25
25
|
NamespacedHTML.call(this, ( configs.NamespacedHTML || {} ) );
|
|
26
26
|
ScopedJS.call( this, ( configs.ScopedJS || {} ) );
|
|
27
27
|
// --------------
|
|
28
|
-
this.wq.oohtml = {};
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
/**
|
|
@@ -13,6 +13,8 @@ import { _ } from '../util.js';
|
|
|
13
13
|
*/
|
|
14
14
|
export default function init( $params = {} ) {
|
|
15
15
|
const window = this, dom = wqDom.call( window );
|
|
16
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
17
|
+
window.wq.Observer = Observer;
|
|
16
18
|
// -------
|
|
17
19
|
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
18
20
|
attr: { namespace: 'namespace', id: ':id', },
|
package/src/scoped-js/index.js
CHANGED
|
@@ -15,14 +15,17 @@ import wqDom from '@webqit/dom';
|
|
|
15
15
|
export default function init( $params = {} ) {
|
|
16
16
|
const window = this, dom = wqDom.call( window );
|
|
17
17
|
if ( !window.wq ) { window.wq = {}; }
|
|
18
|
-
window.wq.
|
|
18
|
+
if ( !window.wq.oohtml ) { window.wq.oohtml = {}; }
|
|
19
|
+
window.wq.oohtml.Script = { compileCache: [ new Map, new Map, ] };
|
|
20
|
+
window.wq.SubscriptFunction = $params.SubscriptFunction/* allow for injection, e.g. from test runner */ || SubscriptFunction;
|
|
21
|
+
window.wq.Observer = Observer;
|
|
19
22
|
// -------
|
|
20
23
|
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
21
24
|
script: { retention: 'retain', mimeType: '' },
|
|
22
25
|
config: resolveParams( {
|
|
23
|
-
parserParams: { allowReturnOutsideFunction: false, allowSuperOutsideMethod: false },
|
|
24
|
-
compilerParams: { globalsNoObserve: [ 'alert' ] },
|
|
25
|
-
runtimeParams: { apiVersion: 2 },
|
|
26
|
+
parserParams: { allowReturnOutsideFunction: false, allowSuperOutsideMethod: false, ...( $params.parserParams || {} ) },
|
|
27
|
+
compilerParams: { globalsNoObserve: [ 'alert' ], ...( $params.compilerParams || {} ) },
|
|
28
|
+
runtimeParams: { apiVersion: 2, ...( $params.runtimeParams || {} ) },
|
|
26
29
|
} ),
|
|
27
30
|
} );
|
|
28
31
|
params.scriptSelector = ( Array.isArray( params.script.mimeType ) ? params.script.mimeType : [ params.script.mimeType ] ).reduce( ( selector, mm ) => {
|
|
@@ -47,10 +50,6 @@ export {
|
|
|
47
50
|
*/
|
|
48
51
|
function realtime( params ) {
|
|
49
52
|
const window = this, { dom } = window.wq;
|
|
50
|
-
// ---
|
|
51
|
-
window.wq.transformCache = new Map;
|
|
52
|
-
window.wq.compileCache = [ new Map, new Map, ];
|
|
53
|
-
// ---
|
|
54
53
|
const handled = () => {};
|
|
55
54
|
dom.realtime( window.document ).observe( params.scriptSelector, record => {
|
|
56
55
|
record.entrants.forEach( script => {
|
|
@@ -64,7 +63,7 @@ function realtime( params ) {
|
|
|
64
63
|
} );
|
|
65
64
|
}, { subtree: true, timing: 'intercept', generation: 'entrants' } );
|
|
66
65
|
// ---
|
|
67
|
-
window.wq.
|
|
66
|
+
window.wq.oohtml.Script.run = ( execHash ) => {
|
|
68
67
|
const exec = fromHash( execHash );
|
|
69
68
|
if ( !exec ) throw new Error( `Argument must be a valid exec hash.` );
|
|
70
69
|
const { script, compiledScript, thisContext } = exec;
|
|
@@ -126,7 +125,8 @@ export function execute( compiledScript, thisContext, script ) {
|
|
|
126
125
|
// ------------------
|
|
127
126
|
// JAVASCRIPT::[SCOPED|CONTRACT]
|
|
128
127
|
export function compile( script, thisContext, params = {} ) {
|
|
129
|
-
const wq
|
|
128
|
+
const { wq: { oohtml, SubscriptFunction } } = this;
|
|
129
|
+
const cache = oohtml.Script.compileCache[ script.contract ? 0 : 1 ];
|
|
130
130
|
const sourceHash = toHash( script.textContent );
|
|
131
131
|
// Script instances are parsed only once
|
|
132
132
|
let source = script.textContent, compiledScript;
|
|
@@ -164,7 +164,7 @@ export function compile( script, thisContext, params = {} ) {
|
|
|
164
164
|
cache.set( sourceHash, compiledScript );
|
|
165
165
|
}
|
|
166
166
|
const execHash = toHash( { script, compiledScript, thisContext } );
|
|
167
|
-
script.textContent = `wq.
|
|
167
|
+
script.textContent = `wq.oohtml.Script.run('${ execHash }');`;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// ------------------
|
package/src/state-api/index.js
CHANGED
|
@@ -13,6 +13,8 @@ import { _ } from '../util.js';
|
|
|
13
13
|
*/
|
|
14
14
|
export default function init( $params = {} ) {
|
|
15
15
|
const window = this, dom = wqDom.call( window );
|
|
16
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
17
|
+
window.wq.Observer = Observer;
|
|
16
18
|
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
17
19
|
api: { state: 'state', },
|
|
18
20
|
} );
|
package/test/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { _internals } from '@webqit/util/js/index.js';
|
|
|
6
6
|
import { createContext, compileFunction, runInContext } from 'vm';
|
|
7
7
|
import jsdom from 'jsdom';
|
|
8
8
|
import init, { Observer } from '../src/index.js';
|
|
9
|
+
import { SubscriptFunction } from '@webqit/subscript';
|
|
9
10
|
import wqDom from '@webqit/dom';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -14,10 +15,8 @@ import wqDom from '@webqit/dom';
|
|
|
14
15
|
* -------
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
export { Observer };
|
|
19
19
|
export const _ = ( el, ...args ) => _internals( el, 'oohtml', ...args );
|
|
20
|
-
|
|
21
20
|
export function delay( duration, callback = undefined ) {
|
|
22
21
|
return new Promise( res => {
|
|
23
22
|
setTimeout( () => res( callback && callback() ), duration );
|
|
@@ -25,14 +24,12 @@ export function delay( duration, callback = undefined ) {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export function createDocument( head = '', body = '', callback = null, ) {
|
|
28
|
-
// -------
|
|
29
27
|
const skeletonDoc = `
|
|
30
28
|
<!DOCTYPE html>
|
|
31
29
|
<html>
|
|
32
30
|
<head>${ head }</head>
|
|
33
31
|
<body>${ body }</body>
|
|
34
32
|
</html>`;
|
|
35
|
-
// --------
|
|
36
33
|
// TODO: Proper indentation for pretty-printing
|
|
37
34
|
const instance = new jsdom.JSDOM( skeletonDoc, {
|
|
38
35
|
url: 'http://localhost',
|
|
@@ -41,51 +38,45 @@ export function createDocument( head = '', body = '', callback = null, ) {
|
|
|
41
38
|
if ( callback ) callback( window, window.wq.dom );
|
|
42
39
|
}
|
|
43
40
|
} );
|
|
44
|
-
// --------
|
|
45
41
|
return instance.window;
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
export function createDocumentForScopedJS( head = '', body = '', callback = null, params = {} ) {
|
|
49
|
-
// -------
|
|
50
45
|
const skeletonDoc = `
|
|
51
46
|
<!DOCTYPE html>
|
|
52
47
|
<html>
|
|
53
48
|
<head>${ head }</head>
|
|
54
49
|
<body>${ body }</body>
|
|
55
50
|
</html>`;
|
|
56
|
-
// --------
|
|
57
51
|
const instance = new jsdom.JSDOM( skeletonDoc, {
|
|
58
|
-
url: 'http://localhost',
|
|
59
52
|
...params,
|
|
53
|
+
url: 'http://localhost',
|
|
60
54
|
beforeParse( window ) {
|
|
61
55
|
window.testRecords = [];
|
|
62
56
|
createContext( window );
|
|
63
|
-
// -----------------
|
|
64
57
|
// Running advanced scripts
|
|
65
|
-
|
|
58
|
+
init.call( window, { ScopedJS: {
|
|
59
|
+
SubscriptFunction,
|
|
66
60
|
runtimeParams: {
|
|
67
61
|
compileFunction: ( code, parameters ) => compileFunction( code, parameters, {
|
|
68
62
|
parsingContext: window,
|
|
69
63
|
} ),
|
|
70
64
|
}
|
|
71
|
-
};
|
|
72
|
-
init.call( window, { ScopedJS: subscriptParams } );
|
|
73
|
-
// -----------------
|
|
65
|
+
} } );
|
|
74
66
|
// Running basic scripts
|
|
75
67
|
const dom = wqDom.call( window );
|
|
76
68
|
if ( params.runScripts !== 'dangerously' ) {
|
|
77
69
|
dom.realtime( window.document ).observe( 'script', record => {
|
|
78
70
|
record.entrants.forEach( script => {
|
|
79
|
-
|
|
71
|
+
if ( !script.textContent.trim() ) return;
|
|
80
72
|
runInContext( script.textContent, window );
|
|
81
73
|
} );
|
|
82
74
|
}, { subtree: true } );
|
|
83
75
|
}
|
|
84
|
-
//
|
|
76
|
+
// Sync callback?
|
|
85
77
|
if ( callback ) callback( window, window.wq.dom );
|
|
86
78
|
}
|
|
87
79
|
} );
|
|
88
|
-
// --------
|
|
89
80
|
return instance.window;
|
|
90
81
|
};
|
|
91
82
|
|
|
@@ -101,19 +92,4 @@ export function mockRemoteFetch( window, contents, delay = 1000 ) {
|
|
|
101
92
|
}, delay );
|
|
102
93
|
} );
|
|
103
94
|
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function printDocument( document, desc = '' ) {
|
|
107
|
-
return; new Promise( res => {
|
|
108
|
-
setTimeout( () => {
|
|
109
|
-
console.log( '' );
|
|
110
|
-
console.log( '-------------' );
|
|
111
|
-
console.log( desc );
|
|
112
|
-
console.log( '-------------' );
|
|
113
|
-
console.log( document.documentElement.outerHTML );
|
|
114
|
-
console.log( '-------------' );
|
|
115
|
-
console.log( '' );
|
|
116
|
-
res();
|
|
117
|
-
}, 0 );
|
|
118
|
-
} );
|
|
119
95
|
}
|
package/test/modules.test.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { expect } from 'chai';
|
|
6
6
|
import Observer from '@webqit/observer';
|
|
7
|
-
import { delay, createDocument, mockRemoteFetch,
|
|
7
|
+
import { delay, createDocument, mockRemoteFetch, _ } from './index.js';
|
|
8
8
|
const getQueryPath = str => str.split( '/' ).join( '/modules/' ).split( '/' );
|
|
9
9
|
|
|
10
10
|
describe(`HTML Modules`, function() {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
5
|
import { expect } from 'chai';
|
|
6
|
-
import { delay, createDocumentForScopedJS
|
|
6
|
+
import { delay, createDocumentForScopedJS } from './index.js';
|
|
7
7
|
|
|
8
8
|
describe(`Test: Scoped JS`, function() {
|
|
9
9
|
|
|
@@ -50,7 +50,7 @@ describe(`Test: Scoped JS`, function() {
|
|
|
50
50
|
await delay( 60 );
|
|
51
51
|
expect( window.testRecords ).to.have.length( 1 );
|
|
52
52
|
expect( window.testRecords[ 0 ] ).to.eql( window.document.body );
|
|
53
|
-
//console.log('::::::::::::', window.
|
|
53
|
+
//console.log('::::::::::::', window.testRecords );
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
});
|
package/test/test.html
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta name="oohtml" content="script.retention=hidden" />
|
|
5
|
-
<script src="/oohtml/dist/main.js"></script>
|
|
6
|
-
<script>
|
|
7
|
-
window.extVar = 'External variable initial value.';
|
|
8
|
-
window.Observer = wq.Observer;
|
|
9
|
-
</script>
|
|
10
|
-
<template exportid="temp0">
|
|
11
|
-
<input exportid="#input" />
|
|
12
|
-
<template exportid="temp1">
|
|
13
|
-
<textarea exportid="#input" placeholder="This is to be rendered"></textarea>
|
|
14
|
-
<template exportid="temp2">
|
|
15
|
-
<select exportid="#input"></select>
|
|
16
|
-
</template>
|
|
17
|
-
<template exportid="temp2b" inherits="#input"></template>
|
|
18
|
-
<template exportid="temp2c">
|
|
19
|
-
<textarea exportid="#input"></textarea>
|
|
20
|
-
</template>
|
|
21
|
-
</template>
|
|
22
|
-
</template>
|
|
23
|
-
</head>
|
|
24
|
-
<body>
|
|
25
|
-
|
|
26
|
-
<div importscontext="temp0/temp1">
|
|
27
|
-
<textarea exportid="#input" placeholder="This is server-rendered"></textarea>
|
|
28
|
-
<!--<import module="#input"></import>-->
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
<div id="div1">
|
|
32
|
-
[1]: Scoped contract script here! See the console.
|
|
33
|
-
<script type="module" scoped contract>
|
|
34
|
-
console.log( '[1]: Execution context: ' + this.tagName, this.someProp );
|
|
35
|
-
console.log( '[1]: Dependencies: ', ( await [ ...this.scripts ][ 0 ].properties ).dependencies );
|
|
36
|
-
console.log( `[1]: ${ extVar }` );
|
|
37
|
-
this.addEventListener( 'remove', e => { console.log( '[1]: Removing...' ); } );
|
|
38
|
-
setTimeout( () => { this.remove(); }, 10000 );
|
|
39
|
-
</script>
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<div id="div2">
|
|
43
|
-
[2]: Scoped contract script here! See the console.
|
|
44
|
-
<script type="module" scoped contract>
|
|
45
|
-
console.log( '[2]: Execution context: ', this.tagName );
|
|
46
|
-
console.log( '[2]: Dependencies: ', ( await [ ...this.scripts ][ 0 ].properties ).dependencies );
|
|
47
|
-
console.log( `[2]: ${ extVar }` );
|
|
48
|
-
this.addEventListener( 'remove', e => { console.log( '[2]: Removing...' ); } );
|
|
49
|
-
setTimeout( () => { this.remove(); }, 10000 );
|
|
50
|
-
</script>
|
|
51
|
-
</div>
|
|
52
|
-
|
|
53
|
-
<script>
|
|
54
|
-
const div1 = document.querySelector( '#div1' );
|
|
55
|
-
setTimeout( () => {
|
|
56
|
-
Observer.set( globalThis, 'extVar', 'External variable updated value!' );
|
|
57
|
-
Observer.set( div1, 'someProp', 'someProp value!' );
|
|
58
|
-
setTimeout( () => {
|
|
59
|
-
Observer.set( globalThis, 'extVar', 'External variable updated value again!' );
|
|
60
|
-
}, 6000 );
|
|
61
|
-
/*
|
|
62
|
-
extVar = 'External variable updated value!';
|
|
63
|
-
div1.scripts.forEach( script => {
|
|
64
|
-
script.rerender( [ 'extVar' ] );
|
|
65
|
-
} );
|
|
66
|
-
*/
|
|
67
|
-
}, 5000 );
|
|
68
|
-
</script>
|
|
69
|
-
|
|
70
|
-
</body>
|
|
71
|
-
</html>
|