sprae 2.3.0 → 2.3.1
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 +1 -1
- package/plan.md +0 -1
- package/r&d.md +10 -3
- package/readme.md +21 -12
- package/sprae.js +1 -1
- package/sprae.min.js +1 -1
- package/src/directives.js +3 -1
package/package.json
CHANGED
package/plan.md
CHANGED
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
* [ ] Sandbox expressions: no global, no "scope" object name, no "arguments"
|
|
31
31
|
* ~~[x] report usignal problem~~ author is not really interested
|
|
32
32
|
* [ ] :oninit
|
|
33
|
-
* [ ] :onconnect, :ondisconnect
|
|
34
33
|
* [ ] frameworks benchmark
|
|
35
34
|
* [ ] examples
|
|
36
35
|
* [x] todomvc
|
package/r&d.md
CHANGED
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
+ methods provided in `init` may not have access to scope _yet_.
|
|
192
192
|
~- not reliable way to obtain scope via `this.x` - better be explicit as `state.x`
|
|
193
193
|
|
|
194
|
-
## [
|
|
194
|
+
## [x] :onconnected/:ondisconnected? -> let's move to plugins for now
|
|
195
195
|
|
|
196
196
|
-> waiting for use-case
|
|
197
197
|
|
|
@@ -223,6 +223,8 @@
|
|
|
223
223
|
* @sprae/item: `<x :item="{type:a, scope:b}"` – provide microdata
|
|
224
224
|
- can be solved naturally, unless there's special meaning
|
|
225
225
|
* @sprae/hcodes: `<x :hcode=""` – provide microformats
|
|
226
|
+
* @sprae/with
|
|
227
|
+
* @sprae/connected
|
|
226
228
|
|
|
227
229
|
## [x] Write any-attributes via :<prop>? -> yep
|
|
228
230
|
|
|
@@ -251,7 +253,7 @@
|
|
|
251
253
|
+ it has better control over serialization
|
|
252
254
|
+ `:onchange:oninput="e=>xyz"` is very good
|
|
253
255
|
|
|
254
|
-
## [ ] Sandbox?
|
|
256
|
+
## [ ] Sandbox? -> too complex for now. Waiting for use-cases
|
|
255
257
|
|
|
256
258
|
1. Use subscript?
|
|
257
259
|
+ solves access to any internal signals on syntactic level
|
|
@@ -290,4 +292,9 @@
|
|
|
290
292
|
## [x] Should getters convert to computed? -> yes, that's relatively cheap and useful
|
|
291
293
|
|
|
292
294
|
+ shorter and nicer syntax
|
|
293
|
-
- possibly longer
|
|
295
|
+
- possibly longer init
|
|
296
|
+
|
|
297
|
+
## [ ] Better :ref
|
|
298
|
+
+ :ref="`a-${1}`"
|
|
299
|
+
+ :id:ref="xyz"
|
|
300
|
+
? maybe id should have same signature
|
package/readme.md
CHANGED
|
@@ -148,9 +148,11 @@ Add event listeners.
|
|
|
148
148
|
<input :value="text" :oninput:onchange="e => text=e.target.value">
|
|
149
149
|
|
|
150
150
|
<!-- Sequence of events -->
|
|
151
|
-
<button :onfocus-onblur="e => {
|
|
151
|
+
<button :onfocus-onblur="e => {
|
|
152
|
+
// onfocus
|
|
152
153
|
let id = setInterval(track,200)
|
|
153
|
-
return e => {
|
|
154
|
+
return e => {
|
|
155
|
+
// onblur
|
|
154
156
|
clearInterval(id)
|
|
155
157
|
}
|
|
156
158
|
}">
|
|
@@ -182,6 +184,9 @@ Set [data-*](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
|
|
|
182
184
|
|
|
183
185
|
```html
|
|
184
186
|
<input :data="{foo: 1, barBaz: true}" />
|
|
187
|
+
<!--
|
|
188
|
+
<input data-foo="1" data-bar-baz="true" />
|
|
189
|
+
-->
|
|
185
190
|
```
|
|
186
191
|
|
|
187
192
|
#### `:aria="values"`
|
|
@@ -189,29 +194,31 @@ Set [data-*](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
|
|
|
189
194
|
Set [aria-role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) attributes. Boolean values are stringified.
|
|
190
195
|
|
|
191
196
|
```html
|
|
192
|
-
<input
|
|
197
|
+
<input role="combobox" :aria="{
|
|
193
198
|
controls: 'joketypes',
|
|
194
199
|
autocomplete: 'list',
|
|
195
200
|
expanded: false,
|
|
196
201
|
activeOption: 'item1',
|
|
197
202
|
activedescendant: ''
|
|
198
203
|
}" />
|
|
204
|
+
<!--
|
|
205
|
+
<input role="combobox" aria-controls="joketypes" aria-autocomplete="list" aria-expanded="false" aria-active-option="item1" aria-activedescendant="">
|
|
206
|
+
-->
|
|
199
207
|
```
|
|
200
208
|
|
|
201
209
|
#### `:ref="id"`
|
|
202
210
|
|
|
203
|
-
Expose element to
|
|
211
|
+
Expose element to data scope with the `id`:
|
|
204
212
|
|
|
205
213
|
```html
|
|
206
214
|
<!-- single item -->
|
|
207
|
-
<textarea :
|
|
215
|
+
<textarea :ref="text" placeholder="Enter text..."></textarea>
|
|
208
216
|
|
|
209
217
|
<!-- iterable items -->
|
|
210
218
|
<ul>
|
|
211
219
|
<li :each="item in items" :ref="item">
|
|
212
220
|
<input
|
|
213
|
-
:onfocus="e => item.classList.add('editing')"
|
|
214
|
-
:onblur="e => item.classList.remove('editing')"
|
|
221
|
+
:onfocus-onblur="e => (item.classList.add('editing'), e => item.classList.remove('editing'))"
|
|
215
222
|
/>
|
|
216
223
|
</li>
|
|
217
224
|
</ul>
|
|
@@ -220,8 +227,8 @@ Expose element to a subtree fragment with the `id`, as well as to scope:
|
|
|
220
227
|
import sprae from 'sprae';
|
|
221
228
|
let state = sprae(document, {items: ['a','b','c']})
|
|
222
229
|
|
|
223
|
-
//
|
|
224
|
-
state.text // <textarea
|
|
230
|
+
// element is in the state
|
|
231
|
+
state.text // <textarea></textarea>
|
|
225
232
|
</script>
|
|
226
233
|
```
|
|
227
234
|
|
|
@@ -249,7 +256,7 @@ This way, for example, _@preact/signals_ or _rxjs_ can be connected directly byp
|
|
|
249
256
|
|
|
250
257
|
## Hints
|
|
251
258
|
|
|
252
|
-
**1.** Data
|
|
259
|
+
**1.** Data supports signal values, which can be an alternative way to control template state:
|
|
253
260
|
|
|
254
261
|
```html
|
|
255
262
|
<div id="done" :text="loading ? 'loading' : result">...</div>
|
|
@@ -289,7 +296,7 @@ This way, for example, _@preact/signals_ or _rxjs_ can be connected directly byp
|
|
|
289
296
|
|
|
290
297
|
```html
|
|
291
298
|
<div id="x-plus-y">
|
|
292
|
-
<span :text="x">x</span> + <span :text="y">y</span> = <span :text="
|
|
299
|
+
<span :text="x">x</span> + <span :text="y">y</span> = <span :text="z">z</span>
|
|
293
300
|
</div>
|
|
294
301
|
|
|
295
302
|
<script type="module">
|
|
@@ -297,17 +304,19 @@ This way, for example, _@preact/signals_ or _rxjs_ can be connected directly byp
|
|
|
297
304
|
let state = sprae(document, { x:1, y:1, get z() { return this.x + this.y } })
|
|
298
305
|
|
|
299
306
|
state.x = 2, state.y = 2
|
|
307
|
+
state.z // 4
|
|
300
308
|
</script>
|
|
301
309
|
```
|
|
302
310
|
|
|
303
311
|
## Examples
|
|
304
312
|
|
|
305
313
|
* TODO MVC: [demo](https://dy.github.io/sprae/examples/todomvc), [code](https://github.com/dy/sprae/blob/main/examples/todomvc.html)
|
|
314
|
+
* Waveedit: [demo](), [code](https://github.com/dy/waveedit)
|
|
306
315
|
|
|
307
316
|
## Justification
|
|
308
317
|
|
|
309
318
|
* [Template-parts](https://github.com/dy/template-parts) / [templize](https://github.com/dy/templize) is progressive, but is stuck with native HTML quirks ([parsing table](https://github.com/github/template-parts/issues/24), [svg attributes](https://github.com/github/template-parts/issues/25), [liquid syntax](https://shopify.github.io/liquid/tags/template/#raw) conflict etc). Also ergonomics of `attr="{{}}"` is inferior to `:attr=""` since it creates flash of uninitialized values.
|
|
310
|
-
* [Alpine](https://github.com/alpinejs/alpine) / [vue](https://github.com/vuejs/petite-vue) / [lit](https://github.com/lit/lit/tree/main/packages/lit-html) escapes native HTML quirks, but the syntax is a bit scattered: `:attr`, `v-*`,`x-*`, `@evt`, `{{}}` can be expressed with single convention. Besides, functionality is too broad and can be reduced to essence. Also they tend to [self-encapsulate](https://github.com/alpinejs/alpine/discussions/3223), making interop hard.
|
|
319
|
+
* [Alpine](https://github.com/alpinejs/alpine) / [vue](https://github.com/vuejs/petite-vue) / [lit](https://github.com/lit/lit/tree/main/packages/lit-html) escapes native HTML quirks, but the syntax is a bit scattered: `:attr`, `v-*`,`x-*`, `@evt`, `{{}}` can be expressed with single convention. Besides, functionality is too broad and can be reduced to essence: perfection is when there's nothing to take away, not add. Also they tend to [self-encapsulate](https://github.com/alpinejs/alpine/discussions/3223), making interop hard.
|
|
311
320
|
* React/[preact](https://ghub.io/preact) does the job wiring up JS to HTML, but with an extreme of migrating HTML to JSX and enforcing SPA, which is not organic for HTML. Also it doesn't support reactive fields (needs render call).
|
|
312
321
|
|
|
313
322
|
_sprae_ takes convention of _templize directives_ (_alpine_/_vue_ attrs) and builds upon [_@preact/signals_](https://ghub.io/@preact/signals).
|
package/sprae.js
CHANGED
|
@@ -664,7 +664,7 @@ function parseExpr(el, expression, dir) {
|
|
|
664
664
|
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /^(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
665
665
|
let evaluate;
|
|
666
666
|
try {
|
|
667
|
-
evaluate = new Function(`
|
|
667
|
+
evaluate = new Function(`__scope`, `with (__scope) { return (${rightSideSafeExpression}) };`).bind(el);
|
|
668
668
|
} catch (e2) {
|
|
669
669
|
return exprError(e2, el, expression, dir);
|
|
670
670
|
}
|
package/sprae.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(){throw new Error("Cycle detected")}function e(){if(n>1)n--;else{for(var t,e=!1;void 0!==r;){var i=r;for(r=void 0,o++;void 0!==i;){var s=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&l(i))try{i.c()}catch(i){e||(t=i,e=!0)}i=s}}if(o=0,n--,e)throw t}}var i=void 0,r=void 0,n=0,o=0,s=0;function f(t){if(void 0!==i){var e=t.n;if(void 0===e||e.t!==i)return i.s=e={i:0,S:t,p:void 0,n:i.s,t:i,e:void 0,x:void 0,r:e},t.n=e,32&i.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=i.s,i.s.p=e,i.s=e),e}}function
|
|
1
|
+
function t(){throw new Error("Cycle detected")}function e(){if(n>1)n--;else{for(var t,e=!1;void 0!==r;){var i=r;for(r=void 0,o++;void 0!==i;){var s=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&l(i))try{i.c()}catch(i){e||(t=i,e=!0)}i=s}}if(o=0,n--,e)throw t}}var i=void 0,r=void 0,n=0,o=0,s=0;function f(t){if(void 0!==i){var e=t.n;if(void 0===e||e.t!==i)return i.s=e={i:0,S:t,p:void 0,n:i.s,t:i,e:void 0,x:void 0,r:e},t.n=e,32&i.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=i.s,i.s.p=e,i.s=e),e}}function a(t){this.v=t,this.i=0,this.n=void 0,this.t=void 0}function u(t){return new a(t)}function l(t){for(var e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function h(t){for(var e=t.s;void 0!==e;e=e.n){var i=e.S.n;void 0!==i&&(e.r=i),e.S.n=e,e.i=-1}}function c(t){for(var e=t.s,i=void 0;void 0!==e;){var r=e.n;-1===e.i?(e.S.U(e),e.n=void 0):(void 0!==i&&(i.p=e),e.p=void 0,e.n=i,i=e),e.S.n=e.r,void 0!==e.r&&(e.r=void 0),e=r}t.s=i}function v(t){a.call(this,void 0),this.x=t,this.s=void 0,this.g=s-1,this.f=4}function p(t){var r=t.u;if(t.u=void 0,"function"==typeof r){n++;var o=i;i=void 0;try{r()}catch(e){throw t.f&=-2,t.f|=8,d(t),e}finally{i=o,e()}}}function d(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,p(t)}function y(t){if(i!==this)throw new Error("Out-of-order effect");c(this),i=t,this.f&=-2,8&this.f&&d(this),e()}function b(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function m(t){var e=new b(t);return e.c(),e.d.bind(e)}a.prototype.h=function(){return!0},a.prototype.S=function(t){this.t!==t&&void 0===t.e&&(t.x=this.t,void 0!==this.t&&(this.t.e=t),this.t=t)},a.prototype.U=function(t){var e=t.e,i=t.x;void 0!==e&&(e.x=i,t.e=void 0),void 0!==i&&(i.e=e,t.x=void 0),t===this.t&&(this.t=i)},a.prototype.subscribe=function(t){var e=this;return m((function(){var i=e.value,r=32&this.f;this.f&=-33;try{t(i)}finally{this.f|=r}}))},a.prototype.valueOf=function(){return this.value},a.prototype.toString=function(){return this.value+""},a.prototype.peek=function(){return this.v},Object.defineProperty(a.prototype,"value",{get:function(){var t=f(this);return void 0!==t&&(t.i=this.i),this.v},set:function(i){if(i!==this.v){o>100&&t(),this.v=i,this.i++,s++,n++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{e()}}}}),(v.prototype=new a).h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===s)return!0;if(this.g=s,this.f|=1,this.i>0&&!l(this))return this.f&=-2,!0;var t=i;try{h(this),i=this;var e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return i=t,c(this),this.f&=-2,!0},v.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(var e=this.s;void 0!==e;e=e.n)e.S.S(e)}a.prototype.S.call(this,t)},v.prototype.U=function(t){if(a.prototype.U.call(this,t),void 0===this.t){this.f&=-33;for(var e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},v.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(v.prototype,"value",{get:function(){1&this.f&&t();var e=f(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),b.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},b.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,p(this),h(this),n++;var e=i;return i=this,y.bind(this,e)},b.prototype.N=function(){2&this.f||(this.f|=2,this.o=r,r=this)},b.prototype.d=function(){this.f|=8,1&this.f||d(this)},Symbol.observable||=Symbol("observable");var g=new FinalizationRegistry((t=>t.call?.())),S=t=>t&&t.peek,x=Symbol("signal-struct");function w(t){if((e=t)&&e[x])return t;var e;let i,r;if(O(t)){i={},r={};let e=Object.getOwnPropertyDescriptors(t);for(let t in e)r[t]=A(i,t,e[t].get?new v(e[t].get.bind(i)):e[t].value);return Object.defineProperty(i,x,{configurable:!1,enumerable:!1,value:!0}),Object.seal(i),i}return Array.isArray(t)?t.map((t=>w(t))):t}function A(t,e,i){let r,n=S(i)?i:O(i)||Array.isArray(i)?u(w(i)):u((r=(o=i)&&!!(o[Symbol.observable]||o[Symbol.asyncIterator]||o.call&&o.set||o.subscribe||o.then))?void 0:i);var o,s,f,a,l,h,c;return r&&(f=t=>n.value=t,(s=i)&&(c=(s[Symbol.observable]?.()||s).subscribe?.(f,a,undefined),h=c&&(()=>c.unsubscribe?.())||s.set&&s.call?.(l,f)||(s.then?.((t=>{!l&&f(t)}),a)||(async t=>{try{for await(t of s){if(l)return;f(t)}}catch(t){}})())&&(t=>l=1),g.register(s,h))),Object.defineProperty(t,e,{get:()=>n.value,set:!S(i)&&O(i)?t=>t?Object.assign(n.value,t):n.value=w(t):t=>n.value=w(t),enumerable:!0,configurable:!1}),n}function O(t){return t&&t.constructor===Object}var j=(t,e,i,r=null)=>{let n,o,s,f=0,a=i.length,u=e.length,{remove:l,same:h,insert:c,replace:v}=j;for(;f<a&&f<u&&h(e[f],i[f]);)f++;for(;f<a&&f<u&&h(i[a-1],e[u-1]);)r=i[(--u,--a)];if(f==u)for(;f<a;)c(r,i[f++],t);else{for(n=e[f];f<a;)s=i[f++],o=n?n.nextSibling:r,h(n,s)?n=o:f<a&&h(i[f],o)?(v(n,s,t),n=o):c(n,s,t);for(;!h(n,r);)o=n.nextSibling,l(n,t),n=o}return i};j.same=(t,e)=>t==e,j.replace=(t,e,i)=>i.replaceChild(e,t),j.insert=(t,e,i)=>i.insertBefore(e,t),j.remove=(t,e)=>e.removeChild(t);var N=j,E={},$={},k={},W={},C=(t,e,i,r)=>{if(r.startsWith("on"))return W.on(t,`{"${r.split("-").map((t=>t.startsWith("on")?t.slice(2):t)).join("-")}": ${e}}`,i);let n=D(t,e,":"+r);return e=>U(t,r,n(e))},U=(t,e,i)=>{null==i||!1===i?t.removeAttribute(e):t.setAttribute(e,!0===i?"":"number"==typeof i||"string"==typeof i?i:"")};W[""]=(t,e,i)=>{let r=D(t,e,":");return e=>{let i=r(e);for(let e in i)U(t,M(e),i[e])}};var B=Symbol(":each"),L=Symbol(":ref");W.ref=(t,e,i)=>{t.hasAttribute(":each")?t[L]=e:i[e]=t},W.if=(t,e,i)=>{let r=document.createTextNode(""),n=[D(t,e,":if")],o=[t],s=t;for(;(s=t.nextElementSibling)&&s.hasAttribute(":else");)s.removeAttribute(":else"),(e=s.getAttribute(":if"))?(s.removeAttribute(":if"),s.remove(),o.push(s),n.push(D(t,e,":else :if"))):(s.remove(),o.push(s),n.push((()=>1)));return t.replaceWith(s=r),t=>{let e=n.findIndex((e=>e(t)));o[e]!=s&&((s[B]||s).replaceWith(s=o[e]||r),F(s,t))}},W.each=(t,e,i)=>{let r=function(t){let e=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,i=t.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/);if(!i)return;let r={};r.items=i[2].trim();let n=i[1].replace(/^\s*\(|\)\s*$/g,"").trim(),o=n.match(e);return o?(r.item=n.replace(e,"").trim(),r.index=o[1].trim()):r.item=n,r}(e);if(!r)return _(new Error,t,e);const n=t[B]=document.createTextNode("");t.replaceWith(n);const o=D(t,r.items,":each"),s=new WeakMap,f=new WeakMap;let a=[];return e=>{let i=o(e);i?"number"==typeof i?i=Array.from({length:i},((t,e)=>[e,e+1])):i.constructor===Object?i=Object.entries(i):Array.isArray(i)?i=i.map(((t,e)=>[e+1,t])):_(Error("Bad list value"),t,r.items,":each"):i=[];let u=[],l=[];for(let[n,o]of i){let i=null===(h=o)?$:void 0===h?k:"number"==typeof h||h instanceof Number?E[h]||(E[h]=new Number(h)):"string"==typeof h||h instanceof String?E[h]||(E[h]=new String(h)):"boolean"==typeof h||h instanceof Boolean?E[h]||(E[h]=new Boolean(h)):h,a=f.get(i);if(a||(a=t.cloneNode(!0),f.set(i,a)),u.push(a),!s.has(i)){let f=Object.create(e);f[r.item]=o,r.index&&(f[r.index]=n),t[L]&&(f[t[L]]=a),s.set(i,f)}l.push(s.get(i))}var h;N(n.parentNode,a,u,n),a=u;for(let t=0;t<u.length;t++)F(u[t],l[t])}},W.id=(t,e,i)=>{let r=D(t,e,":id");return e=>{return i=r(e),t.id=i||0===i?i:"";var i}},W.class=(t,e,i)=>{let r=D(t,e,":class"),n=t.className;return e=>{let i=r(e);t.className=n+typeof i=="string"?i:(Array.isArray(i)?i:Object.entries(i).map((([t,e])=>e?t:""))).filter(Boolean).join(" ")}},W.style=(t,e,i)=>{let r=D(t,e,":style");return e=>{let i=r(e);if("string"==typeof i)t.setAttribute("style",i);else for(let e in i)t.style[e]=i[e]}},W.text=(t,e,i)=>{let r=D(t,e,":text");return e=>{return i=r(e),void(t.textContent=null==i?"":i);var i}},W.value=(t,e,i)=>{let r=D(t,e,":in"),n="text"===t.type||""===t.type?e=>t.setAttribute("value",t.value=null==e?"":e):"checkbox"===t.type?e=>(t.value=e?"on":"",U(t,"checked",e)):"select-one"===t.type?e=>([...t.options].map((t=>t.removeAttribute("selected"))),t.value=e,t.selectedOptions[0]?.setAttribute("selected","")):e=>t.value=e;return t=>n(r(t))},W.on=(t,e,i)=>{let r=D(t,e,":on"),n={};return e=>{for(let e in n)t.removeEventListener(e,n[e]);n=r(e);for(let e in n){const i=e.split("-");if(1===i.length)t.addEventListener(e,n[e]);else{const r=n[e],o=(s,f=0)=>{t.addEventListener(i[f],n[e]=a=>{s=s(a),t.removeEventListener(i[f],n[e]),++f<i.length&&"function"==typeof s?o(s,f):o(r)})};o(r)}}}},W.data=(t,e,i)=>{let r=D(t,e,":data");return e=>{let i=r(e);for(let e in i)t.dataset[e]=i[e]}},W.aria=(t,e,i)=>{let r=D(t,e,":aria");return e=>(e=>{for(let i in e)U(t,"aria-"+M(i),null==e[i]?null:e[i]+"")})(r(e))};var P={};function D(t,e,i){if(P[e])return P[e];let r,n=/^[\n\s]*if.*\(.*\)/.test(e)||/^(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{r=new Function("__scope",`with (__scope) { return (${n}) };`).bind(t)}catch(r){return _(r,t,e,i)}return P[e]=n=>{let o;try{o=r(n)}catch(r){return _(r,t,e,i)}return o}}function _(t,e,i,r){Object.assign(t,{element:e,expression:i}),console.warn(`∴ ${t.message}\n\n${r}=${i?`"${i}"\n\n`:""}`,e),setTimeout((()=>{throw t}),0)}function M(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var T=new WeakMap;function F(t,e){if(!t.children)return;if(T.has(t))return T.get(t);e||={};const i=[],r=(t,n=t.parentNode)=>{if(t.attributes)for(let r=0;r<t.attributes.length;){let o=t.attributes[r];if(":"!==o.name[0]){r++;continue}t.removeAttribute(o.name);let s=o.value,f=o.name.slice(1).split(":");for(let r of f){let o=W[r]||C;if(i.push(o(t,s,e,r)||(()=>{})),T.has(t)||t.parentNode!==n)return!1}}for(let e,i=0;e=t.children[i];i++)!1===r(e,t)&&i--};r(t);const n=w(e);for(let t of i)m((()=>t(n)));return T.set(t,n),n}var I=F;export{I as default};
|
package/src/directives.js
CHANGED
|
@@ -38,6 +38,8 @@ directives['ref'] = (el, expr, values) => {
|
|
|
38
38
|
// make sure :ref is initialized after :each (return to avoid initializing as signal)
|
|
39
39
|
if (el.hasAttribute(':each')) {el[_ref] = expr; return};
|
|
40
40
|
|
|
41
|
+
// FIXME: wait for complex ref use-case
|
|
42
|
+
// parseExpr(el, `__scope[${expr}]=this`, ':ref')(values)
|
|
41
43
|
values[expr] = el;
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -275,7 +277,7 @@ function parseExpr(el, expression, dir) {
|
|
|
275
277
|
// guard static-time eval errors
|
|
276
278
|
let evaluate
|
|
277
279
|
try {
|
|
278
|
-
evaluate = new Function(`
|
|
280
|
+
evaluate = new Function(`__scope`,`with (__scope) { return (${rightSideSafeExpression}) };`).bind(el)
|
|
279
281
|
} catch ( e ) {
|
|
280
282
|
return exprError(e, el, expression, dir)
|
|
281
283
|
}
|