@webqit/oohtml 2.0.0 → 2.0.2
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.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 +11 -11
- package/dist/scoped-js.js.map +3 -3
- package/dist/state-api.js +1 -1
- package/dist/state-api.js.map +2 -2
- package/package.json +3 -3
- package/src/html-modules/index.js +2 -0
- package/src/html-modules/targets.browser.js +5 -2
- package/src/namespaced-html/index.js +3 -1
- package/src/namespaced-html/targets.browser.js +5 -2
- package/src/scoped-js/index.js +36 -29
- package/src/scoped-js/targets.browser.js +5 -2
- package/src/state-api/index.js +2 -0
- package/src/state-api/targets.browser.js +5 -2
- package/src/targets.browser.js +5 -2
- package/test/namespaced-html.test.js +4 -4
- package/test/{scoped-js.js → scoped-js.test2.js} +1 -0
- package/test/test.html +28 -26
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.0.
|
|
17
|
+
"version": "2.0.2",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@webqit/dom": "^2.0.0",
|
|
42
|
-
"@webqit/observer": "^2.0.
|
|
43
|
-
"@webqit/subscript": "^2.1.
|
|
42
|
+
"@webqit/observer": "^2.0.1",
|
|
43
|
+
"@webqit/subscript": "^2.1.35",
|
|
44
44
|
"@webqit/util": "^0.8.9"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import init from './index.js';
|
|
5
|
+
import init, { Observer } from './index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @init
|
|
9
9
|
*/
|
|
10
|
-
init.call( window );
|
|
10
|
+
init.call( window );
|
|
11
|
+
// As globals
|
|
12
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
13
|
+
window.wq.Observer = Observer;
|
|
@@ -15,7 +15,7 @@ export default function init( $params = {} ) {
|
|
|
15
15
|
const window = this, dom = wqDom.call( window );
|
|
16
16
|
// -------
|
|
17
17
|
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
18
|
-
attr: { namespace: 'namespace', id: '
|
|
18
|
+
attr: { namespace: 'namespace', id: ':id', },
|
|
19
19
|
api: { namespace: 'namespace', },
|
|
20
20
|
staticsensitivity: true,
|
|
21
21
|
eagermode: true,
|
|
@@ -27,6 +27,8 @@ export default function init( $params = {} ) {
|
|
|
27
27
|
realtime.call( this, params );
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export { Observer }
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* Exposes Namespaced HTML with native APIs.
|
|
32
34
|
*
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import init from './index.js';
|
|
5
|
+
import init, { Observer } from './index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @init
|
|
9
9
|
*/
|
|
10
|
-
init.call( window );
|
|
10
|
+
init.call( window );
|
|
11
|
+
// As globals
|
|
12
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
13
|
+
window.wq.Observer = Observer;
|
package/src/scoped-js/index.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { parserParams, compilerParams, runtimeParams } from '@webqit/subscript/src/params.js';
|
|
6
|
+
import SubscriptFunction from '@webqit/subscript/src/SubscriptFunctionLite.js';
|
|
7
|
+
import Observer from '@webqit/observer';
|
|
6
8
|
import wqDom from '@webqit/dom';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -14,10 +16,12 @@ export default function init( $params = {} ) {
|
|
|
14
16
|
const window = this, dom = wqDom.call( window );
|
|
15
17
|
// -------
|
|
16
18
|
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
17
|
-
retention: 'retain',
|
|
18
|
-
|
|
19
|
+
script: { retention: 'retain', mimeType: '' },
|
|
20
|
+
parserParams: { ...parserParams, allowReturnOutsideFunction: false, allowSuperOutsideMethod: false, },
|
|
21
|
+
compilerParams: { ...compilerParams, globalsNoObserve: [ ...compilerParams.globalsNoObserve, 'alert' ] },
|
|
22
|
+
runtimeParams: { ...runtimeParams, apiVersion: 2, },
|
|
19
23
|
} );
|
|
20
|
-
params.scriptSelector = ( Array.isArray( params.mimeType ) ? params.mimeType : [ params.mimeType ] ).reduce( ( selector, mm ) => {
|
|
24
|
+
params.scriptSelector = ( Array.isArray( params.script.mimeType ) ? params.script.mimeType : [ params.script.mimeType ] ).reduce( ( selector, mm ) => {
|
|
21
25
|
const qualifier = mm ? `[type=${ window.CSS.escape( mm ) }]` : '';
|
|
22
26
|
return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[contract]` );
|
|
23
27
|
}, [] ).join( ',' );
|
|
@@ -25,6 +29,8 @@ export default function init( $params = {} ) {
|
|
|
25
29
|
realtime.call( this, params );
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
export { Observer }
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* Performs realtime capture of elements and builds their relationships.
|
|
30
36
|
*
|
|
@@ -59,12 +65,12 @@ function realtime( params ) {
|
|
|
59
65
|
if ( !thisContext.scripts ) { Object.defineProperty( thisContext, 'scripts', { value: new Set } ); }
|
|
60
66
|
thisContext.scripts.add( script );
|
|
61
67
|
}
|
|
62
|
-
switch ( params.retention ) {
|
|
68
|
+
switch ( params.script.retention ) {
|
|
63
69
|
case 'dispose':
|
|
64
70
|
script.remove();
|
|
65
71
|
break;
|
|
66
72
|
case 'hidden':
|
|
67
|
-
script.textContent = `"hidden"`;
|
|
73
|
+
script.textContent = `"source hidden"`;
|
|
68
74
|
break;
|
|
69
75
|
default:
|
|
70
76
|
script.textContent = compiledScript.function.originalSource;
|
|
@@ -79,22 +85,30 @@ export function execute( compiledScript, thisContext, script ) {
|
|
|
79
85
|
if ( !compiledScript.function ) throw new Error( `Input script must already be compiled!` );
|
|
80
86
|
// Execute...
|
|
81
87
|
const returnValue = compiledScript.function.call( thisContext );
|
|
82
|
-
if (
|
|
88
|
+
if ( script.contract ) {
|
|
89
|
+
// Rerending processes,,,
|
|
83
90
|
Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
|
|
91
|
+
_await( script.properties, properties => {
|
|
92
|
+
const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
|
|
93
|
+
properties.processes = properties.dependencies.map( path => {
|
|
94
|
+
if ( path[ 0 ] === 'this' ) {
|
|
95
|
+
return Observer.deep( thisContext, path.slice( 1 ), Observer.observe, record_s => {
|
|
96
|
+
script.rerender( ...getPaths( [ 'this' ], record_s ) );
|
|
97
|
+
} );
|
|
98
|
+
}
|
|
99
|
+
return Observer.deep( globalThis, path, Observer.observe, record_s => {
|
|
100
|
+
script.rerender( ...getPaths( [], record_s ) );
|
|
101
|
+
} );
|
|
102
|
+
} );
|
|
103
|
+
} );
|
|
84
104
|
}
|
|
85
|
-
// Observe,,,
|
|
86
105
|
const window = this, { dom } = window.wq;
|
|
87
|
-
if ( !( thisContext instanceof window.EventTarget ) ) return returnValue;
|
|
88
|
-
let changeHandler;
|
|
89
|
-
if ( script.contract ) {
|
|
90
|
-
changeHandler = e => { script.rerender( ( e.detail || { paths: [] } ).paths ); };
|
|
91
|
-
thisContext.addEventListener( 'namespacechange', changeHandler );
|
|
92
|
-
thisContext.addEventListener( 'statechange', changeHandler );
|
|
93
|
-
}
|
|
94
106
|
dom.realtime( window.document ).observe( thisContext, () => {
|
|
95
107
|
if ( script.contract ) {
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
// Rerending processes,,,
|
|
109
|
+
_await( script.properties, properties => {
|
|
110
|
+
properties.processes.forEach( process => process.abort() );
|
|
111
|
+
} );
|
|
98
112
|
}
|
|
99
113
|
thisContext.dispatchEvent( new window.CustomEvent( 'remove' ) );
|
|
100
114
|
thisContext.scripts.delete( script );
|
|
@@ -124,18 +138,11 @@ export function compile( script, thisContext, params = {} ) {
|
|
|
124
138
|
// Let's obtain a material functions
|
|
125
139
|
let _Function;
|
|
126
140
|
if ( script.contract ) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
const runtimeParams = {
|
|
134
|
-
...( params.runtimeParams || {} ),
|
|
135
|
-
async: script.type === 'module',
|
|
136
|
-
apiVersion: 2,
|
|
137
|
-
};
|
|
138
|
-
_Function = SubscriptFunctionLite( source, { ...params, parserParams, runtimeParams, } );
|
|
141
|
+
let { parserParams, compilerParams, runtimeParams } = params;
|
|
142
|
+
parserParams = { ...parserParams, allowAwaitOutsideFunction: script.type === 'module' };
|
|
143
|
+
runtimeParams = { ...runtimeParams, async: script.type === 'module' };
|
|
144
|
+
_Function = SubscriptFunction( source, { compilerParams, parserParams, runtimeParams, } );
|
|
145
|
+
Object.defineProperty( script, 'properties', { configurable: true, value: SubscriptFunction.inspect( _Function, 'properties' ) } );
|
|
139
146
|
} else {
|
|
140
147
|
const isAsync = script.type === 'module'//meta.topLevelAwait || imports.length;
|
|
141
148
|
const _FunctionConstructor = isAsync ? Object.getPrototypeOf( async function() {} ).constructor : Function;
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import init from './index.js';
|
|
5
|
+
import init, { Observer } from './index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @init
|
|
9
9
|
*/
|
|
10
|
-
init.call( window );
|
|
10
|
+
init.call( window );
|
|
11
|
+
// As globals
|
|
12
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
13
|
+
window.wq.Observer = Observer;
|
package/src/state-api/index.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import init from './index.js';
|
|
5
|
+
import init, { Observer } from './index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @init
|
|
9
9
|
*/
|
|
10
|
-
init.call( window );
|
|
10
|
+
init.call( window );
|
|
11
|
+
// As globals
|
|
12
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
13
|
+
window.wq.Observer = Observer;
|
package/src/targets.browser.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import init from './index.js';
|
|
5
|
+
import init, { Observer } from './index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @init
|
|
9
9
|
*/
|
|
10
|
-
init.call(window);
|
|
10
|
+
init.call( window );
|
|
11
|
+
// As globals
|
|
12
|
+
if ( !window.wq ) { window.wq = {}; }
|
|
13
|
+
window.wq.Observer = Observer;
|
|
@@ -11,10 +11,10 @@ describe(`Namespaced HTML`, function() {
|
|
|
11
11
|
describe( `Basic...`, function() {
|
|
12
12
|
|
|
13
13
|
const head = `
|
|
14
|
-
<meta name="oohtml" content="attr.id
|
|
14
|
+
<meta name="oohtml" content="attr.id=:id" />`;
|
|
15
15
|
const body = `
|
|
16
|
-
<div
|
|
17
|
-
<div
|
|
16
|
+
<div :id="main" namespace>
|
|
17
|
+
<div :id="child"></div>
|
|
18
18
|
</div>`;
|
|
19
19
|
const { document } = createDocument( head, body );
|
|
20
20
|
|
|
@@ -29,7 +29,7 @@ describe(`Namespaced HTML`, function() {
|
|
|
29
29
|
idReceived = records[ 0 ].key;
|
|
30
30
|
} );
|
|
31
31
|
const item = document.createElement( 'div' );
|
|
32
|
-
item.setAttribute( '
|
|
32
|
+
item.setAttribute( ':id', 'some-id' );
|
|
33
33
|
document.body.appendChild( item );
|
|
34
34
|
expect( idReceived ).to.eq( 'some-id' );
|
|
35
35
|
} );
|
package/test/test.html
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
|
-
<meta name="
|
|
5
|
-
<script src="/oohtml/dist/main.js"></script>
|
|
4
|
+
<meta name="oohtml" content="script.retention=hidden" />
|
|
5
|
+
<script src="https://unpkg.com/@webqit/oohtml/dist/main.js"></script>
|
|
6
6
|
<script>
|
|
7
7
|
window.extVar = 'External variable initial value.';
|
|
8
|
+
window.Observer = wq.Observer;
|
|
8
9
|
</script>
|
|
9
10
|
<template exportid="temp0">
|
|
10
11
|
<input exportid="input" />
|
|
@@ -27,41 +28,42 @@
|
|
|
27
28
|
<!--<import module="#input"></import>-->
|
|
28
29
|
</div>
|
|
29
30
|
|
|
30
|
-
<div id="
|
|
31
|
-
|
|
32
|
-
<script scoped contract>
|
|
33
|
-
console.log( 'Execution context: ' + this.tagName );
|
|
34
|
-
console.log(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} );
|
|
38
|
-
setTimeout( () => {
|
|
39
|
-
this.remove();
|
|
40
|
-
}, 10000 );
|
|
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 );
|
|
41
39
|
</script>
|
|
42
40
|
</div>
|
|
43
41
|
|
|
44
|
-
<div id="
|
|
45
|
-
|
|
46
|
-
<script scoped contract>
|
|
47
|
-
console.log( 'Execution context: '
|
|
48
|
-
console.log(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} );
|
|
52
|
-
setTimeout( () => {
|
|
53
|
-
this.remove();
|
|
54
|
-
}, 10000 );
|
|
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 );
|
|
55
50
|
</script>
|
|
56
51
|
</div>
|
|
57
52
|
|
|
58
53
|
<script>
|
|
59
|
-
const
|
|
54
|
+
const div1 = document.querySelector( '#div1' );
|
|
60
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
|
+
/*
|
|
61
62
|
extVar = 'External variable updated value!';
|
|
62
|
-
|
|
63
|
+
div1.scripts.forEach( script => {
|
|
63
64
|
script.rerender( [ 'extVar' ] );
|
|
64
65
|
} );
|
|
66
|
+
*/
|
|
65
67
|
}, 5000 );
|
|
66
68
|
</script>
|
|
67
69
|
|