sinho 0.2.3 → 0.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.
Files changed (47) hide show
  1. package/dist/array_mutation.js +1 -1
  2. package/dist/array_mutation.js.map +1 -1
  3. package/dist/bundle.d.ts +7 -2
  4. package/dist/bundle.js +73 -64
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/component.js +4 -1
  7. package/dist/component.js.map +1 -1
  8. package/dist/intrinsic/Dynamic.d.ts +33 -0
  9. package/dist/intrinsic/Dynamic.js +53 -0
  10. package/dist/intrinsic/Dynamic.js.map +1 -0
  11. package/dist/intrinsic/ErrorBoundary.d.ts +14 -0
  12. package/dist/intrinsic/ErrorBoundary.js +36 -0
  13. package/dist/intrinsic/ErrorBoundary.js.map +1 -0
  14. package/dist/intrinsic/For.js +21 -36
  15. package/dist/intrinsic/For.js.map +1 -1
  16. package/dist/intrinsic/Fragment.d.ts +1 -1
  17. package/dist/intrinsic/Fragment.js +5 -3
  18. package/dist/intrinsic/Fragment.js.map +1 -1
  19. package/dist/intrinsic/If.js +16 -12
  20. package/dist/intrinsic/If.js.map +1 -1
  21. package/dist/intrinsic/Portal.js +4 -4
  22. package/dist/intrinsic/Portal.js.map +1 -1
  23. package/dist/intrinsic/TagComponent.js +3 -3
  24. package/dist/intrinsic/TagComponent.js.map +1 -1
  25. package/dist/mod.d.ts +2 -2
  26. package/dist/mod.js +1 -0
  27. package/dist/mod.js.map +1 -1
  28. package/dist/renderer.d.ts +1 -1
  29. package/dist/template.d.ts +7 -2
  30. package/dist/template.js +16 -0
  31. package/dist/template.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/array_mutation.ts +7 -4
  34. package/src/component.ts +4 -2
  35. package/src/intrinsic/For.ts +26 -43
  36. package/src/intrinsic/Fragment.ts +6 -4
  37. package/src/intrinsic/If.ts +22 -16
  38. package/src/intrinsic/Portal.ts +6 -4
  39. package/src/intrinsic/TagComponent.ts +4 -3
  40. package/src/mod.ts +2 -2
  41. package/src/renderer.ts +1 -1
  42. package/src/template.ts +31 -2
  43. package/tsconfig.json +2 -1
  44. package/web/dist/shingo.min.d.ts +1131 -0
  45. package/web/dist/shingo.min.js +1 -0
  46. package/web/static/dist/bundle.d.ts +1126 -0
  47. package/web/static/dist/bundle.min.js +1 -0
@@ -14,7 +14,7 @@ export const useArrayMutation = (array, keyFn) => {
14
14
  const [result, setResult] = useSignal({
15
15
  _mutations: [],
16
16
  _map: new Map(),
17
- });
17
+ }, { force: true });
18
18
  let indexMap = new Map();
19
19
  useEffect(() => {
20
20
  const mutations = [];
@@ -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,EACrB,EAAE;IACxB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE1C,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,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,GAAG,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAoBF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,KAA+B,EAC/B,KAA2C,EACd,EAAE;IAC/B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,CAAsB;QACzD,UAAU,EAA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ts CHANGED
@@ -759,6 +759,11 @@ interface Context<in out T> {
759
759
  declare const createContext: (<T>(value: T, opts?: SetSignalOptions) => Context<T>) & (<T>(value?: T, opts?: SetSignalOptions) => Context<T | undefined>);
760
760
  declare const useContext: <T>(context: Context<T>) => Signal<T>;
761
761
 
762
+ type TemplateNodes = (Node | TemplateNodes)[];
763
+ declare namespace TemplateNodes {
764
+ const forEach: (nodes: TemplateNodes, fn: (node: Node) => void) => void;
765
+ const last: (nodes: TemplateNodes, lastIndex?: number) => Node | undefined;
766
+ }
762
767
  /**
763
768
  * Represents a render result of a component.
764
769
  */
@@ -766,7 +771,7 @@ interface Template {
766
771
  /**
767
772
  * Build the DOM elements represented by this template.
768
773
  */
769
- build(): Node[];
774
+ build(): TemplateNodes;
770
775
  }
771
776
 
772
777
  interface Tagged<in out T> {
@@ -1138,4 +1143,4 @@ declare namespace JSX {
1138
1143
  }
1139
1144
  }
1140
1145
 
1141
- export { type AttributeOptions, type Children, type Cleanup, Component, type ComponentConstructor, type ComponentOptions, type Context, type DangerousHtml, Else, ElseIf, type EventConstructor, For, Fragment, type FunctionalComponent, If, JSX, MaybeSignal, type Metadata, Portal, type PropOptions, type RefSignal, type RefSignalSetter, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, Style, type Styles, type SubscopeOptions, type Template, 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 };
1146
+ export { type AttributeOptions, type Children, type Cleanup, Component, type ComponentConstructor, type ComponentOptions, type Context, type DangerousHtml, Else, ElseIf, type EventConstructor, For, Fragment, type FunctionalComponent, If, JSX, MaybeSignal, type Metadata, Portal, type PropOptions, type RefSignal, type RefSignalSetter, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, Style, type Styles, type SubscopeOptions, type Template, 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 };
package/dist/bundle.js CHANGED
@@ -332,6 +332,29 @@ const useContext = (context) => {
332
332
  });
333
333
  };
334
334
 
335
+ var TemplateNodes;
336
+ (function (TemplateNodes) {
337
+ TemplateNodes.forEach = (nodes, fn) => nodes.forEach((node) => Array.isArray(node) ? TemplateNodes.forEach(node, fn) : fn(node));
338
+ TemplateNodes.last = (nodes, lastIndex = nodes.length - 1) => {
339
+ if (!nodes.length)
340
+ return;
341
+ for (let i = lastIndex; i >= 0; i--) {
342
+ const last = nodes[i];
343
+ if (!Array.isArray(last))
344
+ return last;
345
+ const lastNode = TemplateNodes.last(last);
346
+ if (lastNode)
347
+ return lastNode;
348
+ }
349
+ };
350
+ })(TemplateNodes || (TemplateNodes = {}));
351
+ const createTemplate = (build) => ({
352
+ build() {
353
+ const nodes = build();
354
+ return nodes.build?.() ?? nodes;
355
+ },
356
+ });
357
+
335
358
  /**
336
359
  * Defines a property in your component metadata that can be set from outside
337
360
  * of the component.
@@ -540,7 +563,9 @@ const Component = ((tagName, metadata = {}, opts = {}) => {
540
563
  const prevMountEffects = mountEffects;
541
564
  mountEffects = [];
542
565
  try {
543
- renderParent?.append(...this.render().build());
566
+ TemplateNodes.forEach(this.render().build(), (node) => {
567
+ renderParent.append(node);
568
+ });
544
569
  // Run mount effects
545
570
  mountEffects.forEach(([fn, opts]) => useEffect(fn, opts));
546
571
  }
@@ -679,13 +704,6 @@ const setAttr = (node, name, value, heuristic) => {
679
704
  }
680
705
  };
681
706
 
682
- const createTemplate = (build) => ({
683
- build() {
684
- const nodes = build();
685
- return nodes.build?.() ?? nodes;
686
- },
687
- });
688
-
689
707
  const Text = ({ text, marker }) => createTemplate(() => {
690
708
  const renderer = useRenderer();
691
709
  const anchor = marker && renderer._node(() => document.createComment(""));
@@ -719,9 +737,11 @@ const Fragment = ({ children }) => createTemplate(() => {
719
737
  return !Array.isArray(children)
720
738
  ? children == null
721
739
  ? []
722
- : typeof children == "object"
723
- ? children
724
- : Text({ text: children })
740
+ : [
741
+ typeof children == "object"
742
+ ? children.build()
743
+ : Text({ text: children }).build(),
744
+ ]
725
745
  : children.flatMap((children) => Fragment({ children }).build());
726
746
  });
727
747
 
@@ -770,10 +790,10 @@ const hydrateElement = (node, svg, props, heuristic) => {
770
790
  });
771
791
  }
772
792
  if (props.children != null) {
773
- node.append(...runWithRenderer({
793
+ TemplateNodes.forEach(runWithRenderer({
774
794
  _svg: svg,
775
795
  _nodes: node.childNodes.values(),
776
- }, () => Fragment({ children: props.children }).build()));
796
+ }, () => Fragment({ children: props.children }).build()), (subnode) => node.append(subnode));
777
797
  }
778
798
  return node;
779
799
  };
@@ -847,7 +867,7 @@ const useArrayMutation = (array, keyFn) => {
847
867
  const [result, setResult] = useSignal({
848
868
  _mutations: [],
849
869
  _map: new Map(),
850
- });
870
+ }, { force: true });
851
871
  let indexMap = new Map();
852
872
  useEffect(() => {
853
873
  const mutations = [];
@@ -914,33 +934,21 @@ const For = (props) => createTemplate(() => {
914
934
  const items = MaybeSignal.upgrade(props.each ?? []);
915
935
  const anchor = renderer._node(() => document.createComment(""));
916
936
  const keyFn = props.key ?? ((_, i) => i);
917
- const nodes = [anchor];
937
+ const nodes = [anchor, []];
918
938
  const keyMap = new Map();
919
939
  const mutationResult = useArrayMutation(items, keyFn);
920
- const lookForAnchor = (index) => {
921
- for (let i = index - 1; i >= 0; i--) {
922
- const key = keyFn(items()[index - 1], index - 1);
923
- const nodes = keyMap.get(key)?._subnodes ?? [];
924
- if (nodes.length > 0) {
925
- return nodes[nodes.length - 1];
926
- }
927
- }
928
- return anchor;
929
- };
940
+ const lookForAnchor = (index) => TemplateNodes.last(nodes[1], index - 1) ?? anchor;
930
941
  useEffect(() => {
931
942
  for (const mutation of mutationResult()._mutations) {
932
943
  if (mutation._type == "r") {
933
- const { _subnodes = [], _destroy } = keyMap.get(mutation._key) ?? {};
944
+ const { _subnodes, _destroy } = keyMap.get(mutation._key) ?? {};
934
945
  _destroy?.();
935
- const index = nodes.indexOf(_subnodes[0]);
936
- if (index > 0) {
937
- nodes.splice(index, _subnodes.length);
938
- }
939
- _subnodes.forEach((node) => node.parentNode?.removeChild(node));
946
+ nodes[1].splice(mutation._index, 1);
947
+ TemplateNodes.forEach(_subnodes ?? [], (node) => node.parentNode?.removeChild(node));
940
948
  keyMap.delete(mutation._key);
941
949
  }
942
950
  else if (mutation._type == "a") {
943
- let _subnodes = [];
951
+ let _subnodes;
944
952
  const [, destroy] = useSubscope(() => {
945
953
  const [index, setIndex] = useSignal(mutation._index);
946
954
  const [item, setItem] = useSignal(items()[mutation._index]);
@@ -956,27 +964,24 @@ const For = (props) => createTemplate(() => {
956
964
  }
957
965
  });
958
966
  _subnodes = props.children?.(item, index, items).build() ?? [];
959
- const itemAnchor = lookForAnchor(mutation._index);
960
- const anchorIndex = nodes.indexOf(itemAnchor);
961
- if (anchorIndex >= 0) {
962
- nodes.splice(anchorIndex + 1, 0, ..._subnodes);
963
- }
964
- _subnodes.forEach((node) => itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling));
967
+ nodes[1].splice(mutation._index, 0, _subnodes);
968
+ let itemAnchor = lookForAnchor(mutation._index);
969
+ TemplateNodes.forEach(_subnodes, (node) => {
970
+ itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
971
+ itemAnchor = node;
972
+ });
965
973
  });
966
974
  keyMap.set(mutation._key, { _subnodes, _destroy: destroy });
967
975
  }
968
976
  else if (mutation._type == "m") {
969
- const { _subnodes = [] } = keyMap.get(mutation._key) ?? {};
970
- const index = nodes.indexOf(_subnodes[0]);
971
- if (index >= 0) {
972
- nodes.splice(index, _subnodes.length);
973
- }
974
- const itemAnchor = lookForAnchor(mutation._to);
975
- const anchorIndex = nodes.indexOf(itemAnchor);
976
- if (anchorIndex >= 0) {
977
- nodes.splice(anchorIndex + 1, 0, ..._subnodes);
978
- }
979
- _subnodes.forEach((node) => itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling));
977
+ const { _subnodes } = keyMap.get(mutation._key) ?? {};
978
+ nodes[1].splice(mutation._from, 1);
979
+ nodes[1].splice(mutation._to, 0, _subnodes ?? []);
980
+ let itemAnchor = lookForAnchor(mutation._to);
981
+ TemplateNodes.forEach(_subnodes ?? [], (node) => {
982
+ itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
983
+ itemAnchor = node;
984
+ });
980
985
  }
981
986
  }
982
987
  }, [mutationResult]);
@@ -997,22 +1002,26 @@ const If = (props) => {
997
1002
  */
998
1003
  const ElseIf = (props) => {
999
1004
  const renderer = useRenderer();
1000
- const conditions = renderer._ifConditions;
1001
- const condition = useMemo(() => conditions.every((condition) => !condition()) &&
1002
- MaybeSignal.get(props.condition));
1003
- renderer._ifConditions = [...conditions, condition];
1004
- return runWithRenderer({ _ifConditions: [] }, () => createTemplate(() => {
1005
+ const prevConditions = renderer._ifConditions;
1006
+ const myCondition = MaybeSignal.upgrade(props.condition);
1007
+ const fullCondition = useMemo(() => prevConditions.every((condition) => !condition()) && myCondition());
1008
+ renderer._ifConditions = [...prevConditions, myCondition];
1009
+ return createTemplate(() => runWithRenderer({ _ifConditions: [] }, () => {
1005
1010
  const anchor = renderer._node(() => document.createComment(""));
1006
- const nodes = [anchor];
1007
- const template = useMemo(() => condition() ? Fragment({ children: props.children }) : null);
1011
+ const nodes = [anchor, []];
1012
+ const template = useMemo(() => fullCondition() ? Fragment({ children: props.children }) : null);
1008
1013
  let subnodes = [];
1009
1014
  useEffect(() => {
1010
- subnodes.forEach((node) => node.parentNode?.removeChild(node));
1011
- nodes.length = 1;
1015
+ TemplateNodes.forEach(subnodes, (node) => node.parentNode?.removeChild(node));
1016
+ nodes[1] = [];
1012
1017
  const [, destroy] = useSubscope(() => {
1013
1018
  subnodes = template()?.build() ?? [];
1014
- anchor.after(...subnodes);
1015
- nodes.push(...subnodes);
1019
+ nodes[1] = subnodes;
1020
+ let before = anchor;
1021
+ TemplateNodes.forEach(subnodes, (node) => {
1022
+ before.parentNode?.insertBefore(node, before.nextSibling);
1023
+ before = node;
1024
+ });
1016
1025
  });
1017
1026
  return destroy;
1018
1027
  }, [template]);
@@ -1029,11 +1038,11 @@ const Else = ({ children, }) => {
1029
1038
  const Portal = ({ mount, children }) => createTemplate(() => runWithRenderer({ _nodes: undefined }, () => {
1030
1039
  const nodes = Fragment({ children }).build();
1031
1040
  useEffect(() => {
1032
- nodes.forEach((node) => mount.appendChild(node));
1041
+ TemplateNodes.forEach(nodes, (node) => mount.appendChild(node));
1033
1042
  return () => {
1034
- nodes.forEach((node) => node.parentNode?.removeChild(node));
1043
+ TemplateNodes.forEach(nodes, (node) => node.parentNode?.removeChild(node));
1035
1044
  };
1036
- });
1045
+ }, []);
1037
1046
  return [];
1038
1047
  }));
1039
1048
 
@@ -1109,4 +1118,4 @@ const jsx = (type, props, key) => {
1109
1118
  return createElement(type, props);
1110
1119
  };
1111
1120
 
1112
- export { Component, Else, ElseIf, For, Fragment, If, MaybeSignal, Portal, Style, 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 };
1121
+ export { Component, Else, ElseIf, For, Fragment, If, 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 };
@@ -1 +1 @@
1
- const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.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._?.())),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,p:new Set,u(){const o=n,c=s;n=this;try{this.p.forEach((t=>t.o.delete(this))),this.p.clear(),e&&(s=!1,e.forEach((t=>t()))),s=r,this._?.();const n=this.M.u((()=>i(t)));this._=n?()=>{this.M.u((()=>i(n))),this._=null}:null}finally{n=o,s=c}}};o.o.push(c),c.u(),c.p.size||c._||o.o.pop()},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.push(i);return[i.u(n),()=>{const t=c.i.indexOf(i);t>=0&&c.i.splice(t,1),i.h()}]}finally{e=r}},h=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},_={upgrade:t=>()=>_.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},p=(t={})=>({k:[],C(t){return this.N?.next().value??t()},...t}),m=()=>{const t=r();return t.l.j??=p()},y=(t,n)=>{const e=m(),o=p({...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())),b=t=>t.startsWith("on:")?t.slice(3):w(t.slice(2)),v=Symbol(),g=(t,n)=>({[v]:Math.random().toString(36).slice(2),H:t,L:n}),x=t=>!!t?.[v],S=(t,n,e)=>{n.addEventListener(t[v],(t=>{const n=_.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))}))},M=t=>{const n=m();return a((()=>{let e=t.H;return n.T?.dispatchEvent(new CustomEvent(t[v],{detail:t=>e=t,bubbles:!0,composed:!0})),e}))},k=(t,n)=>({A:"p",O:t,...n}),C=(t=CustomEvent)=>({A:"e",D:t}),E=Symbol();let N;const j=(t,n)=>{N?N.push([t,n]):f(t,n)},H=(t,n={},e={})=>{const o=[],s=new Map;for(const t in n){const e=n[t];if("p"==e.A&&e.attribute){"function"==typeof e.attribute&&(e.attribute={transform:e.attribute});const n=e.attribute={name:w(t),static:!1,transform:t=>t,...e.attribute};s.set(n.name,{name:t,meta:e}),n.static||o.push(n.name)}}e.shadow??={mode:"open"};class i extends HTMLElement{static[E]={I:t};static observedAttributes=o;props={};events={};[E]={};constructor(){super();for(const t in n){const e=n[t];if("p"==e.A){const n=x(e.O)?e.O:null,[o,s]=c(n?void 0:e.O);this.props[t]=o,n&&S(n,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s((()=>t),{force:!0})})}else if("e"==e.A&&t.startsWith("on")){const n=b(t);this.events[t]=t=>this.dispatchEvent(new e.D(n,t))}}}connectedCallback(){const t=(n=this,e.shadow?n.shadowRoot??n.attachShadow(e.shadow):n);var n;this[E].$=d((()=>y({P:!1,T:this,N:t.childNodes.values()},(()=>{this[E].M=r();const n=N;N=[];try{t?.append(...this.render().build()),N.forEach((([t,n])=>f(t,n)))}finally{N=n}}))))[1]}disconnectedCallback(){this[E].$?.()}attributeChangedCallback(t,n,e){const o=s.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):x(o.meta.O)?void 0:o.meta.O)}}return i},L=t=>!!t?.[E],T=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+t[E].I,t)},A=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,O=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||A.test(n)?""+e:e+"px"},D=(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))}},I=t=>({build(){const n=t();return n.build?.()??n}}),$=({text:t,marker:n})=>I((()=>{const e=m(),o=n&&e.C((()=>document.createComment(""))),s=e.C((()=>document.createTextNode("")));return f((()=>{const n=""+(_.get(t)??"");s.textContent!=n&&(s.textContent=n)})),o?[o,s]:[s]})),z=({children:t})=>I((()=>Array.isArray(t)?t.flatMap((t=>z({children:t}).build())):null==t?[]:"object"==typeof t?t:$({text:t}))),P=(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((()=>{O(t,n,_.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=b(n);f((()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s))))}else f((()=>{D(t,n,_.get(e),o)}))}return u&&f((()=>{const n=_.get(u).__html;t.innerHTML!=n&&(t.innerHTML=n)})),s&&f((()=>(s.set(t),()=>s.set(void 0)))),null!=e.children&&t.append(...y({P:n,N:t.childNodes.values()},(()=>z({children:e.children}).build()))),t},V=(t,n={},e)=>(null!=e&&(n.children=e),L(t)?((t,n)=>I((()=>{const e=m().C((()=>new t));return customElements.upgrade(e),P(e,!1,n),[e]})))(t,n):"function"==typeof t?I((()=>t(n))):((t,n={})=>I((()=>{const e=m(),o="svg"==t||!!e.P;return[P(e.C((()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t))),o,n,!0)]})))(t,n)),Z=new Proxy(V,{get:(t,n)=>(e,o)=>t(n,e,o)}),q=(t,n)=>{const[e,o]=c({V:[],Z:new Map});let s=new Map;return f((()=>{const e=[],r=s,c=((t,n)=>{const e=new Map;for(let o=0;o<t.length;o++){const s=n(t[o],o);if(e.has(s))throw Error(`Duplicate key '${s}'`);e.set(s,o)}return e})(t(),n),i=(t=NaN)=>e.map((t=>"r"==t.q?n=>n<t.B?n:n==t.B?NaN:n-1:"a"==t.q?n=>n<t.B?n:n+1:"m"==t.q?n=>t.F<=n&&n<t.G?n+1:n==t.G?t.F:n:t=>t)).reduce(((t,n)=>n(t)),t);for(const t of r.keys()){const n=i(r.get(t));c.has(t)||e.push({q:"r",J:t,B:n})}for(let o=0;o<t().length;o++){const s=n(t()[o],o),c=i(r.get(s));isNaN(c)?e.push({q:"a",J:s,B:o}):c!=o&&e.push({q:"m",J:s,G:c,F:o})}e.length>0&&o({V:e,Z:c}),s=c})),e},B=t=>I((()=>{const n=m(),e=_.upgrade(t.each??[]),o=n.C((()=>document.createComment(""))),s=t.key??((t,n)=>n),r=[o],i=new Map,l=q(e,s),u=t=>{for(let n=t-1;n>=0;n--){const n=s(e()[t-1],t-1),o=i.get(n)?.K??[];if(o.length>0)return o[o.length-1]}return o};return f((()=>{for(const n of l().V)if("r"==n.q){const{K:t=[],$:e}=i.get(n.J)??{};e?.();const o=r.indexOf(t[0]);o>0&&r.splice(o,t.length),t.forEach((t=>t.parentNode?.removeChild(t))),i.delete(n.J)}else if("a"==n.q){let o=[];const[,s]=d((()=>{const[s,i]=c(n.B),[a,d]=c(e()[n.B]);f((()=>{0<=s()&&s()<e().length&&d((()=>e()[s()]))})),f((()=>{const t=l().Z.get(n.J);null!=t&&i(t)})),o=t.children?.(a,s,e).build()??[];const h=u(n.B),_=r.indexOf(h);_>=0&&r.splice(_+1,0,...o),o.forEach((t=>h.parentNode?.insertBefore(t,h.nextSibling)))}));i.set(n.J,{K:o,$:s})}else if("m"==n.q){const{K:t=[]}=i.get(n.J)??{},e=r.indexOf(t[0]);e>=0&&r.splice(e,t.length);const o=u(n.F),s=r.indexOf(o);s>=0&&r.splice(s+1,0,...t),t.forEach((t=>o.parentNode?.insertBefore(t,o.nextSibling)))}}),[l]),r})),F=t=>(m().k=[],G({condition:t.condition,children:t.children})),G=t=>{const n=m(),e=n.k,o=a((()=>e.every((t=>!t()))&&_.get(t.condition)));return n.k=[...e,o],y({k:[]},(()=>I((()=>{const e=n.C((()=>document.createComment(""))),s=[e],r=a((()=>o()?z({children:t.children}):null));let c=[];return f((()=>{c.forEach((t=>t.parentNode?.removeChild(t))),s.length=1;const[,t]=d((()=>{c=r()?.build()??[],e.after(...c),s.push(...c)}));return t}),[r]),s}))))},J=({children:t})=>G({condition:!0,children:t}),K=({mount:t,children:n})=>I((()=>y({N:void 0},(()=>{const e=z({children:n}).build();return f((()=>(e.forEach((n=>t.appendChild(n))),()=>{e.forEach((t=>t.parentNode?.removeChild(t)))}))),[]})))),Q=Symbol(),R=new Map,U=t=>{const n=t.children;if("function"==typeof n){const e=V("style",{},$({text:n,marker:!1}));return t.light?K({mount:document.head,children:e}):e}if(n){const o=m(),s=t.light?document:o.T?.shadowRoot??document,r=((t,n,e)=>{if(!R.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),R.set(n,{R:t,U:0})}const o=R.get(n);o.U++,t.has(n)||t.set(n,{R:o.R,U:0});const s=t.get(n);return s.U++,f((()=>()=>{--s.U||(t.delete(n),e()),--o.U||R.delete(n)})),s.R})((e=s,e[Q]??=new Map),n,(()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter((t=>t!=r))}));s.adoptedStyleSheets.push(r)}var e;return z({})},W=(t,...n)=>{const e=()=>t.reduce(((t,e,o)=>t+e+(_.get(n[o])??"")),"");return n.some((t=>"function"==typeof t))?e:e()},X=(t,n,e)=>(n&&null!=e&&(n.key=e),V(t,n));export{H as Component,J as Else,G as ElseIf,B as For,z as Fragment,F as If,_ as MaybeSignal,K as Portal,U as Style,g as createContext,V as createElement,W as css,T as defineComponents,C as event,l as flushBatch,Z as h,L as isComponent,X as jsx,X as jsxDEV,X as jsxs,k as prop,i as useBatch,M as useContext,j as useEffect,a as useMemo,h as useRef,c as useSignal,d as useSubscope};
1
+ const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.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._?.())),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,p:new Set,u(){const o=n,c=s;n=this;try{this.p.forEach((t=>t.o.delete(this))),this.p.clear(),e&&(s=!1,e.forEach((t=>t()))),s=r,this._?.();const n=this.M.u((()=>i(t)));this._=n?()=>{this.M.u((()=>i(n))),this._=null}:null}finally{n=o,s=c}}};o.o.push(c),c.u(),c.p.size||c._||o.o.pop()},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.push(i);return[i.u(n),()=>{const t=c.i.indexOf(i);t>=0&&c.i.splice(t,1),i.h()}]}finally{e=r}},h=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},_={upgrade:t=>()=>_.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},p=(t={})=>({k:[],C(t){return this.N?.next().value??t()},...t}),y=()=>{const t=r();return t.l.j??=p()},m=(t,n)=>{const e=y(),o=p({...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())),b=t=>t.startsWith("on:")?t.slice(3):w(t.slice(2)),v=Symbol(),g=(t,n)=>({[v]:Math.random().toString(36).slice(2),A:t,H:n}),x=t=>!!t?.[v],S=(t,n,e)=>{n.addEventListener(t[v],(t=>{const n=_.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))}))},M=t=>{const n=y();return a((()=>{let e=t.A;return n.L?.dispatchEvent(new CustomEvent(t[v],{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)=>({T:"p",O:t,...n}),N=(t=CustomEvent)=>({T:"e",D:t}),j=Symbol();let A;const H=(t,n)=>{A?A.push([t,n]):f(t,n)},L=(t,n={},e={})=>{const o=[],s=new Map;for(const t in n){const e=n[t];if("p"==e.T&&e.attribute){"function"==typeof e.attribute&&(e.attribute={transform:e.attribute});const n=e.attribute={name:w(t),static:!1,transform:t=>t,...e.attribute};s.set(n.name,{name:t,meta:e}),n.static||o.push(n.name)}}e.shadow??={mode:"open"};class i extends HTMLElement{static[j]={I:t};static observedAttributes=o;props={};events={};[j]={};constructor(){super();for(const t in n){const e=n[t];if("p"==e.T){const n=x(e.O)?e.O:null,[o,s]=c(n?void 0:e.O);this.props[t]=o,n&&S(n,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s((()=>t),{force:!0})})}else if("e"==e.T&&t.startsWith("on")){const n=b(t);this.events[t]=t=>this.dispatchEvent(new e.D(n,t))}}}connectedCallback(){const t=(n=this,e.shadow?n.shadowRoot??n.attachShadow(e.shadow):n);var n;this[j].$=d((()=>m({P:!1,L:this,N:t.childNodes.values()},(()=>{this[j].M=r();const n=A;A=[];try{k.forEach(this.render().build(),(n=>{t.append(n)})),A.forEach((([t,n])=>f(t,n)))}finally{A=n}}))))[1]}disconnectedCallback(){this[j].$?.()}attributeChangedCallback(t,n,e){const o=s.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):x(o.meta.O)?void 0:o.meta.O)}}return i},T=t=>!!t?.[j],O=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+t[j].I,t)},D=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,I=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||D.test(n)?""+e:e+"px"},$=(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))}},z=({text:t,marker:n})=>C((()=>{const e=y(),o=n&&e.C((()=>document.createComment(""))),s=e.C((()=>document.createTextNode("")));return f((()=>{const n=""+(_.get(t)??"");s.textContent!=n&&(s.textContent=n)})),o?[o,s]:[s]})),P=({children:t})=>C((()=>Array.isArray(t)?t.flatMap((t=>P({children:t}).build())):null==t?[]:["object"==typeof t?t.build():z({text:t}).build()])),V=(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((()=>{I(t,n,_.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=b(n);f((()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s))))}else f((()=>{$(t,n,_.get(e),o)}))}return u&&f((()=>{const n=_.get(u).__html;t.innerHTML!=n&&(t.innerHTML=n)})),s&&f((()=>(s.set(t),()=>s.set(void 0)))),null!=e.children&&k.forEach(m({P:n,N:t.childNodes.values()},(()=>P({children:e.children}).build())),(n=>t.append(n))),t},Z=(t,n={},e)=>(null!=e&&(n.children=e),T(t)?((t,n)=>C((()=>{const e=y().C((()=>new t));return customElements.upgrade(e),V(e,!1,n),[e]})))(t,n):"function"==typeof t?C((()=>t(n))):((t,n={})=>C((()=>{const e=y(),o="svg"==t||!!e.P;return[V(e.C((()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t))),o,n,!0)]})))(t,n)),q=new Proxy(Z,{get:(t,n)=>(e,o)=>t(n,e,o)}),B=(t,n)=>{const[e,o]=c({V:[],Z:new Map},{force:!0});let s=new Map;return f((()=>{const e=[],r=s,c=((t,n)=>{const e=new Map;for(let o=0;o<t.length;o++){const s=n(t[o],o);if(e.has(s))throw Error(`Duplicate key '${s}'`);e.set(s,o)}return e})(t(),n),i=(t=NaN)=>e.map((t=>"r"==t.q?n=>n<t.B?n:n==t.B?NaN:n-1:"a"==t.q?n=>n<t.B?n:n+1:"m"==t.q?n=>t.F<=n&&n<t.G?n+1:n==t.G?t.F:n:t=>t)).reduce(((t,n)=>n(t)),t);for(const t of r.keys()){const n=i(r.get(t));c.has(t)||e.push({q:"r",J:t,B:n})}for(let o=0;o<t().length;o++){const s=n(t()[o],o),c=i(r.get(s));isNaN(c)?e.push({q:"a",J:s,B:o}):c!=o&&e.push({q:"m",J:s,G:c,F:o})}e.length>0&&o({V:e,Z:c}),s=c})),e},F=t=>C((()=>{const n=y(),e=_.upgrade(t.each??[]),o=n.C((()=>document.createComment(""))),s=t.key??((t,n)=>n),r=[o,[]],i=new Map,l=B(e,s),u=t=>k.last(r[1],t-1)??o;return f((()=>{for(const n of l().V)if("r"==n.q){const{K:t,$:e}=i.get(n.J)??{};e?.(),r[1].splice(n.B,1),k.forEach(t??[],(t=>t.parentNode?.removeChild(t))),i.delete(n.J)}else if("a"==n.q){let o;const[,s]=d((()=>{const[s,i]=c(n.B),[a,d]=c(e()[n.B]);f((()=>{0<=s()&&s()<e().length&&d((()=>e()[s()]))})),f((()=>{const t=l().Z.get(n.J);null!=t&&i(t)})),o=t.children?.(a,s,e).build()??[],r[1].splice(n.B,0,o);let h=u(n.B);k.forEach(o,(t=>{h.parentNode?.insertBefore(t,h.nextSibling),h=t}))}));i.set(n.J,{K:o,$:s})}else if("m"==n.q){const{K:t}=i.get(n.J)??{};r[1].splice(n.G,1),r[1].splice(n.F,0,t??[]);let e=u(n.F);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=_.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()?P({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=P({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=Z("style",{},z({text:n,marker:!1}));return t.light?Q({mount:document.head,children:e}):e}if(n){const o=y(),s=t.light?document:o.L?.shadowRoot??document,r=((t,n,e)=>{if(!U.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),U.set(n,{R:t,U:0})}const o=U.get(n);o.U++,t.has(n)||t.set(n,{R:o.R,U:0});const s=t.get(n);return s.U++,f((()=>()=>{--s.U||(t.delete(n),e()),--o.U||U.delete(n)})),s.R})((e=s,e[R]??=new Map),n,(()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter((t=>t!=r))}));s.adoptedStyleSheets.push(r)}var e;return P({})},X=(t,...n)=>{const e=()=>t.reduce(((t,e,o)=>t+e+(_.get(n[o])??"")),"");return n.some((t=>"function"==typeof t))?e:e()},Y=(t,n,e)=>(n&&null!=e&&(n.key=e),Z(t,n));export{L as Component,K as Else,J as ElseIf,F as For,P as Fragment,G as If,_ as MaybeSignal,Q as Portal,W as Style,k as TemplateNodes,g as createContext,Z as createElement,X as css,O as defineComponents,N as event,l as flushBatch,q as h,T as isComponent,Y as jsx,Y as jsxDEV,Y as jsxs,E as prop,i as useBatch,M as useContext,H as useEffect,a as useMemo,h as useRef,c as useSignal,d as useSubscope};
package/dist/component.js CHANGED
@@ -3,6 +3,7 @@ import { runWithRenderer } from "./renderer.js";
3
3
  import { camelCaseToKebabCase, jsxPropNameToEventName, } from "./utils.js";
4
4
  import { useScope } from "./scope.js";
5
5
  import { isContext, provideContext } from "./context.js";
6
+ import { TemplateNodes } from "./template.js";
6
7
  /**
7
8
  * Defines a property in your component metadata that can be set from outside
8
9
  * of the component.
@@ -211,7 +212,9 @@ export const Component = ((tagName, metadata = {}, opts = {}) => {
211
212
  const prevMountEffects = mountEffects;
212
213
  mountEffects = [];
213
214
  try {
214
- renderParent?.append(...this.render().build());
215
+ TemplateNodes.forEach(this.render().build(), (node) => {
216
+ renderParent.append(node);
217
+ });
215
218
  // Run mount effects
216
219
  mountEffects.forEach(([fn, opts]) => useEffect(fn, opts));
217
220
  }
@@ -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,EAEpB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAW,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAoKlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EACnB,EAAE,CAAC,CAAC;IACjC,I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Q,CAAC;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAU,EACiC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC;AAkBxE;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAGyC,CACpE,GAAG,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,CAAC,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { FunctionalComponent } from "../component.js";
2
+ import { MaybeSignal } from "../scope.js";
3
+ import { Template } from "../template.js";
4
+ /**
5
+ * `Dynamic` is a component that can be used to render conditionally.
6
+ *
7
+ * On every change, it will replace all previously rendered nodes with new ones.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const App = () => (
12
+ * const [count, setCount] = useSignal(100);
13
+ *
14
+ * <Dynamic
15
+ * render={() =>
16
+ * count() === 1 ? (
17
+ * <>
18
+ * <h3>Details</h3>
19
+ * { … }
20
+ * </>
21
+ * ) : count() > 1 ? (
22
+ * <p>Multiple items selected</p>
23
+ * ) : (
24
+ * <p>No items</p>
25
+ * )
26
+ * }
27
+ * />
28
+ * );
29
+ * ```
30
+ */
31
+ export declare const Dynamic: FunctionalComponent<{
32
+ render?: MaybeSignal<Template | undefined | void | null>;
33
+ }>;
@@ -0,0 +1,53 @@
1
+ import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
2
+ import { useRenderer } from "../renderer.js";
3
+ import { createTemplate } from "../template.js";
4
+ /**
5
+ * `Dynamic` is a component that can be used to render conditionally.
6
+ *
7
+ * On every change, it will replace all previously rendered nodes with new ones.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const App = () => (
12
+ * const [count, setCount] = useSignal(100);
13
+ *
14
+ * <Dynamic
15
+ * render={() =>
16
+ * count() === 1 ? (
17
+ * <>
18
+ * <h3>Details</h3>
19
+ * { … }
20
+ * </>
21
+ * ) : count() > 1 ? (
22
+ * <p>Multiple items selected</p>
23
+ * ) : (
24
+ * <p>No items</p>
25
+ * )
26
+ * }
27
+ * />
28
+ * );
29
+ * ```
30
+ */
31
+ export const Dynamic = (props) => createTemplate(() => {
32
+ const renderer = useRenderer();
33
+ const anchor = renderer._node(() => document.createComment(""));
34
+ const nodes = [anchor];
35
+ const template = useMemo(() => MaybeSignal.get(props.render));
36
+ useEffect(() => {
37
+ const [subnodes, destroy] = useSubscope(() => {
38
+ const subnodes = template()?.build() ?? [];
39
+ anchor.after(...subnodes);
40
+ nodes.push(...subnodes);
41
+ return subnodes;
42
+ });
43
+ return () => {
44
+ destroy();
45
+ for (const node of subnodes ?? []) {
46
+ node.parentNode?.removeChild(node);
47
+ }
48
+ nodes.length = 1;
49
+ };
50
+ }, [template]);
51
+ return nodes;
52
+ });
53
+ //# sourceMappingURL=Dynamic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dynamic.js","sourceRoot":"","sources":["../../src/intrinsic/Dynamic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAY,MAAM,gBAAgB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,OAAO,GAEf,CAAC,KAAK,EAAE,EAAE,CACb,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE;YAC3C,MAAM,QAAQ,GAAG,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAC3C,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC;YAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAC;YAEV,KAAK,MAAM,IAAI,IAAI,QAAQ,IAAI,EAAE,EAAE,CAAC;gBAClC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAED,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { FunctionalComponent } from "../component.js";
2
+ import { Children } from "./Fragment.js";
3
+ /**
4
+ * `ErrorBoundary` is a component that can be used to catch errors in the
5
+ * component tree.
6
+ */
7
+ export declare const ErrorBoundary: FunctionalComponent<{
8
+ fallback?: FunctionalComponent<{
9
+ error: unknown;
10
+ reset: () => void;
11
+ }>;
12
+ children?: Children;
13
+ }>;
14
+ export declare const useErrorBoundary: () => readonly [show: (err: unknown) => void, reset: () => void];
@@ -0,0 +1,36 @@
1
+ import { useScope, useSignal } from "../scope.js";
2
+ import { createTemplate } from "../template.js";
3
+ import { Fragment } from "./Fragment.js";
4
+ import { createContext, provideContext, useContext } from "../context.js";
5
+ import { If } from "./If.js";
6
+ const ErrorContext = createContext([
7
+ (err) => {
8
+ throw err;
9
+ },
10
+ () => { },
11
+ ]);
12
+ /**
13
+ * `ErrorBoundary` is a component that can be used to catch errors in the
14
+ * component tree.
15
+ */
16
+ export const ErrorBoundary = ({ fallback, children }) => {
17
+ let error;
18
+ const [showError, setShowError] = useSignal(false);
19
+ const show = (err) => {
20
+ error = err;
21
+ setShowError(true);
22
+ };
23
+ const reset = () => setShowError(false);
24
+ return If({
25
+ condition: showError,
26
+ then: createTemplate(() => fallback?.({ error, reset }) ?? []),
27
+ else: createTemplate(() => {
28
+ provideContext(ErrorContext, () => [show, reset]);
29
+ const s = useScope();
30
+ s._onError = show;
31
+ return Fragment({ children });
32
+ }),
33
+ });
34
+ };
35
+ export const useErrorBoundary = () => useContext(ErrorContext)();
36
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../src/intrinsic/ErrorBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAA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ope, } from "../scope.js";
3
3
  import { useRenderer } from "../renderer.js";
4
- import { createTemplate } from "../template.js";
4
+ import { createTemplate, TemplateNodes } from "../template.js";
5
5
  /**
6
6
  * `For` is a component that can be used to render a list of items.
7
7
  */
@@ -10,33 +10,21 @@ export const For = (props) => createTemplate(() => {
10
10
  const items = MaybeSignal.upgrade(props.each ?? []);
11
11
  const anchor = renderer._node(() => document.createComment(""));
12
12
  const keyFn = props.key ?? ((_, i) => i);
13
- const nodes = [anchor];
13
+ const nodes = [anchor, []];
14
14
  const keyMap = new Map();
15
15
  const mutationResult = useArrayMutation(items, keyFn);
16
- const lookForAnchor = (index) => {
17
- for (let i = index - 1; i >= 0; i--) {
18
- const key = keyFn(items()[index - 1], index - 1);
19
- const nodes = keyMap.get(key)?._subnodes ?? [];
20
- if (nodes.length > 0) {
21
- return nodes[nodes.length - 1];
22
- }
23
- }
24
- return anchor;
25
- };
16
+ const lookForAnchor = (index) => TemplateNodes.last(nodes[1], index - 1) ?? anchor;
26
17
  useEffect(() => {
27
18
  for (const mutation of mutationResult()._mutations) {
28
19
  if (mutation._type == "r") {
29
- const { _subnodes = [], _destroy } = keyMap.get(mutation._key) ?? {};
20
+ const { _subnodes, _destroy } = keyMap.get(mutation._key) ?? {};
30
21
  _destroy?.();
31
- const index = nodes.indexOf(_subnodes[0]);
32
- if (index > 0) {
33
- nodes.splice(index, _subnodes.length);
34
- }
35
- _subnodes.forEach((node) => node.parentNode?.removeChild(node));
22
+ nodes[1].splice(mutation._index, 1);
23
+ TemplateNodes.forEach(_subnodes ?? [], (node) => node.parentNode?.removeChild(node));
36
24
  keyMap.delete(mutation._key);
37
25
  }
38
26
  else if (mutation._type == "a") {
39
- let _subnodes = [];
27
+ let _subnodes;
40
28
  const [, destroy] = useSubscope(() => {
41
29
  const [index, setIndex] = useSignal(mutation._index);
42
30
  const [item, setItem] = useSignal(items()[mutation._index]);
@@ -52,27 +40,24 @@ export const For = (props) => createTemplate(() => {
52
40
  }
53
41
  });
54
42
  _subnodes = props.children?.(item, index, items).build() ?? [];
55
- const itemAnchor = lookForAnchor(mutation._index);
56
- const anchorIndex = nodes.indexOf(itemAnchor);
57
- if (anchorIndex >= 0) {
58
- nodes.splice(anchorIndex + 1, 0, ..._subnodes);
59
- }
60
- _subnodes.forEach((node) => itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling));
43
+ nodes[1].splice(mutation._index, 0, _subnodes);
44
+ let itemAnchor = lookForAnchor(mutation._index);
45
+ TemplateNodes.forEach(_subnodes, (node) => {
46
+ itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
47
+ itemAnchor = node;
48
+ });
61
49
  });
62
50
  keyMap.set(mutation._key, { _subnodes, _destroy: destroy });
63
51
  }
64
52
  else if (mutation._type == "m") {
65
- const { _subnodes = [] } = keyMap.get(mutation._key) ?? {};
66
- const index = nodes.indexOf(_subnodes[0]);
67
- if (index >= 0) {
68
- nodes.splice(index, _subnodes.length);
69
- }
70
- const itemAnchor = lookForAnchor(mutation._to);
71
- const anchorIndex = nodes.indexOf(itemAnchor);
72
- if (anchorIndex >= 0) {
73
- nodes.splice(anchorIndex + 1, 0, ..._subnodes);
74
- }
75
- _subnodes.forEach((node) => itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling));
53
+ const { _subnodes } = keyMap.get(mutation._key) ?? {};
54
+ nodes[1].splice(mutation._from, 1);
55
+ nodes[1].splice(mutation._to, 0, _subnodes ?? []);
56
+ let itemAnchor = lookForAnchor(mutation._to);
57
+ TemplateNodes.forEach(_subnodes ?? [], (node) => {
58
+ itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
59
+ itemAnchor = node;
60
+ });
76
61
  }
77
62
  }
78
63
  }, [mutationResult]);