@keboola/design 11.5.0 → 11.6.1
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/AGENTS.md +7 -6
- package/CHANGELOG.md +31 -0
- package/COMPONENT-API.md +5 -5
- package/dist/{AIKit-CNX6aiKm.js → AIKit-CQxVwyAk.js} +212 -38
- package/dist/AIKit-CQxVwyAk.js.map +1 -0
- package/dist/{Alert-Ba5b2YPq.js → Alert-C4Y9IwMI.js} +2 -2
- package/dist/{Alert-Ba5b2YPq.js.map → Alert-C4Y9IwMI.js.map} +1 -1
- package/dist/{Badge-D0pXdekt.js → Badge-o5jURtpB.js} +2 -2
- package/dist/{Badge-D0pXdekt.js.map → Badge-o5jURtpB.js.map} +1 -1
- package/dist/{BrandEditor-CSANsxUz.js → BrandEditor-CS9P4r2p.js} +5 -5
- package/dist/{BrandEditor-CSANsxUz.js.map → BrandEditor-CS9P4r2p.js.map} +1 -1
- package/dist/{Breadcrumb-g_xn_-Nf.js → Breadcrumb-D1id7YXd.js} +2 -2
- package/dist/{Breadcrumb-g_xn_-Nf.js.map → Breadcrumb-D1id7YXd.js.map} +1 -1
- package/dist/{Checkbox-CUIn2jap.js → Checkbox-Bqr6zXcW.js} +2 -2
- package/dist/{Checkbox-CUIn2jap.js.map → Checkbox-Bqr6zXcW.js.map} +1 -1
- package/dist/{Clipboard-BTW6C-b_.js → Clipboard-C2YBRfD8.js} +2 -2
- package/dist/{Clipboard-BTW6C-b_.js.map → Clipboard-C2YBRfD8.js.map} +1 -1
- package/dist/{ClipboardButton-CwZJdRaz.js → ClipboardButton-CrljClL1.js} +2 -2
- package/dist/{ClipboardButton-CwZJdRaz.js.map → ClipboardButton-CrljClL1.js.map} +1 -1
- package/dist/{CodeEditor-C9zy7PxK.js → CodeEditor-C9AS8Ch0.js} +4 -4
- package/dist/{CodeEditor-C9zy7PxK.js.map → CodeEditor-C9AS8Ch0.js.map} +1 -1
- package/dist/{ColorInput-BZV-u_94.js → ColorInput-Dg87lKcR.js} +2 -2
- package/dist/{ColorInput-BZV-u_94.js.map → ColorInput-Dg87lKcR.js.map} +1 -1
- package/dist/{Combobox-BfIfaVMA.js → Combobox-BfanUAqY.js} +3 -3
- package/dist/{Combobox-BfIfaVMA.js.map → Combobox-BfanUAqY.js.map} +1 -1
- package/dist/{Command-Bfa1kpbt.js → Command-CqxoI_De.js} +2 -2
- package/dist/{Command-Bfa1kpbt.js.map → Command-CqxoI_De.js.map} +1 -1
- package/dist/{CopyField-DpT0Ngz1.js → CopyField-Rx9HPTbJ.js} +2 -2
- package/dist/{CopyField-DpT0Ngz1.js.map → CopyField-Rx9HPTbJ.js.map} +1 -1
- package/dist/{DateInput-DiEd5uCL.js → DateInput-DpifECUQ.js} +2 -2
- package/dist/{DateInput-DiEd5uCL.js.map → DateInput-DpifECUQ.js.map} +1 -1
- package/dist/{DateRangeInput-DPfVYchl.js → DateRangeInput-9MIw7P6L.js} +2 -2
- package/dist/{DateRangeInput-DPfVYchl.js.map → DateRangeInput-9MIw7P6L.js.map} +1 -1
- package/dist/DiagramSource-C5_d8Gdj.js +11 -0
- package/dist/DiagramSource-C5_d8Gdj.js.map +1 -0
- package/dist/{FieldItem-B7XMmZSz.js → FieldItem-DtPTzNef.js} +3 -3
- package/dist/{FieldItem-B7XMmZSz.js.map → FieldItem-DtPTzNef.js.map} +1 -1
- package/dist/{FileUpload-ABThVZyg.js → FileUpload-DYQCTGjU.js} +3 -3
- package/dist/{FileUpload-ABThVZyg.js.map → FileUpload-DYQCTGjU.js.map} +1 -1
- package/dist/{Form-CsttTHn4.js → Form-DAaatlBk.js} +5 -5
- package/dist/{Form-CsttTHn4.js.map → Form-DAaatlBk.js.map} +1 -1
- package/dist/{FormGroup-DHvTFdno.js → FormGroup-Bl8JmnzJ.js} +3 -3
- package/dist/{FormGroup-DHvTFdno.js.map → FormGroup-Bl8JmnzJ.js.map} +1 -1
- package/dist/{FullScreenModal-BvPuYibe.js → FullScreenModal-CN9nAs72.js} +50 -2
- package/dist/FullScreenModal-CN9nAs72.js.map +1 -0
- package/dist/{Kbd-Cvvt91Q8.js → Kbd-D1Azcc4g.js} +2 -2
- package/dist/{Kbd-Cvvt91Q8.js.map → Kbd-D1Azcc4g.js.map} +1 -1
- package/dist/{MermaidDiagram-CXG5tC6J.js → MermaidDiagram-CujFxVzk.js} +4 -3
- package/dist/{MermaidDiagram-CXG5tC6J.js.map → MermaidDiagram-CujFxVzk.js.map} +1 -1
- package/dist/{MultiActionButtonGroup-DokHbPgM.js → MultiActionButtonGroup-CNNoBQbv.js} +2 -2
- package/dist/{MultiActionButtonGroup-DokHbPgM.js.map → MultiActionButtonGroup-CNNoBQbv.js.map} +1 -1
- package/dist/{PageToolbar-DExqEYGl.js → PageToolbar-BKVJiDAL.js} +2 -2
- package/dist/{PageToolbar-DExqEYGl.js.map → PageToolbar-BKVJiDAL.js.map} +1 -1
- package/dist/{RadioGroup-DXPbSj8P.js → RadioGroup-CUBsuP7r.js} +2 -2
- package/dist/{RadioGroup-DXPbSj8P.js.map → RadioGroup-CUBsuP7r.js.map} +1 -1
- package/dist/{Search-5uQAiNIP.js → Search-DVpJuzr9.js} +2 -2
- package/dist/{Search-5uQAiNIP.js.map → Search-DVpJuzr9.js.map} +1 -1
- package/dist/{SearchInput-D4UgAXJK.js → SearchInput-Q85p8Ews.js} +2 -2
- package/dist/{SearchInput-D4UgAXJK.js.map → SearchInput-Q85p8Ews.js.map} +1 -1
- package/dist/{SectionNav-OkKCjSA-.js → SectionNav-mpmSM3OC.js} +3 -3
- package/dist/{SectionNav-OkKCjSA-.js.map → SectionNav-mpmSM3OC.js.map} +1 -1
- package/dist/{Sidebar-D3cY1kha.js → Sidebar-CTWsHZhF.js} +2 -2
- package/dist/{Sidebar-D3cY1kha.js.map → Sidebar-CTWsHZhF.js.map} +1 -1
- package/dist/{Slider-CRf-bB4y.js → Slider-Bv0B6lI0.js} +2 -2
- package/dist/{Slider-CRf-bB4y.js.map → Slider-Bv0B6lI0.js.map} +1 -1
- package/dist/{TextInput-DH5SkbsE.js → TextInput-DiEMxVF6.js} +2 -2
- package/dist/{TextInput-DH5SkbsE.js.map → TextInput-DiEMxVF6.js.map} +1 -1
- package/dist/{ThemeProvider-2RMdVGxO.js → ThemeProvider-BI6JWBdJ.js} +2 -2
- package/dist/{ThemeProvider-2RMdVGxO.js.map → ThemeProvider-BI6JWBdJ.js.map} +1 -1
- package/dist/{ZoomableSvg-pooPb1Cu.js → ZoomableSvg-U_VH3QRO.js} +3 -3
- package/dist/{ZoomableSvg-pooPb1Cu.js.map → ZoomableSvg-U_VH3QRO.js.map} +1 -1
- package/dist/editors.js +2 -2
- package/dist/flint.js +3 -2
- package/dist/flint.js.map +1 -1
- package/dist/index.d.ts +358 -283
- package/dist/index.js +32 -32
- package/dist/internal/blocks/AIKit.js +2 -2
- package/dist/internal/blocks/BrandEditor.js +1 -1
- package/dist/internal/blocks/ClipboardButton.js +1 -1
- package/dist/internal/blocks/ColorInput.js +1 -1
- package/dist/internal/blocks/Command.js +1 -1
- package/dist/internal/blocks/CopyField.js +1 -1
- package/dist/internal/blocks/DateInput.js +1 -1
- package/dist/internal/blocks/DateRangeInput.js +1 -1
- package/dist/internal/blocks/ExportMenu.js +1 -1
- package/dist/internal/blocks/Form/connectors/MultiComboboxField.js +1 -1
- package/dist/internal/blocks/Form.js +1 -1
- package/dist/internal/blocks/FormGroup.js +1 -1
- package/dist/internal/blocks/MultiActionButtonGroup.js +1 -1
- package/dist/internal/blocks/MultiCombobox.js +1 -1
- package/dist/internal/blocks/PageToolbar.js +1 -1
- package/dist/internal/blocks/PasswordInput.js +1 -1
- package/dist/internal/blocks/SearchInput.js +1 -1
- package/dist/internal/blocks/SearchInputWithNavigation.js +2 -2
- package/dist/internal/blocks/SectionNav.js +1 -1
- package/dist/internal/blocks/TextInput.js +1 -1
- package/dist/internal/blocks/TimeInput.js +1 -1
- package/dist/internal/components/Alert.js +1 -1
- package/dist/internal/components/Avatar.js +1 -1
- package/dist/internal/components/Badge.js +1 -1
- package/dist/internal/components/Breadcrumb.js +1 -1
- package/dist/internal/components/Checkbox.js +1 -1
- package/dist/internal/components/Clipboard.js +1 -1
- package/dist/internal/components/CollapsiblePanel.js +1 -1
- package/dist/internal/components/Combobox.js +1 -1
- package/dist/internal/components/FileUpload.js +1 -1
- package/dist/internal/components/FullScreenModal.js +1 -1
- package/dist/internal/components/Kbd.js +1 -1
- package/dist/internal/components/Progress.js +3 -1
- package/dist/internal/components/Progress.js.map +1 -1
- package/dist/internal/components/RadioGroup.js +1 -1
- package/dist/internal/components/Search.js +1 -1
- package/dist/internal/components/Sidebar.js +1 -1
- package/dist/internal/components/Slider.js +1 -1
- package/dist/internal/components/ThemeProvider.js +1 -1
- package/dist/internal/components/Tooltip.js +1 -1
- package/dist/internal/components/Truncated.js +1 -1
- package/dist/internal/components/ZoomableSvg.js +1 -1
- package/dist/internal/utils.js +1 -1
- package/dist/markdown-editor.js +4 -4
- package/dist/mermaid.js +1 -1
- package/dist/rjsf.js +9 -9
- package/dist/styles.css +1 -1
- package/dist/{svgTransforms-C9njt92h.js → svgTransforms-CJAYPk7o.js} +2 -10
- package/dist/svgTransforms-CJAYPk7o.js.map +1 -0
- package/dist/testing.js +1 -1
- package/dist/{utils-DSvrhU8E.js → utils-DnkrFYqY.js} +3 -5
- package/dist/utils-DnkrFYqY.js.map +1 -0
- package/package.json +16 -16
- package/dist/AIKit-CNX6aiKm.js.map +0 -1
- package/dist/FullScreenModal-BvPuYibe.js.map +0 -1
- package/dist/svgTransforms-C9njt92h.js.map +0 -1
- package/dist/utils-DSvrhU8E.js.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
2
|
import { Button } from "./Button-DsRrU5F1.js";
|
|
3
|
-
import { TextInput } from "./TextInput-
|
|
3
|
+
import { TextInput } from "./TextInput-DiEMxVF6.js";
|
|
4
4
|
import { Switch } from "./Switch-B0WdGSjz.js";
|
|
5
5
|
import { Select } from "./Select-DV3Hak_l.js";
|
|
6
|
-
import { Checkbox } from "./Checkbox-
|
|
7
|
-
import { FieldItem, fieldContext, formContext, useFieldContext, useFormContext } from "./FieldItem-
|
|
6
|
+
import { Checkbox } from "./Checkbox-Bqr6zXcW.js";
|
|
7
|
+
import { FieldItem, fieldContext, formContext, useFieldContext, useFormContext } from "./FieldItem-DtPTzNef.js";
|
|
8
8
|
import { NumberInput } from "./internal/blocks/NumberInput.js";
|
|
9
9
|
import { Textarea } from "./internal/blocks/Textarea.js";
|
|
10
10
|
import { PasswordInput } from "./internal/blocks/PasswordInput.js";
|
|
11
11
|
import { OtpInput } from "./OtpInput-CbbymqYs.js";
|
|
12
|
-
import { Alert } from "./Alert-
|
|
12
|
+
import { Alert } from "./Alert-C4Y9IwMI.js";
|
|
13
13
|
import { jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createFormHook } from "@tanstack/react-form";
|
|
15
15
|
//#region src/blocks/Form/components/FormBody.tsx
|
|
@@ -308,4 +308,4 @@ const setSubmitError = (form, message) => {
|
|
|
308
308
|
//#endregion
|
|
309
309
|
export { setServerFieldErrors, setSubmitError, useAppForm, withForm };
|
|
310
310
|
|
|
311
|
-
//# sourceMappingURL=Form-
|
|
311
|
+
//# sourceMappingURL=Form-DAaatlBk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form-CsttTHn4.js","names":[],"sources":["../src/blocks/Form/components/FormBody.tsx","../src/blocks/Form/components/SubmitButton.tsx","../src/blocks/Form/components/SubmitErrorAlert.tsx","../src/blocks/Form/connectors/CheckboxField.tsx","../src/blocks/Form/connectors/NumberField.tsx","../src/blocks/Form/connectors/OtpInputField.tsx","../src/blocks/Form/connectors/PasswordField.tsx","../src/blocks/Form/connectors/SelectField.tsx","../src/blocks/Form/connectors/SwitchField.tsx","../src/blocks/Form/connectors/TextareaField.tsx","../src/blocks/Form/connectors/TextField.tsx","../src/blocks/Form/formHook.ts","../src/blocks/Form/setServerFieldErrors.ts","../src/blocks/Form/setSubmitError.ts"],"sourcesContent":["import type { ComponentProps, ReactNode } from 'react';\n\nimport { cn } from '../../../utils';\nimport { useFormContext } from '../contexts';\n\ntype Props = {\n children: ReactNode;\n} & Omit<ComponentProps<'form'>, 'onSubmit'>;\n\nexport const FormBody = ({ children, className, ...formProps }: Props) => {\n const form = useFormContext();\n\n return (\n <form\n {...formProps}\n className={cn('tw:flex tw:flex-col tw:gap-4', className)}\n onSubmit={(e) => {\n e.preventDefault();\n e.stopPropagation();\n void form.handleSubmit();\n }}\n >\n {children}\n </form>\n );\n};\n","import type { ComponentProps, ReactNode } from 'react';\n\nimport { Button } from '../../../components/Button';\nimport { useFormContext } from '../contexts';\n\ntype Props = {\n children?: ReactNode;\n} & Omit<ComponentProps<typeof Button>, 'type' | 'isLoading' | 'disabled'>;\n\nexport const SubmitButton = ({ children = 'Submit', ...buttonProps }: Props) => {\n const form = useFormContext();\n\n return (\n <form.Subscribe\n selector={(state) => ({ isSubmitting: state.isSubmitting, canSubmit: state.canSubmit })}\n >\n {({ isSubmitting, canSubmit }) => (\n <Button\n {...buttonProps}\n type=\"submit\"\n isLoading={isSubmitting}\n disabled={!canSubmit || isSubmitting}\n >\n {children}\n </Button>\n )}\n </form.Subscribe>\n );\n};\n","import { Alert } from '../../../components/Alert';\nimport { useFormContext } from '../contexts';\n\n/**\n * Renders the form-level submit error (set via `setSubmitError` → `errorMap.onSubmit`) as an error\n * `Alert`. Place inside `form.FormBody`, typically just above the submit button. Renders nothing when\n * there is no submit error.\n */\nexport const SubmitErrorAlert = () => {\n const form = useFormContext();\n\n return (\n <form.Subscribe selector={(state) => state.errorMap.onSubmit}>\n {(submitError) =>\n typeof submitError === 'string' ? <Alert variant=\"error\" title={submitError} /> : null\n }\n </form.Subscribe>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { Checkbox } from '../../../components/Checkbox';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\n// Checkbox owns its own label + description (via children), so only the wrapper className applies.\ntype Props = Pick<FieldItemProps, 'className'> &\n Omit<ComponentProps<typeof Checkbox>, 'id' | 'name' | 'checked' | 'onCheckedChange'>;\n\nexport const CheckboxField = ({ className, children, ...checkboxProps }: Props) => {\n // Strictly boolean: coerce Radix's `'indeterminate'` to `false` so a non-boolean never leaks into\n // form state (submit payloads / validators). `'indeterminate'` stays a purely visual state.\n const field = useFieldContext<boolean>();\n\n return (\n <FieldItem className={className}>\n {(control) => (\n <Checkbox\n {...checkboxProps}\n {...control}\n checked={field.state.value ?? false}\n onCheckedChange={(checked) => field.handleChange(checked === true)}\n onBlur={field.handleBlur}\n >\n {children}\n </Checkbox>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { NumberInput } from '../../NumberInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n ComponentProps<typeof FormGroup.NumberInput>,\n 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'\n >;\n\nexport const NumberField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<number | null>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <NumberInput\n {...inputProps}\n {...control}\n value={field.state.value ?? null}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import { OtpInput, type OtpInputProps } from '../../OtpInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n OtpInputProps,\n | 'value'\n | 'onChange'\n | 'children'\n | 'id'\n | 'name'\n | 'aria-describedby'\n | 'aria-required'\n | 'aria-invalid'\n >;\n\nexport const OtpInputField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n maxLength,\n ...otpProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <OtpInput\n {...otpProps}\n {...control}\n maxLength={maxLength}\n value={field.state.value ?? ''}\n onChange={field.handleChange}\n onBlur={field.handleBlur}\n >\n <OtpInput.Group>\n {Array.from({ length: maxLength }, (_, index) => (\n <OtpInput.Slot key={index} index={index} />\n ))}\n </OtpInput.Group>\n </OtpInput>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { PasswordInput } from '../../PasswordInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<ComponentProps<typeof PasswordInput>, 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'>;\n\nexport const PasswordField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <PasswordInput\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import {\n Select,\n type SelectItem,\n type SelectItemGroup,\n type SelectProps,\n} from '../../../components/Select';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n SelectProps,\n // Owned by the field / `FieldItem` — see the connector rules in AGENTS.md. The naming props\n // are on that list too: `FieldItem` renders the label and hands the control its `id`, so a\n // name from the call site could only disagree with it.\n | 'id'\n | 'aria-label'\n | 'aria-labelledby'\n | 'name'\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'onBlur'\n | 'aria-describedby'\n | 'aria-invalid'\n | 'aria-required'\n // `className` styles the field frame, so the trigger gets its own prop below.\n | 'className'\n | 'items'\n > & {\n items: readonly (SelectItem | SelectItemGroup)[];\n triggerClassName?: string;\n };\n\nexport const SelectField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n triggerClassName,\n ...selectProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n // `required` deliberately stays on `FieldItem` (which turns it into `aria-required` via\n // `control`) and is not forwarded to the Radix root: a required hidden native select would\n // fail browser constraint validation and swallow the submit event before the form sees it.\n <Select\n {...selectProps}\n {...control}\n className={triggerClassName ?? 'tw:w-full'}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { Switch } from '../../../components/Switch';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\n// Switch owns its own label + description (via children), so only the wrapper className applies.\ntype Props = Pick<FieldItemProps, 'className'> &\n Omit<ComponentProps<typeof Switch>, 'id' | 'name' | 'checked' | 'onCheckedChange'>;\n\nexport const SwitchField = ({ className, children, ...switchProps }: Props) => {\n const field = useFieldContext<boolean>();\n\n return (\n <FieldItem className={className}>\n {(control) => (\n <Switch\n {...switchProps}\n {...control}\n checked={field.state.value ?? false}\n onCheckedChange={field.handleChange}\n onBlur={field.handleBlur}\n >\n {children}\n </Switch>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { Textarea } from '../../Textarea';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n ComponentProps<typeof FormGroup.Textarea>,\n 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'\n >;\n\nexport const TextareaField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <Textarea\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { TextInput } from '../../TextInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<ComponentProps<typeof FormGroup.TextInput>, 'id' | 'name' | 'value' | 'onChange' | 'onBlur'>;\n\nexport const TextField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <TextInput\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import { createFormHook } from '@tanstack/react-form';\n\nimport { FormBody } from './components/FormBody';\nimport { SubmitButton } from './components/SubmitButton';\nimport { SubmitErrorAlert } from './components/SubmitErrorAlert';\nimport { CheckboxField } from './connectors/CheckboxField';\nimport { NumberField } from './connectors/NumberField';\nimport { OtpInputField } from './connectors/OtpInputField';\nimport { PasswordField } from './connectors/PasswordField';\nimport { SelectField } from './connectors/SelectField';\nimport { SwitchField } from './connectors/SwitchField';\nimport { TextareaField } from './connectors/TextareaField';\nimport { TextField } from './connectors/TextField';\nimport { fieldContext, formContext } from './contexts';\n\n/**\n * Typed form hook + `withForm` binding for the design system.\n *\n * **When to use:** any form layout that has validation, server-side errors, or a submit state — pages,\n * modals, drawers, multi-step wizards. Use `useAppForm({ defaultValues, validators, onSubmit })` at the\n * top of the form component, then render the typed `field.TextField` / `field.NumberField` /\n * `field.PasswordField` / `field.TextareaField` / `field.SelectField` / `field.CheckboxField` /\n * `field.SwitchField` / `field.OtpInputField` connectors inside `form.AppForm` → `form.FormBody`. Submit via `form.SubmitButton`.\n * `MultiComboboxField` (from `@keboola/design`) and `CodeEditorField` (from `@keboola/design/editors`)\n * compose the same way but are imported by name — `fieldComponents` does not shake per key, so a\n * control with heavy dependencies would be carried by every consumer. See their own docs.\n * **When NOT to use:** for a single uncontrolled `<input>` use `TextInput` directly; for a bare label + input\n * pair without validation use `FormGroup` + `FormGroup.TextInput`.\n * **Composition:** schema-library agnostic — pass any [Standard Schema](https://standardschema.dev/) validator\n * (zod, valibot, …) in the consuming app. Server errors come from `setServerFieldErrors` (also re-exported).\n *\n * @see RECIPES.md#modal-form — for the canonical form-in-modal composition\n */\nexport const { useAppForm, withForm } = createFormHook({\n fieldContext,\n formContext,\n fieldComponents: {\n TextField,\n NumberField,\n PasswordField,\n TextareaField,\n SelectField,\n CheckboxField,\n SwitchField,\n OtpInputField,\n },\n formComponents: {\n FormBody,\n SubmitButton,\n SubmitErrorAlert,\n },\n});\n","import type { AnyFormApi } from '@tanstack/react-form';\n\nexport type ServerFieldError = {\n field: string;\n message: string;\n};\n\n/**\n * Map a list of server-returned field errors onto a TanStack form instance.\n *\n * - Marks each field blurred — that is what `FieldItem` gates the error reveal on.\n * - `isTouched` alongside it, for anything reading TanStack's own meta (`canSubmit`, dirty checks).\n * - Both are needed. Called from a mutation's `onError` there is no submit attempt to fall back on, so\n * without `isBlurred` the message would sit in `errorMap` and render nowhere.\n */\nexport const setServerFieldErrors = (form: AnyFormApi, errors: readonly ServerFieldError[]) => {\n for (const { field, message } of errors) {\n form.setFieldMeta(field, (meta) => ({\n ...meta,\n isBlurred: true,\n isTouched: true,\n errors: [message],\n errorMap: { ...meta.errorMap, onServer: message },\n }));\n }\n};\n","import type { AnyFormApi } from '@tanstack/react-form';\n\n/**\n * Set a **form-level** submit error on a TanStack form instance — a failed submission that isn't tied\n * to a single field (bad credentials, 5xx, network). Stored on `errorMap.onSubmit` and rendered by\n * `SubmitErrorAlert`. For field-specific server errors use `setServerFieldErrors` instead.\n *\n * Note: any error entry makes the form \"invalid\", so pair this with `canSubmitWhenInvalid: true` on\n * the form to keep the submit button retryable (a resubmit re-runs the validators and clears it).\n */\nexport const setSubmitError = (form: AnyFormApi, message: string) => {\n form.setErrorMap({ onSubmit: { form: message, fields: {} } });\n};\n"],"mappings":";;;;;;;;;;;;;;;AASA,MAAa,YAAY,EAAE,UAAU,WAAW,GAAG,gBAAuB;CACxE,MAAM,OAAO,eAAe;CAE5B,OACE,oBAAC,QAAD;EACE,GAAI;EACJ,WAAW,GAAG,gCAAgC,SAAS;EACvD,WAAW,MAAM;GACf,EAAE,eAAe;GACjB,EAAE,gBAAgB;GAClB,KAAU,aAAa;EACzB;EAEC;CACG,CAAA;AAEV;;;AChBA,MAAa,gBAAgB,EAAE,WAAW,UAAU,GAAG,kBAAyB;CAC9E,MAAM,OAAO,eAAe;CAE5B,OACE,oBAAC,KAAK,WAAN;EACE,WAAW,WAAW;GAAE,cAAc,MAAM;GAAc,WAAW,MAAM;EAAU;EAEnF,WAAA,EAAE,cAAc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EAAE,CAAC;AAC9D"}
|
|
1
|
+
{"version":3,"file":"Form-DAaatlBk.js","names":[],"sources":["../src/blocks/Form/components/FormBody.tsx","../src/blocks/Form/components/SubmitButton.tsx","../src/blocks/Form/components/SubmitErrorAlert.tsx","../src/blocks/Form/connectors/CheckboxField.tsx","../src/blocks/Form/connectors/NumberField.tsx","../src/blocks/Form/connectors/OtpInputField.tsx","../src/blocks/Form/connectors/PasswordField.tsx","../src/blocks/Form/connectors/SelectField.tsx","../src/blocks/Form/connectors/SwitchField.tsx","../src/blocks/Form/connectors/TextareaField.tsx","../src/blocks/Form/connectors/TextField.tsx","../src/blocks/Form/formHook.ts","../src/blocks/Form/setServerFieldErrors.ts","../src/blocks/Form/setSubmitError.ts"],"sourcesContent":["import type { ComponentProps, ReactNode } from 'react';\n\nimport { cn } from '../../../utils';\nimport { useFormContext } from '../contexts';\n\ntype Props = {\n children: ReactNode;\n} & Omit<ComponentProps<'form'>, 'onSubmit'>;\n\nexport const FormBody = ({ children, className, ...formProps }: Props) => {\n const form = useFormContext();\n\n return (\n <form\n {...formProps}\n className={cn('tw:flex tw:flex-col tw:gap-4', className)}\n onSubmit={(e) => {\n e.preventDefault();\n e.stopPropagation();\n void form.handleSubmit();\n }}\n >\n {children}\n </form>\n );\n};\n","import type { ComponentProps, ReactNode } from 'react';\n\nimport { Button } from '../../../components/Button';\nimport { useFormContext } from '../contexts';\n\ntype Props = {\n children?: ReactNode;\n} & Omit<ComponentProps<typeof Button>, 'type' | 'isLoading' | 'disabled'>;\n\nexport const SubmitButton = ({ children = 'Submit', ...buttonProps }: Props) => {\n const form = useFormContext();\n\n return (\n <form.Subscribe\n selector={(state) => ({ isSubmitting: state.isSubmitting, canSubmit: state.canSubmit })}\n >\n {({ isSubmitting, canSubmit }) => (\n <Button\n {...buttonProps}\n type=\"submit\"\n isLoading={isSubmitting}\n disabled={!canSubmit || isSubmitting}\n >\n {children}\n </Button>\n )}\n </form.Subscribe>\n );\n};\n","import { Alert } from '../../../components/Alert';\nimport { useFormContext } from '../contexts';\n\n/**\n * Renders the form-level submit error (set via `setSubmitError` → `errorMap.onSubmit`) as an error\n * `Alert`. Place inside `form.FormBody`, typically just above the submit button. Renders nothing when\n * there is no submit error.\n */\nexport const SubmitErrorAlert = () => {\n const form = useFormContext();\n\n return (\n <form.Subscribe selector={(state) => state.errorMap.onSubmit}>\n {(submitError) =>\n typeof submitError === 'string' ? <Alert variant=\"error\" title={submitError} /> : null\n }\n </form.Subscribe>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { Checkbox } from '../../../components/Checkbox';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\n// Checkbox owns its own label + description (via children), so only the wrapper className applies.\ntype Props = Pick<FieldItemProps, 'className'> &\n Omit<ComponentProps<typeof Checkbox>, 'id' | 'name' | 'checked' | 'onCheckedChange'>;\n\nexport const CheckboxField = ({ className, children, ...checkboxProps }: Props) => {\n // Strictly boolean: coerce Radix's `'indeterminate'` to `false` so a non-boolean never leaks into\n // form state (submit payloads / validators). `'indeterminate'` stays a purely visual state.\n const field = useFieldContext<boolean>();\n\n return (\n <FieldItem className={className}>\n {(control) => (\n <Checkbox\n {...checkboxProps}\n {...control}\n checked={field.state.value ?? false}\n onCheckedChange={(checked) => field.handleChange(checked === true)}\n onBlur={field.handleBlur}\n >\n {children}\n </Checkbox>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { NumberInput } from '../../NumberInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n ComponentProps<typeof FormGroup.NumberInput>,\n 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'\n >;\n\nexport const NumberField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<number | null>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <NumberInput\n {...inputProps}\n {...control}\n value={field.state.value ?? null}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import { OtpInput, type OtpInputProps } from '../../OtpInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n OtpInputProps,\n | 'value'\n | 'onChange'\n | 'children'\n | 'id'\n | 'name'\n | 'aria-describedby'\n | 'aria-required'\n | 'aria-invalid'\n >;\n\nexport const OtpInputField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n maxLength,\n ...otpProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <OtpInput\n {...otpProps}\n {...control}\n maxLength={maxLength}\n value={field.state.value ?? ''}\n onChange={field.handleChange}\n onBlur={field.handleBlur}\n >\n <OtpInput.Group>\n {Array.from({ length: maxLength }, (_, index) => (\n <OtpInput.Slot key={index} index={index} />\n ))}\n </OtpInput.Group>\n </OtpInput>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { PasswordInput } from '../../PasswordInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<ComponentProps<typeof PasswordInput>, 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'>;\n\nexport const PasswordField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <PasswordInput\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import {\n Select,\n type SelectItem,\n type SelectItemGroup,\n type SelectProps,\n} from '../../../components/Select';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n SelectProps,\n // Owned by the field / `FieldItem` — see the connector rules in AGENTS.md. The naming props\n // are on that list too: `FieldItem` renders the label and hands the control its `id`, so a\n // name from the call site could only disagree with it.\n | 'id'\n | 'aria-label'\n | 'aria-labelledby'\n | 'name'\n | 'value'\n | 'defaultValue'\n | 'onValueChange'\n | 'onBlur'\n | 'aria-describedby'\n | 'aria-invalid'\n | 'aria-required'\n // `className` styles the field frame, so the trigger gets its own prop below.\n | 'className'\n | 'items'\n > & {\n items: readonly (SelectItem | SelectItemGroup)[];\n triggerClassName?: string;\n };\n\nexport const SelectField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n triggerClassName,\n ...selectProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n // `required` deliberately stays on `FieldItem` (which turns it into `aria-required` via\n // `control`) and is not forwarded to the Radix root: a required hidden native select would\n // fail browser constraint validation and swallow the submit event before the form sees it.\n <Select\n {...selectProps}\n {...control}\n className={triggerClassName ?? 'tw:w-full'}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { Switch } from '../../../components/Switch';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\n// Switch owns its own label + description (via children), so only the wrapper className applies.\ntype Props = Pick<FieldItemProps, 'className'> &\n Omit<ComponentProps<typeof Switch>, 'id' | 'name' | 'checked' | 'onCheckedChange'>;\n\nexport const SwitchField = ({ className, children, ...switchProps }: Props) => {\n const field = useFieldContext<boolean>();\n\n return (\n <FieldItem className={className}>\n {(control) => (\n <Switch\n {...switchProps}\n {...control}\n checked={field.state.value ?? false}\n onCheckedChange={field.handleChange}\n onBlur={field.handleBlur}\n >\n {children}\n </Switch>\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { Textarea } from '../../Textarea';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<\n ComponentProps<typeof FormGroup.Textarea>,\n 'id' | 'name' | 'value' | 'onValueChange' | 'onBlur'\n >;\n\nexport const TextareaField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <Textarea\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport type { FormGroup } from '../../FormGroup';\nimport { TextInput } from '../../TextInput';\nimport { useFieldContext } from '../contexts';\n\nimport { FieldItem, type FieldItemProps } from './FieldItem';\n\ntype Props = FieldItemProps &\n Omit<ComponentProps<typeof FormGroup.TextInput>, 'id' | 'name' | 'value' | 'onChange' | 'onBlur'>;\n\nexport const TextField = ({\n label,\n action,\n required,\n requiredMark,\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...inputProps\n}: Props) => {\n const field = useFieldContext<string>();\n\n return (\n <FieldItem\n label={label}\n action={action}\n required={required}\n requiredMark={requiredMark}\n help={help}\n tooltip={tooltip}\n className={className}\n aria-describedby={ariaDescribedBy}\n >\n {(control) => (\n <TextInput\n {...inputProps}\n {...control}\n value={field.state.value ?? ''}\n onValueChange={field.handleChange}\n onBlur={field.handleBlur}\n />\n )}\n </FieldItem>\n );\n};\n","import { createFormHook } from '@tanstack/react-form';\n\nimport { FormBody } from './components/FormBody';\nimport { SubmitButton } from './components/SubmitButton';\nimport { SubmitErrorAlert } from './components/SubmitErrorAlert';\nimport { CheckboxField } from './connectors/CheckboxField';\nimport { NumberField } from './connectors/NumberField';\nimport { OtpInputField } from './connectors/OtpInputField';\nimport { PasswordField } from './connectors/PasswordField';\nimport { SelectField } from './connectors/SelectField';\nimport { SwitchField } from './connectors/SwitchField';\nimport { TextareaField } from './connectors/TextareaField';\nimport { TextField } from './connectors/TextField';\nimport { fieldContext, formContext } from './contexts';\n\n/**\n * Typed form hook + `withForm` binding for the design system.\n *\n * **When to use:** any form layout that has validation, server-side errors, or a submit state — pages,\n * modals, drawers, multi-step wizards. Use `useAppForm({ defaultValues, validators, onSubmit })` at the\n * top of the form component, then render the typed `field.TextField` / `field.NumberField` /\n * `field.PasswordField` / `field.TextareaField` / `field.SelectField` / `field.CheckboxField` /\n * `field.SwitchField` / `field.OtpInputField` connectors inside `form.AppForm` → `form.FormBody`. Submit via `form.SubmitButton`.\n * `MultiComboboxField` (from `@keboola/design`) and `CodeEditorField` (from `@keboola/design/editors`)\n * compose the same way but are imported by name — `fieldComponents` does not shake per key, so a\n * control with heavy dependencies would be carried by every consumer. See their own docs.\n * **When NOT to use:** for a single uncontrolled `<input>` use `TextInput` directly; for a bare label + input\n * pair without validation use `FormGroup` + `FormGroup.TextInput`.\n * **Composition:** schema-library agnostic — pass any [Standard Schema](https://standardschema.dev/) validator\n * (zod, valibot, …) in the consuming app. Server errors come from `setServerFieldErrors` (also re-exported).\n *\n * @see RECIPES.md#modal-form — for the canonical form-in-modal composition\n */\nexport const { useAppForm, withForm } = createFormHook({\n fieldContext,\n formContext,\n fieldComponents: {\n TextField,\n NumberField,\n PasswordField,\n TextareaField,\n SelectField,\n CheckboxField,\n SwitchField,\n OtpInputField,\n },\n formComponents: {\n FormBody,\n SubmitButton,\n SubmitErrorAlert,\n },\n});\n","import type { AnyFormApi } from '@tanstack/react-form';\n\nexport type ServerFieldError = {\n field: string;\n message: string;\n};\n\n/**\n * Map a list of server-returned field errors onto a TanStack form instance.\n *\n * - Marks each field blurred — that is what `FieldItem` gates the error reveal on.\n * - `isTouched` alongside it, for anything reading TanStack's own meta (`canSubmit`, dirty checks).\n * - Both are needed. Called from a mutation's `onError` there is no submit attempt to fall back on, so\n * without `isBlurred` the message would sit in `errorMap` and render nowhere.\n */\nexport const setServerFieldErrors = (form: AnyFormApi, errors: readonly ServerFieldError[]) => {\n for (const { field, message } of errors) {\n form.setFieldMeta(field, (meta) => ({\n ...meta,\n isBlurred: true,\n isTouched: true,\n errors: [message],\n errorMap: { ...meta.errorMap, onServer: message },\n }));\n }\n};\n","import type { AnyFormApi } from '@tanstack/react-form';\n\n/**\n * Set a **form-level** submit error on a TanStack form instance — a failed submission that isn't tied\n * to a single field (bad credentials, 5xx, network). Stored on `errorMap.onSubmit` and rendered by\n * `SubmitErrorAlert`. For field-specific server errors use `setServerFieldErrors` instead.\n *\n * Note: any error entry makes the form \"invalid\", so pair this with `canSubmitWhenInvalid: true` on\n * the form to keep the submit button retryable (a resubmit re-runs the validators and clears it).\n */\nexport const setSubmitError = (form: AnyFormApi, message: string) => {\n form.setErrorMap({ onSubmit: { form: message, fields: {} } });\n};\n"],"mappings":";;;;;;;;;;;;;;;AASA,MAAa,YAAY,EAAE,U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EACA;EACA;CACF;CACA,gBAAgB;EACd;EACA;EACA;CACF;AACF,CAAC;;;;;;;;;;;ACpCD,MAAa,wBAAwB,MAAkB,WAAwC;CAC7F,KAAK,MAAM,EAAE,OAAO,aAAa,QAC/B,KAAK,aAAa,QAAQ,UAAU;EAClC,GAAG;EACH,WAAW;EACX,WAAW;EACX,QAAQ,CAAC,OAAO;EAChB,UAAU;GAAE,GAAG,KAAK;GAAU,UAAU;EAAQ;CAClD,EAAE;AAEN;;;;;;;;;;;ACfA,MAAa,kBAAkB,MAAkB,YAAoB;CACnE,KAAK,YAAY,EAAE,UAAU;EAAE,MAAM;EAAS,QAAQ,CAAC;CAAE,EAAE,CAAC;AAC9D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
|
-
import { TextInput } from "./TextInput-
|
|
3
|
-
import { ColorInput } from "./ColorInput-
|
|
2
|
+
import { TextInput } from "./TextInput-DiEMxVF6.js";
|
|
3
|
+
import { ColorInput } from "./ColorInput-Dg87lKcR.js";
|
|
4
4
|
import { HelpBlock } from "./internal/components/HelpBlock.js";
|
|
5
5
|
import { NumberInput } from "./internal/blocks/NumberInput.js";
|
|
6
6
|
import { Textarea } from "./internal/blocks/Textarea.js";
|
|
@@ -121,4 +121,4 @@ FormGroup.Textarea = FormGroupTextarea;
|
|
|
121
121
|
//#endregion
|
|
122
122
|
export { FormGroup };
|
|
123
123
|
|
|
124
|
-
//# sourceMappingURL=FormGroup-
|
|
124
|
+
//# sourceMappingURL=FormGroup-Bl8JmnzJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormGroup-
|
|
1
|
+
{"version":3,"file":"FormGroup-Bl8JmnzJ.js","names":[],"sources":["../src/blocks/FormGroup/context.ts","../src/blocks/FormGroup/FormGroupColorInput.tsx","../src/blocks/FormGroup/FormGroupError.tsx","../src/blocks/FormGroup/FormGroupHelp.tsx","../src/blocks/FormGroup/FormGroupNumberInput.tsx","../src/blocks/FormGroup/FormGroupTextarea.tsx","../src/blocks/FormGroup/FormGroupTextInput.tsx","../src/blocks/FormGroup/FormGroup.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\nimport type { FormGroupContext } from './types';\n\nconst FormGroupContext = createContext<FormGroupContext>({\n state: 'default',\n});\n\nexport const FormGroupProvider = FormGroupContext;\n\nexport const useFormGroupContext = () => use(FormGroupContext);\n","import type { ComponentProps } from 'react';\n\nimport { ColorInput } from '../ColorInput';\n\nimport { useFormGroupContext } from './context';\n\ntype Props = Omit<ComponentProps<typeof ColorInput>, 'state'>;\n\nexport const FormGroupColorInput = ({ ref, ...props }: Props) => {\n const { state } = useFormGroupContext();\n return <ColorInput state={state} {...props} ref={ref} />;\n};\n","import { useMemo } from 'react';\nimport type { ComponentPropsWithRef, ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentPropsWithRef<'div'> & {\n /**\n * Field validation errors. TanStack Form errors are strings (function validators) or\n * `{ message }` objects (Standard Schema / zod). A single message renders inline; several\n * render as a list. Ignored when `children` is provided.\n */\n errors?: readonly (string | { message?: string } | undefined)[];\n};\n\n// Normalize a TanStack error entry (string or `{ message }`) to a display string.\nconst toMessage = (entry: string | { message?: string } | undefined): string | undefined =>\n typeof entry === 'string' ? entry : entry?.message;\n\n/**\n * Field error message. Unlike `FormGroup.Help` (advisory description), this is a validation\n * error, so it carries `role=\"alert\"` — announced when it appears, even if focus isn't on the\n * field (e.g. surfaced on submit). Renders a `<div>` (not `<p>`) so multiple errors can render\n * as a `<ul>`.\n */\nexport const FormGroupError = ({ children, className, errors, ...rest }: Props) => {\n const content = useMemo<ReactNode>(() => {\n if (children) return children;\n\n // Deduplicated: a field validated on more than one event (`onChange` **and** `onBlur` carrying the\n // same schema) accumulates one entry per validator that ran, so after a blur the identical message\n // is present twice and renders as \"RequiredRequired\". Two validators agreeing is still one thing to\n // tell the reader. That pairing is not the setup to reach for — `Form/AGENTS.md` says to register\n // the schema on `onChange` and nothing else — but this component renders whatever it is handed.\n const messages = [...new Set((errors ?? []).map(toMessage).filter((message) => !!message))];\n if (messages.length === 0) return null;\n if (messages.length === 1) return messages[0];\n\n return (\n <ul className=\"tw:m-0 tw:flex tw:list-disc tw:flex-col tw:gap-0 tw:pl-4\">\n {messages.map((message) => (\n // The message is the key: they are unique after the dedupe above, which also retires the\n // array-index key this list used to need.\n <li key={message}>{message}</li>\n ))}\n </ul>\n );\n }, [children, errors]);\n\n if (!content) return null;\n\n return (\n <div {...rest} role=\"alert\" className={cn('tw:m-0 tw:text-xs tw:text-destructive', className)}>\n {content}\n </div>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { HelpBlock } from '../../components/HelpBlock';\n\nimport { useFormGroupContext } from './context';\n\ntype Props = Omit<ComponentProps<typeof HelpBlock>, 'state'>;\n\nexport const FormGroupHelp = ({ children, ...rest }: Props) => {\n const formGroupContext = useFormGroupContext();\n\n // Help stays advisory; a group's error state surfaces via FormGroup.Error, not here.\n return (\n <HelpBlock state={formGroupContext.state === 'warning' ? 'warning' : 'default'} {...rest}>\n {children}\n </HelpBlock>\n );\n};\n","import type { ComponentProps } from 'react';\n\nimport { NumberInput } from '../NumberInput';\n\nimport { useFormGroupContext } from './context';\n\ntype Props = Omit<ComponentProps<typeof NumberInput>, 'state'>;\n\nexport const FormGroupNumberInput = ({ ref, ...props }: Props) => {\n const { state } = useFormGroupContext();\n return <NumberInput {...props} ref={ref} state={state} />;\n};\n","import type { ComponentProps } from 'react';\n\nimport { Textarea } from '../Textarea';\n\nimport { useFormGroupContext } from './context';\n\ntype Props = Omit<ComponentProps<typeof Textarea>, 'state'>;\n\nexport const FormGroupTextarea = (props: Props) => {\n const { state } = useFormGroupContext();\n return <Textarea state={state} {...props} />;\n};\n","import type { ComponentProps } from 'react';\n\nimport { TextInput } from '../TextInput';\n\nimport { useFormGroupContext } from './context';\n\ntype Props = Omit<ComponentProps<typeof TextInput>, 'state'>;\n\nexport const FormGroupTextInput = ({ ref, ...props }: Props) => {\n const { state } = useFormGroupContext();\n return <TextInput state={state} {...props} ref={ref} />;\n};\n","import type { ComponentPropsWithRef } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { FormGroupProvider } from './context';\nimport { FormGroupColorInput } from './FormGroupColorInput';\nimport { FormGroupError } from './FormGroupError';\nimport { FormGroupHelp } from './FormGroupHelp';\nimport { FormGroupNumberInput } from './FormGroupNumberInput';\nimport { FormGroupTextarea } from './FormGroupTextarea';\nimport { FormGroupTextInput } from './FormGroupTextInput';\nimport type { FormGroupContext } from './types';\n\n/**\n * Props for `FormGroup`. `state` from `FormGroupContext` (\"default\" | \"error\" | \"warning\") propagates via\n * context to nested inputs. `FormGroup.Help` stays advisory (it reacts only to \"warning\"); validation errors\n * render through `FormGroup.Error`, not the input `state`.\n */\ntype FormGroupProps = ComponentPropsWithRef<'div'> & FormGroupContext;\n\n/**\n * Label + input + help-text grouping with shared validation state. Provides the chrome for a single field.\n *\n * **When to use:** rendering a label + bare input + help/error text outside `useAppForm` (e.g. one-off\n * filter fields, settings panes). `state=\"error\"` flips `FormGroup.TextInput` chrome without per-component\n * wiring; the error message itself renders via `FormGroup.Error` (`role=\"alert\"`), while `FormGroup.Help`\n * stays advisory.\n * **When NOT to use:** for a full form with validation and submit state, use `useAppForm` from `blocks/Form` —\n * it composes `FormGroup` internally via the typed field connectors.\n * **Composition:** nest a `Label`, then one of `FormGroup.TextInput` / `FormGroup.NumberInput` /\n * `FormGroup.ColorInput` / `FormGroup.Textarea`, optionally followed by `FormGroup.Help`\n * (advisory description) or `FormGroup.Error` (validation error, announced via `role=\"alert\"`).\n */\nexport const FormGroup = ({ className, children, state, ...rest }: FormGroupProps) => {\n return (\n <FormGroupProvider value={{ state }}>\n <div {...rest} className={cn('tw:flex tw:flex-col tw:gap-1', className)}>\n {children}\n </div>\n </FormGroupProvider>\n );\n};\n\nFormGroup.Help = FormGroupHelp;\nFormGroup.Error = FormGroupError;\nFormGroup.TextInput = FormGroupText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AAA;AAEf;;;ACTA,MAAa,wBAAwB,EAAE,KAAK,GAAG,YAAmB;CAChE,MAAM,EAAE,UAAU,oBAAoB;CACtC,OAAO,oBAAC,aAAD;EAAa,GAAI;EAAY;EAAY;CAAQ,CAAA;AAC1D;;;ACHA,MAAa,qBAAqB,UAAiB;CACjD,MAAM,EAAE,UAAU,oBAAoB;CACtC,OAAO,oBAAC,UAAD;EAAiB;EAAO,GAAI;CAAQ,CAAA;AAC7C;;;ACHA,MAAa,sBAAsB,EAAE,KAAK,GAAG,YAAmB;CAC9D,MAAM,EAAE,UAAU,oBAAoB;CACtC,OAAO,oBAAC,WAAD;EAAkB;EAAO,GAAI;EAAY;CAAM,CAAA;AACxD;;;;;;;;;;;;;;;;ACsBA,MAAa,aAAa,EAAE,WAAW,UAAU,OAAO,GAAG,WAA2B;CACpF,OACE,oBAAC,mBAAD;EAAmB,OAAO,EAAE,MAAM;EAChC,UAAA,oBAAC,OAAD;GAAK,GAAI;GAAM,WAAW,GAAG,gCAAgC,SAAS;GACnE;EACE,CAAA;CACY,CAAA;AAEvB;AAEA,UAAU,OAAO;AACjB,UAAU,QAAQ;AAClB,UAAU,YAAY;AACtB,UAAU,cAAc;AACxB,UAAU,aAAa;AACvB,UAAU,WAAW"}
|
|
@@ -67,9 +67,57 @@ const FullScreenModalRoot = ({ children, className, lockBodyScroll = true, onEsc
|
|
|
67
67
|
if (!Array.from(document.querySelectorAll("[data-fullscreen-modal]")).some((el) => el !== modalElement)) document.body.classList.remove(BODY_LOCK_CLASS);
|
|
68
68
|
};
|
|
69
69
|
}, [lockBodyScroll]);
|
|
70
|
+
/**
|
|
71
|
+
* Whatever had focus when this modal mounted — read during render, and only the first one.
|
|
72
|
+
*
|
|
73
|
+
* - React focuses an `autoFocus` descendant while committing this tree, before any effect here
|
|
74
|
+
* runs. Read in the effect instead, the opener is already gone: `document.activeElement` is
|
|
75
|
+
* the modal's own field, and close hands focus to an element that is being unmounted.
|
|
76
|
+
* - Render is the last moment the opener is readable, so the read sits here rather than in a
|
|
77
|
+
* layout effect — a child's `autoFocus` lands in the same phase as one of those, ahead of it.
|
|
78
|
+
*/
|
|
79
|
+
const openerRef = useRef(null);
|
|
80
|
+
openerRef.current ??= document.activeElement;
|
|
81
|
+
/**
|
|
82
|
+
* Focus moves into the modal on open and back to the opener on close.
|
|
83
|
+
*
|
|
84
|
+
* - `onEscapeKeyDown` is a React `keydown` on this element, so it only ever fires while focus is
|
|
85
|
+
* inside. Left where it was, focus stays on whatever opened the modal — behind it — and Escape
|
|
86
|
+
* reaches nothing.
|
|
87
|
+
* - Only when focus is still outside: a modal whose content autofocuses its own field (an editor,
|
|
88
|
+
* a search box) has already put focus where it wants it, and taking it back would undo that.
|
|
89
|
+
* That is why the move reads focus now and the restore reads the opener.
|
|
90
|
+
* - This is not a focus trap. Tab still walks out into the obscured page behind; trapping and
|
|
91
|
+
* `inert` need this element to own the background, which it does not.
|
|
92
|
+
*/
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const modal = modalRef.current;
|
|
95
|
+
if (!modal) return;
|
|
96
|
+
if (!modal.contains(document.activeElement)) modal.focus();
|
|
97
|
+
return () => {
|
|
98
|
+
const opener = openerRef.current;
|
|
99
|
+
if (opener instanceof HTMLElement && opener.isConnected) opener.focus();
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
/**
|
|
103
|
+
* Escape belongs to the modal it was pressed in.
|
|
104
|
+
*
|
|
105
|
+
* - A nested modal is portalled *beside* the one it is rendered inside, but React routes a
|
|
106
|
+
* portal's events up the *logical* tree — so the inner modal's Escape arrives at the outer
|
|
107
|
+
* one's handler too, and one keypress would dismiss both.
|
|
108
|
+
* - Which modal the key belongs to is read off the DOM, where the nesting is not a lie: the
|
|
109
|
+
* inner modal's element is a sibling of the outer's, not a descendant, so the outer sees a
|
|
110
|
+
* target it does not contain and leaves the key alone.
|
|
111
|
+
* - Not `stopPropagation`. A synthetic `stopPropagation` also stops the native event, and React
|
|
112
|
+
* mounts a portal's listeners on `document.body` — so it would cut off every `document`-level
|
|
113
|
+
* `keydown` handler on the page, including the one kbc-ui's own wrapper closes from.
|
|
114
|
+
*/
|
|
70
115
|
const handleKeyDown = (event) => {
|
|
71
116
|
onKeyDown?.(event);
|
|
72
|
-
if (event.key
|
|
117
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
118
|
+
const target = event.target;
|
|
119
|
+
if (!(target instanceof Node) || !modalRef.current?.contains(target)) return;
|
|
120
|
+
onEscapeKeyDown?.(event);
|
|
73
121
|
};
|
|
74
122
|
return createPortal(/* @__PURE__ */ jsx("div", {
|
|
75
123
|
...props,
|
|
@@ -93,4 +141,4 @@ const FullScreenModal = Object.assign(FullScreenModalRoot, {
|
|
|
93
141
|
//#endregion
|
|
94
142
|
export { FullScreenModal, FullScreenModalBody, FullScreenModalHeader };
|
|
95
143
|
|
|
96
|
-
//# sourceMappingURL=FullScreenModal-
|
|
144
|
+
//# sourceMappingURL=FullScreenModal-CN9nAs72.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FullScreenModal-CN9nAs72.js","names":[],"sources":["../src/components/FullScreenModal/FullScreenModalBody.tsx","../src/components/FullScreenModal/FullScreenModalHeader.tsx","../src/components/FullScreenModal/FullScreenModalRoot.tsx","../src/components/FullScreenModal/FullScreenModal.tsx"],"sourcesContent":["import type { HTMLAttributes, Ref } from 'react';\n\nimport { cn } from '../../utils';\n\ntype Props = HTMLAttributes<HTMLDivElement>;\n\nexport const FullScreenModalBody = ({\n ref,\n className,\n children,\n ...props\n}: Props & { ref?: Ref<HTMLDivElement> }) => (\n <div ref={ref} className={cn('tw:flex-1 tw:min-h-0 tw:overflow-auto', className)} {...props}>\n {children}\n </div>\n);\n","import { useMemo } from 'react';\nimport type { HTMLAttributes, PropsWithChildren, ReactNode } from 'react';\n\nimport { ChevronLeft } from '../../icons';\nimport { cn } from '../../utils';\nimport { Button } from '../Button';\nimport { Truncated } from '../Truncated';\n\nconst DEFAULT_TITLE_STYLES =\n 'tw:text-2xl tw:leading-8 tw:font-normal tw:text-foreground tw:overflow-hidden';\n\ntype Props = PropsWithChildren<\n Omit<HTMLAttributes<HTMLDivElement>, 'title'> & {\n title: ReactNode;\n titleClassName?: string;\n titleWrapperClassName?: string;\n defaultTitleStyles?: boolean;\n isTitleWithIcon?: boolean;\n onClose?: () => void;\n showPreviousTitle?: boolean;\n }\n>;\n\nexport const FullScreenModalHeader = ({\n title,\n titleClassName,\n titleWrapperClassName,\n defaultTitleStyles = true,\n isTitleWithIcon = false,\n children,\n onClose,\n className,\n showPreviousTitle = true,\n ...props\n}: Props) => {\n const previousTitle = useMemo(() => {\n const modals = Array.from(document.querySelectorAll('[data-fullscreen-modal]'));\n return (\n showPreviousTitle &&\n modals?.length > 0 &&\n modals.at(-1)?.querySelector('[data-modal-title]')?.textContent\n );\n }, [showPreviousTitle]);\n\n return (\n <div\n className={cn('tw:p-4 tw:flex tw:shrink-0 tw:items-center tw:justify-between', className)}\n {...props}\n >\n <div className={cn('tw:flex tw:flex-1 tw:items-center', titleWrapperClassName)}>\n {previousTitle && onClose && (\n <Button onClick={onClose} size=\"icon\" className=\"tw:mr-6\">\n <ChevronLeft className=\"tw:size-4\" />\n </Button>\n )}\n\n <div className=\"tw:w-full\">\n <div\n className={cn('tw:m-0', defaultTitleStyles && DEFAULT_TITLE_STYLES, titleClassName)}\n data-modal-title\n >\n {previousTitle && onClose && (\n <button\n type=\"button\"\n onClick={onClose}\n className=\"tailwindcss-preflight\"\n aria-label={`Go back to ${previousTitle}`}\n >\n <Truncated\n text={previousTitle}\n className={cn(\n 'tw:relative tw:top-0 tw:cursor-pointer tw:text-base tw:font-normal tw:text-muted-foreground tw:underline',\n 'tw:hover:text-foreground tw:hover:no-underline',\n isTitleWithIcon && 'tw:ml-14',\n )}\n />\n </button>\n )}\n <div\n className={cn('tw:flex tw:items-center', {\n 'tw:[&>img]:-mt-6': previousTitle,\n })}\n >\n {title}\n </div>\n </div>\n </div>\n </div>\n {children}\n </div>\n );\n};\n","import { useEffect, useRef } from 'react';\nimport type { HTMLAttributes, KeyboardEvent, ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { cn } from '../../utils';\nimport { useArgoDesign } from '../ThemeProvider/context';\n\ntype Props = HTMLAttributes<HTMLDivElement> & {\n children: ReactNode;\n /** Lock body scroll when modal is open. Default: true */\n lockBodyScroll?: boolean;\n /** Callback when ESC key is pressed */\n onEscapeKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;\n};\n\nconst BODY_LOCK_CLASS = 'full-screen-modal-open';\n\nexport const FullScreenModalRoot = ({\n children,\n className,\n lockBodyScroll = true,\n onEscapeKeyDown,\n onKeyDown,\n ...props\n}: Props) => {\n const modalRef = useRef<HTMLDivElement>(null);\n const renderArgo = useArgoDesign();\n\n // Body scroll lock\n useEffect(() => {\n const modalElement = modalRef.current;\n\n if (lockBodyScroll) {\n document.body.classList.add(BODY_LOCK_CLASS);\n }\n\n return () => {\n // Filter out the current modal because it may still be in the DOM\n // when lockBodyScroll toggles from true to false (e.g. switching\n // from full-screen to half-screen mode).\n const hasOtherModals = Array.from(document.querySelectorAll('[data-fullscreen-modal]')).some(\n (el) => el !== modalElement,\n );\n\n if (!hasOtherModals) {\n document.body.classList.remove(BODY_LOCK_CLASS);\n }\n };\n }, [lockBodyScroll]);\n\n /**\n * Whatever had focus when this modal mounted — read during render, and only the first one.\n *\n * - React focuses an `autoFocus` descendant while committing this tree, before any effect here\n * runs. Read in the effect instead, the opener is already gone: `document.activeElement` is\n * the modal's own field, and close hands focus to an element that is being unmounted.\n * - Render is the last moment the opener is readable, so the read sits here rather than in a\n * layout effect — a child's `autoFocus` lands in the same phase as one of those, ahead of it.\n */\n const openerRef = useRef<Element | null>(null);\n openerRef.current ??= document.activeElement;\n\n /**\n * Focus moves into the modal on open and back to the opener on close.\n *\n * - `onEscapeKeyDown` is a React `keydown` on this element, so it only ever fires while focus is\n * inside. Left where it was, focus stays on whatever opened the modal — behind it — and Escape\n * reaches nothing.\n * - Only when focus is still outside: a modal whose content autofocuses its own field (an editor,\n * a search box) has already put focus where it wants it, and taking it back would undo that.\n * That is why the move reads focus now and the restore reads the opener.\n * - This is not a focus trap. Tab still walks out into the obscured page behind; trapping and\n * `inert` need this element to own the background, which it does not.\n */\n useEffect(() => {\n const modal = modalRef.current;\n if (!modal) return;\n\n if (!modal.contains(document.activeElement)) modal.focus();\n\n return () => {\n const opener = openerRef.current;\n if (opener instanceof HTMLElement && opener.isConnected) opener.focus();\n };\n }, []);\n\n /**\n * Escape belongs to the modal it was pressed in.\n *\n * - A nested modal is portalled *beside* the one it is rendered inside, but React routes a\n * portal's events up the *logical* tree — so the inner modal's Escape arrives at the outer\n * one's handler too, and one keypress would dismiss both.\n * - Which modal the key belongs to is read off the DOM, where the nesting is not a lie: the\n * inner modal's element is a sibling of the outer's, not a descendant, so the outer sees a\n * target it does not contain and leaves the key alone.\n * - Not `stopPropagation`. A synthetic `stopPropagation` also stops the native event, and React\n * mounts a portal's listeners on `document.body` — so it would cut off every `document`-level\n * `keydown` handler on the page, including the one kbc-ui's own wrapper closes from.\n */\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (event.key !== 'Escape' || event.defaultPrevented) return;\n\n const target = event.target;\n if (!(target instanceof Node) || !modalRef.current?.contains(target)) return;\n\n onEscapeKeyDown?.(event);\n };\n\n return createPortal(\n <div\n {...props}\n ref={modalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n data-fullscreen-modal\n data-argo={renderArgo}\n onKeyDown={handleKeyDown}\n className={cn(\n 'tailwindcss-preflight',\n 'tw:fixed',\n 'tw:inset-0',\n 'tw:z-[1039]',\n 'tw:flex',\n 'tw:flex-col',\n // One scheme-following surface for both chromes. The legacy branch used\n // to pin `neutral-50`, which the dark scheme cannot reach — and its\n // light value is within a shade of `background` anyway. `text-foreground`\n // has to travel with it: the modal is portalled to `document.body`, so it\n // inherits no app-level foreground and content would sit dark-on-dark.\n 'tw:bg-background',\n 'tw:text-foreground',\n 'tw:focus-visible:outline-hidden',\n className,\n )}\n >\n {children}\n </div>,\n document.body,\n );\n};\n","import { FullScreenModalBody } from './FullScreenModalBody';\nimport { FullScreenModalHeader } from './FullScreenModalHeader';\nimport { FullScreenModalRoot } from './FullScreenModalRoot';\n\nexport const FullScreenModal = Object.assign(FullScreenModalRoot, {\n Header: FullScreenModalHeader,\n Body: FullScreenModalBody,\n});\n"],"mappings":";;;;;;;;;AAMA,MAAa,uBAAuB,EAClC,KACA,WACA,UACA,GAAG,YAEH,oBAAC,OAAD;CAAU;CAAK,WAAW,GAAG,yCAAyC,SAAS;CAAG,GAAI;CACnF;AACE,CAAA;;;ACNP,MAAM,uBACJ;AAcF,MAAa,yBAAyB,EACpC,OACA,gBACA,uBACA,qBAAqB,MACrB,kBAAkB,OAClB,UACA,SACA,WACA,oBAAoB,MACpB,GAAG,YACQ;CACX,MAAM,gBAAgB,cAAc;EAClC,MAAM,SAAS,MAAM,KAAK,SAAS,iBAAiB,yBAAyB,CAAC;EAC9E,OACE,qBACA,QAAQ,SAAS,KACjB,OAAO,GAAG,EAAE,CAAC,EAAE,cAAc,oBAAoB,CAAC,EAAE;CAExD,GAAG,CAAC,iBAAiB,CAAC;CAEtB,OACE,qBAAC,OAAD;EACE,WAAW,GAAG,iEAAiE,SAAS;EACxF,GAAI;EAFN,UAAA,CAIE,qBAAC,OAAD;GAAK,WAAW,GAAG,qCAAqC,qBAAqB;GAA7E,UAAA,CACG,iBAAiB,WAChB,oBAAC,QAAD;IAAQ,SAAS;IAAS,MAAK;IAAO,WAAU;IAC9C,UAAA,oBAAC,aAAD,EAAa,WAAU,YAAa,CAAA;GAC9B,CAAA,GAGV,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,qBAAC,OAAD;KACE,WAAW,GAAG,UAAU,sBAAsB,sBAAsB,cAAc;KAClF,oBAAA;KAFF,UAAA,CAIG,iBAAiB,WAChB,o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AS,SAAS,MAAM,GAAG;EAEtE,kBAAkB,KAAK;CACzB;CAEA,OAAO,aACL,oBAAC,OAAD;EACE,GAAI;EACJ,KAAK;EACL,MAAK;EACL,cAAW;EACX,UAAU;EACV,yBAAA;EACA,aAAW;EACX,WAAW;EACX,WAAW,GACT,yBACA,YACA,cACA,eACA,WACA,eAMA,oBACA,sBACA,mCACA,SACF;EAEC;CACE,CAAA,GACL,SAAS,IACX;AACF;;;ACzIA,MAAa,kBAAkB,OAAO,OAAO,qBAAqB;CAChE,QAAQ;CACR,MAAM;AACR,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
|
-
import { isMac } from "./utils-
|
|
2
|
+
import { isMac } from "./utils-DnkrFYqY.js";
|
|
3
3
|
import { Children, Fragment } from "react";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -118,4 +118,4 @@ const keys = createKeyboardKeys();
|
|
|
118
118
|
//#endregion
|
|
119
119
|
export { Kbd, kbdVariants, keys };
|
|
120
120
|
|
|
121
|
-
//# sourceMappingURL=Kbd-
|
|
121
|
+
//# sourceMappingURL=Kbd-D1Azcc4g.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kbd-
|
|
1
|
+
{"version":3,"file":"Kbd-D1Azcc4g.js","names":[],"sources":["../src/components/Kbd/KbdSeparator.tsx","../src/components/Kbd/KbdGroup.tsx","../src/components/Kbd/styles.ts","../src/components/Kbd/Kbd.tsx","../src/components/Kbd/keyboardKeys.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentProps<'span'>;\n\n/**\n * The `+` / `then` glue between two `Kbd` keys.\n *\n * - Follows the muted chrome token by default.\n * - Turns white inside the legacy dark tooltip, which sets `data-tooltip-content`.\n */\nexport const KbdSeparator = ({ className, ...props }: Props) => (\n <span\n {...props}\n className={cn(\n 'tw:text-xs tw:text-muted-foreground',\n 'tw:[[data-tooltip-content=true]_&]:text-white/70',\n className,\n )}\n />\n);\n","import { Children, Fragment } from 'react';\nimport type { ComponentProps } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { KbdSeparator } from './KbdSeparator';\n\ntype Props = { separator?: string } & ComponentProps<'kbd'>;\n\nexport const KbdGroup = ({ ref, className, children, separator, ...props }: Props) => {\n return (\n <kbd\n {...props}\n ref={ref}\n className={cn('tw:inline-flex', 'tw:items-center', 'tw:gap-1', className)}\n >\n {separator\n ? // oxlint-disable-next-line react-x/no-children-to-array\n Children.toArray(children).map((child, index) => (\n // oxlint-disable-next-line\n <Fragment key={index}>\n {index > 0 && <KbdSeparator>{separator}</KbdSeparator>}\n {child}\n </Fragment>\n ))\n : children}\n </kbd>\n );\n};\n","import { cva } from 'class-variance-authority';\n\nexport const kbdVariants = cva(\n [\n 'tailwindcss-preflight',\n // style\n 'tw:pointer-events-none',\n 'tw:w-fit',\n 'tw:h-5',\n 'tw:min-w-5',\n\n // layout\n 'tw:inline-flex',\n 'tw:items-center',\n 'tw:justify-center',\n 'tw:gap-1',\n 'tw:shrink-0',\n\n // spacing\n 'tw:px-1',\n 'tw:[&_svg:not([class*=\"size-\"])]:size-2.5',\n\n 'tw:text-xs',\n 'tw:font-medium',\n\n 'tw:rounded',\n ],\n {\n defaultVariants: {\n variant: 'default',\n },\n variants: {\n variant: {\n default: 'tw:bg-muted tw:text-muted-foreground',\n // The shortcut-hint key inside a tooltip.\n //\n // - Matches `default` everywhere by default.\n // - Inverts to white on the legacy dark tooltip, which marks itself\n // with `data-tooltip-content`.\n // - Argo's tooltip is a light popover and sets no such attribute, so\n // white-on-white would otherwise render the key invisible.\n primary: [\n 'tw:bg-muted tw:text-muted-foreground',\n 'tw:[[data-tooltip-content=true]_&]:bg-white/20',\n 'tw:[[data-tooltip-content=true]_&]:text-white',\n ],\n },\n },\n },\n);\n","import type { ComponentProps } from 'react';\nimport type { VariantProps } from 'class-variance-authority';\n\nimport { KbdGroup } from './KbdGroup';\nimport { KbdSeparator } from './KbdSeparator';\nimport { kbdVariants } from './styles';\n\ntype Props = ComponentProps<'kbd'> & VariantProps<typeof kbdVariants>;\n\nexport const Kbd = ({ children, className, variant, ...rest }: Props) => (\n <kbd {...rest} className={kbdVariants({ className, variant })}>\n {children}\n </kbd>\n);\n\nKbd.Group = KbdGroup;\nKbd.Separator = KbdSeparator;\n","import { isMac } from '../../utils';\n\ntype KeyName = 'mod' | 'option' | 'shift' | 'enter';\ntype KeyRepresentation = { symbol: string; text: string };\n\ntype KeyDefinition = {\n mac: KeyRepresentation;\n windows: KeyRepresentation;\n};\n\nconst KEY_DEFINITIONS: Record<KeyName, KeyDefinition> = {\n mod: {\n mac: { symbol: '⌘', text: 'Command' },\n windows: { symbol: 'Ctrl', text: 'Ctrl' },\n },\n option: {\n mac: { symbol: '⌥', text: 'Option' },\n windows: { symbol: 'Alt', text: 'Alt' },\n },\n shift: {\n mac: { symbol: '⇧', text: 'Shift' },\n windows: { symbol: '⇧', text: 'Shift' },\n },\n enter: {\n mac: { symbol: '⏎', text: 'Enter' },\n windows: { symbol: '⏎', text: 'Enter' },\n },\n};\n\nconst createKeyboardKeys = () => {\n const keysObj: Record<KeyName, KeyRepresentation> = {} as Record<KeyName, KeyRepresentation>;\n\n for (const keyName of Object.keys(KEY_DEFINITIONS) as KeyName[]) {\n keysObj[keyName] = KEY_DEFINITIONS[keyName][isMac ? 'mac' : 'windows'];\n }\n\n return keysObj;\n};\n\nexport const keys = createKeyboardKeys();\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,gBAAgB,EAAE,WAAW,GAAG,YAC3C,oBAAC,QAAD;CACE,GAAI;CACJ,WAAW,GACT,uCACA,oDACA,SACF;AACD,CAAA;;;ACXH,MAAa,YAAY,EAAE,KAAK,WAAW,UAAU,WAAW,GAAG,YAAmB;CACpF,OACE,oBAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW,G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,QAAQ;CAG9D,OAAO;AACT;AAEA,MAAa,OAAO,mBAAmB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __exportAll } from "./rolldown-runtime-Bdc48AWt.js";
|
|
2
2
|
import { DiagramSkeleton } from "./internal/blocks/DiagramShared/DiagramSkeleton.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DiagramSource } from "./DiagramSource-C5_d8Gdj.js";
|
|
4
|
+
import { ZoomableSvg } from "./ZoomableSvg-U_VH3QRO.js";
|
|
4
5
|
import { createTokenResolver, useThemeAttributes } from "./themeTokens-qP1-55O7.js";
|
|
5
|
-
import {
|
|
6
|
+
import { flattenForeignObjectLabels, hasDrawnContent, makeResponsive } from "./svgTransforms-CJAYPk7o.js";
|
|
6
7
|
import { useEffect, useId, useRef, useState } from "react";
|
|
7
8
|
import { jsx } from "react/jsx-runtime";
|
|
8
9
|
import { renderMermaidSVG } from "beautiful-mermaid";
|
|
@@ -316,4 +317,4 @@ const MermaidDiagram = ({ code, renderActions }) => {
|
|
|
316
317
|
//#endregion
|
|
317
318
|
export { MermaidDiagram, MermaidDiagram_exports };
|
|
318
319
|
|
|
319
|
-
//# sourceMappingURL=MermaidDiagram-
|
|
320
|
+
//# sourceMappingURL=MermaidDiagram-CujFxVzk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MermaidDiagram-CXG5tC6J.js","names":[],"sources":["../src/blocks/MermaidDiagram/mermaidTheme.ts","../src/blocks/MermaidDiagram/MermaidDiagram.tsx"],"sourcesContent":["import type { RenderOptions } from 'beautiful-mermaid';\nimport type { MermaidConfig } from 'mermaid';\n\nimport type { ResolvedColorScheme } from '../../components/ThemeProvider/types';\nimport { createTokenResolver } from '../../utils/themeTokens';\n\nconst DIAGRAM_FONT = 'Inter, system-ui, sans-serif';\n\n/**\n * Fallback channels for the tokens the diagram palette reads, mirroring the\n * `:root` / `[data-theme='dark']` blocks of `styles.css`.\n *\n * `resolveToken` only reaches these when the live custom property is missing —\n * SSR, or a unit test that loads no CSS. In the browser the computed value wins,\n * which is what makes a customer brand re-skin the diagram for free.\n */\nconst FALLBACK_CHANNELS = {\n card: { light: '255 255 255', dark: '34 34 40' },\n 'card-foreground': { light: '30 41 59', dark: '229 230 236' },\n foreground: { light: '30 41 59', dark: '229 230 236' },\n muted: { light: '241 245 249', dark: '38 38 45' },\n 'muted-foreground': { light: '100 116 139', dark: '141 144 153' },\n border: { light: '229 231 235', dark: '52 53 62' },\n primary: { light: '37 99 235', dark: '31 143 255' },\n accent: { light: '224 242 254', dark: '30 58 95' },\n 'accent-foreground': { light: '13 65 127', dark: '147 197 253' },\n warning: { light: '138 82 16', dark: '255 190 92' },\n success: { light: '24 122 76', dark: '62 207 127' },\n destructive: { light: '220 38 38', dark: '229 72 77' },\n} as const;\n\ntype TokenName = keyof typeof FALLBACK_CHANNELS;\n\n/**\n * Binds a token lookup to one `getComputedStyle` snapshot for the whole palette.\n * Built per call, never hoisted: the values move with the scheme and the brand.\n */\nconst tokenReader = (scheme: ResolvedColorScheme, from?: Element | null) => {\n const resolve = createTokenResolver(from);\n return (name: TokenName, alpha?: number): string =>\n resolve(name, FALLBACK_CHANNELS[name][scheme], alpha);\n};\n\n/**\n * Palette for `beautiful-mermaid`'s synchronous renderer. It sets these as CSS\n * variables on the `<svg>` and derives everything else it needs from `bg` + `fg`\n * with `color-mix()` — which is why leaving them at the library defaults painted\n * a near-white node fill (#f8f8f8, mixed from a white `bg`) on a dark page.\n *\n * `transparent` keeps the page background showing through, so `bg` only feeds\n * those derivations; the node fill is pinned explicitly via `surface`.\n */\nexport const fastRenderOptions = (\n scheme: ResolvedColorScheme,\n from?: Element | null,\n): RenderOptions => {\n const token = tokenReader(scheme, from);\n\n return {\n bg: token('card'),\n fg: token('foreground'),\n line: token('border'),\n accent: token('primary'),\n muted: token('muted-foreground'),\n surface: token('muted'),\n border: token('border'),\n transparent: true,\n font: DIAGRAM_FONT,\n };\n};\n\n/**\n * Config for the async `mermaid` renderer (the fallback for dialects the fast\n * renderer can't parse, and for icon-pack diagrams).\n *\n * Built on the `base` theme so every colour comes from `themeVariables` rather\n * than mermaid's own light/dark palettes. Node chrome maps to the `accent` pair\n * (a tinted surface with a legible foreground in both schemes), containers to\n * `card`, and the gantt/note states to the status tokens — consumed as a low\n * alpha tint plus a solid mark, per the brand-neutrality contract, since the\n * status tokens themselves are text-legible colours rather than fills.\n */\nexport const mermaidConfig = (\n scheme: ResolvedColorScheme,\n from?: Element | null,\n): MermaidConfig => {\n const token = tokenReader(scheme, from);\n\n const surface = token('accent');\n const onSurface = token('accent-foreground');\n const container = token('card');\n const onContainer = token('card-foreground');\n const line = token('border');\n const stroke = token('primary');\n const text = token('foreground');\n\n return {\n startOnLoad: false,\n securityLevel: 'strict',\n theme: 'base',\n themeVariables: {\n darkMode: scheme === 'dark',\n background: container,\n primaryColor: surface,\n primaryTextColor: onSurface,\n primaryBorderColor: stroke,\n secondaryColor: container,\n secondaryTextColor: onContainer,\n secondaryBorderColor: line,\n tertiaryColor: token('warning', 0.15),\n tertiaryTextColor: token('warning'),\n tertiaryBorderColor: token('warning'),\n lineColor: line,\n textColor: text,\n mainBkg: surface,\n nodeBorder: stroke,\n clusterBkg: container,\n clusterBorder: line,\n titleColor: text,\n edgeLabelBackground: container,\n nodeTextColor: onSurface,\n actorBorder: stroke,\n actorBkg: surface,\n actorTextColor: onSurface,\n actorLineColor: line,\n signalColor: text,\n signalTextColor: text,\n labelBoxBkgColor: surface,\n labelBoxBorderColor: stroke,\n labelTextColor: onSurface,\n loopTextColor: text,\n noteBorderColor: token('warning'),\n noteBkgColor: token('warning', 0.15),\n noteTextColor: text,\n sectionBkgColor: surface,\n altSectionBkgColor: container,\n sectionBkgColor2: token('muted'),\n taskBorderColor: stroke,\n taskBkgColor: surface,\n taskTextColor: onSurface,\n taskTextDarkColor: text,\n taskTextLightColor: text,\n activeTaskBorderColor: stroke,\n activeTaskBkgColor: token('primary', 0.25),\n doneTaskBorderColor: token('success'),\n doneTaskBkgColor: token('success', 0.15),\n critBorderColor: token('destructive'),\n critBkgColor: token('destructive', 0.15),\n fontFamily: DIAGRAM_FONT,\n fontSize: '14px',\n },\n };\n};\n","import { useEffect, useId, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { renderMermaidSVG } from 'beautiful-mermaid';\nimport type mermaid from 'mermaid';\n\nimport type { ResolvedColorScheme } from '../../components/ThemeProvider/types';\nimport { useThemeAttributes } from '../../components/ThemeProvider/useThemeAttributes';\nimport { ZoomableSvg } from '../../components/ZoomableSvg';\nimport { DiagramSkeleton } from '../DiagramShared/DiagramSkeleton';\nimport { DiagramSource } from '../DiagramShared/DiagramSource';\nimport {\n flattenForeignObjectLabels,\n hasDrawnContent,\n makeResponsive,\n} from '../DiagramShared/svgTransforms';\n\nimport { fastRenderOptions, mermaidConfig } from './mermaidTheme';\n\ntype MermaidModule = { default: typeof mermaid };\n\nlet mermaidPromise: Promise<MermaidModule> | null = null;\n\n// Iconify icon pack registered with mermaid so `@{ icon: \"lucide:name\" }` node\n// shapes and `architecture-beta service <id>(lucide:name)` render — keeping\n// diagram glyphs consistent with the Lucide icons used across the rest of the UI.\n// The pack JSON resolves from a workspace dependency (no CDN fetch) via a dynamic\n// import, so it lands in its own lazy chunk and icons render offline / under a\n// strict CSP without weighing down the initial bundle.\nconst registerLucideIconPack = (m: typeof mermaid): void => {\n m.registerIconPacks([\n {\n name: 'lucide',\n loader: () => import('@iconify-json/lucide/icons.json').then((mod) => mod.default),\n },\n ]);\n};\n\nconst getMermaid = (): Promise<MermaidModule> => {\n if (!mermaidPromise) {\n mermaidPromise = import('mermaid')\n .then((m) => {\n registerLucideIconPack(m.default);\n return m;\n })\n .catch((err) => {\n mermaidPromise = null;\n throw err;\n });\n }\n return mermaidPromise;\n};\n\nconst stripFontImports = (svg: string): string =>\n svg.replace(/@import\\s+url\\([^)]*fonts\\.googleapis\\.com[^)]*\\);?\\s*/g, '');\n\n// beautiful-mermaid's synchronous renderer has no icon-pack support, so a diagram\n// using icon syntax must skip the fast path and take the async mermaid render\n// (which registers the pack). Matches:\n// - the flowchart / treeView icon shape `@{ icon: \"pack:name\" }`\n// - `architecture-beta` / `treeView` refs `icon|service|group <id>(pack:name)`\n// (the id between keyword and `(` is optional)\n// - legacy FontAwesome refs `fa:fa-*` / `fab:` embedded in node text\nconst hasIconSyntax = (code: string): boolean =>\n /@\\{[^}]*\\bicon\\s*:/.test(code) ||\n /\\b(?:icon|service|group)\\b[^\\n(]*\\(\\s*[\\w-]+:/.test(code) ||\n /\\bfa[bslr]?:fa-/.test(code);\n\nconst tryFastRender = (\n code: string,\n scheme: ResolvedColorScheme,\n from: Element | null,\n): string | null => {\n if (hasIconSyntax(code)) return null;\n try {\n const svg = stripFontImports(renderMermaidSVG(code, fastRenderOptions(scheme, from)));\n // A zero-sized result is a silent layout failure, not a diagram — take the\n // async fallback rather than caching an empty box. See `hasDrawnContent`.\n return hasDrawnContent(svg) ? svg : null;\n } catch (err) {\n // beautiful-mermaid can't parse every mermaid dialect; the async mermaid\n // renderer is the fallback. Log at debug so regressions are diagnosable\n // without noising up the console on the expected unsupported-syntax path.\n console.debug('[MermaidDiagram] fast render unavailable, using async fallback:', err);\n return null;\n }\n};\n\n/**\n * Whether a mermaid parse error means \"ran out of input\" rather than \"bad syntax\".\n *\n * - Mermaid's jison parsers report the end of input as token `1`, so a source\n * truncated mid-diagram — every intermediate frame of a streaming answer —\n * fails with `hash.token === 1`.\n * - Genuinely invalid syntax fails on a real token (`'ONLY_ONE'`, …) instead.\n * - Only a lower bound: some truncations do land on a real token and read as\n * invalid. Those fall through to the `<pre>` fallback for one frame and clear\n * when the next chunk arrives, which is the pre-existing behaviour.\n */\nconst isTruncatedDiagram = (err: unknown): boolean =>\n typeof err === 'object' && err !== null && 'hash' in err\n ? (err as { hash?: { token?: unknown } }).hash?.token === 1\n : false;\n\nconst RENDER_DEBOUNCE_MS = 300;\n\n// How long a truncated diagram is held as \"still arriving\" before it is shown as\n// source. Comfortably longer than the gap between streamed chunks, short enough\n// that an abandoned stream resolves while the reader is still looking at it.\nconst TRUNCATION_GRACE_MS = 2_000;\n\n// Module-level SVG cache — persists across component remounts (e.g. tab switches\n// that cause React to remount the tree). The colours are baked into the markup,\n// so the key is the code *plus* the theme key (scheme + brand): the same diagram\n// is a different SVG under a different colour scheme or brand.\nconst svgCache = new Map<string, string>();\n\nconst diagramCacheKey = (code: string, themeKey: string): string => `${themeKey}\\n${code}`;\n\n// Resolve an SVG synchronously: cache hit first, otherwise a fast synchronous\n// render. Caches the result and returns it, or null when neither is available\n// (the caller then falls back to the async mermaid render).\nconst resolveSyncSvg = (\n code: string,\n cacheKey: string,\n scheme: ResolvedColorScheme,\n from: Element | null,\n): string | null => {\n const cached = svgCache.get(cacheKey);\n if (cached) return cached;\n const fast = tryFastRender(code, scheme, from);\n if (fast) svgCache.set(cacheKey, fast);\n return fast;\n};\n\ntype Props = {\n /** Mermaid diagram source code. Supports flowchart, sequence, class, state, ER,\n * pie, gantt, and mindmap. Gantt `dateFormat HH:mm` (time-only) is not supported\n * by mermaid's dayjs parser — use `dateFormat YYYY-MM-DD HH:mm` with `axisFormat %H:%M` instead. */\n code: string;\n /** Extra toolbar controls (e.g. an `ExportMenu`), forwarded to `ZoomableSvg`.\n * Receives the sanitized SVG. Omit to keep the default toolbar. */\n renderActions?: (safeSvg: string) => ReactNode;\n};\n\nexport const MermaidDiagram = ({ code, renderActions }: Props) => {\n const id = useId();\n // Re-renders whenever the active colour scheme or brand changes, so the\n // diagram is re-rendered in the new palette instead of staying a light island\n // on a dark page. The scheme comes out of the same read as the key, so the\n // palette can never be resolved under one scheme and cached under the other —\n // see `useThemeAttributes` for why the theme context is a step ahead of the\n // CSS variables it stands for.\n // `scope` is the element the live tokens are read off — the enclosing `ThemeScope`'s own,\n // or `null` for `<html>`. It is part of `themeKey`, so a palette built before the scope\n // answered is never served afterwards.\n const { scheme, cacheKey: themeKey, scope } = useThemeAttributes();\n const cacheKey = diagramCacheKey(code, themeKey);\n\n const [svg, setSvg] = useState<string | null>(() =>\n resolveSyncSvg(code, cacheKey, scheme, scope),\n );\n const [renderFailed, setRenderFailed] = useState(false);\n const [truncated, setTruncated] = useState(false);\n const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const renderIdRef = useRef(0);\n\n // Synchronously reset stale state when the code or the theme changes, to avoid\n // a one-frame flash of the previous diagram.\n const [prevKey, setPrevKey] = useState(cacheKey);\n if (cacheKey !== prevKey) {\n setPrevKey(cacheKey);\n setSvg(resolveSyncSvg(code, cacheKey, scheme, scope));\n setRenderFailed(false);\n setTruncated(false);\n }\n\n useEffect(() => {\n // Synchronous results (cache hit / fast render) are already applied and\n // cached by the useState initializer (mount) and the render-phase reset\n // (code / theme change). Only the async fallback needs an effect.\n if (svgCache.has(cacheKey)) return;\n\n const currentRenderId = ++renderIdRef.current;\n\n if (debounceRef.current) {\n clearTimeout(debounceRef.current);\n }\n\n debounceRef.current = setTimeout(() => {\n getMermaid()\n .then(async (mermaidModule) => {\n if (renderIdRef.current !== currentRenderId) return;\n const rendererId = `mermaid-${id.replaceAll(':', '')}`;\n const container = document.createElement('div');\n container.style.visibility = 'hidden';\n container.style.position = 'absolute';\n container.style.top = '-9999px';\n container.style.width = '900px';\n document.body.appendChild(container);\n // Re-applied per render rather than once at import: `initialize` is the\n // only way to change mermaid's palette, and the palette follows the\n // active scheme/brand.\n mermaidModule.default.initialize(mermaidConfig(scheme, scope));\n try {\n const result = await mermaidModule.default.render(rendererId, code, container);\n if (renderIdRef.current === currentRenderId && result) {\n const svgOutput = flattenForeignObjectLabels(result.svg);\n svgCache.set(cacheKey, svgOutput);\n setSvg(svgOutput);\n setRenderFailed(false);\n setTruncated(false);\n }\n } finally {\n container.remove();\n }\n })\n .catch((err: unknown) => {\n if (renderIdRef.current !== currentRenderId) return;\n setSvg(null);\n // A diagram arriving a chunk at a time is invalid at almost every\n // intermediate length, so a truncation is treated as \"not ready\" and\n // holds the skeleton instead of the raw-code `<pre>`. It is held for a\n // bounded wait, not indefinitely: a stream that dies mid-entity — or a\n // diagram a user simply left unterminated — never gets a next chunk, and\n // a skeleton that stays forever is worse than showing the source. The\n // timer is cleared by the effect teardown, so any further chunk cancels\n // it and re-renders.\n if (isTruncatedDiagram(err)) {\n console.debug('[MermaidDiagram] incomplete diagram, awaiting more input:', err);\n setTruncated(true);\n return;\n }\n console.error('[MermaidDiagram] fallback failed:', err);\n setRenderFailed(true);\n });\n }, RENDER_DEBOUNCE_MS);\n\n const timer = debounceRef.current;\n const renderId = renderIdRef;\n return () => {\n renderId.current++;\n if (timer) {\n clearTimeout(timer);\n }\n };\n }, [cacheKey, code, id, scheme, scope]);\n\n // A truncated diagram is held as \"still arriving\" for a bounded wait, not\n // indefinitely: a stream that dies mid-entity — or a diagram a user left\n // unterminated — never sends another chunk, and a skeleton that stays forever\n // is worse than showing the source. Any further chunk changes `code`, which\n // resets `truncated` and tears this timer down.\n useEffect(() => {\n if (!truncated) return;\n const timer = setTimeout(() => setRenderFailed(true), TRUNCATION_GRACE_MS);\n return () => clearTimeout(timer);\n }, [truncated, cacheKey]);\n\n const processedSvg = svg ? makeResponsive(svg) : null;\n\n if (renderFailed) {\n return <DiagramSource code={code} />;\n }\n\n if (processedSvg) {\n return (\n <ZoomableSvg\n key={code}\n html={processedSvg}\n copyText={`\\`\\`\\`mermaid\\n${code}\\n\\`\\`\\``}\n className=\"tw:my-3\"\n allowForeignObject\n renderActions={renderActions}\n />\n );\n }\n\n return <DiagramSkeleton />;\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,eAAe;;;;;;;;;AAUrB,MAAM,oBAAoB;CACxB,MAAM;EAAE,OAAO;EAAe,MAAM;CAAW;CAC/C,mBAAmB;EAAE,OAAO;EAAY,MAAM;CAAc;CAC5D,YAAY;EAAE,OAAO;EAAY,MAAM;CAAc;CACrD,OAAO;EAAE,OAAO;EAAe,MAAM;CAAW;CAChD,oBAAoB;EAAE,OAAO;EAAe,MAAM;CAAc;CAChE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;EAAM;EAAI;EAAQ;CAAK,CAAC;CAOtC,gBAAgB;EACd,IAAI,CAAC,WAAW;EAChB,MAAM,QAAQ,iBAAiB,gBAAgB,IAAI,GAAG,mBAAmB;EACzE,aAAa,aAAa,KAAK;CACjC,GAAG,CAAC,WAAW,QAAQ,CAAC;CAExB,MAAM,eAAe,MAAM,eAAe,GAAG,IAAI;CAEjD,IAAI,cACF,OAAO,oBAAC,eAAD,EAAqB,KAAO,CAAA;CAGrC,IAAI,cACF,OACE,oBAAC,aAAD;EAEE,MAAM;EACN,UAAU,kBAAkB,KAAK;EACjC,WAAU;EACV,oBAAA;EACe;CAChB,GANM,IAMN;CAIL,OAAO,oBAAC,iBAAD,CAAkB,CAAA;AAC3B"}
|
|
1
|
+
{"version":3,"file":"MermaidDiagram-CujFxVzk.js","names":[],"sources":["../src/blocks/MermaidDiagram/mermaidTheme.ts","../src/blocks/MermaidDiagram/MermaidDiagram.tsx"],"sourcesContent":["import type { RenderOptions } from 'beautiful-mermaid';\nimport type { MermaidConfig } from 'mermaid';\n\nimport type { ResolvedColorScheme } from '../../components/ThemeProvider/types';\nimport { createTokenResolver } from '../../utils/themeTokens';\n\nconst DIAGRAM_FONT = 'Inter, system-ui, sans-serif';\n\n/**\n * Fallback channels for the tokens the diagram palette reads, mirroring the\n * `:root` / `[data-theme='dark']` blocks of `styles.css`.\n *\n * `resolveToken` only reaches these when the live custom property is missing —\n * SSR, or a unit test that loads no CSS. In the browser the computed value wins,\n * which is what makes a customer brand re-skin the diagram for free.\n */\nconst FALLBACK_CHANNELS = {\n card: { light: '255 255 255', dark: '34 34 40' },\n 'card-foreground': { light: '30 41 59', dark: '229 230 236' },\n foreground: { light: '30 41 59', dark: '229 230 236' },\n muted: { light: '241 245 249', dark: '38 38 45' },\n 'muted-foreground': { light: '100 116 139', dark: '141 144 153' },\n border: { light: '229 231 235', dark: '52 53 62' },\n primary: { light: '37 99 235', dark: '31 143 255' },\n accent: { light: '224 242 254', dark: '30 58 95' },\n 'accent-foreground': { light: '13 65 127', dark: '147 197 253' },\n warning: { light: '138 82 16', dark: '255 190 92' },\n success: { light: '24 122 76', dark: '62 207 127' },\n destructive: { light: '220 38 38', dark: '229 72 77' },\n} as const;\n\ntype TokenName = keyof typeof FALLBACK_CHANNELS;\n\n/**\n * Binds a token lookup to one `getComputedStyle` snapshot for the whole palette.\n * Built per call, never hoisted: the values move with the scheme and the brand.\n */\nconst tokenReader = (scheme: ResolvedColorScheme, from?: Element | null) => {\n const resolve = createTokenResolver(from);\n return (name: TokenName, alpha?: number): string =>\n resolve(name, FALLBACK_CHANNELS[name][scheme], alpha);\n};\n\n/**\n * Palette for `beautiful-mermaid`'s synchronous renderer. It sets these as CSS\n * variables on the `<svg>` and derives everything else it needs from `bg` + `fg`\n * with `color-mix()` — which is why leaving them at the library defaults painted\n * a near-white node fill (#f8f8f8, mixed from a white `bg`) on a dark page.\n *\n * `transparent` keeps the page background showing through, so `bg` only feeds\n * those derivations; the node fill is pinned explicitly via `surface`.\n */\nexport const fastRenderOptions = (\n scheme: ResolvedColorScheme,\n from?: Element | null,\n): RenderOptions => {\n const token = tokenReader(scheme, from);\n\n return {\n bg: token('card'),\n fg: token('foreground'),\n line: token('border'),\n accent: token('primary'),\n muted: token('muted-foreground'),\n surface: token('muted'),\n border: token('border'),\n transparent: true,\n font: DIAGRAM_FONT,\n };\n};\n\n/**\n * Config for the async `mermaid` renderer (the fallback for dialects the fast\n * renderer can't parse, and for icon-pack diagrams).\n *\n * Built on the `base` theme so every colour comes from `themeVariables` rather\n * than mermaid's own light/dark palettes. Node chrome maps to the `accent` pair\n * (a tinted surface with a legible foreground in both schemes), containers to\n * `card`, and the gantt/note states to the status tokens — consumed as a low\n * alpha tint plus a solid mark, per the brand-neutrality contract, since the\n * status tokens themselves are text-legible colours rather than fills.\n */\nexport const mermaidConfig = (\n scheme: ResolvedColorScheme,\n from?: Element | null,\n): MermaidConfig => {\n const token = tokenReader(scheme, from);\n\n const surface = token('accent');\n const onSurface = token('accent-foreground');\n const container = token('card');\n const onContainer = token('card-foreground');\n const line = token('border');\n const stroke = token('primary');\n const text = token('foreground');\n\n return {\n startOnLoad: false,\n securityLevel: 'strict',\n theme: 'base',\n themeVariables: {\n darkMode: scheme === 'dark',\n background: container,\n primaryColor: surface,\n primaryTextColor: onSurface,\n primaryBorderColor: stroke,\n secondaryColor: container,\n secondaryTextColor: onContainer,\n secondaryBorderColor: line,\n tertiaryColor: token('warning', 0.15),\n tertiaryTextColor: token('warning'),\n tertiaryBorderColor: token('warning'),\n lineColor: line,\n textColor: text,\n mainBkg: surface,\n nodeBorder: stroke,\n clusterBkg: container,\n clusterBorder: line,\n titleColor: text,\n edgeLabelBackground: container,\n nodeTextColor: onSurface,\n actorBorder: stroke,\n actorBkg: surface,\n actorTextColor: onSurface,\n actorLineColor: line,\n signalColor: text,\n signalTextColor: text,\n labelBoxBkgColor: surface,\n labelBoxBorderColor: stroke,\n labelTextColor: onSurface,\n loopTextColor: text,\n noteBorderColor: token('warning'),\n noteBkgColor: token('warning', 0.15),\n noteTextColor: text,\n sectionBkgColor: surface,\n altSectionBkgColor: container,\n sectionBkgColor2: token('muted'),\n taskBorderColor: stroke,\n taskBkgColor: surface,\n taskTextColor: onSurface,\n taskTextDarkColor: text,\n taskTextLightColor: text,\n activeTaskBorderColor: stroke,\n activeTaskBkgColor: token('primary', 0.25),\n doneTaskBorderColor: token('success'),\n doneTaskBkgColor: token('success', 0.15),\n critBorderColor: token('destructive'),\n critBkgColor: token('destructive', 0.15),\n fontFamily: DIAGRAM_FONT,\n fontSize: '14px',\n },\n };\n};\n","import { useEffect, useId, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { renderMermaidSVG } from 'beautiful-mermaid';\nimport type mermaid from 'mermaid';\n\nimport type { ResolvedColorScheme } from '../../components/ThemeProvider/types';\nimport { useThemeAttributes } from '../../components/ThemeProvider/useThemeAttributes';\nimport { ZoomableSvg } from '../../components/ZoomableSvg';\nimport { DiagramSkeleton } from '../DiagramShared/DiagramSkeleton';\nimport { DiagramSource } from '../DiagramShared/DiagramSource';\nimport {\n flattenForeignObjectLabels,\n hasDrawnContent,\n makeResponsive,\n} from '../DiagramShared/svgTransforms';\n\nimport { fastRenderOptions, mermaidConfig } from './mermaidTheme';\n\ntype MermaidModule = { default: typeof mermaid };\n\nlet mermaidPromise: Promise<MermaidModule> | null = null;\n\n// Iconify icon pack registered with mermaid so `@{ icon: \"lucide:name\" }` node\n// shapes and `architecture-beta service <id>(lucide:name)` render — keeping\n// diagram glyphs consistent with the Lucide icons used across the rest of the UI.\n// The pack JSON resolves from a workspace dependency (no CDN fetch) via a dynamic\n// import, so it lands in its own lazy chunk and icons render offline / under a\n// strict CSP without weighing down the initial bundle.\nconst registerLucideIconPack = (m: typeof mermaid): void => {\n m.registerIconPacks([\n {\n name: 'lucide',\n loader: () => import('@iconify-json/lucide/icons.json').then((mod) => mod.default),\n },\n ]);\n};\n\nconst getMermaid = (): Promise<MermaidModule> => {\n if (!mermaidPromise) {\n mermaidPromise = import('mermaid')\n .then((m) => {\n registerLucideIconPack(m.default);\n return m;\n })\n .catch((err) => {\n mermaidPromise = null;\n throw err;\n });\n }\n return mermaidPromise;\n};\n\nconst stripFontImports = (svg: string): string =>\n svg.replace(/@import\\s+url\\([^)]*fonts\\.googleapis\\.com[^)]*\\);?\\s*/g, '');\n\n// beautiful-mermaid's synchronous renderer has no icon-pack support, so a diagram\n// using icon syntax must skip the fast path and take the async mermaid render\n// (which registers the pack). Matches:\n// - the flowchart / treeView icon shape `@{ icon: \"pack:name\" }`\n// - `architecture-beta` / `treeView` refs `icon|service|group <id>(pack:name)`\n// (the id between keyword and `(` is optional)\n// - legacy FontAwesome refs `fa:fa-*` / `fab:` embedded in node text\nconst hasIconSyntax = (code: string): boolean =>\n /@\\{[^}]*\\bicon\\s*:/.test(code) ||\n /\\b(?:icon|service|group)\\b[^\\n(]*\\(\\s*[\\w-]+:/.test(code) ||\n /\\bfa[bslr]?:fa-/.test(code);\n\nconst tryFastRender = (\n code: string,\n scheme: ResolvedColorScheme,\n from: Element | null,\n): string | null => {\n if (hasIconSyntax(code)) return null;\n try {\n const svg = stripFontImports(renderMermaidSVG(code, fastRenderOptions(scheme, from)));\n // A zero-sized result is a silent layout failure, not a diagram — take the\n // async fallback rather than caching an empty box. See `hasDrawnContent`.\n return hasDrawnContent(svg) ? svg : null;\n } catch (err) {\n // beautiful-mermaid can't parse every mermaid dialect; the async mermaid\n // renderer is the fallback. Log at debug so regressions are diagnosable\n // without noising up the console on the expected unsupported-syntax path.\n console.debug('[MermaidDiagram] fast render unavailable, using async fallback:', err);\n return null;\n }\n};\n\n/**\n * Whether a mermaid parse error means \"ran out of input\" rather than \"bad syntax\".\n *\n * - Mermaid's jison parsers report the end of input as token `1`, so a source\n * truncated mid-diagram — every intermediate frame of a streaming answer —\n * fails with `hash.token === 1`.\n * - Genuinely invalid syntax fails on a real token (`'ONLY_ONE'`, …) instead.\n * - Only a lower bound: some truncations do land on a real token and read as\n * invalid. Those fall through to the `<pre>` fallback for one frame and clear\n * when the next chunk arrives, which is the pre-existing behaviour.\n */\nconst isTruncatedDiagram = (err: unknown): boolean =>\n typeof err === 'object' && err !== null && 'hash' in err\n ? (err as { hash?: { token?: unknown } }).hash?.token === 1\n : false;\n\nconst RENDER_DEBOUNCE_MS = 300;\n\n// How long a truncated diagram is held as \"still arriving\" before it is shown as\n// source. Comfortably longer than the gap between streamed chunks, short enough\n// that an abandoned stream resolves while the reader is still looking at it.\nconst TRUNCATION_GRACE_MS = 2_000;\n\n// Module-level SVG cache — persists across component remounts (e.g. tab switches\n// that cause React to remount the tree). The colours are baked into the markup,\n// so the key is the code *plus* the theme key (scheme + brand): the same diagram\n// is a different SVG under a different colour scheme or brand.\nconst svgCache = new Map<string, string>();\n\nconst diagramCacheKey = (code: string, themeKey: string): string => `${themeKey}\\n${code}`;\n\n// Resolve an SVG synchronously: cache hit first, otherwise a fast synchronous\n// render. Caches the result and returns it, or null when neither is available\n// (the caller then falls back to the async mermaid render).\nconst resolveSyncSvg = (\n code: string,\n cacheKey: string,\n scheme: ResolvedColorScheme,\n from: Element | null,\n): string | null => {\n const cached = svgCache.get(cacheKey);\n if (cached) return cached;\n const fast = tryFastRender(code, scheme, from);\n if (fast) svgCache.set(cacheKey, fast);\n return fast;\n};\n\ntype Props = {\n /** Mermaid diagram source code. Supports flowchart, sequence, class, state, ER,\n * pie, gantt, and mindmap. Gantt `dateFormat HH:mm` (time-only) is not supported\n * by mermaid's dayjs parser — use `dateFormat YYYY-MM-DD HH:mm` with `axisFormat %H:%M` instead. */\n code: string;\n /** Extra toolbar controls (e.g. an `ExportMenu`), forwarded to `ZoomableSvg`.\n * Receives the sanitized SVG. Omit to keep the default toolbar. */\n renderActions?: (safeSvg: string) => ReactNode;\n};\n\nexport const MermaidDiagram = ({ code, renderActions }: Props) => {\n const id = useId();\n // Re-renders whenever the active colour scheme or brand changes, so the\n // diagram is re-rendered in the new palette instead of staying a light island\n // on a dark page. The scheme comes out of the same read as the key, so the\n // palette can never be resolved under one scheme and cached under the other —\n // see `useThemeAttributes` for why the theme context is a step ahead of the\n // CSS variables it stands for.\n // `scope` is the element the live tokens are read off — the enclosing `ThemeScope`'s own,\n // or `null` for `<html>`. It is part of `themeKey`, so a palette built before the scope\n // answered is never served afterwards.\n const { scheme, cacheKey: themeKey, scope } = useThemeAttributes();\n const cacheKey = diagramCacheKey(code, themeKey);\n\n const [svg, setSvg] = useState<string | null>(() =>\n resolveSyncSvg(code, cacheKey, scheme, scope),\n );\n const [renderFailed, setRenderFailed] = useState(false);\n const [truncated, setTruncated] = useState(false);\n const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const renderIdRef = useRef(0);\n\n // Synchronously reset stale state when the code or the theme changes, to avoid\n // a one-frame flash of the previous diagram.\n const [prevKey, setPrevKey] = useState(cacheKey);\n if (cacheKey !== prevKey) {\n setPrevKey(cacheKey);\n setSvg(resolveSyncSvg(code, cacheKey, scheme, scope));\n setRenderFailed(false);\n setTruncated(false);\n }\n\n useEffect(() => {\n // Synchronous results (cache hit / fast render) are already applied and\n // cached by the useState initializer (mount) and the render-phase reset\n // (code / theme change). Only the async fallback needs an effect.\n if (svgCache.has(cacheKey)) return;\n\n const currentRenderId = ++renderIdRef.current;\n\n if (debounceRef.current) {\n clearTimeout(debounceRef.current);\n }\n\n debounceRef.current = setTimeout(() => {\n getMermaid()\n .then(async (mermaidModule) => {\n if (renderIdRef.current !== currentRenderId) return;\n const rendererId = `mermaid-${id.replaceAll(':', '')}`;\n const container = document.createElement('div');\n container.style.visibility = 'hidden';\n container.style.position = 'absolute';\n container.style.top = '-9999px';\n container.style.width = '900px';\n document.body.appendChild(container);\n // Re-applied per render rather than once at import: `initialize` is the\n // only way to change mermaid's palette, and the palette follows the\n // active scheme/brand.\n mermaidModule.default.initialize(mermaidConfig(scheme, scope));\n try {\n const result = await mermaidModule.default.render(rendererId, code, container);\n if (renderIdRef.current === currentRenderId && result) {\n const svgOutput = flattenForeignObjectLabels(result.svg);\n svgCache.set(cacheKey, svgOutput);\n setSvg(svgOutput);\n setRenderFailed(false);\n setTruncated(false);\n }\n } finally {\n container.remove();\n }\n })\n .catch((err: unknown) => {\n if (renderIdRef.current !== currentRenderId) return;\n setSvg(null);\n // A diagram arriving a chunk at a time is invalid at almost every\n // intermediate length, so a truncation is treated as \"not ready\" and\n // holds the skeleton instead of the raw-code `<pre>`. It is held for a\n // bounded wait, not indefinitely: a stream that dies mid-entity — or a\n // diagram a user simply left unterminated — never gets a next chunk, and\n // a skeleton that stays forever is worse than showing the source. The\n // timer is cleared by the effect teardown, so any further chunk cancels\n // it and re-renders.\n if (isTruncatedDiagram(err)) {\n console.debug('[MermaidDiagram] incomplete diagram, awaiting more input:', err);\n setTruncated(true);\n return;\n }\n console.error('[MermaidDiagram] fallback failed:', err);\n setRenderFailed(true);\n });\n }, RENDER_DEBOUNCE_MS);\n\n const timer = debounceRef.current;\n const renderId = renderIdRef;\n return () => {\n renderId.current++;\n if (timer) {\n clearTimeout(timer);\n }\n };\n }, [cacheKey, code, id, scheme, scope]);\n\n // A truncated diagram is held as \"still arriving\" for a bounded wait, not\n // indefinitely: a stream that dies mid-entity — or a diagram a user left\n // unterminated — never sends another chunk, and a skeleton that stays forever\n // is worse than showing the source. Any further chunk changes `code`, which\n // resets `truncated` and tears this timer down.\n useEffect(() => {\n if (!truncated) return;\n const timer = setTimeout(() => setRenderFailed(true), TRUNCATION_GRACE_MS);\n return () => clearTimeout(timer);\n }, [truncated, cacheKey]);\n\n const processedSvg = svg ? makeResponsive(svg) : null;\n\n if (renderFailed) {\n return <DiagramSource code={code} />;\n }\n\n if (processedSvg) {\n return (\n <ZoomableSvg\n key={code}\n html={processedSvg}\n copyText={`\\`\\`\\`mermaid\\n${code}\\n\\`\\`\\``}\n className=\"tw:my-3\"\n allowForeignObject\n renderActions={renderActions}\n />\n );\n }\n\n return <DiagramSkeleton />;\n};\n"],"mappings":";;;;;;;;;;AAMA,MAAM,eAAe;;;;;;;;;AAUrB,MAAM,oBAAoB;CACxB,MAAM;EAAE,OAAO;EAAe,MAAM;CAAW;CAC/C,mBAAmB;EAAE,OAAO;EAAY,MAAM;CAAc;CAC5D,YAAY;EAAE,OAAO;EAAY,MAAM;CAAc;CACrD,OAAO;EAAE,OAAO;EAAe,MAAM;CAAW;CAChD,oBAAoB;EAAE,OAAO;EAAe,MAAM;CAAc;CAChE,QAAQ;EAAE,OAAO;EAAe,MAAM;CAAW;CACjD,SAAS;EAAE,OAAO;EAAa,MAAM;CAAa;CAClD,QAAQ;EAAE,OAAO;EAAe,MAAM;CAAW;CACjD,qBAAqB;EAAE,OAAO;EAAa,MAAM;CAAc;CAC/D,SAAS;EAAE,OAAO;EAAa,MAAM;CAAa;CAClD,SAAS;EAAE,OAAO;EAAa,MAAM;CAAa;CAClD,aAAa;EAAE,OAAO;EAAa,MAAM;CAAY;AACvD;;;;;AAQA,MAAM,eAAe,QAA6B,SAA0B;CAC1E,MAAM,UAAU,oBA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ACjC,WAAU;EACV,oBAAA;EACe;CAChB,GANM,IAMN;CAIL,OAAO,oBAAC,iBAAD,CAAkB,CAAA;AAC3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
|
-
import { Tooltip } from "./utils-
|
|
2
|
+
import { Tooltip } from "./utils-DnkrFYqY.js";
|
|
3
3
|
import { Button } from "./Button-DsRrU5F1.js";
|
|
4
4
|
import { ButtonGroup } from "./internal/components/ButtonGroup.js";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -30,4 +30,4 @@ MultiActionButtonGroup.Button = MultiActionButton;
|
|
|
30
30
|
//#endregion
|
|
31
31
|
export { MultiActionButtonGroup };
|
|
32
32
|
|
|
33
|
-
//# sourceMappingURL=MultiActionButtonGroup-
|
|
33
|
+
//# sourceMappingURL=MultiActionButtonGroup-CNNoBQbv.js.map
|
package/dist/{MultiActionButtonGroup-DokHbPgM.js.map → MultiActionButtonGroup-CNNoBQbv.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiActionButtonGroup-
|
|
1
|
+
{"version":3,"file":"MultiActionButtonGroup-CNNoBQbv.js","names":[],"sources":["../src/blocks/MultiActionButtonGroup/MultiActionButton.tsx","../src/blocks/MultiActionButtonGroup/MultiActionButtonGroup.tsx"],"sourcesContent":["import type { ComponentProps, ReactNode } from 'react';\n\nimport { Button } from '../../components/Button';\nimport { Tooltip } from '../../components/Tooltip';\n\ntype Props = {\n disabled?: boolean;\n icon: ReactNode;\n isLoading?: boolean;\n label: string;\n onClick: ComponentProps<typeof Button>['onClick'];\n tooltipContent: ReactNode;\n tooltipVariant?: ComponentProps<typeof Tooltip>['variant'];\n 'data-testid'?: string;\n};\n\nexport const MultiActionButton = ({\n disabled,\n icon,\n isLoading,\n label,\n onClick,\n tooltipContent,\n tooltipVariant,\n 'data-testid': dataTestId,\n}: Props) => (\n <Tooltip placement=\"top\" tooltip={tooltipContent} triggerAsChild variant={tooltipVariant}>\n <Button\n disabled={disabled}\n isLoading={isLoading}\n aria-label={label}\n onClick={onClick}\n variant=\"invisible\"\n size=\"icon\"\n data-testid={dataTestId}\n >\n {!isLoading && icon}\n </Button>\n </Tooltip>\n);\n","import type { PropsWithChildren } from 'react';\n\nimport { ButtonGroup } from '../../components/ButtonGroup';\nimport { cn } from '../../utils';\n\nimport { MultiActionButton } from './MultiActionButton';\n\ntype Props = {\n className?: string;\n} & PropsWithChildren;\n\nexport const MultiActionButtonGroup = ({ children, className }: Props) => (\n <ButtonGroup className={cn('tw:text-nowrap', className)}>{children}</ButtonGroup>\n);\n\nMultiActionButtonGroup.Button = MultiActionButton;\n"],"mappings":";;;;;;AAgBA,MAAa,qBAAqB,EAChC,UACA,MACA,WACA,OACA,SACA,gBACA,gBACA,eAAe,iBAEf,oBAAC,SAAD;CAAS,WAAU;CAAM,SAAS;CAAgB,gBAAA;CAAe,SAAS;CACxE,UAAA,oBAAC,QAAD;EACY;EACC;EACX,cAAY;EACH;EACT,SAAQ;EACR,MAAK;EACL,eAAa;EAEZ,UAAA,CAAC,aAAa;CACT,CAAA;AACD,CAAA;;;AC3BX,MAAa,0BAA0B,EAAE,UAAU,gBACjD,oBAAC,aAAD;CAAa,WAAW,GAAG,kBAAkB,SAAS;CAAI;AAAsB,CAAA;AAGlF,uBAAuB,SAAS"}
|
|
@@ -2,7 +2,7 @@ import { cn } from "./classNames-BzrkDnOD.js";
|
|
|
2
2
|
import { ChevronDown, Plus, X } from "./icons-Cek151jC.js";
|
|
3
3
|
import { Button } from "./Button-DsRrU5F1.js";
|
|
4
4
|
import { Popover } from "./Popover-BEbQrC_P.js";
|
|
5
|
-
import { Badge } from "./Badge-
|
|
5
|
+
import { Badge } from "./Badge-o5jURtpB.js";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
//#region src/blocks/PageToolbar/PageToolbarToken.tsx
|
|
8
8
|
/**
|
|
@@ -150,4 +150,4 @@ const PageToolbar = Object.assign(Root, {
|
|
|
150
150
|
//#endregion
|
|
151
151
|
export { PageToolbar };
|
|
152
152
|
|
|
153
|
-
//# sourceMappingURL=PageToolbar-
|
|
153
|
+
//# sourceMappingURL=PageToolbar-BKVJiDAL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageToolbar-
|
|
1
|
+
{"version":3,"file":"PageToolbar-BKVJiDAL.js","names":[],"sources":["../src/blocks/PageToolbar/PageToolbarToken.tsx","../src/blocks/PageToolbar/PageToolbar.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, ReactNode } from 'react';\n\nimport { Badge } from '../../components/Badge';\nimport { Button } from '../../components/Button';\nimport { Popover } from '../../components/Popover';\nimport { ChevronDown, X } from '../../icons';\n\ntype PageToolbarTokenProps = Omit<\n ComponentPropsWithoutRef<typeof Badge>,\n 'variant' | 'color' | 'suffix' | 'children' | 'asChild' | 'popover'\n> & {\n children: ReactNode;\n /** Popover content rendered when the chevron-down trigger is clicked — typically a value editor. */\n popover: ReactNode;\n onRemove: () => void;\n removeAriaLabel: string;\n};\n\n/**\n * Editable filter token (Query Builder variant) — `Badge` pill with a `chevron-down`\n * popover trigger for editing values and an `×` dismiss button. The popover content\n * is supplied by the caller via the `popover` slot (typically a `Combobox` or option list).\n */\nexport const PageToolbarToken = ({\n children,\n popover,\n onRemove,\n removeAriaLabel,\n ...props\n}: PageToolbarTokenProps) => (\n <Popover>\n <Badge\n {...props}\n asChild\n variant=\"pill\"\n color=\"blue-inverse\"\n suffix={\n <Button\n type=\"button\"\n variant=\"inline\"\n size=\"icon-2xs\"\n aria-label={removeAriaLabel}\n onClick={onRemove}\n >\n <X className=\"tw:size-3\" />\n </Button>\n }\n >\n <Popover.Trigger\n type=\"button\"\n className=\"tw:inline-flex tw:cursor-pointer tw:items-center tw:gap-1 tw:bg-inherit tw:text-inherit tailwindcss-preflight\"\n >\n {children}\n <ChevronDown className=\"tw:size-3\" />\n </Popover.Trigger>\n </Badge>\n <Popover.Content align=\"start\">{popover}</Popover.Content>\n </Popover>\n);\n","import type { ComponentProps, ComponentPropsWithoutRef, ReactNode } from 'react';\n\nimport { Badge } from '../../components/Badge';\nimport { Button } from '../../components/Button';\nimport { Plus, X } from '../../icons';\nimport { cn } from '../../utils';\n\nimport { PageToolbarToken } from './PageToolbarToken';\n\ntype DivProps = ComponentProps<'div'>;\n\nconst Root = ({ ref, className, children, ...props }: DivProps) => (\n <div\n ref={ref}\n className={cn('tw:flex tw:flex-wrap tw:items-center tw:gap-3 tw:w-full', className)}\n {...props}\n >\n {children}\n </div>\n);\n\nconst Search = ({ ref, className, children, ...props }: DivProps) => (\n <div\n ref={ref}\n className={cn(\n 'tw:mr-auto tw:flex tw:items-center tw:gap-2 tw:w-full tw:sm:w-auto tw:sm:min-w-64 tw:sm:max-w-md',\n // The slot sizes itself between `min-w-64` and `max-w-md`, so the search field has to fill it —\n // without this the input stays content-width (≈224px inside a 448px slot) and truncates its own\n // placeholder, and every caller ends up hand-picking a width class to compensate.\n //\n // - First child only. The documented composition is the search field followed by filter pills;\n // stretching every child would size the pills to match the input.\n // - `min-w-0` so a long value shrinks the input rather than overflowing the toolbar.\n 'tw:*:first:min-w-0 tw:*:first:flex-1',\n className,\n )}\n {...props}\n >\n {children}\n </div>\n);\n\nconst Right = ({ ref, className, children, ...props }: DivProps) => (\n <div\n ref={ref}\n className={cn('tw:flex tw:flex-wrap tw:items-center tw:gap-2', className)}\n {...props}\n >\n {children}\n </div>\n);\n\nconst ControlGroup = ({ ref, className, children, ...props }: DivProps) => (\n <div ref={ref} className={cn('tw:flex tw:items-center tw:gap-2', className)} {...props}>\n {children}\n </div>\n);\n\nconst ActiveFilters = ({ ref, className, children, ...props }: DivProps) => (\n <div\n ref={ref}\n className={cn('tw:flex tw:flex-wrap tw:items-center tw:gap-2 tw:basis-full', className)}\n {...props}\n >\n {children}\n </div>\n);\n\ntype ChipProps = Omit<\n ComponentPropsWithoutRef<typeof Badge>,\n 'variant' | 'color' | 'suffix' | 'children'\n> & {\n children: ReactNode;\n onRemove: () => void;\n removeAriaLabel: string;\n};\n\nconst Chip = ({ children, onRemove, removeAriaLabel, ...props }: ChipProps) => (\n <Badge\n {...props}\n variant=\"pill\"\n color=\"blue-inverse\"\n suffix={\n <Button\n type=\"button\"\n variant=\"inline\"\n size=\"icon-2xs\"\n aria-label={removeAriaLabel}\n onClick={onRemove}\n >\n <X className=\"tw:size-3\" />\n </Button>\n }\n >\n {children}\n </Badge>\n);\n\ntype ActionProps = ComponentPropsWithoutRef<typeof Button>;\n\nconst AddFilter = ({ className, children, ...props }: ActionProps) => (\n <Button variant=\"invisible\" size=\"small\" className={cn('tw:gap-1.5', className)} {...props}>\n <Plus className=\"tw:size-4\" />\n {children ?? 'Add filter'}\n </Button>\n);\n\nconst Clear = ({ className, children, ...props }: ActionProps) => (\n <Button variant=\"invisible\" size=\"small\" className={cn('tw:ml-auto', className)} {...props}>\n {children ?? 'Clear all'}\n </Button>\n);\n\n/**\n * Two-row toolbar for index pages — search on the left, filter / sort / utility / view\n * controls on the right, an optional Active Filters row below for filter chips or tokens.\n *\n * **When to use:** every index page that supports search or filtering. Hosts inside\n * `PageLayout` as the search / filter row, between `PageLayout.Header` and `PageLayout.Content`.\n * **When NOT to use:** detail pages, form pages, or anywhere there is no search / filter\n * surface. For routing-based tab rows reach for `PageLayout.Tabs`.\n *\n * **Recommended composition (enforced at the call site):**\n *\n * - `Search` sits on the left; the right cluster auto-aligns via flex.\n * - Right cluster order: `Filters` → `Sort` → `Actions` → `View`. View controls are always\n * the final control group — do not render any control after `View`.\n * - `ActiveFilters` is the second row. Render it only when one or more filters are active.\n * - `Clear` self-aligns to the far right of `ActiveFilters`.\n *\n * The block is variant-agnostic: render filter chips (Standard variant, non-editable) or\n * tokens (Query Builder variant, editable) into `ActiveFilters` as plain children — do not\n * mix the two in one toolbar.\n *\n * @see https://github.com/evviku/design-system-docs/blob/main/docs/patterns/toolbar/toolbar.md\n */\nexport const PageToolbar = Object.assign(Root, {\n /** Left slot — typically a `SearchInput`. */\n Search,\n /** Right cluster — host the four control groups below in the recommended order. */\n Right,\n /** Filter controls (`Combobox`, `Select`, `DatePicker`). */\n Filters: ControlGroup,\n /** Sort control. */\n Sort: ControlGroup,\n /** Utility actions (Export, Refresh, …). */\n Actions: ControlGroup,\n /** View toggle (List / Grid). Always render last in the right cluster. */\n View: ControlGroup,\n /**\n * Active filters row. Render only when one or more filters are active. Pass filter chips\n * (Standard variant) or tokens (Query Builder variant) as children, optionally followed\n * by `AddFilter` / `Clear`.\n */\n ActiveFilters,\n /** Non-editable filter chip (Standard variant) — `Badge` pill with a dismiss button. */\n Chip,\n /**\n * Editable filter token (Query Builder variant) — `Badge` pill with a `chevron-down`\n * popover trigger for editing values and an `×` dismiss button. The popover content\n * is supplied by the caller via the `popover` slot (typically a `Combobox` or option list).\n */\n Token: PageToolbarToken,\n /** \"+ Add filter\" action — typically rendered after the chips/tokens in `ActiveFilters`. */\n AddFilter,\n /** \"Clear all\" action — self-aligns to the far right of `ActiveFilters`. */\n Clear,\n});\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,oBAAoB,EAC/B,UACA,SACA,UACA,iBACA,GAAG,YAEH,qBAAC,SAAD,EAAA,UAAA,CACE,oBAAC,OAAD;CACE,GAAI;CACJ,SAAA;CACA,SAAQ;CACR,OAAM;CACN,QACE,oBAAC,QAAD;EACE,MAAK;EACL,SAAQ;EACR,MAAK;EACL,cAAY;EACZ,SAAS;EAET,UAAA,oBAAC,GAAD,EAAG,WAAU,YAAa,CAAA;CACpB,CAAA;CAGV,UAAA,qBAAC,QAAQ,SAAT;EACE,MAAK;EACL,WAAU;EAFZ,UAAA,CAIG,UACD,oBAAC,aAAD,EAAa,WAAU,YAAa,CAAA,CACrB;;AACZ,CAAA,GACP,oBAAC,QAAQ,SAAT;CAAiB,OAAM;CAAS,UAAA;AAAyB,CAAA,CAClD,EAAA,CAAA;;;AC9CX,MAAM,QAAQ,E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