@webqit/oohtml 3.1.6 → 3.1.8
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/README.md +21 -21
- package/dist/bindings-api.js +1 -1
- package/dist/bindings-api.js.map +2 -2
- package/dist/context-api.js +1 -1
- package/dist/context-api.js.map +2 -2
- package/dist/data-binding.js +16 -15
- package/dist/data-binding.js.map +2 -2
- package/dist/html-imports.js +1 -1
- package/dist/html-imports.js.map +2 -2
- package/dist/main.js +25 -24
- package/dist/main.js.map +2 -2
- package/dist/main.lite.js +19 -18
- package/dist/main.lite.js.map +2 -2
- package/dist/namespaced-html.js +1 -1
- package/dist/namespaced-html.js.map +2 -2
- package/dist/scoped-css.js +1 -1
- package/dist/scoped-css.js.map +2 -2
- package/dist/scoped-js.js +1 -1
- package/dist/scoped-js.js.map +2 -2
- package/package.json +3 -3
- package/src/context-api/DOMContext.js +1 -1
- package/src/data-binding/index.js +50 -33
- package/src/scoped-js/index.js +1 -1
|
@@ -50,9 +50,15 @@ function realtime( config ) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function createDynamicScope( config, root ) {
|
|
53
|
-
const { webqit: { Observer, DOMBindingsContext } } = this;
|
|
53
|
+
const { webqit: { realdom, Observer, DOMBindingsContext } } = this;
|
|
54
54
|
if ( _( root ).has( 'data-binding' ) ) return _( root ).get( 'data-binding' );
|
|
55
|
-
const scope =
|
|
55
|
+
const scope = Object.create( null ), abortController = new AbortController;
|
|
56
|
+
scope[ '$exec__' ] = ( target, prop, ...args ) => {
|
|
57
|
+
realdom.schedule( 'write', () => target[ prop ]( ...args ) );
|
|
58
|
+
};
|
|
59
|
+
scope[ '$assign__' ] = ( target, prop, val ) => {
|
|
60
|
+
realdom.schedule( 'write', () => (target[ prop ] = val) );
|
|
61
|
+
};
|
|
56
62
|
Observer.intercept( scope, {
|
|
57
63
|
get: ( e, recieved, next ) => {
|
|
58
64
|
if ( !( e.key in scope ) ) {
|
|
@@ -76,7 +82,7 @@ function cleanup( ...entries ) {
|
|
|
76
82
|
const { bindings, abortController } = _( root ).get( 'data-binding' ) || {};
|
|
77
83
|
if ( !bindings?.has( node ) ) return;
|
|
78
84
|
bindings.get( node ).state.dispose();
|
|
79
|
-
bindings.get( node ).signals
|
|
85
|
+
bindings.get( node ).signals?.forEach( s => s.abort() );
|
|
80
86
|
bindings.delete( node );
|
|
81
87
|
if ( !bindings.size ) {
|
|
82
88
|
abortController.abort();
|
|
@@ -119,51 +125,57 @@ async function mountDiscreteBindings( config, ...entries ) {
|
|
|
119
125
|
}, [] );
|
|
120
126
|
|
|
121
127
|
for ( const { textNode, template, anchorNode } of instances ) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if ( anchorNode ) { source += `$anchorNode__.nodeValue = "${ config.tokens.tagStart }${ escDouble( template.expr ) }${ config.tokens.stateStart }" + content.length + "${ config.tokens.stateEnd } ${ config.tokens.tagEnd }";`; }
|
|
127
|
-
const compiled = new QuantumAsyncFunction( '$signals__', `$anchorNode__`, source, { env } );
|
|
128
|
-
const signals = [];
|
|
129
|
-
bindings.set( textNode, { compiled, signals, state: await compiled.call( textNode, signals, anchorNode ), } );
|
|
128
|
+
const compiled = compileDiscreteBindings( config, template.expr );
|
|
129
|
+
const { scope, bindings } = createDynamicScope.call( this, config, textNode.parentNode );
|
|
130
|
+
Object.defineProperty( textNode, '$oohtml_internal_databinding_anchorNode', { value: anchorNode, configurable: true } );
|
|
131
|
+
bindings.set( textNode, { state: await ( await compiled.bind( textNode, scope ) ).execute(), } );
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
const discreteParseCache = new Map;
|
|
136
|
+
function compileDiscreteBindings( config, str ) {
|
|
137
|
+
if ( discreteParseCache.has( str ) ) return discreteParseCache.get( str );
|
|
138
|
+
let source = `let content = ((${ str }) ?? '') + '';`;
|
|
139
|
+
source += `$assign__(this, 'nodeValue', content);`;
|
|
140
|
+
source += `if ( this.$oohtml_internal_databinding_anchorNode ) { $assign__(this.$oohtml_internal_databinding_anchorNode, 'nodeValue', "${ config.tokens.tagStart }${ escDouble( str ) }${ config.tokens.stateStart }" + content.length + "${ config.tokens.stateEnd } ${ config.tokens.tagEnd }"); }`;
|
|
141
|
+
const { webqit: { QuantumModule } } = this;
|
|
142
|
+
const compiled = new QuantumModule( source );
|
|
143
|
+
discreteParseCache.set( str, compiled );
|
|
144
|
+
return compiled;
|
|
145
|
+
}
|
|
146
|
+
|
|
133
147
|
async function mountInlineBindings( config, ...entries ) {
|
|
134
|
-
const { webqit: { QuantumAsyncFunction } } = this;
|
|
135
148
|
for ( const node of entries ) {
|
|
136
|
-
const
|
|
137
|
-
const { scope
|
|
138
|
-
const compiled = new QuantumAsyncFunction( '$signals__', source, { env } );
|
|
149
|
+
const compiled = compileInlineBindings( config, node.getAttribute( config.attr.expr ) );
|
|
150
|
+
const { scope, bindings } = createDynamicScope.call( this, config, node );
|
|
139
151
|
const signals = [];
|
|
140
|
-
|
|
152
|
+
Object.defineProperty( node, '$oohtml_internal_databinding_signals', { value: signals, configurable: true } );
|
|
153
|
+
bindings.set( node, { signals, state: await ( await compiled.bind( node, scope ) ).execute(), } );
|
|
141
154
|
}
|
|
142
155
|
}
|
|
143
156
|
|
|
144
|
-
const
|
|
145
|
-
function
|
|
146
|
-
if (
|
|
157
|
+
const inlineParseCache = new Map;
|
|
158
|
+
function compileInlineBindings( config, str ) {
|
|
159
|
+
if ( inlineParseCache.has( str ) ) return inlineParseCache.get( str );
|
|
147
160
|
const validation = {};
|
|
148
|
-
const escDouble = str => str.replace(/"/g, '\\"');
|
|
149
161
|
const source = splitOuter( str, ';' ).map( str => {
|
|
150
162
|
const [ left, right ] = splitOuter( str, ':' ).map( x => x.trim() );
|
|
151
163
|
const directive = left[ 0 ], param = left.slice( 1 ).trim();
|
|
152
164
|
const arg = `(${ right })`, $arg = `(${ arg } ?? '')`;
|
|
153
165
|
if ( directive === '&' ) {
|
|
154
|
-
if ( param.startsWith( '--' ) ) return
|
|
155
|
-
return
|
|
166
|
+
if ( param.startsWith( '--' ) ) return `$exec__(this.style, 'setProperty', "${ escDouble( param ) }", ${ $arg });`;
|
|
167
|
+
return `$assign__(this.style, "${ escDouble( param ) }", ${ $arg });`;
|
|
156
168
|
}
|
|
157
|
-
if ( directive === '%' ) return
|
|
169
|
+
if ( directive === '%' ) return `$exec__(this.classList, 'toggle', "${ escDouble( param ) }", !!${ arg });`;
|
|
158
170
|
if ( directive === '~' ) {
|
|
159
|
-
if ( param.startsWith( '?' ) ) return
|
|
160
|
-
return
|
|
171
|
+
if ( param.startsWith( '?' ) ) return `$exec__(this, 'toggleAttribute', "${ escDouble( param.substring( 1 ).trim() ) }", !!${ arg });`;
|
|
172
|
+
return `$exec__(this, 'setAttribute', "${ escDouble( param ) }", ${ $arg });`;
|
|
161
173
|
}
|
|
162
174
|
if ( directive === '@' ) {
|
|
163
175
|
if ( validation[ param ] ) throw new Error( `Duplicate binding: ${ left }.` );
|
|
164
176
|
validation[ param ] = true;
|
|
165
|
-
if ( param === 'text' ) return
|
|
166
|
-
if ( param === 'html' ) return
|
|
177
|
+
if ( param === 'text' ) return `$assign__(this, 'textContent', ${ $arg });`;
|
|
178
|
+
if ( param === 'html' ) return `$exec__(this, 'setHTML', ${ $arg });`;
|
|
167
179
|
if ( param === 'items' ) {
|
|
168
180
|
const [ iterationSpec, importSpec ] = splitOuter( right, '/' );
|
|
169
181
|
if ( !importSpec ) throw new Error( `Invalid ${ directive }items spec: ${ str }; no import specifier.` );
|
|
@@ -177,7 +189,7 @@ function parseInlineBindings( config, str ) {
|
|
|
177
189
|
return `
|
|
178
190
|
let $iteratee__ = ${ iteratee };
|
|
179
191
|
let $import__ = this.${ config.HTML_IMPORTS.context.api.import }( ${ importSpec.trim() }, true );
|
|
180
|
-
|
|
192
|
+
this.$oohtml_internal_databinding_signals?.push( $import__ );
|
|
181
193
|
|
|
182
194
|
if ( $import__.value && $iteratee__ ) {
|
|
183
195
|
let $existing__ = new Map;
|
|
@@ -194,13 +206,14 @@ function parseInlineBindings( config, str ) {
|
|
|
194
206
|
let $itemNode__ = $existing__.get( $key___ );
|
|
195
207
|
if ( $itemNode__ ) {
|
|
196
208
|
$existing__.delete( $key___ );
|
|
209
|
+
$exec__($itemNode__, '${ config.BINDINGS_API.api.bind }', $itemBinding__ );
|
|
197
210
|
} else {
|
|
198
211
|
$itemNode__ = ( Array.isArray( $import__.value ) ? $import__.value[ 0 ] : ( $import__.value instanceof window.HTMLTemplateElement ? $import__.value.content.firstElementChild : $import__.value ) ).cloneNode( true );
|
|
199
212
|
$itemNode__.setAttribute( "${ config.attr.itemIndex }", $key___ );
|
|
200
|
-
|
|
213
|
+
$exec__($itemNode__, '${ config.BINDINGS_API.api.bind }', $itemBinding__ );
|
|
214
|
+
$exec__(this, 'appendChild', $itemNode__ );
|
|
201
215
|
}
|
|
202
216
|
|
|
203
|
-
$itemNode__.${ config.BINDINGS_API.api.bind }( $itemBinding__ );
|
|
204
217
|
if ( ${ kind === 'in' ? `!( ${ production[ 0 ] } in $iteratee__ )` : `typeof ${ production[ 0 ] } === 'undefined'` } ) { $itemNode__.remove(); }
|
|
205
218
|
}
|
|
206
219
|
$existing__.forEach( x => x.remove() );
|
|
@@ -210,8 +223,10 @@ function parseInlineBindings( config, str ) {
|
|
|
210
223
|
}
|
|
211
224
|
if ( str.trim() ) throw new Error( `Invalid binding: ${ str }.` );
|
|
212
225
|
} ).join( `\n` );
|
|
213
|
-
|
|
214
|
-
|
|
226
|
+
const { webqit: { QuantumModule } } = this;
|
|
227
|
+
const compiled = new QuantumModule( source );
|
|
228
|
+
inlineParseCache.set( str, compiled );
|
|
229
|
+
return compiled;
|
|
215
230
|
}
|
|
216
231
|
|
|
217
232
|
export function splitOuter( str, delim ) {
|
|
@@ -227,4 +242,6 @@ export function splitOuter( str, delim ) {
|
|
|
227
242
|
splits[ 0 ] += x;
|
|
228
243
|
return [ quote, depth, splits ]
|
|
229
244
|
}, [ null, 0, [ '' ] ] )[ 2 ].reverse();
|
|
230
|
-
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const escDouble = str => str.replace(/"/g, '\\"');
|
package/src/scoped-js/index.js
CHANGED
|
@@ -77,7 +77,7 @@ function realtime( config ) {
|
|
|
77
77
|
const { parserParams, compilerParams, runtimeParams } = config.advanced;
|
|
78
78
|
compiledScript = new ( script.type === 'module' ? QuantumModule : ( QuantumScript || QuantumAsyncScript ) )( textContent, {
|
|
79
79
|
exportNamespace: `#${ script.id }`,
|
|
80
|
-
fileName
|
|
80
|
+
fileName:`${ window.document.url?.split( '#' )?.[ 0 ] || '' }#${ script.id }`,
|
|
81
81
|
parserParams,
|
|
82
82
|
compilerParams: { ...compilerParams, startStatic: !script.quantum },
|
|
83
83
|
runtimeParams,
|