@webqit/oohtml 2.1.20 → 2.1.21

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.1.20",
17
+ "version": "2.1.21",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -40,14 +40,14 @@
40
40
  "dependencies": {
41
41
  "@webqit/dom": "^2.0.8",
42
42
  "@webqit/observer": "^2.0.7",
43
- "@webqit/subscript": "^2.1.39",
43
+ "@webqit/subscript": "^2.1.40",
44
44
  "@webqit/util": "^0.8.11"
45
45
  },
46
46
  "devDependencies": {
47
+ "@webqit/oohtml-ssr": "^1.2.4",
47
48
  "chai": "^4.3.4",
48
49
  "coveralls": "^3.1.1",
49
50
  "esbuild": "^0.14.43",
50
- "jsdom": "^20.0.0",
51
51
  "mocha": "^10.0.0",
52
52
  "mocha-lcov-reporter": "^1.3.0"
53
53
  },
@@ -19,7 +19,7 @@ export default function init( { advanced = {}, ...$config } ) {
19
19
  advanced: resolveParams( advanced, {
20
20
  parserParams: { allowReturnOutsideFunction: false, allowSuperOutsideMethod: false },
21
21
  compilerParams: { globalsNoObserve: [ 'alert' ] },
22
- runtimeParams: { apiVersion: 2, compileFunction: this.webqit.compileFunctionCallback },
22
+ runtimeParams: { apiVersion: 2 },
23
23
  } ),
24
24
  } );
25
25
  config.scriptSelector = ( Array.isArray( config.script.mimeType ) ? config.script.mimeType : [ config.script.mimeType ] ).reduce( ( selector, mm ) => {
@@ -27,7 +27,7 @@ export default function init( { advanced = {}, ...$config } ) {
27
27
  return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[contract]` );
28
28
  }, [] ).join( ',' );
29
29
  window.webqit.oohtml.Script = { compileCache: [ new Map, new Map, ] };
30
- window.webqit.SubscriptFunction/* if already injected */ || ( window.webqit.SubscriptFunction = SubscriptFunction );
30
+ window.webqit.SubscriptFunction = SubscriptFunction;
31
31
  window.webqit.Observer = Observer;
32
32
  realtime.call( window, config );
33
33
  }
@@ -41,21 +41,27 @@ export {
41
41
  // Script runner
42
42
  export function execute( compiledScript, thisContext, script ) {
43
43
  if ( !compiledScript.function ) throw new Error( `Input script must already be compiled!` );
44
+ const _try = ( callback, isRerender = false ) => {
45
+ return callback();
46
+ };
44
47
  // Execute...
45
48
  const returnValue = compiledScript.function.call( thisContext );
46
49
  if ( script.contract ) {
47
50
  // Rerending processes,,,
48
51
  Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
49
52
  _await( script.properties, properties => {
50
- const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
51
53
  properties.processes = properties.dependencies.map( path => {
52
- if ( path[ 0 ] === 'this' ) {
53
- return Observer.deep( thisContext, path.slice( 1 ), Observer.observe, record_s => {
54
- script.rerender( ...getPaths( [ 'this' ], record_s ) );
54
+ const _env = { 'this': thisContext, 'globalThis': globalThis };
55
+ const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
56
+ properties.processes = properties.dependencies.map( path => {
57
+ if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
58
+ return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
59
+ script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
60
+ } );
61
+ }
62
+ return Observer.deep( globalThis, path, Observer.observe, record_s => {
63
+ script.rerender( ...getPaths( [], record_s ) );
55
64
  } );
56
- }
57
- return Observer.deep( globalThis, path, Observer.observe, record_s => {
58
- script.rerender( ...getPaths( [], record_s ) );
59
65
  } );
60
66
  } );
61
67
  } );
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { expect } from 'chai';
6
6
  import { createDocument } from './index.js';
7
- import Observer from '@webqit/observer';
8
7
 
9
8
  describe(`Bindings API`, function() {
10
9
 
@@ -12,7 +11,7 @@ describe(`Bindings API`, function() {
12
11
 
13
12
  const head = ``;
14
13
  const body = ``;
15
- const { document } = createDocument( head, body );
14
+ const { document, window } = createDocument( head, body );
16
15
 
17
16
  it ( `The document object and elements should expose a "bindings" property each...`, async function() {
18
17
  expect( document ).to.have.property( 'bindings' );
@@ -20,6 +19,7 @@ describe(`Bindings API`, function() {
20
19
  } );
21
20
 
22
21
  it ( `Bindings objects should be observable...`, async function() {
22
+ const { webqit: { Observer } } = window;
23
23
  let idReceived = null;
24
24
  Observer.observe( document.bindings, records => {
25
25
  idReceived = records[ 0 ].key;
@@ -3,7 +3,7 @@
3
3
  * @imports
4
4
  */
5
5
  import { expect } from 'chai';
6
- import { delay, createDocument, mockRemoteFetch, _ } from './index.js';
6
+ import { createDocument, mockRemoteFetch, delay } from './index.js';
7
7
 
8
8
  describe(`HTML Imports`, function() {
9
9
 
@@ -25,8 +25,7 @@ describe(`HTML Imports`, function() {
25
25
 
26
26
  it ( `<import> element be automatically resolved: import default export...`, async function() {
27
27
  expect( document.body.children ).to.have.length( 2 );
28
- const importElement = _( document.body.firstElementChild ).get( 'slot@imports' );
29
- expect( importElement.nodeName ).to.eq( 'IMPORT' );
28
+ expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
30
29
  } );
31
30
 
32
31
  it( `<import> element be resolved again: after having mutated an export right at its module.`, async function() {
@@ -147,7 +146,7 @@ describe(`HTML Imports`, function() {
147
146
  // Should stil be waiting...
148
147
  expect( document.body.firstElementChild.nodeName ).to.eq( 'IMPORT' );
149
148
  // When remote request must have completed
150
- await delay( ( timeout * 2 ) + 100 );
149
+ await delay( ( timeout * 2 ) + 150 );
151
150
  expect( document.body.firstElementChild.nodeName ).to.eq( 'P' );
152
151
  expect( document.body.lastElementChild.nodeName ).to.eq( 'P' );
153
152
  } );
@@ -173,7 +172,7 @@ describe(`HTML Imports`, function() {
173
172
  <!--<import module="#input"></import>-->
174
173
  </div>`;
175
174
  const { document } = createDocument( head, body );
176
- await true;
175
+ await delay( 20 );
177
176
 
178
177
  const routingElement = document.body.firstElementChild;
179
178
  expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
@@ -205,7 +204,7 @@ describe(`HTML Imports`, function() {
205
204
  <!--<import module="#input"></import>-->
206
205
  </div>`;
207
206
  const { document } = createDocument( head, body );
208
- await true;
207
+ await delay( 20 );
209
208
 
210
209
  const routingElement = document.body.firstElementChild;
211
210
  expect( routingElement.firstElementChild.nodeName ).to.eq( 'TEXTAREA' );
package/test/index.js CHANGED
@@ -2,12 +2,7 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import { _internals } from '@webqit/util/js/index.js';
6
- import { createContext, compileFunction, runInContext } from 'vm';
7
- import jsdom from 'jsdom';
8
- import init, { Observer } from '../src/index.js';
9
- import { SubscriptFunction } from '@webqit/subscript';
10
- import webqitDom from '@webqit/dom';
5
+ import { createWindow } from '@webqit/oohtml-ssr';
11
6
 
12
7
  /**
13
8
  * -------
@@ -15,8 +10,6 @@ import webqitDom from '@webqit/dom';
15
10
  * -------
16
11
  */
17
12
 
18
- export { Observer };
19
- export const _ = ( ...args ) => _internals( 'oohtml', ...args );
20
13
  export function delay( duration, callback = undefined ) {
21
14
  return new Promise( res => {
22
15
  setTimeout( () => res( callback && callback() ), duration );
@@ -27,59 +20,23 @@ export function createDocument( head = '', body = '', callback = null, ) {
27
20
  const skeletonDoc = `
28
21
  <!DOCTYPE html>
29
22
  <html>
30
- <head>${ head }</head>
23
+ <head>
24
+ <meta name="subscript-compiler-url" content="../subscript/dist/compiler.js">
25
+ <script ssr src="/dist/main.js"></script>
26
+ ${ head }
27
+ </head>
31
28
  <body>${ body }</body>
32
29
  </html>`;
33
- // TODO: Proper indentation for pretty-printing
34
- const instance = new jsdom.JSDOM( skeletonDoc, {
35
- url: 'http://localhost',
30
+ return createWindow( skeletonDoc, {
31
+ // Notice we do not want to use the Path utility here.
32
+ // Destroys the file:/// url convention especially in windows
33
+ url: import.meta.url.substring( 0, import.meta.url.lastIndexOf( '/test/' ) ),
36
34
  beforeParse( window ) {
37
- init.call( window );
38
- if ( callback ) callback( window, window.webqit.dom );
35
+ if ( callback ) callback( window );
39
36
  }
40
37
  } );
41
- return instance.window;
42
38
  }
43
39
 
44
- export function createDocumentForScopedJS( head = '', body = '', callback = null, params = {} ) {
45
- const skeletonDoc = `
46
- <!DOCTYPE html>
47
- <html>
48
- <head>${ head }</head>
49
- <body>${ body }</body>
50
- </html>`;
51
- const instance = new jsdom.JSDOM( skeletonDoc, {
52
- ...params,
53
- url: 'http://localhost',
54
- beforeParse( window ) {
55
- window.testRecords = [];
56
- createContext( window );
57
- // Running advanced scripts
58
- window.webqit = {
59
- SubscriptFunction,
60
- compileFunctionCallback: ( code, parameters ) => compileFunction( code, parameters, {
61
- parsingContext: window,
62
- } ),
63
- };
64
- init.call( window );
65
- // Running basic scripts
66
- const dom = webqitDom.call( window );
67
- if ( params.runScripts !== 'dangerously' ) {
68
- dom.realtime( window.document ).observe( 'script', record => {
69
- record.entrants.forEach( script => {
70
- if ( !script.textContent.trim() ) return;
71
- runInContext( script.textContent, window );
72
- } );
73
- }, { subtree: true } );
74
- }
75
- // Sync callback?
76
- if ( callback ) callback( window, window.webqit.dom );
77
- }
78
- } );
79
- return instance.window;
80
- };
81
-
82
-
83
40
  export function mockRemoteFetch( window, contents, delay = 1000 ) {
84
41
  window.fetch = url => {
85
42
  console.info( 'Fetching .......... ', url );
@@ -3,8 +3,7 @@
3
3
  * @imports
4
4
  */
5
5
  import { expect } from 'chai';
6
- import Observer from '@webqit/observer';
7
- import { delay, createDocument, mockRemoteFetch, _ } from './index.js';
6
+ import { createDocument, mockRemoteFetch, delay } from './index.js';
8
7
  const getQueryPath = str => str.split( '/' ).join( '/modules/' ).split( '/' );
9
8
 
10
9
  describe(`HTML Modules`, function() {
@@ -47,8 +46,9 @@ describe(`HTML Modules`, function() {
47
46
  <p>Hellort</p>
48
47
  </template>
49
48
  </template>`;
50
- const { document } = createDocument( head, body );
51
- await delay( 200 );
49
+ const { document, window } = createDocument( head, body );
50
+ await delay( 20 );
51
+ const { webqit: { Observer } } = window;
52
52
  // -------
53
53
  const temp0 = Observer.deep( document.modules, getQueryPath( 'temp0' ), Observer.get );
54
54
  expect( temp0 ).to.have.property( 'modules' );
@@ -79,13 +79,12 @@ describe(`HTML Modules`, function() {
79
79
  } );
80
80
 
81
81
  describe( `Remote...`, function() {
82
- //return;
83
82
  this.timeout( 10000 );
84
83
 
85
84
  it( `Add remote lazy module, with a nested remote lazy module, then resolve.`, async function() {
86
85
 
87
86
  const head = ``, body = ``;
88
- const window = createDocument( head, body, window => {
87
+ const { document, window } = createDocument( head, body, window => {
89
88
  // Define remote responses
90
89
  const temp0 = `
91
90
  <template exportid="temp1" src="/temp1.html" loading="lazy"></template>`;
@@ -97,7 +96,9 @@ describe(`HTML Modules`, function() {
97
96
  <p>Hellort</p>`;
98
97
  const timeout = 1000;
99
98
  mockRemoteFetch( window, { '/temp0.html': temp0, '/temp1.html': temp1, '/temp2.html': temp2 }, timeout );
100
- } ), document = window.document;
99
+ } );
100
+ await delay( 20 );
101
+ const { webqit: { Observer } } = window;
101
102
  // -------
102
103
  // Add a remote module
103
104
  const templateEl = document.createElement( 'template' );
@@ -132,7 +133,6 @@ describe(`HTML Modules`, function() {
132
133
  } );
133
134
 
134
135
  describe( `Context...`, function() {
135
- //return;
136
136
  this.timeout( 10000 );
137
137
 
138
138
  it( `Use the context API to fire a scoped-request that is imitially resolved from the document and then from a scoped context.`, async function() {
@@ -146,7 +146,9 @@ describe(`HTML Modules`, function() {
146
146
  </template>`;
147
147
  const body = `
148
148
  <div></div>`;
149
- const window = createDocument( head, body ), document = window.document;
149
+ const { document, window } = createDocument( head, body );
150
+ await delay( 20 );
151
+
150
152
  // -------
151
153
  const addScopedModules = () => {
152
154
  const templateEl = document.createElement( 'template' );
@@ -3,12 +3,11 @@
3
3
  * @imports
4
4
  */
5
5
  import { expect } from 'chai';
6
- import { createDocument } from './index.js';
7
- import Observer from '@webqit/observer';
6
+ import { createDocument, delay } from './index.js';
8
7
 
9
8
  describe(`Namespaced HTML`, function() {
10
9
 
11
- describe( `Basic...`, function() {
10
+ describe( `Basic...`, async function() {
12
11
 
13
12
  const head = `
14
13
  <meta name="oohtml" content="attr.id=:id" />`;
@@ -16,7 +15,9 @@ describe(`Namespaced HTML`, function() {
16
15
  <div :id="main" namespace>
17
16
  <div :id="child"></div>
18
17
  </div>`;
19
- const { document } = createDocument( head, body );
18
+ const { document, window } = createDocument( head, body );
19
+ await delay( 60 );
20
+ const { webqit: { Observer } } = window;
20
21
 
21
22
  it ( `The document object and elements should expose a "namespace" property each...`, async function() {
22
23
  expect( document ).to.have.property( 'namespace' );
@@ -3,38 +3,10 @@
3
3
  * @imports
4
4
  */
5
5
  import { expect } from 'chai';
6
- import { delay, createDocumentForScopedJS } from './index.js';
6
+ import { createDocument, delay } from './index.js';
7
7
 
8
8
  describe(`Test: Scoped JS`, function() {
9
9
 
10
- describe(`Scripts`, function() {
11
-
12
- it(`Should do basic observe`, async function() {
13
- const head = '', body = `
14
- <h1>Hello World!</h1>
15
- <script>
16
- let ul = document.createElement( 'ul' );
17
- let li = document.createElement( 'li' );
18
- ul.appendChild(li);
19
- document.body.appendChild(ul);
20
- </script>
21
- <div><p>Hello World!</p></div>`;
22
-
23
- const window = createDocumentForScopedJS( head, body, ( window, dom ) => {
24
- // Observer is bound before document is parsed.
25
- // Elements are going to show up as they are being parsed.
26
- dom.realtime( window.document ).observe( 'h1,p,li', record => {
27
- window.testRecords.push( record.entrants[ 0 ] );
28
- }, { subtree: true } );
29
- }, { runScripts: 'dangerously' } );
30
-
31
- await delay( 60 );
32
- expect( window.testRecords ).to.have.length( 3 );
33
- });
34
-
35
-
36
- });
37
-
38
10
  describe(`Scripts`, function() {
39
11
 
40
12
  it(`Should do basic observe`, async function() {
@@ -45,12 +17,12 @@ describe(`Test: Scoped JS`, function() {
45
17
  console.log('-------scoped JS here.');
46
18
  </script>`;
47
19
 
48
- const window = createDocumentForScopedJS( head, body );
20
+ const window = createDocument( head, body );
21
+ window.testRecords = [];
22
+ await delay( 160 ); // Takes time to dynamically load Subscript compiler
49
23
 
50
- await delay( 60 );
51
24
  expect( window.testRecords ).to.have.length( 1 );
52
25
  expect( window.testRecords[ 0 ] ).to.eql( window.document.body );
53
- //console.log('::::::::::::', window.testRecords );
54
26
  });
55
27
 
56
28
  });