@fluixi/dom 1.0.0-alpha.83 → 1.0.0-alpha.85
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/cdn/dom-client.cjs +1427 -1
- package/dist/cdn/dom-client.d.ts +2 -2
- package/dist/cdn/dom-client.global.js +2 -1
- package/dist/cdn/dom-client.js +3 -3
- package/dist/cdn/dom-client.mjs +1430 -1
- package/dist/cdn/dom.cjs +3127 -1
- package/dist/cdn/dom.d.ts +2 -2
- package/dist/cdn/dom.global.js +2 -1
- package/dist/cdn/dom.js +4 -4
- package/dist/cdn/dom.mjs +3133 -1
- package/dist/index.cjs +3155 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +3149 -1
- package/dist/lib/component/index.cjs +128 -1
- package/dist/lib/component/index.mjs +105 -1
- package/dist/lib/component/modifiers.cjs +126 -1
- package/dist/lib/component/modifiers.d.ts +12 -0
- package/dist/lib/component/modifiers.d.ts.map +1 -1
- package/dist/lib/component/modifiers.js +12 -84
- package/dist/lib/component/modifiers.mjs +105 -1
- package/dist/lib/dom/delegate.cjs +60 -1
- package/dist/lib/dom/delegate.js +1 -1
- package/dist/lib/dom/delegate.mjs +39 -1
- package/dist/lib/dom/dynamic-element.cjs +949 -1
- package/dist/lib/dom/dynamic-element.d.ts +3 -3
- package/dist/lib/dom/dynamic-element.js +2 -2
- package/dist/lib/dom/dynamic-element.mjs +928 -1
- package/dist/lib/dom/hydration-state.cjs +93 -1
- package/dist/lib/dom/hydration-state.d.ts +1 -1
- package/dist/lib/dom/hydration-state.js +1 -1
- package/dist/lib/dom/hydration-state.mjs +72 -1
- package/dist/lib/dom/hydration.cjs +685 -1
- package/dist/lib/dom/hydration.js +8 -8
- package/dist/lib/dom/hydration.mjs +664 -1
- package/dist/lib/dom/index.cjs +2040 -1
- package/dist/lib/dom/index.js +1 -1
- package/dist/lib/dom/index.mjs +2020 -1
- package/dist/lib/dom/integration.cjs +71 -1
- package/dist/lib/dom/integration.js +3 -3
- package/dist/lib/dom/integration.mjs +51 -1
- package/dist/lib/dom/island.cjs +790 -1
- package/dist/lib/dom/island.d.ts +1 -1
- package/dist/lib/dom/island.js +11 -11
- package/dist/lib/dom/island.mjs +769 -1
- package/dist/lib/dom/runtime.cjs +1432 -1
- package/dist/lib/dom/runtime.d.ts +60 -17
- package/dist/lib/dom/runtime.d.ts.map +1 -1
- package/dist/lib/dom/runtime.js +122 -79
- package/dist/lib/dom/runtime.mjs +1414 -1
- package/dist/lib/dom/server/fx-data.cjs +53 -1
- package/dist/lib/dom/server/fx-data.d.ts +5 -5
- package/dist/lib/dom/server/fx-data.js +6 -6
- package/dist/lib/dom/server/fx-data.mjs +32 -1
- package/dist/lib/dom/server/host.cjs +66 -1
- package/dist/lib/dom/server/host.d.ts +6 -0
- package/dist/lib/dom/server/host.d.ts.map +1 -1
- package/dist/lib/dom/server/host.js +7 -1
- package/dist/lib/dom/server/host.mjs +45 -1
- package/dist/lib/dom/server/index.cjs +759 -1
- package/dist/lib/dom/server/index.d.ts +1 -1
- package/dist/lib/dom/server/index.js +1 -1
- package/dist/lib/dom/server/index.mjs +743 -1
- package/dist/lib/dom/server/nodes.cjs +302 -1
- package/dist/lib/dom/server/nodes.d.ts +2 -2
- package/dist/lib/dom/server/nodes.d.ts.map +1 -1
- package/dist/lib/dom/server/nodes.js +4 -4
- package/dist/lib/dom/server/nodes.mjs +279 -1
- package/dist/lib/dom/server/parse-template.cjs +395 -1
- package/dist/lib/dom/server/parse-template.d.ts +1 -1
- package/dist/lib/dom/server/parse-template.js +4 -4
- package/dist/lib/dom/server/parse-template.mjs +372 -1
- package/dist/lib/dom/server/render.cjs +691 -1
- package/dist/lib/dom/server/render.d.ts +9 -1
- package/dist/lib/dom/server/render.d.ts.map +1 -1
- package/dist/lib/dom/server/render.js +23 -15
- package/dist/lib/dom/server/render.mjs +677 -1
- package/dist/lib/dom/server/request-context.cjs +110 -1
- package/dist/lib/dom/server/request-context.d.ts +29 -9
- package/dist/lib/dom/server/request-context.d.ts.map +1 -1
- package/dist/lib/dom/server/request-context.js +28 -8
- package/dist/lib/dom/server/request-context.mjs +89 -1
- package/dist/lib/dom/server/serialize.cjs +187 -1
- package/dist/lib/dom/server/serialize.js +3 -3
- package/dist/lib/dom/server/serialize.mjs +164 -1
- package/dist/lib/dom/server-renderer.cjs +760 -1
- package/dist/lib/dom/server-renderer.js +1 -1
- package/dist/lib/dom/server-renderer.mjs +745 -1
- package/dist/lib/dom/types.cjs +18 -1
- package/dist/lib/dom/utils.cjs +381 -1
- package/dist/lib/dom/utils.d.ts +1 -88
- package/dist/lib/dom/utils.d.ts.map +1 -1
- package/dist/lib/dom/utils.js +2 -99
- package/dist/lib/dom/utils.mjs +361 -1
- package/dist/lib/dom/versions.cjs +60 -1
- package/dist/lib/dom/versions.d.ts +3 -3
- package/dist/lib/dom/versions.d.ts.map +1 -1
- package/dist/lib/dom/versions.js +17 -5
- package/dist/lib/dom/versions.mjs +37 -1
- package/dist/lib/element/attributes.cjs +19 -1
- package/dist/lib/element/attributes.d.ts +7 -7
- package/dist/lib/element/attributes.js +1 -1
- package/dist/lib/element/attributes.mjs +1 -0
- package/dist/lib/element/index.cjs +19 -1
- package/dist/lib/element/index.mjs +1 -0
- package/dist/lib/element/types.cjs +18 -1
- package/dist/lib/element/types.d.ts +4 -5
- package/dist/lib/element/types.d.ts.map +1 -1
- package/dist/lib/element/types.js +0 -1
- package/dist/lib/flow/class-map.cjs +38 -1
- package/dist/lib/flow/class-map.d.ts +3 -3
- package/dist/lib/flow/class-map.js +2 -2
- package/dist/lib/flow/class-map.mjs +17 -1
- package/dist/lib/flow/client-only.cjs +57 -1
- package/dist/lib/flow/client-only.d.ts +4 -4
- package/dist/lib/flow/client-only.js +3 -3
- package/dist/lib/flow/client-only.mjs +36 -1
- package/dist/lib/flow/dynamic.cjs +53 -1
- package/dist/lib/flow/dynamic.d.ts +2 -2
- package/dist/lib/flow/dynamic.js +3 -3
- package/dist/lib/flow/dynamic.mjs +32 -1
- package/dist/lib/flow/error-boundary.cjs +43 -1
- package/dist/lib/flow/error-boundary.d.ts +2 -2
- package/dist/lib/flow/error-boundary.js +3 -3
- package/dist/lib/flow/error-boundary.mjs +22 -1
- package/dist/lib/flow/for.cjs +66 -1
- package/dist/lib/flow/for.d.ts +9 -9
- package/dist/lib/flow/for.d.ts.map +1 -1
- package/dist/lib/flow/for.js +2 -2
- package/dist/lib/flow/for.mjs +45 -1
- package/dist/lib/flow/index-flow.cjs +67 -1
- package/dist/lib/flow/index-flow.d.ts +5 -5
- package/dist/lib/flow/index-flow.js +4 -4
- package/dist/lib/flow/index-flow.mjs +46 -1
- package/dist/lib/flow/index.cjs +805 -1
- package/dist/lib/flow/index.mjs +792 -1
- package/dist/lib/flow/portal.cjs +538 -1
- package/dist/lib/flow/portal.mjs +519 -1
- package/dist/lib/flow/show.cjs +81 -1
- package/dist/lib/flow/show.d.ts +1 -1
- package/dist/lib/flow/show.d.ts.map +1 -1
- package/dist/lib/flow/show.js +4 -115
- package/dist/lib/flow/show.mjs +67 -1
- package/dist/lib/flow/style-map.cjs +43 -1
- package/dist/lib/flow/style-map.d.ts +3 -3
- package/dist/lib/flow/style-map.js +3 -3
- package/dist/lib/flow/style-map.mjs +22 -1
- package/dist/lib/flow/switch.cjs +91 -1
- package/dist/lib/flow/switch.d.ts +3 -3
- package/dist/lib/flow/switch.d.ts.map +1 -1
- package/dist/lib/flow/switch.js +6 -6
- package/dist/lib/flow/switch.mjs +70 -1
- package/dist/lib/flow/utils.cjs +44 -1
- package/dist/lib/flow/utils.d.ts +1 -1
- package/dist/lib/flow/utils.js +1 -1
- package/dist/lib/flow/utils.mjs +23 -1
- package/dist/lib/html.cjs +32 -1
- package/dist/lib/html.d.ts +6 -6
- package/dist/lib/html.js +5 -5
- package/dist/lib/html.mjs +11 -1
- package/dist/lib/index.cjs +3104 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +2 -3
- package/dist/lib/index.mjs +3097 -1
- package/dist/lib/shared/types.cjs +18 -1
- package/dist/lib/shared/types.d.ts +8 -8
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/version.generated.cjs +26 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +2 -2
- package/dist/version.generated.mjs +5 -1
- package/package.json +7 -6
- package/dist/lib/jsx/control-flow/flow.cjs +0 -1
- package/dist/lib/jsx/control-flow/flow.d.ts +0 -2
- package/dist/lib/jsx/control-flow/flow.d.ts.map +0 -1
- package/dist/lib/jsx/control-flow/flow.js +0 -627
- package/dist/lib/jsx/control-flow/flow.mjs +0 -0
- package/dist/lib/jsx/control-flow/for-flow.cjs +0 -1
- package/dist/lib/jsx/control-flow/for-flow.d.ts +0 -2
- package/dist/lib/jsx/control-flow/for-flow.d.ts.map +0 -1
- package/dist/lib/jsx/control-flow/for-flow.js +0 -1
- package/dist/lib/jsx/control-flow/for-flow.mjs +0 -0
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/flow/client-only.ts
|
|
2
|
+
import { createMemo, createSignal } from "@fluixi/reactive/signal";
|
|
3
|
+
|
|
4
|
+
// src/lib/dom/server/host.ts
|
|
5
|
+
var STATE = /* @__PURE__ */ Symbol.for("fluixi.dom.server-host");
|
|
6
|
+
var realm = globalThis;
|
|
7
|
+
var state = realm[STATE] ??= {
|
|
8
|
+
server: typeof document === "undefined",
|
|
9
|
+
nodes: null
|
|
10
|
+
};
|
|
11
|
+
function isServer() {
|
|
12
|
+
return state.server;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/lib/dom/hydration-state.ts
|
|
16
|
+
var hydration = {
|
|
17
|
+
active: false,
|
|
18
|
+
cursor: null,
|
|
19
|
+
parents: []
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/flow/client-only.ts
|
|
23
|
+
function ClientOnly(props) {
|
|
24
|
+
if (isServer()) return props.fallback ?? null;
|
|
25
|
+
const hydrating = hydration.active;
|
|
26
|
+
const [ready, setReady] = createSignal(!hydrating);
|
|
27
|
+
if (hydrating) queueMicrotask(() => setReady(true));
|
|
28
|
+
return createMemo(() => ready() ? props.children : props.fallback ?? null, void 0, {
|
|
29
|
+
name: "client-only"
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var NoSsr = ClientOnly;
|
|
33
|
+
export {
|
|
34
|
+
ClientOnly,
|
|
35
|
+
NoSsr
|
|
36
|
+
};
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/flow/dynamic.ts
|
|
21
|
+
var dynamic_exports = {};
|
|
22
|
+
__export(dynamic_exports, {
|
|
23
|
+
Dynamic: () => Dynamic
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(dynamic_exports);
|
|
26
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
27
|
+
|
|
28
|
+
// src/lib/flow/utils.ts
|
|
29
|
+
function normalizeAccessor(value) {
|
|
30
|
+
return typeof value === "function" ? value : (() => value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/flow/dynamic.ts
|
|
34
|
+
function Dynamic(props) {
|
|
35
|
+
const getComponent = normalizeAccessor(props.component);
|
|
36
|
+
const { component: _c, ...rest } = props;
|
|
37
|
+
const parentOwner = (0, import_signal.getOwner)();
|
|
38
|
+
let scope = null;
|
|
39
|
+
let current;
|
|
40
|
+
return (0, import_signal.createMemo)(() => {
|
|
41
|
+
const C = getComponent();
|
|
42
|
+
if (C !== current) {
|
|
43
|
+
if (scope) (0, import_signal.disposeScope)(scope);
|
|
44
|
+
scope = (0, import_signal.createChildOwner)(parentOwner);
|
|
45
|
+
current = C;
|
|
46
|
+
}
|
|
47
|
+
if (C == null) return null;
|
|
48
|
+
if (typeof C === "string") {
|
|
49
|
+
return { tag: C, props: rest };
|
|
50
|
+
}
|
|
51
|
+
return (0, import_signal.runWithOwner)(scope, () => C(rest));
|
|
52
|
+
}, void 0, { name: "Dynamic" });
|
|
53
|
+
}
|
|
@@ -11,11 +11,11 @@ export interface DynamicProps<T extends Record<string, any> = Record<string, any
|
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Renders a component dynamically
|
|
14
|
+
* Renders a component dynamically: mirrors SolidJS `<Dynamic>`.
|
|
15
15
|
*
|
|
16
16
|
* The `component` prop can be a reactive accessor. When it changes,
|
|
17
17
|
* the old output is discarded and the new component is called.
|
|
18
|
-
* Returns a memo
|
|
18
|
+
* Returns a memo: works in both JSX and `html` templates.
|
|
19
19
|
*
|
|
20
20
|
* @example JSX
|
|
21
21
|
* <Dynamic component={tab() === 'a' ? CompA : CompB} value={x()} />
|
package/dist/lib/flow/dynamic.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createMemo, createChildOwner, disposeScope, getOwner, runWithOwner } from '@fluixi/reactive/signal';
|
|
2
2
|
import { normalizeAccessor } from './utils.js';
|
|
3
3
|
/**
|
|
4
|
-
* Renders a component dynamically
|
|
4
|
+
* Renders a component dynamically: mirrors SolidJS `<Dynamic>`.
|
|
5
5
|
*
|
|
6
6
|
* The `component` prop can be a reactive accessor. When it changes,
|
|
7
7
|
* the old output is discarded and the new component is called.
|
|
8
|
-
* Returns a memo
|
|
8
|
+
* Returns a memo: works in both JSX and `html` templates.
|
|
9
9
|
*
|
|
10
10
|
* @example JSX
|
|
11
11
|
* <Dynamic component={tab() === 'a' ? CompA : CompB} value={x()} />
|
|
@@ -35,7 +35,7 @@ export function Dynamic(props) {
|
|
|
35
35
|
if (C == null)
|
|
36
36
|
return null;
|
|
37
37
|
if (typeof C === 'string') {
|
|
38
|
-
// Intrinsic element
|
|
38
|
+
// Intrinsic element: return a descriptor that the runtime can handle.
|
|
39
39
|
return { tag: C, props: rest };
|
|
40
40
|
}
|
|
41
41
|
return runWithOwner(scope, () => C(rest));
|
|
@@ -1 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/flow/dynamic.ts
|
|
2
|
+
import { createMemo, createChildOwner, disposeScope, getOwner, runWithOwner } from "@fluixi/reactive/signal";
|
|
3
|
+
|
|
4
|
+
// src/lib/flow/utils.ts
|
|
5
|
+
function normalizeAccessor(value) {
|
|
6
|
+
return typeof value === "function" ? value : (() => value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/lib/flow/dynamic.ts
|
|
10
|
+
function Dynamic(props) {
|
|
11
|
+
const getComponent = normalizeAccessor(props.component);
|
|
12
|
+
const { component: _c, ...rest } = props;
|
|
13
|
+
const parentOwner = getOwner();
|
|
14
|
+
let scope = null;
|
|
15
|
+
let current;
|
|
16
|
+
return createMemo(() => {
|
|
17
|
+
const C = getComponent();
|
|
18
|
+
if (C !== current) {
|
|
19
|
+
if (scope) disposeScope(scope);
|
|
20
|
+
scope = createChildOwner(parentOwner);
|
|
21
|
+
current = C;
|
|
22
|
+
}
|
|
23
|
+
if (C == null) return null;
|
|
24
|
+
if (typeof C === "string") {
|
|
25
|
+
return { tag: C, props: rest };
|
|
26
|
+
}
|
|
27
|
+
return runWithOwner(scope, () => C(rest));
|
|
28
|
+
}, void 0, { name: "Dynamic" });
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
Dynamic
|
|
32
|
+
};
|
|
@@ -1 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/flow/error-boundary.ts
|
|
21
|
+
var error_boundary_exports = {};
|
|
22
|
+
__export(error_boundary_exports, {
|
|
23
|
+
ErrorBoundary: () => ErrorBoundary
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(error_boundary_exports);
|
|
26
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
27
|
+
function ErrorBoundary(props) {
|
|
28
|
+
const [error, setError] = (0, import_signal.createSignal)(null);
|
|
29
|
+
const reset = () => setError(null);
|
|
30
|
+
return (0, import_signal.createMemo)(() => {
|
|
31
|
+
const err = error();
|
|
32
|
+
if (err !== null) {
|
|
33
|
+
return typeof props.fallback === "function" ? props.fallback(err, reset) : props.fallback;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const content = typeof props.children === "function" ? props.children() : props.children;
|
|
37
|
+
return content;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
setError(e);
|
|
40
|
+
return typeof props.fallback === "function" ? props.fallback(e, reset) : props.fallback;
|
|
41
|
+
}
|
|
42
|
+
}, void 0, { name: "ErrorBoundary" });
|
|
43
|
+
}
|
|
@@ -9,10 +9,10 @@ export interface ErrorBoundaryProps {
|
|
|
9
9
|
* Catches synchronous errors thrown during child rendering.
|
|
10
10
|
*
|
|
11
11
|
* When a child throws, renders `fallback` instead. `fallback` can be a
|
|
12
|
-
* static value or a function `(err, reset) => UI
|
|
12
|
+
* static value or a function `(err, reset) => UI`, calling `reset()` clears
|
|
13
13
|
* the error state and retries rendering the children.
|
|
14
14
|
*
|
|
15
|
-
* Returns a memo
|
|
15
|
+
* Returns a memo: works in both JSX and `html` templates.
|
|
16
16
|
*
|
|
17
17
|
* Note: Only catches errors thrown synchronously during the render phase
|
|
18
18
|
* (memo evaluation). Async errors inside effects are not caught here.
|
|
@@ -3,10 +3,10 @@ import { createMemo, createSignal } from '@fluixi/reactive/signal';
|
|
|
3
3
|
* Catches synchronous errors thrown during child rendering.
|
|
4
4
|
*
|
|
5
5
|
* When a child throws, renders `fallback` instead. `fallback` can be a
|
|
6
|
-
* static value or a function `(err, reset) => UI
|
|
6
|
+
* static value or a function `(err, reset) => UI`, calling `reset()` clears
|
|
7
7
|
* the error state and retries rendering the children.
|
|
8
8
|
*
|
|
9
|
-
* Returns a memo
|
|
9
|
+
* Returns a memo: works in both JSX and `html` templates.
|
|
10
10
|
*
|
|
11
11
|
* Note: Only catches errors thrown synchronously during the render phase
|
|
12
12
|
* (memo evaluation). Async errors inside effects are not caught here.
|
|
@@ -39,7 +39,7 @@ export function ErrorBoundary(props) {
|
|
|
39
39
|
return content;
|
|
40
40
|
}
|
|
41
41
|
catch (e) {
|
|
42
|
-
// Caught a synchronous render error
|
|
42
|
+
// Caught a synchronous render error: switch to fallback.
|
|
43
43
|
setError(e);
|
|
44
44
|
return typeof props.fallback === 'function'
|
|
45
45
|
? props.fallback(e, reset)
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/flow/error-boundary.ts
|
|
2
|
+
import { createMemo, createSignal } from "@fluixi/reactive/signal";
|
|
3
|
+
function ErrorBoundary(props) {
|
|
4
|
+
const [error, setError] = createSignal(null);
|
|
5
|
+
const reset = () => setError(null);
|
|
6
|
+
return createMemo(() => {
|
|
7
|
+
const err = error();
|
|
8
|
+
if (err !== null) {
|
|
9
|
+
return typeof props.fallback === "function" ? props.fallback(err, reset) : props.fallback;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const content = typeof props.children === "function" ? props.children() : props.children;
|
|
13
|
+
return content;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
setError(e);
|
|
16
|
+
return typeof props.fallback === "function" ? props.fallback(e, reset) : props.fallback;
|
|
17
|
+
}
|
|
18
|
+
}, void 0, { name: "ErrorBoundary" });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
ErrorBoundary
|
|
22
|
+
};
|
package/dist/lib/flow/for.cjs
CHANGED
|
@@ -1 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/flow/for.ts
|
|
21
|
+
var for_exports = {};
|
|
22
|
+
__export(for_exports, {
|
|
23
|
+
For: () => For
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(for_exports);
|
|
26
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
27
|
+
|
|
28
|
+
// src/lib/flow/utils.ts
|
|
29
|
+
function resolveReactiveProp(read) {
|
|
30
|
+
return () => {
|
|
31
|
+
const value = read();
|
|
32
|
+
return typeof value === "function" ? value() : value;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/lib/dom/hydration-state.ts
|
|
37
|
+
var hydration = {
|
|
38
|
+
active: false,
|
|
39
|
+
cursor: null,
|
|
40
|
+
parents: []
|
|
41
|
+
};
|
|
42
|
+
function ascendPast(node) {
|
|
43
|
+
const idx = hydration.parents.lastIndexOf(node);
|
|
44
|
+
if (idx !== -1) hydration.parents.length = idx;
|
|
45
|
+
hydration.cursor = node.nextSibling;
|
|
46
|
+
}
|
|
47
|
+
function hydrateAdvancePast(rendered) {
|
|
48
|
+
if (!hydration.active || rendered == null) return;
|
|
49
|
+
const last = Array.isArray(rendered) ? rendered[rendered.length - 1] : rendered;
|
|
50
|
+
if (last && typeof last.nodeType === "number") {
|
|
51
|
+
ascendPast(last);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/lib/flow/for.ts
|
|
56
|
+
function For(props) {
|
|
57
|
+
const each = resolveReactiveProp(() => props.each);
|
|
58
|
+
const fallback = () => props.fallback ?? null;
|
|
59
|
+
const render = (item, index) => {
|
|
60
|
+
const children = props.children;
|
|
61
|
+
const rendered = Array.isArray(children) ? children.map((c) => typeof c === "function" ? c(item, index) : c) : typeof children === "function" ? children(item, index) : children;
|
|
62
|
+
hydrateAdvancePast(rendered);
|
|
63
|
+
return rendered;
|
|
64
|
+
};
|
|
65
|
+
return props.by ? (0, import_signal.keyArray)(each, props.by, (item, index) => render(item, index), { fallback }) : (0, import_signal.mapArray)(each, (item, index) => render(item, index), { fallback });
|
|
66
|
+
}
|
package/dist/lib/flow/for.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
2
|
type EachSource<T> = ReadonlyArray<T> | (() => ReadonlyArray<T> | null | undefined) | Accessor<ReadonlyArray<T>> | null | undefined | false;
|
|
3
|
-
/** Props when `by` is
|
|
3
|
+
/** Props when `by` is not provided: item is the plain value `T`. */
|
|
4
4
|
export interface ForPropsUnkeyed<T, U = any> {
|
|
5
|
-
/** Reactive array to iterate over
|
|
5
|
+
/** Reactive array to iterate over: static, readonly, accessor, or signal. */
|
|
6
6
|
each: EachSource<T>;
|
|
7
7
|
/** Rendered when the array is empty or nullish. */
|
|
8
8
|
fallback?: any;
|
|
@@ -15,15 +15,15 @@ export interface ForPropsUnkeyed<T, U = any> {
|
|
|
15
15
|
children: (item: T, index: Accessor<number>) => U;
|
|
16
16
|
by?: undefined;
|
|
17
17
|
}
|
|
18
|
-
/** Props when `by`
|
|
18
|
+
/** Props when `by` is provided: item is a reactive `Accessor<T>`. */
|
|
19
19
|
export interface ForPropsKeyed<T, U = any> {
|
|
20
|
-
/** Reactive array to iterate over
|
|
20
|
+
/** Reactive array to iterate over: static, readonly, accessor, or signal. */
|
|
21
21
|
each: EachSource<T>;
|
|
22
22
|
/** Rendered when the array is empty or nullish. */
|
|
23
23
|
fallback?: any;
|
|
24
24
|
/**
|
|
25
25
|
* Render function called once per unique key.
|
|
26
|
-
* `item` is a reactive accessor
|
|
26
|
+
* `item` is a reactive accessor: call `item()` inside to read the current value.
|
|
27
27
|
* The same DOM is reused whenever `by(item)` returns the same key, even if the
|
|
28
28
|
* object reference changes.
|
|
29
29
|
*
|
|
@@ -39,21 +39,21 @@ export interface ForPropsKeyed<T, U = any> {
|
|
|
39
39
|
}
|
|
40
40
|
export type ForProps<T, U = any> = ForPropsUnkeyed<T, U> | ForPropsKeyed<T, U>;
|
|
41
41
|
/**
|
|
42
|
-
* Keyed list rendering
|
|
42
|
+
* Keyed list rendering: mirrors SolidJS `<For>`.
|
|
43
43
|
*
|
|
44
|
-
* Default: keyed by object reference. Same object at new index
|
|
44
|
+
* Default: keyed by object reference. Same object at new index -> only index
|
|
45
45
|
* signal updates (no DOM re-render). Removed items are disposed.
|
|
46
46
|
*
|
|
47
47
|
* With `by`: keyed by the return value of `by(item)`. When the same key is
|
|
48
48
|
* found in the previous render, the DOM entry is reused and the index signal
|
|
49
49
|
* is updated. The item accessor is a live `createMemo(() => list[idx()])` so
|
|
50
50
|
* that reading `item().someField` inside a reactive context creates a
|
|
51
|
-
* fine-grained dependency on the store proxy property
|
|
51
|
+
* fine-grained dependency on the store proxy property, not a frozen snapshot.
|
|
52
52
|
*
|
|
53
53
|
* @example Reference-keyed (default)
|
|
54
54
|
* <For each={items}>{(item, idx) => <li>{item.name}</li>}</For>
|
|
55
55
|
*
|
|
56
|
-
* @example Stable-key (by prop)
|
|
56
|
+
* @example Stable-key (by prop): survives object recreation
|
|
57
57
|
* <For each={rows} by={r => r.id}>
|
|
58
58
|
* {(row, idx) => <tr><td>{() => row().name}</td></tr>}
|
|
59
59
|
* </For>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,yBAAyB,CAAC;AAIvE,KAAK,UAAU,CAAC,CAAC,IACb,aAAa,CAAC,CAAC,CAAC,GAChB,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAC3C,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAC1B,IAAI,GACJ,SAAS,GACT,KAAK,CAAC;AAEV,
|
|
1
|
+
{"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,yBAAyB,CAAC;AAIvE,KAAK,UAAU,CAAC,CAAC,IACb,aAAa,CAAC,CAAC,CAAC,GAChB,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAC3C,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAC1B,IAAI,GACJ,SAAS,GACT,KAAK,CAAC;AAEV,oEAAoE;AACpE,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG;IACzC,6EAA6E;IAC7E,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACpB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClD,EAAE,CAAC,EAAE,SAAS,CAAC;CAChB;AAED,qEAAqE;AACrE,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG;IACvC,6EAA6E;IAC7E,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACpB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf;;;;;;;;OAQG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D;;;OAGG;IACH,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC;CACtB;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;AACrE,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC"}
|
package/dist/lib/flow/for.js
CHANGED
|
@@ -4,7 +4,7 @@ import { hydrateAdvancePast } from '../dom/hydration-state.js';
|
|
|
4
4
|
export function For(props) {
|
|
5
5
|
// Read `each` lazily through the prop getter so `each={items()}` re-runs inside
|
|
6
6
|
// mapArray's tracking memo (fine-grained keyed diffing), while `each={items}` still
|
|
7
|
-
// works
|
|
7
|
+
// works: resolveReactiveProp unwraps the accessor form once.
|
|
8
8
|
const each = resolveReactiveProp(() => props.each);
|
|
9
9
|
const fallback = () => props.fallback ?? null;
|
|
10
10
|
// Render the children (a fn, or an array of fn/values) for one item, then
|
|
@@ -19,7 +19,7 @@ export function For(props) {
|
|
|
19
19
|
hydrateAdvancePast(rendered);
|
|
20
20
|
return rendered;
|
|
21
21
|
};
|
|
22
|
-
// `by`
|
|
22
|
+
// `by` -> key-function reconciliation (item is a live accessor); default ->
|
|
23
23
|
// reference reconciliation (item is the plain value). Both keep each item in
|
|
24
24
|
// its own root so list items stay owner-stable.
|
|
25
25
|
return props.by
|
package/dist/lib/flow/for.mjs
CHANGED
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/flow/for.ts
|
|
2
|
+
import { mapArray, keyArray } from "@fluixi/reactive/signal";
|
|
3
|
+
|
|
4
|
+
// src/lib/flow/utils.ts
|
|
5
|
+
function resolveReactiveProp(read) {
|
|
6
|
+
return () => {
|
|
7
|
+
const value = read();
|
|
8
|
+
return typeof value === "function" ? value() : value;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/lib/dom/hydration-state.ts
|
|
13
|
+
var hydration = {
|
|
14
|
+
active: false,
|
|
15
|
+
cursor: null,
|
|
16
|
+
parents: []
|
|
17
|
+
};
|
|
18
|
+
function ascendPast(node) {
|
|
19
|
+
const idx = hydration.parents.lastIndexOf(node);
|
|
20
|
+
if (idx !== -1) hydration.parents.length = idx;
|
|
21
|
+
hydration.cursor = node.nextSibling;
|
|
22
|
+
}
|
|
23
|
+
function hydrateAdvancePast(rendered) {
|
|
24
|
+
if (!hydration.active || rendered == null) return;
|
|
25
|
+
const last = Array.isArray(rendered) ? rendered[rendered.length - 1] : rendered;
|
|
26
|
+
if (last && typeof last.nodeType === "number") {
|
|
27
|
+
ascendPast(last);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/lib/flow/for.ts
|
|
32
|
+
function For(props) {
|
|
33
|
+
const each = resolveReactiveProp(() => props.each);
|
|
34
|
+
const fallback = () => props.fallback ?? null;
|
|
35
|
+
const render = (item, index) => {
|
|
36
|
+
const children = props.children;
|
|
37
|
+
const rendered = Array.isArray(children) ? children.map((c) => typeof c === "function" ? c(item, index) : c) : typeof children === "function" ? children(item, index) : children;
|
|
38
|
+
hydrateAdvancePast(rendered);
|
|
39
|
+
return rendered;
|
|
40
|
+
};
|
|
41
|
+
return props.by ? keyArray(each, props.by, (item, index) => render(item, index), { fallback }) : mapArray(each, (item, index) => render(item, index), { fallback });
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
For
|
|
45
|
+
};
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/flow/index-flow.ts
|
|
21
|
+
var index_flow_exports = {};
|
|
22
|
+
__export(index_flow_exports, {
|
|
23
|
+
Index: () => Index
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_flow_exports);
|
|
26
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
27
|
+
|
|
28
|
+
// src/lib/flow/utils.ts
|
|
29
|
+
function resolveReactiveProp(read) {
|
|
30
|
+
return () => {
|
|
31
|
+
const value = read();
|
|
32
|
+
return typeof value === "function" ? value() : value;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/lib/dom/hydration-state.ts
|
|
37
|
+
var hydration = {
|
|
38
|
+
active: false,
|
|
39
|
+
cursor: null,
|
|
40
|
+
parents: []
|
|
41
|
+
};
|
|
42
|
+
function ascendPast(node) {
|
|
43
|
+
const idx = hydration.parents.lastIndexOf(node);
|
|
44
|
+
if (idx !== -1) hydration.parents.length = idx;
|
|
45
|
+
hydration.cursor = node.nextSibling;
|
|
46
|
+
}
|
|
47
|
+
function hydrateAdvancePast(rendered) {
|
|
48
|
+
if (!hydration.active || rendered == null) return;
|
|
49
|
+
const last = Array.isArray(rendered) ? rendered[rendered.length - 1] : rendered;
|
|
50
|
+
if (last && typeof last.nodeType === "number") {
|
|
51
|
+
ascendPast(last);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/lib/flow/index-flow.ts
|
|
56
|
+
function Index(props) {
|
|
57
|
+
const each = resolveReactiveProp(() => props.each);
|
|
58
|
+
return (0, import_signal.indexArray)(
|
|
59
|
+
each,
|
|
60
|
+
(item, index) => {
|
|
61
|
+
const rendered = props.children(item, index);
|
|
62
|
+
hydrateAdvancePast(rendered);
|
|
63
|
+
return rendered;
|
|
64
|
+
},
|
|
65
|
+
{ fallback: () => props.fallback ?? null }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -6,7 +6,7 @@ export interface IndexProps<T, U = any> {
|
|
|
6
6
|
fallback?: any;
|
|
7
7
|
/**
|
|
8
8
|
* Render function called once per stable index slot.
|
|
9
|
-
* `item` is a reactive accessor
|
|
9
|
+
* `item` is a reactive accessor: updates when the item at that index changes.
|
|
10
10
|
* `index` is a plain number (stable).
|
|
11
11
|
*
|
|
12
12
|
* JSX: <Index each={items()}>{(item, index) => <li>{item().name}</li>}</Index>
|
|
@@ -15,20 +15,20 @@ export interface IndexProps<T, U = any> {
|
|
|
15
15
|
children: (item: Accessor<T>, index: number) => U;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Non-keyed list rendering
|
|
18
|
+
* Non-keyed list rendering: mirrors SolidJS `<Index>`.
|
|
19
19
|
*
|
|
20
20
|
* Keyed by position. When the list grows, new slots are created.
|
|
21
21
|
* When it shrinks, trailing slots are disposed. When an item at a
|
|
22
22
|
* given index changes value, only the `item` signal updates (no re-render).
|
|
23
|
-
* Returns a memo of the rendered array
|
|
23
|
+
* Returns a memo of the rendered array: works in both JSX and `html` templates.
|
|
24
24
|
*
|
|
25
25
|
* @example JSX
|
|
26
26
|
* <Index each={items()} fallback={<p>Empty</p>}>
|
|
27
|
-
* {(item, index) => <li>{index}
|
|
27
|
+
* {(item, index) => <li>{index}: {item().name}</li>}
|
|
28
28
|
* </Index>
|
|
29
29
|
*
|
|
30
30
|
* @example html template
|
|
31
|
-
* Index({ each: items, children: (item, i) => html`<li>${i}
|
|
31
|
+
* Index({ each: items, children: (item, i) => html`<li>${i}. ${item().name}</li>` })
|
|
32
32
|
*/
|
|
33
33
|
export declare function Index<T, U = any>(props: IndexProps<T, U>): Accessor<U[] | any>;
|
|
34
34
|
//# sourceMappingURL=index-flow.d.ts.map
|
|
@@ -2,20 +2,20 @@ import { indexArray } from '@fluixi/reactive/signal';
|
|
|
2
2
|
import { resolveReactiveProp } from './utils.js';
|
|
3
3
|
import { hydrateAdvancePast } from '../dom/hydration-state.js';
|
|
4
4
|
/**
|
|
5
|
-
* Non-keyed list rendering
|
|
5
|
+
* Non-keyed list rendering: mirrors SolidJS `<Index>`.
|
|
6
6
|
*
|
|
7
7
|
* Keyed by position. When the list grows, new slots are created.
|
|
8
8
|
* When it shrinks, trailing slots are disposed. When an item at a
|
|
9
9
|
* given index changes value, only the `item` signal updates (no re-render).
|
|
10
|
-
* Returns a memo of the rendered array
|
|
10
|
+
* Returns a memo of the rendered array: works in both JSX and `html` templates.
|
|
11
11
|
*
|
|
12
12
|
* @example JSX
|
|
13
13
|
* <Index each={items()} fallback={<p>Empty</p>}>
|
|
14
|
-
* {(item, index) => <li>{index}
|
|
14
|
+
* {(item, index) => <li>{index}: {item().name}</li>}
|
|
15
15
|
* </Index>
|
|
16
16
|
*
|
|
17
17
|
* @example html template
|
|
18
|
-
* Index({ each: items, children: (item, i) => html`<li>${i}
|
|
18
|
+
* Index({ each: items, children: (item, i) => html`<li>${i}. ${item().name}</li>` })
|
|
19
19
|
*/
|
|
20
20
|
export function Index(props) {
|
|
21
21
|
const each = resolveReactiveProp(() => props.each);
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/flow/index-flow.ts
|
|
2
|
+
import { indexArray } from "@fluixi/reactive/signal";
|
|
3
|
+
|
|
4
|
+
// src/lib/flow/utils.ts
|
|
5
|
+
function resolveReactiveProp(read) {
|
|
6
|
+
return () => {
|
|
7
|
+
const value = read();
|
|
8
|
+
return typeof value === "function" ? value() : value;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/lib/dom/hydration-state.ts
|
|
13
|
+
var hydration = {
|
|
14
|
+
active: false,
|
|
15
|
+
cursor: null,
|
|
16
|
+
parents: []
|
|
17
|
+
};
|
|
18
|
+
function ascendPast(node) {
|
|
19
|
+
const idx = hydration.parents.lastIndexOf(node);
|
|
20
|
+
if (idx !== -1) hydration.parents.length = idx;
|
|
21
|
+
hydration.cursor = node.nextSibling;
|
|
22
|
+
}
|
|
23
|
+
function hydrateAdvancePast(rendered) {
|
|
24
|
+
if (!hydration.active || rendered == null) return;
|
|
25
|
+
const last = Array.isArray(rendered) ? rendered[rendered.length - 1] : rendered;
|
|
26
|
+
if (last && typeof last.nodeType === "number") {
|
|
27
|
+
ascendPast(last);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/lib/flow/index-flow.ts
|
|
32
|
+
function Index(props) {
|
|
33
|
+
const each = resolveReactiveProp(() => props.each);
|
|
34
|
+
return indexArray(
|
|
35
|
+
each,
|
|
36
|
+
(item, index) => {
|
|
37
|
+
const rendered = props.children(item, index);
|
|
38
|
+
hydrateAdvancePast(rendered);
|
|
39
|
+
return rendered;
|
|
40
|
+
},
|
|
41
|
+
{ fallback: () => props.fallback ?? null }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
Index
|
|
46
|
+
};
|