@lattice-php/lattice 0.3.0 → 0.5.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/dist/action/components/action-form.js +3 -3
- package/dist/action/components/action-group.js +1 -1
- package/dist/action/components/action.js +10 -16
- package/dist/action/components/action.js.map +1 -1
- package/dist/action/run-action.d.ts +9 -0
- package/dist/action/run-action.js +22 -0
- package/dist/action/run-action.js.map +1 -0
- package/dist/chat/components/chat-box.js +31 -14
- package/dist/chat/components/chat-box.js.map +1 -1
- package/dist/chat/components/message.js +2 -2
- package/dist/chat/components/message.js.map +1 -1
- package/dist/chat/components/prompt-input.js +1 -1
- package/dist/chat/index.js +2 -0
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/transport.d.ts +2 -0
- package/dist/chat/transport.js +23 -3
- package/dist/chat/transport.js.map +1 -1
- package/dist/core/api.d.ts +14 -7
- package/dist/core/api.js +77 -1
- package/dist/core/api.js.map +1 -1
- package/dist/core/components/badge.js +4 -4
- package/dist/core/components/badge.js.map +1 -1
- package/dist/core/components/button.js +31 -19
- package/dist/core/components/button.js.map +1 -1
- package/dist/core/components/card.js +3 -2
- package/dist/core/components/card.js.map +1 -1
- package/dist/core/components/chart.js +3 -2
- package/dist/core/components/chart.js.map +1 -1
- package/dist/core/components/checkbox.js +1 -1
- package/dist/core/components/checkbox.js.map +1 -1
- package/dist/core/components/control.js +4 -4
- package/dist/core/components/control.js.map +1 -1
- package/dist/core/components/dialog.d.ts +1 -1
- package/dist/core/components/dialog.js +3 -2
- package/dist/core/components/dialog.js.map +1 -1
- package/dist/core/components/floating-panel.js +5 -4
- package/dist/core/components/floating-panel.js.map +1 -1
- package/dist/core/components/fragment.js +3 -6
- package/dist/core/components/fragment.js.map +1 -1
- package/dist/core/components/grid.js +2 -1
- package/dist/core/components/grid.js.map +1 -1
- package/dist/core/components/heading.js +1 -1
- package/dist/core/components/heading.js.map +1 -1
- package/dist/core/components/index.js +0 -2
- package/dist/core/components/index.js.map +1 -1
- package/dist/core/components/popover.d.ts +1 -1
- package/dist/core/components/popover.js +1 -1
- package/dist/core/components/popover.js.map +1 -1
- package/dist/core/components/section.js +7 -11
- package/dist/core/components/section.js.map +1 -1
- package/dist/core/components/segmented-pills.js +1 -1
- package/dist/core/components/segmented-pills.js.map +1 -1
- package/dist/core/components/stack.js +9 -2
- package/dist/core/components/stack.js.map +1 -1
- package/dist/core/components/tabs.js +2 -2
- package/dist/core/components/tabs.js.map +1 -1
- package/dist/core/nodes.d.ts +6 -0
- package/dist/core/nodes.js +13 -0
- package/dist/core/nodes.js.map +1 -0
- package/dist/core/renderer.js +1 -1
- package/dist/core/types.d.ts +3 -1
- package/dist/create-app.d.ts +21 -0
- package/dist/create-app.js +31 -0
- package/dist/create-app.js.map +1 -0
- package/dist/effects/registry.js +2 -1
- package/dist/effects/registry.js.map +1 -1
- package/dist/effects/use-effect-dispatcher.js +1 -1
- package/dist/effects/use-flash-effects.js +1 -1
- package/dist/events/event-names.d.ts +3 -2
- package/dist/events/event-names.js +3 -2
- package/dist/events/event-names.js.map +1 -1
- package/dist/form/components/base/affix-group.d.ts +17 -0
- package/dist/form/components/base/affix-group.js +49 -0
- package/dist/form/components/base/affix-group.js.map +1 -0
- package/dist/form/components/base/input-otp.d.ts +7 -0
- package/dist/form/components/base/input-otp.js +30 -0
- package/dist/form/components/base/input-otp.js.map +1 -0
- package/dist/form/components/base/label.js +1 -1
- package/dist/form/components/base/label.js.map +1 -1
- package/dist/form/components/base/submit-button.js +1 -1
- package/dist/form/components/base/submit-button.js.map +1 -1
- package/dist/form/components/base/textarea.js +1 -1
- package/dist/form/components/base/textarea.js.map +1 -1
- package/dist/form/components/conditions.js +1 -1
- package/dist/form/components/conditions.js.map +1 -1
- package/dist/form/components/fields/file-upload.js +35 -3
- package/dist/form/components/fields/file-upload.js.map +1 -1
- package/dist/form/components/fields/number-input.js +21 -15
- package/dist/form/components/fields/number-input.js.map +1 -1
- package/dist/form/components/fields/otp-input.d.ts +2 -0
- package/dist/form/components/fields/otp-input.js +25 -0
- package/dist/form/components/fields/otp-input.js.map +1 -0
- package/dist/form/components/fields/password-input.js +21 -15
- package/dist/form/components/fields/password-input.js.map +1 -1
- package/dist/form/components/fields/rich-editor.js +2 -2
- package/dist/form/components/fields/rich-editor.js.map +1 -1
- package/dist/form/components/fields/row-item.js +1 -1
- package/dist/form/components/fields/table-rows.js +1 -1
- package/dist/form/components/fields/text-input.js +19 -13
- package/dist/form/components/fields/text-input.js.map +1 -1
- package/dist/form/components/form.js +2 -2
- package/dist/form/components/form.js.map +1 -1
- package/dist/form/components/index.d.ts +1 -0
- package/dist/form/components/index.js +2 -1
- package/dist/form/components/prefill-targets.d.ts +0 -1
- package/dist/form/components/prefill-targets.js +1 -4
- package/dist/form/components/prefill-targets.js.map +1 -1
- package/dist/form/components/use-form-resolver.js +2 -2
- package/dist/form/components/use-form-resolver.js.map +1 -1
- package/dist/form/index.js +1 -0
- package/dist/form/index.js.map +1 -1
- package/dist/form/skeleton.js +1 -1
- package/dist/form/skeleton.js.map +1 -1
- package/dist/i18n/locale-reload.js +1 -1
- package/dist/i18n/translatable.d.ts +4 -0
- package/dist/i18n/translatable.js +24 -0
- package/dist/i18n/translatable.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -13
- package/dist/lattice.css +99 -6
- package/dist/layout/breadcrumbs.js +3 -2
- package/dist/layout/breadcrumbs.js.map +1 -1
- package/dist/layout/callouts.js +2 -2
- package/dist/layout/callouts.js.map +1 -1
- package/dist/layout/components.js +4 -2
- package/dist/layout/components.js.map +1 -1
- package/dist/layout/dropdown.js +2 -1
- package/dist/layout/dropdown.js.map +1 -1
- package/dist/layout/menu-item.js +33 -12
- package/dist/layout/menu-item.js.map +1 -1
- package/dist/layout/menu.js +2 -1
- package/dist/layout/menu.js.map +1 -1
- package/dist/layout/popover.js +1 -1
- package/dist/layout/sidebar.js +69 -29
- package/dist/layout/sidebar.js.map +1 -1
- package/dist/layout/topbar.d.ts +3 -0
- package/dist/layout/topbar.js +16 -0
- package/dist/layout/topbar.js.map +1 -0
- package/dist/page.js +15 -10
- package/dist/page.js.map +1 -1
- package/dist/realtime/build-effects.d.ts +4 -0
- package/dist/realtime/build-effects.js +23 -0
- package/dist/realtime/build-effects.js.map +1 -0
- package/dist/realtime/listeners.d.ts +8 -0
- package/dist/realtime/listeners.js +31 -0
- package/dist/realtime/listeners.js.map +1 -0
- package/dist/realtime/subscriptions.d.ts +4 -0
- package/dist/realtime/subscriptions.js +45 -0
- package/dist/realtime/subscriptions.js.map +1 -0
- package/dist/registry.js +3 -2
- package/dist/registry.js.map +1 -1
- package/dist/remote/components/data-list.d.ts +10 -0
- package/dist/remote/components/data-list.js +106 -0
- package/dist/remote/components/data-list.js.map +1 -0
- package/dist/remote/index.d.ts +1 -0
- package/dist/remote/index.js +11 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/table/components/bulk-bar.js +10 -15
- package/dist/table/components/bulk-bar.js.map +1 -1
- package/dist/table/components/cells/text-cell.js +38 -3
- package/dist/table/components/cells/text-cell.js.map +1 -1
- package/dist/table/components/column-filter-control.d.ts +2 -1
- package/dist/table/components/column-filter-control.js +28 -19
- package/dist/table/components/column-filter-control.js.map +1 -1
- package/dist/table/components/column-header.js +2 -2
- package/dist/table/components/column-header.js.map +1 -1
- package/dist/table/components/filter-bar.d.ts +7 -6
- package/dist/table/components/filter-bar.js +51 -28
- package/dist/table/components/filter-bar.js.map +1 -1
- package/dist/table/components/filter-controls.js +2 -2
- package/dist/table/components/filter-controls.js.map +1 -1
- package/dist/table/components/filter-stack-bar.js +4 -3
- package/dist/table/components/filter-stack-bar.js.map +1 -1
- package/dist/table/components/filter-value-input.js +1 -1
- package/dist/table/components/filter-value-input.js.map +1 -1
- package/dist/table/components/sort-bar.js +1 -1
- package/dist/table/components/sort-bar.js.map +1 -1
- package/dist/table/components/table.js +26 -17
- package/dist/table/components/table.js.map +1 -1
- package/dist/table/filter-values.d.ts +5 -0
- package/dist/table/filter-values.js +10 -3
- package/dist/table/filter-values.js.map +1 -1
- package/dist/table/query.js +5 -4
- package/dist/table/query.js.map +1 -1
- package/dist/table/use-table.d.ts +1 -0
- package/dist/table/use-table.js +4 -0
- package/dist/table/use-table.js.map +1 -1
- package/dist/toast/toast.js +5 -2
- package/dist/toast/toast.js.map +1 -1
- package/dist/toast/toaster.js +6 -5
- package/dist/toast/toaster.js.map +1 -1
- package/dist/types/generated.d.ts +122 -14
- package/dist/vite.js +32 -1
- package/dist/vite.js.map +1 -1
- package/package.json +33 -3
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { cn } from "../../lib/utils.js";
|
|
2
|
-
import { nodeIdentity, prefixedTestId } from "../test-id.js";
|
|
3
2
|
import { Icon } from "../../icons/sprite.js";
|
|
4
3
|
import { Renderer } from "../renderer.js";
|
|
4
|
+
import { nodeIdentity, prefixedTestId } from "../test-id.js";
|
|
5
|
+
import { toNodes } from "../nodes.js";
|
|
5
6
|
import { useState } from "react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
//#region resources/js/core/components/section.tsx
|
|
@@ -10,15 +11,11 @@ function readStored(key, remember, fallback) {
|
|
|
10
11
|
const stored = window.localStorage.getItem(key);
|
|
11
12
|
return stored === null ? fallback : stored === "true";
|
|
12
13
|
}
|
|
13
|
-
function getNodes(value) {
|
|
14
|
-
if (!Array.isArray(value)) return [];
|
|
15
|
-
return value.filter((node) => typeof node === "object" && node !== null && "type" in node && typeof node.type === "string");
|
|
16
|
-
}
|
|
17
14
|
var SectionComponent = ({ children, node }) => {
|
|
18
15
|
const { title, description } = node.props;
|
|
19
16
|
const collapsible = node.props.collapsible === true;
|
|
20
17
|
const rememberState = node.props.rememberState !== false;
|
|
21
|
-
const headerActions =
|
|
18
|
+
const headerActions = toNodes(node.props.headerActions);
|
|
22
19
|
const identity = nodeIdentity(node);
|
|
23
20
|
const storageKey = `lattice:section:${identity ?? "default"}`;
|
|
24
21
|
const [collapsed, setCollapsed] = useState(() => readStored(storageKey, collapsible && rememberState, node.props.collapsed === true));
|
|
@@ -30,11 +27,10 @@ var SectionComponent = ({ children, node }) => {
|
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
29
|
const isCollapsed = collapsible && collapsed;
|
|
33
|
-
const hasHeader = Boolean(title || description || headerActions.length > 0 || collapsible);
|
|
34
30
|
return /* @__PURE__ */ jsxs("section", {
|
|
35
|
-
className: "flex flex-col gap-6 rounded-lt border border-lt-border bg-lt-surface py-6 text-lt-surface-fg shadow-
|
|
36
|
-
"data-lattice-component":
|
|
37
|
-
children: [
|
|
31
|
+
className: "flex flex-col gap-6 rounded-lt border border-lt-border bg-lt-surface py-6 text-lt-surface-fg shadow-lt-sm",
|
|
32
|
+
"data-lattice-component": identity,
|
|
33
|
+
children: [Boolean(title || description || headerActions.length > 0 || collapsible) && /* @__PURE__ */ jsxs("div", {
|
|
38
34
|
className: "flex items-start justify-between gap-4 px-6",
|
|
39
35
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
40
36
|
className: "flex min-w-0 items-start gap-2",
|
|
@@ -42,7 +38,7 @@ var SectionComponent = ({ children, node }) => {
|
|
|
42
38
|
"aria-expanded": !isCollapsed,
|
|
43
39
|
"aria-label": isCollapsed ? "Expand section" : "Collapse section",
|
|
44
40
|
"data-test": prefixedTestId("section-toggle", identity) ?? "section-toggle-default",
|
|
45
|
-
className: "mt-0.5 inline-flex shrink-0 items-center rounded-
|
|
41
|
+
className: "mt-0.5 inline-flex shrink-0 items-center rounded-lt-sm p-0.5 text-lt-muted-fg transition-colors hover:bg-lt-muted hover:text-lt-fg",
|
|
46
42
|
onClick: toggle,
|
|
47
43
|
type: "button",
|
|
48
44
|
children: /* @__PURE__ */ jsx(Icon, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.js","names":[],"sources":["../../../resources/js/core/components/section.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { Icon } from \"@lattice-php/lattice/icons\";\nimport { Renderer } from \"@lattice-php/lattice/core/renderer\";\nimport { nodeIdentity, prefixedTestId } from \"@lattice-php/lattice/core/test-id\";\nimport type {
|
|
1
|
+
{"version":3,"file":"section.js","names":[],"sources":["../../../resources/js/core/components/section.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { Icon } from \"@lattice-php/lattice/icons\";\nimport { Renderer } from \"@lattice-php/lattice/core/renderer\";\nimport { nodeIdentity, prefixedTestId } from \"@lattice-php/lattice/core/test-id\";\nimport { toNodes } from \"@lattice-php/lattice/core/nodes\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\nfunction readStored(key: string, remember: boolean, fallback: boolean): boolean {\n if (!remember || typeof window === \"undefined\") {\n return fallback;\n }\n\n const stored = window.localStorage.getItem(key);\n\n return stored === null ? fallback : stored === \"true\";\n}\n\nconst SectionComponent: RendererComponent<\"section\"> = ({ children, node }) => {\n const { title, description } = node.props;\n const collapsible = node.props.collapsible === true;\n const rememberState = node.props.rememberState !== false;\n const headerActions = toNodes(node.props.headerActions);\n const identity = nodeIdentity(node);\n const storageKey = `lattice:section:${identity ?? \"default\"}`;\n\n const [collapsed, setCollapsed] = useState(() =>\n readStored(storageKey, collapsible && rememberState, node.props.collapsed === true),\n );\n\n function toggle(): void {\n setCollapsed((value) => {\n const next = !value;\n\n if (rememberState && typeof window !== \"undefined\") {\n window.localStorage.setItem(storageKey, String(next));\n }\n\n return next;\n });\n }\n\n const isCollapsed = collapsible && collapsed;\n const hasHeader = Boolean(title || description || headerActions.length > 0 || collapsible);\n\n return (\n <section\n className=\"flex flex-col gap-6 rounded-lt border border-lt-border bg-lt-surface py-6 text-lt-surface-fg shadow-lt-sm\"\n data-lattice-component={identity}\n >\n {hasHeader && (\n <div className=\"flex items-start justify-between gap-4 px-6\">\n <div className=\"flex min-w-0 items-start gap-2\">\n {collapsible && (\n <button\n aria-expanded={!isCollapsed}\n aria-label={isCollapsed ? \"Expand section\" : \"Collapse section\"}\n data-test={prefixedTestId(\"section-toggle\", identity) ?? \"section-toggle-default\"}\n className=\"mt-0.5 inline-flex shrink-0 items-center rounded-lt-sm p-0.5 text-lt-muted-fg transition-colors hover:bg-lt-muted hover:text-lt-fg\"\n onClick={toggle}\n type=\"button\"\n >\n <Icon\n name=\"chevron-down\"\n className={cn(\n \"size-lt-icon-md transition-transform\",\n isCollapsed && \"-rotate-90\",\n )}\n />\n </button>\n )}\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n {title && <div className=\"font-semibold leading-none\">{title}</div>}\n {description && <div className=\"text-sm text-lt-muted-fg\">{description}</div>}\n </div>\n </div>\n\n {headerActions.length > 0 && (\n <div className=\"flex shrink-0 items-center gap-2\">\n <Renderer nodes={headerActions} />\n </div>\n )}\n </div>\n )}\n\n {!isCollapsed && children && <div className=\"flex flex-col gap-6 px-6\">{children}</div>}\n </section>\n );\n};\n\nexport default SectionComponent;\n"],"mappings":";;;;;;;;AAQA,SAAS,WAAW,KAAa,UAAmB,UAA4B;CAC9E,IAAI,CAAC,YAAY,OAAO,WAAW,aACjC,OAAO;CAGT,MAAM,SAAS,OAAO,aAAa,QAAQ,GAAG;CAE9C,OAAO,WAAW,OAAO,WAAW,WAAW;AACjD;AAEA,IAAM,oBAAkD,EAAE,UAAU,WAAW;CAC7E,MAAM,EAAE,OAAO,gBAAgB,KAAK;CACpC,MAAM,cAAc,KAAK,MAAM,gBAAgB;CAC/C,MAAM,gBAAgB,KAAK,MAAM,kBAAkB;CACnD,MAAM,gBAAgB,QAAQ,KAAK,MAAM,aAAa;CACtD,MAAM,WAAW,aAAa,IAAI;CAClC,MAAM,aAAa,mBAAmB,YAAY;CAElD,MAAM,CAAC,WAAW,gBAAgB,eAChC,WAAW,YAAY,eAAe,eAAe,KAAK,MAAM,cAAc,IAAI,CACpF;CAEA,SAAS,SAAe;EACtB,cAAc,UAAU;GACtB,MAAM,OAAO,CAAC;GAEd,IAAI,iBAAiB,OAAO,WAAW,aACrC,OAAO,aAAa,QAAQ,YAAY,OAAO,IAAI,CAAC;GAGtD,OAAO;EACT,CAAC;CACH;CAEA,MAAM,cAAc,eAAe;CAGnC,OACE,qBAAC,WAAD;EACE,WAAU;EACV,0BAAwB;YAF1B,CAHgB,QAAQ,SAAS,eAAe,cAAc,SAAS,KAAK,WAOzE,KACC,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,qBAAC,OAAD;IAAK,WAAU;cAAf,CACG,eACC,oBAAC,UAAD;KACE,iBAAe,CAAC;KAChB,cAAY,cAAc,mBAAmB;KAC7C,aAAW,eAAe,kBAAkB,QAAQ,KAAK;KACzD,WAAU;KACV,SAAS;KACT,MAAK;eAEL,oBAAC,MAAD;MACE,MAAK;MACL,WAAW,GACT,wCACA,eAAe,YACjB;KACD,CAAA;IACK,CAAA,GAEV,qBAAC,OAAD;KAAK,WAAU;eAAf,CACG,SAAS,oBAAC,OAAD;MAAK,WAAU;gBAA8B;KAAW,CAAA,GACjE,eAAe,oBAAC,OAAD;MAAK,WAAU;gBAA4B;KAAiB,CAAA,CACzE;MACF;OAEJ,cAAc,SAAS,KACtB,oBAAC,OAAD;IAAK,WAAU;cACb,oBAAC,UAAD,EAAU,OAAO,cAAgB,CAAA;GAC9B,CAAA,CAEJ;MAGN,CAAC,eAAe,YAAY,oBAAC,OAAD;GAAK,WAAU;GAA4B;EAAc,CAAA,CAC/E;;AAEb"}
|
|
@@ -23,7 +23,7 @@ function SegmentedPills({ ariaLabel, autoFocus = false, disabled = false, name,
|
|
|
23
23
|
return /* @__PURE__ */ jsx("button", {
|
|
24
24
|
"aria-checked": isSelected,
|
|
25
25
|
"data-test": `${name ?? "segment"}-${option.value}`,
|
|
26
|
-
className: cn("whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors", isSelected ? "bg-lt-bg text-lt-fg shadow-xs" : "text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg", disabled && "cursor-not-allowed opacity-60"),
|
|
26
|
+
className: cn("whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors", isSelected ? "bg-lt-bg text-lt-fg shadow-lt-xs" : "text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg", disabled && "cursor-not-allowed opacity-60"),
|
|
27
27
|
disabled,
|
|
28
28
|
onClick: () => onSelect(option.value),
|
|
29
29
|
role: "radio",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmented-pills.js","names":[],"sources":["../../../resources/js/core/components/segmented-pills.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport type { Option } from \"@lattice-php/lattice/core/types\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\n/**\n * Presentational segmented pill group. Used by the form choice field (bound to a\n * form value) and the core segmented control (standalone, emits an event).\n */\nexport function SegmentedPills({\n ariaLabel,\n autoFocus = false,\n disabled = false,\n name,\n onSelect,\n options,\n tabIndex,\n value,\n}: {\n ariaLabel?: string;\n autoFocus?: boolean;\n disabled?: boolean;\n name?: string;\n onSelect: (value: string) => void;\n options: Option[];\n tabIndex?: number;\n value: string;\n}) {\n const groupRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!autoFocus) {\n return;\n }\n\n const group = groupRef.current;\n const target =\n group?.querySelector<HTMLButtonElement>('button[aria-checked=\"true\"]') ??\n group?.querySelector<HTMLButtonElement>(\"button\");\n\n target?.focus();\n }, [autoFocus]);\n\n return (\n <div\n aria-label={ariaLabel}\n className=\"inline-flex w-fit max-w-full gap-1 overflow-x-auto rounded-lt bg-lt-muted p-1\"\n ref={groupRef}\n role=\"radiogroup\"\n >\n {options.map((option) => {\n const isSelected = value === option.value;\n\n return (\n <button\n aria-checked={isSelected}\n data-test={`${name ?? \"segment\"}-${option.value}`}\n className={cn(\n \"whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors\",\n isSelected\n ? \"bg-lt-bg text-lt-fg shadow-xs\"\n : \"text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg\",\n disabled && \"cursor-not-allowed opacity-60\",\n )}\n disabled={disabled}\n key={option.value}\n onClick={() => onSelect(option.value)}\n role=\"radio\"\n tabIndex={tabIndex}\n type=\"button\"\n >\n {option.label}\n </button>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,eAAe,EAC7B,WACA,YAAY,OACZ,WAAW,OACX,MACA,UACA,SACA,UACA,SAUC;CACD,MAAM,WAAW,OAAuB,IAAI;CAE5C,gBAAgB;EACd,IAAI,CAAC,WACH;EAGF,MAAM,QAAQ,SAAS;EAKvB,CAHE,OAAO,cAAiC,+BAA6B,KACrE,OAAO,cAAiC,QAAQ,IAE1C,MAAM;CAChB,GAAG,CAAC,SAAS,CAAC;CAEd,OACE,oBAAC,OAAD;EACE,cAAY;EACZ,WAAU;EACV,KAAK;EACL,MAAK;YAEJ,QAAQ,KAAK,WAAW;GACvB,MAAM,aAAa,UAAU,OAAO;GAEpC,OACE,oBAAC,UAAD;IACE,gBAAc;IACd,aAAW,GAAG,QAAQ,UAAU,GAAG,OAAO;IAC1C,WAAW,GACT,qFACA,aACI,
|
|
1
|
+
{"version":3,"file":"segmented-pills.js","names":[],"sources":["../../../resources/js/core/components/segmented-pills.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport type { Option } from \"@lattice-php/lattice/core/types\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\n/**\n * Presentational segmented pill group. Used by the form choice field (bound to a\n * form value) and the core segmented control (standalone, emits an event).\n */\nexport function SegmentedPills({\n ariaLabel,\n autoFocus = false,\n disabled = false,\n name,\n onSelect,\n options,\n tabIndex,\n value,\n}: {\n ariaLabel?: string;\n autoFocus?: boolean;\n disabled?: boolean;\n name?: string;\n onSelect: (value: string) => void;\n options: Option[];\n tabIndex?: number;\n value: string;\n}) {\n const groupRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!autoFocus) {\n return;\n }\n\n const group = groupRef.current;\n const target =\n group?.querySelector<HTMLButtonElement>('button[aria-checked=\"true\"]') ??\n group?.querySelector<HTMLButtonElement>(\"button\");\n\n target?.focus();\n }, [autoFocus]);\n\n return (\n <div\n aria-label={ariaLabel}\n className=\"inline-flex w-fit max-w-full gap-1 overflow-x-auto rounded-lt bg-lt-muted p-1\"\n ref={groupRef}\n role=\"radiogroup\"\n >\n {options.map((option) => {\n const isSelected = value === option.value;\n\n return (\n <button\n aria-checked={isSelected}\n data-test={`${name ?? \"segment\"}-${option.value}`}\n className={cn(\n \"whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors\",\n isSelected\n ? \"bg-lt-bg text-lt-fg shadow-lt-xs\"\n : \"text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg\",\n disabled && \"cursor-not-allowed opacity-60\",\n )}\n disabled={disabled}\n key={option.value}\n onClick={() => onSelect(option.value)}\n role=\"radio\"\n tabIndex={tabIndex}\n type=\"button\"\n >\n {option.label}\n </button>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,eAAe,EAC7B,WACA,YAAY,OACZ,WAAW,OACX,MACA,UACA,SACA,UACA,SAUC;CACD,MAAM,WAAW,OAAuB,IAAI;CAE5C,gBAAgB;EACd,IAAI,CAAC,WACH;EAGF,MAAM,QAAQ,SAAS;EAKvB,CAHE,OAAO,cAAiC,+BAA6B,KACrE,OAAO,cAAiC,QAAQ,IAE1C,MAAM;CAChB,GAAG,CAAC,SAAS,CAAC;CAEd,OACE,oBAAC,OAAD;EACE,cAAY;EACZ,WAAU;EACV,KAAK;EACL,MAAK;YAEJ,QAAQ,KAAK,WAAW;GACvB,MAAM,aAAa,UAAU,OAAO;GAEpC,OACE,oBAAC,UAAD;IACE,gBAAc;IACd,aAAW,GAAG,QAAQ,UAAU,GAAG,OAAO;IAC1C,WAAW,GACT,qFACA,aACI,qCACA,uDACJ,YAAY,+BACd;IACU;IAEV,eAAe,SAAS,OAAO,KAAK;IACpC,MAAK;IACK;IACV,MAAK;cAEJ,OAAO;GACF,GAPD,OAAO,KAON;EAEZ,CAAC;CACE,CAAA;AAET"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../../lib/utils.js";
|
|
2
|
+
import { nodeIdentity } from "../test-id.js";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
//#region resources/js/core/components/stack.tsx
|
|
4
5
|
var gridAlignments = {
|
|
@@ -20,6 +21,7 @@ var stackGaps = {
|
|
|
20
21
|
xl: "gap-8"
|
|
21
22
|
};
|
|
22
23
|
var stackWidths = {
|
|
24
|
+
auto: "w-auto",
|
|
23
25
|
fill: "min-w-0 flex-1",
|
|
24
26
|
full: "w-full",
|
|
25
27
|
lg: "mx-auto w-full max-w-4xl",
|
|
@@ -38,6 +40,10 @@ var stackHeights = {
|
|
|
38
40
|
full: "h-full",
|
|
39
41
|
screen: "min-h-screen"
|
|
40
42
|
};
|
|
43
|
+
var floatClasses = {
|
|
44
|
+
end: "ml-auto",
|
|
45
|
+
start: "mr-auto"
|
|
46
|
+
};
|
|
41
47
|
var StackComponent = ({ children, node }) => {
|
|
42
48
|
const align = node.props.align ?? "stretch";
|
|
43
49
|
const direction = node.props.direction ?? "column";
|
|
@@ -45,10 +51,11 @@ var StackComponent = ({ children, node }) => {
|
|
|
45
51
|
const width = node.props.width ?? "full";
|
|
46
52
|
const justify = node.props.justify;
|
|
47
53
|
const height = node.props.height;
|
|
54
|
+
const float = node.props.float;
|
|
48
55
|
const isFlex = direction === "row" || justify != null;
|
|
49
56
|
return /* @__PURE__ */ jsx("div", {
|
|
50
|
-
"data-lattice-component": node
|
|
51
|
-
className: cn(isFlex ? cn("flex", direction === "row" ? "flex-wrap" : "flex-col") : "grid content-start", isFlex ? flexAlignments[align] ?? flexAlignments.stretch : gridAlignments[align] ?? gridAlignments.stretch, stackGaps[gap] ?? stackGaps.md, stackWidths[width] ?? stackWidths.full, justify ? justifyClasses[justify] : null, height ? stackHeights[height] : null),
|
|
57
|
+
"data-lattice-component": nodeIdentity(node),
|
|
58
|
+
className: cn(isFlex ? cn("flex", direction === "row" ? "flex-wrap" : "flex-col") : "grid content-start", isFlex ? flexAlignments[align] ?? flexAlignments.stretch : gridAlignments[align] ?? gridAlignments.stretch, stackGaps[gap] ?? stackGaps.md, stackWidths[width] ?? stackWidths.full, justify ? justifyClasses[justify] : null, height ? stackHeights[height] : null, float ? floatClasses[float] : null),
|
|
52
59
|
children
|
|
53
60
|
});
|
|
54
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","names":[],"sources":["../../../resources/js/core/components/stack.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\nconst gridAlignments: Record<string, string> = {\n center: \"justify-items-center text-center\",\n start: \"justify-items-start text-left\",\n stretch: \"justify-items-stretch\",\n};\n\nconst flexAlignments: Record<string, string> = {\n center: \"items-center text-center\",\n start: \"items-center text-left\",\n stretch: \"items-stretch justify-stretch\",\n};\n\nconst stackGaps: Record<string, string> = {\n none: \"gap-0\",\n xs: \"gap-1\",\n lg: \"gap-6\",\n md: \"gap-4\",\n sm: \"gap-2\",\n xl: \"gap-8\",\n};\n\nconst stackWidths: Record<string, string> = {\n fill: \"min-w-0 flex-1\",\n full: \"w-full\",\n lg: \"mx-auto w-full max-w-4xl\",\n md: \"mx-auto w-full max-w-2xl\",\n sm: \"mx-auto w-full max-w-md\",\n};\n\nconst justifyClasses: Record<string, string> = {\n around: \"justify-around\",\n between: \"justify-between\",\n center: \"justify-center\",\n end: \"justify-end\",\n evenly: \"justify-evenly\",\n start: \"justify-start\",\n};\n\nconst stackHeights: Record<string, string> = {\n full: \"h-full\",\n screen: \"min-h-screen\",\n};\n\nconst StackComponent: RendererComponent<\"stack\"> = ({ children, node }) => {\n const align = node.props.align ?? \"stretch\";\n const direction = node.props.direction ?? \"column\";\n const gap = node.props.gap ?? \"md\";\n const width = node.props.width ?? \"full\";\n const justify = node.props.justify;\n const height = node.props.height;\n const isFlex = direction === \"row\" || justify != null;\n\n return (\n <div\n data-lattice-component={node
|
|
1
|
+
{"version":3,"file":"stack.js","names":[],"sources":["../../../resources/js/core/components/stack.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { nodeIdentity } from \"@lattice-php/lattice/core/test-id\";\n\nconst gridAlignments: Record<string, string> = {\n center: \"justify-items-center text-center\",\n start: \"justify-items-start text-left\",\n stretch: \"justify-items-stretch\",\n};\n\nconst flexAlignments: Record<string, string> = {\n center: \"items-center text-center\",\n start: \"items-center text-left\",\n stretch: \"items-stretch justify-stretch\",\n};\n\nconst stackGaps: Record<string, string> = {\n none: \"gap-0\",\n xs: \"gap-1\",\n lg: \"gap-6\",\n md: \"gap-4\",\n sm: \"gap-2\",\n xl: \"gap-8\",\n};\n\nconst stackWidths: Record<string, string> = {\n auto: \"w-auto\",\n fill: \"min-w-0 flex-1\",\n full: \"w-full\",\n lg: \"mx-auto w-full max-w-4xl\",\n md: \"mx-auto w-full max-w-2xl\",\n sm: \"mx-auto w-full max-w-md\",\n};\n\nconst justifyClasses: Record<string, string> = {\n around: \"justify-around\",\n between: \"justify-between\",\n center: \"justify-center\",\n end: \"justify-end\",\n evenly: \"justify-evenly\",\n start: \"justify-start\",\n};\n\nconst stackHeights: Record<string, string> = {\n full: \"h-full\",\n screen: \"min-h-screen\",\n};\n\nconst floatClasses: Record<string, string> = {\n end: \"ml-auto\",\n start: \"mr-auto\",\n};\n\nconst StackComponent: RendererComponent<\"stack\"> = ({ children, node }) => {\n const align = node.props.align ?? \"stretch\";\n const direction = node.props.direction ?? \"column\";\n const gap = node.props.gap ?? \"md\";\n const width = node.props.width ?? \"full\";\n const justify = node.props.justify;\n const height = node.props.height;\n const float = node.props.float;\n const isFlex = direction === \"row\" || justify != null;\n\n return (\n <div\n data-lattice-component={nodeIdentity(node)}\n className={cn(\n isFlex ? cn(\"flex\", direction === \"row\" ? \"flex-wrap\" : \"flex-col\") : \"grid content-start\",\n isFlex\n ? (flexAlignments[align] ?? flexAlignments.stretch)\n : (gridAlignments[align] ?? gridAlignments.stretch),\n stackGaps[gap] ?? stackGaps.md,\n stackWidths[width] ?? stackWidths.full,\n justify ? justifyClasses[justify] : null,\n height ? stackHeights[height] : null,\n float ? floatClasses[float] : null,\n )}\n >\n {children}\n </div>\n );\n};\n\nexport default StackComponent;\n"],"mappings":";;;;AAIA,IAAM,iBAAyC;CAC7C,QAAQ;CACR,OAAO;CACP,SAAS;AACX;AAEA,IAAM,iBAAyC;CAC7C,QAAQ;CACR,OAAO;CACP,SAAS;AACX;AAEA,IAAM,YAAoC;CACxC,MAAM;CACN,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,cAAsC;CAC1C,MAAM;CACN,MAAM;CACN,MAAM;CACN,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,iBAAyC;CAC7C,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,KAAK;CACL,QAAQ;CACR,OAAO;AACT;AAEA,IAAM,eAAuC;CAC3C,MAAM;CACN,QAAQ;AACV;AAEA,IAAM,eAAuC;CAC3C,KAAK;CACL,OAAO;AACT;AAEA,IAAM,kBAA8C,EAAE,UAAU,WAAW;CACzE,MAAM,QAAQ,KAAK,MAAM,SAAS;CAClC,MAAM,YAAY,KAAK,MAAM,aAAa;CAC1C,MAAM,MAAM,KAAK,MAAM,OAAO;CAC9B,MAAM,QAAQ,KAAK,MAAM,SAAS;CAClC,MAAM,UAAU,KAAK,MAAM;CAC3B,MAAM,SAAS,KAAK,MAAM;CAC1B,MAAM,QAAQ,KAAK,MAAM;CACzB,MAAM,SAAS,cAAc,SAAS,WAAW;CAEjD,OACE,oBAAC,OAAD;EACE,0BAAwB,aAAa,IAAI;EACzC,WAAW,GACT,SAAS,GAAG,QAAQ,cAAc,QAAQ,cAAc,UAAU,IAAI,sBACtE,SACK,eAAe,UAAU,eAAe,UACxC,eAAe,UAAU,eAAe,SAC7C,UAAU,QAAQ,UAAU,IAC5B,YAAY,UAAU,YAAY,MAClC,UAAU,eAAe,WAAW,MACpC,SAAS,aAAa,UAAU,MAChC,QAAQ,aAAa,SAAS,IAChC;EAEC;CACE,CAAA;AAET"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "../../lib/utils.js";
|
|
2
2
|
import { useT } from "../../i18n/instance.js";
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
3
|
import { router } from "@inertiajs/react";
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
//#region resources/js/core/components/tabs.tsx
|
|
7
7
|
var TabsContext = createContext(null);
|
|
@@ -101,7 +101,7 @@ var TabsComponent = ({ children, node }) => {
|
|
|
101
101
|
"aria-controls": `${tab.value}-panel`,
|
|
102
102
|
"aria-selected": isActive,
|
|
103
103
|
"data-test": `tab-${tab.value}`,
|
|
104
|
-
className: cn("whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors", isActive ? "bg-lt-bg text-lt-fg shadow-xs" : "text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg", isVertical && "text-left"),
|
|
104
|
+
className: cn("whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors", isActive ? "bg-lt-bg text-lt-fg shadow-lt-xs" : "text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg", isVertical && "text-left"),
|
|
105
105
|
id: `${tab.value}-tab`,
|
|
106
106
|
onClick: () => selectTab(tab),
|
|
107
107
|
onKeyDown: onTablistKeyDown,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","names":[],"sources":["../../../resources/js/core/components/tabs.tsx"],"sourcesContent":["import { router } from \"@inertiajs/react\";\nimport { createContext, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport type { Node, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport type { Tab } from \"@lattice-php/lattice/types/generated\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\n\ntype TabsContextValue = {\n activeValue: string;\n setActiveValue: (value: string) => void;\n};\n\nconst TabsContext = createContext<TabsContextValue | null>(null);\n\nfunction useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext);\n\n if (!context) {\n return {\n activeValue: \"\",\n setActiveValue: () => {},\n };\n }\n\n return context;\n}\n\ntype TabItem = {\n confirm?: {\n required?: boolean;\n };\n label: string;\n value: string;\n};\n\nfunction getTabs(node: Node): TabItem[] {\n return (node.schema ?? [])\n .filter((child) => child.type === \"tab\")\n .map((child) => {\n const props = child.props as unknown as Tab;\n\n return {\n confirm: props.confirm ? { required: props.confirm.required } : undefined,\n label: props.label,\n value: props.value,\n };\n })\n .filter((tab) => tab.value !== \"\");\n}\n\nfunction queryValue(queryKey: string, tabs: Array<{ value: string }>): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n const value = new URLSearchParams(window.location.search).get(queryKey);\n\n if (!value || !tabs.some((tab) => tab.value === value)) {\n return null;\n }\n\n return value;\n}\n\nfunction replaceQueryValue(queryKey: string, value: string): void {\n if (typeof window === \"undefined\") {\n return;\n }\n\n const url = new URL(window.location.href);\n url.searchParams.set(queryKey, value);\n window.history.replaceState(window.history.state, \"\", `${url.pathname}${url.search}${url.hash}`);\n}\n\nfunction queryUrl(queryKey: string, value: string): string {\n if (typeof window === \"undefined\") {\n return \"\";\n }\n\n const url = new URL(window.location.href);\n url.searchParams.set(queryKey, value);\n\n return `${url.pathname}${url.search}${url.hash}`;\n}\n\nexport const TabsComponent: RendererComponent<\"tabs\"> = ({ children, node }) => {\n const { t } = useT(\"lattice\");\n const tabs = useMemo(() => getTabs(node), [node]);\n const firstValue = tabs[0]?.value ?? \"\";\n const queryKey = node.props.queryKey;\n const orientation = node.props.orientation;\n const isVertical = orientation === \"vertical\";\n const serverActiveValue = node.props.activeValue;\n const defaultValue = node.props.defaultValue ?? firstValue;\n const tablistRef = useRef<HTMLDivElement>(null);\n const [activeValue, setActiveTabValue] = useState(\n () => serverActiveValue || (queryValue(queryKey, tabs) ?? defaultValue) || firstValue,\n );\n\n function selectTab(tab: TabItem): void {\n if (tab.confirm?.required) {\n router.visit(queryUrl(queryKey, tab.value), {\n preserveScroll: true,\n });\n\n return;\n }\n\n setActiveTabValue(tab.value);\n replaceQueryValue(queryKey, tab.value);\n }\n\n function selectTabValue(value: string): void {\n const tab = tabs.find((item) => item.value === value);\n\n if (tab) {\n selectTab(tab);\n }\n }\n\n function onTablistKeyDown(event: KeyboardEvent<HTMLButtonElement>): void {\n const nextKey = isVertical ? \"ArrowDown\" : \"ArrowRight\";\n const prevKey = isVertical ? \"ArrowUp\" : \"ArrowLeft\";\n\n if (\n event.key !== nextKey &&\n event.key !== prevKey &&\n event.key !== \"Home\" &&\n event.key !== \"End\"\n ) {\n return;\n }\n\n const buttons = Array.from(\n tablistRef.current?.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]') ?? [],\n );\n\n if (buttons.length === 0) {\n return;\n }\n\n event.preventDefault();\n const current = buttons.indexOf(document.activeElement as HTMLButtonElement);\n\n let index: number;\n if (event.key === \"Home\") {\n index = 0;\n } else if (event.key === \"End\") {\n index = buttons.length - 1;\n } else {\n const delta = event.key === nextKey ? 1 : -1;\n const base = current < 0 ? 0 : current;\n index = (base + delta + buttons.length) % buttons.length;\n }\n\n buttons[index]?.focus();\n }\n\n return (\n <TabsContext.Provider value={{ activeValue, setActiveValue: selectTabValue }}>\n <div\n className={cn(\"gap-6\", isVertical ? \"flex\" : \"grid\")}\n data-lattice-tabs={node.key ?? node.id}\n >\n <div\n aria-label={t(\"a11y.tabs\", \"Tabs\")}\n aria-orientation={orientation}\n className={cn(\n \"gap-1 rounded-lt bg-lt-muted p-1\",\n isVertical ? \"flex flex-col\" : \"inline-flex w-fit max-w-full overflow-x-auto\",\n )}\n ref={tablistRef}\n role=\"tablist\"\n >\n {tabs.map((tab) => {\n const isActive = activeValue === tab.value;\n\n return (\n <button\n aria-controls={`${tab.value}-panel`}\n aria-selected={isActive}\n data-test={`tab-${tab.value}`}\n className={cn(\n \"whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors\",\n isActive\n ? \"bg-lt-bg text-lt-fg shadow-xs\"\n : \"text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg\",\n isVertical && \"text-left\",\n )}\n id={`${tab.value}-tab`}\n key={tab.value}\n onClick={() => selectTab(tab)}\n onKeyDown={onTablistKeyDown}\n role=\"tab\"\n tabIndex={isActive ? 0 : -1}\n type=\"button\"\n >\n {tab.label}\n </button>\n );\n })}\n </div>\n\n <div className={cn(\"min-w-0\", isVertical && \"flex-1\")}>{children}</div>\n </div>\n </TabsContext.Provider>\n );\n};\n\nconst TabComponent: RendererComponent<\"tab\"> = ({ children, node }) => {\n const { activeValue } = useTabsContext();\n const value = node.props.value;\n const isActive = activeValue === value;\n const [hasOpened, setHasOpened] = useState(isActive);\n\n useEffect(() => {\n if (isActive) {\n setHasOpened(true);\n }\n }, [isActive]);\n\n return (\n <section\n aria-labelledby={`${value}-tab`}\n className={cn(\"space-y-8\", !isActive && \"hidden\")}\n hidden={!isActive}\n id={`${value}-panel`}\n role=\"tabpanel\"\n tabIndex={0}\n >\n {hasOpened ? (children as ReactNode) : null}\n </section>\n );\n};\n\nexport default TabComponent;\n"],"mappings":";;;;;;AAaA,IAAM,cAAc,cAAuC,IAAI;AAE/D,SAAS,iBAAmC;CAC1C,MAAM,UAAU,WAAW,WAAW;CAEtC,IAAI,CAAC,SACH,OAAO;EACL,aAAa;EACb,sBAAsB,CAAC;CAC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Content":["import { router } from \"@inertiajs/react\";\nimport { createContext, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport type { Node, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport type { Tab } from \"@lattice-php/lattice/types/generated\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\n\ntype TabsContextValue = {\n activeValue: string;\n setActiveValue: (value: string) => void;\n};\n\nconst TabsContext = createContext<TabsContextValue | null>(null);\n\nfunction useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext);\n\n if (!context) {\n return {\n activeValue: \"\",\n setActiveValue: () => {},\n };\n }\n\n return context;\n}\n\ntype TabItem = {\n confirm?: {\n required?: boolean;\n };\n label: string;\n value: string;\n};\n\nfunction getTabs(node: Node): TabItem[] {\n return (node.schema ?? [])\n .filter((child) => child.type === \"tab\")\n .map((child) => {\n const props = child.props as unknown as Tab;\n\n return {\n confirm: props.confirm ? { required: props.confirm.required } : undefined,\n label: props.label,\n value: props.value,\n };\n })\n .filter((tab) => tab.value !== \"\");\n}\n\nfunction queryValue(queryKey: string, tabs: Array<{ value: string }>): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n const value = new URLSearchParams(window.location.search).get(queryKey);\n\n if (!value || !tabs.some((tab) => tab.value === value)) {\n return null;\n }\n\n return value;\n}\n\nfunction replaceQueryValue(queryKey: string, value: string): void {\n if (typeof window === \"undefined\") {\n return;\n }\n\n const url = new URL(window.location.href);\n url.searchParams.set(queryKey, value);\n window.history.replaceState(window.history.state, \"\", `${url.pathname}${url.search}${url.hash}`);\n}\n\nfunction queryUrl(queryKey: string, value: string): string {\n if (typeof window === \"undefined\") {\n return \"\";\n }\n\n const url = new URL(window.location.href);\n url.searchParams.set(queryKey, value);\n\n return `${url.pathname}${url.search}${url.hash}`;\n}\n\nexport const TabsComponent: RendererComponent<\"tabs\"> = ({ children, node }) => {\n const { t } = useT(\"lattice\");\n const tabs = useMemo(() => getTabs(node), [node]);\n const firstValue = tabs[0]?.value ?? \"\";\n const queryKey = node.props.queryKey;\n const orientation = node.props.orientation;\n const isVertical = orientation === \"vertical\";\n const serverActiveValue = node.props.activeValue;\n const defaultValue = node.props.defaultValue ?? firstValue;\n const tablistRef = useRef<HTMLDivElement>(null);\n const [activeValue, setActiveTabValue] = useState(\n () => serverActiveValue || (queryValue(queryKey, tabs) ?? defaultValue) || firstValue,\n );\n\n function selectTab(tab: TabItem): void {\n if (tab.confirm?.required) {\n router.visit(queryUrl(queryKey, tab.value), {\n preserveScroll: true,\n });\n\n return;\n }\n\n setActiveTabValue(tab.value);\n replaceQueryValue(queryKey, tab.value);\n }\n\n function selectTabValue(value: string): void {\n const tab = tabs.find((item) => item.value === value);\n\n if (tab) {\n selectTab(tab);\n }\n }\n\n function onTablistKeyDown(event: KeyboardEvent<HTMLButtonElement>): void {\n const nextKey = isVertical ? \"ArrowDown\" : \"ArrowRight\";\n const prevKey = isVertical ? \"ArrowUp\" : \"ArrowLeft\";\n\n if (\n event.key !== nextKey &&\n event.key !== prevKey &&\n event.key !== \"Home\" &&\n event.key !== \"End\"\n ) {\n return;\n }\n\n const buttons = Array.from(\n tablistRef.current?.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]') ?? [],\n );\n\n if (buttons.length === 0) {\n return;\n }\n\n event.preventDefault();\n const current = buttons.indexOf(document.activeElement as HTMLButtonElement);\n\n let index: number;\n if (event.key === \"Home\") {\n index = 0;\n } else if (event.key === \"End\") {\n index = buttons.length - 1;\n } else {\n const delta = event.key === nextKey ? 1 : -1;\n const base = current < 0 ? 0 : current;\n index = (base + delta + buttons.length) % buttons.length;\n }\n\n buttons[index]?.focus();\n }\n\n return (\n <TabsContext.Provider value={{ activeValue, setActiveValue: selectTabValue }}>\n <div\n className={cn(\"gap-6\", isVertical ? \"flex\" : \"grid\")}\n data-lattice-tabs={node.key ?? node.id}\n >\n <div\n aria-label={t(\"a11y.tabs\", \"Tabs\")}\n aria-orientation={orientation}\n className={cn(\n \"gap-1 rounded-lt bg-lt-muted p-1\",\n isVertical ? \"flex flex-col\" : \"inline-flex w-fit max-w-full overflow-x-auto\",\n )}\n ref={tablistRef}\n role=\"tablist\"\n >\n {tabs.map((tab) => {\n const isActive = activeValue === tab.value;\n\n return (\n <button\n aria-controls={`${tab.value}-panel`}\n aria-selected={isActive}\n data-test={`tab-${tab.value}`}\n className={cn(\n \"whitespace-nowrap rounded-lt-sm px-3 py-1.5 text-sm font-medium transition-colors\",\n isActive\n ? \"bg-lt-bg text-lt-fg shadow-lt-xs\"\n : \"text-lt-muted-fg hover:bg-lt-bg/60 hover:text-lt-fg\",\n isVertical && \"text-left\",\n )}\n id={`${tab.value}-tab`}\n key={tab.value}\n onClick={() => selectTab(tab)}\n onKeyDown={onTablistKeyDown}\n role=\"tab\"\n tabIndex={isActive ? 0 : -1}\n type=\"button\"\n >\n {tab.label}\n </button>\n );\n })}\n </div>\n\n <div className={cn(\"min-w-0\", isVertical && \"flex-1\")}>{children}</div>\n </div>\n </TabsContext.Provider>\n );\n};\n\nconst TabComponent: RendererComponent<\"tab\"> = ({ children, node }) => {\n const { activeValue } = useTabsContext();\n const value = node.props.value;\n const isActive = activeValue === value;\n const [hasOpened, setHasOpened] = useState(isActive);\n\n useEffect(() => {\n if (isActive) {\n setHasOpened(true);\n }\n }, [isActive]);\n\n return (\n <section\n aria-labelledby={`${value}-tab`}\n className={cn(\"space-y-8\", !isActive && \"hidden\")}\n hidden={!isActive}\n id={`${value}-panel`}\n role=\"tabpanel\"\n tabIndex={0}\n >\n {hasOpened ? (children as ReactNode) : null}\n </section>\n );\n};\n\nexport default TabComponent;\n"],"mappings":";;;;;;AAaA,IAAM,cAAc,cAAuC,IAAI;AAE/D,SAAS,iBAAmC;CAC1C,MAAM,UAAU,WAAW,WAAW;CAEtC,IAAI,CAAC,SACH,OAAO;EACL,aAAa;EACb,sBAAsB,CAAC;CACzB;CAGF,OAAO;AACT;AAUA,SA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es from an untyped value, dropping
|
|
4
|
+
* anything that isn't an object carrying a string `type`.
|
|
5
|
+
*/
|
|
6
|
+
function toNodes(value) {
|
|
7
|
+
if (!Array.isArray(value)) return [];
|
|
8
|
+
return value.filter((node) => typeof node === "object" && node !== null && "type" in node && typeof node.type === "string");
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { toNodes };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","names":[],"sources":["../../resources/js/core/nodes.ts"],"sourcesContent":["import type { Node } from \"@lattice-php/lattice/core/types\";\n\n/**\n * Keep only the well-formed component nodes from an untyped value, dropping\n * anything that isn't an object carrying a string `type`.\n */\nexport function toNodes(value: unknown): Node[] {\n if (!Array.isArray(value)) {\n return [];\n }\n\n return value.filter(\n (node): node is Node =>\n typeof node === \"object\" && node !== null && \"type\" in node && typeof node.type === \"string\",\n );\n}\n"],"mappings":";;;;;AAMA,SAAgB,QAAQ,OAAwB;CAC9C,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,OAAO,CAAC;CAGV,OAAO,MAAM,QACV,SACC,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU,QAAQ,OAAO,KAAK,SAAS,QACxF;AACF"}
|
package/dist/core/renderer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useComponentRegistry } from "./registry-context.js";
|
|
2
1
|
import { useCollapsed } from "./collapsed-context.js";
|
|
2
|
+
import { useComponentRegistry } from "./registry-context.js";
|
|
3
3
|
import { Suspense } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region resources/js/core/renderer.tsx
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ComponentType as ReactComponentType, ReactNode } from 'react';
|
|
2
|
-
import { Node as WireNode, NodeType, Option, PageContainer as KnownPageContainer } from '../types/generated';
|
|
2
|
+
import { Node as WireNode, NodeType, Option, PageContainer as KnownPageContainer, ListenerPayload } from '../types/generated';
|
|
3
3
|
export type { KnownPageContainer, NodeType, WireNode };
|
|
4
4
|
/** Loose props bag for nodes whose `type` is not a generated built-in. */
|
|
5
5
|
export type NodeProps = Record<string, unknown>;
|
|
6
6
|
export type CommonNodeProps = {
|
|
7
|
+
dataBindings?: Record<string, string> | null;
|
|
7
8
|
hideWhenCollapsed?: boolean | null;
|
|
8
9
|
};
|
|
9
10
|
/** A `{ label, value }` pair used by the choice, select and segmented controls. */
|
|
@@ -76,6 +77,7 @@ export type PagePayload = {
|
|
|
76
77
|
breadcrumbs: PageBreadcrumb[];
|
|
77
78
|
container: PageContainer;
|
|
78
79
|
layout: LayoutPayload | null;
|
|
80
|
+
listeners?: ListenerPayload[];
|
|
79
81
|
schema: Schema;
|
|
80
82
|
title: string | null;
|
|
81
83
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createInertiaApp } from '@inertiajs/react';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { Registry } from './core/registry';
|
|
4
|
+
import { SpriteValue } from './icons/sprite';
|
|
5
|
+
import { CreateLayoutResolverOptions, PageModules } from './inertia';
|
|
6
|
+
type InertiaAppOptions = NonNullable<Parameters<typeof createInertiaApp>[0]>;
|
|
7
|
+
export type CreateLatticeAppOptions = Omit<InertiaAppOptions, "resolve" | "layout" | "setup" | "withApp" | "pages"> & {
|
|
8
|
+
registry?: Registry;
|
|
9
|
+
sprite?: SpriteValue;
|
|
10
|
+
/** Normal Inertia page modules, e.g. `import.meta.glob('./pages/**\/*.tsx')`. */
|
|
11
|
+
pages?: PageModules;
|
|
12
|
+
defaultLayout?: CreateLayoutResolverOptions["defaultLayout"];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Bootstrap an Inertia app with the Lattice shell: the page/layout resolvers
|
|
16
|
+
* (server-driven Lattice pages and normal Inertia pages alike), the Provider —
|
|
17
|
+
* registry, sprite, flash toasts via Lattice's own Toaster — and theme
|
|
18
|
+
* initialization. Forwards any other createInertiaApp option.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createLatticeApp({ registry, sprite, pages, defaultLayout, strictMode, ...inertiaOptions }?: CreateLatticeAppOptions): Promise<void | ((page: import('@inertiajs/core').Page<import('@inertiajs/core').PageProps>, renderToString: (element: ReactElement) => string) => Promise<import('@inertiajs/core').InertiaAppSSRResponse>)>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { initializeTheme } from "./appearance/index.js";
|
|
2
|
+
import { createLayoutResolver, createPageResolver } from "./inertia.js";
|
|
3
|
+
import { Provider } from "./provider.js";
|
|
4
|
+
import { createInertiaApp } from "@inertiajs/react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region resources/js/create-app.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Bootstrap an Inertia app with the Lattice shell: the page/layout resolvers
|
|
9
|
+
* (server-driven Lattice pages and normal Inertia pages alike), the Provider —
|
|
10
|
+
* registry, sprite, flash toasts via Lattice's own Toaster — and theme
|
|
11
|
+
* initialization. Forwards any other createInertiaApp option.
|
|
12
|
+
*/
|
|
13
|
+
function createLatticeApp({ registry, sprite, pages = {}, defaultLayout, strictMode = true, ...inertiaOptions } = {}) {
|
|
14
|
+
const app = createInertiaApp({
|
|
15
|
+
...inertiaOptions,
|
|
16
|
+
strictMode,
|
|
17
|
+
resolve: createPageResolver(pages),
|
|
18
|
+
layout: createLayoutResolver({ defaultLayout }),
|
|
19
|
+
withApp: (node) => /* @__PURE__ */ jsx(Provider, {
|
|
20
|
+
registry,
|
|
21
|
+
sprite,
|
|
22
|
+
children: node
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
initializeTheme();
|
|
26
|
+
return app;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createLatticeApp };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=create-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.js","names":[],"sources":["../resources/js/create-app.tsx"],"sourcesContent":["import { createInertiaApp } from \"@inertiajs/react\";\nimport type { ReactElement } from \"react\";\nimport { initializeTheme } from \"./appearance\";\nimport type { Registry } from \"./core/registry\";\nimport type { SpriteValue } from \"./icons/sprite\";\nimport {\n createLayoutResolver,\n createPageResolver,\n type CreateLayoutResolverOptions,\n type PageModules,\n} from \"./inertia\";\nimport { Provider } from \"./provider\";\n\ntype InertiaAppOptions = NonNullable<Parameters<typeof createInertiaApp>[0]>;\n\nexport type CreateLatticeAppOptions = Omit<\n InertiaAppOptions,\n \"resolve\" | \"layout\" | \"setup\" | \"withApp\" | \"pages\"\n> & {\n registry?: Registry;\n sprite?: SpriteValue;\n /** Normal Inertia page modules, e.g. `import.meta.glob('./pages/**\\/*.tsx')`. */\n pages?: PageModules;\n defaultLayout?: CreateLayoutResolverOptions[\"defaultLayout\"];\n};\n\n/**\n * Bootstrap an Inertia app with the Lattice shell: the page/layout resolvers\n * (server-driven Lattice pages and normal Inertia pages alike), the Provider —\n * registry, sprite, flash toasts via Lattice's own Toaster — and theme\n * initialization. Forwards any other createInertiaApp option.\n */\nexport function createLatticeApp({\n registry,\n sprite,\n pages = {},\n defaultLayout,\n strictMode = true,\n ...inertiaOptions\n}: CreateLatticeAppOptions = {}) {\n const app = createInertiaApp({\n ...inertiaOptions,\n strictMode,\n resolve: createPageResolver(pages),\n layout: createLayoutResolver({ defaultLayout }),\n withApp: (node: ReactElement): ReactElement => (\n <Provider registry={registry} sprite={sprite}>\n {node}\n </Provider>\n ),\n });\n\n initializeTheme();\n\n return app;\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,SAAgB,iBAAiB,EAC/B,UACA,QACA,QAAQ,CAAC,GACT,eACA,aAAa,MACb,GAAG,mBACwB,CAAC,GAAG;CAC/B,MAAM,MAAM,iBAAiB;EAC3B,GAAG;EACH;EACA,SAAS,mBAAmB,KAAK;EACjC,QAAQ,qBAAqB,EAAE,cAAc,CAAC;EAC9C,UAAU,SACR,oBAAC,UAAD;GAAoB;GAAkB;aACnC;EACO,CAAA;CAEd,CAAC;CAED,gBAAgB;CAEhB,OAAO;AACT"}
|
package/dist/effects/registry.js
CHANGED
|
@@ -37,7 +37,8 @@ var builtinEffectHandlers = {
|
|
|
37
37
|
reloadComponent: bridge(LATTICE_EVENT.reloadComponent),
|
|
38
38
|
openModal: bridge(LATTICE_EVENT.openModal),
|
|
39
39
|
closeModal: bridge(LATTICE_EVENT.closeModal),
|
|
40
|
-
resetForm: bridge(LATTICE_EVENT.resetForm)
|
|
40
|
+
resetForm: bridge(LATTICE_EVENT.resetForm),
|
|
41
|
+
toggleSidebar: bridge(LATTICE_EVENT.toggleSidebar)
|
|
41
42
|
};
|
|
42
43
|
function mergeEffectHandlers(...registries) {
|
|
43
44
|
return registries.reduce((merged, registry) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":[],"sources":["../../resources/js/effects/registry.ts"],"sourcesContent":["import { router } from \"@inertiajs/react\";\nimport type { ResolveProps } from \"@lattice-php/lattice/core/types\";\nimport type { Effect } from \"@lattice-php/lattice/types/generated\";\nimport { LATTICE_EVENT } from \"@lattice-php/lattice/events/event-names\";\nimport { setLocale } from \"@lattice-php/lattice/i18n/locale\";\n\n/**\n * Augmentable map of effect `type` → payload (the effect's fields minus `type`).\n * Consumer apps extend it via `declare module \"@lattice-php/lattice\"` so their\n * custom effects type their handler's payload; built-ins resolve through the\n * generated `Effect` union.\n */\nexport interface EffectProps {}\n\n// The generated built-in effect payloads, keyed by `type` (the discriminant stripped).\ntype EffectPayloads = { [TEffect in Effect as TEffect[\"type\"]]: Omit<TEffect, \"type\"> };\n\ntype EffectPayloadOf<TType extends string> = ResolveProps<\n EffectProps,\n EffectPayloads,\n TType,\n Record<string, unknown>\n>;\n\n/**\n * Resolves an effect `type` to its full shape — `{ type, ...payload }` — the way\n * `Node<T>` pairs a type with its props, so built-ins and consumer effects alike\n * always carry `type`. An unknown type falls back to the loose `Effect` union.\n */\nexport type EffectOf<TType extends string> = string extends TType\n ? Effect\n : { type: TType } & EffectPayloadOf<TType>;\n\nexport type EffectHandler<TType extends string = string> = (effect: EffectOf<TType>) => void;\n\nexport type EffectHandlerRegistry = Record<string, EffectHandler>;\n\n/**\n * Registers a typed effect handler, erasing the type parameter for the registry.\n * Mirrors `eagerComponent`/`columnCell`: author against `EffectHandler<\"my.type\">`\n * for a typed payload, register through this.\n */\nexport function effectHandler<TType extends string>(\n _type: TType,\n fn: EffectHandler<TType>,\n): EffectHandler {\n return fn as unknown as EffectHandler;\n}\n\nfunction triggerDownload(url: string): void {\n const link = document.createElement(\"a\");\n link.href = url;\n link.rel = \"noopener\";\n document.body.appendChild(link);\n link.click();\n link.remove();\n}\n\n/** Re-broadcast an effect as its `lattice:*` DOM event for feature components. */\nfunction bridge(event: string): EffectHandler {\n return (effect) => window.dispatchEvent(new CustomEvent(event, { detail: effect }));\n}\n\n/**\n * Built-in effect handlers. Imperative effects act directly; the rest bridge to\n * the `lattice:*` DOM events that toast/callout/modal/fragment/form subscribe to\n * — preserving today's behavior exactly.\n */\nexport const builtinEffectHandlers: EffectHandlerRegistry = {\n reloadPage: () => router.reload(),\n redirect: effectHandler(\"redirect\", (effect) => router.visit(effect.url)),\n download: effectHandler(\"download\", (effect) => triggerDownload(effect.url)),\n localeChange: effectHandler(\"localeChange\", (effect) => setLocale(effect.locale)),\n toast: bridge(LATTICE_EVENT.toast),\n callout: bridge(LATTICE_EVENT.callout),\n reloadComponent: bridge(LATTICE_EVENT.reloadComponent),\n openModal: bridge(LATTICE_EVENT.openModal),\n closeModal: bridge(LATTICE_EVENT.closeModal),\n resetForm: bridge(LATTICE_EVENT.resetForm),\n};\n\nexport function mergeEffectHandlers(\n ...registries: Array<EffectHandlerRegistry | undefined>\n): EffectHandlerRegistry {\n return registries.reduce<EffectHandlerRegistry>(\n (merged, registry) => ({ ...merged, ...registry }),\n {},\n );\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAgB,cACd,OACA,IACe;CACf,OAAO;AACT;AAEA,SAAS,gBAAgB,KAAmB;CAC1C,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,OAAO;CACZ,KAAK,MAAM;CACX,SAAS,KAAK,YAAY,IAAI;CAC9B,KAAK,MAAM;CACX,KAAK,OAAO;AACd;;AAGA,SAAS,OAAO,OAA8B;CAC5C,QAAQ,WAAW,OAAO,cAAc,IAAI,YAAY,OAAO,EAAE,QAAQ,OAAO,CAAC,CAAC;AACpF;;;;;;AAOA,IAAa,wBAA+C;CAC1D,kBAAkB,OAAO,OAAO;CAChC,UAAU,cAAc,aAAa,WAAW,OAAO,MAAM,OAAO,GAAG,CAAC;CACxE,UAAU,cAAc,aAAa,WAAW,gBAAgB,OAAO,GAAG,CAAC;CAC3E,cAAc,cAAc,iBAAiB,WAAW,UAAU,OAAO,MAAM,CAAC;CAChF,OAAO,OAAO,cAAc,KAAK;CACjC,SAAS,OAAO,cAAc,OAAO;CACrC,iBAAiB,OAAO,cAAc,eAAe;CACrD,WAAW,OAAO,cAAc,SAAS;CACzC,YAAY,OAAO,cAAc,UAAU;CAC3C,WAAW,OAAO,cAAc,SAAS;
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../resources/js/effects/registry.ts"],"sourcesContent":["import { router } from \"@inertiajs/react\";\nimport type { ResolveProps } from \"@lattice-php/lattice/core/types\";\nimport type { Effect } from \"@lattice-php/lattice/types/generated\";\nimport { LATTICE_EVENT } from \"@lattice-php/lattice/events/event-names\";\nimport { setLocale } from \"@lattice-php/lattice/i18n/locale\";\n\n/**\n * Augmentable map of effect `type` → payload (the effect's fields minus `type`).\n * Consumer apps extend it via `declare module \"@lattice-php/lattice\"` so their\n * custom effects type their handler's payload; built-ins resolve through the\n * generated `Effect` union.\n */\nexport interface EffectProps {}\n\n// The generated built-in effect payloads, keyed by `type` (the discriminant stripped).\ntype EffectPayloads = { [TEffect in Effect as TEffect[\"type\"]]: Omit<TEffect, \"type\"> };\n\ntype EffectPayloadOf<TType extends string> = ResolveProps<\n EffectProps,\n EffectPayloads,\n TType,\n Record<string, unknown>\n>;\n\n/**\n * Resolves an effect `type` to its full shape — `{ type, ...payload }` — the way\n * `Node<T>` pairs a type with its props, so built-ins and consumer effects alike\n * always carry `type`. An unknown type falls back to the loose `Effect` union.\n */\nexport type EffectOf<TType extends string> = string extends TType\n ? Effect\n : { type: TType } & EffectPayloadOf<TType>;\n\nexport type EffectHandler<TType extends string = string> = (effect: EffectOf<TType>) => void;\n\nexport type EffectHandlerRegistry = Record<string, EffectHandler>;\n\n/**\n * Registers a typed effect handler, erasing the type parameter for the registry.\n * Mirrors `eagerComponent`/`columnCell`: author against `EffectHandler<\"my.type\">`\n * for a typed payload, register through this.\n */\nexport function effectHandler<TType extends string>(\n _type: TType,\n fn: EffectHandler<TType>,\n): EffectHandler {\n return fn as unknown as EffectHandler;\n}\n\nfunction triggerDownload(url: string): void {\n const link = document.createElement(\"a\");\n link.href = url;\n link.rel = \"noopener\";\n document.body.appendChild(link);\n link.click();\n link.remove();\n}\n\n/** Re-broadcast an effect as its `lattice:*` DOM event for feature components. */\nfunction bridge(event: string): EffectHandler {\n return (effect) => window.dispatchEvent(new CustomEvent(event, { detail: effect }));\n}\n\n/**\n * Built-in effect handlers. Imperative effects act directly; the rest bridge to\n * the `lattice:*` DOM events that toast/callout/modal/fragment/form subscribe to\n * — preserving today's behavior exactly.\n */\nexport const builtinEffectHandlers: EffectHandlerRegistry = {\n reloadPage: () => router.reload(),\n redirect: effectHandler(\"redirect\", (effect) => router.visit(effect.url)),\n download: effectHandler(\"download\", (effect) => triggerDownload(effect.url)),\n localeChange: effectHandler(\"localeChange\", (effect) => setLocale(effect.locale)),\n toast: bridge(LATTICE_EVENT.toast),\n callout: bridge(LATTICE_EVENT.callout),\n reloadComponent: bridge(LATTICE_EVENT.reloadComponent),\n openModal: bridge(LATTICE_EVENT.openModal),\n closeModal: bridge(LATTICE_EVENT.closeModal),\n resetForm: bridge(LATTICE_EVENT.resetForm),\n toggleSidebar: bridge(LATTICE_EVENT.toggleSidebar),\n};\n\nexport function mergeEffectHandlers(\n ...registries: Array<EffectHandlerRegistry | undefined>\n): EffectHandlerRegistry {\n return registries.reduce<EffectHandlerRegistry>(\n (merged, registry) => ({ ...merged, ...registry }),\n {},\n );\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAgB,cACd,OACA,IACe;CACf,OAAO;AACT;AAEA,SAAS,gBAAgB,KAAmB;CAC1C,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,OAAO;CACZ,KAAK,MAAM;CACX,SAAS,KAAK,YAAY,IAAI;CAC9B,KAAK,MAAM;CACX,KAAK,OAAO;AACd;;AAGA,SAAS,OAAO,OAA8B;CAC5C,QAAQ,WAAW,OAAO,cAAc,IAAI,YAAY,OAAO,EAAE,QAAQ,OAAO,CAAC,CAAC;AACpF;;;;;;AAOA,IAAa,wBAA+C;CAC1D,kBAAkB,OAAO,OAAO;CAChC,UAAU,cAAc,aAAa,WAAW,OAAO,MAAM,OAAO,GAAG,CAAC;CACxE,UAAU,cAAc,aAAa,WAAW,gBAAgB,OAAO,GAAG,CAAC;CAC3E,cAAc,cAAc,iBAAiB,WAAW,UAAU,OAAO,MAAM,CAAC;CAChF,OAAO,OAAO,cAAc,KAAK;CACjC,SAAS,OAAO,cAAc,OAAO;CACrC,iBAAiB,OAAO,cAAc,eAAe;CACrD,WAAW,OAAO,cAAc,SAAS;CACzC,YAAY,OAAO,cAAc,UAAU;CAC3C,WAAW,OAAO,cAAc,SAAS;CACzC,eAAe,OAAO,cAAc,aAAa;AACnD;AAEA,SAAgB,oBACd,GAAG,YACoB;CACvB,OAAO,WAAW,QACf,QAAQ,cAAc;EAAE,GAAG;EAAQ,GAAG;CAAS,IAChD,CAAC,CACH;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { useEffectHandlerRegistry } from "../core/registry-context.js";
|
|
1
2
|
import { builtinEffectHandlers, mergeEffectHandlers } from "./registry.js";
|
|
2
3
|
import { dispatchEffects } from "./dispatch.js";
|
|
3
|
-
import { useEffectHandlerRegistry } from "../core/registry-context.js";
|
|
4
4
|
import { useCallback, useMemo } from "react";
|
|
5
5
|
//#region resources/js/effects/use-effect-dispatcher.ts
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getActionEffects } from "./dispatch.js";
|
|
2
2
|
import { useEffectDispatcher } from "./use-effect-dispatcher.js";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
3
|
import { router } from "@inertiajs/react";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
5
|
//#region resources/js/effects/use-flash-effects.ts
|
|
6
6
|
/**
|
|
7
7
|
* Drains the `latticeEffects` flash bag (server `Effects::flash(...)`) on each
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Single source of truth for the `lattice:*` DOM events the runtime dispatches
|
|
3
|
-
* and listens for.
|
|
4
|
-
*
|
|
3
|
+
* and listens for. The built-in effect handlers in effects/registry.ts bridge
|
|
4
|
+
* effects to these events; the rest are framework events with no PHP counterpart.
|
|
5
5
|
*/
|
|
6
6
|
export declare const LATTICE_EVENT: {
|
|
7
7
|
readonly callout: "lattice:callout";
|
|
@@ -13,6 +13,7 @@ export declare const LATTICE_EVENT: {
|
|
|
13
13
|
readonly openModal: "lattice:open-modal";
|
|
14
14
|
readonly closeModal: "lattice:close-modal";
|
|
15
15
|
readonly resetForm: "lattice:reset-form";
|
|
16
|
+
readonly toggleSidebar: "lattice:toggle-sidebar";
|
|
16
17
|
readonly appearanceChange: "lattice:appearance-change";
|
|
17
18
|
readonly localeChange: "lattice:locale-change";
|
|
18
19
|
readonly actionError: "lattice:action-error";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//#region resources/js/events/event-names.ts
|
|
2
2
|
/**
|
|
3
3
|
* Single source of truth for the `lattice:*` DOM events the runtime dispatches
|
|
4
|
-
* and listens for.
|
|
5
|
-
*
|
|
4
|
+
* and listens for. The built-in effect handlers in effects/registry.ts bridge
|
|
5
|
+
* effects to these events; the rest are framework events with no PHP counterpart.
|
|
6
6
|
*/
|
|
7
7
|
var LATTICE_EVENT = {
|
|
8
8
|
callout: "lattice:callout",
|
|
@@ -14,6 +14,7 @@ var LATTICE_EVENT = {
|
|
|
14
14
|
openModal: "lattice:open-modal",
|
|
15
15
|
closeModal: "lattice:close-modal",
|
|
16
16
|
resetForm: "lattice:reset-form",
|
|
17
|
+
toggleSidebar: "lattice:toggle-sidebar",
|
|
17
18
|
appearanceChange: "lattice:appearance-change",
|
|
18
19
|
localeChange: "lattice:locale-change",
|
|
19
20
|
actionError: "lattice:action-error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-names.js","names":[],"sources":["../../resources/js/events/event-names.ts"],"sourcesContent":["/**\n * Single source of truth for the `lattice:*` DOM events the runtime dispatches\n * and listens for.
|
|
1
|
+
{"version":3,"file":"event-names.js","names":[],"sources":["../../resources/js/events/event-names.ts"],"sourcesContent":["/**\n * Single source of truth for the `lattice:*` DOM events the runtime dispatches\n * and listens for. The built-in effect handlers in effects/registry.ts bridge\n * effects to these events; the rest are framework events with no PHP counterpart.\n */\nexport const LATTICE_EVENT = {\n callout: \"lattice:callout\",\n toast: \"lattice:toast\",\n reloadComponent: \"lattice:reload-component\",\n reloadPage: \"lattice:reload-page\",\n redirect: \"lattice:redirect\",\n download: \"lattice:download\",\n openModal: \"lattice:open-modal\",\n closeModal: \"lattice:close-modal\",\n resetForm: \"lattice:reset-form\",\n toggleSidebar: \"lattice:toggle-sidebar\",\n appearanceChange: \"lattice:appearance-change\",\n localeChange: \"lattice:locale-change\",\n actionError: \"lattice:action-error\",\n} as const;\n\nexport type ReloadComponentEvent = CustomEvent<{\n component?: string;\n type?: string;\n}>;\n"],"mappings":";;;;;;AAKA,IAAa,gBAAgB;CAC3B,SAAS;CACT,OAAO;CACP,iBAAiB;CACjB,YAAY;CACZ,UAAU;CACV,UAAU;CACV,WAAW;CACX,YAAY;CACZ,WAAW;CACX,eAAe;CACf,kBAAkB;CAClB,cAAc;CACd,aAAa;AACf"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Affix } from '../../../types/generated';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a single-line control in a prefix/suffix input group. The control is a
|
|
5
|
+
* render prop receiving the class names that square the corners adjacent to an
|
|
6
|
+
* affix; with no affixes the control renders untouched.
|
|
7
|
+
*
|
|
8
|
+
* The focus ring lives on the group, not the bare input, so it surrounds the
|
|
9
|
+
* whole control — affixes included — instead of being clipped by the opaque
|
|
10
|
+
* affix segments. The control itself stays the focus target; only its own ring
|
|
11
|
+
* is suppressed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function AffixGroup({ prefix, suffix, children, }: {
|
|
14
|
+
prefix?: Affix | null;
|
|
15
|
+
suffix?: Affix | null;
|
|
16
|
+
children: (controlClassName: string) => ReactNode;
|
|
17
|
+
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { cn } from "../../../lib/utils.js";
|
|
2
|
+
import { IconRenderer } from "../../../icons/icon-renderer.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region resources/js/form/components/base/affix-group.tsx
|
|
5
|
+
function AffixSegment({ affix, side }) {
|
|
6
|
+
return /* @__PURE__ */ jsx("span", {
|
|
7
|
+
"data-slot": `affix-${side}`,
|
|
8
|
+
className: cn("inline-flex h-lt-control-md shrink-0 items-center border border-lt-input bg-lt-muted px-3 text-base whitespace-nowrap text-lt-muted-fg", "group-has-[:focus-visible]:border-lt-ring", side === "start" ? "rounded-l-lt-sm border-r-0" : "rounded-r-lt-sm border-l-0"),
|
|
9
|
+
children: affix.icon ? /* @__PURE__ */ jsx(IconRenderer, {
|
|
10
|
+
className: "size-lt-icon-md",
|
|
11
|
+
icon: affix.icon
|
|
12
|
+
}) : affix.text
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a single-line control in a prefix/suffix input group. The control is a
|
|
17
|
+
* render prop receiving the class names that square the corners adjacent to an
|
|
18
|
+
* affix; with no affixes the control renders untouched.
|
|
19
|
+
*
|
|
20
|
+
* The focus ring lives on the group, not the bare input, so it surrounds the
|
|
21
|
+
* whole control — affixes included — instead of being clipped by the opaque
|
|
22
|
+
* affix segments. The control itself stays the focus target; only its own ring
|
|
23
|
+
* is suppressed.
|
|
24
|
+
*/
|
|
25
|
+
function AffixGroup({ prefix, suffix, children }) {
|
|
26
|
+
if (!prefix && !suffix) return children("");
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
className: "group flex w-full rounded-lt-sm transition-[color,box-shadow] has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-lt-ring/50",
|
|
29
|
+
"data-slot": "affix-group",
|
|
30
|
+
children: [
|
|
31
|
+
prefix ? /* @__PURE__ */ jsx(AffixSegment, {
|
|
32
|
+
affix: prefix,
|
|
33
|
+
side: "start"
|
|
34
|
+
}) : null,
|
|
35
|
+
/* @__PURE__ */ jsx("div", {
|
|
36
|
+
className: "min-w-0 flex-1",
|
|
37
|
+
children: children(cn("focus-visible:ring-0", prefix && "rounded-l-none", suffix && "rounded-r-none"))
|
|
38
|
+
}),
|
|
39
|
+
suffix ? /* @__PURE__ */ jsx(AffixSegment, {
|
|
40
|
+
affix: suffix,
|
|
41
|
+
side: "end"
|
|
42
|
+
}) : null
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { AffixGroup };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=affix-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affix-group.js","names":[],"sources":["../../../../resources/js/form/components/base/affix-group.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { Affix } from \"@lattice-php/lattice/types/generated\";\nimport { IconRenderer } from \"@lattice-php/lattice/icons\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\nfunction AffixSegment({ affix, side }: { affix: Affix; side: \"start\" | \"end\" }) {\n return (\n <span\n data-slot={`affix-${side}`}\n className={cn(\n \"inline-flex h-lt-control-md shrink-0 items-center border border-lt-input bg-lt-muted px-3 text-base whitespace-nowrap text-lt-muted-fg\",\n \"group-has-[:focus-visible]:border-lt-ring\",\n side === \"start\" ? \"rounded-l-lt-sm border-r-0\" : \"rounded-r-lt-sm border-l-0\",\n )}\n >\n {affix.icon ? <IconRenderer className=\"size-lt-icon-md\" icon={affix.icon} /> : affix.text}\n </span>\n );\n}\n\n/**\n * Wraps a single-line control in a prefix/suffix input group. The control is a\n * render prop receiving the class names that square the corners adjacent to an\n * affix; with no affixes the control renders untouched.\n *\n * The focus ring lives on the group, not the bare input, so it surrounds the\n * whole control — affixes included — instead of being clipped by the opaque\n * affix segments. The control itself stays the focus target; only its own ring\n * is suppressed.\n */\nexport function AffixGroup({\n prefix,\n suffix,\n children,\n}: {\n prefix?: Affix | null;\n suffix?: Affix | null;\n children: (controlClassName: string) => ReactNode;\n}) {\n if (!prefix && !suffix) {\n return children(\"\");\n }\n\n return (\n <div\n className=\"group flex w-full rounded-lt-sm transition-[color,box-shadow] has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-lt-ring/50\"\n data-slot=\"affix-group\"\n >\n {prefix ? <AffixSegment affix={prefix} side=\"start\" /> : null}\n <div className=\"min-w-0 flex-1\">\n {children(\n cn(\"focus-visible:ring-0\", prefix && \"rounded-l-none\", suffix && \"rounded-r-none\"),\n )}\n </div>\n {suffix ? <AffixSegment affix={suffix} side=\"end\" /> : null}\n </div>\n );\n}\n"],"mappings":";;;;AAKA,SAAS,aAAa,EAAE,OAAO,QAAiD;CAC9E,OACE,oBAAC,QAAD;EACE,aAAW,SAAS;EACpB,WAAW,GACT,0IACA,6CACA,SAAS,UAAU,+BAA+B,4BACpD;YAEC,MAAM,OAAO,oBAAC,cAAD;GAAc,WAAU;GAAkB,MAAM,MAAM;EAAO,CAAA,IAAI,MAAM;CACjF,CAAA;AAEV;;;;;;;;;;;AAYA,SAAgB,WAAW,EACzB,QACA,QACA,YAKC;CACD,IAAI,CAAC,UAAU,CAAC,QACd,OAAO,SAAS,EAAE;CAGpB,OACE,qBAAC,OAAD;EACE,WAAU;EACV,aAAU;YAFZ;GAIG,SAAS,oBAAC,cAAD;IAAc,OAAO;IAAQ,MAAK;GAAS,CAAA,IAAI;GACzD,oBAAC,OAAD;IAAK,WAAU;cACZ,SACC,GAAG,wBAAwB,UAAU,kBAAkB,UAAU,gBAAgB,CACnF;GACG,CAAA;GACJ,SAAS,oBAAC,cAAD;IAAc,OAAO;IAAQ,MAAK;GAAO,CAAA,IAAI;EACpD;;AAET"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OTPInput } from 'input-otp';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
export type InputOTPProps = Omit<ComponentProps<typeof OTPInput>, "children" | "maxLength" | "render"> & {
|
|
4
|
+
length: number;
|
|
5
|
+
};
|
|
6
|
+
/** A segmented one-time-code input styled to match Lattice's control surfaces. */
|
|
7
|
+
export declare function InputOTP({ length, containerClassName, pattern, ...props }: InputOTPProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cn } from "../../../lib/utils.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { OTPInput, REGEXP_ONLY_DIGITS } from "input-otp";
|
|
4
|
+
//#region resources/js/form/components/base/input-otp.tsx
|
|
5
|
+
function Slot({ char, hasFakeCaret, isActive }) {
|
|
6
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
7
|
+
className: cn("relative flex h-lt-control-md w-10 items-center justify-center border-y border-r border-lt-input text-base shadow-lt-xs transition-all first:rounded-l-lt-sm first:border-l last:rounded-r-lt-sm", isActive && "z-10 border-lt-ring ring-lt-ring/50 ring-[3px]"),
|
|
8
|
+
children: [char, hasFakeCaret ? /* @__PURE__ */ jsx("div", {
|
|
9
|
+
className: "pointer-events-none absolute inset-0 flex items-center justify-center",
|
|
10
|
+
children: /* @__PURE__ */ jsx("div", { className: "bg-lt-fg h-5 w-px animate-pulse" })
|
|
11
|
+
}) : null]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** A segmented one-time-code input styled to match Lattice's control surfaces. */
|
|
15
|
+
function InputOTP({ length, containerClassName, pattern = REGEXP_ONLY_DIGITS, ...props }) {
|
|
16
|
+
return /* @__PURE__ */ jsx(OTPInput, {
|
|
17
|
+
maxLength: length,
|
|
18
|
+
pattern,
|
|
19
|
+
containerClassName: cn("flex items-center gap-2 has-[:disabled]:opacity-50", containerClassName),
|
|
20
|
+
render: ({ slots }) => /* @__PURE__ */ jsx("div", {
|
|
21
|
+
className: "flex items-center",
|
|
22
|
+
children: slots.map((slot, index) => /* @__PURE__ */ jsx(Slot, { ...slot }, index))
|
|
23
|
+
}),
|
|
24
|
+
...props
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { InputOTP };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=input-otp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-otp.js","names":[],"sources":["../../../../resources/js/form/components/base/input-otp.tsx"],"sourcesContent":["import { OTPInput, REGEXP_ONLY_DIGITS, type SlotProps } from \"input-otp\";\nimport type { ComponentProps } from \"react\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\n\nfunction Slot({ char, hasFakeCaret, isActive }: SlotProps) {\n return (\n <div\n className={cn(\n \"relative flex h-lt-control-md w-10 items-center justify-center border-y border-r border-lt-input text-base shadow-lt-xs transition-all first:rounded-l-lt-sm first:border-l last:rounded-r-lt-sm\",\n isActive && \"z-10 border-lt-ring ring-lt-ring/50 ring-[3px]\",\n )}\n >\n {char}\n {hasFakeCaret ? (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n <div className=\"bg-lt-fg h-5 w-px animate-pulse\" />\n </div>\n ) : null}\n </div>\n );\n}\n\nexport type InputOTPProps = Omit<\n ComponentProps<typeof OTPInput>,\n \"children\" | \"maxLength\" | \"render\"\n> & {\n length: number;\n};\n\n/** A segmented one-time-code input styled to match Lattice's control surfaces. */\nexport function InputOTP({\n length,\n containerClassName,\n pattern = REGEXP_ONLY_DIGITS,\n ...props\n}: InputOTPProps) {\n return (\n <OTPInput\n maxLength={length}\n pattern={pattern}\n containerClassName={cn(\n \"flex items-center gap-2 has-[:disabled]:opacity-50\",\n containerClassName,\n )}\n render={({ slots }) => (\n <div className=\"flex items-center\">\n {slots.map((slot, index) => (\n <Slot key={index} {...slot} />\n ))}\n </div>\n )}\n {...props}\n />\n );\n}\n"],"mappings":";;;;AAIA,SAAS,KAAK,EAAE,MAAM,cAAc,YAAuB;CACzD,OACE,qBAAC,OAAD;EACE,WAAW,GACT,oMACA,YAAY,gDACd;YAJF,CAMG,MACA,eACC,oBAAC,OAAD;GAAK,WAAU;aACb,oBAAC,OAAD,EAAK,WAAU,kCAAmC,CAAA;EAC/C,CAAA,IACH,IACD;;AAET;;AAUA,SAAgB,SAAS,EACvB,QACA,oBACA,UAAU,oBACV,GAAG,SACa;CAChB,OACE,oBAAC,UAAD;EACE,WAAW;EACF;EACT,oBAAoB,GAClB,sDACA,kBACF;EACA,SAAS,EAAE,YACT,oBAAC,OAAD;GAAK,WAAU;aACZ,MAAM,KAAK,MAAM,UAChB,oBAAC,MAAD,EAAkB,GAAI,KAAO,GAAlB,KAAkB,CAC9B;EACE,CAAA;EAEP,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -6,7 +6,7 @@ import * as LabelPrimitive from "@radix-ui/react-label";
|
|
|
6
6
|
function Label({ className, ...props }) {
|
|
7
7
|
return /* @__PURE__ */ jsx(LabelPrimitive.Root, {
|
|
8
8
|
"data-slot": "label",
|
|
9
|
-
className: cn("text-
|
|
9
|
+
className: cn("text-base leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className),
|
|
10
10
|
...props
|
|
11
11
|
});
|
|
12
12
|
}
|