@keboola/design 11.0.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -1
- package/CHANGELOG.md +2138 -0
- package/COMPONENT-API.md +40 -1
- package/dist/{AIKit-Dre37SJr.js → AIKit-DiS0CVOW.js} +6 -6
- package/dist/{AIKit-Dre37SJr.js.map → AIKit-DiS0CVOW.js.map} +1 -1
- package/dist/{AlertModal-BUC4Es8o.js → AlertModal-Dp_XuJBW.js} +3 -6
- package/dist/{AlertModal-BUC4Es8o.js.map → AlertModal-Dp_XuJBW.js.map} +1 -1
- package/dist/{BrandEditor-B8o9zdZO.js → BrandEditor-DyzgfVkl.js} +6 -6
- package/dist/{BrandEditor-B8o9zdZO.js.map → BrandEditor-DyzgfVkl.js.map} +1 -1
- package/dist/{Breadcrumb-DJp7WwSv.js → Breadcrumb-Frst8MTA.js} +3 -3
- package/dist/{Breadcrumb-DJp7WwSv.js.map → Breadcrumb-Frst8MTA.js.map} +1 -1
- package/dist/{Button-nzmDNS2q.js → Button-6xBX0nNl.js} +15 -15
- package/dist/Button-6xBX0nNl.js.map +1 -0
- package/dist/{ClipboardButton-ez5V3fkk.js → ClipboardButton-ClcluT0C.js} +2 -2
- package/dist/{ClipboardButton-ez5V3fkk.js.map → ClipboardButton-ClcluT0C.js.map} +1 -1
- package/dist/{CodeEditor-BfQJfbhL.js → CodeEditor-DyaN-Ij2.js} +58 -10
- package/dist/CodeEditor-DyaN-Ij2.js.map +1 -0
- package/dist/{ColorInput-Dx8Dsv7Y.js → ColorInput-B8z4j4Y_.js} +2 -2
- package/dist/{ColorInput-Dx8Dsv7Y.js.map → ColorInput-B8z4j4Y_.js.map} +1 -1
- package/dist/{ColorModeSwitch-CCqj7tjE.js → ColorModeSwitch-dZFZyqy1.js} +3 -3
- package/dist/{ColorModeSwitch-CCqj7tjE.js.map → ColorModeSwitch-dZFZyqy1.js.map} +1 -1
- package/dist/{Combobox-c_xBjf0P.js → Combobox-Dgm6Z4ib.js} +9 -5
- package/dist/Combobox-Dgm6Z4ib.js.map +1 -0
- package/dist/{Command-CQ_bQsJp.js → Command-C0aZfVTq.js} +2 -2
- package/dist/{Command-CQ_bQsJp.js.map → Command-C0aZfVTq.js.map} +1 -1
- package/dist/{DateInput-CMD3dY-T.js → DateInput-B3UdzRfW.js} +3 -3
- package/dist/{DateInput-CMD3dY-T.js.map → DateInput-B3UdzRfW.js.map} +1 -1
- package/dist/{DatePicker-BbFbmsGl.js → DatePicker-Dw3DpbUh.js} +2 -2
- package/dist/{DatePicker-BbFbmsGl.js.map → DatePicker-Dw3DpbUh.js.map} +1 -1
- package/dist/{DateRangeInput-D3BhiKyk.js → DateRangeInput-DTuySEiq.js} +3 -3
- package/dist/{DateRangeInput-D3BhiKyk.js.map → DateRangeInput-DTuySEiq.js.map} +1 -1
- package/dist/{DateRangePicker-BiUgtt_M.js → DateRangePicker-DCmMHg4s.js} +4 -4
- package/dist/{DateRangePicker-BiUgtt_M.js.map → DateRangePicker-DCmMHg4s.js.map} +1 -1
- package/dist/{DropdownMenu-B6ZbYvaM.js → DropdownMenu-t90tVw6l.js} +8 -8
- package/dist/DropdownMenu-t90tVw6l.js.map +1 -0
- package/dist/FieldItem-CAPj9lj3.d.ts +111 -0
- package/dist/FieldItem-D-h1NeBo.js +108 -0
- package/dist/FieldItem-D-h1NeBo.js.map +1 -0
- package/dist/{FileUpload-sXRv7JiY.js → FileUpload-BRv0TaZk.js} +2 -2
- package/dist/{FileUpload-sXRv7JiY.js.map → FileUpload-BRv0TaZk.js.map} +1 -1
- package/dist/{Form-BDCef6O9.js → Form-DHvcFoEi.js} +18 -78
- package/dist/{Form-BDCef6O9.js.map → Form-DHvcFoEi.js.map} +1 -1
- package/dist/{FormGroup-S9mPNHKH.js → FormGroup-C41n65cE.js} +7 -7
- package/dist/FormGroup-C41n65cE.js.map +1 -0
- package/dist/{FullScreenModal-CJa2VkJ2.js → FullScreenModal-Cb3PGgh4.js} +2 -2
- package/dist/{FullScreenModal-CJa2VkJ2.js.map → FullScreenModal-Cb3PGgh4.js.map} +1 -1
- package/dist/{InputGroup-BJWsI35s.js → InputGroup-CdTq8H7c.js} +2 -2
- package/dist/{InputGroup-BJWsI35s.js.map → InputGroup-CdTq8H7c.js.map} +1 -1
- package/dist/{MermaidDiagram-BB06gymm.js → MermaidDiagram-ChL3WIQT.js} +2 -2
- package/dist/{MermaidDiagram-BB06gymm.js.map → MermaidDiagram-ChL3WIQT.js.map} +1 -1
- package/dist/{Modal-BA5Wc3sx.js → Modal-wqG8nJiK.js} +2 -2
- package/dist/{Modal-BA5Wc3sx.js.map → Modal-wqG8nJiK.js.map} +1 -1
- package/dist/{MultiActionButtonGroup-CiBHxsSk.js → MultiActionButtonGroup-BiIIubiL.js} +2 -2
- package/dist/{MultiActionButtonGroup-CiBHxsSk.js.map → MultiActionButtonGroup-BiIIubiL.js.map} +1 -1
- package/dist/{Navbar-t16usFZQ.js → Navbar-BfaPeLUL.js} +5 -2
- package/dist/Navbar-BfaPeLUL.js.map +1 -0
- package/dist/{PageToolbar-0_1OBzaZ.js → PageToolbar-OQg3mPF-.js} +4 -4
- package/dist/PageToolbar-OQg3mPF-.js.map +1 -0
- package/dist/{Pagination-CM_Rszz-.js → Pagination-Cjfda8KG.js} +2 -2
- package/dist/{Pagination-CM_Rszz-.js.map → Pagination-Cjfda8KG.js.map} +1 -1
- package/dist/{Popconfirm-BGe1jLov.js → Popconfirm-D7_vfxFd.js} +4 -7
- package/dist/{Popconfirm-BGe1jLov.js.map → Popconfirm-D7_vfxFd.js.map} +1 -1
- package/dist/{Popover-Ca0V6AD1.js → Popover-CzeHjvrB.js} +6 -13
- package/dist/Popover-CzeHjvrB.js.map +1 -0
- package/dist/{SearchInput-D2fcOv7E.js → SearchInput-C7dF_Ir-.js} +2 -2
- package/dist/{SearchInput-D2fcOv7E.js.map → SearchInput-C7dF_Ir-.js.map} +1 -1
- package/dist/{SectionNav--7bw2b6u.js → SectionNav-8NoTOKO8.js} +3 -3
- package/dist/{SectionNav--7bw2b6u.js.map → SectionNav-8NoTOKO8.js.map} +1 -1
- package/dist/{Select-4YX38G5h.js → Select-Is0VkePH.js} +2 -2
- package/dist/{Select-4YX38G5h.js.map → Select-Is0VkePH.js.map} +1 -1
- package/dist/{Sheet-BQrX8-h5.js → Sheet-Dw9BDvjI.js} +2 -2
- package/dist/{Sheet-BQrX8-h5.js.map → Sheet-Dw9BDvjI.js.map} +1 -1
- package/dist/{Sidebar-ROaR_AqC.js → Sidebar-Dcb4rinA.js} +2 -2
- package/dist/{Sidebar-ROaR_AqC.js.map → Sidebar-Dcb4rinA.js.map} +1 -1
- package/dist/{Slider-Da_3mS5v.js → Slider-BOPfMOMm.js} +2 -2
- package/dist/{Slider-Da_3mS5v.js.map → Slider-BOPfMOMm.js.map} +1 -1
- package/dist/{Tabs-EAihyqCt.js → Tabs-UMQuDoW8.js} +2 -2
- package/dist/{Tabs-EAihyqCt.js.map → Tabs-UMQuDoW8.js.map} +1 -1
- package/dist/{TextInput-BGed-V13.js → TextInput-CMuN1WfY.js} +2 -2
- package/dist/{TextInput-BGed-V13.js.map → TextInput-CMuN1WfY.js.map} +1 -1
- package/dist/{TimePicker-B_NegL-7.js → TimePicker-D9zktB8A.js} +2 -2
- package/dist/{TimePicker-B_NegL-7.js.map → TimePicker-D9zktB8A.js.map} +1 -1
- package/dist/{ZoomableSvg-DG9PnAm8.js → ZoomableSvg-CZEu6sAq.js} +3 -3
- package/dist/{ZoomableSvg-DG9PnAm8.js.map → ZoomableSvg-CZEu6sAq.js.map} +1 -1
- package/dist/editors.d.ts +71 -9
- package/dist/editors.js +58 -3
- package/dist/editors.js.map +1 -1
- package/dist/index.d.ts +314 -312
- package/dist/index.js +41 -40
- package/dist/internal/blocks/AIKit.js +1 -1
- 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/ColorModeSwitch.js +1 -1
- package/dist/internal/blocks/Command.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 +2 -2
- package/dist/internal/blocks/Form/connectors/MultiComboboxField.js +56 -0
- package/dist/internal/blocks/Form/connectors/MultiComboboxField.js.map +1 -0
- 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 +8 -3
- package/dist/internal/blocks/MultiCombobox.js.map +1 -1
- package/dist/internal/blocks/NumberInput.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/SplitButton.js +2 -2
- package/dist/internal/blocks/TextInput.js +1 -1
- package/dist/internal/blocks/Textarea.js +1 -1
- package/dist/internal/blocks/TimeInput.js +2 -2
- package/dist/internal/components/AlertModal.js +1 -1
- package/dist/internal/components/Breadcrumb.js +1 -1
- package/dist/internal/components/Button.js +1 -1
- package/dist/internal/components/Combobox.js +1 -1
- package/dist/internal/components/DatePicker.js +1 -1
- package/dist/internal/components/DateRangePicker.js +1 -1
- package/dist/internal/components/DropdownMenu.js +1 -1
- package/dist/internal/components/FileUpload.js +1 -1
- package/dist/internal/components/FullScreenModal.js +1 -1
- package/dist/internal/components/InputGroup.js +1 -1
- package/dist/internal/components/Modal.js +1 -1
- package/dist/internal/components/Navbar.js +1 -1
- package/dist/internal/components/Pagination.js +1 -1
- package/dist/internal/components/Popconfirm.js +1 -1
- package/dist/internal/components/Popover.js +1 -1
- package/dist/internal/components/Select.js +1 -1
- package/dist/internal/components/Sheet.js +1 -1
- package/dist/internal/components/Sidebar.js +1 -1
- package/dist/internal/components/Slider.js +1 -1
- package/dist/internal/components/Tabs.js +1 -1
- package/dist/internal/components/TimePicker.js +1 -1
- package/dist/internal/components/ZoomableSvg.js +1 -1
- package/dist/markdown-editor.js +5 -5
- package/dist/mermaid.js +1 -1
- package/dist/rjsf.d.ts +13 -1
- package/dist/rjsf.js +233 -173
- package/dist/rjsf.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +7 -6
- package/dist/Button-nzmDNS2q.js.map +0 -1
- package/dist/CodeEditor-BfQJfbhL.js.map +0 -1
- package/dist/Combobox-c_xBjf0P.js.map +0 -1
- package/dist/DropdownMenu-B6ZbYvaM.js.map +0 -1
- package/dist/FormGroup-S9mPNHKH.js.map +0 -1
- package/dist/Navbar-t16usFZQ.js.map +0 -1
- package/dist/PageToolbar-0_1OBzaZ.js.map +0 -1
- package/dist/Popover-Ca0V6AD1.js.map +0 -1
- package/dist/constants-D6JcsD4_.d.ts +0 -41
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput-
|
|
1
|
+
{"version":3,"file":"TextInput-CMuN1WfY.js","names":[],"sources":["../src/blocks/TextInput/utils.ts","../src/blocks/TextInput/TextInput.tsx"],"sourcesContent":["import { createPrefixedString } from '../../utils';\n\nexport const genInputTestId = (prefix: string = '') => {\n const ps = createPrefixedString(prefix);\n return {\n toString: () => prefix,\n inputWrapper: ps`input-wrapper`,\n input: ps`input`,\n clearButton: ps`clear-button`,\n };\n};\n","import { useRef } from 'react';\nimport type {\n ChangeEventHandler,\n ComponentProps,\n ComponentRef,\n FocusEventHandler,\n MouseEventHandler,\n ReactNode,\n} from 'react';\n\nimport { InputGroup } from '../../components/InputGroup';\nimport { useControllableState } from '../../hooks/useControllableState';\nimport { X } from '../../icons';\nimport { cn, createChangeInputEvent, mergeRefs } from '../../utils';\n\nimport { genInputTestId } from './utils';\n\ntype InputGroupProps = Pick<\n ComponentProps<typeof InputGroup>,\n 'variant' | 'focusVariant' | 'sizing' | 'state'\n>;\n\ntype OwnProps = {\n prefix?: ReactNode;\n rightSuffix?: ReactNode;\n rightSuffixVariant?: 'addon' | 'default';\n leftSuffix?: ReactNode;\n allowClear?: boolean;\n onClear?: () => void;\n testId?: string;\n value?: string | null;\n defaultValue?: string | null;\n /** Called with the unwrapped string value on every change. For the raw event use `onChange`. */\n onValueChange?: (value: string) => void;\n /** Called with the unwrapped string value on blur. For the raw event use `onBlur`. */\n onValueBlur?: (value: string) => void;\n type?: 'text' | 'email' | 'password' | 'datetime-local' | 'date';\n};\n\n/**\n * Props for `TextInput`. Combines `InputGroup` chrome (variant / sizing / state / focusVariant) with\n * input-specific slots (`prefix`, `leftSuffix`, `rightSuffix`, `allowClear`) and a string-typed\n * `value` / `defaultValue` plus convenience `onValueChange` / `onValueBlur` callbacks. `null` /\n * `undefined` are coerced to empty strings.\n */\nexport type Props = InputGroupProps &\n OwnProps &\n Omit<ComponentProps<'input'>, 'prefix' | 'value' | 'defaultValue' | 'type' | 'accept' | 'step'>;\n\nconst sanitizeTextInputValue = (value: string | null | undefined) => {\n if (typeof value === 'string' && value.trim() === '') return '';\n return value;\n};\n\n/**\n * Standard text input with a string-only API, built on `InputGroup` chrome — addons, clear button,\n * sizing, focus variants. The default choice for a bare text input.\n *\n * **When to use:** any plain text / email / password / date-input field outside `useAppForm`. Pair with\n * `onValueChange` instead of unwrapping `event.target.value` from `onChange`.\n * **When NOT to use:** for fields inside a labelled group use `FormGroup.TextInput`; for forms with\n * validation use `useAppForm` + `field.TextField`; for search use `SearchInput`.\n * **Composition:** wrap in a `FormGroup` for shared error / help-text state, or render directly inside\n * page layouts. Chrome resolves from the active brand automatically: a modern brand always renders argo\n * (any `variant` is ignored), while `variant` only tunes the legacy-brand chrome.\n */\nexport const TextInput = ({\n ref: forwardedRef,\n state = 'default',\n sizing = 'default',\n className,\n prefix = null,\n rightSuffix = null,\n rightSuffixVariant = 'default',\n leftSuffix = null,\n allowClear = false,\n onClear,\n disabled = false,\n testId: prefixTestId = '',\n autoFocus = false,\n id,\n name,\n variant,\n readOnly,\n type = 'text',\n focusVariant = 'default',\n onChange,\n onBlur,\n onValueChange,\n onValueBlur,\n value: valueProp,\n defaultValue,\n ...inputProps\n}: Props) => {\n const inputRef = useRef<ComponentRef<'input'>>(null);\n\n const [value, setValue] = useControllableState<string>({\n // `undefined` stays uncontrolled; any provided value (incl. `null`) is controlled and coerced\n // to a string. Whitespace-only input collapses to '' via `sanitizeTextInputValue`.\n prop: valueProp === undefined ? undefined : (sanitizeTextInputValue(valueProp) ?? ''),\n defaultProp: sanitizeTextInputValue(defaultValue) ?? '',\n onChange: onValueChange,\n });\n\n const testId = genInputTestId(prefixTestId);\n const isClearButtonVisible = (!!value && !disabled && !readOnly) || !!onClear;\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {\n setValue(event.target.value);\n onChange?.(event);\n };\n\n const handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {\n onValueBlur?.(event.target.value);\n onBlur?.(event);\n };\n\n const handleClear: MouseEventHandler<HTMLButtonElement> = () => {\n if (inputRef.current === null) return;\n inputRef.current.value = ''; // keep the DOM node in sync before firing the synthetic change\n inputRef.current.focus();\n onClear?.();\n handleChange(createChangeInputEvent(inputRef.current));\n };\n\n return (\n <InputGroup\n state={state}\n variant={variant}\n sizing={sizing}\n focusVariant={focusVariant}\n className={className}\n data-testid={testId.inputWrapper}\n >\n {prefix && <InputGroup.Addon align=\"inline-start\">{prefix}</InputGroup.Addon>}\n\n <InputGroup.Input\n {...inputProps}\n value={value}\n autoFocus={autoFocus}\n type={type}\n onChange={handleChange}\n onBlur={handleBlur}\n ref={mergeRefs(forwardedRef ?? null, inputRef)}\n disabled={disabled}\n id={id}\n name={name}\n readOnly={readOnly}\n data-testid={testId.input}\n />\n\n {(leftSuffix || allowClear || rightSuffix) && (\n <InputGroup.Addon align=\"inline-end\">\n {leftSuffix}\n {allowClear && isClearButtonVisible && (\n <InputGroup.Button\n aria-label=\"Clear\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={handleClear}\n data-testid={testId.clearButton}\n >\n <X className=\"tw:size-4\" />\n </InputGroup.Button>\n )}\n {rightSuffix && (\n <div\n className={cn({\n 'tw:whitespace-nowrap tw:bg-muted tw:px-4 tw:-mr-4 tw:py-2.5':\n rightSuffixVariant === 'addon',\n })}\n >\n {rightSuffix}\n </div>\n )}\n </InputGroup.Addon>\n )}\n </InputGroup>\n );\n};\n"],"mappings":";;;;;;;;;AAEA,MAAa,kBAAkB,SAAiB,OAAO;CACrD,MAAM,KAAK,qBAAqB,MAAM;CACtC,OAAO;EACL,gBAAgB;EAChB,cAAc,EAAE;EAChB,OAAO,EAAE;EACT,aAAa,EAAE;CACjB;AACF;;;ACuCA,MAAM,0BAA0B,UAAqC;CACnE,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI,OAAO;CAC7D,OAAO;AACT;;;;;;;;;;;;;AAcA,MAAa,aAAa,EACxB,KAAK,cACL,QAAQ,WACR,SAAS,WACT,WACA,SAAS,MACT,cAAc,MACd,qBAAqB,WACrB,aAAa,MACb,aAAa,OACb,SACA,WAAW,OACX,QAAQ,eAAe,IACvB,YAAY,OACZ,IACA,MACA,SACA,UACA,OAAO,QACP,eAAe,WACf,UACA,QACA,eACA,aACA,OAAO,WACP,cACA,GAAG,iBACQ;CACX,MAAM,WAAW,OAA8B,IAAI;CAEnD,MAAM,CAAC,OAAO,YAAY,qBAA6B;EAGrD,MAAM,cAAc,KAAA,IAAY,KAAA,IAAa,uBAAuB,SAAS,KAAK;EAClF,aAAa,uBAAuB,YAAY,KAAK;EACrD,UAAU;CACZ,CAAC;CAED,MAAM,SAAS,eAAe,YAAY;CAC1C,MAAM,uBAAwB,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,YAAa,CAAC,CAAC;CAEtE,MAAM,gBAAsD,UAAU;EACpE,SAAS,MAAM,OAAO,KAAK;EAC3B,WAAW,KAAK;CAClB;CAEA,MAAM,cAAmD,UAAU;EACjE,cAAc,MAAM,OAAO,KAAK;EAChC,SAAS,KAAK;CAChB;CAEA,MAAM,oBAA0D;EAC9D,IAAI,SAAS,YAAY,MAAM;EAC/B,SAAS,QAAQ,QAAQ;EACzB,SAAS,QAAQ,MAAM;EACvB,UAAU;EACV,aAAa,uBAAuB,SAAS,OAAO,CAAC;CACvD;CAEA,OACE,qBAAC,YAAD;EACS;EACE;EACD;EACM;EACH;EACX,eAAa,OAAO;EANtB,UAAA;GAQG,UAAU,oBAAC,WAAW,OAAZ;IAAkB,OAAM;IAAgB,UAAA;GAAyB,CAAA;GAE5E,oBAAC,WAAW,OAAZ;IACE,GAAI;IACG;IACI;IACL;IACN,UAAU;IACV,QAAQ;IACR,KAAK,UAAU,gBAAgB,MAAM,QAAQ;IACnC;IACN;IACE;IACI;IACV,eAAa,OAAO;GACrB,CAAA;IAEC,cAAc,cAAc,gBAC5B,qBAAC,WAAW,OAAZ;IAAkB,OAAM;IAAxB,UAAA;KACG;KACA,cAAc,wBACb,oBAAC,WAAW,QAAZ;MACE,cAAW;MACX,cAAc,MAAM,EAAE,eAAe;MACrC,SAAS;MACT,eAAa,OAAO;MAEpB,UAAA,oBAAC,GAAD,EAAG,WAAU,YAAa,CAAA;KACT,CAAA;KAEpB,eACC,oBAAC,OAAD;MACE,WAAW,GAAG,EACZ,+DACE,uBAAuB,QAC3B,CAAC;MAEA,UAAA;KACE,CAAA;IAES;;EAEV;;AAEhB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ScrollArea } from "./internal/components/ScrollArea.js";
|
|
2
2
|
import { Toggle } from "./internal/components/Toggle.js";
|
|
3
|
-
import { Popover } from "./Popover-
|
|
3
|
+
import { Popover } from "./Popover-CzeHjvrB.js";
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
//#region src/components/TimePicker/utils.ts
|
|
@@ -95,4 +95,4 @@ const TimePicker = ({ align = "end", alignOffset = -18, children, defaultOpen, d
|
|
|
95
95
|
//#endregion
|
|
96
96
|
export { TimePicker, formatTime, pad, parseTime };
|
|
97
97
|
|
|
98
|
-
//# sourceMappingURL=TimePicker-
|
|
98
|
+
//# sourceMappingURL=TimePicker-D9zktB8A.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimePicker-
|
|
1
|
+
{"version":3,"file":"TimePicker-D9zktB8A.js","names":[],"sources":["../src/components/TimePicker/utils.ts","../src/components/TimePicker/TimePicker.tsx"],"sourcesContent":["export const pad = (n: number) => n.toString().padStart(2, '0');\n\n/** The \"HH:mm\" shape `parseTime` parses back. */\nexport const formatTime = (hour: number, minute: number) => `${pad(hour)}:${pad(minute)}`;\n\nexport const parseTime = (time?: string | null) => {\n if (!time) return { hour: null, minute: null };\n\n const match = /^(\\d{1,2}):(\\d{1,2})$/.exec(time.trim());\n if (!match) return { hour: null, minute: null };\n\n const hour = Number(match[1]);\n const minute = Number(match[2]);\n if (\n Number.isNaN(hour) ||\n Number.isNaN(minute) ||\n hour < 0 ||\n hour > 23 ||\n minute < 0 ||\n minute > 59\n )\n return { hour: null, minute: null };\n\n return { hour, minute };\n};\n\nexport const scrollToSelected = (viewport: HTMLDivElement | null) => {\n if (!viewport) return;\n // Defer scroll until after the popover open animation completes and layout is calculated\n requestAnimationFrame(() => {\n const selected = viewport.querySelector('[aria-pressed=\"true\"]');\n selected?.scrollIntoView({ block: 'center' });\n });\n};\n","import { useState } from 'react';\nimport type { ReactNode } from 'react';\nimport type { PopoverContentProps, PopoverProps } from '@radix-ui/react-popover';\n\nimport { Popover } from '../Popover';\nimport { ScrollArea } from '../ScrollArea';\nimport { Toggle } from '../Toggle';\n\nimport { formatTime, pad, parseTime, scrollToSelected } from './utils';\n\nconst HOURS = Array.from({ length: 24 }, (_, i) => i);\nconst MINUTES = Array.from({ length: 60 }, (_, i) => i);\n\ntype Props = {\n children?: ReactNode;\n defaultSelected?: string | null;\n selected?: string | null;\n onSelect?: (time: string) => void;\n} & Pick<PopoverProps, 'open' | 'onOpenChange' | 'defaultOpen'> &\n Pick<PopoverContentProps, 'align' | 'alignOffset' | 'sideOffset'>;\n\nexport const TimePicker = ({\n align = 'end',\n alignOffset = -18,\n children,\n defaultOpen,\n defaultSelected,\n onOpenChange,\n onSelect,\n open,\n selected,\n sideOffset = 12,\n}: Props) => {\n const [internalSelected, setInternalSelected] = useState<string | null>(defaultSelected ?? null);\n\n const isControlled = selected !== undefined;\n const currentValue = isControlled ? selected : internalSelected;\n\n const parsed = parseTime(currentValue);\n const hour = parsed.hour ?? null;\n const minute = parsed.minute ?? null;\n\n const handleSelect = (time: string) => {\n if (!isControlled) {\n setInternalSelected(time);\n }\n onSelect?.(time);\n };\n\n const handleHourSelect = (h: number) => {\n handleSelect(formatTime(h, minute ?? 0));\n };\n\n const handleMinuteSelect = (m: number) => {\n handleSelect(formatTime(hour ?? 0, m));\n };\n\n return (\n <Popover defaultOpen={defaultOpen} onOpenChange={onOpenChange} open={open}>\n <Popover.Trigger asChild>{children}</Popover.Trigger>\n <Popover.Content\n align={align}\n alignOffset={alignOffset}\n sideOffset={sideOffset}\n className=\"tw:flex tw:flex-row\"\n >\n <ScrollArea type=\"always\" ref={scrollToSelected} viewPortClassName=\"tw:h-60 tw:p-3\">\n {HOURS.map((value) => (\n <Toggle\n key={value}\n variant=\"ghost\"\n className=\"tw:size-10 tw:p-0\"\n pressed={value === hour}\n onPressedChange={() => handleHourSelect(value)}\n >\n {pad(value)}\n </Toggle>\n ))}\n </ScrollArea>\n\n <ScrollArea type=\"always\" ref={scrollToSelected} viewPortClassName=\"tw:h-60 tw:p-3\">\n {MINUTES.map((value) => (\n <Toggle\n key={value}\n variant=\"ghost\"\n className=\"tw:size-10 tw:p-0\"\n pressed={value === minute}\n onPressedChange={() => handleMinuteSelect(value)}\n >\n {pad(value)}\n </Toggle>\n ))}\n </ScrollArea>\n </Popover.Content>\n </Popover>\n );\n};\n"],"mappings":";;;;;;AAAA,MAAa,OAA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B,IAAI;EAE1B,WAAW,IAAI;CACjB;CAEA,MAAM,oBAAoB,MAAc;EACtC,aAAa,WAAW,GAAG,UAAU,CAAC,CAAC;CACzC;CAEA,MAAM,sBAAsB,MAAc;EACxC,aAAa,WAAW,QAAQ,GAAG,CAAC,CAAC;CACvC;CAEA,OACE,qBAAC,SAAD;EAAsB;EAA2B;EAAoB;EAArE,UAAA,CACE,oBAAC,QAAQ,SAAT;GAAiB,SAAA;GAAS;EAA0B,CAAA,GACpD,qBAAC,QAAQ,SAAT;GACS;GACM;GACD;GACZ,WAAU;GAJZ,UAAA,CAME,oBAAC,YAAD;IAAY,MAAK;IAAS,KAAK;IAAkB,mBAAkB;IAChE,UAAA,MAAM,KAAK,UACV,oBAAC,QAAD;KAEE,SAAQ;KACR,WAAU;KACV,SAAS,UAAU;KACnB,uBAAuB,iBAAiB,KAAK;KAE5C,UAAA,IAAI,KAAK;IACJ,GAPD,KAOC,CACT;GACS,CAAA,GAEZ,oBAAC,YAAD;IAAY,MAAK;IAAS,KAAK;IAAkB,mBAAkB;IAChE,UAAA,QAAQ,KAAK,UACZ,oBAAC,QAAD;KAEE,SAAQ;KACR,WAAU;KACV,SAAS,UAAU;KACnB,uBAAuB,mBAAmB,KAAK;KAE9C,UAAA,IAAI,KAAK;IACJ,GAPD,KAOC,CACT;GACS,CAAA,CACG;EACV,CAAA,CAAA;;AAEb"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
2
|
import { Tooltip } from "./utils-D0c5VAyF.js";
|
|
3
3
|
import { Maximize2, Minimize2 } from "./icons-Cek151jC.js";
|
|
4
|
-
import { Button } from "./Button-
|
|
5
|
-
import { ClipboardButton } from "./ClipboardButton-
|
|
4
|
+
import { Button } from "./Button-6xBX0nNl.js";
|
|
5
|
+
import { ClipboardButton } from "./ClipboardButton-ClcluT0C.js";
|
|
6
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { createPortal } from "react-dom";
|
|
@@ -245,4 +245,4 @@ const svgToPngBlob = async (svg, background) => {
|
|
|
245
245
|
//#endregion
|
|
246
246
|
export { ZoomableSvg, svgToPngBlob, toSvgFileContent };
|
|
247
247
|
|
|
248
|
-
//# sourceMappingURL=ZoomableSvg-
|
|
248
|
+
//# sourceMappingURL=ZoomableSvg-CZEu6sAq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZoomableSvg-DG9PnAm8.js","names":[],"sources":["../src/components/ZoomableSvg/ZoomableSvg.tsx","../src/components/ZoomableSvg/exportSvg.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\nimport DOMPurify from 'dompurify';\n\nimport { ClipboardButton } from '../../blocks/ClipboardButton';\nimport { Maximize2, Minimize2 } from '../../icons';\nimport { cn } from '../../utils';\nimport { Button } from '../Button';\nimport { Tooltip } from '../Tooltip';\n\nconst MIN_SCALE = 0.5;\nconst MAX_SCALE = 3;\nconst ZOOM_STEP = 0.1;\n\ntype Props = {\n /** Raw SVG markup. Sanitized internally with DOMPurify (SVG profile) before rendering, so it is\n * safe even when it originates from user/LLM-controlled content. Non-SVG HTML is stripped. */\n html: string;\n copyText?: string;\n className?: string;\n /**\n * Opt in to keeping `<foreignObject>` elements through sanitization. Off by\n * default — the SVG profile drops `<foreignObject>` so no HTML subtree can\n * survive. Only enable when the caller pre-flattens each `<foreignObject>` to\n * bare text (the SVG profile still strips any HTML children even when the\n * element itself is allowed). `MermaidDiagram` sets this for node/icon labels.\n */\n allowForeignObject?: boolean;\n /**\n * Extra toolbar controls, rendered between the copy and fullscreen buttons.\n *\n * Injected rather than built in, so export behaviour — filenames,\n * rasterization, error reporting — stays with the consumer and this component\n * keeps shipping in the lazy `@keboola/design/mermaid` chunk with no download\n * dependencies of its own. Pass `ExportMenu` here. Receives the sanitized\n * SVG so an exporter writes exactly what is on screen.\n */\n renderActions?: (safeSvg: string) => ReactNode;\n};\n\nexport const ZoomableSvg = ({\n html,\n copyText,\n className,\n allowForeignObject,\n renderActions,\n}: Props) => {\n const safeHtml = useMemo(\n () =>\n DOMPurify.sanitize(html, {\n USE_PROFILES: { svg: true, svgFilters: true },\n ...(allowForeignObject ? { ADD_TAGS: ['foreignObject'] } : {}),\n }),\n [html, allowForeignObject],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [scale, setScale] = useState(1);\n const [translate, setTranslate] = useState({ x: 0, y: 0 });\n const [isFullscreen, setIsFullscreen] = useState(false);\n\n useEffect(() => {\n if (!isFullscreen) return;\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n setIsFullscreen(false);\n }\n };\n document.addEventListener('keydown', onKeyDown, { capture: true });\n return () => document.removeEventListener('keydown', onKeyDown, { capture: true });\n }, [isFullscreen]);\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startTx: number;\n startTy: number;\n } | null>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n\n const onWheel = (e: WheelEvent) => {\n if (!e.ctrlKey && !e.metaKey) return;\n e.preventDefault();\n const delta = e.deltaY > 0 ? -ZOOM_STEP : ZOOM_STEP;\n setScale((s) => Math.min(MAX_SCALE, Math.max(MIN_SCALE, s + delta)));\n };\n\n el.addEventListener('wheel', onWheel, { passive: false });\n return () => el.removeEventListener('wheel', onWheel);\n // Re-bind when toggling fullscreen: the portal/inline switch remounts the\n // container element, so the listener must attach to the new node.\n }, [isFullscreen]);\n\n const didDragRef = useRef(false);\n\n const handleMouseDown = useCallback(\n (e: React.MouseEvent) => {\n if (e.button !== 0) return;\n e.preventDefault();\n didDragRef.current = false;\n dragRef.current = {\n startX: e.clientX,\n startY: e.clientY,\n startTx: translate.x,\n startTy: translate.y,\n };\n },\n [translate],\n );\n\n const handleMouseMove = useCallback((e: React.MouseEvent) => {\n if (!dragRef.current) return;\n didDragRef.current = true;\n setTranslate({\n x: dragRef.current.startTx + e.clientX - dragRef.current.startX,\n y: dragRef.current.startTy + e.clientY - dragRef.current.startY,\n });\n }, []);\n\n const handleMouseUp = useCallback(() => {\n dragRef.current = null;\n }, []);\n\n const handleReset = useCallback(() => {\n setScale(1);\n setTranslate({ x: 0, y: 0 });\n }, []);\n\n const isZoomed = Math.abs(scale - 1) > 0.001 || translate.x !== 0 || translate.y !== 0;\n\n const handleClick = useCallback((e: React.MouseEvent) => {\n if (didDragRef.current) {\n e.stopPropagation();\n }\n }, []);\n\n const stopPropagation = useCallback((e: React.SyntheticEvent) => {\n e.stopPropagation();\n }, []);\n\n const diagramContent = (\n <div\n role=\"presentation\"\n className={cn('tw:group/zoom tw:relative', isFullscreen && 'tw:h-full')}\n onClick={handleClick}\n >\n <div\n role=\"presentation\"\n ref={containerRef}\n className={cn(\n 'tw:overflow-hidden tw:cursor-grab tw:active:cursor-grabbing tw:p-3',\n isFullscreen && 'tw:h-full',\n )}\n onMouseDown={handleMouseDown}\n onMouseMove={handleMouseMove}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n >\n <div\n className={cn(\n 'tw:flex tw:justify-center tw:origin-center',\n isFullscreen && 'tw:h-full tw:[&>svg]:h-full',\n )}\n style={{ transform: `translate(${translate.x}px, ${translate.y}px) scale(${scale})` }}\n dangerouslySetInnerHTML={{ __html: safeHtml }}\n />\n </div>\n <div\n role=\"presentation\"\n // `focus-within` as well as hover: the toolbar is opacity-0 but still in\n // the tab order, so without this a keyboard user tabs through invisible\n // controls with no visible focus ring.\n className=\"tw:absolute tw:right-1 tw:top-1 tw:flex tw:gap-1 tw:opacity-0 tw:transition-opacity tw:focus-within:opacity-100 tw:group-hover/zoom:opacity-100\"\n onClick={stopPropagation}\n >\n {isZoomed && (\n <Tooltip tooltip=\"Reset zoom\" placement=\"top\" triggerAsChild>\n <Button size=\"small\" variant=\"outline\" onClick={handleReset}>\n Reset\n </Button>\n </Tooltip>\n )}\n {copyText && (\n <ClipboardButton text={copyText} tooltip=\"Copy code\" size=\"icon-sm\" variant=\"outline\" />\n )}\n {renderActions?.(safeHtml)}\n <Tooltip\n tooltip={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'}\n placement=\"top\"\n triggerAsChild\n >\n <Button\n size=\"icon-sm\"\n variant=\"outline\"\n aria-label={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'}\n onClick={() => setIsFullscreen((f) => !f)}\n >\n {isFullscreen ? (\n <Minimize2 className=\"tw:size-4\" />\n ) : (\n <Maximize2 className=\"tw:size-4\" />\n )}\n </Button>\n </Tooltip>\n </div>\n </div>\n );\n\n if (isFullscreen) {\n return createPortal(\n <div\n role=\"presentation\"\n data-testid=\"zoomable-svg-fullscreen\"\n /**\n * Stacking contract for this overlay, which portals to `document.body`.\n *\n * - Sits at z-1051, the Modal/Sheet band: above page chrome.\n * - Stays *below* the floating-panel layer (z-1055: DropdownMenu,\n * Popover, Select, Combobox), which portals to `document.body` too —\n * an overlay above it hides any menu opened from the toolbar.\n * - `Tooltip` (z-1060) renders above, as it does over a Modal.\n * - `SpotlightBackdrop` (z-1056) dims this overlay rather than sitting\n * under it — by design, since it deliberately covers the portalled\n * surface tier so a tour's dim can't be punched through.\n * - An app may clamp poppers into this same band, making it a tie that\n * DOM order settles; Radix mounts its portal after this one.\n */\n className=\"tw:fixed tw:inset-0 tw:z-[1051] tw:bg-muted tw:p-4 tailwindcss-preflight\"\n onClick={stopPropagation}\n >\n {diagramContent}\n </div>,\n document.body,\n );\n }\n\n return (\n <div\n className={cn(\n 'tw:overflow-hidden tw:rounded-md tw:border tw:border-border tw:bg-muted',\n className,\n )}\n >\n {diagramContent}\n </div>\n );\n};\n","const PNG_SCALE = 2;\n\n// The root `<svg …>` tag, so the namespace check looks only at its attributes.\n// A plain `includes('xmlns=')` would also match a nested element or body text,\n// and would miss `xmlns = \"…\"` — adding a second declaration, which parsers\n// reject outright with \"Attribute xmlns redefined\".\nconst ROOT_SVG_TAG = /^<svg\\b[^>]*>/i;\nconst HAS_DEFAULT_NAMESPACE = /\\bxmlns\\s*=/i;\n\n// A standalone SVG file needs the namespace declaration; mermaid's inline output\n// omits it because an inline <svg> inherits it from the host document.\n// Trim before matching: the anchored `^<svg` misses markup that arrives with a\n// leading newline or indentation, which would emit a standalone file with no\n// namespace — unopenable in an image viewer.\nconst withSvgNamespace = (svg: string) => {\n const trimmed = svg.trim();\n const rootTag = trimmed.match(ROOT_SVG_TAG)?.[0];\n\n if (!rootTag || HAS_DEFAULT_NAMESPACE.test(rootTag)) return trimmed;\n\n return trimmed.replace(/^<svg\\b/i, '<svg xmlns=\"http://www.w3.org/2000/svg\"');\n};\n\nexport const toSvgFileContent = (svg: string) =>\n `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n${withSvgNamespace(svg).trim()}\\n`;\n\n// A single decimal number: `12`, `12.5`, `.5`. Deliberately stricter than\n// `[\\d.]+`, which also matches `1.2.3` — and `parseFloat` truncates that to\n// `1.2` rather than rejecting it, so a malformed value would pass as a plausible\n// one.\nconst NUMBER = String.raw`\\d+(?:\\.\\d+)?|\\.\\d+`;\n\n// `parseFloat` happily reads a relative length as a number — `\"100%\"` becomes\n// `100`, `\"2em\"` becomes `2` — and `makeResponsive` sets `width=\"100%\"` on every\n// mermaid root, so an SVG with no usable viewBox would rasterize 100px wide with\n// no error. Accept only a unitless number or an explicit `px`.\nconst PIXEL_LENGTH = new RegExp(String.raw`^\\s*(?:${NUMBER})(?:px)?\\s*$`, 'i');\n\nconst parsePixelLength = (value: string | null): number | null => {\n if (!PIXEL_LENGTH.test(value ?? '')) return null;\n\n const parsed = Number.parseFloat(value ?? '');\n\n return Number.isFinite(parsed) && parsed > 0 ? parsed : null;\n};\n\nexport const parseSvgSize = (svg: string) => {\n const doc = new DOMParser().parseFromString(withSvgNamespace(svg), 'image/svg+xml');\n const element = doc.documentElement;\n\n const viewBox = element\n .getAttribute('viewBox')\n ?.split(/[\\s,]+/)\n .map(Number);\n // `> 0`, not truthiness: a negative extent is accepted by a truthy check, and\n // negative canvas dimensions silently fall back to the 300x150 default — an\n // export at the wrong size with no error. Falling through to width/height is\n // the better answer, since those are usually still valid.\n if (viewBox?.length === 4 && viewBox.every((value) => Number.isFinite(value))) {\n const [, , width, height] = viewBox;\n if (width !== undefined && height !== undefined && width > 0 && height > 0) {\n return { width, height };\n }\n }\n\n const width = parsePixelLength(element.getAttribute('width'));\n const height = parsePixelLength(element.getAttribute('height'));\n\n return width !== null && height !== null ? { width, height } : null;\n};\n\n// Resolve the themed page background so the exported PNG follows the active\n// brand and color scheme instead of a frozen literal. Falls back to `white`\n// (a CSS keyword, not a brand-locked hex) when the token is unset.\n//\n// The token holds Tailwind's bare channel triplet (\"249 250 251\") so utilities\n// can add an alpha. Canvas `fillStyle` rejects that form *silently* and keeps\n// its previous value (black), so wrap it back into rgb() before use.\nconst CHANNEL_TRIPLET = new RegExp(String.raw`^(?:${NUMBER})\\s+(?:${NUMBER})\\s+(?:${NUMBER})$`);\n\nexport const toCanvasColor = (token: string) => {\n const trimmed = token.trim();\n if (!trimmed) return 'white';\n\n // Only wrap a well-formed triplet. A malformed one (`1.2.3 4 5`) would produce\n // an invalid `rgb()` that `fillStyle` rejects silently, painting the PNG on\n // whatever colour was set before — passing it through unwrapped at least lets\n // a genuine CSS color value work.\n return CHANNEL_TRIPLET.test(trimmed) ? `rgb(${trimmed})` : trimmed;\n};\n\nconst resolveBackground = () =>\n toCanvasColor(getComputedStyle(document.documentElement).getPropertyValue('--color-background'));\n\n/**\n * Rasterize SVG markup to a PNG blob at 2x for legible text.\n *\n * The SVG is loaded as a data URL rather than a blob URL: an <img> loading SVG\n * is treated as a foreign resource, so a blob URL would taint the canvas and\n * make toBlob throw a SecurityError. A background is painted first because a\n * transparent PNG reads as unusable when pasted into a slide deck.\n */\nexport const svgToPngBlob = async (svg: string, background?: string): Promise<Blob> => {\n const size = parseSvgSize(svg);\n if (!size) throw new Error('Cannot determine diagram dimensions.');\n\n const encoded = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(toSvgFileContent(svg))}`;\n\n const image = new Image();\n image.decoding = 'sync';\n await new Promise<void>((resolve, reject) => {\n image.onload = () => resolve();\n image.onerror = () => reject(new Error('Failed to load the diagram for export.'));\n image.src = encoded;\n });\n\n const canvas = document.createElement('canvas');\n canvas.width = Math.round(size.width * PNG_SCALE);\n canvas.height = Math.round(size.height * PNG_SCALE);\n\n const context = canvas.getContext('2d');\n if (!context) throw new Error('Canvas is unavailable in this browser.');\n\n context.fillStyle = background ?? resolveBackground();\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.drawImage(image, 0, 0, canvas.width, canvas.height);\n\n return new Promise<Blob>((resolve, reject) => {\n canvas.toBlob(\n (blob) => (blob ? resolve(blob) : reject(new Error('Failed to encode the PNG.'))),\n 'image/png',\n );\n });\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AA4BlB,MAAa,eAAe,EAC1B,MACA,UACA,WACA,oBACA,oBACW;CACX,MAAM,WAAW,cAEb,UAAU,SAAS,MAAM;EACvB,cAAc;GAAE,KAAK;GAAM,YAAY;EAAK;EAC5C,GAAI,qBAAqB,EAAE,UAAU,CAAC,eAAe,EAAE,IAAI,CAAC;CAC9D,CAAC,GACH,CAAC,MAAM,kBAAkB,CAC3B;CAEA,MAAM,eAAe,OAAuB,IAAI;CAChD,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,CAAC,WAAW,gBAAgB,SAAS;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC;CACzD,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CAEtD,gBAAgB;EACd,IAAI,CAAC,cAAc;EACnB,MAAM,aAAa,MAAqB;GACtC,IAAI,EAAE,QAAQ,UAAU;IACtB,EAAE,gBAAgB;IAClB,gBAAgB,KAAK;GACvB;EACF;EACA,SAAS,iBAAiB,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AO,WAAW,IAAI;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,wCAAwC;CAEtE,QAAQ,YAAY,cAAc,kBAAkB;CACpD,QAAQ,SAAS,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM;CAClD,QAAQ,UAAU,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM;CAE1D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC5C,OAAO,QACJ,SAAU,OAAO,QAAQ,IAAI,IAAI,uBAAO,IAAI,MAAM,2BAA2B,CAAC,GAC/E,WACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"ZoomableSvg-CZEu6sAq.js","names":[],"sources":["../src/components/ZoomableSvg/ZoomableSvg.tsx","../src/components/ZoomableSvg/exportSvg.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\nimport DOMPurify from 'dompurify';\n\nimport { ClipboardButton } from '../../blocks/ClipboardButton';\nimport { Maximize2, Minimize2 } from '../../icons';\nimport { cn } from '../../utils';\nimport { Button } from '../Button';\nimport { Tooltip } from '../Tooltip';\n\nconst MIN_SCALE = 0.5;\nconst MAX_SCALE = 3;\nconst ZOOM_STEP = 0.1;\n\ntype Props = {\n /** Raw SVG markup. Sanitized internally with DOMPurify (SVG profile) before rendering, so it is\n * safe even when it originates from user/LLM-controlled content. Non-SVG HTML is stripped. */\n html: string;\n copyText?: string;\n className?: string;\n /**\n * Opt in to keeping `<foreignObject>` elements through sanitization. Off by\n * default — the SVG profile drops `<foreignObject>` so no HTML subtree can\n * survive. Only enable when the caller pre-flattens each `<foreignObject>` to\n * bare text (the SVG profile still strips any HTML children even when the\n * element itself is allowed). `MermaidDiagram` sets this for node/icon labels.\n */\n allowForeignObject?: boolean;\n /**\n * Extra toolbar controls, rendered between the copy and fullscreen buttons.\n *\n * Injected rather than built in, so export behaviour — filenames,\n * rasterization, error reporting — stays with the consumer and this component\n * keeps shipping in the lazy `@keboola/design/mermaid` chunk with no download\n * dependencies of its own. Pass `ExportMenu` here. Receives the sanitized\n * SVG so an exporter writes exactly what is on screen.\n */\n renderActions?: (safeSvg: string) => ReactNode;\n};\n\nexport const ZoomableSvg = ({\n html,\n copyText,\n className,\n allowForeignObject,\n renderActions,\n}: Props) => {\n const safeHtml = useMemo(\n () =>\n DOMPurify.sanitize(html, {\n USE_PROFILES: { svg: true, svgFilters: true },\n ...(allowForeignObject ? { ADD_TAGS: ['foreignObject'] } : {}),\n }),\n [html, allowForeignObject],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [scale, setScale] = useState(1);\n const [translate, setTranslate] = useState({ x: 0, y: 0 });\n const [isFullscreen, setIsFullscreen] = useState(false);\n\n useEffect(() => {\n if (!isFullscreen) return;\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n setIsFullscreen(false);\n }\n };\n document.addEventListener('keydown', onKeyDown, { capture: true });\n return () => document.removeEventListener('keydown', onKeyDown, { capture: true });\n }, [isFullscreen]);\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startTx: number;\n startTy: number;\n } | null>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n\n const onWheel = (e: WheelEvent) => {\n if (!e.ctrlKey && !e.metaKey) return;\n e.preventDefault();\n const delta = e.deltaY > 0 ? -ZOOM_STEP : ZOOM_STEP;\n setScale((s) => Math.min(MAX_SCALE, Math.max(MIN_SCALE, s + delta)));\n };\n\n el.addEventListener('wheel', onWheel, { passive: false });\n return () => el.removeEventListener('wheel', onWheel);\n // Re-bind when toggling fullscreen: the portal/inline switch remounts the\n // container element, so the listener must attach to the new node.\n }, [isFullscreen]);\n\n const didDragRef = useRef(false);\n\n const handleMouseDown = useCallback(\n (e: React.MouseEvent) => {\n if (e.button !== 0) return;\n e.preventDefault();\n didDragRef.current = false;\n dragRef.current = {\n startX: e.clientX,\n startY: e.clientY,\n startTx: translate.x,\n startTy: translate.y,\n };\n },\n [translate],\n );\n\n const handleMouseMove = useCallback((e: React.MouseEvent) => {\n if (!dragRef.current) return;\n didDragRef.current = true;\n setTranslate({\n x: dragRef.current.startTx + e.clientX - dragRef.current.startX,\n y: dragRef.current.startTy + e.clientY - dragRef.current.startY,\n });\n }, []);\n\n const handleMouseUp = useCallback(() => {\n dragRef.current = null;\n }, []);\n\n const handleReset = useCallback(() => {\n setScale(1);\n setTranslate({ x: 0, y: 0 });\n }, []);\n\n const isZoomed = Math.abs(scale - 1) > 0.001 || translate.x !== 0 || translate.y !== 0;\n\n const handleClick = useCallback((e: React.MouseEvent) => {\n if (didDragRef.current) {\n e.stopPropagation();\n }\n }, []);\n\n const stopPropagation = useCallback((e: React.SyntheticEvent) => {\n e.stopPropagation();\n }, []);\n\n const diagramContent = (\n <div\n role=\"presentation\"\n className={cn('tw:group/zoom tw:relative', isFullscreen && 'tw:h-full')}\n onClick={handleClick}\n >\n <div\n role=\"presentation\"\n ref={containerRef}\n className={cn(\n 'tw:overflow-hidden tw:cursor-grab tw:active:cursor-grabbing tw:p-3',\n isFullscreen && 'tw:h-full',\n )}\n onMouseDown={handleMouseDown}\n onMouseMove={handleMouseMove}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n >\n <div\n className={cn(\n 'tw:flex tw:justify-center tw:origin-center',\n isFullscreen && 'tw:h-full tw:[&>svg]:h-full',\n )}\n style={{ transform: `translate(${translate.x}px, ${translate.y}px) scale(${scale})` }}\n dangerouslySetInnerHTML={{ __html: safeHtml }}\n />\n </div>\n <div\n role=\"presentation\"\n // `focus-within` as well as hover: the toolbar is opacity-0 but still in\n // the tab order, so without this a keyboard user tabs through invisible\n // controls with no visible focus ring.\n className=\"tw:absolute tw:right-1 tw:top-1 tw:flex tw:gap-1 tw:opacity-0 tw:transition-opacity tw:focus-within:opacity-100 tw:group-hover/zoom:opacity-100\"\n onClick={stopPropagation}\n >\n {isZoomed && (\n <Tooltip tooltip=\"Reset zoom\" placement=\"top\" triggerAsChild>\n <Button size=\"small\" variant=\"outline\" onClick={handleReset}>\n Reset\n </Button>\n </Tooltip>\n )}\n {copyText && (\n <ClipboardButton text={copyText} tooltip=\"Copy code\" size=\"icon-sm\" variant=\"outline\" />\n )}\n {renderActions?.(safeHtml)}\n <Tooltip\n tooltip={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'}\n placement=\"top\"\n triggerAsChild\n >\n <Button\n size=\"icon-sm\"\n variant=\"outline\"\n aria-label={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'}\n onClick={() => setIsFullscreen((f) => !f)}\n >\n {isFullscreen ? (\n <Minimize2 className=\"tw:size-4\" />\n ) : (\n <Maximize2 className=\"tw:size-4\" />\n )}\n </Button>\n </Tooltip>\n </div>\n </div>\n );\n\n if (isFullscreen) {\n return createPortal(\n <div\n role=\"presentation\"\n data-testid=\"zoomable-svg-fullscreen\"\n /**\n * Stacking contract for this overlay, which portals to `document.body`.\n *\n * - Sits at z-1051, the Modal/Sheet band: above page chrome.\n * - Stays *below* the floating-panel layer (z-1055: DropdownMenu,\n * Popover, Select, Combobox), which portals to `document.body` too —\n * an overlay above it hides any menu opened from the toolbar.\n * - `Tooltip` (z-1060) renders above, as it does over a Modal.\n * - `SpotlightBackdrop` (z-1056) dims this overlay rather than sitting\n * under it — by design, since it deliberately covers the portalled\n * surface tier so a tour's dim can't be punched through.\n * - An app may clamp poppers into this same band, making it a tie that\n * DOM order settles; Radix mounts its portal after this one.\n */\n className=\"tw:fixed tw:inset-0 tw:z-[1051] tw:bg-muted tw:p-4 tailwindcss-preflight\"\n onClick={stopPropagation}\n >\n {diagramContent}\n </div>,\n document.body,\n );\n }\n\n return (\n <div\n className={cn(\n 'tw:overflow-hidden tw:rounded-md tw:border tw:border-border tw:bg-muted',\n className,\n )}\n >\n {diagramContent}\n </div>\n );\n};\n","const PNG_SCALE = 2;\n\n// The root `<svg …>` tag, so the namespace check looks only at its attributes.\n// A plain `includes('xmlns=')` would also match a nested element or body text,\n// and would miss `xmlns = \"…\"` — adding a second declaration, which parsers\n// reject outright with \"Attribute xmlns redefined\".\nconst ROOT_SVG_TAG = /^<svg\\b[^>]*>/i;\nconst HAS_DEFAULT_NAMESPACE = /\\bxmlns\\s*=/i;\n\n// A standalone SVG file needs the namespace declaration; mermaid's inline output\n// omits it because an inline <svg> inherits it from the host document.\n// Trim before matching: the anchored `^<svg` misses markup that arrives with a\n// leading newline or indentation, which would emit a standalone file with no\n// namespace — unopenable in an image viewer.\nconst withSvgNamespace = (svg: string) => {\n const trimmed = svg.trim();\n const rootTag = trimmed.match(ROOT_SVG_TAG)?.[0];\n\n if (!rootTag || HAS_DEFAULT_NAMESPACE.test(rootTag)) return trimmed;\n\n return trimmed.replace(/^<svg\\b/i, '<svg xmlns=\"http://www.w3.org/2000/svg\"');\n};\n\nexport const toSvgFileContent = (svg: string) =>\n `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n${withSvgNamespace(svg).trim()}\\n`;\n\n// A single decimal number: `12`, `12.5`, `.5`. Deliberately stricter than\n// `[\\d.]+`, which also matches `1.2.3` — and `parseFloat` truncates that to\n// `1.2` rather than rejecting it, so a malformed value would pass as a plausible\n// one.\nconst NUMBER = String.raw`\\d+(?:\\.\\d+)?|\\.\\d+`;\n\n// `parseFloat` happily reads a relative length as a number — `\"100%\"` becomes\n// `100`, `\"2em\"` becomes `2` — and `makeResponsive` sets `width=\"100%\"` on every\n// mermaid root, so an SVG with no usable viewBox would rasterize 100px wide with\n// no error. Accept only a unitless number or an explicit `px`.\nconst PIXEL_LENGTH = new RegExp(String.raw`^\\s*(?:${NUMBER})(?:px)?\\s*$`, 'i');\n\nconst parsePixelLength = (value: string | null): number | null => {\n if (!PIXEL_LENGTH.test(value ?? '')) return null;\n\n const parsed = Number.parseFloat(value ?? '');\n\n return Number.isFinite(parsed) && parsed > 0 ? parsed : null;\n};\n\nexport const parseSvgSize = (svg: string) => {\n const doc = new DOMParser().parseFromString(withSvgNamespace(svg), 'image/svg+xml');\n const element = doc.documentElement;\n\n const viewBox = element\n .getAttribute('viewBox')\n ?.split(/[\\s,]+/)\n .map(Number);\n // `> 0`, not truthiness: a negative extent is accepted by a truthy check, and\n // negative canvas dimensions silently fall back to the 300x150 default — an\n // export at the wrong size with no error. Falling through to width/height is\n // the better answer, since those are usually still valid.\n if (viewBox?.length === 4 && viewBox.every((value) => Number.isFinite(value))) {\n const [, , width, height] = viewBox;\n if (width !== undefined && height !== undefined && width > 0 && height > 0) {\n return { width, height };\n }\n }\n\n const width = parsePixelLength(element.getAttribute('width'));\n const height = parsePixelLength(element.getAttribute('height'));\n\n return width !== null && height !== null ? { width, height } : null;\n};\n\n// Resolve the themed page background so the exported PNG follows the active\n// brand and color scheme instead of a frozen literal. Falls back to `white`\n// (a CSS keyword, not a brand-locked hex) when the token is unset.\n//\n// The token holds Tailwind's bare channel triplet (\"249 250 251\") so utilities\n// can add an alpha. Canvas `fillStyle` rejects that form *silently* and keeps\n// its previous value (black), so wrap it back into rgb() before use.\nconst CHANNEL_TRIPLET = new RegExp(String.raw`^(?:${NUMBER})\\s+(?:${NUMBER})\\s+(?:${NUMBER})$`);\n\nexport const toCanvasColor = (token: string) => {\n const trimmed = token.trim();\n if (!trimmed) return 'white';\n\n // Only wrap a well-formed triplet. A malformed one (`1.2.3 4 5`) would produce\n // an invalid `rgb()` that `fillStyle` rejects silently, painting the PNG on\n // whatever colour was set before — passing it through unwrapped at least lets\n // a genuine CSS color value work.\n return CHANNEL_TRIPLET.test(trimmed) ? `rgb(${trimmed})` : trimmed;\n};\n\nconst resolveBackground = () =>\n toCanvasColor(getComputedStyle(document.documentElement).getPropertyValue('--color-background'));\n\n/**\n * Rasterize SVG markup to a PNG blob at 2x for legible text.\n *\n * The SVG is loaded as a data URL rather than a blob URL: an <img> loading SVG\n * is treated as a foreign resource, so a blob URL would taint the canvas and\n * make toBlob throw a SecurityError. A background is painted first because a\n * transparent PNG reads as unusable when pasted into a slide deck.\n */\nexport const svgToPngBlob = async (svg: string, background?: string): Promise<Blob> => {\n const size = parseSvgSize(svg);\n if (!size) throw new Error('Cannot determine diagram dimensions.');\n\n const encoded = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(toSvgFileContent(svg))}`;\n\n const image = new Image();\n image.decoding = 'sync';\n await new Promise<void>((resolve, reject) => {\n image.onload = () => resolve();\n image.onerror = () => reject(new Error('Failed to load the diagram for export.'));\n image.src = encoded;\n });\n\n const canvas = document.createElement('canvas');\n canvas.width = Math.round(size.width * PNG_SCALE);\n canvas.height = Math.round(size.height * PNG_SCALE);\n\n const context = canvas.getContext('2d');\n if (!context) throw new Error('Canvas is unavailable in this browser.');\n\n context.fillStyle = background ?? resolveBackground();\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.drawImage(image, 0, 0, canvas.width, canvas.height);\n\n return new Promise<Blob>((resolve, reject) => {\n canvas.toBlob(\n (blob) => (blob ? resolve(blob) : reject(new Error('Failed to encode the PNG.'))),\n 'image/png',\n );\n });\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AA4BlB,MAAa,eAAe,EAC1B,MACA,UACA,WACA,oBACA,oBACW;CACX,MAAM,WAAW,cAEb,UAAU,SAAS,MAAM;EACvB,cAAc;GAAE,KAAK;GAAM,YAAY;EAAK;EAC5C,GAAI,qBAAqB,EAAE,UAAU,CAAC,eAAe,EAAE,IAAI,CAAC;CAC9D,CAAC,GACH,CAAC,MAAM,kBAAkB,CAC3B;CAEA,MAAM,eAAe,OAAuB,IAAI;CAChD,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,CAAC,WAAW,gBAAgB,SAAS;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC;CACzD,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CAEtD,gBAAgB;EACd,IAAI,CAAC,cAAc;EACnB,MAAM,aAAa,MAAqB;GACtC,IAAI,EAAE,QAAQ,UAAU;IAC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CAChD,OAAO,SAAS,KAAK,MAAM,KAAK,SAAS,SAAS;CAElD,MAAM,UAAU,OAAO,WAAW,IAAI;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,wCAAwC;CAEtE,QAAQ,YAAY,cAAc,kBAAkB;CACpD,QAAQ,SAAS,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM;CAClD,QAAQ,UAAU,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM;CAE1D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC5C,OAAO,QACJ,SAAU,OAAO,QAAQ,IAAI,IAAI,uBAAO,IAAI,MAAM,2BAA2B,CAAC,GAC/E,WACF;CACF,CAAC;AACH"}
|
package/dist/editors.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ChangeClassification, MergeConflict } from "./
|
|
2
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { ChangeClassification, FieldItemProps, MergeConflict } from "./FieldItem-CAPj9lj3.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
3
|
import { CompletionSource } from "@codemirror/autocomplete";
|
|
4
4
|
import { EditorView } from "@codemirror/view";
|
|
5
5
|
import { EditorState, EditorView as EditorView$1 } from "@uiw/react-codemirror";
|
|
6
6
|
import { SQLNamespace } from "@codemirror/lang-sql";
|
|
7
7
|
import { StreamLanguage } from "@codemirror/language";
|
|
8
|
+
import "@codemirror/lint";
|
|
8
9
|
import { SqlDialectName, SqlDialectName as SqlDialectName$1 } from "@keboola/codemirror-lang-sql";
|
|
9
10
|
import "@codemirror/state";
|
|
10
11
|
//#region src/components/CodeEditor/helpers.d.ts
|
|
@@ -19,7 +20,7 @@ type EditorVariable = {
|
|
|
19
20
|
};
|
|
20
21
|
//#endregion
|
|
21
22
|
//#region src/components/CodeEditor/CodeEditor.d.ts
|
|
22
|
-
type Props$
|
|
23
|
+
type Props$3 = {
|
|
23
24
|
value: string;
|
|
24
25
|
previousValue?: string;
|
|
25
26
|
/**
|
|
@@ -36,6 +37,35 @@ type Props$2 = {
|
|
|
36
37
|
placeholder?: string;
|
|
37
38
|
/** Names the editable region for screen readers — the editor has no visible label of its own. */
|
|
38
39
|
ariaLabel?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Names the editable region from an existing element, for when the label is already on screen.
|
|
42
|
+
* Prefer this over `ariaLabel` inside a form — `CodeEditorField` passes the field's own label id.
|
|
43
|
+
*/
|
|
44
|
+
ariaLabelledBy?: string;
|
|
45
|
+
/** Links the editable region to help / error text. Space-delimited idref list. */
|
|
46
|
+
ariaDescribedBy?: string;
|
|
47
|
+
/** Marks the editable region invalid. Visual error styling is the caller's (`variant="field"`). */
|
|
48
|
+
ariaInvalid?: boolean;
|
|
49
|
+
ariaRequired?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Treats a blank document as valid instead of a parse error (JSON modes only).
|
|
52
|
+
*
|
|
53
|
+
* - Off by default: for a standalone editor "Unexpected end of input" is correct, and at several
|
|
54
|
+
* call sites the gutter marker is the only thing explaining a Save button that
|
|
55
|
+
* `isValidJsonConfig('') === false` has already disabled.
|
|
56
|
+
* - `CodeEditorField` turns it on for a field that is not `required`, where an empty document is
|
|
57
|
+
* how the value is removed.
|
|
58
|
+
*/
|
|
59
|
+
allowBlankDocument?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Fires when focus leaves the editable region — what a form connector needs to mark its field
|
|
62
|
+
* blurred, which is the gate errors are revealed on.
|
|
63
|
+
*
|
|
64
|
+
* - Bound as a CodeMirror DOM handler on the content node, not on the wrapper: the wrapper is not
|
|
65
|
+
* what gets focused.
|
|
66
|
+
* - Installed only when passed, so an editor without it keeps the extension set it had.
|
|
67
|
+
*/
|
|
68
|
+
onBlur?: () => void;
|
|
39
69
|
/**
|
|
40
70
|
* Highlights every occurrence and scrolls the selected one into view. The find
|
|
41
71
|
* UI is the caller's — pass the query it holds, and omit both props entirely to
|
|
@@ -102,7 +132,7 @@ type Props$2 = {
|
|
|
102
132
|
readOnly?: boolean;
|
|
103
133
|
onChange: (value: string) => void;
|
|
104
134
|
});
|
|
105
|
-
declare const CodeEditor: ({ value, previousValue, onChange, variant, mode, placeholder, ariaLabel, searchQuery, searchMatchIndex, readOnly, inputLocked, autocompletions, completionSource, variables, extraKeys, withToggleCommentHint, withAutofocus, withLineNumbers, withLineWrapping, withCollapseUnchanged, withCopyButton, completeAny, help, helpPostfix, renderAdditionalButtons, className }: Props$
|
|
135
|
+
declare const CodeEditor: ({ value, previousValue, onChange, variant, mode, placeholder, ariaLabel, ariaLabelledBy, ariaDescribedBy, ariaInvalid, ariaRequired, allowBlankDocument, onBlur, searchQuery, searchMatchIndex, readOnly, inputLocked, autocompletions, completionSource, variables, extraKeys, withToggleCommentHint, withAutofocus, withLineNumbers, withLineWrapping, withCollapseUnchanged, withCopyButton, completeAny, help, helpPostfix, renderAdditionalButtons, className }: Props$3) => import("react/jsx-runtime").JSX.Element;
|
|
106
136
|
//#endregion
|
|
107
137
|
//#region src/components/CodeEditor/highlighting.d.ts
|
|
108
138
|
type HighlightedLines = {
|
|
@@ -119,7 +149,7 @@ type HighlightedLines = {
|
|
|
119
149
|
} | null;
|
|
120
150
|
//#endregion
|
|
121
151
|
//#region src/components/CodeEditor/SqlEditor.d.ts
|
|
122
|
-
type Props$
|
|
152
|
+
type Props$2 = {
|
|
123
153
|
value: string;
|
|
124
154
|
onChange?: (value: string) => void;
|
|
125
155
|
onSelectionChange?: (text: string) => void;
|
|
@@ -156,10 +186,10 @@ type Props$1 = {
|
|
|
156
186
|
highlightLines?: HighlightedLines;
|
|
157
187
|
dialect?: SqlDialectName$1;
|
|
158
188
|
};
|
|
159
|
-
declare const SqlEditor: ({ value, onChange, onSelectionChange, onCreateEditor, onDestroyEditor, onBlurEditor, onFocusEditor, placeholder, searchQuery, searchMatchIndex, readOnly, queryParser, autoFocus, lineNumbers, className, schema, completionSource, variables, defaultDatabase, defaultSchema, highlightLines, dialect }: Props$
|
|
189
|
+
declare const SqlEditor: ({ value, onChange, onSelectionChange, onCreateEditor, onDestroyEditor, onBlurEditor, onFocusEditor, placeholder, searchQuery, searchMatchIndex, readOnly, queryParser, autoFocus, lineNumbers, className, schema, completionSource, variables, defaultDatabase, defaultSchema, highlightLines, dialect }: Props$2) => import("react/jsx-runtime").JSX.Element;
|
|
160
190
|
//#endregion
|
|
161
191
|
//#region src/components/MergeEditor/MergeEditor.d.ts
|
|
162
|
-
type Props = {
|
|
192
|
+
type Props$1 = {
|
|
163
193
|
mergeValue: string;
|
|
164
194
|
handleMergeChange: (value: string) => void;
|
|
165
195
|
leftText: string;
|
|
@@ -190,7 +220,39 @@ type Props = {
|
|
|
190
220
|
leftDeleted?: boolean;
|
|
191
221
|
rightDeleted?: boolean;
|
|
192
222
|
};
|
|
193
|
-
declare const MergeEditor: ({ mergeValue, handleMergeChange, leftText, rightText, leftConflicts, rightConflicts, leftHighlightedLines, rightHighlightedLines, leftClassification, rightClassification, mergeHighlightedLines, mergeClassification, acceptLeft, acceptRight, dismissLeft, dismissRight, leftHeader, middleHeader, middleHeaderClassName, middleClassName, rightHeader, className, leftDeleted, rightDeleted }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
223
|
+
declare const MergeEditor: ({ mergeValue, handleMergeChange, leftText, rightText, leftConflicts, rightConflicts, leftHighlightedLines, rightHighlightedLines, leftClassification, rightClassification, mergeHighlightedLines, mergeClassification, acceptLeft, acceptRight, dismissLeft, dismissRight, leftHeader, middleHeader, middleHeaderClassName, middleClassName, rightHeader, className, leftDeleted, rightDeleted }: Props$1) => import("react/jsx-runtime").JSX.Element;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/components/CodeEditor/CodeEditorField.d.ts
|
|
226
|
+
type Props = FieldItemProps & Omit<ComponentProps<typeof CodeEditor>, 'value' | 'onChange' | 'onBlur' | 'ariaLabel' | 'ariaLabelledBy' | 'ariaDescribedBy' | 'ariaInvalid' | 'ariaRequired' | 'readOnly' | 'className' | 'allowBlankDocument'> & {
|
|
227
|
+
/** Styles the editor box; `className` styles the field frame. */
|
|
228
|
+
editorClassName?: string;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Code / JSON editor field. State is the raw editor text (`string`) — never a parsed value.
|
|
232
|
+
*
|
|
233
|
+
* ⚠️ Shipped from **`@keboola/design/editors`**, not as a `field.*` connector on `useAppForm`, and
|
|
234
|
+
* deliberately: CodeMirror plus its language modes is ~170 kB brotlied, and registering this in the root
|
|
235
|
+
* form hook pulled all of it into `@keboola/design`'s main entry — every consumer paying for an editor
|
|
236
|
+
* most of them never render. That is the whole reason the `editors` subpath exists.
|
|
237
|
+
*
|
|
238
|
+
* It still reads the field from context, so it composes exactly like a connector:
|
|
239
|
+
*
|
|
240
|
+
* ```tsx
|
|
241
|
+
* import { CodeEditorField } from '@keboola/design/editors';
|
|
242
|
+
*
|
|
243
|
+
* <form.AppField name="schema">{() => <CodeEditorField label="Schema" />}</form.AppField>
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* Text in, text out, deliberately: a JSON field is mid-edit invalid for most of the time the user is
|
|
247
|
+
* typing in it, and parsing on every keystroke would either throw away their cursor position or throw
|
|
248
|
+
* away the text. Parse in the schema (or at submit) and keep the editor's own content authoritative.
|
|
249
|
+
*
|
|
250
|
+
* `variant="field"` by default so it reads as a form control rather than a code block.
|
|
251
|
+
*
|
|
252
|
+
* Labelled with `aria-labelledby`, not `for`: CodeMirror's editable node is a `div[role="textbox"]`,
|
|
253
|
+
* which is not a labelable element.
|
|
254
|
+
*/
|
|
255
|
+
declare const CodeEditorField: ({ label, action, required, requiredMark, help, tooltip, className, 'aria-describedby': ariaDescribedBy, editorClassName, variant, ...editorProps }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
194
256
|
//#endregion
|
|
195
|
-
export { CodeEditor, type EditorVariable, type LANGUAGE_MODE, LANGUAGE_MODES, MergeEditor, type SqlDialectName, SqlEditor, isLanguageMode };
|
|
257
|
+
export { CodeEditor, CodeEditorField, type EditorVariable, type LANGUAGE_MODE, LANGUAGE_MODES, MergeEditor, type SqlDialectName, SqlEditor, isLanguageMode };
|
|
196
258
|
//# sourceMappingURL=editors.d.ts.map
|
package/dist/editors.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { cn } from "./classNames-BzrkDnOD.js";
|
|
2
2
|
import { ChevronsLeft, ChevronsRight, X } from "./icons-Cek151jC.js";
|
|
3
|
-
import { Button } from "./Button-
|
|
3
|
+
import { Button } from "./Button-6xBX0nNl.js";
|
|
4
|
+
import { FieldItem, useFieldContext } from "./FieldItem-D-h1NeBo.js";
|
|
4
5
|
import { CHANGE_CLASS } from "./internal/components/MergeEditor/constants.js";
|
|
5
6
|
import { useStableCallback } from "./internal/hooks/useStableCallback.js";
|
|
6
7
|
import { resolveToken } from "./themeTokens-BNg98Mu9.js";
|
|
7
|
-
import { CodeEditor, LANGUAGE_MODES, buildBaseThemeStyles, buildBasicSetup, buildCanvasChrome, buildChromeStyles, buildCustomTheme, isLanguageMode, searchExtension, updateSearch, useThemedExtension, useTooltipsExtension, useVariableCompletion } from "./CodeEditor-
|
|
8
|
+
import { CodeEditor, LANGUAGE_MODES, buildBaseThemeStyles, buildBasicSetup, buildCanvasChrome, buildChromeStyles, buildCustomTheme, isLanguageMode, searchExtension, updateSearch, useThemedExtension, useTooltipsExtension, useVariableCompletion } from "./CodeEditor-DyaN-Ij2.js";
|
|
8
9
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
9
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
import { Decoration, EditorView, GutterMarker, ViewPlugin, gutter, gutterLineClass } from "@codemirror/view";
|
|
@@ -755,6 +756,60 @@ const MergeEditor = ({ mergeValue, handleMergeChange, leftText, rightText, leftC
|
|
|
755
756
|
});
|
|
756
757
|
};
|
|
757
758
|
//#endregion
|
|
758
|
-
|
|
759
|
+
//#region src/components/CodeEditor/CodeEditorField.tsx
|
|
760
|
+
/**
|
|
761
|
+
* Code / JSON editor field. State is the raw editor text (`string`) — never a parsed value.
|
|
762
|
+
*
|
|
763
|
+
* ⚠️ Shipped from **`@keboola/design/editors`**, not as a `field.*` connector on `useAppForm`, and
|
|
764
|
+
* deliberately: CodeMirror plus its language modes is ~170 kB brotlied, and registering this in the root
|
|
765
|
+
* form hook pulled all of it into `@keboola/design`'s main entry — every consumer paying for an editor
|
|
766
|
+
* most of them never render. That is the whole reason the `editors` subpath exists.
|
|
767
|
+
*
|
|
768
|
+
* It still reads the field from context, so it composes exactly like a connector:
|
|
769
|
+
*
|
|
770
|
+
* ```tsx
|
|
771
|
+
* import { CodeEditorField } from '@keboola/design/editors';
|
|
772
|
+
*
|
|
773
|
+
* <form.AppField name="schema">{() => <CodeEditorField label="Schema" />}</form.AppField>
|
|
774
|
+
* ```
|
|
775
|
+
*
|
|
776
|
+
* Text in, text out, deliberately: a JSON field is mid-edit invalid for most of the time the user is
|
|
777
|
+
* typing in it, and parsing on every keystroke would either throw away their cursor position or throw
|
|
778
|
+
* away the text. Parse in the schema (or at submit) and keep the editor's own content authoritative.
|
|
779
|
+
*
|
|
780
|
+
* `variant="field"` by default so it reads as a form control rather than a code block.
|
|
781
|
+
*
|
|
782
|
+
* Labelled with `aria-labelledby`, not `for`: CodeMirror's editable node is a `div[role="textbox"]`,
|
|
783
|
+
* which is not a labelable element.
|
|
784
|
+
*/
|
|
785
|
+
const CodeEditorField = ({ label, action, required, requiredMark, help, tooltip, className, "aria-describedby": ariaDescribedBy, editorClassName, variant = "field", ...editorProps }) => {
|
|
786
|
+
const field = useFieldContext();
|
|
787
|
+
return /* @__PURE__ */ jsx(FieldItem, {
|
|
788
|
+
label,
|
|
789
|
+
action,
|
|
790
|
+
required,
|
|
791
|
+
requiredMark,
|
|
792
|
+
labelling: "aria-labelledby",
|
|
793
|
+
help,
|
|
794
|
+
tooltip,
|
|
795
|
+
className,
|
|
796
|
+
"aria-describedby": ariaDescribedBy,
|
|
797
|
+
children: (control) => /* @__PURE__ */ jsx(CodeEditor, {
|
|
798
|
+
...editorProps,
|
|
799
|
+
variant,
|
|
800
|
+
className: editorClassName,
|
|
801
|
+
ariaLabelledBy: control["aria-labelledby"],
|
|
802
|
+
ariaDescribedBy: control["aria-describedby"],
|
|
803
|
+
ariaInvalid: control["aria-invalid"],
|
|
804
|
+
ariaRequired: control["aria-required"],
|
|
805
|
+
allowBlankDocument: !required,
|
|
806
|
+
value: field.state.value ?? "",
|
|
807
|
+
onChange: field.handleChange,
|
|
808
|
+
onBlur: field.handleBlur
|
|
809
|
+
})
|
|
810
|
+
});
|
|
811
|
+
};
|
|
812
|
+
//#endregion
|
|
813
|
+
export { CodeEditor, CodeEditorField, LANGUAGE_MODES, MergeEditor, SqlEditor, isLanguageMode };
|
|
759
814
|
|
|
760
815
|
//# sourceMappingURL=editors.js.map
|