tagu-tagu 2.0.1 → 2.1.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/dist/bundle.min.js +1 -1
- package/package.json +1 -1
- package/src/Modify.ts +8 -0
- package/src/data/useBinding.ts +8 -3
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S=class{node2Data=new WeakMap;addCallbacks(t,n){if(!n)return;this.node2DescendantCallbacks.has(t)||this.node2DescendantCallbacks.set(t,{});let o=this.node2DescendantCallbacks.get(t);w(o,n);let i=this.node2Data.get(t);
|
|
1
|
+
var S=class{node2Data=new WeakMap;addCallbacks(t,n){if(!n)return;this.node2DescendantCallbacks.has(t)||this.node2DescendantCallbacks.set(t,{});let o=this.node2DescendantCallbacks.get(t);w(o,n);let i=this.node2Data.get(t);k(o,i)}setDataRecord(t,n){n&&this.node2Data.set(t,n)}resolveCallbacks(t,n){let o=(a,d)=>{if(k(d,this.node2Data.get(a)),!!Object.keys(d).length){if(!a.parentElement){this.node2DescendantCallbacks.has(a)||this.node2DescendantCallbacks.set(a,{});let m=this.node2DescendantCallbacks.get(a);m&&w(m,d);return}o(a.parentElement,d)}},i=this.node2DescendantCallbacks.get(n);i&&o(t,i)}node2DescendantCallbacks=new WeakMap};function k(e,t){for(let n in t)if(n in e){for(let o of e[n])o(t[n]);delete e[n]}}var s=new S;function H(e,t){s.setDataRecord(e,t)}function $(e){if(!e)return;let t={};for(let n in e){let o=e[n];t[n]=[o]}if(Object.keys(t).length)return t}function w(e,t){for(let n in t)e[n]||(e[n]=[]),e[n].push(...t[n])}function z(e,t){if(!e)return;let n=s.node2Data.get(e);return n&&t in n?n[t]:z(e.parentElement,t)}function b(e,t){s.addCallbacks(e,$(t))}function A(e,t=n=>n){return new T(e,t)}var T=class{constructor(t,n){this.key=t;this.map=n}};var c=class{next=null;firstNode=null};var p=class{#e;constructor(t){this.#e=t}get=()=>this.#e;set(t){this.#e=t,this.#n("change")}#n(t){this.#t.dispatchEvent(new Event(t))}#t=new EventTarget;on(t,n){this.#t.addEventListener(t,n)}};function ie(e){return new p(e)}function R(e,t){let n=new p(t()),o=()=>{n.set(t())};for(let i of e)i.on("change",o);return n}function D(e,t){let n=j(t);K(n);for(let o of n)O(e,o)}function O(e,t){t instanceof c?t.run(e):(s.resolveCallbacks(e,t),e.appendChild(t))}function j(e){return e.map(t=>{if(typeof t=="string"||t instanceof p){let n=document.createTextNode("");return y(t,o=>{n.textContent=o}),n}return t})}function K(e){for(let t=0;t<e.length;t++){let n=e[t];n instanceof c&&(n.next=e[t+1]??null)}}function B(e){let t=e.next;return t===null?null:t instanceof Node?t:t.firstNode?t.firstNode:B(t)}function g(e){let t=B(e);return t?.parentElement?t:null}function y(e,t){if(typeof e=="string")t(e);else{let n=()=>{t(e.get())};n(),e.on("change",n)}}function x(e,t,n){t instanceof T?b(e,{[t.key]:o=>{let a=o instanceof p?R([o],()=>t.map(o.get())):t.map(o);y(a,n)}}):y(t,n)}function V(e,t){t!==void 0&&x(e,t,n=>{e.innerHTML=n})}function F(e,t){t!==void 0&&x(e,t,n=>{e.textContent=n})}function q(e,t){let n=e.style;if(n instanceof CSSStyleDeclaration)for(let o in t){let i=t[o];x(e,i,a=>n.setProperty(o,a))}}function P(e,t){for(let n in t){let o=t[n];x(e,o,i=>{i?e.setAttribute(n,i):e.removeAttribute(n)})}}function G(e,t){for(let n in t){let o=t[n];x(e,o,i=>{e[n]=i})}}function U(e,t){for(let n in t){let o=e.querySelector(n);o&&C(o,t[n])}}function W(e,t){for(let n in t){let o=e.querySelectorAll(n);for(let i of o)C(i,t[n])}}function Q(e,t){for(let n in t){let i=t[n];i&&(typeof i=="function"?e.addEventListener(n,i):i instanceof T?b(e,{[i.key]:a=>{let d=i.map(a);e.addEventListener(n,d)}}):e.addEventListener(n,i.listener,i.options))}}function C(e,t){e&&(typeof t=="string"||t instanceof p?F(e,t):Array.isArray(t)?D(e,t):typeof t=="function"?t(e):(V(e,t.html),F(e,t.text),P(e,t.attr),G(e,t.prop),q(e,t.css),U(e,t.$),W(e,t.$$),Q(e,t.on),H(e,t.data)))}function v(e,...t){let n=typeof e=="string"?document.querySelector(e):e;for(let o of t)C(n,o);return n}function xe(e,...t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);return v(n,...t)}function r(e,...t){let n=document.createElement(e);return v(n,...t),n}function ye(e,...t){let n=L({html:e}).children[0];return v(n,...t)}function Se(...e){return r("h1",...e)}function be(...e){return r("h2",...e)}function Ce(...e){return r("h3",...e)}function Le(...e){return r("h4",...e)}function Me(...e){return r("h5",...e)}function Ne(...e){return r("h6",...e)}function Ie(...e){return r("p",...e)}function ke(...e){return r("section",...e)}function we(...e){return r("button",...e)}function He(...e){return r("span",...e)}function ze(e){function t(n,o){return`${n} {${Object.keys(o).map(i=>`${i}: ${o[i]};`).join("")}}`}return r("style",[Object.keys(e).map(n=>t(n,e[n])).join("")])}function L(...e){return r("div",...e)}function Re(...e){return L({css:{display:"flex"}},...e)}function De(...e){return r("input",...e)}function Be(...e){return r("textarea",...e)}function Fe(...e){return r("select",...e)}function $e(...e){return r("option",...e)}function Ae(...e){return r("br",...e)}function Oe(...e){return r("tr",...e)}function je(...e){return r("td",...e)}function Ke(...e){return r("b",...e)}function Ve(...e){return r("label",...e)}function qe(...e){return r("a",...e)}function Pe(...e){return r("blockquote",...e)}function Ge(...e){return r("li",...e)}function Ue(...e){return r("ol",...e)}function We(...e){return r("ul",...e)}function Qe(...e){return r("audio",...e)}function Je(...e){return r("video",...e)}function Xe(...e){return r("img",...e)}function Ye(...e){return r("canvas",...e)}function Ze(...e){return r("iframe",...e)}function _e(...e){return r("form",...e)}function et(...e){return r("table",...e)}function tt(...e){return r("tbody",...e)}function nt(...e){return r("hr",...e)}function J(e,t){return new M(e,t)}var M=class extends c{constructor(n,o){super();this.list=n;this.map=o}run(n){let o=new Map,i=new Map,a=()=>{let d=[];for(let l of this.list.get())o.has(l)||d.push(l);let m=[],f=new Set(this.list.get());for(let l of i.keys()){let u=i.get(l);u&&!f.has(u)&&m.push(l)}for(let l of d){let u=this.map(l),h=typeof u=="string"?document.createTextNode(u):u;s.resolveCallbacks(n,h),i.set(h,l),o.set(l,h)}for(let l of m){l.parentNode?.removeChild(l);let u=i.get(l);i.delete(l),u&&o.delete(u)}for(let l of[...i.keys()])l.parentElement?.removeChild(l);let E=g(this);for(let l of this.list.get())n.insertBefore(o.get(l),E);this.firstNode=o.get(this.list.get()[0])??null};a(),this.list.on("change",()=>{a()})}};function X(e,t,n){return new N(e,t,n)}var N=class extends c{#e;#n;#t;constructor(t,n,o){super(),this.#e=t,this.#n=n,this.#t=o}run(t){let n,o,i=()=>{let a=g(this);this.#e.get()?(n||(n=this.#n()),s.resolveCallbacks(t,n),this.firstNode=n,o?.remove(),t.insertBefore(n,a)):(o||(o=this.#t?.()),o&&s.resolveCallbacks(t,o),this.firstNode=o??null,n?.remove(),o&&t.insertBefore(o,a))};i(),this.#e.on("change",i)}};function Y(e,t,n){return new I(e,t,n)}var I=class extends c{#e;#n;#t;constructor(t,n,o){super(),this.#e=t,this.#n=n,this.#t=o}run(t){let n=new Map,o=new Map;for(let f of this.#n)o.set(f.case,f);let i,a,d=f=>{let E=o.get(f);if(E){if(!n.has(f)){let l=E.show();n.set(f,l)}return n.get(f)}return this.#t&&!a&&(a=this.#t()),a},m=()=>{let f=this.#e.get(),E=g(this),l=d(f);l&&s.resolveCallbacks(t,l),i?.remove(),l&&t.insertBefore(l,E),i=l};m(),this.#e.on("change",m)}};export{c as ControlFlow,Re as FlexDiv,J as For,R as FromStates,r as Html,X as If,v as Modify,p as State,xe as Svg,Y as Switch,ye as Tag,qe as a,y as applyStringOrState,Qe as audio,Ke as b,Pe as blockquote,Ae as br,we as button,Ye as canvas,L as div,z as findData,_e as form,Se as h1,be as h2,Ce as h3,Le as h4,Me as h5,Ne as h6,nt as hr,Ze as iframe,Xe as img,De as input,Ve as label,Ge as li,Ue as ol,$e as option,Ie as p,ke as section,Fe as select,He as span,ze as style,et as table,tt as tbody,je as td,Be as textarea,Oe as tr,We as ul,A as useBinding,ie as useState,Je as video};
|
package/package.json
CHANGED
package/src/Modify.ts
CHANGED
|
@@ -11,6 +11,7 @@ type EventListenerType<
|
|
|
11
11
|
type EventListenerRecord<TEventType2Event> = {
|
|
12
12
|
[TEventType in keyof TEventType2Event]?:
|
|
13
13
|
| EventListenerType<TEventType2Event, TEventType>
|
|
14
|
+
| Binding
|
|
14
15
|
| {
|
|
15
16
|
listener: EventListenerType<TEventType2Event, TEventType>;
|
|
16
17
|
options: boolean | AddEventListenerOptions;
|
|
@@ -170,6 +171,13 @@ function initializeEventListeners<TEventType2Event>(
|
|
|
170
171
|
if (!listener) continue;
|
|
171
172
|
if (typeof listener === "function") {
|
|
172
173
|
element.addEventListener(eventName, listener as EventListener);
|
|
174
|
+
} else if (listener instanceof Binding) {
|
|
175
|
+
waitForData(element, {
|
|
176
|
+
[listener.key]: (data) => {
|
|
177
|
+
const func = listener.map(data);
|
|
178
|
+
element.addEventListener(eventName, func);
|
|
179
|
+
},
|
|
180
|
+
});
|
|
173
181
|
} else {
|
|
174
182
|
element.addEventListener(
|
|
175
183
|
eventName,
|
package/src/data/useBinding.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
export function useBinding<T>(key: string
|
|
1
|
+
export function useBinding<T>(key: string): Binding<T, T>;
|
|
2
|
+
export function useBinding<T, TResult>(
|
|
3
|
+
key: string,
|
|
4
|
+
map: (value: T) => TResult,
|
|
5
|
+
): Binding<T, TResult>;
|
|
6
|
+
export function useBinding<T>(key: string, map = (value: T) => value) {
|
|
2
7
|
return new Binding(key, map);
|
|
3
8
|
}
|
|
4
9
|
|
|
5
|
-
export class Binding<T = any> {
|
|
10
|
+
export class Binding<T = any, TResult = any> {
|
|
6
11
|
constructor(
|
|
7
12
|
public key: string,
|
|
8
|
-
public map: (value: T) =>
|
|
13
|
+
public map: (value: T) => TResult,
|
|
9
14
|
) {}
|
|
10
15
|
}
|