@webqit/oohtml 2.1.34 → 2.1.35

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.
Files changed (52) hide show
  1. package/.gitignore +3 -3
  2. package/LICENSE +20 -20
  3. package/README.md +733 -67
  4. package/dist/bindings-api.js +1 -1
  5. package/dist/bindings-api.js.map +3 -3
  6. package/dist/context-api.js +1 -1
  7. package/dist/context-api.js.map +3 -3
  8. package/dist/html-imports.js +1 -1
  9. package/dist/html-imports.js.map +3 -3
  10. package/dist/main.js +12 -12
  11. package/dist/main.js.map +3 -3
  12. package/dist/namespace-api.js +1 -1
  13. package/dist/namespace-api.js.map +3 -3
  14. package/dist/scoped-css.js +2 -2
  15. package/dist/scoped-css.js.map +3 -3
  16. package/dist/scoped-js.js +7 -7
  17. package/dist/scoped-js.js.map +3 -3
  18. package/package.json +76 -76
  19. package/src/bindings-api/index.js +83 -83
  20. package/src/bindings-api/targets.browser.js +10 -10
  21. package/src/context-api/HTMLContext.js +76 -157
  22. package/src/context-api/HTMLContextProvider.js +158 -0
  23. package/src/context-api/_ContextRequestEvent.js +25 -25
  24. package/src/context-api/index.js +51 -51
  25. package/src/context-api/targets.browser.js +9 -9
  26. package/src/{html-modules/HTMLExportsManager.js → html-imports/_HTMLExportsManager.js} +185 -199
  27. package/src/html-imports/_HTMLImportElement.js +211 -213
  28. package/src/{html-modules/_HTMLImportsContext.js → html-imports/_HTMLImportsProvider.js} +122 -114
  29. package/src/html-imports/index.js +197 -88
  30. package/src/html-imports/targets.browser.js +9 -9
  31. package/src/index.js +30 -32
  32. package/src/namespace-api/index.js +144 -144
  33. package/src/namespace-api/targets.browser.js +10 -10
  34. package/src/scoped-css/index.js +45 -45
  35. package/src/scoped-css/targets.browser.js +10 -10
  36. package/src/scoped-js/Compiler.js +297 -297
  37. package/src/scoped-js/index.js +112 -112
  38. package/src/scoped-js/targets.browser.js +10 -10
  39. package/src/targets.browser.js +9 -9
  40. package/src/util.js +34 -34
  41. package/test/bindings-api.test.js +42 -42
  42. package/test/imports.test.js +221 -221
  43. package/test/index.js +50 -50
  44. package/test/modules.test.js +200 -200
  45. package/test/namespace-api.test.js +51 -51
  46. package/test/scoped-css.test.js +31 -31
  47. package/test/scoped-js.test.js +29 -29
  48. package/dist/html-modules.js +0 -2
  49. package/dist/html-modules.js.map +0 -7
  50. package/src/context-api/HTMLContextManager.js +0 -77
  51. package/src/html-modules/index.js +0 -131
  52. package/src/html-modules/targets.browser.js +0 -10
@@ -1,112 +1,112 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _isTypeObject } from '@webqit/util/js/index.js';
6
- import { resolveParams } from '@webqit/subscript/src/params.js';
7
- import SubscriptFunction from '@webqit/subscript/src/SubscriptFunctionLite.js';
8
- import Observer from '@webqit/observer';
9
- import Compiler from './Compiler.js';
10
- import { _init } from '../util.js';
11
-
12
- /**
13
- * @init
14
- *
15
- * @param Object $config
16
- */
17
- export default function init( { advanced = {}, ...$config } ) {
18
- const { config, window } = _init.call( this, 'scoped-js', $config, {
19
- script: { retention: 'retain', mimeType: '' },
20
- advanced: resolveParams( advanced, {
21
- parserParams: { allowReturnOutsideFunction: false, allowSuperOutsideMethod: false },
22
- compilerParams: { globalsNoObserve: [ 'alert' ] },
23
- runtimeParams: { apiVersion: 2 },
24
- } ),
25
- } );
26
- config.scriptSelector = ( Array.isArray( config.script.mimeType ) ? config.script.mimeType : [ config.script.mimeType ] ).reduce( ( selector, mm ) => {
27
- const qualifier = mm ? `[type=${ window.CSS.escape( mm ) }]` : '';
28
- return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[contract]` );
29
- }, [] ).join( ',' );
30
- window.webqit.oohtml.Script = { compileCache: [ new Map, new Map, ] };
31
- window.webqit.SubscriptFunction = SubscriptFunction;
32
- window.webqit.Observer = Observer;
33
- realtime.call( window, config );
34
- }
35
-
36
- export {
37
- SubscriptFunction,
38
- Observer,
39
- }
40
-
41
- // ------------------
42
- // Script runner
43
- export function execute( compiledScript, thisContext, script ) {
44
- if ( !compiledScript.function ) throw new Error( `Input script must already be compiled!` );
45
- const _try = ( callback, isRerender = false ) => {
46
- return callback();
47
- };
48
- // Execute...
49
- const returnValue = compiledScript.function.call( thisContext );
50
- if ( script.contract ) {
51
- // Rerending processes,,,
52
- Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
53
- _await( script.properties, properties => {
54
- properties.processes = properties.dependencies.map( path => {
55
- const _env = { 'this': thisContext, 'globalThis': globalThis, 'window': globalThis.window, 'self': globalThis.self };
56
- const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
57
- properties.processes = properties.dependencies.map( path => {
58
- if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
59
- return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
60
- script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
61
- } );
62
- }
63
- return Observer.deep( globalThis, path, Observer.observe, record_s => {
64
- script.rerender( ...getPaths( [], record_s ) );
65
- } );
66
- } );
67
- } );
68
- } );
69
- }
70
- const window = this, { realdom } = window.webqit;
71
- realdom.realtime( window.document ).observe( thisContext, () => {
72
- if ( script.contract ) {
73
- // Rerending processes,,,
74
- _await( script.properties, properties => {
75
- properties.processes.forEach( process => process.abort() );
76
- } );
77
- }
78
- thisContext.dispatchEvent( new window.CustomEvent( 'remove' ) );
79
- thisContext.scripts.delete( script );
80
- }, { subtree: true, timing: 'sync', generation: 'exits' } );
81
- return script;
82
- }
83
-
84
- /**
85
- * Performs realtime capture of elements and builds their relationships.
86
- *
87
- * @param Object config
88
- *
89
- * @return Void
90
- */
91
- function realtime( config ) {
92
- const window = this, { realdom } = window.webqit;
93
- if ( !window.HTMLScriptElement.supports ) { window.HTMLScriptElement.supports = () => false; }
94
- const potentialManualTypes = [ 'module' ].concat( config.script.mimeType || [] );
95
- const compiler = new Compiler( window, config, execute ), handled = () => {};
96
- realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( config.scriptSelector, record => {
97
- record.entrants.forEach( script => {
98
- if ( 'contract' in script ) return handled( script );
99
- Object.defineProperty( script, 'contract', { value: script.hasAttribute( 'contract' ) } );
100
- if ( 'scoped' in script ) return handled( script );
101
- Object.defineProperty( script, 'scoped', { value: script.hasAttribute( 'scoped' ) } );
102
- if ( record.type === 'query' || ( potentialManualTypes.includes( script.type ) && !window.HTMLScriptElement.supports( script.type ) ) ) {
103
- Object.defineProperty( script, 'handling', { value: 'manual' } );
104
- }
105
- const thisContext = script.scoped ? record.target : ( script.type === 'module' ? undefined : window );
106
- compiler.compile( script, thisContext );
107
- } );
108
- }, { live: true, timing: 'intercept', generation: 'entrants' } );
109
- // ---
110
- }
111
-
112
- const _await = ( value, callback ) => value instanceof Promise ? value.then( callback ) : callback( value );
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { _isTypeObject } from '@webqit/util/js/index.js';
6
+ import { resolveParams } from '@webqit/subscript/src/params.js';
7
+ import SubscriptFunction from '@webqit/subscript/src/SubscriptFunctionLite.js';
8
+ import Observer from '@webqit/observer';
9
+ import Compiler from './Compiler.js';
10
+ import { _init } from '../util.js';
11
+
12
+ /**
13
+ * @init
14
+ *
15
+ * @param Object $config
16
+ */
17
+ export default function init( { advanced = {}, ...$config } ) {
18
+ const { config, window } = _init.call( this, 'scoped-js', $config, {
19
+ script: { retention: 'retain', mimeType: '' },
20
+ advanced: resolveParams( advanced, {
21
+ parserParams: { allowReturnOutsideFunction: false, allowSuperOutsideMethod: false },
22
+ compilerParams: { globalsNoObserve: [ 'alert' ] },
23
+ runtimeParams: { apiVersion: 2 },
24
+ } ),
25
+ } );
26
+ config.scriptSelector = ( Array.isArray( config.script.mimeType ) ? config.script.mimeType : [ config.script.mimeType ] ).reduce( ( selector, mm ) => {
27
+ const qualifier = mm ? `[type=${ window.CSS.escape( mm ) }]` : '';
28
+ return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[contract]` );
29
+ }, [] ).join( ',' );
30
+ window.webqit.oohtml.Script = { compileCache: [ new Map, new Map, ] };
31
+ window.webqit.SubscriptFunction = SubscriptFunction;
32
+ window.webqit.Observer = Observer;
33
+ realtime.call( window, config );
34
+ }
35
+
36
+ export {
37
+ SubscriptFunction,
38
+ Observer,
39
+ }
40
+
41
+ // ------------------
42
+ // Script runner
43
+ export function execute( compiledScript, thisContext, script ) {
44
+ if ( !compiledScript.function ) throw new Error( `Input script must already be compiled!` );
45
+ const _try = ( callback, isRerender = false ) => {
46
+ return callback();
47
+ };
48
+ // Execute...
49
+ const returnValue = compiledScript.function.call( thisContext );
50
+ if ( script.contract ) {
51
+ // Rerending processes,,,
52
+ Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
53
+ _await( script.properties, properties => {
54
+ properties.processes = properties.dependencies.map( path => {
55
+ const _env = { 'this': thisContext, 'globalThis': globalThis, 'window': globalThis.window, 'self': globalThis.self };
56
+ const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
57
+ properties.processes = properties.dependencies.map( path => {
58
+ if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
59
+ return Observer.deep( _env[ path[ 0 ] ], path.slice( 1 ), Observer.observe, record_s => {
60
+ script.rerender( ...getPaths( [ path[ 0 ] ], record_s ) );
61
+ } );
62
+ }
63
+ return Observer.deep( globalThis, path, Observer.observe, record_s => {
64
+ script.rerender( ...getPaths( [], record_s ) );
65
+ } );
66
+ } );
67
+ } );
68
+ } );
69
+ }
70
+ const window = this, { realdom } = window.webqit;
71
+ realdom.realtime( window.document ).observe( thisContext, () => {
72
+ if ( script.contract ) {
73
+ // Rerending processes,,,
74
+ _await( script.properties, properties => {
75
+ properties.processes.forEach( process => process.abort() );
76
+ } );
77
+ }
78
+ thisContext.dispatchEvent( new window.CustomEvent( 'remove' ) );
79
+ thisContext.scripts.delete( script );
80
+ }, { subtree: true, timing: 'sync', generation: 'exits' } );
81
+ return script;
82
+ }
83
+
84
+ /**
85
+ * Performs realtime capture of elements and builds their relationships.
86
+ *
87
+ * @param Object config
88
+ *
89
+ * @return Void
90
+ */
91
+ function realtime( config ) {
92
+ const window = this, { realdom } = window.webqit;
93
+ if ( !window.HTMLScriptElement.supports ) { window.HTMLScriptElement.supports = () => false; }
94
+ const potentialManualTypes = [ 'module' ].concat( config.script.mimeType || [] );
95
+ const compiler = new Compiler( window, config, execute ), handled = () => {};
96
+ realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( config.scriptSelector, record => {
97
+ record.entrants.forEach( script => {
98
+ if ( 'contract' in script ) return handled( script );
99
+ Object.defineProperty( script, 'contract', { value: script.hasAttribute( 'contract' ) } );
100
+ if ( 'scoped' in script ) return handled( script );
101
+ Object.defineProperty( script, 'scoped', { value: script.hasAttribute( 'scoped' ) } );
102
+ if ( record.type === 'query' || ( potentialManualTypes.includes( script.type ) && !window.HTMLScriptElement.supports( script.type ) ) ) {
103
+ Object.defineProperty( script, 'handling', { value: 'manual' } );
104
+ }
105
+ const thisContext = script.scoped ? script.parentNode || record.target : ( script.type === 'module' ? undefined : window );
106
+ compiler.compile( script, thisContext );
107
+ } );
108
+ }, { live: true, timing: 'intercept', generation: 'entrants', eventDetails: true } );
109
+ // ---
110
+ }
111
+
112
+ const _await = ( value, callback ) => value instanceof Promise ? value.then( callback ) : callback( value );
@@ -1,10 +1,10 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import init from './index.js';
6
-
7
- /**
8
- * @init
9
- */
10
- init.call( window );
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import init from './index.js';
6
+
7
+ /**
8
+ * @init
9
+ */
10
+ init.call( window );
@@ -1,10 +1,10 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import init from './index.js';
6
-
7
- /**
8
- * @init
9
- */
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import init from './index.js';
6
+
7
+ /**
8
+ * @init
9
+ */
10
10
  init.call( window );
package/src/util.js CHANGED
@@ -1,35 +1,35 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import realdomInit from '@webqit/realdom';
6
- import { _internals } from '@webqit/util/js/index.js';
7
- import { _merge } from '@webqit/util/obj/index.js';
8
-
9
- export const _ = ( ...args ) => _internals( 'oohtml', ...args );
10
-
11
- export function _init( name, $config, $defaults ) {
12
- const _name = name.toUpperCase().replace( '-', '_' );
13
- const window = this, realdom = realdomInit.call( window );
14
- window.webqit || ( window.webqit = {} );
15
- window.webqit.oohtml || ( window.webqit.oohtml = {} );
16
- window.webqit.oohtml.configs || ( window.webqit.oohtml.configs = {} );
17
- window.webqit.oohtml.configs[ _name ] || ( window.webqit.oohtml.configs[ _name ] = {} );
18
- // ---------------------
19
- _merge( 2, window.webqit.oohtml.configs[ _name ], $defaults, $config, realdom.meta( name ).json() );
20
- // ---------------------
21
- return { config: window.webqit.oohtml.configs[ _name ], realdom, window };
22
- }
23
-
24
- export function _compare( a, b, depth = 1, objectSizing = false ) {
25
- if ( depth && typeof a === 'object' && a && typeof b === 'object' && b && ( !objectSizing || Object.keys( a ).length === Object.keys( b ).length ) ) {
26
- for ( let key in a ) {
27
- if ( !_compare( a[ key ], b[ key ], depth - 1, objectSizing ) ) return false;
28
- }
29
- return true;
30
- }
31
- if ( Array.isArray( a ) && Array.isArray( b ) && a.length === b.length ) {
32
- return ( b = b.slice( 0 ).sort() ) && a.slice( 0 ).sort().every( ( valueA, i ) => valueA === b[ i ] );
33
- }
34
- return a === b;
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import realdomInit from '@webqit/realdom';
6
+ import { _internals } from '@webqit/util/js/index.js';
7
+ import { _merge } from '@webqit/util/obj/index.js';
8
+
9
+ export const _ = ( ...args ) => _internals( 'oohtml', ...args );
10
+
11
+ export function _init( name, $config, $defaults ) {
12
+ const _name = name.toUpperCase().replace( '-', '_' );
13
+ const window = this, realdom = realdomInit.call( window );
14
+ window.webqit || ( window.webqit = {} );
15
+ window.webqit.oohtml || ( window.webqit.oohtml = {} );
16
+ window.webqit.oohtml.configs || ( window.webqit.oohtml.configs = {} );
17
+ window.webqit.oohtml.configs[ _name ] || ( window.webqit.oohtml.configs[ _name ] = {} );
18
+ // ---------------------
19
+ _merge( 2, window.webqit.oohtml.configs[ _name ], $defaults, $config, realdom.meta( name ).json() );
20
+ // ---------------------
21
+ return { config: window.webqit.oohtml.configs[ _name ], realdom, window };
22
+ }
23
+
24
+ export function _compare( a, b, depth = 1, objectSizing = false ) {
25
+ if ( depth && typeof a === 'object' && a && typeof b === 'object' && b && ( !objectSizing || Object.keys( a ).length === Object.keys( b ).length ) ) {
26
+ for ( let key in a ) {
27
+ if ( !_compare( a[ key ], b[ key ], depth - 1, objectSizing ) ) return false;
28
+ }
29
+ return true;
30
+ }
31
+ if ( Array.isArray( a ) && Array.isArray( b ) && a.length === b.length ) {
32
+ return ( b = b.slice( 0 ).sort() ) && a.slice( 0 ).sort().every( ( valueA, i ) => valueA === b[ i ] );
33
+ }
34
+ return a === b;
35
35
  };
@@ -1,42 +1,42 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { expect } from 'chai';
6
- import { createDocument } from './index.js';
7
-
8
- describe(`Bindings API`, function() {
9
-
10
- describe( `Basic...`, function() {
11
-
12
- const head = ``;
13
- const body = ``;
14
- const { document, window } = createDocument( head, body );
15
-
16
- it ( `The document object and elements should expose a "bindings" property each...`, async function() {
17
- expect( document ).to.have.property( 'bindings' );
18
- expect( document.body ).to.have.property( 'bindings' );
19
- } );
20
-
21
- it ( `Bindings objects should be observable...`, async function() {
22
- const { webqit: { Observer } } = window;
23
- let idReceived = null;
24
- Observer.observe( document.bindings, records => {
25
- idReceived = records[ 0 ].key;
26
- } );
27
- document.bindings.someKey = 'someValue'; // new
28
- expect( idReceived ).to.eq( 'someKey' );
29
- // -------------
30
- let changes = [];
31
- Observer.observe( document.bindings, records => {
32
- changes.push( ...records );
33
- } );
34
- document.bindings.someKey2 = 'someValue2'; // new
35
- document.bind( { someKey: 'someValue'/* update */, someKey3: 'someValue3'/* new */ } );
36
- expect( changes ).to.an( 'array' ).with.length( 4 ); // (1) sets: someKey2, (2) deletes: someKey2, (3) updates: someKey, (4) sets: someKey3;
37
- } );
38
-
39
- } );
40
-
41
- } );
42
-
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { expect } from 'chai';
6
+ import { createDocument } from './index.js';
7
+
8
+ describe(`Bindings API`, function() {
9
+
10
+ describe( `Basic...`, function() {
11
+
12
+ const head = ``;
13
+ const body = ``;
14
+ const { document, window } = createDocument( head, body );
15
+
16
+ it ( `The document object and elements should expose a "bindings" property each...`, async function() {
17
+ expect( document ).to.have.property( 'bindings' );
18
+ expect( document.body ).to.have.property( 'bindings' );
19
+ } );
20
+
21
+ it ( `Bindings objects should be observable...`, async function() {
22
+ const { webqit: { Observer } } = window;
23
+ let idReceived = null;
24
+ Observer.observe( document.bindings, records => {
25
+ idReceived = records[ 0 ].key;
26
+ } );
27
+ document.bindings.someKey = 'someValue'; // new
28
+ expect( idReceived ).to.eq( 'someKey' );
29
+ // -------------
30
+ let changes = [];
31
+ Observer.observe( document.bindings, records => {
32
+ changes.push( ...records );
33
+ } );
34
+ document.bindings.someKey2 = 'someValue2'; // new
35
+ document.bind( { someKey: 'someValue'/* update */, someKey3: 'someValue3'/* new */ } );
36
+ expect( changes ).to.an( 'array' ).with.length( 4 ); // (1) sets: someKey2, (2) deletes: someKey2, (3) updates: someKey, (4) sets: someKey3;
37
+ } );
38
+
39
+ } );
40
+
41
+ } );
42
+