@constructive-io/blocks-ui 0.2.0
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/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.cjs +440 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +112 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +407 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BlockRegistry, BlockProps } from 'blocks-renderer';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { UINodeProps } from 'blocks-schema';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The default registry: Constructive node types → components.
|
|
8
|
+
*
|
|
9
|
+
* It is split into three layers so a host can take only what it wants — the
|
|
10
|
+
* widgets without the page chrome, say — and compose the rest itself.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Every field widget in `WIDGET_NODE_TYPES`. */
|
|
14
|
+
declare const widgetRegistry: BlockRegistry;
|
|
15
|
+
/** Every layout type in `CONTAINER_NODE_TYPES`. */
|
|
16
|
+
declare const containerRegistry: BlockRegistry;
|
|
17
|
+
/** The blocks that need no data source. */
|
|
18
|
+
declare const blockRegistry: BlockRegistry;
|
|
19
|
+
/**
|
|
20
|
+
* Everything above, ready to render a generated document. Layer over it rather
|
|
21
|
+
* than editing it: `composeRegistry(defaultBlockRegistry, myRegistry)`.
|
|
22
|
+
*/
|
|
23
|
+
declare const defaultBlockRegistry: BlockRegistry;
|
|
24
|
+
|
|
25
|
+
/** The value/error wiring for one widget node, plus a stable control id. */
|
|
26
|
+
declare function useNodeField(props: UINodeProps): {
|
|
27
|
+
name: string | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
value: unknown;
|
|
30
|
+
error: string | undefined;
|
|
31
|
+
setValue: (() => void) | ((value: unknown) => void);
|
|
32
|
+
/** `edit` is the authoring surface, so widgets are inert there. */
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
required: boolean;
|
|
35
|
+
placeholder: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
interface FieldShellProps {
|
|
38
|
+
props: UINodeProps;
|
|
39
|
+
id: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Label, description, and error chrome around a control. `hidden` fields stay
|
|
45
|
+
* in the document (they still carry a value) but render nothing.
|
|
46
|
+
*/
|
|
47
|
+
declare function FieldShell({ props, id, error, children }: FieldShellProps): react.JSX.Element | null;
|
|
48
|
+
/** `{ label, value }[]`, however the document spelled the options. */
|
|
49
|
+
interface WidgetOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
declare function readOptions(props: UINodeProps): WidgetOption[];
|
|
54
|
+
/** Controlled inputs cannot take `undefined`, and `null` means "cleared". */
|
|
55
|
+
declare function textValue(value: unknown): string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A button either submits its form or fires its `click` action; the renderer
|
|
59
|
+
* decides what an action means, so this block only reports the event.
|
|
60
|
+
*/
|
|
61
|
+
declare function ButtonBlock({ node, props }: BlockProps): react.JSX.Element;
|
|
62
|
+
declare function ActionBarBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* Markdown source is rendered as pre-wrapped text rather than parsed: a parser
|
|
65
|
+
* is a dependency and an XSS surface, and a host that wants one registers it.
|
|
66
|
+
*/
|
|
67
|
+
declare function MarkdownBlock({ props }: BlockProps): react.JSX.Element;
|
|
68
|
+
declare function StatCardBlock({ props }: BlockProps): react.JSX.Element;
|
|
69
|
+
|
|
70
|
+
declare function PageBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
71
|
+
/**
|
|
72
|
+
* Submitting delegates to the renderer: it validates every field against the
|
|
73
|
+
* document's constraints before calling the host's `onSubmit`, so this component
|
|
74
|
+
* never inspects values itself.
|
|
75
|
+
*/
|
|
76
|
+
declare function FormBlock({ node, props, children }: BlockProps): react.JSX.Element;
|
|
77
|
+
declare function SectionBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
78
|
+
/** `columns` is a count, so the grid stays declarative rather than class-driven. */
|
|
79
|
+
declare function GridBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
80
|
+
declare function GridColumnBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
81
|
+
declare function TabsBlock({ node }: BlockProps): react.JSX.Element | null;
|
|
82
|
+
/** Rendered inside a `TabsContent` by {@link TabsBlock}; it owns no chrome. */
|
|
83
|
+
declare function TabBlock({ children }: BlockProps): react.JSX.Element;
|
|
84
|
+
|
|
85
|
+
declare function InputBlock({ props }: BlockProps): react.JSX.Element;
|
|
86
|
+
declare function TextareaBlock({ props }: BlockProps): react.JSX.Element;
|
|
87
|
+
/**
|
|
88
|
+
* Code and prose editors fall back to a monospace textarea: a real editor is a
|
|
89
|
+
* heavy dependency, and a host that wants one registers it for these two types.
|
|
90
|
+
*/
|
|
91
|
+
declare function CodeBlock({ props }: BlockProps): react.JSX.Element;
|
|
92
|
+
declare function NumberInputBlock({ props }: BlockProps): react.JSX.Element;
|
|
93
|
+
declare function SelectBlock({ props }: BlockProps): react.JSX.Element;
|
|
94
|
+
declare function RadioGroupBlock({ props }: BlockProps): react.JSX.Element;
|
|
95
|
+
declare function CheckboxBlock({ props }: BlockProps): react.JSX.Element;
|
|
96
|
+
declare function SwitchBlock({ props }: BlockProps): react.JSX.Element;
|
|
97
|
+
declare function DatePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
98
|
+
/**
|
|
99
|
+
* `datetime-local` needs `YYYY-MM-DDTHH:mm`, while a document (and Postgres)
|
|
100
|
+
* speaks ISO-8601 with a zone, so the value is trimmed for display and the
|
|
101
|
+
* incoming zone is reapplied on write-back rather than dropped.
|
|
102
|
+
*/
|
|
103
|
+
declare function DateTimePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
104
|
+
declare function TimePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
105
|
+
declare function PhoneInputBlock({ props }: BlockProps): react.JSX.Element;
|
|
106
|
+
/**
|
|
107
|
+
* A file field holds the file name in form state; uploading bytes needs a
|
|
108
|
+
* storage adapter, which is a host concern rather than a widget's.
|
|
109
|
+
*/
|
|
110
|
+
declare function FileUploadBlock({ props }: BlockProps): react.JSX.Element;
|
|
111
|
+
|
|
112
|
+
export { ActionBarBlock, ButtonBlock, CheckboxBlock, CodeBlock, DatePickerBlock, DateTimePickerBlock, FieldShell, type FieldShellProps, FileUploadBlock, FormBlock, GridBlock, GridColumnBlock, InputBlock, MarkdownBlock, NumberInputBlock, PageBlock, PhoneInputBlock, RadioGroupBlock, SectionBlock, SelectBlock, StatCardBlock, SwitchBlock, TabBlock, TabsBlock, TextareaBlock, TimePickerBlock, type WidgetOption, blockRegistry, containerRegistry, defaultBlockRegistry, readOptions, textValue, useNodeField, widgetRegistry };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BlockRegistry, BlockProps } from 'blocks-renderer';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { UINodeProps } from 'blocks-schema';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The default registry: Constructive node types → components.
|
|
8
|
+
*
|
|
9
|
+
* It is split into three layers so a host can take only what it wants — the
|
|
10
|
+
* widgets without the page chrome, say — and compose the rest itself.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Every field widget in `WIDGET_NODE_TYPES`. */
|
|
14
|
+
declare const widgetRegistry: BlockRegistry;
|
|
15
|
+
/** Every layout type in `CONTAINER_NODE_TYPES`. */
|
|
16
|
+
declare const containerRegistry: BlockRegistry;
|
|
17
|
+
/** The blocks that need no data source. */
|
|
18
|
+
declare const blockRegistry: BlockRegistry;
|
|
19
|
+
/**
|
|
20
|
+
* Everything above, ready to render a generated document. Layer over it rather
|
|
21
|
+
* than editing it: `composeRegistry(defaultBlockRegistry, myRegistry)`.
|
|
22
|
+
*/
|
|
23
|
+
declare const defaultBlockRegistry: BlockRegistry;
|
|
24
|
+
|
|
25
|
+
/** The value/error wiring for one widget node, plus a stable control id. */
|
|
26
|
+
declare function useNodeField(props: UINodeProps): {
|
|
27
|
+
name: string | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
value: unknown;
|
|
30
|
+
error: string | undefined;
|
|
31
|
+
setValue: (() => void) | ((value: unknown) => void);
|
|
32
|
+
/** `edit` is the authoring surface, so widgets are inert there. */
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
required: boolean;
|
|
35
|
+
placeholder: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
interface FieldShellProps {
|
|
38
|
+
props: UINodeProps;
|
|
39
|
+
id: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Label, description, and error chrome around a control. `hidden` fields stay
|
|
45
|
+
* in the document (they still carry a value) but render nothing.
|
|
46
|
+
*/
|
|
47
|
+
declare function FieldShell({ props, id, error, children }: FieldShellProps): react.JSX.Element | null;
|
|
48
|
+
/** `{ label, value }[]`, however the document spelled the options. */
|
|
49
|
+
interface WidgetOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
declare function readOptions(props: UINodeProps): WidgetOption[];
|
|
54
|
+
/** Controlled inputs cannot take `undefined`, and `null` means "cleared". */
|
|
55
|
+
declare function textValue(value: unknown): string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A button either submits its form or fires its `click` action; the renderer
|
|
59
|
+
* decides what an action means, so this block only reports the event.
|
|
60
|
+
*/
|
|
61
|
+
declare function ButtonBlock({ node, props }: BlockProps): react.JSX.Element;
|
|
62
|
+
declare function ActionBarBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* Markdown source is rendered as pre-wrapped text rather than parsed: a parser
|
|
65
|
+
* is a dependency and an XSS surface, and a host that wants one registers it.
|
|
66
|
+
*/
|
|
67
|
+
declare function MarkdownBlock({ props }: BlockProps): react.JSX.Element;
|
|
68
|
+
declare function StatCardBlock({ props }: BlockProps): react.JSX.Element;
|
|
69
|
+
|
|
70
|
+
declare function PageBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
71
|
+
/**
|
|
72
|
+
* Submitting delegates to the renderer: it validates every field against the
|
|
73
|
+
* document's constraints before calling the host's `onSubmit`, so this component
|
|
74
|
+
* never inspects values itself.
|
|
75
|
+
*/
|
|
76
|
+
declare function FormBlock({ node, props, children }: BlockProps): react.JSX.Element;
|
|
77
|
+
declare function SectionBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
78
|
+
/** `columns` is a count, so the grid stays declarative rather than class-driven. */
|
|
79
|
+
declare function GridBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
80
|
+
declare function GridColumnBlock({ props, children }: BlockProps): react.JSX.Element;
|
|
81
|
+
declare function TabsBlock({ node }: BlockProps): react.JSX.Element | null;
|
|
82
|
+
/** Rendered inside a `TabsContent` by {@link TabsBlock}; it owns no chrome. */
|
|
83
|
+
declare function TabBlock({ children }: BlockProps): react.JSX.Element;
|
|
84
|
+
|
|
85
|
+
declare function InputBlock({ props }: BlockProps): react.JSX.Element;
|
|
86
|
+
declare function TextareaBlock({ props }: BlockProps): react.JSX.Element;
|
|
87
|
+
/**
|
|
88
|
+
* Code and prose editors fall back to a monospace textarea: a real editor is a
|
|
89
|
+
* heavy dependency, and a host that wants one registers it for these two types.
|
|
90
|
+
*/
|
|
91
|
+
declare function CodeBlock({ props }: BlockProps): react.JSX.Element;
|
|
92
|
+
declare function NumberInputBlock({ props }: BlockProps): react.JSX.Element;
|
|
93
|
+
declare function SelectBlock({ props }: BlockProps): react.JSX.Element;
|
|
94
|
+
declare function RadioGroupBlock({ props }: BlockProps): react.JSX.Element;
|
|
95
|
+
declare function CheckboxBlock({ props }: BlockProps): react.JSX.Element;
|
|
96
|
+
declare function SwitchBlock({ props }: BlockProps): react.JSX.Element;
|
|
97
|
+
declare function DatePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
98
|
+
/**
|
|
99
|
+
* `datetime-local` needs `YYYY-MM-DDTHH:mm`, while a document (and Postgres)
|
|
100
|
+
* speaks ISO-8601 with a zone, so the value is trimmed for display and the
|
|
101
|
+
* incoming zone is reapplied on write-back rather than dropped.
|
|
102
|
+
*/
|
|
103
|
+
declare function DateTimePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
104
|
+
declare function TimePickerBlock({ props }: BlockProps): react.JSX.Element;
|
|
105
|
+
declare function PhoneInputBlock({ props }: BlockProps): react.JSX.Element;
|
|
106
|
+
/**
|
|
107
|
+
* A file field holds the file name in form state; uploading bytes needs a
|
|
108
|
+
* storage adapter, which is a host concern rather than a widget's.
|
|
109
|
+
*/
|
|
110
|
+
declare function FileUploadBlock({ props }: BlockProps): react.JSX.Element;
|
|
111
|
+
|
|
112
|
+
export { ActionBarBlock, ButtonBlock, CheckboxBlock, CodeBlock, DatePickerBlock, DateTimePickerBlock, FieldShell, type FieldShellProps, FileUploadBlock, FormBlock, GridBlock, GridColumnBlock, InputBlock, MarkdownBlock, NumberInputBlock, PageBlock, PhoneInputBlock, RadioGroupBlock, SectionBlock, SelectBlock, StatCardBlock, SwitchBlock, TabBlock, TabsBlock, TextareaBlock, TimePickerBlock, type WidgetOption, blockRegistry, containerRegistry, defaultBlockRegistry, readOptions, textValue, useNodeField, widgetRegistry };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { Button, Card, CardHeader, CardTitle, CardDescription, CardContent, Tabs, TabsList, TabsTrigger, TabsContent, Field, Textarea, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, RadioGroup, Label, Radio, Checkbox, Switch } from '@constructive-io/ui';
|
|
2
|
+
import { useRenderer, BlockRenderer, useBlockField } from 'blocks-renderer';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import { useId } from 'react';
|
|
5
|
+
|
|
6
|
+
function text(props, ...keys) {
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
const value = props[key];
|
|
9
|
+
if (typeof value === "string") return value;
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
var VARIANTS = /* @__PURE__ */ new Set(["default", "destructive", "outline", "secondary", "ghost", "link"]);
|
|
14
|
+
function ButtonBlock({ node, props }) {
|
|
15
|
+
const { onAction } = useRenderer();
|
|
16
|
+
const label = text(props, "text", "label") ?? "Button";
|
|
17
|
+
const variant = text(props, "variant");
|
|
18
|
+
const submits = props.type === "submit" || props.submit === true;
|
|
19
|
+
const action = node.actions?.click;
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
Button,
|
|
22
|
+
{
|
|
23
|
+
type: submits ? "submit" : "button",
|
|
24
|
+
disabled: Boolean(props.disabled),
|
|
25
|
+
...variant && VARIANTS.has(variant) ? { variant } : {},
|
|
26
|
+
...action ? { onClick: () => onAction?.(action, "click") } : {},
|
|
27
|
+
children: label
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function ActionBarBlock({ props, children }) {
|
|
32
|
+
return /* @__PURE__ */ jsx("div", { className: ["flex flex-wrap items-center gap-2", props.className ? String(props.className) : ""].join(" ").trim(), children });
|
|
33
|
+
}
|
|
34
|
+
function MarkdownBlock({ props }) {
|
|
35
|
+
const content = text(props, "content", "text", "markdown") ?? "";
|
|
36
|
+
return /* @__PURE__ */ jsx("div", { className: "whitespace-pre-wrap text-sm leading-relaxed", children: content });
|
|
37
|
+
}
|
|
38
|
+
function StatCardBlock({ props }) {
|
|
39
|
+
const label = text(props, "label", "title") ?? "";
|
|
40
|
+
const value = props.value;
|
|
41
|
+
const description = text(props, "description");
|
|
42
|
+
return /* @__PURE__ */ jsxs(Card, { children: [
|
|
43
|
+
/* @__PURE__ */ jsxs(CardHeader, { children: [
|
|
44
|
+
/* @__PURE__ */ jsx(CardTitle, { className: "text-sm font-medium text-muted-foreground", children: label }),
|
|
45
|
+
description && /* @__PURE__ */ jsx(CardDescription, { children: description })
|
|
46
|
+
] }),
|
|
47
|
+
/* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("span", { className: "text-2xl font-semibold tabular-nums", children: value === null || value === void 0 ? "\u2014" : String(value) }) })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
function text2(props, key) {
|
|
51
|
+
const value = props[key];
|
|
52
|
+
return typeof value === "string" ? value : void 0;
|
|
53
|
+
}
|
|
54
|
+
function PageBlock({ props, children }) {
|
|
55
|
+
const title = text2(props, "title");
|
|
56
|
+
const description = text2(props, "description");
|
|
57
|
+
return /* @__PURE__ */ jsxs("div", { className: props.className ? String(props.className) : "flex flex-col gap-6", children: [
|
|
58
|
+
(title || description) && /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-1", children: [
|
|
59
|
+
title && /* @__PURE__ */ jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: title }),
|
|
60
|
+
description && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: description })
|
|
61
|
+
] }),
|
|
62
|
+
children
|
|
63
|
+
] });
|
|
64
|
+
}
|
|
65
|
+
function FormBlock({ node, props, children }) {
|
|
66
|
+
const { onAction } = useRenderer();
|
|
67
|
+
const submitLabel = text2(props, "submitLabel") ?? (props.mode === "update" ? "Save" : "Submit");
|
|
68
|
+
return /* @__PURE__ */ jsxs(
|
|
69
|
+
"form",
|
|
70
|
+
{
|
|
71
|
+
className: "flex flex-col gap-5",
|
|
72
|
+
noValidate: true,
|
|
73
|
+
onSubmit: (event) => {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
onAction?.(node.actions?.submit ?? { type: "handler", handler: "submit" }, "submit");
|
|
76
|
+
},
|
|
77
|
+
children: [
|
|
78
|
+
children,
|
|
79
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-2", children: /* @__PURE__ */ jsx(Button, { type: "submit", children: submitLabel }) })
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function SectionBlock({ props, children }) {
|
|
85
|
+
const title = text2(props, "title");
|
|
86
|
+
if (!title) {
|
|
87
|
+
return /* @__PURE__ */ jsx("section", { className: "flex flex-col gap-4", children });
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ jsxs(Card, { children: [
|
|
90
|
+
/* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: title }) }),
|
|
91
|
+
/* @__PURE__ */ jsx(CardContent, { className: "flex flex-col gap-5", children })
|
|
92
|
+
] });
|
|
93
|
+
}
|
|
94
|
+
function GridBlock({ props, children }) {
|
|
95
|
+
const columns = typeof props.columns === "number" ? Math.min(Math.max(props.columns, 1), 4) : 2;
|
|
96
|
+
const template = ["grid-cols-1", "md:grid-cols-2", "md:grid-cols-3", "md:grid-cols-4"][columns - 1];
|
|
97
|
+
return /* @__PURE__ */ jsx("div", { className: `grid gap-5 ${template}`, children });
|
|
98
|
+
}
|
|
99
|
+
var SPANS = ["", "md:col-span-2", "md:col-span-3", "md:col-span-4"];
|
|
100
|
+
function GridColumnBlock({ props, children }) {
|
|
101
|
+
const span = typeof props.span === "number" ? Math.min(Math.max(props.span, 1), 4) : 1;
|
|
102
|
+
return /* @__PURE__ */ jsx("div", { className: ["flex flex-col gap-5", SPANS[span - 1]].filter(Boolean).join(" "), children });
|
|
103
|
+
}
|
|
104
|
+
function TabsBlock({ node }) {
|
|
105
|
+
const tabs = node.children ?? [];
|
|
106
|
+
if (tabs.length === 0) return null;
|
|
107
|
+
const first = tabs[0].key;
|
|
108
|
+
return /* @__PURE__ */ jsxs(Tabs, { defaultValue: first, children: [
|
|
109
|
+
/* @__PURE__ */ jsx(TabsList, { children: tabs.map((tab) => /* @__PURE__ */ jsx(TabsTrigger, { value: tab.key, children: text2(tab.props, "label") ?? text2(tab.props, "title") ?? tab.key }, tab.key)) }),
|
|
110
|
+
tabs.map((tab) => /* @__PURE__ */ jsx(TabsContent, { value: tab.key, children: /* @__PURE__ */ jsx(BlockRenderer, { node: tab }) }, tab.key))
|
|
111
|
+
] });
|
|
112
|
+
}
|
|
113
|
+
function TabBlock({ children }) {
|
|
114
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-5 pt-4", children });
|
|
115
|
+
}
|
|
116
|
+
function useNodeField(props) {
|
|
117
|
+
const name = typeof props.name === "string" ? props.name : void 0;
|
|
118
|
+
const { value, error, setValue, mode } = useBlockField(name);
|
|
119
|
+
const id = useId();
|
|
120
|
+
return {
|
|
121
|
+
name,
|
|
122
|
+
id,
|
|
123
|
+
value,
|
|
124
|
+
error,
|
|
125
|
+
setValue,
|
|
126
|
+
/** `edit` is the authoring surface, so widgets are inert there. */
|
|
127
|
+
disabled: Boolean(props.disabled) || mode === "edit",
|
|
128
|
+
required: Boolean(props.required),
|
|
129
|
+
placeholder: typeof props.placeholder === "string" ? props.placeholder : void 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function FieldShell({ props, id, error, children }) {
|
|
133
|
+
if (props.hidden) return null;
|
|
134
|
+
const label = typeof props.label === "string" ? props.label : props.name ?? "";
|
|
135
|
+
return /* @__PURE__ */ jsx(
|
|
136
|
+
Field,
|
|
137
|
+
{
|
|
138
|
+
label,
|
|
139
|
+
htmlFor: id,
|
|
140
|
+
required: Boolean(props.required),
|
|
141
|
+
...typeof props.description === "string" ? { description: props.description } : {},
|
|
142
|
+
...error ? { error } : {},
|
|
143
|
+
...typeof props.className === "string" ? { className: props.className } : {},
|
|
144
|
+
children
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function readOptions(props) {
|
|
149
|
+
const options = props.options;
|
|
150
|
+
if (!Array.isArray(options)) return [];
|
|
151
|
+
return options.map((option) => {
|
|
152
|
+
if (option !== null && typeof option === "object") {
|
|
153
|
+
const entry = option;
|
|
154
|
+
const value2 = String(entry.value ?? "");
|
|
155
|
+
return { label: String(entry.label ?? value2), value: value2 };
|
|
156
|
+
}
|
|
157
|
+
const value = String(option ?? "");
|
|
158
|
+
return { label: value, value };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function textValue(value) {
|
|
162
|
+
if (value === void 0 || value === null) return "";
|
|
163
|
+
return typeof value === "string" ? value : String(value);
|
|
164
|
+
}
|
|
165
|
+
function inputConstraints(props) {
|
|
166
|
+
const constraints = props.constraints ?? {};
|
|
167
|
+
return {
|
|
168
|
+
...constraints.minLength != null ? { minLength: constraints.minLength } : {},
|
|
169
|
+
...constraints.maxLength != null ? { maxLength: constraints.maxLength } : {},
|
|
170
|
+
...constraints.pattern ? { pattern: constraints.pattern } : {}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function numericConstraints(props) {
|
|
174
|
+
const constraints = props.constraints ?? {};
|
|
175
|
+
return {
|
|
176
|
+
...constraints.minValue != null ? { min: constraints.minValue } : {},
|
|
177
|
+
...constraints.maxValue != null ? { max: constraints.maxValue } : {},
|
|
178
|
+
...typeof props.step === "number" ? { step: props.step } : {}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function numberValue(raw) {
|
|
182
|
+
if (raw === "") return null;
|
|
183
|
+
const parsed = Number(raw);
|
|
184
|
+
return Number.isFinite(parsed) ? parsed : raw;
|
|
185
|
+
}
|
|
186
|
+
var ZONE_SUFFIX = /(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
187
|
+
function zonedValue(local, zone) {
|
|
188
|
+
if (local === "") return null;
|
|
189
|
+
if (!zone) return local;
|
|
190
|
+
const seconds = local.length > 16 ? "" : ":00";
|
|
191
|
+
return `${local}${seconds}${zone}`;
|
|
192
|
+
}
|
|
193
|
+
function TextInput({ props, type }) {
|
|
194
|
+
const field = useNodeField(props);
|
|
195
|
+
const inputType = type ?? (typeof props.inputType === "string" ? props.inputType : "text");
|
|
196
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
197
|
+
Input,
|
|
198
|
+
{
|
|
199
|
+
id: field.id,
|
|
200
|
+
name: field.name,
|
|
201
|
+
type: inputType,
|
|
202
|
+
value: textValue(field.value),
|
|
203
|
+
onChange: (event) => field.setValue(event.target.value),
|
|
204
|
+
disabled: field.disabled,
|
|
205
|
+
required: field.required,
|
|
206
|
+
...field.placeholder ? { placeholder: field.placeholder } : {},
|
|
207
|
+
...inputConstraints(props)
|
|
208
|
+
}
|
|
209
|
+
) });
|
|
210
|
+
}
|
|
211
|
+
function InputBlock({ props }) {
|
|
212
|
+
return /* @__PURE__ */ jsx(TextInput, { props });
|
|
213
|
+
}
|
|
214
|
+
function TextareaBlock({ props }) {
|
|
215
|
+
const field = useNodeField(props);
|
|
216
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
217
|
+
Textarea,
|
|
218
|
+
{
|
|
219
|
+
id: field.id,
|
|
220
|
+
name: field.name,
|
|
221
|
+
value: textValue(field.value),
|
|
222
|
+
onChange: (event) => field.setValue(event.target.value),
|
|
223
|
+
disabled: field.disabled,
|
|
224
|
+
required: field.required,
|
|
225
|
+
...field.placeholder ? { placeholder: field.placeholder } : {},
|
|
226
|
+
...inputConstraints(props)
|
|
227
|
+
}
|
|
228
|
+
) });
|
|
229
|
+
}
|
|
230
|
+
function CodeBlock({ props }) {
|
|
231
|
+
const field = useNodeField(props);
|
|
232
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
233
|
+
Textarea,
|
|
234
|
+
{
|
|
235
|
+
id: field.id,
|
|
236
|
+
name: field.name,
|
|
237
|
+
className: "font-mono text-sm",
|
|
238
|
+
rows: 10,
|
|
239
|
+
spellCheck: false,
|
|
240
|
+
value: textValue(field.value),
|
|
241
|
+
onChange: (event) => field.setValue(event.target.value),
|
|
242
|
+
disabled: field.disabled,
|
|
243
|
+
required: field.required,
|
|
244
|
+
...field.placeholder ? { placeholder: field.placeholder } : {}
|
|
245
|
+
}
|
|
246
|
+
) });
|
|
247
|
+
}
|
|
248
|
+
function NumberInputBlock({ props }) {
|
|
249
|
+
const field = useNodeField(props);
|
|
250
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
251
|
+
Input,
|
|
252
|
+
{
|
|
253
|
+
id: field.id,
|
|
254
|
+
name: field.name,
|
|
255
|
+
type: "number",
|
|
256
|
+
value: textValue(field.value),
|
|
257
|
+
onChange: (event) => field.setValue(numberValue(event.target.value)),
|
|
258
|
+
disabled: field.disabled,
|
|
259
|
+
required: field.required,
|
|
260
|
+
...field.placeholder ? { placeholder: field.placeholder } : {},
|
|
261
|
+
...numericConstraints(props)
|
|
262
|
+
}
|
|
263
|
+
) });
|
|
264
|
+
}
|
|
265
|
+
function SelectBlock({ props }) {
|
|
266
|
+
const field = useNodeField(props);
|
|
267
|
+
const options = readOptions(props);
|
|
268
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsxs(
|
|
269
|
+
Select,
|
|
270
|
+
{
|
|
271
|
+
value: textValue(field.value),
|
|
272
|
+
onValueChange: (value) => field.setValue(value),
|
|
273
|
+
disabled: field.disabled,
|
|
274
|
+
children: [
|
|
275
|
+
/* @__PURE__ */ jsx(SelectTrigger, { id: field.id, children: /* @__PURE__ */ jsx(SelectValue, { placeholder: field.placeholder ?? "Select\u2026" }) }),
|
|
276
|
+
/* @__PURE__ */ jsx(SelectContent, { children: options.map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option.value, children: option.label }, option.value)) })
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
) });
|
|
280
|
+
}
|
|
281
|
+
function RadioGroupBlock({ props }) {
|
|
282
|
+
const field = useNodeField(props);
|
|
283
|
+
const options = readOptions(props);
|
|
284
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
285
|
+
RadioGroup,
|
|
286
|
+
{
|
|
287
|
+
value: textValue(field.value),
|
|
288
|
+
onValueChange: (value) => field.setValue(value),
|
|
289
|
+
disabled: field.disabled,
|
|
290
|
+
children: options.map((option) => /* @__PURE__ */ jsxs(Label, { className: "flex items-center gap-2 font-normal", children: [
|
|
291
|
+
/* @__PURE__ */ jsx(Radio, { value: option.value }),
|
|
292
|
+
option.label
|
|
293
|
+
] }, option.value))
|
|
294
|
+
}
|
|
295
|
+
) });
|
|
296
|
+
}
|
|
297
|
+
function BooleanField({
|
|
298
|
+
props,
|
|
299
|
+
control
|
|
300
|
+
}) {
|
|
301
|
+
const field = useNodeField(props);
|
|
302
|
+
if (props.hidden) return null;
|
|
303
|
+
const label = typeof props.label === "string" ? props.label : props.name ?? "";
|
|
304
|
+
return /* @__PURE__ */ jsxs("div", { className: typeof props.className === "string" ? props.className : void 0, children: [
|
|
305
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: field.id, className: "flex items-center gap-2 font-normal", children: [
|
|
306
|
+
control({
|
|
307
|
+
id: field.id,
|
|
308
|
+
checked: Boolean(field.value),
|
|
309
|
+
disabled: field.disabled,
|
|
310
|
+
onCheckedChange: (checked) => field.setValue(checked)
|
|
311
|
+
}),
|
|
312
|
+
label
|
|
313
|
+
] }),
|
|
314
|
+
typeof props.description === "string" && /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: props.description }),
|
|
315
|
+
field.error && /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-destructive", children: field.error })
|
|
316
|
+
] });
|
|
317
|
+
}
|
|
318
|
+
function CheckboxBlock({ props }) {
|
|
319
|
+
return /* @__PURE__ */ jsx(BooleanField, { props, control: (args) => /* @__PURE__ */ jsx(Checkbox, { ...args }) });
|
|
320
|
+
}
|
|
321
|
+
function SwitchBlock({ props }) {
|
|
322
|
+
return /* @__PURE__ */ jsx(BooleanField, { props, control: (args) => /* @__PURE__ */ jsx(Switch, { ...args }) });
|
|
323
|
+
}
|
|
324
|
+
function DatePickerBlock({ props }) {
|
|
325
|
+
return /* @__PURE__ */ jsx(TextInput, { props, type: "date" });
|
|
326
|
+
}
|
|
327
|
+
function DateTimePickerBlock({ props }) {
|
|
328
|
+
const field = useNodeField(props);
|
|
329
|
+
const raw = textValue(field.value);
|
|
330
|
+
const local = raw.length > 16 ? raw.slice(0, 16) : raw;
|
|
331
|
+
const zone = ZONE_SUFFIX.exec(raw)?.[0] ?? "";
|
|
332
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
333
|
+
Input,
|
|
334
|
+
{
|
|
335
|
+
id: field.id,
|
|
336
|
+
name: field.name,
|
|
337
|
+
type: "datetime-local",
|
|
338
|
+
value: local,
|
|
339
|
+
onChange: (event) => field.setValue(zonedValue(event.target.value, zone)),
|
|
340
|
+
disabled: field.disabled,
|
|
341
|
+
required: field.required
|
|
342
|
+
}
|
|
343
|
+
) });
|
|
344
|
+
}
|
|
345
|
+
function TimePickerBlock({ props }) {
|
|
346
|
+
return /* @__PURE__ */ jsx(TextInput, { props, type: "time" });
|
|
347
|
+
}
|
|
348
|
+
function PhoneInputBlock({ props }) {
|
|
349
|
+
return /* @__PURE__ */ jsx(TextInput, { props, type: "tel" });
|
|
350
|
+
}
|
|
351
|
+
function FileUploadBlock({ props }) {
|
|
352
|
+
const field = useNodeField(props);
|
|
353
|
+
return /* @__PURE__ */ jsx(FieldShell, { props, id: field.id, error: field.error, children: /* @__PURE__ */ jsx(
|
|
354
|
+
Input,
|
|
355
|
+
{
|
|
356
|
+
id: field.id,
|
|
357
|
+
name: field.name,
|
|
358
|
+
type: "file",
|
|
359
|
+
onChange: (event) => field.setValue(event.target.files?.[0]?.name ?? null),
|
|
360
|
+
disabled: field.disabled,
|
|
361
|
+
required: field.required
|
|
362
|
+
}
|
|
363
|
+
) });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/registry.ts
|
|
367
|
+
var widgetRegistry = {
|
|
368
|
+
Input: InputBlock,
|
|
369
|
+
Textarea: TextareaBlock,
|
|
370
|
+
Select: SelectBlock,
|
|
371
|
+
RadioGroup: RadioGroupBlock,
|
|
372
|
+
Checkbox: CheckboxBlock,
|
|
373
|
+
Switch: SwitchBlock,
|
|
374
|
+
NumberInput: NumberInputBlock,
|
|
375
|
+
DatePicker: DatePickerBlock,
|
|
376
|
+
DateTimePicker: DateTimePickerBlock,
|
|
377
|
+
TimePicker: TimePickerBlock,
|
|
378
|
+
PhoneInput: PhoneInputBlock,
|
|
379
|
+
CodeEditor: CodeBlock,
|
|
380
|
+
MarkdownEditor: CodeBlock,
|
|
381
|
+
JsonEditor: CodeBlock,
|
|
382
|
+
FileUpload: FileUploadBlock
|
|
383
|
+
};
|
|
384
|
+
var containerRegistry = {
|
|
385
|
+
Page: PageBlock,
|
|
386
|
+
Form: FormBlock,
|
|
387
|
+
Section: SectionBlock,
|
|
388
|
+
Grid: GridBlock,
|
|
389
|
+
GridColumn: GridColumnBlock,
|
|
390
|
+
Tabs: TabsBlock,
|
|
391
|
+
Tab: TabBlock
|
|
392
|
+
};
|
|
393
|
+
var blockRegistry = {
|
|
394
|
+
Button: ButtonBlock,
|
|
395
|
+
ActionBar: ActionBarBlock,
|
|
396
|
+
Markdown: MarkdownBlock,
|
|
397
|
+
StatCard: StatCardBlock
|
|
398
|
+
};
|
|
399
|
+
var defaultBlockRegistry = {
|
|
400
|
+
...widgetRegistry,
|
|
401
|
+
...containerRegistry,
|
|
402
|
+
...blockRegistry
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
export { ActionBarBlock, ButtonBlock, CheckboxBlock, CodeBlock, DatePickerBlock, DateTimePickerBlock, FieldShell, FileUploadBlock, FormBlock, GridBlock, GridColumnBlock, InputBlock, MarkdownBlock, NumberInputBlock, PageBlock, PhoneInputBlock, RadioGroupBlock, SectionBlock, SelectBlock, StatCardBlock, SwitchBlock, TabBlock, TabsBlock, TextareaBlock, TimePickerBlock, blockRegistry, containerRegistry, defaultBlockRegistry, readOptions, textValue, useNodeField, widgetRegistry };
|
|
406
|
+
//# sourceMappingURL=index.js.map
|
|
407
|
+
//# sourceMappingURL=index.js.map
|