@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/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.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.0",
43
- "@webqit/subscript": "^2.1.34",
42
+ "@webqit/observer": "^2.0.1",
43
+ "@webqit/subscript": "^2.1.35",
44
44
  "@webqit/util": "^0.8.9"
45
45
  },
46
46
  "devDependencies": {
@@ -35,6 +35,8 @@ export default function init( $params = {} ) {
35
35
  realtime.call( this, params );
36
36
  }
37
37
 
38
+ export { Observer }
39
+
38
40
  /**
39
41
  * Returns the "exports" object associated with the given node.
40
42
  *
@@ -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: 'data-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;
@@ -2,7 +2,9 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import SubscriptFunctionLite from '@webqit/subscript/src/SubscriptFunctionLite.js';
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
- mimeType: '',
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 ( compiledScript.contract ) {
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
- thisContext.removeEventListener( 'namespacechange', changeHandler );
97
- thisContext.removeEventListener( 'statechange', changeHandler );
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
- const parserParams = {
128
- ...( params.parserParams || {} ),
129
- allowReturnOutsideFunction: false,
130
- allowAwaitOutsideFunction: script.type === 'module',
131
- allowSuperOutsideMethod: false,
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;
@@ -19,6 +19,8 @@ export default function init( $params = {} ) {
19
19
  exposeAPIs.call( this, params );
20
20
  }
21
21
 
22
+ export { Observer }
23
+
22
24
  /**
23
25
  * @Exports
24
26
  *
@@ -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;
@@ -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=data-id" />`;
14
+ <meta name="oohtml" content="attr.id=:id" />`;
15
15
  const body = `
16
- <div data-id="main" namespace>
17
- <div data-id="child"></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( 'data-id', 'some-id' );
32
+ item.setAttribute( ':id', 'some-id' );
33
33
  document.body.appendChild( item );
34
34
  expect( idReceived ).to.eq( 'some-id' );
35
35
  } );
@@ -42,6 +42,7 @@ describe(`Test: Scoped JS`, function() {
42
42
  <h1>Hello World!</h1>
43
43
  <script scoped contract>
44
44
  testRecords.push( this );
45
+ console.log('-------scoped JS here.');
45
46
  </script>`;
46
47
 
47
48
  const window = createDocumentForScopedJS( head, body );
package/test/test.html CHANGED
@@ -1,10 +1,11 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <meta name="subscript-compiler-url" content="http://127.0.0.1:5500/subscript/dist/compiler.js" />
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="diiiiv">
31
- DIV
32
- <script scoped contract>
33
- console.log( 'Execution context: ' + this.tagName );
34
- console.log( extVar );
35
- this.addEventListener( 'remove', e => {
36
- console.log('removing...');
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="diiiiv2">
45
- DIV
46
- <script scoped contract>
47
- console.log( 'Execution context: ' + this.tagName );
48
- console.log( extVar );
49
- this.addEventListener( 'beforeremove', e => {
50
- console.log('removing...');
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 diiiiv = document.querySelector( '#diiiiv' );
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
- diiiiv.scripts.forEach( script => {
63
+ div1.scripts.forEach( script => {
63
64
  script.rerender( [ 'extVar' ] );
64
65
  } );
66
+ */
65
67
  }, 5000 );
66
68
  </script>
67
69