@webqit/oohtml 4.3.8 → 4.3.9

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.3.8",
17
+ "version": "4.3.9",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -22,9 +22,9 @@ export default class HTMLImportsContext extends DOMContext {
22
22
  request.detail = detail;
23
23
  request.targetContext = Infinity;
24
24
  } else if ( detail?.startsWith( '@' ) ) {
25
- const [ targetContext, ...detail ] = detail.slice( 1 ).split( /(?<=\w)(?=\/|#)/ ).map( s => s.trim() );
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
  }
@@ -33,11 +33,14 @@ export default class HTMLImportsContext extends DOMContext {
33
33
  * @localModules
34
34
  */
35
35
  get localModules() { return getDefs( this.host ); }
36
+ get inheritedModules() { return this.#inheritedModules; }
37
+ #inheritedModules = {};
38
+
36
39
 
37
40
  /**
38
41
  * @handle()
39
42
  */
40
- handle( event ) {
43
+ handle__( event ) {
41
44
  const { window: { webqit: { Observer } } } = env;
42
45
  // Any existing event.meta.controller? Abort!
43
46
  event.meta.controller?.abort();
@@ -55,27 +58,22 @@ export default class HTMLImportsContext extends DOMContext {
55
58
  const _result = Array.isArray( result ) ? result : result.value;
56
59
  const _isValidLocalResult = Array.isArray( result ) ? result.length : result.value;
57
60
  if ( !_isValidLocalResult && this.host.isConnected === false ) return; // Subtree is being disposed
58
- if ( _isValidLocalResult || !this.contextModules ) {
61
+ if ( _isValidLocalResult || !this.#inheritedModules ) {
59
62
  event._isValidLocalResult = _isValidLocalResult;
60
63
  return event.respondWith( _result );
61
64
  }
62
65
  // This superModules binding is automatically aborted by the injected control.signal; see below
63
- return Observer.reduce( this.contextModules, path, Observer.get, result => {
66
+ return Observer.reduce( this.#inheritedModules, path, Observer.get, result => {
64
67
  event._currentSource = 'context';
65
68
  return event.respondWith( Array.isArray( result ) ? result : result.value );
66
69
  }, { ...options, signal } );
67
70
  }, { lifecycleSignals: true, ...options } );
68
71
  }
69
72
 
70
- /**
71
- * @unsubscribed()
72
- */
73
- unsubscribed( event ) { event.meta.controller?.abort(); }
74
-
75
73
  /**
76
74
  * @startRealtime()
77
75
  */
78
- realtimeSources( host ) {
76
+ realtimeSources__( host ) {
79
77
  this.host = host;
80
78
  // ----------------
81
79
  const update = () => {
@@ -87,35 +85,100 @@ export default class HTMLImportsContext extends DOMContext {
87
85
  // ----------------
88
86
  const $config = this.configs.HTML_IMPORTS;
89
87
  if ( !this.host.matches || !$config.attr.importscontext ) return;
90
- // Any existing this.refdSourceController? Abort!
91
- this.refdSourceController?.disconnect();
92
88
  const realdom = this.host.ownerDocument.defaultView.webqit.realdom;
93
89
  let prevRef;
94
- this.refdSourceController = realdom.realtime( this.host ).attr( $config.attr.importscontext, ( record, { signal } ) => {
90
+ this.controller3 = realdom.realtime( this.host ).attr( $config.attr.importscontext, ( record, { signal } ) => {
95
91
  if (record.value === prevRef) return;
96
92
  prevRef = record.value;
97
- // No importscontext attr set. But we're still watching
98
- if ( !record.value ) {
99
- this.contextModules = undefined;
100
- return update();
101
- }
102
93
  // This superModules contextrequest is automatically aborted by the injected signal below
103
- const request = { ...this.constructor.createRequest( record.value.trim() ), live: true, signal, diff: true };
94
+ const request = { ...this.constructor.createRequest( record.value?.trim() ), live: true, signal, diff: true };
104
95
  this.host.parentNode[ this.configs.CONTEXT_API.api.contexts ].request( request, response => {
105
- this.contextModules = !( response && Object.getPrototypeOf( response ) ) ? response : getDefs( response );
96
+ this.#inheritedModules = !( response && Object.getPrototypeOf( response ) ) ? response : getDefs( response );
106
97
  update();
107
98
  } );
108
99
  }, { live: true, timing: 'sync', lifecycleSignals: true } );
109
100
  }
110
101
 
102
+ /**
103
+ * @handle()
104
+ */
105
+
106
+ handle( event ) {
107
+ const { window: { webqit: { Observer } } } = env;
108
+ // Any existing event.meta.controller? Abort!
109
+ event.meta.controller?.abort();
110
+ // Parse and translate detail
111
+ let path = ( event.detail || '' ).split( /\/|(?<=\w)(?=#)/g ).map( x => x.trim() ).filter( x => x );
112
+ if ( !path.length ) return event.respondWith();
113
+ path = path.join( `/${ this.configs.HTML_IMPORTS.api.defs }/` )?.split( '/' ).map( x => x === '*' ? Infinity : x ) || [];
114
+ // We'll now fulfill request
115
+ const options = { live: event.live, signal: event.signal, descripted: true };
116
+ event.meta.controller = Observer.reduce( this.#modules, path, Observer.get, ( m ) => {
117
+ if ( Array.isArray( m ) ) {
118
+ // Paths with wildcard
119
+ for ( const n of m ) {
120
+ event.respondWith( n );
121
+ }
122
+ } else event.respondWith( m.value );
123
+ }, options );
124
+ }
125
+
126
+ /**
127
+ * @unsubscribed()
128
+ */
129
+ unsubscribed( event ) { event.meta.controller?.abort(); }
130
+
111
131
  /**
112
132
  * @initialize()
113
133
  */
134
+ #modules;
135
+ #controller1;
136
+ #controller2;
114
137
  initialize( host ) {
138
+ this.host = host;
139
+ const { window: { webqit: { Observer } } } = env;
140
+ // ----------------
141
+ // Observe local
142
+ this.#modules = Object.assign( {}, this.localModules );
143
+ this.#controller1?.abort();
144
+ this.#controller1 = Observer.observe( this.localModules, ( mutations ) => {
145
+ for ( const m of mutations ) {
146
+ if ( m.type === 'delete' ) {
147
+ if ( this.inheritedModules && Observer.has( this.inheritedModules, m.key ) ) {
148
+ Observer.set( this.#modules, m.key, Observer.get( this.inheritedModules, m.key ) );
149
+ } else Observer.deleteProperty( this.#modules, m.key );
150
+ } else Observer.set( this.#modules, m.key, m.value );
151
+ }
152
+ }, { timing: 'sync' } );
153
+ // ----------------
115
154
  // If host has importscontext attr, compute that
116
- this.realtimeSources( host );
117
- // Now, listen for contextrequest and contextclaim events
118
- // And process own claim
155
+ const $config = this.configs.HTML_IMPORTS;
156
+ if ( this.host.matches && $config.attr.importscontext ) {
157
+ const realdom = this.host.ownerDocument.defaultView.webqit.realdom;
158
+ let prevRef;
159
+ this.#controller2?.disconnect();
160
+ this.#controller2 = realdom.realtime( this.host ).attr( $config.attr.importscontext, ( record, { signal } ) => {
161
+ const moduleRef = ( record.value || '' ).trim();
162
+ if ( moduleRef === prevRef ) return;
163
+ prevRef = moduleRef;
164
+ // This superModules contextrequest is automatically aborted by the injected signal below
165
+ const request = { ...this.constructor.createRequest( moduleRef ? `${moduleRef}/*` : '*' ), live: true, signal, diff: true };
166
+ this.host.parentNode[ this.configs.CONTEXT_API.api.contexts ].request( request, ( m ) => {
167
+ if ( m.type === 'delete' ) {
168
+ Reflect.deleteProperty( this.inheritedModules, m.key );
169
+ if ( !Observer.has( this.localModules, m.key ) ) {
170
+ Observer.deleteProperty( this.#modules, m.key );
171
+ }
172
+ } else {
173
+ Reflect.set( this.inheritedModules, m.key, m.value );
174
+ if ( !Observer.has( this.localModules, m.key ) ) {
175
+ Observer.set( this.#modules, m.key, m.value );
176
+ }
177
+ }
178
+ } );
179
+ }, { live: true, timing: 'sync', lifecycleSignals: true } );
180
+ }
181
+ // ----------------
119
182
  return super.initialize( host );
120
183
  }
121
184
 
@@ -124,7 +187,8 @@ export default class HTMLImportsContext extends DOMContext {
124
187
  */
125
188
  dispose( host ) {
126
189
  // Stop listening for sources
127
- this.refdSourceController?.disconnect();
190
+ this.#controller1?.abort();
191
+ this.#controller2?.disconnect();
128
192
  // Now, stop listening for contextrequest and contextclaim events
129
193
  // And relinquish own subscribers to owner context
130
194
  return super.dispose( host );
@@ -186,6 +186,7 @@ describe(`HTML Modules`, function() {
186
186
  // -------
187
187
  scoped.remove();
188
188
  expect( defsObjs ).to.have.length( 3 );
189
+
189
190
  expect( defsObjs[ 2 ] ).to.have.property( 'scoped', false );
190
191
  // -------
191
192
  document.body.appendChild( scoped );