sinho 0.3.0 → 0.3.2
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/.github/workflows/ci.yml +7 -5
- package/.github/workflows/deploy-docs.yml +2 -2
- package/dist/bundle.d.ts +12 -9
- package/dist/bundle.js +8 -6
- package/dist/bundle.min.js +1 -1
- package/dist/component.d.ts +1 -1
- package/dist/intrinsic/For.d.ts +3 -3
- package/dist/intrinsic/If.js +7 -7
- package/dist/intrinsic/If.js.map +1 -1
- package/dist/jsx-runtime/mod.d.ts +2 -2
- package/dist/renderer.d.ts +1 -1
- package/dist/scope.d.ts +4 -2
- package/dist/scope.js +2 -0
- package/dist/scope.js.map +1 -1
- package/package.json +18 -6
- package/src/intrinsic/If.ts +10 -18
- package/src/renderer.ts +1 -1
- package/web/docusaurus.config.ts +0 -18
- package/web/package-lock.json +8165 -4481
- package/web/package.json +5 -7
- package/web/src/components/monacoEditor.tsx +1 -1
- package/web/src/components/playground.tsx +1 -1
- package/web/src/pages/index.tsx +1 -3
- package/web/static/dist/bundle.d.ts +36 -15
- package/web/static/dist/bundle.min.js +1 -1
- package/dist/intrinsic/Dynamic.d.ts +0 -33
- package/dist/intrinsic/Dynamic.js +0 -53
- package/dist/intrinsic/Dynamic.js.map +0 -1
- package/dist/intrinsic/ErrorBoundary.d.ts +0 -14
- package/dist/intrinsic/ErrorBoundary.js +0 -36
- package/dist/intrinsic/ErrorBoundary.js.map +0 -1
- package/web/dist/shingo.min.d.ts +0 -1131
- package/web/dist/shingo.min.js +0 -1
package/web/package.json
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"typecheck": "tsc"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@docusaurus/core": "3.2
|
|
20
|
-
"@docusaurus/preset-classic": "3.2
|
|
19
|
+
"@docusaurus/core": "^3.9.2",
|
|
20
|
+
"@docusaurus/preset-classic": "^3.9.2",
|
|
21
21
|
"@mdx-js/react": "^3.0.0",
|
|
22
22
|
"@swc/wasm-web": "^1.4.17",
|
|
23
23
|
"clsx": "^2.0.0",
|
|
@@ -29,11 +29,9 @@
|
|
|
29
29
|
"sinho": "file:.."
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@docusaurus/module-type-aliases": "3.2
|
|
33
|
-
"@docusaurus/tsconfig": "3.2
|
|
34
|
-
"@docusaurus/types": "3.2
|
|
35
|
-
"docusaurus-plugin-typedoc-api": "^4.2.0",
|
|
36
|
-
"typedoc": "^0.25.13",
|
|
32
|
+
"@docusaurus/module-type-aliases": "^3.9.2",
|
|
33
|
+
"@docusaurus/tsconfig": "^3.9.2",
|
|
34
|
+
"@docusaurus/types": "^3.9.2",
|
|
37
35
|
"typescript": "^5.4.3"
|
|
38
36
|
},
|
|
39
37
|
"browserslist": {
|
|
@@ -10,7 +10,7 @@ export const MonacoEditor: FC<{
|
|
|
10
10
|
}> = (props) => {
|
|
11
11
|
const divRef = useRef<HTMLDivElement>(null);
|
|
12
12
|
const typesPath = useBaseUrl("/dist/bundle.d.ts");
|
|
13
|
-
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>();
|
|
13
|
+
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(null);
|
|
14
14
|
const { colorMode } = useColorMode();
|
|
15
15
|
|
|
16
16
|
useEffect(() => {
|
package/web/src/pages/index.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import Heading from "@theme/Heading";
|
|
|
7
7
|
import { CodeSnippetComponentPlayground } from "../components/playground";
|
|
8
8
|
import styles from "./index.module.css";
|
|
9
9
|
import CodeBlock from "@theme/CodeBlock";
|
|
10
|
+
import type { JSX } from "react";
|
|
10
11
|
|
|
11
12
|
function HomepageHeader() {
|
|
12
13
|
const { siteConfig } = useDocusaurusContext();
|
|
@@ -24,9 +25,6 @@ function HomepageHeader() {
|
|
|
24
25
|
>
|
|
25
26
|
Documentation
|
|
26
27
|
</Link>
|
|
27
|
-
<Link className="button button--secondary button--lg" to="/api">
|
|
28
|
-
API
|
|
29
|
-
</Link>
|
|
30
28
|
</div>
|
|
31
29
|
</div>
|
|
32
30
|
</header>
|
|
@@ -18,6 +18,12 @@ interface Signal<out T> extends SignalLike<T> {
|
|
|
18
18
|
*/
|
|
19
19
|
peek(): T;
|
|
20
20
|
}
|
|
21
|
+
interface SignalOptions<T> extends SetSignalOptions {
|
|
22
|
+
/**
|
|
23
|
+
* A custom equality function to compare the new value with the old value.
|
|
24
|
+
*/
|
|
25
|
+
equals?: (a: T, b: T) => boolean;
|
|
26
|
+
}
|
|
21
27
|
interface SetSignalOptions {
|
|
22
28
|
/**
|
|
23
29
|
* Whether to force the update of the signal even if the new value has the
|
|
@@ -40,9 +46,10 @@ interface SubscopeOptions {
|
|
|
40
46
|
details?: object;
|
|
41
47
|
}
|
|
42
48
|
interface Effect {
|
|
49
|
+
_scope: Scope;
|
|
50
|
+
_pure: boolean;
|
|
43
51
|
_clean?: Cleanup;
|
|
44
52
|
_deps: Set<Signal<unknown>>;
|
|
45
|
-
_scope: Scope;
|
|
46
53
|
_run(): void;
|
|
47
54
|
}
|
|
48
55
|
/**
|
|
@@ -63,7 +70,7 @@ declare const useScope: <T = {}>() => Scope<T>;
|
|
|
63
70
|
* Creates a new signal with the given value.
|
|
64
71
|
* @returns A tuple with the signal and its setter.
|
|
65
72
|
*/
|
|
66
|
-
declare const useSignal: (<T>(value: T, opts?:
|
|
73
|
+
declare const useSignal: (<T>(value: T, opts?: SignalOptions<T>) => readonly [Signal<T>, SignalSetter<T>]) & (<T>(value?: T, opts?: SignalOptions<T | undefined>) => readonly [Signal<T | undefined>, SignalSetter<T | undefined>]);
|
|
67
74
|
/**
|
|
68
75
|
* Runs the given function in a batch.
|
|
69
76
|
*
|
|
@@ -71,12 +78,20 @@ declare const useSignal: (<T>(value: T, opts?: SetSignalOptions) => readonly [Si
|
|
|
71
78
|
* and updated at the same time.
|
|
72
79
|
*/
|
|
73
80
|
declare const useBatch: <T>(fn: () => T) => T;
|
|
81
|
+
declare const flushBatch: () => void;
|
|
74
82
|
/**
|
|
75
83
|
* Creates a memoized signal.
|
|
76
84
|
*
|
|
77
85
|
* @param fn The computation function.
|
|
78
86
|
*/
|
|
79
|
-
declare const useMemo: <T>(fn: () => T, opts?:
|
|
87
|
+
declare const useMemo: <T>(fn: () => T, opts?: SignalOptions<T>) => Signal<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Executes a function inside a subscope which can be manually destroyed.
|
|
90
|
+
*
|
|
91
|
+
* @param fn The function to run in the subscope.
|
|
92
|
+
* @returns A function to manually destroy the subscope.
|
|
93
|
+
*/
|
|
94
|
+
declare const useSubscope: <T>(fn: () => T, opts?: SubscopeOptions) => [T, () => void];
|
|
80
95
|
/**
|
|
81
96
|
* Provide write capabilities to a signal.
|
|
82
97
|
*/
|
|
@@ -98,7 +113,7 @@ interface RefSignalSetter<in T> {
|
|
|
98
113
|
/**
|
|
99
114
|
* Creates a new signal with write capabilities.
|
|
100
115
|
*/
|
|
101
|
-
declare const useRef: (<T>(value: T, opts?:
|
|
116
|
+
declare const useRef: (<T>(value: T, opts?: SignalOptions<T>) => RefSignal<T>) & (<T>(value?: T, opts?: SignalOptions<T | undefined>) => RefSignal<T | undefined>);
|
|
102
117
|
/**
|
|
103
118
|
* Represents a value that can be a signal or a constant value.
|
|
104
119
|
*
|
|
@@ -116,11 +131,11 @@ declare const MaybeSignal: {
|
|
|
116
131
|
/**
|
|
117
132
|
* Gets the value of the given {@link MaybeSignal}.
|
|
118
133
|
*/
|
|
119
|
-
get: <
|
|
134
|
+
get: <T>(signal: MaybeSignal<T>) => T;
|
|
120
135
|
/**
|
|
121
136
|
* Accesses the value of the given {@link MaybeSignal} without tracking.
|
|
122
137
|
*/
|
|
123
|
-
peek<
|
|
138
|
+
peek<T>(signal: MaybeSignal<T>): T;
|
|
124
139
|
};
|
|
125
140
|
|
|
126
141
|
interface DomIntrinsicElements {
|
|
@@ -744,6 +759,11 @@ interface Context<in out T> {
|
|
|
744
759
|
declare const createContext: (<T>(value: T, opts?: SetSignalOptions) => Context<T>) & (<T>(value?: T, opts?: SetSignalOptions) => Context<T | undefined>);
|
|
745
760
|
declare const useContext: <T>(context: Context<T>) => Signal<T>;
|
|
746
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
|
+
}
|
|
747
767
|
/**
|
|
748
768
|
* Represents a render result of a component.
|
|
749
769
|
*/
|
|
@@ -751,7 +771,7 @@ interface Template {
|
|
|
751
771
|
/**
|
|
752
772
|
* Build the DOM elements represented by this template.
|
|
753
773
|
*/
|
|
754
|
-
build():
|
|
774
|
+
build(): TemplateNodes;
|
|
755
775
|
}
|
|
756
776
|
|
|
757
777
|
interface Tagged<in out T> {
|
|
@@ -947,7 +967,7 @@ interface ComponentOptions {
|
|
|
947
967
|
*
|
|
948
968
|
* @param fn The function to run; it may return a cleanup function.
|
|
949
969
|
*/
|
|
950
|
-
declare const useMountEffect: (fn: () => Cleanup, deps?:
|
|
970
|
+
declare const useMountEffect: (fn: () => Cleanup, deps?: SignalLike<unknown>[]) => void;
|
|
951
971
|
type Component<M extends Metadata = {}> = {
|
|
952
972
|
-readonly [K in keyof Props<M>]: Props<M>[K] extends Signal<infer T> ? T : never;
|
|
953
973
|
} & ComponentInner<M> & HTMLElement;
|
|
@@ -980,7 +1000,7 @@ declare const Component: ((tagName: string) => ComponentConstructor<{}>) & (<con
|
|
|
980
1000
|
* Determines whether the given value is a component created by
|
|
981
1001
|
* extending {@link ComponentConstructor}.
|
|
982
1002
|
*/
|
|
983
|
-
declare const isComponent: (value: any) => value is ComponentConstructor
|
|
1003
|
+
declare const isComponent: (value: any) => value is ComponentConstructor | Component;
|
|
984
1004
|
/**
|
|
985
1005
|
* Represents a functional component.
|
|
986
1006
|
*
|
|
@@ -1066,9 +1086,9 @@ declare const h: typeof createElement & {
|
|
|
1066
1086
|
* `For` is a component that can be used to render a list of items.
|
|
1067
1087
|
*/
|
|
1068
1088
|
declare const For: <T>(props: {
|
|
1069
|
-
each?: MaybeSignal<readonly T[]
|
|
1070
|
-
key?: (
|
|
1071
|
-
children?: (
|
|
1089
|
+
each?: MaybeSignal<readonly T[]>;
|
|
1090
|
+
key?: (item: T, index: number) => string | number;
|
|
1091
|
+
children?: (item: Signal<T>, index: Signal<number>, arr: SignalLike<readonly T[]>) => Template;
|
|
1072
1092
|
}) => Template;
|
|
1073
1093
|
|
|
1074
1094
|
/**
|
|
@@ -1105,9 +1125,9 @@ declare const Style: FunctionalComponent<{
|
|
|
1105
1125
|
declare const css: (strings: TemplateStringsArray, ...values: MaybeSignal<string | number>[]) => MaybeSignal<string>;
|
|
1106
1126
|
|
|
1107
1127
|
/** @ignore */
|
|
1108
|
-
declare const jsx: (type: any, props?:
|
|
1128
|
+
declare const jsx: (type: any, props?: object & {
|
|
1109
1129
|
key?: unknown;
|
|
1110
|
-
}
|
|
1130
|
+
}, key?: unknown) => Template;
|
|
1111
1131
|
/** @ignore */
|
|
1112
1132
|
declare namespace JSX {
|
|
1113
1133
|
type Element = Template;
|
|
@@ -1123,4 +1143,5 @@ declare namespace JSX {
|
|
|
1123
1143
|
}
|
|
1124
1144
|
}
|
|
1125
1145
|
|
|
1126
|
-
export {
|
|
1146
|
+
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 };
|
|
1147
|
+
export type { AttributeOptions, Children, Cleanup, ComponentConstructor, ComponentOptions, Context, DangerousHtml, EventConstructor, FunctionalComponent, Metadata, PropOptions, RefSignal, RefSignalSetter, SetSignalOptions, Signal, SignalLike, SignalSetter, Styles, SubscopeOptions, Template };
|
|
@@ -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.p.forEach(
|
|
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};
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}>;
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,14 +0,0 @@
|
|
|
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];
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,MAAM,YAAY,GAAG,aAAa,CAAC;IACjC,CAAC,GAAY,EAAQ,EAAE;QACrB,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,GAAS,EAAE,GAAE,CAAC;CACN,CAAC,CAAC;AAEZ;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAMrB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC9B,IAAI,KAAc,CAAC;IACnB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,CAAC,GAAY,EAAE,EAAE;QAC5B,KAAK,GAAG,GAAG,CAAC;QACZ,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;IACF,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAExC,OAAO,EAAE,CAAC;QACR,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC9D,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE;YACxB,cAAc,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAU,CAAC,CAAC;YAC3D,MAAM,CAAC,GAAG,QAAQ,EAAE,CAAC;YACrB,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;YAElB,OAAO,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAG9B,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC"}
|