@webqit/oohtml 4.1.15 → 4.3.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.15",
17
+ "version": "4.3.0",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@webqit/quantum-js": "^4.5.11",
43
- "@webqit/realdom": "^2.1.28",
43
+ "@webqit/realdom": "^2.1.30",
44
44
  "@webqit/util": "^0.8.11"
45
45
  },
46
46
  "devDependencies": {
@@ -54,8 +54,7 @@ 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
+ try { target[ prop ]( ...args ); } catch( e ) { console.error( `Error executing "${ prop }": ${ e.message } at ${ e.cause }` ); }
59
58
  };
60
59
  realdom.schedule( 'write', exec );
61
60
  };
@@ -177,20 +176,24 @@ function compileInlineBindings( config, str ) {
177
176
  const [ left, right ] = _splitOuter( str, ':' ).map( x => x.trim() );
178
177
  const directive = left[ 0 ], param = left.slice( 1 ).trim();
179
178
  const arg = `(${ right })`, $arg = `(${ arg } ?? '')`;
179
+ // CSS
180
180
  if ( directive === '&' ) {
181
181
  if ( param.startsWith( '--' ) ) return `$exec__(this.style, 'setProperty', "${ escDouble( param ) }", ${ $arg });`;
182
182
  return `$assign__(this.style, "${ escDouble( param ) }", ${ $arg });`;
183
183
  }
184
+ // Class list
184
185
  if ( directive === '%' ) return `$exec__(this.classList, 'toggle', "${ escDouble( param ) }", !!${ arg });`;
186
+ // Attribute
185
187
  if ( directive === '~' ) {
186
188
  if ( param.startsWith( '?' ) ) return `$exec__(this, 'toggleAttribute', "${ escDouble( param.substring( 1 ).trim() ) }", !!${ arg });`;
187
189
  return `$exec__(this, 'setAttribute', "${ escDouble( param ) }", ${ $arg });`;
188
190
  }
189
- if ( directive === '@' ) {
191
+ // Structure
192
+ if ( directive === '#' ) {
190
193
  if ( validation[ param ] ) throw new Error( `Duplicate binding: ${ left }.` );
191
194
  validation[ param ] = true;
192
195
  if ( param === 'text' ) return `$assign__(this, 'textContent', ${ $arg });`;
193
- if ( param === 'html' ) return `$exec__(this, 'setHTML', ${ $arg });`;
196
+ if ( param === 'html' ) return `$exec__(this, 'setHTMLUnsafe', ${ $arg });`;
194
197
  if ( param === 'items' ) {
195
198
  const [ iterationSpec, importSpec ] = _splitOuter( right, '/' );
196
199
  if ( !importSpec ) throw new Error( `Invalid ${ directive }items spec: ${ str }; no import specifier.` );
@@ -235,14 +238,20 @@ function compileInlineBindings( config, str ) {
235
238
  $existing__.clear();
236
239
  }`;
237
240
  }
238
- // Treat other "@" directives as events
241
+ }
242
+ // Events
243
+ if ( directive === '@' ) {
239
244
  return `
240
- const handler = () => ${ arg };
245
+ const handler = event => ${ right.startsWith('{') ? right : arg };
241
246
  this.addEventListener( '${ param }', handler );
242
247
  const abort = () => this.removeEventListener( '${ param }', handler );
243
248
  this.$oohtml_internal_databinding_signals?.push( { abort } );
244
249
  `;
245
250
  }
251
+ // Functions
252
+ if ( directive === '$' ) {
253
+ return `$exec__(this, '${ param }', ${ arg });`;
254
+ }
246
255
  if ( str.trim() ) throw new Error( `Invalid binding: ${ str }.` );
247
256
  } ).join( `\n` );
248
257
  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(); }