@webqit/oohtml 4.5.8 → 4.5.10

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": "4.5.8",
17
+ "version": "4.5.10",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -219,7 +219,6 @@ function compileInlineBindings( config, str ) {
219
219
  let $iteratee__ = ${ iteratee };
220
220
  let $import__ = this.${ config.HTML_IMPORTS.api.import }( ${ importSpec.trim() }, true );
221
221
  this.$oohtml_internal_databinding_signals?.push( $import__ );
222
-
223
222
  if ( $import__.value && $iteratee__ ) {
224
223
  let $existing__ = new Map;
225
224
  [ ...this.children ].filter( el => el.matches( '[${ config.attr.itemIndex }]' ) ).forEach( x => {
@@ -16,60 +16,60 @@ export default class HTMLImportsContext extends DOMContext {
16
16
  /**
17
17
  * @createRequest
18
18
  */
19
- static createRequest( detail = null ) {
19
+ static createRequest(detail = null) {
20
20
  const request = super.createRequest();
21
- if ( detail?.startsWith( '/' ) ) {
21
+ if (detail?.startsWith('/')) {
22
22
  request.detail = detail;
23
23
  request.targetContext = Infinity;
24
- } else if ( detail?.startsWith( '@' ) ) {
25
- const [ targetContext, ..._detail ] = detail.slice( 1 ).split( /(?<=\w)(?=\/|#)/ ).map( s => s.trim() );
24
+ } else if (detail?.startsWith('@')) {
25
+ const [targetContext, ..._detail] = detail.slice(1).split(/(?<=\w)(?=\/|#)/).map(s => s.trim());
26
26
  request.targetContext = targetContext;
27
- request.detail = _detail.join( '' );
27
+ request.detail = _detail.join('');
28
28
  } else { request.detail = detail; }
29
29
  return request;
30
30
  }
31
-
31
+
32
32
  /**
33
33
  * @localModules
34
34
  */
35
- get localModules() { return getDefs( this.host ); }
35
+ get localModules() { return getDefs(this.host); }
36
36
  get inheritedModules() { return this.#inheritedModules; }
37
37
  #inheritedModules = {};
38
38
 
39
39
  /**
40
40
  * @handle()
41
41
  */
42
-
43
- handle( event ) {
42
+
43
+ handle(event) {
44
44
  const { window: { webqit: { Observer } } } = env;
45
45
  // Any existing event.meta.controller? Abort!
46
46
  event.meta.controller?.abort();
47
47
  // Parse and translate detail
48
- let path = ( event.detail || '' ).split( /\/|(?<=\w)(?=#)/g ).map( x => x.trim() ).filter( x => x );
49
- if ( !path.length ) return event.respondWith();
50
- path = path.join( `/${ this.configs.HTML_IMPORTS.api.defs }/` )?.split( '/' ).map( x => x === '*' ? Infinity : x ) || [];
48
+ let path = (event.detail || '').split(/\/|(?<=\w)(?=#)/g).map(x => x.trim()).filter(x => x);
49
+ if (!path.length) return event.respondWith();
50
+ path = path.join(`/${this.configs.HTML_IMPORTS.api.defs}/`)?.split('/').map(x => x === '*' ? Infinity : x) || [];
51
51
  // We'll now fulfill request
52
- const options = { live: event.live, signal: event.signal, descripted: true };
53
- event.meta.controller = Observer.reduce( this.#modules, path, Observer.get, ( m ) => {
54
- if ( Array.isArray( m ) ) {
55
- if ( !m.length ) {
52
+ const options = { live: event.live, sig_nal: event.signal, descripted: true };
53
+ event.meta.controller = Observer.reduce(this.#modules, path, Observer.get, (m) => {
54
+ if (Array.isArray(m)) {
55
+ if (!m.length) {
56
56
  event.respondWith();
57
57
  return;
58
58
  }
59
59
  // Paths with wildcard
60
- for ( const n of m ) {
61
- event.respondWith( n );
60
+ for (const n of m) {
61
+ event.respondWith(n);
62
62
  }
63
63
  } else {
64
- event.respondWith( m.value );
64
+ event.respondWith(m.value);
65
65
  }
66
- }, options );
66
+ }, options);
67
67
  }
68
68
 
69
69
  /**
70
70
  * @unsubscribed()
71
71
  */
72
- unsubscribed( event ) { event.meta.controller?.abort(); }
72
+ unsubscribed(event) { event.meta.controller?.abort(); }
73
73
 
74
74
  /**
75
75
  * @initialize()
@@ -77,21 +77,21 @@ export default class HTMLImportsContext extends DOMContext {
77
77
  #modules;
78
78
  #controller1;
79
79
  #controller2;
80
- initialize( host ) {
80
+ initialize(host) {
81
81
  this.host = host;
82
82
  const { window: { webqit: { Observer } } } = env;
83
83
  // ----------------
84
84
  // Resolve
85
85
  const resolve = () => {
86
86
  for (const key of new Set([...Object.keys(this.localModules), ...Object.keys(this.inheritedModules), ...Object.keys(this.#modules)])) {
87
- if ( !Observer.has( this.localModules, key ) && !Observer.has( this.inheritedModules, key ) ) {
88
- Observer.deleteProperty( this.#modules, key );
89
- } else if (key === '#' && Observer.has( this.localModules, key ) && Observer.has( this.inheritedModules, key ) ) {
90
- Observer.set( this.#modules, key, [...Observer.get( this.localModules, key ), ...Observer.get( this.inheritedModules, key )] );
87
+ if (!Observer.has(this.localModules, key) && !Observer.has(this.inheritedModules, key)) {
88
+ Observer.deleteProperty(this.#modules, key);
89
+ } else if (key === '#' && Observer.has(this.localModules, key) && Observer.has(this.inheritedModules, key)) {
90
+ Observer.set(this.#modules, key, [...Observer.get(this.localModules, key), ...Observer.get(this.inheritedModules, key)]);
91
91
  } else {
92
- const _module = Observer.get( this.localModules, key ) || Observer.get( this.inheritedModules, key );
93
- if ( Observer.get( this.#modules, key ) !== _module ) {
94
- Observer.set( this.#modules, key, _module );
92
+ const _module = Observer.get(this.localModules, key) || Observer.get(this.inheritedModules, key);
93
+ if (Observer.get(this.#modules, key) !== _module) {
94
+ Observer.set(this.#modules, key, _module);
95
95
  }
96
96
  }
97
97
  }
@@ -100,53 +100,52 @@ export default class HTMLImportsContext extends DOMContext {
100
100
  // Observe local
101
101
  this.#modules = { ...this.localModules };
102
102
  this.#controller1?.abort();
103
- this.#controller1 = Observer.observe( this.localModules, () => resolve('local'), { timing: 'sync' } );
103
+ this.#controller1 = Observer.observe(this.localModules, () => resolve('local'), { timing: 'sync' });
104
104
  // ----------------
105
105
  // If host has importscontext attr, compute that
106
106
  const $config = this.configs.HTML_IMPORTS;
107
- if ( this.host.matches && $config.attr.importscontext ) {
107
+ if (this.host.matches && $config.attr.importscontext) {
108
108
  const realdom = this.host.ownerDocument.defaultView.webqit.realdom;
109
109
  let prevRef;
110
110
  this.#controller2?.disconnect();
111
- this.#controller2 = realdom.realtime( this.host ).attr( $config.attr.importscontext, ( record, { signal } ) => {
112
- const moduleRef = ( record.value || '' ).trim();
113
- if ( moduleRef === prevRef ) return;
111
+ this.#controller2 = realdom.realtime(this.host).attr($config.attr.importscontext, (record, { signal }) => {
112
+ const moduleRef = (record.value || '').trim();
114
113
  prevRef = moduleRef;
115
114
  // This superModules contextrequest is automatically aborted by the injected signal below
116
115
  this.#inheritedModules = {};
117
- const request = { ...this.constructor.createRequest( moduleRef ? `${moduleRef}/*` : '*' ), live: true, signal, diff: true };
118
- this.host.parentNode[ this.configs.CONTEXT_API.api.contexts ].request( request, ( m ) => {
119
- if ( !m ) {
116
+ const request = { ...this.constructor.createRequest(moduleRef ? `${moduleRef}/*` : '*'), live: true, signal, diff: true };
117
+ this.host.parentNode[this.configs.CONTEXT_API.api.contexts].request(request, (m) => {
118
+ if (!m) {
120
119
  this.#inheritedModules = {};
121
120
  resolve('inherited');
122
- } else if ( m.type === 'delete' ) {
121
+ } else if (m.type === 'delete') {
123
122
  delete this.#inheritedModules[m.key];
124
- if ( !Reflect.has( this.localModules, m.key ) ) {
125
- Observer.deleteProperty( this.#modules, m.key );
123
+ if (!Reflect.has(this.localModules, m.key)) {
124
+ Observer.deleteProperty(this.#modules, m.key);
126
125
  }
127
126
  } else {
128
127
  this.#inheritedModules[m.key] = m.value;
129
- if ( !Reflect.has( this.localModules, m.key ) && Reflect.get( this.#modules, m.key ) !== m.value ) {
130
- Observer.set( this.#modules, m.key, m.value );
128
+ if (!Reflect.has(this.localModules, m.key) && Reflect.get(this.#modules, m.key) !== m.value) {
129
+ Observer.set(this.#modules, m.key, m.value);
131
130
  }
132
131
  }
133
- } );
132
+ });
134
133
  resolve('inherited');
135
- }, { live: true, timing: 'sync', oldValue: true, lifecycleSignals: true } );
134
+ }, { live: true, timing: 'sync', oldValue: true, lifecycleSignals: true });
136
135
  }
137
136
  // ----------------
138
- return super.initialize( host );
137
+ return super.initialize(host);
139
138
  }
140
-
139
+
141
140
  /**
142
141
  * @dispose()
143
142
  */
144
- dispose( host ) {
143
+ dispose(host) {
145
144
  // Stop listening for sources
146
145
  this.#controller1?.abort();
147
146
  this.#controller2?.disconnect();
148
147
  // Now, stop listening for contextrequest and contextclaim events
149
148
  // And relinquish own subscribers to owner context
150
- return super.dispose( host );
149
+ return super.dispose(host);
151
150
  }
152
151
  }
@@ -10,37 +10,37 @@ export default class HTMLModule {
10
10
  /**
11
11
  * @instance
12
12
  */
13
- static instance( host ) {
14
- return _wq( host ).get( 'defsmanager::instance' ) || new this( host );
13
+ static instance(host) {
14
+ return _wq(host).get('defsmanager::instance') || new this(host);
15
15
  }
16
16
 
17
17
  /**
18
18
  * @constructor
19
19
  */
20
- constructor( host, parent = null, level = 0 ) {
20
+ constructor(host, parent = null, level = 0) {
21
21
  const { window } = env, { webqit: { realdom, oohtml: { configs } } } = window;
22
- _wq( host ).get( `defsmanager::instance` )?.dispose();
23
- _wq( host ).set( `defsmanager::instance`, this );
22
+ _wq(host).get(`defsmanager::instance`)?.dispose();
23
+ _wq(host).set(`defsmanager::instance`, this);
24
24
  this.window = window;
25
25
  this.host = host;
26
26
  this.config = configs.HTML_IMPORTS;
27
27
  this.parent = parent;
28
28
  this.level = level;
29
- this.defs = getDefs( this.host );
30
- this.defId = ( this.host.getAttribute( this.config.attr.def ) || '' ).trim();
31
- this.validateDefId( this.defId );
29
+ this.defs = getDefs(this.host);
30
+ this.defId = (this.host.getAttribute(this.config.attr.def) || '').trim();
31
+ this.validateDefId(this.defId);
32
32
  // ----------
33
- this.realtimeA = realdom.realtime( this.host.content ).children( record => {
34
- this.expose( record.entrants, true );
35
- this.expose( record.exits, false );
36
- }, { live: true, timing: 'sync' } );
33
+ this.realtimeA = realdom.realtime(this.host.content).children(record => {
34
+ this.expose(record.exits, false); // Must come first
35
+ this.expose(record.entrants, true);
36
+ }, { live: true, timing: 'sync' });
37
37
  // ----------
38
- this.realtimeB = realdom.realtime( this.host ).attr( [ 'src', 'loading' ], ( ...args ) => this.evaluateLoading( ...args ), {
38
+ this.realtimeB = realdom.realtime(this.host).attr(['src', 'loading'], (...args) => this.evaluateLoading(...args), {
39
39
  live: true,
40
40
  atomic: true,
41
41
  timing: 'sync',
42
42
  lifecycleSignals: true
43
- } );
43
+ });
44
44
  // ----------
45
45
  this.realtimeC = this.evalInheritance();
46
46
  // ----------
@@ -53,9 +53,9 @@ export default class HTMLModule {
53
53
  *
54
54
  * @returns Void
55
55
  */
56
- validateDefId( defId ) {
57
- if ( [ '@', '/', '*', '#' ].some( token => defId.includes( token ) ) ) {
58
- throw new Error( `The export ID "${ defId }" contains an invalid character.` );
56
+ validateDefId(defId) {
57
+ if (['@', '/', '*', '#'].some(token => defId.includes(token))) {
58
+ throw new Error(`The export ID "${defId}" contains an invalid character.`);
59
59
  }
60
60
  }
61
61
 
@@ -67,39 +67,39 @@ export default class HTMLModule {
67
67
  *
68
68
  * @returns Void
69
69
  */
70
- expose( entries, isConnected ) {
70
+ expose(entries, isConnected) {
71
71
  const { window } = env, { webqit: { Observer } } = window;
72
- let dirty, allFragments = this.defs[ '#' ] || [];
73
- entries.forEach( entry => {
74
- if ( !entry || entry.nodeType !== 1 ) return;
75
- const isTemplate = entry.matches( this.config.templateSelector );
76
- const defId = ( entry.getAttribute( isTemplate ? this.config.attr.def : this.config.attr.fragmentdef ) || '' ).trim();
77
- if ( isConnected ) {
78
- if ( isTemplate && defId ) {
79
- new HTMLModule( entry, this.host, this.level + 1 );
72
+ let dirty, allFragments = this.defs['#'] || [];
73
+ entries.forEach(entry => {
74
+ if (!entry || entry.nodeType !== 1) return;
75
+ const isTemplate = entry.matches(this.config.templateSelector);
76
+ const defId = (entry.getAttribute(isTemplate ? this.config.attr.def : this.config.attr.fragmentdef) || '').trim();
77
+ if (isConnected) {
78
+ if (isTemplate && defId) {
79
+ new HTMLModule(entry, this.host, this.level + 1);
80
80
  } else {
81
- allFragments.push( entry );
81
+ allFragments.push(entry);
82
82
  dirty = true;
83
- if ( typeof requestIdleCallback === 'function' ) {
84
- requestIdleCallback( () => {
85
- this.config.idleCompilers?.forEach( callback => callback.call( this.window, entry ) );
86
- } );
83
+ if (typeof requestIdleCallback === 'function') {
84
+ requestIdleCallback(() => {
85
+ this.config.idleCompilers?.forEach(callback => callback.call(this.window, entry));
86
+ });
87
87
  }
88
88
  }
89
- if ( defId ) {
90
- this.validateDefId( defId );
91
- Observer.set( this.defs, ( !isTemplate && '#' || '' ) + defId, entry );
89
+ if (defId) {
90
+ this.validateDefId(defId);
91
+ Observer.set(this.defs, (!isTemplate && '#' || '') + defId, entry);
92
92
  }
93
93
  } else {
94
- if ( isTemplate && defId ) { HTMLModule.instance( entry ).dispose(); }
94
+ if (isTemplate && defId) { HTMLModule.instance(entry).dispose(); }
95
95
  else {
96
- allFragments = allFragments.filter( x => x !== entry );
96
+ allFragments = allFragments.filter(x => x !== entry);
97
97
  dirty = true;
98
98
  }
99
- if ( defId ) Observer.deleteProperty( this.defs, ( !isTemplate && '#' || '' ) + defId );
99
+ if (defId) Observer.deleteProperty(this.defs, (!isTemplate && '#' || '') + defId);
100
100
  }
101
- } );
102
- if ( dirty ) Observer.set( this.defs, '#', allFragments );
101
+ });
102
+ if (dirty) Observer.set(this.defs, '#', allFragments);
103
103
  }
104
104
 
105
105
  /**
@@ -109,23 +109,23 @@ export default class HTMLModule {
109
109
  *
110
110
  * @returns Void
111
111
  */
112
- evaluateLoading( [ record1, record2 ], { signal } ) {
112
+ evaluateLoading([record1, record2], { signal }) {
113
113
  const { window: { webqit: { Observer } } } = env;
114
- const src = ( record1.value || '' ).trim();
115
- if ( !src ) return;
114
+ const src = (record1.value || '').trim();
115
+ if (!src) return;
116
116
  let $loadingPromise, loadingPromise = promise => {
117
- if ( !promise ) return $loadingPromise; // Get
118
- $loadingPromise = promise.then( () => interception.remove() ); // Set
117
+ if (!promise) return $loadingPromise; // Get
118
+ $loadingPromise = promise.then(() => interception.remove()); // Set
119
119
  };
120
- const loading = ( record2.value || '' ).trim();
121
- const interception = Observer.intercept( this.defs, 'get', async ( descriptor, recieved, next ) => {
122
- if ( loading === 'lazy' ) { loadingPromise( this.load( src, true ) ); }
120
+ const loading = (record2.value || '').trim();
121
+ const interception = Observer.intercept(this.defs, 'get', async (descriptor, recieved, next) => {
122
+ if (loading === 'lazy') { loadingPromise(this.load(src, true)); }
123
123
  await loadingPromise();
124
124
  return next();
125
- }, { signal } );
126
- if ( loading !== 'lazy' ) { loadingPromise( this.load( src ) ); }
125
+ }, { signal });
126
+ if (loading !== 'lazy') { loadingPromise(this.load(src)); }
127
127
  }
128
-
128
+
129
129
  /**
130
130
  * Fetches a module's "src".
131
131
  *
@@ -135,33 +135,33 @@ export default class HTMLModule {
135
135
  */
136
136
  #fetchedURLs = new Set;
137
137
  #fetchInFlight;
138
- load( src ) {
138
+ load(src) {
139
139
  const { window } = env;
140
- if ( this.#fetchedURLs.has( src ) ) {
140
+ if (this.#fetchedURLs.has(src)) {
141
141
  // Cache busting is needed to
142
142
  return Promise.resolve();
143
143
  }
144
- this.#fetchedURLs.add( src );
145
- if ( this.#fetchedURLs.size === 1 && this.host.content.children.length ) {
144
+ this.#fetchedURLs.add(src);
145
+ if (this.#fetchedURLs.size === 1 && this.host.content.children.length) {
146
146
  return Promise.resolve();
147
147
  }
148
148
  // Ongoing request?
149
149
  this.#fetchInFlight?.controller.abort();
150
150
  // The promise
151
151
  const controller = new AbortController();
152
- const fire = ( type, detail ) => this.host.dispatchEvent( new window.CustomEvent( type, { detail } ) );
153
- const request = window.fetch( src, { signal: controller.signal, element: this.host } ).then( response => {
154
- return response.ok ? response.text() : Promise.reject( response.statusText );
155
- } ).then( content => {
152
+ const fire = (type, detail) => this.host.dispatchEvent(new window.CustomEvent(type, { detail }));
153
+ const request = window.fetch(src, { signal: controller.signal, element: this.host }).then(response => {
154
+ return response.ok ? response.text() : Promise.reject(response.statusText);
155
+ }).then(content => {
156
156
  this.host.innerHTML = content.trim(); // IMPORTANT: .trim()
157
- fire( 'load' );
157
+ fire('load');
158
158
  return this.host;
159
- } ).catch( e => {
160
- console.error( `Error fetching the bundle at "${ src }": ${ e.message }` );
159
+ }).catch(e => {
160
+ console.error(`Error fetching the bundle at "${src}": ${e.message}`);
161
161
  this.#fetchInFlight = null;
162
- fire( 'loaderror' );
162
+ fire('loaderror');
163
163
  return this.host;
164
- } );
164
+ });
165
165
  this.#fetchInFlight = { request, controller };
166
166
  return request;
167
167
  }
@@ -171,32 +171,32 @@ export default class HTMLModule {
171
171
  *
172
172
  * @returns Void|AbortController
173
173
  */
174
- evalInheritance( ) {
175
- if ( !this.parent ) return [];
174
+ evalInheritance() {
175
+ if (!this.parent) return [];
176
176
  const { window: { webqit: { Observer } } } = env;
177
- let extendedId = ( this.host.getAttribute( this.config.attr.extends ) || '' ).trim();
178
- let inheritedIds = ( this.host.getAttribute( this.config.attr.inherits ) || '' ).trim().split( ' ' ).map( id => id.trim() ).filter( x => x );
177
+ let extendedId = (this.host.getAttribute(this.config.attr.extends) || '').trim();
178
+ let inheritedIds = (this.host.getAttribute(this.config.attr.inherits) || '').trim().split(' ').map(id => id.trim()).filter(x => x);
179
179
  const handleInherited = records => {
180
- records.forEach( record => {
181
- if ( Observer.get( this.defs, record.key ) !== record.oldValue ) return;
182
- if ( [ 'get'/*initial get*/, 'set', 'def' ].includes( record.type ) ) {
183
- Observer[ record.type.replace( 'get', 'set' ) ]( this.defs, record.key, record.value );
184
- } else if ( record.type === 'delete' ) {
185
- Observer.deleteProperty( this.defs, record.key );
180
+ records.forEach(record => {
181
+ if (Observer.get(this.defs, record.key) !== record.oldValue) return;
182
+ if (['get'/*initial get*/, 'set', 'def'].includes(record.type)) {
183
+ Observer[record.type.replace('get', 'set')](this.defs, record.key, record.value);
184
+ } else if (record.type === 'delete') {
185
+ Observer.deleteProperty(this.defs, record.key);
186
186
  }
187
- } );
187
+ });
188
188
  };
189
189
  const realtimes = [];
190
- const parentDefsObj = getDefs( this.parent );
191
- if ( extendedId ) {
192
- realtimes.push( Observer.reduce( parentDefsObj, [ extendedId, this.config.api.defs, Infinity ], Observer.get, handleInherited, { live: true } ) );
190
+ const parentDefsObj = getDefs(this.parent);
191
+ if (extendedId) {
192
+ realtimes.push(Observer.reduce(parentDefsObj, [extendedId, this.config.api.defs, Infinity], Observer.get, handleInherited, { live: true }));
193
193
  }
194
- if ( inheritedIds.length ) {
195
- realtimes.push( Observer.get( parentDefsObj, inheritedIds.includes( '*' ) ? Infinity : inheritedIds, handleInherited, { live: true } ) );
194
+ if (inheritedIds.length) {
195
+ realtimes.push(Observer.get(parentDefsObj, inheritedIds.includes('*') ? Infinity : inheritedIds, handleInherited, { live: true }));
196
196
  }
197
197
  return realtimes;
198
198
  }
199
-
199
+
200
200
  /**
201
201
  * Disposes the instance and its processes.
202
202
  *
@@ -205,10 +205,10 @@ export default class HTMLModule {
205
205
  dispose() {
206
206
  this.realtimeA.disconnect();
207
207
  this.realtimeB.disconnect();
208
- this.realtimeC.forEach( r => ( r instanceof Promise ? r.then( r => r.abort() ) : r.abort() ) );
209
- Object.entries( this.defs ).forEach( ( [ key, entry ] ) => {
210
- if ( key.startsWith( '#' ) ) return;
211
- HTMLModule.instance( entry ).dispose();
212
- } );
208
+ this.realtimeC.forEach(r => (r instanceof Promise ? r.then(r => r.abort()) : r.abort()));
209
+ Object.entries(this.defs).forEach(([key, entry]) => {
210
+ if (key.startsWith('#')) return;
211
+ HTMLModule.instance(entry).dispose();
212
+ });
213
213
  }
214
214
  }