@webqit/oohtml 4.1.14 → 4.2.0

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.1.14",
17
+ "version": "4.2.0",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -39,8 +39,8 @@
39
39
  "postpublish": "git push && git push --tags"
40
40
  },
41
41
  "dependencies": {
42
- "@webqit/quantum-js": "^4.5.8",
43
- "@webqit/realdom": "^2.1.28",
42
+ "@webqit/quantum-js": "^4.5.11",
43
+ "@webqit/realdom": "^2.1.30",
44
44
  "@webqit/util": "^0.8.11"
45
45
  },
46
46
  "devDependencies": {
@@ -54,8 +54,8 @@ function createDynamicScope( config, root ) {
54
54
  const scope = Object.create( null ), abortController = new AbortController;
55
55
  scope[ '$exec__' ] = ( target, prop, ...args ) => {
56
56
  const exec = () => {
57
- try { target[ prop ]( ...args ); }
58
- catch( e ) { console.error( `${ e.message } at ${ e.cause }` ); }
57
+ target[ prop ]( ...args );
58
+ try { } catch( e ) { console.error( `${ e.message } at ${ e.cause }` ); }
59
59
  };
60
60
  realdom.schedule( 'write', exec );
61
61
  };
@@ -177,20 +177,24 @@ function compileInlineBindings( config, str ) {
177
177
  const [ left, right ] = _splitOuter( str, ':' ).map( x => x.trim() );
178
178
  const directive = left[ 0 ], param = left.slice( 1 ).trim();
179
179
  const arg = `(${ right })`, $arg = `(${ arg } ?? '')`;
180
+ // CSS
180
181
  if ( directive === '&' ) {
181
182
  if ( param.startsWith( '--' ) ) return `$exec__(this.style, 'setProperty', "${ escDouble( param ) }", ${ $arg });`;
182
183
  return `$assign__(this.style, "${ escDouble( param ) }", ${ $arg });`;
183
184
  }
185
+ // Class list
184
186
  if ( directive === '%' ) return `$exec__(this.classList, 'toggle', "${ escDouble( param ) }", !!${ arg });`;
187
+ // Attribute
185
188
  if ( directive === '~' ) {
186
189
  if ( param.startsWith( '?' ) ) return `$exec__(this, 'toggleAttribute', "${ escDouble( param.substring( 1 ).trim() ) }", !!${ arg });`;
187
190
  return `$exec__(this, 'setAttribute', "${ escDouble( param ) }", ${ $arg });`;
188
191
  }
189
- if ( directive === '@' ) {
192
+ // Structure
193
+ if ( directive === '#' ) {
190
194
  if ( validation[ param ] ) throw new Error( `Duplicate binding: ${ left }.` );
191
195
  validation[ param ] = true;
192
196
  if ( param === 'text' ) return `$assign__(this, 'textContent', ${ $arg });`;
193
- if ( param === 'html' ) return `$exec__(this, 'setHTML', ${ $arg });`;
197
+ if ( param === 'html' ) return `$exec__(this, 'setHTMLUnsafe', ${ $arg });`;
194
198
  if ( param === 'items' ) {
195
199
  const [ iterationSpec, importSpec ] = _splitOuter( right, '/' );
196
200
  if ( !importSpec ) throw new Error( `Invalid ${ directive }items spec: ${ str }; no import specifier.` );
@@ -235,14 +239,20 @@ function compileInlineBindings( config, str ) {
235
239
  $existing__.clear();
236
240
  }`;
237
241
  }
238
- // Treat other "@" directives as events
242
+ }
243
+ // Events
244
+ if ( directive === '@' ) {
239
245
  return `
240
- const handler = () => ${ arg };
246
+ const handler = event => ${ right.startsWith('{') ? right : arg };
241
247
  this.addEventListener( '${ param }', handler );
242
248
  const abort = () => this.removeEventListener( '${ param }', handler );
243
249
  this.$oohtml_internal_databinding_signals?.push( { abort } );
244
250
  `;
245
251
  }
252
+ // Functions
253
+ if ( directive === '$' ) {
254
+ return `$exec__(this, '${ param }', ${ arg });`;
255
+ }
246
256
  if ( str.trim() ) throw new Error( `Invalid binding: ${ str }.` );
247
257
  } ).join( `\n` );
248
258
  const { webqit: { QuantumModule } } = this;
@@ -297,7 +297,7 @@ function realtime( config ) {
297
297
  } else {
298
298
  const newAttrValue = _( entry, 'attrOriginals' ).get( attrName );// oldValue.split( ' ' ).map( lid => ( lid = lid.trim() ) && $lidUtil.uuidToLidref( lid ) ).join( ' ' );
299
299
  entry.setAttribute( attrName, newAttrValue );
300
- _( namespaceObj ).get( 'idrefs' ).delete( entry );
300
+ _( namespaceObj ).get( 'idrefs' )?.delete( entry );
301
301
  }
302
302
  } );
303
303
  };
@@ -75,7 +75,7 @@ async function execute( config, execHash ) {
75
75
  if ( !_( varScope ).has( 'scriptEnv' ) ) {
76
76
  _( varScope ).set( 'scriptEnv', Object.create( null ) );
77
77
  }
78
- const state = ( await compiledScript.bind( thisContext, _( varScope ).get( 'scriptEnv' ) ) ).execute();
78
+ const state = await ( await compiledScript.bind( thisContext, _( varScope ).get( 'scriptEnv' ) ) ).execute();
79
79
  if ( script.quantum ) { Object.defineProperty( script, 'state', { value: state } ); }
80
80
  realdom.realtime( window.document ).observe( script, () => {
81
81
  if ( script.quantum ) { state.dispose(); }
@@ -117,7 +117,7 @@ function realtime( config ) {
117
117
  function compileScript( config, script ) {
118
118
  const window = this, { webqit: { oohtml, QuantumScript, AsyncQuantumScript, QuantumModule } } = window;
119
119
  const textContent = ( script._ = script.textContent.trim() ) && script._.startsWith( '/*@oohtml*/if(false){' ) && script._.endsWith( '}/*@oohtml*/' ) ? script._.slice( 21, -12 ) : script.textContent;
120
- if ( !script.scoped && !script.quantum && !textContent.includes( 'quantum' ) ) return;
120
+ if ( !textContent.trim().length ) return;
121
121
  const sourceHash = _toHash( textContent );
122
122
  const compileCache = oohtml.Script.compileCache[ script.quantum ? 0 : 1 ];
123
123
  let compiledScript;