sinho 0.3.6 → 0.3.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/dist/array_mutation.js +51 -30
- package/dist/array_mutation.js.map +1 -1
- package/dist/bundle.d.ts +5 -5
- package/dist/bundle.js +51 -30
- package/dist/bundle.min.js +1 -1
- package/dist/component.d.ts +3 -3
- package/dist/component.js.map +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.js.map +1 -1
- package/package.json +1 -1
- package/src/array_mutation.ts +74 -44
- package/src/component.ts +4 -4
- package/src/mod.ts +10 -7
- package/web/static/dist/bundle.d.ts +1147 -0
- package/web/static/dist/bundle.min.js +1 -0
package/dist/array_mutation.js
CHANGED
|
@@ -1,50 +1,71 @@
|
|
|
1
1
|
import { useEffect, useSignal } from "./scope.js";
|
|
2
|
-
const getIndexMap = (array, keyFn) => {
|
|
3
|
-
const
|
|
2
|
+
const getIndexMap = (array, keyFn, oldIndexMap) => {
|
|
3
|
+
const _indexMap = new Map();
|
|
4
4
|
for (let i = 0; i < array.length; i++) {
|
|
5
5
|
const key = keyFn(array[i], i);
|
|
6
|
-
if (
|
|
6
|
+
if (_indexMap.has(key)) {
|
|
7
7
|
throw new Error(`Duplicate key '${key}'`);
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
_indexMap.set(key, i);
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
const _removedFromOld = [];
|
|
12
|
+
let removedBefore = 0;
|
|
13
|
+
for (const [key, i] of oldIndexMap) {
|
|
14
|
+
if (!_indexMap.has(key)) {
|
|
15
|
+
_removedFromOld.push({
|
|
16
|
+
_key: key,
|
|
17
|
+
_oldIndex: i,
|
|
18
|
+
_removedBefore: removedBefore++,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { _indexMap, _removedFromOld };
|
|
12
23
|
};
|
|
13
24
|
export const useArrayMutation = (array, keyFn) => {
|
|
14
25
|
const [result, setResult] = useSignal({
|
|
15
26
|
_mutations: [],
|
|
16
27
|
_map: new Map(),
|
|
17
|
-
}
|
|
28
|
+
});
|
|
18
29
|
let indexMap = new Map();
|
|
19
30
|
useEffect(() => {
|
|
20
31
|
const mutations = [];
|
|
21
32
|
const oldIndexMap = indexMap;
|
|
22
|
-
const newIndexMap = getIndexMap(array(), keyFn);
|
|
23
|
-
const transformToOldIndex = (i = NaN) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
const { _indexMap: newIndexMap, _removedFromOld } = getIndexMap(array(), keyFn, oldIndexMap);
|
|
34
|
+
const transformToOldIndex = (i = NaN) => {
|
|
35
|
+
let index = i;
|
|
36
|
+
for (const mutation of mutations) {
|
|
37
|
+
if (isNaN(index))
|
|
38
|
+
break;
|
|
39
|
+
if (mutation._type == "r") {
|
|
40
|
+
index =
|
|
41
|
+
index < mutation._index
|
|
42
|
+
? index
|
|
43
|
+
: index == mutation._index
|
|
44
|
+
? NaN
|
|
45
|
+
: index - 1;
|
|
46
|
+
}
|
|
47
|
+
else if (mutation._type == "a") {
|
|
48
|
+
index = index < mutation._index ? index : index + 1;
|
|
49
|
+
}
|
|
50
|
+
else if (mutation._type == "m") {
|
|
51
|
+
index =
|
|
52
|
+
mutation._to <= index && index < mutation._from
|
|
53
|
+
? index + 1
|
|
54
|
+
: index == mutation._from
|
|
55
|
+
? mutation._to
|
|
56
|
+
: index;
|
|
57
|
+
}
|
|
44
58
|
}
|
|
59
|
+
return index;
|
|
60
|
+
};
|
|
61
|
+
for (const entry of _removedFromOld) {
|
|
62
|
+
mutations.push({
|
|
63
|
+
_type: "r",
|
|
64
|
+
_key: entry._key,
|
|
65
|
+
_index: entry._oldIndex - entry._removedBefore,
|
|
66
|
+
});
|
|
45
67
|
}
|
|
46
|
-
for (
|
|
47
|
-
const key = keyFn(array()[i], i);
|
|
68
|
+
for (const [key, i] of newIndexMap) {
|
|
48
69
|
const oldIndex = transformToOldIndex(oldIndexMap.get(key));
|
|
49
70
|
if (isNaN(oldIndex)) {
|
|
50
71
|
mutations.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array_mutation.js","sourceRoot":"","sources":["../src/array_mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,GAAG,CAClB,KAAmB,EACnB,KAA2C,
|
|
1
|
+
{"version":3,"file":"array_mutation.js","sourceRoot":"","sources":["../src/array_mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,GAAG,CAClB,KAAmB,EACnB,KAA2C,EAC3C,WAAiC,EAQjC,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAE/B,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,GAAG,CAAC,CAAC;QAC5C,CAAC;QAED,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,eAAe,GAIhB,EAAE,CAAC;IACR,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,CAAC,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AC,IAAI,CAAC;oBACb,KAAK,EAAE,GAAG;oBACV,IAAI,EAAE,GAAG;oBACT,KAAK,EAAE,QAAQ;oBACf,GAAG,EAAE,CAAC;iBACP,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,SAAS,CAAC;gBACR,UAAU,EAAE,SAAS;gBACrB,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,GAAG,WAAW,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/bundle.d.ts
CHANGED
|
@@ -907,7 +907,7 @@ type _CustomEventContructor<T> = undefined extends T ? typeof CustomEvent<T> : E
|
|
|
907
907
|
*/
|
|
908
908
|
declare const event: (() => EventMeta<_CustomEventContructor<undefined>>) & (<T>() => EventMeta<_CustomEventContructor<T>>) & (<E extends EventConstructor>(eventConstructor: E) => EventMeta<E>);
|
|
909
909
|
type Metadata = {
|
|
910
|
-
[K in keyof
|
|
910
|
+
[K in keyof _ComponentInner<any> | "props" | "events"]?: never;
|
|
911
911
|
} & {
|
|
912
912
|
[K in keyof DomProps<any>]?: never;
|
|
913
913
|
} & {
|
|
@@ -917,7 +917,7 @@ type Metadata = {
|
|
|
917
917
|
};
|
|
918
918
|
declare const componentSym: unique symbol;
|
|
919
919
|
declare const jsxPropsSym: unique symbol;
|
|
920
|
-
declare abstract class
|
|
920
|
+
declare abstract class _ComponentInner<M extends Metadata> {
|
|
921
921
|
protected props: Props<M>;
|
|
922
922
|
protected events: EventEmitters<M>;
|
|
923
923
|
readonly [jsxPropsSym]?: ComponentJsxProps<M>;
|
|
@@ -960,7 +960,7 @@ interface ComponentOptions {
|
|
|
960
960
|
declare const useMountEffect: (fn: () => Cleanup, deps?: SignalLike<unknown>[]) => void;
|
|
961
961
|
type Component<M extends Metadata = {}> = {
|
|
962
962
|
-readonly [K in keyof Props<M>]: Props<M>[K] extends Signal<infer T> ? T | undefined : never;
|
|
963
|
-
} &
|
|
963
|
+
} & _ComponentInner<M> & HTMLElement;
|
|
964
964
|
/**
|
|
965
965
|
* Creates a new web component class.
|
|
966
966
|
*
|
|
@@ -1133,5 +1133,5 @@ declare namespace JSX {
|
|
|
1133
1133
|
}
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
|
-
export { Component, Else, ElseIf, For, Fragment, If, JSX, MaybeSignal, Portal, Style, TemplateNodes, createContext, createElement, css, defineComponents, event, flushBatch, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
|
1137
|
-
export type { AttributeOptions, Children, Cleanup, ComponentConstructor, ComponentOptions, Context, DangerousHtml, EventConstructor, FunctionalComponent, Metadata, PropOptions, RefSignal, RefSignalSetter, SetSignalOptions, Signal, SignalLike, SignalSetter, Styles, SubscopeOptions, Template };
|
|
1136
|
+
export { Component, Else, ElseIf, For, Fragment, If, JSX, MaybeSignal, Portal, Style, TemplateNodes, _ComponentInner, createContext, createElement, css, defineComponents, event, flushBatch, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
|
1137
|
+
export type { AttributeOptions, Children, Cleanup, ComponentConstructor, ComponentOptions, Context, DangerousHtml, EventConstructor, EventMeta, FunctionalComponent, Metadata, PropMeta, PropOptions, RefSignal, RefSignalSetter, SetSignalOptions, Signal, SignalLike, SignalSetter, Styles, SubscopeOptions, Template };
|
package/dist/bundle.js
CHANGED
|
@@ -859,52 +859,73 @@ const h = new Proxy(createElement, {
|
|
|
859
859
|
get: (target, type) => (props, children) => target(type, props, children),
|
|
860
860
|
});
|
|
861
861
|
|
|
862
|
-
const getIndexMap = (array, keyFn) => {
|
|
863
|
-
const
|
|
862
|
+
const getIndexMap = (array, keyFn, oldIndexMap) => {
|
|
863
|
+
const _indexMap = new Map();
|
|
864
864
|
for (let i = 0; i < array.length; i++) {
|
|
865
865
|
const key = keyFn(array[i], i);
|
|
866
|
-
if (
|
|
866
|
+
if (_indexMap.has(key)) {
|
|
867
867
|
throw new Error(`Duplicate key '${key}'`);
|
|
868
868
|
}
|
|
869
|
-
|
|
869
|
+
_indexMap.set(key, i);
|
|
870
|
+
}
|
|
871
|
+
const _removedFromOld = [];
|
|
872
|
+
let removedBefore = 0;
|
|
873
|
+
for (const [key, i] of oldIndexMap) {
|
|
874
|
+
if (!_indexMap.has(key)) {
|
|
875
|
+
_removedFromOld.push({
|
|
876
|
+
_key: key,
|
|
877
|
+
_oldIndex: i,
|
|
878
|
+
_removedBefore: removedBefore++,
|
|
879
|
+
});
|
|
880
|
+
}
|
|
870
881
|
}
|
|
871
|
-
return
|
|
882
|
+
return { _indexMap, _removedFromOld };
|
|
872
883
|
};
|
|
873
884
|
const useArrayMutation = (array, keyFn) => {
|
|
874
885
|
const [result, setResult] = useSignal({
|
|
875
886
|
_mutations: [],
|
|
876
887
|
_map: new Map(),
|
|
877
|
-
}
|
|
888
|
+
});
|
|
878
889
|
let indexMap = new Map();
|
|
879
890
|
useEffect(() => {
|
|
880
891
|
const mutations = [];
|
|
881
892
|
const oldIndexMap = indexMap;
|
|
882
|
-
const newIndexMap = getIndexMap(array(), keyFn);
|
|
883
|
-
const transformToOldIndex = (i = NaN) =>
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
893
|
+
const { _indexMap: newIndexMap, _removedFromOld } = getIndexMap(array(), keyFn, oldIndexMap);
|
|
894
|
+
const transformToOldIndex = (i = NaN) => {
|
|
895
|
+
let index = i;
|
|
896
|
+
for (const mutation of mutations) {
|
|
897
|
+
if (isNaN(index))
|
|
898
|
+
break;
|
|
899
|
+
if (mutation._type == "r") {
|
|
900
|
+
index =
|
|
901
|
+
index < mutation._index
|
|
902
|
+
? index
|
|
903
|
+
: index == mutation._index
|
|
904
|
+
? NaN
|
|
905
|
+
: index - 1;
|
|
906
|
+
}
|
|
907
|
+
else if (mutation._type == "a") {
|
|
908
|
+
index = index < mutation._index ? index : index + 1;
|
|
909
|
+
}
|
|
910
|
+
else if (mutation._type == "m") {
|
|
911
|
+
index =
|
|
912
|
+
mutation._to <= index && index < mutation._from
|
|
913
|
+
? index + 1
|
|
914
|
+
: index == mutation._from
|
|
915
|
+
? mutation._to
|
|
916
|
+
: index;
|
|
917
|
+
}
|
|
904
918
|
}
|
|
919
|
+
return index;
|
|
920
|
+
};
|
|
921
|
+
for (const entry of _removedFromOld) {
|
|
922
|
+
mutations.push({
|
|
923
|
+
_type: "r",
|
|
924
|
+
_key: entry._key,
|
|
925
|
+
_index: entry._oldIndex - entry._removedBefore,
|
|
926
|
+
});
|
|
905
927
|
}
|
|
906
|
-
for (
|
|
907
|
-
const key = keyFn(array()[i], i);
|
|
928
|
+
for (const [key, i] of newIndexMap) {
|
|
908
929
|
const oldIndex = transformToOldIndex(oldIndexMap.get(key));
|
|
909
930
|
if (isNaN(oldIndex)) {
|
|
910
931
|
mutations.push({
|
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>({t:t,o:new Set,i:new Set,l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},
|
|
1
|
+
const t=t=>({t:t,o:new Set,i:new Set,l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},_(){[...this.i].forEach((t,n,e)=>{e[e.length-1-n]._()}),this.i=new Set,[...this.o].forEach((t,n,e)=>{const o=e[e.length-1-n];o.p?.(),o.u=()=>{},o.h.forEach(t=>t.o.delete(o)),o.h.clear()}),this.o=new Set}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.h.add(r),r.o.add(n)),r.peek());r.o=new Set,r.peek=()=>t;const c=(n,s)=>{const l={...o,...s};if(l.equals??=(t,n)=>t===n,e){const o="function"==typeof n?n(r.peek()):n;!l?.force&&l.equals(o,r.peek())||(l?.force?t=o:e.m.push(()=>t=o),l?.silent||r.o.forEach(t=>{t.v?e.S.add(t):e.o.add(t)}))}else i(()=>c(n,l))};return[r,c]},i=t=>{if(e)return t();e={m:[],o:new Set,S:new Set};try{const n=t();return l(),n}finally{e=void 0}},l=()=>{for(;e&&e.m.length+e.o.size+e.S.size>0;){e.o.forEach(t=>t.p?.()),e.m.forEach(t=>t()),e.m=[];const t=e.S.values().next().value??e.o.values().next().value;t&&(t.u(),e.S.delete(t),e.o.delete(t))}};let u=!1;const f=(t,e)=>{const r=!!e,c={M:o,v:u,h:new Set,u(){const o=n,c=s;n=this;try{this.h.forEach(t=>t.o.delete(this)),this.h.clear(),e&&(s=!1,e.forEach(t=>t())),s=r,this.p?.();const n=this.M.u(()=>i(t));this.p=n?()=>{this.M.u(()=>i(n)),this.p=null}:null}finally{n=o,s=c}}};o.o.add(c),c.u(),c.h.size||c.p||o.o.delete(c)},a=(t,n)=>{const[e,o]=c(void 0,n);let s=!0;u=!0;try{f(()=>{o(t,s?{force:!0}:{}),s=!1})}finally{u=!1}return e},d=(n,s)=>{const r=e;e=void 0;const c=o,i=t(c);Object.assign(i.l,s?.details);try{c.i.add(i);return[i.u(n),()=>{c.i.delete(i),i._()}]}finally{e=r}},_=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},p={upgrade:t=>()=>p.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},h=(t={})=>({k:[],C(t){return this.N?.next().value??t()},...t}),y=()=>{const t=r();return t.l.j??=h()},m=(t,n)=>{const e=y(),o=h({...e,...t}),[s,r]=d(n,{details:{j:o}});return f(()=>r),s},w=t=>(t[0]??"").toLowerCase()+t.slice(1).replace(/[A-Z]/g,t=>"-"+t.toLowerCase()),v=t=>t.startsWith("on:")?t.slice(3):w(t.slice(2)),b=Symbol(),g=(t,n)=>({[b]:Math.random().toString(36).slice(2),O:t,A:n}),S=t=>!!t?.[b],x=(t,n,e)=>{n.addEventListener(t[b],t=>{const n=p.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))})},M=t=>{const n=y();return a(()=>{let e=t.O;return n.H?.dispatchEvent(new CustomEvent(t[b],{detail:t=>e=t,bubbles:!0,composed:!0})),e})};var k;!function(t){t.forEach=(n,e)=>n.forEach(n=>Array.isArray(n)?t.forEach(n,e):e(n)),t.last=(n,e=n.length-1)=>{if(n.length)for(let o=e;o>=0;o--){const e=n[o];if(!Array.isArray(e))return e;const s=t.last(e);if(s)return s}}}(k||(k={}));const C=t=>({build(){const n=t();return n.build?.()??n}}),E=(t,n)=>({L:"p",T:t,...n}),N=(t=CustomEvent)=>({L:"e",I:t}),j=Symbol();let O;const A=(t,n)=>{O?O.push([t,n]):f(t,n)},H=(t,n,e)=>{const o="string"==typeof t?t:null,s="string"==typeof t?n:t,i=("string"==typeof t?e:n)??{},l=[],u=new Map;for(const t in s){const n=s[t];if("p"==n.L&&n.attribute){"function"==typeof n.attribute&&(n.attribute={transform:n.attribute});const e=n.attribute={name:w(t),static:!1,transform:t=>t,...n.attribute};u.set(e.name,{name:t,meta:n}),e.static||l.push(e.name)}}i.shadow??={mode:"open"};class a extends HTMLElement{static[j]={D:o};static observedAttributes=l;props={};events={};[j]={};constructor(){super();for(const t in s){const n=s[t];if("p"==n.L){const e=S(n.T)?n.T:null,[o,s]=c(e?void 0:n.T);this.props[t]=o,e&&x(e,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s(()=>e||void 0!==t?t:n.T,{force:!0})})}else if("e"==n.L&&t.startsWith("on")){const e=v(t);this.events[t]=t=>this.dispatchEvent(new n.I(e,t))}}}connectedCallback(){const t=(n=this,i.shadow?n.shadowRoot??n.attachShadow(i.shadow):n);var n;this[j].F=d(()=>m({$:!1,H:this,N:t.childNodes.values()},()=>{this[j].M=r();const n=O;O=[];try{k.forEach(this.render().build(),n=>{t.append(n)}),O.forEach(([t,n])=>f(t,n))}finally{O=n}}))[1]}disconnectedCallback(){this[j].F?.()}attributeChangedCallback(t,n,e){const o=u.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):void 0)}}return a},L=t=>!!t?.[j],T=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+(t[j].D??w(t.name)),t)},I=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,D=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||I.test(n)?""+e:e+"px"},F=(t,n,e,o)=>{const s=null==e||!1===e&&!n.includes("-");if(n.startsWith("prop:"))t[n.slice(5)]=e;else if(n.startsWith("attr:"))n=n.slice(5),s?t.removeAttribute(n):t.setAttribute(n,e);else if(!["innerHTML","outerHTML"].includes(n)){if(!["tabIndex","role",...o?["width","height","href","list","form","download","rowSpan","colSpan"]:[]].includes(n)&&n in t)try{return void(t[n]=e)}catch(t){}"function"==typeof e||(s?t.removeAttribute(n):t.setAttribute(n,e))}},$=({text:t,marker:n})=>C(()=>{const e=y(),o=n&&e.C(()=>document.createComment("")),s=e.C(()=>document.createTextNode(""));return f(()=>{const n=""+(p.get(t)??"");s.textContent!=n&&(s.textContent=n)}),o?[o,s]:[s]}),z=({children:t})=>C(()=>Array.isArray(t)?t.flatMap(t=>z({children:t}).build()):null==t?[]:["object"==typeof t?t.build():$({text:t}).build()]),B=(t,n,e,o)=>{const{ref:s,style:c,children:l,dangerouslySetInnerHTML:u,...a}=e;for(const n in c??{}){const e=c[n];f(()=>{D(t,n,p.get(e))})}for(const n in a){const e=a[n];if(n.startsWith("on")){const o=r(),s=t=>{o.u(()=>i(()=>e(t)))},c=v(n);f(()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s)))}else f(()=>{F(t,n,p.get(e),o)})}return u&&f(()=>{const n=p.get(u).__html;t.innerHTML!=n&&(t.innerHTML=n)}),s&&f(()=>(s.set(t),()=>s.set(void 0))),null!=e.children&&k.forEach(m({$:n,N:t.childNodes.values()},()=>z({children:e.children}).build()),n=>t.append(n)),t},P=(t,n={},e)=>(null!=e&&(n.children=e),L(t)?((t,n)=>C(()=>{const e=y().C(()=>new t);return customElements.upgrade(e),B(e,!1,n),[e]}))(t,n):"function"==typeof t?C(()=>t(n)):((t,n={})=>C(()=>{const e=y(),o="svg"==t||!!e.$;return[B(e.C(()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t)),(!o||"foreignObject"!==t)&&o,n,!0)]}))(t,n)),V=new Proxy(P,{get:(t,n)=>(e,o)=>t(n,e,o)}),Z=(t,n)=>{const[e,o]=c({B:[],P:new Map});let s=new Map;return f(()=>{const e=[],r=s,{V:c,Z:i}=((t,n,e)=>{const o=new Map;for(let e=0;e<t.length;e++){const s=n(t[e],e);if(o.has(s))throw Error(`Duplicate key '${s}'`);o.set(s,e)}const s=[];let r=0;for(const[t,n]of e)o.has(t)||s.push({q:t,G:n,J:r++});return{V:o,Z:s}})(t(),n,r),l=(t=NaN)=>{let n=t;for(const t of e){if(isNaN(n))break;"r"==t.K?n=n<t.R?n:n==t.R?NaN:n-1:"a"==t.K?n=n<t.R?n:n+1:"m"==t.K&&(n=t.U<=n&&n<t.W?n+1:n==t.W?t.U:n)}return n};for(const t of i)e.push({K:"r",q:t.q,R:t.G-t.J});for(const[t,n]of c){const o=l(r.get(t));isNaN(o)?e.push({K:"a",q:t,R:n}):o!=n&&e.push({K:"m",q:t,W:o,U:n})}e.length>0&&o({B:e,P:c}),s=c}),e},q=t=>C(()=>{const n=y(),e=p.upgrade(t.each??[]),o=n.C(()=>document.createComment("")),s=t.key??((t,n)=>n),r=[o,[]],i=new Map,l=Z(e,s),u=t=>k.last(r[1],t-1)??o;return f(()=>{for(const n of l().B)if("r"==n.K){const{X:t,F:e}=i.get(n.q)??{};e?.(),r[1].splice(n.R,1),k.forEach(t??[],t=>t.parentNode?.removeChild(t)),i.delete(n.q)}else if("a"==n.K){let o;const[,s]=d(()=>{const[s,i]=c(n.R),[a,d]=c(e()[n.R]);f(()=>{0<=s()&&s()<e().length&&d(()=>e()[s()])}),f(()=>{const t=l().P.get(n.q);null!=t&&i(t)}),o=t.children?.(a,s,e).build()??[],r[1].splice(n.R,0,o);let _=u(n.R);k.forEach(o,t=>{_.parentNode?.insertBefore(t,_.nextSibling),_=t})});i.set(n.q,{X:o,F:s})}else if("m"==n.K){const{X:t}=i.get(n.q)??{};r[1].splice(n.W,1),r[1].splice(n.U,0,t??[]);let e=u(n.U);k.forEach(t??[],t=>{e.parentNode?.insertBefore(t,e.nextSibling),e=t})}},[l]),r}),G=t=>(y().k=[],J({condition:t.condition,children:t.children})),J=t=>{const n=y(),e=n.k,o=p.upgrade(t.condition),s=a(()=>e.every(t=>!t())&&o());return n.k=[...e,o],C(()=>m({k:[]},()=>{const e=n.C(()=>document.createComment("")),o=[e,[]],r=a(()=>s()?z({children:t.children}):null);let c=[];return f(()=>{k.forEach(c,t=>t.parentNode?.removeChild(t)),o[1]=[];const[,t]=d(()=>{c=r()?.build()??[],o[1]=c;let t=e;k.forEach(c,n=>{t.parentNode?.insertBefore(n,t.nextSibling),t=n})});return t},[r]),o}))},K=({children:t})=>J({condition:!0,children:t}),Q=({mount:t,children:n})=>C(()=>m({N:void 0},()=>{const e=z({children:n}).build();return f(()=>(k.forEach(e,n=>t.appendChild(n)),()=>{k.forEach(e,t=>t.parentNode?.removeChild(t))}),[]),[]})),R=Symbol(),U=new Map,W=t=>{const n=t.children;if("function"==typeof n){const e=P("style",{},$({text:n,marker:!1}));return t.light?Q({mount:document.head,children:e}):e}if(n){const o=y(),s=t.light?document:o.H?.shadowRoot??document,r=((t,n,e)=>{if(!U.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),U.set(n,{Y:t,tt:0})}const o=U.get(n);o.tt++,t.has(n)||t.set(n,{Y:o.Y,tt:0});const s=t.get(n);return s.tt++,f(()=>()=>{--s.tt||(t.delete(n),e()),--o.tt||U.delete(n)}),s.Y})((e=s,e[R]??=new Map),n,()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter(t=>t!=r)});s.adoptedStyleSheets.push(r)}var e;return z({})},X=(t,...n)=>{const e=()=>t.reduce((t,e,o)=>t+e+(p.get(n[o])??""),"");return n.some(t=>"function"==typeof t)?e:e()},Y=(t,n,e)=>(n&&null!=e&&(n.key=e),P(t,n));export{H as Component,K as Else,J as ElseIf,q as For,z as Fragment,G as If,p as MaybeSignal,Q as Portal,W as Style,k as TemplateNodes,g as createContext,P as createElement,X as css,T as defineComponents,N as event,l as flushBatch,V as h,L as isComponent,Y as jsx,Y as jsxDEV,Y as jsxs,E as prop,i as useBatch,M as useContext,A as useEffect,a as useMemo,_ as useRef,c as useSignal,d as useSubscope};
|
package/dist/component.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ type _CustomEventContructor<T> = undefined extends T ? typeof CustomEvent<T> : E
|
|
|
147
147
|
*/
|
|
148
148
|
export declare const event: (() => EventMeta<_CustomEventContructor<undefined>>) & (<T>() => EventMeta<_CustomEventContructor<T>>) & (<E extends EventConstructor>(eventConstructor: E) => EventMeta<E>);
|
|
149
149
|
export type Metadata = {
|
|
150
|
-
[K in keyof
|
|
150
|
+
[K in keyof _ComponentInner<any> | "props" | "events"]?: never;
|
|
151
151
|
} & {
|
|
152
152
|
[K in keyof DomProps<any>]?: never;
|
|
153
153
|
} & {
|
|
@@ -157,7 +157,7 @@ export type Metadata = {
|
|
|
157
157
|
};
|
|
158
158
|
export declare const componentSym: unique symbol;
|
|
159
159
|
export declare const jsxPropsSym: unique symbol;
|
|
160
|
-
declare abstract class
|
|
160
|
+
export declare abstract class _ComponentInner<M extends Metadata> {
|
|
161
161
|
protected props: Props<M>;
|
|
162
162
|
protected events: EventEmitters<M>;
|
|
163
163
|
readonly [jsxPropsSym]?: ComponentJsxProps<M>;
|
|
@@ -174,7 +174,7 @@ declare abstract class ComponentInner<M extends Metadata> {
|
|
|
174
174
|
}
|
|
175
175
|
export type Component<M extends Metadata = {}> = {
|
|
176
176
|
-readonly [K in keyof Props<M>]: Props<M>[K] extends Signal<infer T> ? T | undefined : never;
|
|
177
|
-
} &
|
|
177
|
+
} & _ComponentInner<M> & HTMLElement;
|
|
178
178
|
export interface ComponentConstructor<M extends Metadata = {}> {
|
|
179
179
|
/** @ignore */
|
|
180
180
|
readonly [componentSym]: {
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,WAAW,EACX,SAAS,GAEV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,oBAAoB,EAGpB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAW,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAY,aAAa,EAAE,MAAM,eAAe,CAAC;AAmKxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,IAAI,GAQiB,CAChC,gBAAiC,EACjC,IAAqB,EACN,EAAE,CAAC,CAAC;IACnB,IAAI,EAAE,GAAG;IACT,iBAAiB,EAAE,gBAAgB;IACnC,GAAG,IAAI;CACR,CAAC,CAAC;AAaH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,KAAK,GAEsD,CAAC,CACvE,mBAAqC,WAAW,EACn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AG,IAAgE,EACnE,EAAE;IACF,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GACxB,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ;QACxB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAA2B,CAAC;QACpD,CAAC,CAAC,CAAC,EAAE,EAAE,IAA8B,CAAC,CAAC;IAE3C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,cAAc,CAAC,MAAM,CACnB,MAAM;YACJ,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ;gBAC/B,oBAAoB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EACzC,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Component, defineComponents, event, isComponent, prop, useMountEffect as useEffect, type AttributeOptions, type Metadata, type PropOptions, type PropMeta, type EventMeta, type ComponentConstructor, type _ComponentInner, type ComponentOptions, type FunctionalComponent, type EventConstructor, } from "./component.js";
|
|
2
2
|
export { type Context, createContext, useContext } from "./context.js";
|
|
3
3
|
export { createElement, h } from "./create_element.js";
|
|
4
4
|
export { type DangerousHtml, type Styles } from "./dom.js";
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,IAAI,EACJ,cAAc,IAAI,SAAS,GAW5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAiB,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAEL,WAAW,EAQX,WAAW,EACX,OAAO,EACP,SAAS,EACT,MAAM,EACN,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
package/package.json
CHANGED
package/src/array_mutation.ts
CHANGED
|
@@ -3,20 +3,45 @@ import { Signal, SignalLike, useEffect, useSignal } from "./scope.js";
|
|
|
3
3
|
const getIndexMap = <T>(
|
|
4
4
|
array: readonly T[],
|
|
5
5
|
keyFn: (entry: T, index: number) => unknown,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
oldIndexMap: Map<unknown, number>,
|
|
7
|
+
): {
|
|
8
|
+
_indexMap: Map<unknown, number>;
|
|
9
|
+
_removedFromOld: Array<{
|
|
10
|
+
_key: unknown;
|
|
11
|
+
_oldIndex: number;
|
|
12
|
+
_removedBefore: number;
|
|
13
|
+
}>;
|
|
14
|
+
} => {
|
|
15
|
+
const _indexMap = new Map<unknown, number>();
|
|
8
16
|
|
|
9
17
|
for (let i = 0; i < array.length; i++) {
|
|
10
18
|
const key = keyFn(array[i], i);
|
|
11
19
|
|
|
12
|
-
if (
|
|
20
|
+
if (_indexMap.has(key)) {
|
|
13
21
|
throw new Error(`Duplicate key '${key}'`);
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
_indexMap.set(key, i);
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
const _removedFromOld: Array<{
|
|
28
|
+
_key: unknown;
|
|
29
|
+
_oldIndex: number;
|
|
30
|
+
_removedBefore: number;
|
|
31
|
+
}> = [];
|
|
32
|
+
let removedBefore = 0;
|
|
33
|
+
|
|
34
|
+
for (const [key, i] of oldIndexMap) {
|
|
35
|
+
if (!_indexMap.has(key)) {
|
|
36
|
+
_removedFromOld.push({
|
|
37
|
+
_key: key,
|
|
38
|
+
_oldIndex: i,
|
|
39
|
+
_removedBefore: removedBefore++,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { _indexMap, _removedFromOld };
|
|
20
45
|
};
|
|
21
46
|
|
|
22
47
|
export type ArrayMutation =
|
|
@@ -41,54 +66,59 @@ export const useArrayMutation = <T extends unknown>(
|
|
|
41
66
|
array: SignalLike<readonly T[]>,
|
|
42
67
|
keyFn: (entry: T, index: number) => unknown,
|
|
43
68
|
): Signal<ArrayMutationResult> => {
|
|
44
|
-
const [result, setResult] = useSignal<ArrayMutationResult>(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
{ force: true },
|
|
50
|
-
);
|
|
69
|
+
const [result, setResult] = useSignal<ArrayMutationResult>({
|
|
70
|
+
_mutations: [],
|
|
71
|
+
_map: new Map(),
|
|
72
|
+
});
|
|
51
73
|
|
|
52
74
|
let indexMap = new Map<unknown, number>();
|
|
53
75
|
|
|
54
76
|
useEffect(() => {
|
|
55
77
|
const mutations: ArrayMutation[] = [];
|
|
56
78
|
const oldIndexMap = indexMap;
|
|
57
|
-
const newIndexMap = getIndexMap(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
79
|
+
const { _indexMap: newIndexMap, _removedFromOld } = getIndexMap(
|
|
80
|
+
array(),
|
|
81
|
+
keyFn,
|
|
82
|
+
oldIndexMap,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const transformToOldIndex = (i: number = NaN) => {
|
|
86
|
+
let index = i;
|
|
87
|
+
|
|
88
|
+
for (const mutation of mutations) {
|
|
89
|
+
if (isNaN(index)) break;
|
|
90
|
+
|
|
91
|
+
if (mutation._type == "r") {
|
|
92
|
+
index =
|
|
93
|
+
index < mutation._index
|
|
94
|
+
? index
|
|
95
|
+
: index == mutation._index
|
|
96
|
+
? NaN
|
|
97
|
+
: index - 1;
|
|
98
|
+
} else if (mutation._type == "a") {
|
|
99
|
+
index = index < mutation._index ? index : index + 1;
|
|
100
|
+
} else if (mutation._type == "m") {
|
|
101
|
+
index =
|
|
102
|
+
mutation._to <= index && index < mutation._from
|
|
103
|
+
? index + 1
|
|
104
|
+
: index == mutation._from
|
|
105
|
+
? mutation._to
|
|
106
|
+
: index;
|
|
107
|
+
}
|
|
87
108
|
}
|
|
109
|
+
|
|
110
|
+
return index;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
for (const entry of _removedFromOld) {
|
|
114
|
+
mutations.push({
|
|
115
|
+
_type: "r",
|
|
116
|
+
_key: entry._key,
|
|
117
|
+
_index: entry._oldIndex - entry._removedBefore,
|
|
118
|
+
});
|
|
88
119
|
}
|
|
89
120
|
|
|
90
|
-
for (
|
|
91
|
-
const key = keyFn(array()[i], i);
|
|
121
|
+
for (const [key, i] of newIndexMap) {
|
|
92
122
|
const oldIndex = transformToOldIndex(oldIndexMap.get(key));
|
|
93
123
|
|
|
94
124
|
if (isNaN(oldIndex)) {
|
package/src/component.ts
CHANGED
|
@@ -301,7 +301,7 @@ export const event: (() => EventMeta<_CustomEventContructor<undefined>>) &
|
|
|
301
301
|
|
|
302
302
|
export type Metadata = {
|
|
303
303
|
// Forbid all library properties
|
|
304
|
-
[K in keyof
|
|
304
|
+
[K in keyof _ComponentInner<any> | "props" | "events"]?: never;
|
|
305
305
|
} & {
|
|
306
306
|
// Forbid all dom props
|
|
307
307
|
[K in keyof DomProps<any>]?: never;
|
|
@@ -315,7 +315,7 @@ export type Metadata = {
|
|
|
315
315
|
export const componentSym = Symbol("Component");
|
|
316
316
|
export declare const jsxPropsSym: unique symbol;
|
|
317
317
|
|
|
318
|
-
declare abstract class
|
|
318
|
+
export declare abstract class _ComponentInner<M extends Metadata> {
|
|
319
319
|
protected props: Props<M>;
|
|
320
320
|
protected events: EventEmitters<M>;
|
|
321
321
|
|
|
@@ -361,7 +361,7 @@ export type Component<M extends Metadata = {}> = {
|
|
|
361
361
|
-readonly [K in keyof Props<M>]: Props<M>[K] extends Signal<infer T>
|
|
362
362
|
? T | undefined
|
|
363
363
|
: never;
|
|
364
|
-
} &
|
|
364
|
+
} & _ComponentInner<M> &
|
|
365
365
|
HTMLElement;
|
|
366
366
|
|
|
367
367
|
export interface ComponentConstructor<M extends Metadata = {}> {
|
|
@@ -516,7 +516,7 @@ export const Component: ((tagName?: string) => ComponentConstructor<{}>) &
|
|
|
516
516
|
protected props: Record<string, Signal<any>> = {};
|
|
517
517
|
protected events: Record<string, (arg: unknown) => any> = {};
|
|
518
518
|
|
|
519
|
-
readonly [componentSym]:
|
|
519
|
+
readonly [componentSym]: _ComponentInner<any>[typeof componentSym] = {};
|
|
520
520
|
|
|
521
521
|
constructor() {
|
|
522
522
|
super();
|
package/src/mod.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
export {
|
|
2
|
-
type AttributeOptions,
|
|
3
2
|
Component,
|
|
4
|
-
type ComponentConstructor,
|
|
5
|
-
type ComponentOptions,
|
|
6
3
|
defineComponents,
|
|
7
4
|
event,
|
|
8
|
-
type EventConstructor,
|
|
9
|
-
type FunctionalComponent,
|
|
10
5
|
isComponent,
|
|
11
|
-
type Metadata,
|
|
12
6
|
prop,
|
|
13
|
-
type PropOptions,
|
|
14
7
|
useMountEffect as useEffect,
|
|
8
|
+
type AttributeOptions,
|
|
9
|
+
type Metadata,
|
|
10
|
+
type PropOptions,
|
|
11
|
+
type PropMeta,
|
|
12
|
+
type EventMeta,
|
|
13
|
+
type ComponentConstructor,
|
|
14
|
+
type _ComponentInner,
|
|
15
|
+
type ComponentOptions,
|
|
16
|
+
type FunctionalComponent,
|
|
17
|
+
type EventConstructor,
|
|
15
18
|
} from "./component.js";
|
|
16
19
|
export { type Context, createContext, useContext } from "./context.js";
|
|
17
20
|
export { createElement, h } from "./create_element.js";
|