@jsudc/react 0.3.0 → 0.4.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/README.md +561 -20
- package/dist/calendar/CalendarRenderer.js +1 -1
- package/dist/calendar/EventDetail.js +1 -1
- package/dist/calendar.js +1 -1
- package/dist/cards/CardRenderer.d.ts +2 -1
- package/dist/cards/CardRenderer.js +143 -109
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/cells/registry.d.ts +60 -0
- package/dist/cells/registry.js +47 -0
- package/dist/cells/registry.js.map +1 -0
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +4 -3
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js +2 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/popover.js +2 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/select.js +2 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/toast.js +3 -2
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/tooltip.js +2 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/Freshness.js +1 -1
- package/dist/data-view/SearchBox.js +1 -1
- package/dist/data-view/UdcDataView.d.ts +83 -1
- package/dist/data-view/UdcDataView.js +171 -85
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/data-view/useDataViewState.d.ts +8 -0
- package/dist/data-view/useDataViewState.js +2 -1
- package/dist/data-view/useDataViewState.js.map +1 -1
- package/dist/headless.d.ts +3 -0
- package/dist/headless.js +5 -2
- package/dist/i18n/translations.js +8 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -3
- package/dist/kanban/KanbanColumn.js +1 -1
- package/dist/kanban/KanbanRenderer.js +1 -1
- package/dist/kanban/model.d.ts +7 -0
- package/dist/kanban/model.js +19 -1
- package/dist/kanban/model.js.map +1 -1
- package/dist/kanban/useKanbanBoard.d.ts +5 -1
- package/dist/kanban/useKanbanBoard.js +6 -2
- package/dist/kanban/useKanbanBoard.js.map +1 -1
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +12 -0
- package/dist/lib/scope.js.map +1 -0
- package/dist/lookup/LookupCombobox.js +2 -2
- package/dist/lookup/LookupCombobox.js.map +1 -1
- package/dist/map/MapRenderer.js +1 -1
- package/dist/renderers/types.d.ts +12 -0
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +74 -0
- package/dist/rows/useRowActivation.js +225 -0
- package/dist/rows/useRowActivation.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/schema-editor/TagInput.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +2 -0
- package/dist/table/CellEditor.js +1 -0
- package/dist/table/CellEditor.js.map +1 -1
- package/dist/table/TableRenderer.d.ts +2 -1
- package/dist/table/TableRenderer.js +41 -8
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.d.ts +13 -2
- package/dist/table/cells.js +14 -1
- package/dist/table/cells.js.map +1 -1
- package/dist/table/states.d.ts +6 -0
- package/dist/table/states.js +14 -1
- package/dist/table/states.js.map +1 -1
- package/dist/tree/TreeNode.js +1 -1
- package/dist/tree/TreeRenderer.js +1 -1
- package/dist/udc/client.d.ts +15 -1
- package/dist/udc/client.js +31 -10
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +8 -3
- package/dist/udc/provider.d.ts +5 -2
- package/dist/udc/provider.js +6 -1
- package/dist/udc/provider.js.map +1 -1
- package/dist/ui-kit/ui.d.ts +1 -0
- package/dist/ui.js +2 -1
- package/dist/url-state/adapters.d.ts +23 -0
- package/dist/url-state/adapters.js +57 -0
- package/dist/url-state/adapters.js.map +1 -0
- package/dist/url-state/index.d.ts +1 -0
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LookupCombobox.js","names":[],"sources":["../../src/lookup/LookupCombobox.tsx"],"sourcesContent":["import type { FieldDef, LookupDef } from \"@jsudc/core\";\nimport { X } from \"lucide-react\";\nimport { type KeyboardEvent, useEffect, useRef, useState } from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { cn } from \"../lib/utils.js\";\nimport { lookupLabel } from \"./label.js\";\nimport { type LookupOption, useLookupOptions } from \"./options.js\";\nimport { keyString, lookupKeys, useUdcLookup } from \"./useUdcLookup.js\";\n\nexport type ComboboxCommitReason = \"enter\" | \"tab\" | \"shift-tab\" | \"blur\";\n\n/**\n * The inline editor of a lookup cell: a search over the target collection\n * (`contains` on `label_field`, the first 50 by label) in a list under the\n * cell. On a `lookup` a pick commits that key; on a `lookup_array` a pick\n * adds or removes a key, and Enter on an empty search commits the list.\n * Arrow keys move, Escape cancels, Tab commits and moves on.\n */\nexport function LookupCombobox({\n def,\n lookup,\n initial,\n saving,\n onCommit,\n onCancel,\n}: {\n def: FieldDef;\n lookup: LookupDef;\n initial: unknown;\n saving: boolean;\n /** `value` is the key (or `null`), on a lookup_array the list of keys. */\n onCommit: (value: unknown, reason: ComboboxCommitReason) => void;\n onCancel: () => void;\n}) {\n const { t } = useI18n();\n const multi = def.type === \"lookup_array\";\n const [needle, setNeedle] = useState(\"\");\n const [active, setActive] = useState(0);\n // Keys as stored: a number key stays a number when it is written back.\n const [picked, setPicked] = useState<unknown[]>(() =>\n multi ? (Array.isArray(initial) ? [...initial] : []) : [],\n );\n const { options, isLoading } = useLookupOptions(lookup, needle);\n const labels = useUdcLookup(lookup, multi ? picked : [initial]);\n const input = useRef<HTMLInputElement>(null);\n const done = useRef(false);\n\n useEffect(() => input.current?.focus(), []);\n\n const pickedKeys = new Set(lookupKeys(picked));\n // A single lookup offers \"none\" first, so a key can be cleared.\n const rows: (LookupOption | null)[] = multi ? options : [null, ...options];\n\n const commit = (value: unknown, reason: ComboboxCommitReason) => {\n if (done.current || saving) return;\n done.current = true;\n onCommit(value, reason);\n };\n\n const choose = (o: LookupOption | null, reason: ComboboxCommitReason = \"enter\") => {\n if (!multi) return commit(o ? o.raw : null, reason);\n if (!o) return;\n setPicked((p) =>\n pickedKeys.has(o.key) ? p.filter((k) => keyString(k) !== o.key) : [...p, o.raw],\n );\n setNeedle(\"\");\n input.current?.focus();\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n const step = e.key === \"ArrowDown\" ? 1 : -1;\n setActive((a) => Math.max(0, Math.min(rows.length - 1, a + step)));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (multi && needle === \"\") commit(picked, \"enter\");\n else if (rows.length) choose(rows[active] ?? null);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n done.current = true;\n onCancel();\n } else if (e.key === \"Tab\") {\n e.preventDefault();\n const reason = e.shiftKey ? \"shift-tab\" : \"tab\";\n if (multi) commit(picked, reason);\n else {\n done.current = true;\n onCancel();\n }\n } else if (multi && e.key === \"Backspace\" && needle === \"\" && picked.length) {\n setPicked((p) => p.slice(0, -1));\n }\n };\n\n const current = multi ? undefined : lookupLabel(labels.row(initial), lookup);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: focus leaving the whole editor is the commit, not an interaction\n <div\n className=\"udc:relative udc:flex udc:h-full udc:w-full udc:min-w-0 udc:items-center udc:gap-1\"\n data-testid=\"lookup-combobox\"\n onBlur={(e) => {\n // Leaving the editor (not moving inside it) commits a list and drops a single pick.\n if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;\n if (multi) commit(picked, \"blur\");\n else {\n done.current = true;\n onCancel();\n }\n }}\n >\n {multi\n ? picked.map((k) => {\n const key = keyString(k);\n return (\n <span\n key={key}\n data-testid=\"lookup-picked\"\n className=\"udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:gap-0.5 udc:rounded-full udc:bg-muted udc:pr-0.5 udc:pl-2 udc:text-[11px] udc:font-medium\"\n >\n {lookupLabel(labels.row(k), lookup) ?? key}\n <button\n type=\"button\"\n aria-label={`${t(\"APP\", \"CLEAR\")} ${key}`}\n className=\"udc:grid udc:size-4 udc:place-items-center udc:rounded-full udc:hover:bg-primary/15\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setPicked((p) => p.filter((x) => keyString(x) !== key))}\n >\n <X className=\"udc:size-2.5\" />\n </button>\n </span>\n );\n })\n : null}\n <input\n ref={input}\n type=\"text\"\n role=\"combobox\"\n aria-expanded\n aria-controls=\"udc-lookup-options\"\n aria-activedescendant={`udc-lookup-option-${active}`}\n data-testid=\"lookup-search\"\n className=\"udc:h-full udc:min-w-12 udc:flex-1 udc:bg-transparent udc:text-[13px] udc:text-foreground udc:outline-none\"\n value={needle}\n placeholder={current ?? t(\"APP\", \"LOOKUP_SEARCH\")}\n readOnly={saving}\n onChange={(e) => {\n setNeedle(e.target.value);\n setActive(0);\n }}\n onKeyDown={onKeyDown}\n />\n <div\n id=\"udc-lookup-options\"\n role=\"listbox\"\n aria-multiselectable={multi || undefined}\n data-testid=\"lookup-options\"\n className=\"udc-scroll-thin udc:absolute udc:top-full udc:-left-1.5 udc:z-30 udc:mt-1 udc:max-h-64 udc:w-64 udc:overflow-y-auto udc:rounded-md udc:border udc:border-border udc:bg-popover udc:p-1 udc:text-popover-foreground udc:shadow-md\"\n >\n {rows.map((o, i) => {\n const selected = o\n ? multi\n ? pickedKeys.has(o.key)\n : keyString(initial) === o.key\n : false;\n return (\n <div\n key={o?.key ?? \"∅\"}\n id={`udc-lookup-option-${i}`}\n role=\"option\"\n tabIndex={-1}\n aria-selected={selected}\n data-testid={o ? `lookup-option-${o.key}` : \"lookup-option-none\"}\n data-label={o?.label}\n onMouseDown={(e) => e.preventDefault()}\n onMouseEnter={() => setActive(i)}\n onClick={() => choose(o)}\n onKeyDown={() => {}}\n className={cn(\n \"udc:flex udc:h-7 udc:cursor-pointer udc:items-center udc:gap-2 udc:rounded-sm udc:px-2 udc:text-[13px]\",\n i === active && \"udc:bg-hover\",\n selected && \"udc:font-semibold udc:text-primary\",\n !o && \"udc:text-muted-foreground\",\n )}\n >\n <span className=\"udc:truncate\">{o ? o.label : t(\"APP\", \"LOOKUP_NONE\")}</span>\n </div>\n );\n })}\n {!isLoading && options.length === 0 ? (\n <div className=\"udc:px-2 udc:py-1.5 udc:text-xs udc:text-muted-foreground\">\n {t(\"APP\", \"LOOKUP_NO_MATCH\")}\n </div>\n ) : null}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAe,EAC7B,KACA,QACA,SACA,QACA,UACA,YASC;CACD,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,QAAQ,IAAI,SAAS;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,CAAC,QAAQ,aAAa,SAAS,CAAC;CAEtC,MAAM,CAAC,QAAQ,aAAa,eAC1B,QAAS,MAAM,QAAQ,OAAO,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC,IAAK,CAAC,CAC1D;CACA,MAAM,EAAE,SAAS,cAAc,iBAAiB,QAAQ,MAAM;CAC9D,MAAM,SAAS,aAAa,QAAQ,QAAQ,SAAS,CAAC,OAAO,CAAC;CAC9D,MAAM,QAAQ,OAAyB,IAAI;CAC3C,MAAM,OAAO,OAAO,KAAK;CAEzB,gBAAgB,MAAM,SAAS,MAAM,GAAG,CAAC,CAAC;CAE1C,MAAM,aAAa,IAAI,IAAI,WAAW,MAAM,CAAC;CAE7C,MAAM,OAAgC,QAAQ,UAAU,CAAC,MAAM,GAAG,OAAO;CAEzE,MAAM,UAAU,OAAgB,WAAiC;EAC/D,IAAI,KAAK,WAAW,QAAQ;EAC5B,KAAK,UAAU;EACf,SAAS,OAAO,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AM,EAAE,eAAe;MACrC,oBAAoB,UAAU,CAAC;MAC/B,eAAe,OAAO,CAAC;MACvB,iBAAiB,CAAC;MAClB,WAAW,GACT,0GACA,MAAM,UAAU,gBAChB,YAAY,sCACZ,CAAC,KAAK,2BACR;MAEA,UAAA,oBAAC,QAAD;OAAM,WAAU;OAAgB,UAAA,IAAI,EAAE,QAAQ,EAAE,OAAO,aAAa;MAAQ,CAAA;KACzE,GAnBE,GAAG,OAAO,GAmBZ;IAET,CAAC,GACA,CAAC,aAAa,QAAQ,WAAW,IAChC,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,EAAE,OAAO,iBAAiB;IACxB,CAAA,IACH,IACD;;EACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"LookupCombobox.js","names":[],"sources":["../../src/lookup/LookupCombobox.tsx"],"sourcesContent":["import type { FieldDef, LookupDef } from \"@jsudc/core\";\nimport { X } from \"lucide-react\";\nimport { type KeyboardEvent, useEffect, useRef, useState } from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { cn } from \"../lib/utils.js\";\nimport { lookupLabel } from \"./label.js\";\nimport { type LookupOption, useLookupOptions } from \"./options.js\";\nimport { keyString, lookupKeys, useUdcLookup } from \"./useUdcLookup.js\";\n\nexport type ComboboxCommitReason = \"enter\" | \"tab\" | \"shift-tab\" | \"blur\";\n\n/**\n * The inline editor of a lookup cell: a search over the target collection\n * (`contains` on `label_field`, the first 50 by label) in a list under the\n * cell. On a `lookup` a pick commits that key; on a `lookup_array` a pick\n * adds or removes a key, and Enter on an empty search commits the list.\n * Arrow keys move, Escape cancels, Tab commits and moves on.\n */\nexport function LookupCombobox({\n def,\n lookup,\n initial,\n saving,\n onCommit,\n onCancel,\n}: {\n def: FieldDef;\n lookup: LookupDef;\n initial: unknown;\n saving: boolean;\n /** `value` is the key (or `null`), on a lookup_array the list of keys. */\n onCommit: (value: unknown, reason: ComboboxCommitReason) => void;\n onCancel: () => void;\n}) {\n const { t } = useI18n();\n const multi = def.type === \"lookup_array\";\n const [needle, setNeedle] = useState(\"\");\n const [active, setActive] = useState(0);\n // Keys as stored: a number key stays a number when it is written back.\n const [picked, setPicked] = useState<unknown[]>(() =>\n multi ? (Array.isArray(initial) ? [...initial] : []) : [],\n );\n const { options, isLoading } = useLookupOptions(lookup, needle);\n const labels = useUdcLookup(lookup, multi ? picked : [initial]);\n const input = useRef<HTMLInputElement>(null);\n const done = useRef(false);\n\n useEffect(() => input.current?.focus(), []);\n\n const pickedKeys = new Set(lookupKeys(picked));\n // A single lookup offers \"none\" first, so a key can be cleared.\n const rows: (LookupOption | null)[] = multi ? options : [null, ...options];\n\n const commit = (value: unknown, reason: ComboboxCommitReason) => {\n if (done.current || saving) return;\n done.current = true;\n onCommit(value, reason);\n };\n\n const choose = (o: LookupOption | null, reason: ComboboxCommitReason = \"enter\") => {\n if (!multi) return commit(o ? o.raw : null, reason);\n if (!o) return;\n setPicked((p) =>\n pickedKeys.has(o.key) ? p.filter((k) => keyString(k) !== o.key) : [...p, o.raw],\n );\n setNeedle(\"\");\n input.current?.focus();\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n const step = e.key === \"ArrowDown\" ? 1 : -1;\n setActive((a) => Math.max(0, Math.min(rows.length - 1, a + step)));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (multi && needle === \"\") commit(picked, \"enter\");\n else if (rows.length) choose(rows[active] ?? null);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n done.current = true;\n onCancel();\n } else if (e.key === \"Tab\") {\n e.preventDefault();\n const reason = e.shiftKey ? \"shift-tab\" : \"tab\";\n if (multi) commit(picked, reason);\n else {\n done.current = true;\n onCancel();\n }\n } else if (multi && e.key === \"Backspace\" && needle === \"\" && picked.length) {\n setPicked((p) => p.slice(0, -1));\n }\n };\n\n const current = multi ? undefined : lookupLabel(labels.row(initial), lookup);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: focus leaving the whole editor is the commit, not an interaction\n <div\n className=\"udc:relative udc:flex udc:h-full udc:w-full udc:min-w-0 udc:items-center udc:gap-1\"\n data-testid=\"lookup-combobox\"\n onBlur={(e) => {\n // Leaving the editor (not moving inside it) commits a list and drops a single pick.\n if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;\n if (multi) commit(picked, \"blur\");\n else {\n done.current = true;\n onCancel();\n }\n }}\n >\n {multi\n ? picked.map((k) => {\n const key = keyString(k);\n return (\n <span\n key={key}\n data-testid=\"lookup-picked\"\n className=\"udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:gap-0.5 udc:rounded-full udc:bg-muted udc:pr-0.5 udc:pl-2 udc:text-[11px] udc:font-medium\"\n >\n {lookupLabel(labels.row(k), lookup) ?? key}\n <button\n type=\"button\"\n aria-label={`${t(\"APP\", \"CLEAR\")} ${key}`}\n className=\"udc:grid udc:size-4 udc:place-items-center udc:rounded-full udc:hover:bg-primary/15\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setPicked((p) => p.filter((x) => keyString(x) !== key))}\n >\n <X className=\"udc:size-2.5\" />\n </button>\n </span>\n );\n })\n : null}\n <input\n ref={input}\n type=\"text\"\n role=\"combobox\"\n aria-expanded\n aria-controls=\"udc-lookup-options\"\n aria-activedescendant={`udc-lookup-option-${active}`}\n data-testid=\"lookup-search\"\n className=\"udc:h-full udc:min-w-12 udc:flex-1 udc:bg-transparent udc:text-[13px] udc:text-foreground udc:outline-none\"\n value={needle}\n placeholder={current ?? t(\"APP\", \"LOOKUP_SEARCH\")}\n readOnly={saving}\n onChange={(e) => {\n setNeedle(e.target.value);\n setActive(0);\n }}\n onKeyDown={onKeyDown}\n />\n <div\n id=\"udc-lookup-options\"\n role=\"listbox\"\n aria-multiselectable={multi || undefined}\n data-testid=\"lookup-options\"\n className=\"udc-scroll-thin udc:absolute udc:top-full udc:-left-1.5 udc:z-30 udc:mt-1 udc:max-h-64 udc:w-64 udc:overflow-y-auto udc:rounded-md udc:border udc:border-border udc:bg-surface-raised udc:p-1 udc:text-foreground udc:shadow-md\"\n >\n {rows.map((o, i) => {\n const selected = o\n ? multi\n ? pickedKeys.has(o.key)\n : keyString(initial) === o.key\n : false;\n return (\n <div\n key={o?.key ?? \"∅\"}\n id={`udc-lookup-option-${i}`}\n role=\"option\"\n tabIndex={-1}\n aria-selected={selected}\n data-testid={o ? `lookup-option-${o.key}` : \"lookup-option-none\"}\n data-label={o?.label}\n onMouseDown={(e) => e.preventDefault()}\n onMouseEnter={() => setActive(i)}\n onClick={() => choose(o)}\n onKeyDown={() => {}}\n className={cn(\n \"udc:flex udc:h-7 udc:cursor-pointer udc:items-center udc:gap-2 udc:rounded-sm udc:px-2 udc:text-[13px]\",\n i === active && \"udc:bg-hover\",\n selected && \"udc:font-semibold udc:text-primary\",\n !o && \"udc:text-muted-foreground\",\n )}\n >\n <span className=\"udc:truncate\">{o ? o.label : t(\"APP\", \"LOOKUP_NONE\")}</span>\n </div>\n );\n })}\n {!isLoading && options.length === 0 ? (\n <div className=\"udc:px-2 udc:py-1.5 udc:text-xs udc:text-muted-foreground\">\n {t(\"APP\", \"LOOKUP_NO_MATCH\")}\n </div>\n ) : null}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAe,EAC7B,KACA,QACA,SACA,QACA,UACA,YASC;CACD,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,QAAQ,IAAI,SAAS;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,CAAC,QAAQ,aAAa,SAAS,CAAC;CAEtC,MAAM,CAAC,QAAQ,aAAa,eAC1B,QAAS,MAAM,QAAQ,OAAO,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC,IAAK,CAAC,CAC1D;CACA,MAAM,EAAE,SAAS,cAAc,iBAAiB,QAAQ,MAAM;CAC9D,MAAM,SAAS,aAAa,QAAQ,QAAQ,SAAS,CAAC,OAAO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;IACL,wBAAsB,SAAS,KAAA;IAC/B,eAAY;IACZ,WAAU;IALZ,UAAA,CAOG,KAAK,KAAK,GAAG,MAAM;KAClB,MAAM,WAAW,IACb,QACE,WAAW,IAAI,EAAE,GAAG,IACpB,UAAU,OAAO,MAAM,EAAE,MAC3B;KACJ,OACE,oBAAC,OAAD;MAEE,IAAI,qBAAqB;MACzB,MAAK;MACL,UAAU;MACV,iBAAe;MACf,eAAa,IAAI,iBAAiB,EAAE,QAAQ;MAC5C,cAAY,GAAG;MACf,cAAc,MAAM,EAAE,eAAe;MACrC,oBAAoB,UAAU,CAAC;MAC/B,eAAe,OAAO,CAAC;MACvB,iBAAiB,CAAC;MAClB,WAAW,GACT,0GACA,MAAM,UAAU,gBAChB,YAAY,sCACZ,CAAC,KAAK,2BACR;MAEA,UAAA,oBAAC,QAAD;OAAM,WAAU;OAAgB,UAAA,IAAI,EAAE,QAAQ,EAAE,OAAO,aAAa;MAAQ,CAAA;KACzE,GAnBE,GAAG,OAAO,GAmBZ;IAET,CAAC,GACA,CAAC,aAAa,QAAQ,WAAW,IAChC,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,EAAE,OAAO,iBAAiB;IACxB,CAAA,IACH,IACD;;EACF;;AAET"}
|
package/dist/map/MapRenderer.js
CHANGED
|
@@ -5,8 +5,8 @@ import { EmptyState, ErrorState } from "../table/states.js";
|
|
|
5
5
|
import { useUdcAllRows } from "../udc/hooks.js";
|
|
6
6
|
import { useUiKit } from "../ui-kit/context.js";
|
|
7
7
|
import { airplaneHtml, boundsOf, initialView, regionAt, regionById, toMarkers, trailMarkers } from "./model.js";
|
|
8
|
-
import { Maximize } from "lucide-react";
|
|
9
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { Maximize } from "lucide-react";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import "leaflet/dist/leaflet.css";
|
|
12
12
|
import L from "leaflet";
|
|
@@ -65,6 +65,18 @@ export interface RendererProps {
|
|
|
65
65
|
onCount: (count: RendererCount | null) => void;
|
|
66
66
|
/** Set when the view has `folder_options`. */
|
|
67
67
|
folder?: FolderNav | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Row activation (0.4.0; `useRowActivation` of `@jsudc/react/headless` does
|
|
70
|
+
* all of it): Enter or a plain click on a row. Absent unless the host asked.
|
|
71
|
+
*/
|
|
72
|
+
onRowActivate?: ((row: Row) => void) | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The row to draw as active; `null` for none. Set (kept by the view when the
|
|
75
|
+
* host does not control it) whenever activation is on, else absent.
|
|
76
|
+
*/
|
|
77
|
+
activeRowId?: string | null | undefined;
|
|
78
|
+
/** Report the active row moving (keys, a click on another row); set whenever activation is on. */
|
|
79
|
+
onActiveRowChange?: ((row: Row | null) => void) | undefined;
|
|
68
80
|
}
|
|
69
81
|
export interface RendererEntry {
|
|
70
82
|
component: ComponentType<RendererProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/renderers/types.ts"],"sourcesContent":["import type { DescribeResponse, FilterNode, FolderOptions, Row, SortKey } from \"@jsudc/core\";\nimport type { LucideIcon } from \"lucide-react\";\nimport type { ComponentType } from \"react\";\nimport type { ChartWindowState } from \"../chart/useChartWindow.js\";\nimport type { SchemaAction } from \"../schema-editor/fieldForm.js\";\nimport type { UdcCollectionResult } from \"../udc/hooks.js\";\nimport type { PagingMode } from \"../udc/keys.js\";\n\n/** The row count a renderer that loads its own rows reports to the toolbar. */\nexport interface RendererCount {\n shown: number;\n total: number | null;\n /**\n * `nodes`: the toolbar reads \"N nodes\" (the tree), `map`: \"N on map of M\"\n * (rows without a position are not drawn), `chart`: \"N points in window of\n * M\" (M counts the filter without the window), instead of \"Showing N of M\".\n */\n unit?: \"nodes\" | \"map\" | \"chart\";\n /** A source serving a fetched copy (http_api): when it was fetched, and whether it is stale. */\n fetchedAt?: string | null;\n stale?: boolean;\n}\n\n/** A folder-shaped collection (`folder_options`): what a folder row or a file row does on click. */\nexport interface FolderNav {\n options: FolderOptions;\n /** Open a folder by its path (`\"\"`: the root). */\n open: (path: string) => void;\n /** Preview a file row; absent when the view has no preview. */\n openFile?: ((row: Row) => void) | undefined;\n}\n\n/** Is `row` a folder of `nav`'s listing (the `..` row included)? */\nexport function isFolderRow(row: Row, nav: FolderNav): boolean {\n return row[nav.options.kind_field] === nav.options.dir_value;\n}\n\n/** What `<UdcDataView>` hands every renderer; each takes the parts it uses. */\nexport interface RendererProps {\n collection: string;\n /** `describe` with soft-deleted fields already gone. */\n describe: DescribeResponse;\n /** The data view's paged list; loaded only for a renderer with `paging`. */\n data: UdcCollectionResult;\n /** Search, chips and filter tree, composed. */\n filter: FilterNode | undefined;\n /** Chips and filter tree without the search: for a renderer that searches what it loaded. */\n baseFilter: FilterNode | undefined;\n /**\n * The chart window, when the view has one and it applies (on the chart tab,\n * or on any tab once the URL picked it): already ANDed into `filter` and\n * `baseFilter`.\n */\n chartWindow?: ChartWindowState | undefined;\n /** `filter` without the chart window: what \"of M\" counts. */\n unwindowedFilter?: FilterNode | undefined;\n /** The search box, as typed. */\n search: string;\n sort: SortKey[];\n onSort: (field: string, multi: boolean) => void;\n mode: PagingMode;\n page: number;\n limit: number;\n onPage: (page: number) => void;\n filtered: boolean;\n onClearFilters: () => void;\n resetKey: string;\n /** Set when the schema may be edited and the renderer has `editMode`. */\n onSchemaAction?: ((a: SchemaAction) => void) | undefined;\n /** For a renderer without `paging`: the count the toolbar shows. */\n onCount: (count: RendererCount | null) => void;\n /** Set when the view has `folder_options`. */\n folder?: FolderNav | undefined;\n}\n\nexport interface RendererEntry {\n component: ComponentType<RendererProps>;\n icon: LucideIcon;\n /** `APP.<labelKey>` is the tab label. */\n labelKey: string;\n /** Reads the data view's paged list: the paging toggle shows, the list loads. */\n paging: boolean;\n /** Offers the schema editor (column menus, add column). */\n editMode: boolean;\n /** Extra controls in the toolbar while this tab is open. */\n toolbar?: ComponentType<{ collection: string; describe: DescribeResponse }>;\n}\n\n/** One renderer as its subpath exports it (`tableRenderer` from `@jsudc/react/table`). */\nexport interface RendererDefinition extends RendererEntry {\n /** The name a view lists in `available_renderers`. */\n name: string;\n}\n\n/** Renderer name → entry: what `UdcDataView` draws its tabs with. `createRendererRegistry` builds one. */\nexport type RendererRegistry = Readonly<Record<string, RendererEntry>>;\n"],"mappings":";;AAiCA,SAAgB,YAAY,KAAU,KAAyB;CAC7D,OAAO,IAAI,IAAI,QAAQ,gBAAgB,IAAI,QAAQ;AACrD"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/renderers/types.ts"],"sourcesContent":["import type { DescribeResponse, FilterNode, FolderOptions, Row, SortKey } from \"@jsudc/core\";\nimport type { LucideIcon } from \"lucide-react\";\nimport type { ComponentType } from \"react\";\nimport type { ChartWindowState } from \"../chart/useChartWindow.js\";\nimport type { SchemaAction } from \"../schema-editor/fieldForm.js\";\nimport type { UdcCollectionResult } from \"../udc/hooks.js\";\nimport type { PagingMode } from \"../udc/keys.js\";\n\n/** The row count a renderer that loads its own rows reports to the toolbar. */\nexport interface RendererCount {\n shown: number;\n total: number | null;\n /**\n * `nodes`: the toolbar reads \"N nodes\" (the tree), `map`: \"N on map of M\"\n * (rows without a position are not drawn), `chart`: \"N points in window of\n * M\" (M counts the filter without the window), instead of \"Showing N of M\".\n */\n unit?: \"nodes\" | \"map\" | \"chart\";\n /** A source serving a fetched copy (http_api): when it was fetched, and whether it is stale. */\n fetchedAt?: string | null;\n stale?: boolean;\n}\n\n/** A folder-shaped collection (`folder_options`): what a folder row or a file row does on click. */\nexport interface FolderNav {\n options: FolderOptions;\n /** Open a folder by its path (`\"\"`: the root). */\n open: (path: string) => void;\n /** Preview a file row; absent when the view has no preview. */\n openFile?: ((row: Row) => void) | undefined;\n}\n\n/** Is `row` a folder of `nav`'s listing (the `..` row included)? */\nexport function isFolderRow(row: Row, nav: FolderNav): boolean {\n return row[nav.options.kind_field] === nav.options.dir_value;\n}\n\n/** What `<UdcDataView>` hands every renderer; each takes the parts it uses. */\nexport interface RendererProps {\n collection: string;\n /** `describe` with soft-deleted fields already gone. */\n describe: DescribeResponse;\n /** The data view's paged list; loaded only for a renderer with `paging`. */\n data: UdcCollectionResult;\n /** Search, chips and filter tree, composed. */\n filter: FilterNode | undefined;\n /** Chips and filter tree without the search: for a renderer that searches what it loaded. */\n baseFilter: FilterNode | undefined;\n /**\n * The chart window, when the view has one and it applies (on the chart tab,\n * or on any tab once the URL picked it): already ANDed into `filter` and\n * `baseFilter`.\n */\n chartWindow?: ChartWindowState | undefined;\n /** `filter` without the chart window: what \"of M\" counts. */\n unwindowedFilter?: FilterNode | undefined;\n /** The search box, as typed. */\n search: string;\n sort: SortKey[];\n onSort: (field: string, multi: boolean) => void;\n mode: PagingMode;\n page: number;\n limit: number;\n onPage: (page: number) => void;\n filtered: boolean;\n onClearFilters: () => void;\n resetKey: string;\n /** Set when the schema may be edited and the renderer has `editMode`. */\n onSchemaAction?: ((a: SchemaAction) => void) | undefined;\n /** For a renderer without `paging`: the count the toolbar shows. */\n onCount: (count: RendererCount | null) => void;\n /** Set when the view has `folder_options`. */\n folder?: FolderNav | undefined;\n /**\n * Row activation (0.4.0; `useRowActivation` of `@jsudc/react/headless` does\n * all of it): Enter or a plain click on a row. Absent unless the host asked.\n */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row to draw as active; `null` for none. Set (kept by the view when the\n * host does not control it) whenever activation is on, else absent.\n */\n activeRowId?: string | null | undefined;\n /** Report the active row moving (keys, a click on another row); set whenever activation is on. */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\nexport interface RendererEntry {\n component: ComponentType<RendererProps>;\n icon: LucideIcon;\n /** `APP.<labelKey>` is the tab label. */\n labelKey: string;\n /** Reads the data view's paged list: the paging toggle shows, the list loads. */\n paging: boolean;\n /** Offers the schema editor (column menus, add column). */\n editMode: boolean;\n /** Extra controls in the toolbar while this tab is open. */\n toolbar?: ComponentType<{ collection: string; describe: DescribeResponse }>;\n}\n\n/** One renderer as its subpath exports it (`tableRenderer` from `@jsudc/react/table`). */\nexport interface RendererDefinition extends RendererEntry {\n /** The name a view lists in `available_renderers`. */\n name: string;\n}\n\n/** Renderer name → entry: what `UdcDataView` draws its tabs with. `createRendererRegistry` builds one. */\nexport type RendererRegistry = Readonly<Record<string, RendererEntry>>;\n"],"mappings":";;AAiCA,SAAgB,YAAY,KAAU,KAAyB;CAC7D,OAAO,IAAI,IAAI,QAAQ,gBAAgB,IAAI,QAAQ;AACrD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Row } from "@jsudc/core";
|
|
2
|
+
import { type FocusEvent, type KeyboardEvent, type MouseEvent } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The activation props of `UdcDataView` and of `RendererProps`. All optional;
|
|
5
|
+
* with none of them a list behaves as before 0.4.0 (no tab stop on the rows,
|
|
6
|
+
* no keys, no active row).
|
|
7
|
+
*/
|
|
8
|
+
export interface RowActivationProps {
|
|
9
|
+
/** A row was activated: Enter on it, or a plain click (no modifier, the main button). */
|
|
10
|
+
onRowActivate?: ((row: Row) => void) | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The row drawn as active (`aria-selected="true"`, `data-active`, the
|
|
13
|
+
* `--selected` background). Passed: controlled, the host moves it in
|
|
14
|
+
* `onActiveRowChange`; `null` is "none". Left out: the list keeps it itself.
|
|
15
|
+
*/
|
|
16
|
+
activeRowId?: string | null | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The active row changed by the user: moved by the keys (without Enter) or a
|
|
19
|
+
* click on another row (before `onRowActivate`). Preview on move here.
|
|
20
|
+
*/
|
|
21
|
+
onActiveRowChange?: ((row: Row | null) => void) | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Is activation on: any of the three props passed? */
|
|
24
|
+
export declare function rowActivationEnabled(p: RowActivationProps): boolean;
|
|
25
|
+
export interface UseRowActivationOptions extends RowActivationProps {
|
|
26
|
+
/** The loaded rows, in the order they are drawn. */
|
|
27
|
+
rows: readonly Row[];
|
|
28
|
+
/** Infinite mode: moving past the last loaded row asks for the next page. */
|
|
29
|
+
hasNextPage?: boolean | undefined;
|
|
30
|
+
isFetchingNextPage?: boolean | undefined;
|
|
31
|
+
fetchNextPage?: (() => unknown) | undefined;
|
|
32
|
+
/** Override the default, `rowActivationEnabled(options)`. */
|
|
33
|
+
enabled?: boolean | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */
|
|
36
|
+
export interface RowActivationRowProps {
|
|
37
|
+
ref: (el: HTMLElement | null) => void;
|
|
38
|
+
/** One tab stop for the list: the active row, else the last focused one, else the first. */
|
|
39
|
+
tabIndex: 0 | -1;
|
|
40
|
+
"aria-selected": boolean;
|
|
41
|
+
/** `"true"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */
|
|
42
|
+
"data-active": "true" | undefined;
|
|
43
|
+
onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;
|
|
44
|
+
onFocus: (e: FocusEvent<HTMLElement>) => void;
|
|
45
|
+
onBlur: (e: FocusEvent<HTMLElement>) => void;
|
|
46
|
+
}
|
|
47
|
+
export interface RowActivation {
|
|
48
|
+
/** Off: `rowProps` is `{}` and the handlers do nothing. */
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
/** The active row's id when it is among `rows`, else `null`. */
|
|
51
|
+
activeRowId: string | null;
|
|
52
|
+
/** The row holding the list's tab stop. */
|
|
53
|
+
tabStopId: string | null;
|
|
54
|
+
/** The props of one row's element (`{}` when off). */
|
|
55
|
+
rowProps: (row: Row) => RowActivationRowProps | Record<string, never>;
|
|
56
|
+
/**
|
|
57
|
+
* A click on the row: a plain click activates it (and focuses it, unless the
|
|
58
|
+
* click went to a focusable cell). A modified or non-main-button click, or one
|
|
59
|
+
* on a link, button, input or menu, is left alone. `true` when it activated.
|
|
60
|
+
*/
|
|
61
|
+
handleClick: (e: MouseEvent<HTMLElement>, row: Row) => boolean;
|
|
62
|
+
/** Activate `row` as Enter does: make it active, then `onRowActivate`. */
|
|
63
|
+
activate: (row: Row) => void;
|
|
64
|
+
/** Move the active row, as the keys do, and focus it. */
|
|
65
|
+
move: (to: "next" | "previous" | "first" | "last") => void;
|
|
66
|
+
}
|
|
67
|
+
/** Does a key pressed on `target` belong to it rather than to the list? */
|
|
68
|
+
export declare function ownsKeys(target: EventTarget | null): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* The active row of a list and the keys that move it. Spread `rowProps(row)`
|
|
71
|
+
* on each row's element, call `handleClick` from its `onClick`, and give the
|
|
72
|
+
* list `role="grid"` (rows `role="row"`) while `enabled`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useRowActivation(options: UseRowActivationOptions): RowActivation;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
// src/rows/useRowActivation.ts
|
|
3
|
+
/** Is activation on: any of the three props passed? */
|
|
4
|
+
function rowActivationEnabled(p) {
|
|
5
|
+
return p.onRowActivate !== void 0 || p.activeRowId !== void 0 || p.onActiveRowChange !== void 0;
|
|
6
|
+
}
|
|
7
|
+
/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */
|
|
8
|
+
var OWNS_KEYS = "input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]";
|
|
9
|
+
/** Where a click is the control's, not the row's. */
|
|
10
|
+
var OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;
|
|
11
|
+
function closestOf(target, selector) {
|
|
12
|
+
const el = target;
|
|
13
|
+
return el && typeof el.closest === "function" ? el.closest(selector) : null;
|
|
14
|
+
}
|
|
15
|
+
/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */
|
|
16
|
+
function within(container, target) {
|
|
17
|
+
const node = target;
|
|
18
|
+
return !!node && typeof node.nodeType === "number" && container.contains(node);
|
|
19
|
+
}
|
|
20
|
+
/** Does a key pressed on `target` belong to it rather than to the list? */
|
|
21
|
+
function ownsKeys(target) {
|
|
22
|
+
if (target?.isContentEditable === true) return true;
|
|
23
|
+
return closestOf(target, OWNS_KEYS) !== null;
|
|
24
|
+
}
|
|
25
|
+
var idOf = (r) => r.__meta.id;
|
|
26
|
+
/**
|
|
27
|
+
* The active row of a list and the keys that move it. Spread `rowProps(row)`
|
|
28
|
+
* on each row's element, call `handleClick` from its `onClick`, and give the
|
|
29
|
+
* list `role="grid"` (rows `role="row"`) while `enabled`.
|
|
30
|
+
*/
|
|
31
|
+
function useRowActivation(options) {
|
|
32
|
+
const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;
|
|
33
|
+
const enabled = options.enabled ?? rowActivationEnabled(options);
|
|
34
|
+
const controlled = controlledId !== void 0;
|
|
35
|
+
const [ownId, setOwnId] = useState(null);
|
|
36
|
+
const [focusId, setFocusId] = useState(null);
|
|
37
|
+
const rawId = controlled ? controlledId : ownId;
|
|
38
|
+
const has = (id) => id !== null && rows.some((r) => idOf(r) === id);
|
|
39
|
+
const activeRowId = enabled && has(rawId) ? rawId : null;
|
|
40
|
+
const tabStopId = !enabled ? null : activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null);
|
|
41
|
+
const latest = useRef({
|
|
42
|
+
rows,
|
|
43
|
+
activeRowId,
|
|
44
|
+
onRowActivate,
|
|
45
|
+
onActiveRowChange,
|
|
46
|
+
controlled
|
|
47
|
+
});
|
|
48
|
+
latest.current = {
|
|
49
|
+
rows,
|
|
50
|
+
activeRowId,
|
|
51
|
+
onRowActivate,
|
|
52
|
+
onActiveRowChange,
|
|
53
|
+
controlled
|
|
54
|
+
};
|
|
55
|
+
const paging = useRef(options);
|
|
56
|
+
paging.current = options;
|
|
57
|
+
const elements = useRef(/* @__PURE__ */ new Map());
|
|
58
|
+
const refs = useRef(/* @__PURE__ */ new Map());
|
|
59
|
+
const refFor = (id) => {
|
|
60
|
+
let cb = refs.current.get(id);
|
|
61
|
+
if (!cb) {
|
|
62
|
+
cb = (el) => {
|
|
63
|
+
if (el) elements.current.set(id, el);
|
|
64
|
+
else elements.current.delete(id);
|
|
65
|
+
};
|
|
66
|
+
refs.current.set(id, cb);
|
|
67
|
+
}
|
|
68
|
+
return cb;
|
|
69
|
+
};
|
|
70
|
+
/** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */
|
|
71
|
+
const focusedRef = useRef(null);
|
|
72
|
+
/** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */
|
|
73
|
+
const pendingRef = useRef(null);
|
|
74
|
+
const focusRow = useCallback((id) => {
|
|
75
|
+
const el = elements.current.get(id);
|
|
76
|
+
if (!el) return;
|
|
77
|
+
el.focus({ preventScroll: true });
|
|
78
|
+
if (typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
79
|
+
}, []);
|
|
80
|
+
const changeActive = useCallback((row) => {
|
|
81
|
+
const now = latest.current;
|
|
82
|
+
if (now.activeRowId === idOf(row)) return;
|
|
83
|
+
if (!now.controlled) setOwnId(idOf(row));
|
|
84
|
+
now.onActiveRowChange?.(row);
|
|
85
|
+
}, []);
|
|
86
|
+
const go = useCallback((row) => {
|
|
87
|
+
setFocusId(idOf(row));
|
|
88
|
+
focusedRef.current = idOf(row);
|
|
89
|
+
changeActive(row);
|
|
90
|
+
focusRow(idOf(row));
|
|
91
|
+
}, [changeActive, focusRow]);
|
|
92
|
+
const activate = useCallback((row) => {
|
|
93
|
+
changeActive(row);
|
|
94
|
+
latest.current.onRowActivate?.(row);
|
|
95
|
+
}, [changeActive]);
|
|
96
|
+
const step = useCallback((from, to) => {
|
|
97
|
+
const list = latest.current.rows;
|
|
98
|
+
if (list.length === 0) return;
|
|
99
|
+
if (to === "first") return go(list[0]);
|
|
100
|
+
const last = list.length - 1;
|
|
101
|
+
if (to === "last") return go(list[last]);
|
|
102
|
+
const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);
|
|
103
|
+
if (i < 0) return go(list[0]);
|
|
104
|
+
const next = to === "next" ? i + 1 : i - 1;
|
|
105
|
+
if (next < 0) return;
|
|
106
|
+
if (next > last) {
|
|
107
|
+
const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;
|
|
108
|
+
if (hasNextPage && fetchNextPage) {
|
|
109
|
+
pendingRef.current = idOf(list[last]);
|
|
110
|
+
if (!isFetchingNextPage) fetchNextPage();
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
go(list[next]);
|
|
115
|
+
}, [go]);
|
|
116
|
+
const move = useCallback((to) => {
|
|
117
|
+
const now = latest.current;
|
|
118
|
+
step(now.activeRowId ?? focusedRef.current, to);
|
|
119
|
+
}, [step]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const pending = pendingRef.current;
|
|
122
|
+
if (!enabled || pending === null) return;
|
|
123
|
+
const i = rows.findIndex((r) => idOf(r) === pending);
|
|
124
|
+
const next = i >= 0 ? rows[i + 1] : void 0;
|
|
125
|
+
if (next) {
|
|
126
|
+
pendingRef.current = null;
|
|
127
|
+
go(next);
|
|
128
|
+
} else if (i < 0 || !options.isFetchingNextPage && !options.hasNextPage) pendingRef.current = null;
|
|
129
|
+
}, [
|
|
130
|
+
enabled,
|
|
131
|
+
rows,
|
|
132
|
+
go,
|
|
133
|
+
options.isFetchingNextPage,
|
|
134
|
+
options.hasNextPage
|
|
135
|
+
]);
|
|
136
|
+
useLayoutEffect(() => {
|
|
137
|
+
const id = focusedRef.current;
|
|
138
|
+
if (!enabled || id === null) return;
|
|
139
|
+
const el = elements.current.get(id);
|
|
140
|
+
if (!el) return;
|
|
141
|
+
const active = typeof document === "undefined" ? null : document.activeElement;
|
|
142
|
+
if (active === el) return;
|
|
143
|
+
if (active === null || active === document.body) el.focus({ preventScroll: true });
|
|
144
|
+
}, [enabled, rows]);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (activeRowId === null) return;
|
|
147
|
+
const el = elements.current.get(activeRowId);
|
|
148
|
+
if (el && typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
149
|
+
}, [activeRowId]);
|
|
150
|
+
const onKeyDown = (e, row) => {
|
|
151
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
152
|
+
if (!within(e.currentTarget, e.target)) return;
|
|
153
|
+
if (ownsKeys(e.target)) return;
|
|
154
|
+
const id = idOf(row);
|
|
155
|
+
switch (e.key) {
|
|
156
|
+
case "ArrowDown":
|
|
157
|
+
case "j":
|
|
158
|
+
step(id, "next");
|
|
159
|
+
break;
|
|
160
|
+
case "ArrowUp":
|
|
161
|
+
case "k":
|
|
162
|
+
step(id, "previous");
|
|
163
|
+
break;
|
|
164
|
+
case "Home":
|
|
165
|
+
step(id, "first");
|
|
166
|
+
break;
|
|
167
|
+
case "End":
|
|
168
|
+
step(id, "last");
|
|
169
|
+
break;
|
|
170
|
+
case "Enter":
|
|
171
|
+
if (closestOf(e.target, "a,button") !== null && e.target !== e.currentTarget) return;
|
|
172
|
+
activate(row);
|
|
173
|
+
break;
|
|
174
|
+
default: return;
|
|
175
|
+
}
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
};
|
|
178
|
+
const handleClick = (e, row) => {
|
|
179
|
+
if (!enabled || e.defaultPrevented) return false;
|
|
180
|
+
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;
|
|
181
|
+
if (!within(e.currentTarget, e.target)) return false;
|
|
182
|
+
if (closestOf(e.target, OWNS_CLICK)) return false;
|
|
183
|
+
const id = idOf(row);
|
|
184
|
+
setFocusId(id);
|
|
185
|
+
const focusable = closestOf(e.target, "[tabindex]");
|
|
186
|
+
if (!focusable || focusable === e.currentTarget) {
|
|
187
|
+
focusedRef.current = id;
|
|
188
|
+
elements.current.get(id)?.focus({ preventScroll: true });
|
|
189
|
+
}
|
|
190
|
+
activate(row);
|
|
191
|
+
return true;
|
|
192
|
+
};
|
|
193
|
+
const rowProps = (row) => {
|
|
194
|
+
if (!enabled) return {};
|
|
195
|
+
const id = idOf(row);
|
|
196
|
+
return {
|
|
197
|
+
ref: refFor(id),
|
|
198
|
+
tabIndex: id === tabStopId ? 0 : -1,
|
|
199
|
+
"aria-selected": id === activeRowId,
|
|
200
|
+
"data-active": id === activeRowId ? "true" : void 0,
|
|
201
|
+
onKeyDown: (e) => onKeyDown(e, row),
|
|
202
|
+
onFocus: (e) => {
|
|
203
|
+
if (e.target !== e.currentTarget) return;
|
|
204
|
+
focusedRef.current = id;
|
|
205
|
+
setFocusId(id);
|
|
206
|
+
},
|
|
207
|
+
onBlur: (e) => {
|
|
208
|
+
const list = e.currentTarget.parentElement;
|
|
209
|
+
if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
return {
|
|
214
|
+
enabled,
|
|
215
|
+
activeRowId,
|
|
216
|
+
tabStopId,
|
|
217
|
+
rowProps,
|
|
218
|
+
handleClick,
|
|
219
|
+
activate,
|
|
220
|
+
move
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export { ownsKeys, rowActivationEnabled, useRowActivation };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=useRowActivation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowActivation.js","names":[],"sources":["../../src/rows/useRowActivation.ts"],"sourcesContent":["// Row activation and keyboard movement over a list of rows: the active row, a roving tab\n// stop, ArrowUp / ArrowDown / j / k / Home / End / Enter, and a click that activates. The\n// table and the cards use it; a host renderer gets the same behaviour from\n// `@jsudc/react/headless`. No JSX.\nimport type { Row } from \"@jsudc/core\";\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\n/**\n * The activation props of `UdcDataView` and of `RendererProps`. All optional;\n * with none of them a list behaves as before 0.4.0 (no tab stop on the rows,\n * no keys, no active row).\n */\nexport interface RowActivationProps {\n /** A row was activated: Enter on it, or a plain click (no modifier, the main button). */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row drawn as active (`aria-selected=\"true\"`, `data-active`, the\n * `--selected` background). Passed: controlled, the host moves it in\n * `onActiveRowChange`; `null` is \"none\". Left out: the list keeps it itself.\n */\n activeRowId?: string | null | undefined;\n /**\n * The active row changed by the user: moved by the keys (without Enter) or a\n * click on another row (before `onRowActivate`). Preview on move here.\n */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\n/** Is activation on: any of the three props passed? */\nexport function rowActivationEnabled(p: RowActivationProps): boolean {\n return (\n p.onRowActivate !== undefined ||\n p.activeRowId !== undefined ||\n p.onActiveRowChange !== undefined\n );\n}\n\nexport interface UseRowActivationOptions extends RowActivationProps {\n /** The loaded rows, in the order they are drawn. */\n rows: readonly Row[];\n /** Infinite mode: moving past the last loaded row asks for the next page. */\n hasNextPage?: boolean | undefined;\n isFetchingNextPage?: boolean | undefined;\n fetchNextPage?: (() => unknown) | undefined;\n /** Override the default, `rowActivationEnabled(options)`. */\n enabled?: boolean | undefined;\n}\n\n/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */\nexport interface RowActivationRowProps {\n ref: (el: HTMLElement | null) => void;\n /** One tab stop for the list: the active row, else the last focused one, else the first. */\n tabIndex: 0 | -1;\n \"aria-selected\": boolean;\n /** `\"true\"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */\n \"data-active\": \"true\" | undefined;\n onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus: (e: FocusEvent<HTMLElement>) => void;\n onBlur: (e: FocusEvent<HTMLElement>) => void;\n}\n\nexport interface RowActivation {\n /** Off: `rowProps` is `{}` and the handlers do nothing. */\n enabled: boolean;\n /** The active row's id when it is among `rows`, else `null`. */\n activeRowId: string | null;\n /** The row holding the list's tab stop. */\n tabStopId: string | null;\n /** The props of one row's element (`{}` when off). */\n rowProps: (row: Row) => RowActivationRowProps | Record<string, never>;\n /**\n * A click on the row: a plain click activates it (and focuses it, unless the\n * click went to a focusable cell). A modified or non-main-button click, or one\n * on a link, button, input or menu, is left alone. `true` when it activated.\n */\n handleClick: (e: MouseEvent<HTMLElement>, row: Row) => boolean;\n /** Activate `row` as Enter does: make it active, then `onRowActivate`. */\n activate: (row: Row) => void;\n /** Move the active row, as the keys do, and focus it. */\n move: (to: \"next\" | \"previous\" | \"first\" | \"last\") => void;\n}\n\n/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */\nconst OWNS_KEYS =\n 'input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]';\n/** Where a click is the control's, not the row's. */\nconst OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;\n\n// Duck-typed, so an element of another realm (an iframe) counts too.\nfunction closestOf(target: EventTarget | null, selector: string): Element | null {\n const el = target as Element | null;\n return el && typeof el.closest === \"function\" ? el.closest(selector) : null;\n}\n\n/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */\nfunction within(container: HTMLElement, target: EventTarget | null): boolean {\n const node = target as Node | null;\n return !!node && typeof node.nodeType === \"number\" && container.contains(node);\n}\n\n/** Does a key pressed on `target` belong to it rather than to the list? */\nexport function ownsKeys(target: EventTarget | null): boolean {\n if ((target as HTMLElement | null)?.isContentEditable === true) return true;\n return closestOf(target, OWNS_KEYS) !== null;\n}\n\nconst idOf = (r: Row) => r.__meta.id;\n\n/**\n * The active row of a list and the keys that move it. Spread `rowProps(row)`\n * on each row's element, call `handleClick` from its `onClick`, and give the\n * list `role=\"grid\"` (rows `role=\"row\"`) while `enabled`.\n */\nexport function useRowActivation(options: UseRowActivationOptions): RowActivation {\n const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;\n const enabled = options.enabled ?? rowActivationEnabled(options);\n const controlled = controlledId !== undefined;\n const [ownId, setOwnId] = useState<string | null>(null);\n const [focusId, setFocusId] = useState<string | null>(null);\n const rawId = controlled ? controlledId : ownId;\n const has = (id: string | null): id is string => id !== null && rows.some((r) => idOf(r) === id);\n const activeRowId = enabled && has(rawId) ? rawId : null;\n const tabStopId = !enabled\n ? null\n : (activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null));\n\n // The latest values, for handlers that outlive a render.\n const latest = useRef({ rows, activeRowId, onRowActivate, onActiveRowChange, controlled });\n latest.current = { rows, activeRowId, onRowActivate, onActiveRowChange, controlled };\n const paging = useRef(options);\n paging.current = options;\n\n // One stable ref callback per row id, so React does not detach and reattach each render.\n const elements = useRef(new Map<string, HTMLElement>());\n const refs = useRef(new Map<string, (el: HTMLElement | null) => void>());\n const refFor = (id: string) => {\n let cb = refs.current.get(id);\n if (!cb) {\n cb = (el) => {\n if (el) elements.current.set(id, el);\n else elements.current.delete(id);\n };\n refs.current.set(id, cb);\n }\n return cb;\n };\n\n /** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */\n const focusedRef = useRef<string | null>(null);\n /** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */\n const pendingRef = useRef<string | null>(null);\n\n const focusRow = useCallback((id: string) => {\n const el = elements.current.get(id);\n if (!el) return;\n el.focus({ preventScroll: true });\n if (typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, []);\n\n const changeActive = useCallback((row: Row) => {\n const now = latest.current;\n if (now.activeRowId === idOf(row)) return;\n if (!now.controlled) setOwnId(idOf(row));\n now.onActiveRowChange?.(row);\n }, []);\n\n const go = useCallback(\n (row: Row) => {\n setFocusId(idOf(row));\n focusedRef.current = idOf(row);\n changeActive(row);\n focusRow(idOf(row));\n },\n [changeActive, focusRow],\n );\n\n const activate = useCallback(\n (row: Row) => {\n changeActive(row);\n latest.current.onRowActivate?.(row);\n },\n [changeActive],\n );\n\n const step = useCallback(\n (from: string | null, to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const list = latest.current.rows;\n if (list.length === 0) return;\n if (to === \"first\") return go(list[0] as Row);\n const last = list.length - 1;\n if (to === \"last\") return go(list[last] as Row);\n const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);\n if (i < 0) return go(list[0] as Row);\n const next = to === \"next\" ? i + 1 : i - 1;\n if (next < 0) return;\n if (next > last) {\n const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;\n if (hasNextPage && fetchNextPage) {\n pendingRef.current = idOf(list[last] as Row);\n if (!isFetchingNextPage) fetchNextPage();\n }\n return;\n }\n go(list[next] as Row);\n },\n [go],\n );\n\n const move = useCallback(\n (to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const now = latest.current;\n step(now.activeRowId ?? focusedRef.current, to);\n },\n [step],\n );\n\n // A page arrived after ArrowDown on the last row: continue onto its first row.\n useEffect(() => {\n const pending = pendingRef.current;\n if (!enabled || pending === null) return;\n const i = rows.findIndex((r) => idOf(r) === pending);\n const next = i >= 0 ? rows[i + 1] : undefined;\n if (next) {\n pendingRef.current = null;\n go(next);\n } else if (i < 0 || (!options.isFetchingNextPage && !options.hasNextPage)) {\n pendingRef.current = null;\n }\n }, [enabled, rows, go, options.isFetchingNextPage, options.hasNextPage]);\n\n // Rows unmounted under the focus (a refetch drawing skeletons, a sort): give it back by id.\n // biome-ignore lint/correctness/useExhaustiveDependencies: `rows` is the trigger, not an input\n useLayoutEffect(() => {\n const id = focusedRef.current;\n if (!enabled || id === null) return;\n const el = elements.current.get(id);\n if (!el) return;\n const active = typeof document === \"undefined\" ? null : document.activeElement;\n if (active === el) return;\n if (active === null || active === document.body) el.focus({ preventScroll: true });\n }, [enabled, rows]);\n\n // The active row set from outside (the host opened a message) is scrolled into view.\n useEffect(() => {\n if (activeRowId === null) return;\n const el = elements.current.get(activeRowId);\n if (el && typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, [activeRowId]);\n\n const onKeyDown = (e: KeyboardEvent<HTMLElement>, row: Row) => {\n if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;\n // A key from a portalled menu or dialog bubbles through React to here: not the list's.\n if (!within(e.currentTarget, e.target)) return;\n if (ownsKeys(e.target)) return;\n const id = idOf(row);\n switch (e.key) {\n case \"ArrowDown\":\n case \"j\":\n step(id, \"next\");\n break;\n case \"ArrowUp\":\n case \"k\":\n step(id, \"previous\");\n break;\n case \"Home\":\n step(id, \"first\");\n break;\n case \"End\":\n step(id, \"last\");\n break;\n case \"Enter\":\n // Enter on a link or a button in the row is that control's.\n if (closestOf(e.target, \"a,button\") !== null && e.target !== e.currentTarget) return;\n activate(row);\n break;\n default:\n return;\n }\n e.preventDefault();\n };\n\n const handleClick = (e: MouseEvent<HTMLElement>, row: Row): boolean => {\n if (!enabled || e.defaultPrevented) return false;\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;\n if (!within(e.currentTarget, e.target)) return false;\n if (closestOf(e.target, OWNS_CLICK)) return false;\n const id = idOf(row);\n setFocusId(id);\n // A click in a focusable cell (an editable one) keeps the focus there.\n const focusable = closestOf(e.target, \"[tabindex]\");\n if (!focusable || focusable === e.currentTarget) {\n focusedRef.current = id;\n elements.current.get(id)?.focus({ preventScroll: true });\n }\n activate(row);\n return true;\n };\n\n const rowProps = (row: Row): RowActivationRowProps | Record<string, never> => {\n if (!enabled) return {};\n const id = idOf(row);\n return {\n ref: refFor(id),\n tabIndex: id === tabStopId ? 0 : -1,\n \"aria-selected\": id === activeRowId,\n \"data-active\": id === activeRowId ? \"true\" : undefined,\n onKeyDown: (e) => onKeyDown(e, row),\n onFocus: (e) => {\n if (e.target !== e.currentTarget) return;\n focusedRef.current = id;\n setFocusId(id);\n },\n onBlur: (e) => {\n // Focus left the list (not to another row or a cell of it): forget it.\n const list = e.currentTarget.parentElement;\n if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;\n },\n };\n };\n\n return { enabled, activeRowId, tabStopId, rowProps, handleClick, activate, move };\n}\n"],"mappings":";;;AAsCA,SAAgB,qBAAqB,GAAgC;CACnE,OACE,EAAE,kBAAkB,KAAA,KACpB,EAAE,gBAAgB,KAAA,KAClB,EAAE,sBAAsB,KAAA;AAE5B;;AAgDA,IAAM,YACJ;;AAEF,IAAM,aAAa,kBAAkB;AAGrC,SAAS,UAAU,QAA4B,UAAkC;CAC/E,MAAM,KAAK;CACX,OAAO,MAAM,OAAO,GAAG,YAAY,aAAa,GAAG,QAAQ,QAAQ,IAAI;AACzE;;AAGA,SAAS,OAAO,WAAwB,QAAqC;CAC3E,MAAM,OAAO;CACb,OAAO,CAAC,CAAC,QAAQ,OAAO,KAAK,aAAa,YAAY,UAAU,SAAS,IAAI;AAC/E;;AAGA,SAAgB,SAAS,QAAqC;CAC5D,IAAK,QAA+B,sBAAsB,MAAM,OAAO;CACvE,OAAO,UAAU,QAAQ,SAAS,MAAM;AAC1C;AAEA,IAAM,QAAQ,MAAW,EAAE,OAAO;;;;;;AAOlC,SAAgB,iBAAiB,SAAiD;CAChF,MAAM,EAAE,MAAM,aAAa,cAAc,eAAe,sBAAsB;CAC9E,MAAM,UAAU,QAAQ,WAAW,qBAAqB,OAAO;CAC/D,MAAM,aAAa,iBAAiB,KAAA;CACpC,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CACtD,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAC1D,MAAM,QAAQ,aAAa,eAAe;CAC1C,MAAM,OAAO,OAAoC,OAAO,QAAQ,KAAK,MAAM,MAAM,KAAK,CAAC,MAAM,EAAE;CAC/F,MAAM,cAAc,WAAW,IAAI,KAAK,IAAI,QAAQ;CACpD,MAAM,YAAY,CAAC,UACf,OACC,gBAAgB,IAAI,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EACrE,IAAI,CAAC,WAAW,EAAE,kBAAkB,OAAO;EAC3C,IAAI,EAAE,WAAW,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,OAAO;EAC/E,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;EAC/C,IAAI,UAAU,EAAE,QAAQ,UAAU,GAAG,OAAO;EAC5C,MAAM,KAAK,KAAK,GAAG;EACnB,WAAW,EAAE;EAEb,MAAM,YAAY,UAAU,EAAE,QAAQ,YAAY;EAClD,IAAI,CAAC,aAAa,cAAc,EAAE,eAAe;GAC/C,WAAW,UAAU;GACrB,SAAS,QAAQ,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,KAAK,CAAC;EACzD;EACA,SAAS,GAAG;EACZ,OAAO;CACT;CAEA,MAAM,YAAY,QAA4D;EAC5E,IAAI,CAAC,SAAS,OAAO,CAAC;EACtB,MAAM,KAAK,KAAK,GAAG;EACnB,OAAO;GACL,KAAK,OAAO,EAAE;GACd,UAAU,OAAO,YAAY,IAAI;GACjC,iBAAiB,OAAO;GACxB,eAAe,OAAO,cAAc,SAAS,KAAA;GAC7C,YAAY,MAAM,UAAU,GAAG,GAAG;GAClC,UAAU,MAAM;IACd,IAAI,EAAE,WAAW,EAAE,eAAe;IAClC,WAAW,UAAU;IACrB,WAAW,EAAE;GACf;GACA,SAAS,MAAM;IAEb,MAAM,OAAO,EAAE,cAAc;IAC7B,IAAI,CAAC,QAAQ,CAAC,OAAO,MAAM,EAAE,aAAa,GAAG,WAAW,UAAU;GACpE;EACF;CACF;CAEA,OAAO;EAAE;EAAS;EAAa;EAAW;EAAU;EAAa;EAAU;CAAK;AAClF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useI18n } from "../i18n/i18n.js";
|
|
2
2
|
import { useUdcSchema } from "../udc/hooks.js";
|
|
3
3
|
import { useUiKit } from "../ui-kit/context.js";
|
|
4
|
-
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
5
4
|
import { useState } from "react";
|
|
5
|
+
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
6
6
|
import { isUdcError } from "@jsudc/core";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// src/schema-editor/DeleteFieldDialog.tsx
|
|
@@ -4,8 +4,8 @@ import { useUdcSchema } from "../udc/hooks.js";
|
|
|
4
4
|
import { useUiKit } from "../ui-kit/context.js";
|
|
5
5
|
import { FORM_TYPES, draftFromDef, draftToFieldDef, emptyDraft, nameProblem, suggestName, typeControls, validateDraft } from "./fieldForm.js";
|
|
6
6
|
import { TagInput } from "./TagInput.js";
|
|
7
|
-
import { AlertTriangle, Lock } from "lucide-react";
|
|
8
7
|
import { useId, useState } from "react";
|
|
8
|
+
import { AlertTriangle, Lock } from "lucide-react";
|
|
9
9
|
import { isUdcError } from "@jsudc/core";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
// src/schema-editor/FieldFormDialog.tsx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
|
-
import { X } from "lucide-react";
|
|
3
2
|
import { useState } from "react";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/schema-editor/TagInput.tsx
|
|
6
6
|
/** A list of short strings: Enter or comma adds the typed one, Backspace on empty drops the last. */
|