create-flow-os 0.0.1-dev.1771840262 → 0.0.1-dev.1771979366
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/package.json +8 -23
- package/{profiles/server/packages/style → src/create}/index.ts +31 -30
- package/src/index.ts +14 -0
- package/src/init/index.ts +66 -0
- package/src/init/lib.ts +36 -0
- package/src/init/scaffold.ts +43 -0
- package/LICENSE +0 -97
- package/README.md +0 -26
- package/bin/index.js +0 -1215
- package/config.json +0 -89
- package/lib/utils.ts +0 -91
- package/packages/client/client/root.css +0 -9
- package/packages/client/client/root.tsx +0 -6
- package/packages/client/client/routes/404.tsx +0 -24
- package/packages/client/client/routes/index.tsx +0 -48
- package/packages/server/server/routes/hello.get.ts +0 -3
- package/profiles/client/.dockerignore +0 -12
- package/profiles/client/.oxfmtrc.json +0 -7
- package/profiles/client/.oxlintrc.json +0 -13
- package/profiles/client/.vscode/settings.json +0 -12
- package/profiles/client/Dockerfile +0 -26
- package/profiles/client/README.md +0 -34
- package/profiles/client/bun.lock +0 -352
- package/profiles/client/client/root.css +0 -9
- package/profiles/client/client/root.tsx +0 -6
- package/profiles/client/client/routes/404.tsx +0 -24
- package/profiles/client/client/routes/about.tsx +0 -7
- package/profiles/client/client/routes/index.tsx +0 -48
- package/profiles/client/flow.config.ts +0 -6
- package/profiles/client/index.html +0 -5
- package/profiles/client/package.json +0 -32
- package/profiles/client/packages/client/LICENSE +0 -97
- package/profiles/client/packages/client/build/config.ts +0 -211
- package/profiles/client/packages/client/build/vite.ts +0 -98
- package/profiles/client/packages/client/features/attrs.ts +0 -32
- package/profiles/client/packages/client/features/class-flow.ts +0 -116
- package/profiles/client/packages/client/features/index.ts +0 -8
- package/profiles/client/packages/client/features/pseudo-injector.ts +0 -40
- package/profiles/client/packages/client/features/style-flow.ts +0 -106
- package/profiles/client/packages/client/features/style.ts +0 -27
- package/profiles/client/packages/client/features/utils.ts +0 -4
- package/profiles/client/packages/client/features/viewport.ts +0 -20
- package/profiles/client/packages/client/index.ts +0 -7
- package/profiles/client/packages/client/package.json +0 -48
- package/profiles/client/packages/client/runtime/dom.ts +0 -2
- package/profiles/client/packages/client/runtime/jsx-dev-runtime.ts +0 -1
- package/profiles/client/packages/client/runtime/jsx-runtime.ts +0 -1
- package/profiles/client/packages/client/runtime/jsx-types.d.ts +0 -66
- package/profiles/client/packages/client/runtime/jsx.ts +0 -101
- package/profiles/client/packages/client/scripts/build.ts +0 -14
- package/profiles/client/packages/client/scripts/preview.ts +0 -14
- package/profiles/client/packages/client/scripts/start-dev.ts +0 -49
- package/profiles/client/packages/core/LICENSE +0 -97
- package/profiles/client/packages/core/dom.ts +0 -43
- package/profiles/client/packages/core/for.ts +0 -42
- package/profiles/client/packages/core/index.ts +0 -5
- package/profiles/client/packages/core/lifecycle.ts +0 -6
- package/profiles/client/packages/core/package.json +0 -16
- package/profiles/client/packages/core/show-switch.ts +0 -56
- package/profiles/client/packages/core/state.ts +0 -56
- package/profiles/client/packages/router/LICENSE +0 -97
- package/profiles/client/packages/router/index.ts +0 -20
- package/profiles/client/packages/router/matcher.ts +0 -105
- package/profiles/client/packages/router/package.json +0 -15
- package/profiles/client/packages/router/router.ts +0 -185
- package/profiles/client/packages/router/types.ts +0 -34
- package/profiles/client/packages/router/utils.ts +0 -45
- package/profiles/client/packages/style/LICENSE +0 -97
- package/profiles/client/packages/style/breakpoints.ts +0 -20
- package/profiles/client/packages/style/extension/.vscodeignore +0 -5
- package/profiles/client/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/client/packages/style/extension/out/extension.js +0 -130
- package/profiles/client/packages/style/extension/package.json +0 -24
- package/profiles/client/packages/style/extension/src/extension.ts +0 -146
- package/profiles/client/packages/style/extension/tsconfig.json +0 -12
- package/profiles/client/packages/style/index.ts +0 -30
- package/profiles/client/packages/style/package.json +0 -20
- package/profiles/client/packages/style/react.ts +0 -68
- package/profiles/client/packages/style/resolve.ts +0 -127
- package/profiles/client/packages/style/server.ts +0 -299
- package/profiles/client/packages/style/shorthand.ts +0 -96
- package/profiles/client/packages/style/style-builder/button.ts +0 -41
- package/profiles/client/packages/style/style-builder/constants.ts +0 -16
- package/profiles/client/packages/style/style-builder/dom.ts +0 -18
- package/profiles/client/packages/style/style-builder/index.ts +0 -48
- package/profiles/client/packages/style/style-builder/panel.ts +0 -69
- package/profiles/client/packages/style/style-builder/position.ts +0 -25
- package/profiles/client/packages/style/visual-builder.ts +0 -822
- package/profiles/client/packages/style/vite-plugin.ts +0 -86
- package/profiles/client/tsconfig.json +0 -30
- package/profiles/full/.dockerignore +0 -12
- package/profiles/full/.oxfmtrc.json +0 -7
- package/profiles/full/.oxlintrc.json +0 -13
- package/profiles/full/.vscode/settings.json +0 -12
- package/profiles/full/Dockerfile +0 -26
- package/profiles/full/README.md +0 -34
- package/profiles/full/bun.lock +0 -352
- package/profiles/full/client/root.css +0 -9
- package/profiles/full/client/root.tsx +0 -6
- package/profiles/full/client/routes/404.tsx +0 -24
- package/profiles/full/client/routes/about.tsx +0 -7
- package/profiles/full/client/routes/index.tsx +0 -48
- package/profiles/full/flow.config.ts +0 -6
- package/profiles/full/index.html +0 -5
- package/profiles/full/package.json +0 -33
- package/profiles/full/packages/client/LICENSE +0 -97
- package/profiles/full/packages/client/build/config.ts +0 -211
- package/profiles/full/packages/client/build/vite.ts +0 -98
- package/profiles/full/packages/client/features/attrs.ts +0 -32
- package/profiles/full/packages/client/features/class-flow.ts +0 -116
- package/profiles/full/packages/client/features/index.ts +0 -8
- package/profiles/full/packages/client/features/pseudo-injector.ts +0 -40
- package/profiles/full/packages/client/features/style-flow.ts +0 -106
- package/profiles/full/packages/client/features/style.ts +0 -27
- package/profiles/full/packages/client/features/utils.ts +0 -4
- package/profiles/full/packages/client/features/viewport.ts +0 -20
- package/profiles/full/packages/client/index.ts +0 -7
- package/profiles/full/packages/client/package.json +0 -48
- package/profiles/full/packages/client/runtime/dom.ts +0 -2
- package/profiles/full/packages/client/runtime/jsx-dev-runtime.ts +0 -1
- package/profiles/full/packages/client/runtime/jsx-runtime.ts +0 -1
- package/profiles/full/packages/client/runtime/jsx-types.d.ts +0 -66
- package/profiles/full/packages/client/runtime/jsx.ts +0 -101
- package/profiles/full/packages/client/scripts/build.ts +0 -14
- package/profiles/full/packages/client/scripts/preview.ts +0 -14
- package/profiles/full/packages/client/scripts/start-dev.ts +0 -49
- package/profiles/full/packages/core/LICENSE +0 -97
- package/profiles/full/packages/core/dom.ts +0 -43
- package/profiles/full/packages/core/for.ts +0 -42
- package/profiles/full/packages/core/index.ts +0 -5
- package/profiles/full/packages/core/lifecycle.ts +0 -6
- package/profiles/full/packages/core/package.json +0 -16
- package/profiles/full/packages/core/show-switch.ts +0 -56
- package/profiles/full/packages/core/state.ts +0 -56
- package/profiles/full/packages/router/LICENSE +0 -97
- package/profiles/full/packages/router/index.ts +0 -20
- package/profiles/full/packages/router/matcher.ts +0 -105
- package/profiles/full/packages/router/package.json +0 -15
- package/profiles/full/packages/router/router.ts +0 -185
- package/profiles/full/packages/router/types.ts +0 -34
- package/profiles/full/packages/router/utils.ts +0 -45
- package/profiles/full/packages/server/LICENSE +0 -97
- package/profiles/full/packages/server/core.ts +0 -140
- package/profiles/full/packages/server/index.ts +0 -24
- package/profiles/full/packages/server/package.json +0 -32
- package/profiles/full/packages/server/plugin.ts +0 -79
- package/profiles/full/packages/server/production.ts +0 -75
- package/profiles/full/packages/server/scripts/start.ts +0 -11
- package/profiles/full/packages/style/LICENSE +0 -97
- package/profiles/full/packages/style/breakpoints.ts +0 -20
- package/profiles/full/packages/style/extension/.vscodeignore +0 -5
- package/profiles/full/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/full/packages/style/extension/out/extension.js +0 -130
- package/profiles/full/packages/style/extension/package.json +0 -24
- package/profiles/full/packages/style/extension/src/extension.ts +0 -146
- package/profiles/full/packages/style/extension/tsconfig.json +0 -12
- package/profiles/full/packages/style/index.ts +0 -30
- package/profiles/full/packages/style/package.json +0 -20
- package/profiles/full/packages/style/react.ts +0 -68
- package/profiles/full/packages/style/resolve.ts +0 -127
- package/profiles/full/packages/style/server.ts +0 -299
- package/profiles/full/packages/style/shorthand.ts +0 -96
- package/profiles/full/packages/style/style-builder/button.ts +0 -41
- package/profiles/full/packages/style/style-builder/constants.ts +0 -16
- package/profiles/full/packages/style/style-builder/dom.ts +0 -18
- package/profiles/full/packages/style/style-builder/index.ts +0 -48
- package/profiles/full/packages/style/style-builder/panel.ts +0 -69
- package/profiles/full/packages/style/style-builder/position.ts +0 -25
- package/profiles/full/packages/style/visual-builder.ts +0 -822
- package/profiles/full/packages/style/vite-plugin.ts +0 -86
- package/profiles/full/server/routes/hello.get.ts +0 -3
- package/profiles/full/tsconfig.json +0 -30
- package/profiles/server/.dockerignore +0 -12
- package/profiles/server/.oxfmtrc.json +0 -7
- package/profiles/server/.oxlintrc.json +0 -13
- package/profiles/server/.vscode/settings.json +0 -12
- package/profiles/server/Dockerfile +0 -26
- package/profiles/server/README.md +0 -34
- package/profiles/server/bun.lock +0 -352
- package/profiles/server/flow.config.ts +0 -7
- package/profiles/server/index.html +0 -5
- package/profiles/server/package.json +0 -30
- package/profiles/server/packages/core/LICENSE +0 -97
- package/profiles/server/packages/core/dom.ts +0 -43
- package/profiles/server/packages/core/for.ts +0 -42
- package/profiles/server/packages/core/index.ts +0 -5
- package/profiles/server/packages/core/lifecycle.ts +0 -6
- package/profiles/server/packages/core/package.json +0 -16
- package/profiles/server/packages/core/show-switch.ts +0 -56
- package/profiles/server/packages/core/state.ts +0 -56
- package/profiles/server/packages/router/LICENSE +0 -97
- package/profiles/server/packages/router/index.ts +0 -20
- package/profiles/server/packages/router/matcher.ts +0 -105
- package/profiles/server/packages/router/package.json +0 -15
- package/profiles/server/packages/router/router.ts +0 -185
- package/profiles/server/packages/router/types.ts +0 -34
- package/profiles/server/packages/router/utils.ts +0 -45
- package/profiles/server/packages/server/LICENSE +0 -97
- package/profiles/server/packages/server/core.ts +0 -140
- package/profiles/server/packages/server/index.ts +0 -24
- package/profiles/server/packages/server/package.json +0 -32
- package/profiles/server/packages/server/plugin.ts +0 -79
- package/profiles/server/packages/server/production.ts +0 -75
- package/profiles/server/packages/server/scripts/start.ts +0 -11
- package/profiles/server/packages/style/LICENSE +0 -97
- package/profiles/server/packages/style/breakpoints.ts +0 -20
- package/profiles/server/packages/style/extension/.vscodeignore +0 -5
- package/profiles/server/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/server/packages/style/extension/out/extension.js +0 -130
- package/profiles/server/packages/style/extension/package.json +0 -24
- package/profiles/server/packages/style/extension/src/extension.ts +0 -146
- package/profiles/server/packages/style/extension/tsconfig.json +0 -12
- package/profiles/server/packages/style/package.json +0 -20
- package/profiles/server/packages/style/react.ts +0 -68
- package/profiles/server/packages/style/resolve.ts +0 -127
- package/profiles/server/packages/style/server.ts +0 -299
- package/profiles/server/packages/style/shorthand.ts +0 -96
- package/profiles/server/packages/style/style-builder/button.ts +0 -41
- package/profiles/server/packages/style/style-builder/constants.ts +0 -16
- package/profiles/server/packages/style/style-builder/dom.ts +0 -18
- package/profiles/server/packages/style/style-builder/index.ts +0 -48
- package/profiles/server/packages/style/style-builder/panel.ts +0 -69
- package/profiles/server/packages/style/style-builder/position.ts +0 -25
- package/profiles/server/packages/style/visual-builder.ts +0 -822
- package/profiles/server/packages/style/vite-plugin.ts +0 -86
- package/profiles/server/server/routes/hello.get.ts +0 -3
- package/profiles/server/tsconfig.json +0 -30
- package/templates/flow.config.client.ts +0 -6
- package/templates/flow.config.full.ts +0 -6
- package/templates/flow.config.server.ts +0 -7
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { effect } from '@flow.os/core';
|
|
2
|
-
import { isGetter } from './utils.js';
|
|
3
|
-
import {
|
|
4
|
-
VIEWPORT_KEYS,
|
|
5
|
-
PSEUDO_KEYS,
|
|
6
|
-
resolveLayer,
|
|
7
|
-
resolvePseudoStyle,
|
|
8
|
-
type PlainLayer,
|
|
9
|
-
type ViewportKey,
|
|
10
|
-
type PseudoKey,
|
|
11
|
-
} from '@flow.os/style';
|
|
12
|
-
import { getViewportBreakpoint } from './viewport.js';
|
|
13
|
-
import { getPseudoClass } from './pseudo-injector.js';
|
|
14
|
-
|
|
15
|
-
const RESERVED = new Set<string>([...VIEWPORT_KEYS, ...PSEUDO_KEYS]);
|
|
16
|
-
|
|
17
|
-
/** Chiama getter e restituisce oggetto plain (una livello, escluse chiavi reserved). */
|
|
18
|
-
function gatherPlain(obj: Record<string, unknown> | null | undefined): PlainLayer {
|
|
19
|
-
const out: PlainLayer = {};
|
|
20
|
-
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return out;
|
|
21
|
-
for (const [k, v] of Object.entries(obj)) {
|
|
22
|
-
if (RESERVED.has(k)) continue;
|
|
23
|
-
if (v === undefined || v === null) continue;
|
|
24
|
-
if (isGetter(v)) {
|
|
25
|
-
const x = (v as () => unknown)();
|
|
26
|
-
if (typeof x === 'boolean') out[k] = x;
|
|
27
|
-
else if (typeof x === 'number' || typeof x === 'string') out[k] = x;
|
|
28
|
-
else if (Array.isArray(x) && x.length === 2 && isGetter(x[0]))
|
|
29
|
-
out[k] = String((x[0] as () => unknown)()) + String(x[1]);
|
|
30
|
-
else out[k] = String(x);
|
|
31
|
-
} else if (typeof v === 'object' && v !== null && !(v instanceof Node)) {
|
|
32
|
-
if (k === 'base') out['base'] = (v as Record<string, string>)['base'] ?? String(v);
|
|
33
|
-
// nested layer (mob/tab/des/hover/...) già esclusi da RESERVED
|
|
34
|
-
} else {
|
|
35
|
-
out[k] = v as string | number | boolean;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Normalizza value in base string + flat object. */
|
|
42
|
-
function normalize(
|
|
43
|
-
value: unknown
|
|
44
|
-
): { base: string; flat: Record<string, unknown> } {
|
|
45
|
-
if (value == null) return { base: '', flat: {} };
|
|
46
|
-
if (typeof value === 'string') return { base: value, flat: {} };
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
const base = typeof value[0] === 'string' ? value[0] : '';
|
|
49
|
-
const flat = (value[1] && typeof value[1] === 'object' && !Array.isArray(value[1]))
|
|
50
|
-
? (value[1] as Record<string, unknown>)
|
|
51
|
-
: {};
|
|
52
|
-
return { base, flat };
|
|
53
|
-
}
|
|
54
|
-
if (typeof value === 'object' && !Array.isArray(value) && !(value instanceof Node)) {
|
|
55
|
-
const flat = value as Record<string, unknown>;
|
|
56
|
-
const base = typeof flat['base'] === 'string' ? flat['base'] : '';
|
|
57
|
-
return { base, flat };
|
|
58
|
-
}
|
|
59
|
-
return { base: '', flat: {} };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function applyStyleFlow(el: HTMLElement, value: unknown): void {
|
|
63
|
-
if (value == null) return;
|
|
64
|
-
const { base, flat } = normalize(value);
|
|
65
|
-
let prevStyleKeys: string[] = [];
|
|
66
|
-
|
|
67
|
-
effect(() => {
|
|
68
|
-
const viewport: ViewportKey = getViewportBreakpoint();
|
|
69
|
-
const plainBase = gatherPlain(flat);
|
|
70
|
-
if (base) plainBase.base = (plainBase.base ? `${plainBase.base} ` : '') + base;
|
|
71
|
-
const viewportLayer = flat[viewport];
|
|
72
|
-
const plainViewport = gatherPlain(
|
|
73
|
-
viewportLayer && typeof viewportLayer === 'object' && !Array.isArray(viewportLayer)
|
|
74
|
-
? (viewportLayer as Record<string, unknown>)
|
|
75
|
-
: {}
|
|
76
|
-
);
|
|
77
|
-
const merged: PlainLayer = { ...plainBase };
|
|
78
|
-
if (plainViewport.base) merged.base = (merged.base ? `${merged.base} ` : '') + plainViewport.base;
|
|
79
|
-
for (const [k, v] of Object.entries(plainViewport)) {
|
|
80
|
-
if (k === 'base') continue;
|
|
81
|
-
(merged as Record<string, unknown>)[k] = v;
|
|
82
|
-
}
|
|
83
|
-
const resolved = resolveLayer(merged);
|
|
84
|
-
|
|
85
|
-
const pseudoClasses: string[] = [];
|
|
86
|
-
for (const pseudo of PSEUDO_KEYS) {
|
|
87
|
-
const rawPseudo = flat[pseudo];
|
|
88
|
-
const plainPseudo = gatherPlain(
|
|
89
|
-
rawPseudo && typeof rawPseudo === 'object' && !Array.isArray(rawPseudo)
|
|
90
|
-
? (rawPseudo as Record<string, unknown>)
|
|
91
|
-
: {}
|
|
92
|
-
);
|
|
93
|
-
const stylePseudo = resolvePseudoStyle(plainPseudo);
|
|
94
|
-
const cls = getPseudoClass(pseudo as PseudoKey, stylePseudo);
|
|
95
|
-
if (cls) pseudoClasses.push(cls);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
el.className = [resolved.class, ...pseudoClasses].filter(Boolean).join(' ');
|
|
99
|
-
for (const k of prevStyleKeys) el.style.removeProperty(k);
|
|
100
|
-
prevStyleKeys = Object.keys(resolved.style);
|
|
101
|
-
for (const [k, v] of Object.entries(resolved.style)) {
|
|
102
|
-
if (k.startsWith('--')) el.style.setProperty(k, v);
|
|
103
|
-
else (el.style as unknown as Record<string, string>)[k] = v;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { effect } from '@flow.os/core';
|
|
2
|
-
import { isGetter } from './utils.js';
|
|
3
|
-
import { setStyleProp, toStyleValue } from './class-flow.js';
|
|
4
|
-
|
|
5
|
-
export function applyStyle(el: HTMLElement, styleVal: unknown): void {
|
|
6
|
-
if (styleVal == null) return;
|
|
7
|
-
if (isGetter(styleVal)) {
|
|
8
|
-
effect(() => {
|
|
9
|
-
const style = (styleVal as () => Record<string, string> | string)();
|
|
10
|
-
if (typeof style === 'string') {
|
|
11
|
-
el.setAttribute('style', style);
|
|
12
|
-
} else if (style && typeof style === 'object') {
|
|
13
|
-
for (const [sk, sv] of Object.entries(style)) setStyleProp(el, sk, toStyleValue(sv));
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (typeof styleVal !== 'object' || styleVal === null || styleVal instanceof Node) return;
|
|
19
|
-
const style = styleVal as Record<string, string | number | (() => string | number)>;
|
|
20
|
-
for (const [sk, sv] of Object.entries(style)) {
|
|
21
|
-
if (isGetter(sv)) {
|
|
22
|
-
effect(() => setStyleProp(el, sk, toStyleValue((sv as () => unknown)())));
|
|
23
|
-
} else {
|
|
24
|
-
setStyleProp(el, sk, toStyleValue(sv));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { state } from '@flow.os/core';
|
|
2
|
-
import type { ViewportKey } from '@flow.os/style';
|
|
3
|
-
import { getViewportKeyFromWidth } from '@flow.os/style';
|
|
4
|
-
|
|
5
|
-
const [getViewport, setViewport] = state<ViewportKey>('mob');
|
|
6
|
-
let subscribed = false;
|
|
7
|
-
|
|
8
|
-
function subscribe(): void {
|
|
9
|
-
if (subscribed) return;
|
|
10
|
-
subscribed = true;
|
|
11
|
-
const update = () => setViewport(getViewportKeyFromWidth(window.innerWidth));
|
|
12
|
-
update();
|
|
13
|
-
window.addEventListener('resize', update);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Breakpoint viewport reattivo (mob/tab/des). Una sola subscription condivisa. */
|
|
17
|
-
export function getViewportBreakpoint(): ViewportKey {
|
|
18
|
-
subscribe();
|
|
19
|
-
return getViewport();
|
|
20
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference path="./runtime/jsx-types.d.ts" />
|
|
2
|
-
// Like Tailwind: one package. Use s or styleFlow in JSX; FlowStyle() for imperative / other frameworks.
|
|
3
|
-
export { Fragment, jsx, jsxs, jsxDEV } from './runtime/jsx.js';
|
|
4
|
-
export { normalizeChild, setContent } from './runtime/dom.js';
|
|
5
|
-
export { default as config } from './build/config.js';
|
|
6
|
-
export { applyClassFlow, applyClassAndClassList, applyStyle, applyStyleFlow, applyAttrs } from './features/index.js';
|
|
7
|
-
export { FlowStyle } from '@flow.os/style';
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@flow.os/client",
|
|
3
|
-
"version": "0.0.5",
|
|
4
|
-
"license": "PolyForm-Shield-1.0.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./index.ts",
|
|
7
|
-
"types": "./index.ts",
|
|
8
|
-
"bin": {
|
|
9
|
-
"flow-os-dev": "./scripts/start-dev.ts",
|
|
10
|
-
"flow-os-build": "./scripts/build.ts",
|
|
11
|
-
"flow-os-preview": "./scripts/preview.ts"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@flow.os/core": "^0.0.1",
|
|
15
|
-
"@flow.os/router": "^0.0.1",
|
|
16
|
-
"@flow.os/style": "^0.0.1"
|
|
17
|
-
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"vite": ">=5.0.0"
|
|
20
|
-
},
|
|
21
|
-
"exports": {
|
|
22
|
-
".": {
|
|
23
|
-
"types": "./index.ts",
|
|
24
|
-
"import": "./index.ts",
|
|
25
|
-
"default": "./index.ts"
|
|
26
|
-
},
|
|
27
|
-
"./config": {
|
|
28
|
-
"types": "./build/config.ts",
|
|
29
|
-
"import": "./build/config.ts",
|
|
30
|
-
"default": "./build/config.ts"
|
|
31
|
-
},
|
|
32
|
-
"./vite": {
|
|
33
|
-
"types": "./build/vite.ts",
|
|
34
|
-
"import": "./build/vite.ts",
|
|
35
|
-
"default": "./build/vite.ts"
|
|
36
|
-
},
|
|
37
|
-
"./jsx-runtime": {
|
|
38
|
-
"types": "./runtime/jsx.ts",
|
|
39
|
-
"import": "./runtime/jsx.ts",
|
|
40
|
-
"default": "./runtime/jsx.ts"
|
|
41
|
-
},
|
|
42
|
-
"./jsx-dev-runtime": {
|
|
43
|
-
"types": "./runtime/jsx.ts",
|
|
44
|
-
"import": "./runtime/jsx.ts",
|
|
45
|
-
"default": "./runtime/jsx.ts"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './jsx.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './jsx.js';
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { StyleShorthandKey } from '@flow.os/style';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
namespace JSX {
|
|
5
|
-
type Element = Node;
|
|
6
|
-
|
|
7
|
-
/** classFlow (legacy) */
|
|
8
|
-
type ClassFlowValue = string | number | (() => string | number) | [() => number, string];
|
|
9
|
-
|
|
10
|
-
/** styleFlow: valori per proprietà stile (numero→px, getter, [getter, unità]). */
|
|
11
|
-
type StyleFlowStyleValue =
|
|
12
|
-
| number
|
|
13
|
-
| string
|
|
14
|
-
| (() => number | string)
|
|
15
|
-
| [() => number, string];
|
|
16
|
-
/** styleFlow: valori per classList (bool/getter). */
|
|
17
|
-
type StyleFlowClassValue = boolean | (() => boolean);
|
|
18
|
-
|
|
19
|
-
/** Layer per hover/active/focus: solo shorthand stile. */
|
|
20
|
-
interface StyleFlowPseudoLayer
|
|
21
|
-
extends Partial<Record<StyleShorthandKey, StyleFlowStyleValue>> {
|
|
22
|
-
[key: string]: StyleFlowStyleValue | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Layer styleFlow: base + responsive + pseudo + shorthand + classList. */
|
|
26
|
-
interface StyleFlowLayer
|
|
27
|
-
extends Partial<Record<StyleShorthandKey, StyleFlowStyleValue>> {
|
|
28
|
-
base?: string;
|
|
29
|
-
mob?: StyleFlowLayer;
|
|
30
|
-
tab?: StyleFlowLayer;
|
|
31
|
-
des?: StyleFlowLayer;
|
|
32
|
-
hover?: StyleFlowPseudoLayer;
|
|
33
|
-
active?: StyleFlowPseudoLayer;
|
|
34
|
-
focus?: StyleFlowPseudoLayer;
|
|
35
|
-
focusVisible?: StyleFlowPseudoLayer;
|
|
36
|
-
[key: string]:
|
|
37
|
-
| StyleFlowStyleValue
|
|
38
|
-
| StyleFlowClassValue
|
|
39
|
-
| StyleFlowLayer
|
|
40
|
-
| StyleFlowPseudoLayer
|
|
41
|
-
| string
|
|
42
|
-
| undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** styleFlow: stringa (solo classi) | [base, layer] | layer. */
|
|
46
|
-
type StyleFlow = string | [string, StyleFlowLayer] | StyleFlowLayer;
|
|
47
|
-
|
|
48
|
-
interface FlowHTMLAttributes {
|
|
49
|
-
class?: string | (() => string) | (string | (() => string))[];
|
|
50
|
-
classList?: Record<string, boolean | (() => boolean)>;
|
|
51
|
-
classFlow?: (() => Record<string, string | number>) | Record<string, ClassFlowValue>;
|
|
52
|
-
/** Style layer: string | [base, layer] | layer. Use s or styleFlow, same thing. */
|
|
53
|
-
s?: StyleFlow;
|
|
54
|
-
styleFlow?: StyleFlow;
|
|
55
|
-
style?: Record<string, string | number | (() => string | number)>;
|
|
56
|
-
children?: unknown;
|
|
57
|
-
[key: string]: unknown;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface IntrinsicElements {
|
|
61
|
-
[tag: string]: FlowHTMLAttributes;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/// <reference path="./jsx-types.d.ts" />
|
|
2
|
-
import { effect } from '@flow.os/core';
|
|
3
|
-
import { isGetter } from '../features/utils.js';
|
|
4
|
-
import {
|
|
5
|
-
applyClassFlow,
|
|
6
|
-
applyClassAndClassList,
|
|
7
|
-
applyStyle,
|
|
8
|
-
applyStyleFlow,
|
|
9
|
-
applyAttrs,
|
|
10
|
-
} from '../features/index.js';
|
|
11
|
-
|
|
12
|
-
export const Fragment = Symbol.for('flow.fragment');
|
|
13
|
-
|
|
14
|
-
type Props = Record<string, unknown> & { children?: unknown };
|
|
15
|
-
type JsxType = string | ((props: Props) => Node | null) | typeof Fragment;
|
|
16
|
-
|
|
17
|
-
function normalizeChild(c: unknown): Node | string | null {
|
|
18
|
-
if (c == null) return null;
|
|
19
|
-
if (typeof c === 'string' || typeof c === 'number') return String(c);
|
|
20
|
-
if (c instanceof Node) return c;
|
|
21
|
-
if (isGetter(c)) {
|
|
22
|
-
const text = document.createTextNode('');
|
|
23
|
-
effect(() => {
|
|
24
|
-
text.textContent = String(c());
|
|
25
|
-
});
|
|
26
|
-
return text;
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(c)) {
|
|
29
|
-
const frag = document.createDocumentFragment();
|
|
30
|
-
for (const x of c) {
|
|
31
|
-
const n = normalizeChild(x);
|
|
32
|
-
if (n !== null) frag.appendChild(typeof n === 'string' ? document.createTextNode(n) : n);
|
|
33
|
-
}
|
|
34
|
-
return frag;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function appendChildren(el: Node, children: unknown): void {
|
|
40
|
-
const c = normalizeChild(children);
|
|
41
|
-
if (c === null) return;
|
|
42
|
-
if (typeof c === 'string') {
|
|
43
|
-
el.appendChild(document.createTextNode(c));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
el.appendChild(c);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function applyProps(el: HTMLElement, props: Props): void {
|
|
50
|
-
const {
|
|
51
|
-
children,
|
|
52
|
-
class: classProp,
|
|
53
|
-
className: classNameProp,
|
|
54
|
-
classList,
|
|
55
|
-
classFlow,
|
|
56
|
-
style: styleProp,
|
|
57
|
-
s,
|
|
58
|
-
styleFlow,
|
|
59
|
-
...rest
|
|
60
|
-
} = props;
|
|
61
|
-
const styleFlowValue = s ?? styleFlow;
|
|
62
|
-
if (styleFlowValue != null) {
|
|
63
|
-
applyStyleFlow(el, styleFlowValue);
|
|
64
|
-
} else {
|
|
65
|
-
applyClassFlow(el, classFlow);
|
|
66
|
-
applyClassAndClassList(el, classProp, classNameProp, classList);
|
|
67
|
-
applyStyle(el, styleProp);
|
|
68
|
-
}
|
|
69
|
-
applyAttrs(el, rest);
|
|
70
|
-
if (children !== undefined) appendChildren(el, children);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function jsxs(type: JsxType, props: Props, _key?: string | number): Node {
|
|
74
|
-
return jsx(type, props, _key);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function jsx(type: JsxType, props: Props, _key?: string | number): Node {
|
|
78
|
-
if (type === Fragment) {
|
|
79
|
-
const frag = document.createDocumentFragment();
|
|
80
|
-
if (props.children !== undefined) appendChildren(frag, props.children);
|
|
81
|
-
return frag;
|
|
82
|
-
}
|
|
83
|
-
if (typeof type === 'function') {
|
|
84
|
-
const out = type(props);
|
|
85
|
-
return out ?? document.createDocumentFragment();
|
|
86
|
-
}
|
|
87
|
-
const el = document.createElement(type as string);
|
|
88
|
-
applyProps(el, props);
|
|
89
|
-
return el;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function jsxDEV(
|
|
93
|
-
type: JsxType,
|
|
94
|
-
props: Props,
|
|
95
|
-
key: string | number | undefined,
|
|
96
|
-
_isStatic: boolean,
|
|
97
|
-
_source: unknown,
|
|
98
|
-
_self: unknown
|
|
99
|
-
): Node {
|
|
100
|
-
return jsx(type, props, key as string | undefined);
|
|
101
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { build } from 'vite';
|
|
5
|
-
|
|
6
|
-
const cwd = process.cwd();
|
|
7
|
-
const configPath = join(cwd, 'flow.config.ts');
|
|
8
|
-
const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
|
|
9
|
-
console.error('Flow: could not load flow.config.ts:', e.message);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
});
|
|
12
|
-
const getConfig = mod.default;
|
|
13
|
-
const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
|
|
14
|
-
await build(config);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { preview } from 'vite';
|
|
5
|
-
|
|
6
|
-
const cwd = process.cwd();
|
|
7
|
-
const configPath = join(cwd, 'flow.config.ts');
|
|
8
|
-
const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
|
|
9
|
-
console.error('Flow: could not load flow.config.ts:', e.message);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
});
|
|
12
|
-
const getConfig = mod.default;
|
|
13
|
-
const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
|
|
14
|
-
await preview(config);
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/** Dev server: carica flow.config.ts e avvia Vite. Porta libera 3000–3020. */
|
|
3
|
-
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { createServer } from 'vite';
|
|
7
|
-
import net from 'node:net';
|
|
8
|
-
|
|
9
|
-
const cwd = process.cwd();
|
|
10
|
-
const configPath = join(cwd, 'flow.config.ts');
|
|
11
|
-
const configUrl = pathToFileURL(configPath).href;
|
|
12
|
-
|
|
13
|
-
function isPortFree(port: number): Promise<boolean> {
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
const s = net.createServer();
|
|
16
|
-
s.once('error', () => resolve(false));
|
|
17
|
-
s.once('listening', () => {
|
|
18
|
-
s.close(() => resolve(true));
|
|
19
|
-
});
|
|
20
|
-
s.listen(port, '127.0.0.1');
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function findFreePort(from: number, to: number): Promise<number> {
|
|
25
|
-
for (let p = from; p <= to; p++) {
|
|
26
|
-
if (await isPortFree(p)) return p;
|
|
27
|
-
}
|
|
28
|
-
throw new Error(`Nessuna porta libera tra ${from} e ${to}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const port = await findFreePort(3000, 3020);
|
|
32
|
-
process.env.FLOW_DEV_PORT = String(port);
|
|
33
|
-
|
|
34
|
-
const mod = await import(configUrl).catch((e: Error) => {
|
|
35
|
-
console.error('Flow: could not load flow.config.ts:', e.message);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
const getConfig = mod.default;
|
|
39
|
-
const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
|
|
40
|
-
const server = await createServer(config);
|
|
41
|
-
await server.listen();
|
|
42
|
-
|
|
43
|
-
const shutdown = () => {
|
|
44
|
-
server.close().then(() => process.exit(0)).catch(() => process.exit(1));
|
|
45
|
-
};
|
|
46
|
-
process.on('SIGINT', shutdown);
|
|
47
|
-
process.on('SIGTERM', shutdown);
|
|
48
|
-
|
|
49
|
-
server.watcher.on('change', () => {});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
Flow OS Framework and all packages in this repository are licensed under the
|
|
2
|
-
PolyForm Shield License 1.0.0. This license applies to the entire repository
|
|
3
|
-
(framework, packages/*, client, server, and any other code herein).
|
|
4
|
-
|
|
5
|
-
Required Notice: Copyright (c) Flow OS. All rights reserved.
|
|
6
|
-
|
|
7
|
-
-------------------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
# PolyForm Shield License 1.0.0
|
|
10
|
-
|
|
11
|
-
## Acceptance
|
|
12
|
-
|
|
13
|
-
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
14
|
-
|
|
15
|
-
## Copyright License
|
|
16
|
-
|
|
17
|
-
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
-
|
|
19
|
-
## Distribution License
|
|
20
|
-
|
|
21
|
-
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
22
|
-
|
|
23
|
-
## Notices
|
|
24
|
-
|
|
25
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
26
|
-
|
|
27
|
-
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
28
|
-
|
|
29
|
-
## Changes and New Works License
|
|
30
|
-
|
|
31
|
-
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
32
|
-
|
|
33
|
-
## Patent License
|
|
34
|
-
|
|
35
|
-
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
36
|
-
|
|
37
|
-
## Noncompete
|
|
38
|
-
|
|
39
|
-
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
40
|
-
|
|
41
|
-
## Competition
|
|
42
|
-
|
|
43
|
-
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
44
|
-
|
|
45
|
-
## New Products
|
|
46
|
-
|
|
47
|
-
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
48
|
-
|
|
49
|
-
## Discontinued Products
|
|
50
|
-
|
|
51
|
-
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
52
|
-
|
|
53
|
-
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
54
|
-
|
|
55
|
-
Licensor Line of Business: Flow OS application framework and development tooling (create-flow, @flow.os/* packages, and related framework components).
|
|
56
|
-
|
|
57
|
-
## Sales of Business
|
|
58
|
-
|
|
59
|
-
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
60
|
-
|
|
61
|
-
## Fair Use
|
|
62
|
-
|
|
63
|
-
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
64
|
-
|
|
65
|
-
## No Other Rights
|
|
66
|
-
|
|
67
|
-
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
68
|
-
|
|
69
|
-
## Patent Defense
|
|
70
|
-
|
|
71
|
-
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
72
|
-
|
|
73
|
-
## Violations
|
|
74
|
-
|
|
75
|
-
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
76
|
-
|
|
77
|
-
## No Liability
|
|
78
|
-
|
|
79
|
-
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
80
|
-
|
|
81
|
-
## Definitions
|
|
82
|
-
|
|
83
|
-
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
84
|
-
|
|
85
|
-
A **product** can be a good or service, or a combination of them.
|
|
86
|
-
|
|
87
|
-
**You** refers to the individual or entity agreeing to these terms.
|
|
88
|
-
|
|
89
|
-
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
90
|
-
|
|
91
|
-
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
92
|
-
|
|
93
|
-
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
94
|
-
|
|
95
|
-
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
96
|
-
|
|
97
|
-
**Use** means anything you do with the software requiring one of your licenses.
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper DOM per Show/For: normalizza children (getter, string, Node, array) e setContent.
|
|
3
|
-
*/
|
|
4
|
-
import { effect } from './state.js';
|
|
5
|
-
|
|
6
|
-
function isGetter(fn: unknown): fn is () => unknown {
|
|
7
|
-
return typeof fn === 'function' && fn.length === 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function normalizeChild(c: unknown): Node | string | null {
|
|
11
|
-
if (c == null) return null;
|
|
12
|
-
if (typeof c === 'string' || typeof c === 'number') return String(c);
|
|
13
|
-
if (c instanceof Node) return c;
|
|
14
|
-
if (isGetter(c)) {
|
|
15
|
-
const text = document.createTextNode('');
|
|
16
|
-
effect(() => {
|
|
17
|
-
text.textContent = String(c());
|
|
18
|
-
});
|
|
19
|
-
return text;
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(c)) {
|
|
22
|
-
const frag = document.createDocumentFragment();
|
|
23
|
-
for (const x of c) {
|
|
24
|
-
const n = normalizeChild(x);
|
|
25
|
-
if (n !== null) frag.appendChild(typeof n === 'string' ? document.createTextNode(n) : n);
|
|
26
|
-
}
|
|
27
|
-
return frag;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function setContent(el: HTMLElement, c: unknown): void {
|
|
33
|
-
const n = normalizeChild(c);
|
|
34
|
-
if (n === null) {
|
|
35
|
-
el.replaceChildren();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (typeof n === 'string') {
|
|
39
|
-
el.replaceChildren(document.createTextNode(n));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
el.replaceChildren(n);
|
|
43
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For: lista reattiva. each={() => T[]}, children (item, index) => content.
|
|
3
|
-
* Opzionale key (item, index) => string|number per reconciliation keyed.
|
|
4
|
-
*/
|
|
5
|
-
import { effect } from './state.js';
|
|
6
|
-
import { normalizeChild } from './dom.js';
|
|
7
|
-
|
|
8
|
-
function isGetter(fn: unknown): fn is () => unknown {
|
|
9
|
-
return typeof fn === 'function' && fn.length === 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function appendNormalized(parent: Node, c: unknown): void {
|
|
13
|
-
const n = normalizeChild(c);
|
|
14
|
-
if (n === null) return;
|
|
15
|
-
parent.appendChild(typeof n === 'string' ? document.createTextNode(n) : n);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** For: rende una lista reattiva. each=getter array, children=(item, index)=>content, fallback=vuoto. */
|
|
19
|
-
export function For<T>(props: {
|
|
20
|
-
each: (() => T[]) | T[];
|
|
21
|
-
fallback?: unknown;
|
|
22
|
-
children: (item: T, index: number) => unknown;
|
|
23
|
-
}): HTMLElement {
|
|
24
|
-
const container = document.createElement('span');
|
|
25
|
-
container.style.display = 'contents';
|
|
26
|
-
const getList = isGetter(props.each) ? props.each : () => props.each as T[];
|
|
27
|
-
effect(() => {
|
|
28
|
-
const list = getList();
|
|
29
|
-
const len = Array.isArray(list) ? list.length : 0;
|
|
30
|
-
if (len === 0) {
|
|
31
|
-
appendNormalized(container, props.fallback);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
container.replaceChildren();
|
|
35
|
-
for (let i = 0; i < len; i++) {
|
|
36
|
-
const item = list[i];
|
|
37
|
-
if (item === undefined) continue;
|
|
38
|
-
appendNormalized(container, props.children(item, i));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return container;
|
|
42
|
-
}
|