@rebasepro/cms 0.33.2 → 0.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +1 -1
  2. package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js +1 -1
  3. package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +1 -1
  4. package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js +1 -1
  5. package/dist/components/BrandLogo.d.ts +16 -0
  6. package/dist/components/BrandLogo.js +34 -0
  7. package/dist/components/BrandLogo.js.map +1 -0
  8. package/dist/components/CollectionViewBinding/BoardCardBinding.js +3 -3
  9. package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
  10. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +2 -2
  11. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
  12. package/dist/components/CollectionViewBinding/CollectionViewActions.js +1 -6
  13. package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
  14. package/dist/components/CollectionViewBinding/EntityCardBinding.js +3 -3
  15. package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
  16. package/dist/components/CollectionViewBinding/SlotValue.js +2 -2
  17. package/dist/components/CollectionViewBinding/SlotValue.js.map +1 -1
  18. package/dist/components/DefaultAppBar.d.ts +3 -1
  19. package/dist/components/DefaultAppBar.js +11 -6
  20. package/dist/components/DefaultAppBar.js.map +1 -1
  21. package/dist/components/DefaultDrawer.d.ts +5 -2
  22. package/dist/components/DefaultDrawer.js +9 -6
  23. package/dist/components/DefaultDrawer.js.map +1 -1
  24. package/dist/components/EntityIdentityBar.js +1 -1
  25. package/dist/components/EntityIdentityBar.js.map +1 -1
  26. package/dist/components/PropertyKeyHint.js +1 -1
  27. package/dist/components/PropertyKeyHint.js.map +1 -1
  28. package/dist/components/RebaseAuthGate.d.ts +5 -1
  29. package/dist/components/RebaseAuthGate.js +6 -2
  30. package/dist/components/RebaseAuthGate.js.map +1 -1
  31. package/dist/components/RebaseLayout.d.ts +2 -0
  32. package/dist/components/RebaseLayout.js +4 -2
  33. package/dist/components/RebaseLayout.js.map +1 -1
  34. package/dist/components/RebaseNavigation.js +7 -14
  35. package/dist/components/RebaseNavigation.js.map +1 -1
  36. package/dist/components/RebaseShell.d.ts +6 -1
  37. package/dist/components/RebaseShell.js +21 -16
  38. package/dist/components/RebaseShell.js.map +1 -1
  39. package/dist/components/RelationSelector.js +1 -1
  40. package/dist/components/RelationSelector.js.map +1 -1
  41. package/dist/components/app/Drawer.d.ts +2 -1
  42. package/dist/components/app/Drawer.js +2 -1
  43. package/dist/components/app/Drawer.js.map +1 -1
  44. package/dist/components/app/Scaffold.d.ts +5 -0
  45. package/dist/components/app/Scaffold.js +5 -3
  46. package/dist/components/app/Scaffold.js.map +1 -1
  47. package/dist/components/app/useApp.d.ts +1 -0
  48. package/dist/components/app/useApp.js.map +1 -1
  49. package/dist/editor/components/SlashCommandMenu.js +1 -1
  50. package/dist/editor/components/SlashCommandMenu.js.map +1 -1
  51. package/dist/editor/selectors/link-selector.js +1 -1
  52. package/dist/editor/selectors/link-selector.js.map +1 -1
  53. package/dist/editor/selectors/text-buttons.js +1 -1
  54. package/dist/editor/selectors/text-buttons.js.map +1 -1
  55. package/dist/form/field_bindings/VectorFieldBinding.js +1 -1
  56. package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
  57. package/dist/hooks/navigation/compose_collections.d.ts +3 -2
  58. package/dist/hooks/navigation/compose_collections.js +27 -3
  59. package/dist/hooks/navigation/compose_collections.js.map +1 -1
  60. package/dist/index.js +17 -17
  61. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"Scaffold.js","names":[],"sources":["../../../src/components/app/Scaffold.tsx"],"sourcesContent":["import React, { PropsWithChildren, useCallback, useMemo } from \"react\";\nimport { cls, defaultBorderMixin, IconButton, Sheet, Tooltip } from \"@rebasepro/ui\";\nimport { ChevronLeftIcon, ErrorBoundary, MenuIcon } from \"@rebasepro/ui\";\nimport { deepEqual as equal } from \"fast-equals\"\n\nimport { ConnectionLostBanner, RlsSimulationBanner, useLargeLayout, useTranslation } from \"@rebasepro/app\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { AppContext } from \"./useApp\";\n\nexport const DRAWER_WIDTH = 280;\n\n/**\n * Namespaced by base path: two admins served from one origin are two different\n * navigations, and a single key would have them overwrite each other's drawer.\n */\nexport function drawerOpenStorageKey(basePath: string | undefined) {\n return `rebase-drawer-open:${basePath || \"/\"}`;\n}\n\n/** `null` when the user has never toggled the drawer, or storage is unavailable. */\nfunction readStoredDrawerOpen(key: string): boolean | null {\n if (typeof window === \"undefined\") return null;\n try {\n const stored = window.localStorage.getItem(key);\n return stored === null ? null : stored === \"true\";\n } catch (e) {\n // Storage can be blocked: private mode, sandboxed iframe, cookie policy.\n return null;\n }\n}\n\nfunction writeStoredDrawerOpen(key: string, open: boolean) {\n if (typeof window === \"undefined\") return;\n try {\n window.localStorage.setItem(key, String(open));\n } catch (e) {\n // Same as above: a drawer that forgets is better than a crash.\n }\n}\n\n/**\n * @group Core\n */\nexport interface ScaffoldProps {\n\n /**\n * Expand the collapsed drawer while the pointer is over it. On by default —\n * pass `false` to keep the rail a rail until the user clicks the toggle.\n */\n autoOpenDrawer?: boolean;\n\n /**\n * Start with the drawer expanded rather than collapsed to icons.\n *\n * Distinct from {@link autoOpenDrawer}, which is a hover behaviour: this one\n * only seeds the very first visit. Once the user toggles the drawer, that\n * choice is stored in `localStorage` and wins over this prop on every load.\n *\n * Ignored on small layouts, where an expanded drawer covers the content it is\n * meant to navigate.\n */\n defaultDrawerOpen?: boolean;\n\n /**\n * Logo to be displayed in the top bar and drawer.\n * Note that this has no effect if you are using a custom AppBar or Drawer.\n */\n logo?: string;\n\n /**\n * If true, the main content will be padded in large layouts. Defaults to true.\n */\n padding?: boolean;\n\n className?: string;\n\n style?: React.CSSProperties;\n}\n\n/**\n * This view acts as a scaffold for Rebase.\n *\n * It is in charge of displaying the navigation drawer, top bar and main\n * collection views.\n * This component needs a parent {@link Rebase}\n *\n * @param props\n\n * @group Core\n */\nexport const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(\n function Scaffold(props: PropsWithChildren<ScaffoldProps>) {\n\n const {\n children,\n autoOpenDrawer = true,\n defaultDrawerOpen = false,\n logo,\n className,\n style,\n padding = true\n } = props;\n\n // `toArray` keeps strings and numbers, and those have no `.type` at all.\n // Reading `child.type.componentType` off one threw a TypeError from\n // inside the layout, which is a bewildering way to be told that a stray\n // text node — a conditional that rendered `\"\"`, a template string —\n // reached the Scaffold. Anything that is not an element is just \"other\".\n const slotOf = (child: React.ReactNode): string | undefined =>\n React.isValidElement(child)\n ? (child.type as { componentType?: string })?.componentType\n : undefined;\n\n const childArray = React.Children.toArray(children);\n const drawerChildren = childArray.filter((child) => slotOf(child) === \"Drawer\");\n if (drawerChildren.length > 1) {\n throw Error(\"Only one Drawer component is allowed in Scaffold\");\n }\n const appBarChildren = childArray.filter((child) => slotOf(child) === \"AppBar\");\n if (appBarChildren.length > 1) {\n throw Error(\"Only one AppBar component is allowed in Scaffold\");\n }\n const otherChildren = childArray\n .filter((child) => slotOf(child) !== \"Drawer\" && slotOf(child) !== \"AppBar\");\n const includeDrawer = drawerChildren.length > 0;\n const largeLayout = useLargeLayout();\n\n const storageKey = drawerOpenStorageKey(useUrlController().basePath);\n\n // Seeded once, deliberately: a `useEffect` syncing this to the prop would\n // re-expand the drawer under a user who had just collapsed it.\n const [drawerOpen, setDrawerOpenState] = React.useState(defaultDrawerOpen && largeLayout);\n const [onHover, setOnHover] = React.useState(false);\n\n // The stored choice is a client-only fact, so it is applied after the first\n // render rather than seeded into it: reading storage while rendering would\n // make the client disagree with server-rendered HTML. A layout effect runs\n // before paint, so the drawer still arrives in its remembered state.\n // `defaultDrawerOpen` seeds the very first visit and is ignored after that.\n React.useLayoutEffect(() => {\n const stored = readStoredDrawerOpen(storageKey);\n if (stored === null) return;\n setDrawerOpenState(stored && largeLayout);\n // Deliberately not re-run on `largeLayout`: crossing the breakpoint is\n // the effect below, and re-running here would undo a user's toggle.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storageKey]);\n\n // One piece of state drives two different things: the expanded rail on\n // large layouts, and the modal sheet on small ones. Carrying an expanded\n // rail across the breakpoint would drop that sheet, overlay and all, over\n // the content — so the crossing resets it, and widening again restores\n // whatever the user last chose.\n const wasLargeLayout = React.useRef(largeLayout);\n React.useEffect(() => {\n if (wasLargeLayout.current === largeLayout) return;\n wasLargeLayout.current = largeLayout;\n setDrawerOpenState(largeLayout ? (readStoredDrawerOpen(storageKey) ?? defaultDrawerOpen) : false);\n }, [largeLayout, defaultDrawerOpen, storageKey]);\n\n const setDrawerOpen = useCallback((open: boolean) => {\n setDrawerOpenState(open);\n // Small layouts render the drawer as a modal sheet. Remembering that\n // one would greet the next load with an overlay over the content.\n if (!largeLayout) return;\n writeStoredDrawerOpen(storageKey, open);\n }, [largeLayout, storageKey]);\n\n // The pointer has left, but a popover the drawer opened is still up, so the\n // collapse is owed rather than cancelled. See `setOnHoverFalse`.\n const collapseWhenPopoverCloses = React.useRef(false);\n\n const setOnHoverTrue = useCallback(() => {\n // Hover expansion is the default; `autoOpenDrawer={false}` opts out for\n // admins that want the rail to stay a rail until the toggle is clicked.\n if (!autoOpenDrawer) return;\n collapseWhenPopoverCloses.current = false;\n setOnHover(true);\n }, [autoOpenDrawer]);\n const setOnHoverFalse = useCallback(() => {\n // Don't collapse the drawer out from under an open popover/dropdown —\n // its content is portalled outside the drawer, so reaching for it reads\n // as a mouseleave. The collapse is owed until that popover closes.\n if (document.querySelector(\"[data-radix-popper-content-wrapper]\")) {\n collapseWhenPopoverCloses.current = true;\n return;\n }\n collapseWhenPopoverCloses.current = false;\n setOnHover(false);\n }, []);\n\n // Nothing fires a second mouseleave when the popover finally closes, so the\n // owed collapse has to be noticed rather than waited for. Only mounted\n // while the drawer is actually floating open.\n React.useEffect(() => {\n if (!onHover) return;\n const collapseIfOwed = () => {\n if (!collapseWhenPopoverCloses.current) return;\n if (document.querySelector(\"[data-radix-popper-content-wrapper]\")) return;\n collapseWhenPopoverCloses.current = false;\n setOnHover(false);\n };\n const observer = new MutationObserver(collapseIfOwed);\n observer.observe(document.body, {\n childList: true,\n subtree: true\n });\n return () => observer.disconnect();\n }, [onHover]);\n\n const handleDrawerOpen = useCallback(() => {\n setDrawerOpen(true);\n }, [setDrawerOpen]);\n\n const handleDrawerClose = useCallback(() => {\n setDrawerOpen(false);\n }, [setDrawerOpen]);\n\n const computedDrawerOpen: boolean = drawerOpen;\n const computedDrawerHovered = Boolean(largeLayout && onHover);\n\n const hasAppBar = Boolean(appBarChildren.length > 0);\n // Below `lg` the drawer is a sheet, opened from a menu button. An app\n // bar leaves room for that button; without one, the button floated over\n // the first thing on the page — the collection toolbar's view switcher —\n // so it gets a row of its own instead.\n const menuButtonRow = Boolean(includeDrawer) && !largeLayout && !hasAppBar;\n const appContextValue = useMemo(() => ({\n hasDrawer: Boolean(includeDrawer),\n drawerOpen: computedDrawerOpen,\n drawerHovered: computedDrawerHovered,\n openDrawer: handleDrawerOpen,\n closeDrawer: handleDrawerClose,\n closeHover: setOnHoverFalse,\n logo\n }), [includeDrawer, computedDrawerOpen, computedDrawerHovered, handleDrawerOpen, handleDrawerClose, setOnHoverFalse, logo]);\n\n return (\n <AppContext.Provider value={appContextValue}>\n <div\n className={cls(\"flex h-screen w-screen overflow-hidden\",\n \"bg-surface-frame\",\n \"text-surface-900 dark:text-white\", className)}\n style={{\n paddingTop: \"env(safe-area-inset-top)\",\n paddingLeft: \"env(safe-area-inset-left)\",\n paddingRight: \"env(safe-area-inset-right)\",\n paddingBottom: \"env(safe-area-inset-bottom)\",\n height: \"100dvh\",\n ...style\n }}>\n {appBarChildren}\n\n <DrawerWrapper\n displayed={includeDrawer}\n onMouseEnter={setOnHoverTrue}\n onMouseMove={setOnHoverTrue}\n onMouseLeave={setOnHoverFalse}\n open={drawerOpen}\n hovered={onHover}\n setDrawerOpen={setDrawerOpen}\n floatingMenuButton={!menuButtonRow}>\n {includeDrawer && drawerChildren}\n </DrawerWrapper>\n\n <main\n className=\"flex flex-col grow overflow-auto\">\n\n {hasAppBar && <DrawerHeader/>}\n {menuButtonRow && <MenuButtonRow onOpen={handleDrawerOpen}/>}\n\n {/* Above the sheet, so it is there on every screen: while\n the realtime connection is down, every live view is\n showing what it last received. */}\n <ConnectionLostBanner className={cls(\"px-2 pt-1\", {\n \"lg:pt-0 lg:pb-2\": padding,\n \"lg:pt-2\": !hasAppBar && padding\n })}/>\n\n {/* While access is simulated, every data view shows\n another identity's rows: say so on every screen. */}\n <RlsSimulationBanner className={cls(\"px-2 pt-1\", {\n \"lg:pt-0 lg:pb-2\": padding,\n \"lg:pt-2\": !hasAppBar && padding\n })}/>\n\n <div\n // The sheet is one lightness step above the frame AND carries a\n // plain hairline on its edge. The step alone (#090a0c to #111316,\n // #eff0f3 to #f8f9fa) is about 3 L* on both themes, under what a\n // dimmed screen renders, and the first pass of this system removed\n // the line on the theory that the step would do its work; the\n // frame and the sheet then read as one black. The reference's own\n // content sheet carries this line. Only in the inset `lg` layout:\n // edge-to-edge on small screens, a border draws at the viewport.\n className={cls(\"bg-surface-sheet\", \"grow overflow-auto m-0\", \"lg:border lg:border-hairline\", {\n \"mt-1 lg:m-0 lg:mx-2 lg:mb-2 lg:rounded-xl\": padding,\n // No app bar means no DrawerHeader spacer above, so inset the\n // panel by the same amount as its sides and bottom.\n // Must come after the padding classes, which reset lg margins.\n \"lg:mt-2\": !hasAppBar && padding,\n \"lg:mt-4\": !hasAppBar && !padding\n })}>\n\n <ErrorBoundary>\n {otherChildren}\n </ErrorBoundary>\n\n </div>\n </main>\n </div>\n </AppContext.Provider>\n );\n },\n equal\n)\n\nconst DrawerHeader = () => {\n return (\n <div className=\"flex flex-col min-h-14\"></div>\n );\n};\n\n/** The small-layout menu button, in the flow above the sheet. */\nfunction MenuButtonRow({ onOpen }: { onOpen: () => void }) {\n const { t } = useTranslation();\n return (\n <div className=\"flex items-center shrink-0 px-2 sm:px-4 pt-1\">\n <IconButton aria-label={t(\"open_menu\")} onClick={onOpen}>\n <MenuIcon/>\n </IconButton>\n </div>\n );\n}\n\nfunction DrawerWrapper(props: {\n children: React.ReactNode,\n displayed: boolean,\n open: boolean,\n logo?: string,\n hovered: boolean,\n setDrawerOpen: (open: boolean) => void,\n /** Draw the small layout's menu button over the page; false when the page has a row for it. */\n floatingMenuButton: boolean,\n onMouseEnter: () => void,\n onMouseMove: () => void,\n onMouseLeave: () => void\n}) {\n\n const layoutWidth = !props.displayed ? 0 : (props.open ? DRAWER_WIDTH : 72);\n const visualWidth = !props.displayed ? 0 : ((props.open || props.hovered) ? DRAWER_WIDTH : 72);\n\n const isFloating = props.hovered && !props.open;\n const { t } = useTranslation();\n\n // The drawer is part of the frame, on both themes. When it floats over the\n // sheet it needs an edge, because a frame-coloured panel over the sheet is\n // an object at that moment; docked, it is a region and gets none.\n const innerDrawer = <div\n className={cls(\"h-full overflow-hidden bg-surface-frame\", defaultBorderMixin,\n isFloating ? \"absolute top-0 left-0 bottom-0 z-50 shadow-lg border-r\" : \"relative\")}\n style={{\n width: visualWidth,\n transition: \"left 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms\"\n }}\n >\n\n <div className={\"flex flex-col h-full\"}>\n {props.children}\n </div>\n\n </div>;\n\n const largeLayout = useLargeLayout();\n if (!largeLayout) {\n if (!props.displayed)\n return null;\n return <>\n {props.floatingMenuButton && <IconButton\n aria-label={t(\"open_menu\")}\n onClick={() => props.setDrawerOpen(true)}\n className=\"absolute sm:top-2 sm:left-4 top-1 left-2\"\n >\n <MenuIcon/>\n </IconButton>}\n <Sheet side={\"left\"}\n transparent={true}\n open={props.open}\n onOpenChange={props.setDrawerOpen}\n title={t(\"navigation_drawer\")}\n overlayClassName={\"bg-surface-scrim\"}\n >\n {innerDrawer}\n </Sheet>\n </>;\n }\n\n return (\n <div\n className=\"z-20 relative flex-shrink-0 overflow-visible\"\n onMouseEnter={props.onMouseEnter}\n onMouseMove={props.onMouseMove}\n onMouseLeave={props.onMouseLeave}\n style={{\n width: layoutWidth,\n minWidth: layoutWidth,\n transition: \"left 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms\"\n }}>\n\n {innerDrawer}\n\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAeA,SAAgB,qBAAqB,UAA8B;CAC/D,OAAO,sBAAsB,YAAY;AAC7C;;AAGA,SAAS,qBAAqB,KAA6B;CACvD,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,IAAI;EACA,MAAM,SAAS,OAAO,aAAa,QAAQ,GAAG;EAC9C,OAAO,WAAW,OAAO,OAAO,WAAW;CAC/C,SAAS,GAAG;EAER,OAAO;CACX;AACJ;AAEA,SAAS,sBAAsB,KAAa,MAAe;CACvD,IAAI,OAAO,WAAW,aAAa;CACnC,IAAI;EACA,OAAO,aAAa,QAAQ,KAAK,OAAO,IAAI,CAAC;CACjD,SAAS,GAAG,CAEZ;AACJ;;;;;;;;;;;;AAoDA,IAAa,WAAW,MAAM,KAC1B,SAAS,SAAS,OAAyC;CAEvD,MAAM,EACF,UACA,iBAAiB,MACjB,oBAAoB,OACpB,MACA,WACA,OACA,UAAU,SACV;CAOJ,MAAM,UAAU,UACZ,MAAM,eAAe,KAAK,IACnB,MAAM,MAAqC,gBAC5C,KAAA;CAEV,MAAM,aAAa,MAAM,SAAS,QAAQ,QAAQ;CAClD,MAAM,iBAAiB,WAAW,QAAQ,UAAU,OAAO,KAAK,MAAM,QAAQ;CAC9E,IAAI,eAAe,SAAS,GACxB,MAAM,MAA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AAD;GAAK,WAAW;aACX,MAAM;EACN,CAAA;CAEJ,CAAA;CAGL,IAAI,CADgB,eACf,GAAa;EACd,IAAI,CAAC,MAAM,WACP,OAAO;EACX,OAAO,qBAAA,UAAA,EAAA,UAAA,CACF,MAAM,sBAAsB,oBAAC,YAAD;GACzB,cAAY,EAAE,WAAW;GACzB,eAAe,MAAM,cAAc,IAAI;GACvC,WAAU;aAEV,oBAAC,UAAD,CAAU,CAAA;EACF,CAAA,GACZ,oBAAC,OAAD;GAAO,MAAM;GACT,aAAa;GACb,MAAM,MAAM;GACZ,cAAc,MAAM;GACpB,OAAO,EAAE,mBAAmB;GAC5B,kBAAkB;aAEjB;EACE,CAAA,CACT,EAAA,CAAA;CACN;CAEA,OACI,oBAAC,OAAD;EACI,WAAU;EACV,cAAc,MAAM;EACpB,aAAa,MAAM;EACnB,cAAc,MAAM;EACpB,OAAO;GACH,OAAO;GACP,UAAU;GACV,YAAY;EAChB;YAEC;CAEA,CAAA;AAEb"}
1
+ {"version":3,"file":"Scaffold.js","names":[],"sources":["../../../src/components/app/Scaffold.tsx"],"sourcesContent":["import React, { PropsWithChildren, useCallback, useMemo } from \"react\";\nimport { cls, defaultBorderMixin, IconButton, Sheet, Tooltip } from \"@rebasepro/ui\";\nimport { ChevronLeftIcon, ErrorBoundary, MenuIcon } from \"@rebasepro/ui\";\nimport { deepEqual as equal } from \"fast-equals\"\n\nimport { ConnectionLostBanner, RlsSimulationBanner, useLargeLayout, useTranslation } from \"@rebasepro/app\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { AppContext } from \"./useApp\";\n\nexport const DRAWER_WIDTH = 280;\n\n/**\n * Namespaced by base path: two admins served from one origin are two different\n * navigations, and a single key would have them overwrite each other's drawer.\n */\nexport function drawerOpenStorageKey(basePath: string | undefined) {\n return `rebase-drawer-open:${basePath || \"/\"}`;\n}\n\n/** `null` when the user has never toggled the drawer, or storage is unavailable. */\nfunction readStoredDrawerOpen(key: string): boolean | null {\n if (typeof window === \"undefined\") return null;\n try {\n const stored = window.localStorage.getItem(key);\n return stored === null ? null : stored === \"true\";\n } catch (e) {\n // Storage can be blocked: private mode, sandboxed iframe, cookie policy.\n return null;\n }\n}\n\nfunction writeStoredDrawerOpen(key: string, open: boolean) {\n if (typeof window === \"undefined\") return;\n try {\n window.localStorage.setItem(key, String(open));\n } catch (e) {\n // Same as above: a drawer that forgets is better than a crash.\n }\n}\n\n/**\n * @group Core\n */\nexport interface ScaffoldProps {\n\n /**\n * Expand the collapsed drawer while the pointer is over it. On by default —\n * pass `false` to keep the rail a rail until the user clicks the toggle.\n */\n autoOpenDrawer?: boolean;\n\n /**\n * Start with the drawer expanded rather than collapsed to icons.\n *\n * Distinct from {@link autoOpenDrawer}, which is a hover behaviour: this one\n * only seeds the very first visit. Once the user toggles the drawer, that\n * choice is stored in `localStorage` and wins over this prop on every load.\n *\n * Ignored on small layouts, where an expanded drawer covers the content it is\n * meant to navigate.\n */\n defaultDrawerOpen?: boolean;\n\n /**\n * Logo to be displayed in the top bar and drawer.\n * Note that this has no effect if you are using a custom AppBar or Drawer.\n */\n logo?: string;\n\n /**\n * The logo for the dark theme, when `logo` would not read on a dark\n * background. Falls back to `logo`.\n */\n logoDark?: string;\n\n /**\n * If true, the main content will be padded in large layouts. Defaults to true.\n */\n padding?: boolean;\n\n className?: string;\n\n style?: React.CSSProperties;\n}\n\n/**\n * This view acts as a scaffold for Rebase.\n *\n * It is in charge of displaying the navigation drawer, top bar and main\n * collection views.\n * This component needs a parent {@link Rebase}\n *\n * @param props\n\n * @group Core\n */\nexport const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(\n function Scaffold(props: PropsWithChildren<ScaffoldProps>) {\n\n const {\n children,\n autoOpenDrawer = true,\n defaultDrawerOpen = false,\n logo,\n logoDark,\n className,\n style,\n padding = true\n } = props;\n\n // `toArray` keeps strings and numbers, and those have no `.type` at all.\n // Reading `child.type.componentType` off one threw a TypeError from\n // inside the layout, which is a bewildering way to be told that a stray\n // text node — a conditional that rendered `\"\"`, a template string —\n // reached the Scaffold. Anything that is not an element is just \"other\".\n const slotOf = (child: React.ReactNode): string | undefined =>\n React.isValidElement(child)\n ? (child.type as { componentType?: string })?.componentType\n : undefined;\n\n const childArray = React.Children.toArray(children);\n const drawerChildren = childArray.filter((child) => slotOf(child) === \"Drawer\");\n if (drawerChildren.length > 1) {\n throw Error(\"Only one Drawer component is allowed in Scaffold\");\n }\n const appBarChildren = childArray.filter((child) => slotOf(child) === \"AppBar\");\n if (appBarChildren.length > 1) {\n throw Error(\"Only one AppBar component is allowed in Scaffold\");\n }\n const otherChildren = childArray\n .filter((child) => slotOf(child) !== \"Drawer\" && slotOf(child) !== \"AppBar\");\n const includeDrawer = drawerChildren.length > 0;\n const largeLayout = useLargeLayout();\n\n const storageKey = drawerOpenStorageKey(useUrlController().basePath);\n\n // Seeded once, deliberately: a `useEffect` syncing this to the prop would\n // re-expand the drawer under a user who had just collapsed it.\n const [drawerOpen, setDrawerOpenState] = React.useState(defaultDrawerOpen && largeLayout);\n const [onHover, setOnHover] = React.useState(false);\n\n // The stored choice is a client-only fact, so it is applied after the first\n // render rather than seeded into it: reading storage while rendering would\n // make the client disagree with server-rendered HTML. A layout effect runs\n // before paint, so the drawer still arrives in its remembered state.\n // `defaultDrawerOpen` seeds the very first visit and is ignored after that.\n React.useLayoutEffect(() => {\n const stored = readStoredDrawerOpen(storageKey);\n if (stored === null) return;\n setDrawerOpenState(stored && largeLayout);\n // Deliberately not re-run on `largeLayout`: crossing the breakpoint is\n // the effect below, and re-running here would undo a user's toggle.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storageKey]);\n\n // One piece of state drives two different things: the expanded rail on\n // large layouts, and the modal sheet on small ones. Carrying an expanded\n // rail across the breakpoint would drop that sheet, overlay and all, over\n // the content — so the crossing resets it, and widening again restores\n // whatever the user last chose.\n const wasLargeLayout = React.useRef(largeLayout);\n React.useEffect(() => {\n if (wasLargeLayout.current === largeLayout) return;\n wasLargeLayout.current = largeLayout;\n setDrawerOpenState(largeLayout ? (readStoredDrawerOpen(storageKey) ?? defaultDrawerOpen) : false);\n }, [largeLayout, defaultDrawerOpen, storageKey]);\n\n const setDrawerOpen = useCallback((open: boolean) => {\n setDrawerOpenState(open);\n // Small layouts render the drawer as a modal sheet. Remembering that\n // one would greet the next load with an overlay over the content.\n if (!largeLayout) return;\n writeStoredDrawerOpen(storageKey, open);\n }, [largeLayout, storageKey]);\n\n // The pointer has left, but a popover the drawer opened is still up, so the\n // collapse is owed rather than cancelled. See `setOnHoverFalse`.\n const collapseWhenPopoverCloses = React.useRef(false);\n\n const setOnHoverTrue = useCallback(() => {\n // Hover expansion is the default; `autoOpenDrawer={false}` opts out for\n // admins that want the rail to stay a rail until the toggle is clicked.\n if (!autoOpenDrawer) return;\n collapseWhenPopoverCloses.current = false;\n setOnHover(true);\n }, [autoOpenDrawer]);\n const setOnHoverFalse = useCallback(() => {\n // Don't collapse the drawer out from under an open popover/dropdown —\n // its content is portalled outside the drawer, so reaching for it reads\n // as a mouseleave. The collapse is owed until that popover closes.\n if (document.querySelector(\"[data-radix-popper-content-wrapper]\")) {\n collapseWhenPopoverCloses.current = true;\n return;\n }\n collapseWhenPopoverCloses.current = false;\n setOnHover(false);\n }, []);\n\n // Nothing fires a second mouseleave when the popover finally closes, so the\n // owed collapse has to be noticed rather than waited for. Only mounted\n // while the drawer is actually floating open.\n React.useEffect(() => {\n if (!onHover) return;\n const collapseIfOwed = () => {\n if (!collapseWhenPopoverCloses.current) return;\n if (document.querySelector(\"[data-radix-popper-content-wrapper]\")) return;\n collapseWhenPopoverCloses.current = false;\n setOnHover(false);\n };\n const observer = new MutationObserver(collapseIfOwed);\n observer.observe(document.body, {\n childList: true,\n subtree: true\n });\n return () => observer.disconnect();\n }, [onHover]);\n\n const handleDrawerOpen = useCallback(() => {\n setDrawerOpen(true);\n }, [setDrawerOpen]);\n\n const handleDrawerClose = useCallback(() => {\n setDrawerOpen(false);\n }, [setDrawerOpen]);\n\n const computedDrawerOpen: boolean = drawerOpen;\n const computedDrawerHovered = Boolean(largeLayout && onHover);\n\n const hasAppBar = Boolean(appBarChildren.length > 0);\n // Below `lg` the drawer is a sheet, opened from a menu button. An app\n // bar leaves room for that button; without one, the button floated over\n // the first thing on the page — the collection toolbar's view switcher —\n // so it gets a row of its own instead.\n const menuButtonRow = Boolean(includeDrawer) && !largeLayout && !hasAppBar;\n const appContextValue = useMemo(() => ({\n hasDrawer: Boolean(includeDrawer),\n drawerOpen: computedDrawerOpen,\n drawerHovered: computedDrawerHovered,\n openDrawer: handleDrawerOpen,\n closeDrawer: handleDrawerClose,\n closeHover: setOnHoverFalse,\n logo,\n logoDark\n }), [includeDrawer, computedDrawerOpen, computedDrawerHovered, handleDrawerOpen, handleDrawerClose, setOnHoverFalse, logo, logoDark]);\n\n return (\n <AppContext.Provider value={appContextValue}>\n <div\n className={cls(\"flex h-screen w-screen overflow-hidden\",\n \"bg-surface-frame\",\n \"text-surface-900 dark:text-white\", className)}\n style={{\n paddingTop: \"env(safe-area-inset-top)\",\n paddingLeft: \"env(safe-area-inset-left)\",\n paddingRight: \"env(safe-area-inset-right)\",\n paddingBottom: \"env(safe-area-inset-bottom)\",\n height: \"100dvh\",\n ...style\n }}>\n {appBarChildren}\n\n <DrawerWrapper\n displayed={includeDrawer}\n onMouseEnter={setOnHoverTrue}\n onMouseMove={setOnHoverTrue}\n onMouseLeave={setOnHoverFalse}\n open={drawerOpen}\n hovered={onHover}\n setDrawerOpen={setDrawerOpen}\n floatingMenuButton={!menuButtonRow}>\n {includeDrawer && drawerChildren}\n </DrawerWrapper>\n\n <main\n className=\"flex flex-col grow overflow-auto\">\n\n {hasAppBar && <DrawerHeader/>}\n {menuButtonRow && <MenuButtonRow onOpen={handleDrawerOpen}/>}\n\n {/* Above the sheet, so it is there on every screen: while\n the realtime connection is down, every live view is\n showing what it last received. */}\n <ConnectionLostBanner className={cls(\"px-2 pt-1\", {\n \"lg:pt-0 lg:pb-2\": padding,\n \"lg:pt-2\": !hasAppBar && padding\n })}/>\n\n {/* While access is simulated, every data view shows\n another identity's rows: say so on every screen. */}\n <RlsSimulationBanner className={cls(\"px-2 pt-1\", {\n \"lg:pt-0 lg:pb-2\": padding,\n \"lg:pt-2\": !hasAppBar && padding\n })}/>\n\n <div\n // The sheet is one lightness step above the frame AND carries a\n // plain hairline on its edge. The step alone (#090a0c to #111316,\n // #eff0f3 to #f8f9fa) is about 3 L* on both themes, under what a\n // dimmed screen renders, and the first pass of this system removed\n // the line on the theory that the step would do its work; the\n // frame and the sheet then read as one black. The reference's own\n // content sheet carries this line. Only in the inset `lg` layout:\n // edge-to-edge on small screens, a border draws at the viewport.\n className={cls(\"bg-surface-sheet\", \"grow overflow-auto m-0\", \"lg:border lg:border-hairline\", {\n \"mt-1 lg:m-0 lg:mx-2 lg:mb-2 lg:rounded-xl\": padding,\n // No app bar means no DrawerHeader spacer above, so inset the\n // panel by the same amount as its sides and bottom.\n // Must come after the padding classes, which reset lg margins.\n \"lg:mt-2\": !hasAppBar && padding,\n \"lg:mt-4\": !hasAppBar && !padding\n })}>\n\n <ErrorBoundary>\n {otherChildren}\n </ErrorBoundary>\n\n </div>\n </main>\n </div>\n </AppContext.Provider>\n );\n },\n equal\n)\n\nconst DrawerHeader = () => {\n return (\n <div className=\"flex flex-col min-h-14\"></div>\n );\n};\n\n/** The small-layout menu button, in the flow above the sheet. */\nfunction MenuButtonRow({ onOpen }: { onOpen: () => void }) {\n const { t } = useTranslation();\n return (\n <div className=\"flex items-center shrink-0 px-2 sm:px-4 pt-1\">\n <IconButton aria-label={t(\"open_menu\")} onClick={onOpen}>\n <MenuIcon/>\n </IconButton>\n </div>\n );\n}\n\nfunction DrawerWrapper(props: {\n children: React.ReactNode,\n displayed: boolean,\n open: boolean,\n logo?: string,\n hovered: boolean,\n setDrawerOpen: (open: boolean) => void,\n /** Draw the small layout's menu button over the page; false when the page has a row for it. */\n floatingMenuButton: boolean,\n onMouseEnter: () => void,\n onMouseMove: () => void,\n onMouseLeave: () => void\n}) {\n\n const layoutWidth = !props.displayed ? 0 : (props.open ? DRAWER_WIDTH : 72);\n const visualWidth = !props.displayed ? 0 : ((props.open || props.hovered) ? DRAWER_WIDTH : 72);\n\n const isFloating = props.hovered && !props.open;\n const { t } = useTranslation();\n\n // The drawer is part of the frame, on both themes. When it floats over the\n // sheet it needs an edge, because a frame-coloured panel over the sheet is\n // an object at that moment; docked, it is a region and gets none.\n const innerDrawer = <div\n className={cls(\"h-full overflow-hidden bg-surface-frame\", defaultBorderMixin,\n isFloating ? \"absolute top-0 left-0 bottom-0 z-50 shadow-lg border-r\" : \"relative\")}\n style={{\n width: visualWidth,\n transition: \"left 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms\"\n }}\n >\n\n <div className={\"flex flex-col h-full\"}>\n {props.children}\n </div>\n\n </div>;\n\n const largeLayout = useLargeLayout();\n if (!largeLayout) {\n if (!props.displayed)\n return null;\n return <>\n {props.floatingMenuButton && <IconButton\n aria-label={t(\"open_menu\")}\n onClick={() => props.setDrawerOpen(true)}\n className=\"absolute sm:top-2 sm:left-4 top-1 left-2\"\n >\n <MenuIcon/>\n </IconButton>}\n <Sheet side={\"left\"}\n transparent={true}\n open={props.open}\n onOpenChange={props.setDrawerOpen}\n title={t(\"navigation_drawer\")}\n overlayClassName={\"bg-surface-scrim\"}\n >\n {innerDrawer}\n </Sheet>\n </>;\n }\n\n return (\n <div\n className=\"z-20 relative flex-shrink-0 overflow-visible\"\n onMouseEnter={props.onMouseEnter}\n onMouseMove={props.onMouseMove}\n onMouseLeave={props.onMouseLeave}\n style={{\n width: layoutWidth,\n minWidth: layoutWidth,\n transition: \"left 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 75ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 75ms cubic-bezier(0.4, 0, 0.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cAAc,MAAM;GACpB,OAAO,EAAE,mBAAmB;GAC5B,kBAAkB;aAEjB;EACE,CAAA,CACT,EAAA,CAAA;CACN;CAEA,OACI,oBAAC,OAAD;EACI,WAAU;EACV,cAAc,MAAM;EACpB,aAAa,MAAM;EACnB,cAAc,MAAM;EACpB,OAAO;GACH,OAAO;GACP,UAAU;GACV,YAAY;EAChB;YAEC;CAEA,CAAA;AAEb"}
@@ -12,6 +12,7 @@ export type AppState = {
12
12
  closeHover: () => void;
13
13
  autoOpenDrawer?: boolean;
14
14
  logo?: string;
15
+ logoDark?: string;
15
16
  };
16
17
  export declare const AppContext: React.Context<AppState>;
17
18
  export declare function useApp(): AppState;
@@ -1 +1 @@
1
- {"version":3,"file":"useApp.js","names":[],"sources":["../../../src/components/app/useApp.tsx"],"sourcesContent":["import React from \"react\";\n\n/**\n * This context represents the state of the app in terms of layout.\n * @group Core\n */\nexport type AppState = {\n hasDrawer: boolean,\n drawerHovered: boolean,\n drawerOpen: boolean,\n openDrawer: () => void,\n closeDrawer: () => void,\n closeHover: () => void,\n autoOpenDrawer?: boolean,\n logo?: string\n}\n\nexport const AppContext = React.createContext<AppState>({\n hasDrawer: false,\n drawerHovered: false,\n drawerOpen: false,\n openDrawer: () => {\n throw new Error(\"openDrawer not implemented\");\n },\n closeDrawer: () => {\n throw new Error(\"closeDrawer not implemented\");\n },\n closeHover: () => {\n throw new Error(\"closeHover not implemented\");\n },\n autoOpenDrawer: false\n});\n\nexport function useApp() {\n return React.useContext(AppContext);\n}\n"],"mappings":";;AAiBA,IAAa,aAAa,MAAM,cAAwB;CACpD,WAAW;CACX,eAAe;CACf,YAAY;CACZ,kBAAkB;EACd,MAAM,IAAI,MAAM,4BAA4B;CAChD;CACA,mBAAmB;EACf,MAAM,IAAI,MAAM,6BAA6B;CACjD;CACA,kBAAkB;EACd,MAAM,IAAI,MAAM,4BAA4B;CAChD;CACA,gBAAgB;AACpB,CAAC;AAED,SAAgB,SAAS;CACrB,OAAO,MAAM,WAAW,UAAU;AACtC"}
1
+ {"version":3,"file":"useApp.js","names":[],"sources":["../../../src/components/app/useApp.tsx"],"sourcesContent":["import React from \"react\";\n\n/**\n * This context represents the state of the app in terms of layout.\n * @group Core\n */\nexport type AppState = {\n hasDrawer: boolean,\n drawerHovered: boolean,\n drawerOpen: boolean,\n openDrawer: () => void,\n closeDrawer: () => void,\n closeHover: () => void,\n autoOpenDrawer?: boolean,\n logo?: string,\n logoDark?: string\n}\n\nexport const AppContext = React.createContext<AppState>({\n hasDrawer: false,\n drawerHovered: false,\n drawerOpen: false,\n openDrawer: () => {\n throw new Error(\"openDrawer not implemented\");\n },\n closeDrawer: () => {\n throw new Error(\"closeDrawer not implemented\");\n },\n closeHover: () => {\n throw new Error(\"closeHover not implemented\");\n },\n autoOpenDrawer: false\n});\n\nexport function useApp() {\n return React.useContext(AppContext);\n}\n"],"mappings":";;AAkBA,IAAa,aAAa,MAAM,cAAwB;CACpD,WAAW;CACX,eAAe;CACf,YAAY;CACZ,kBAAkB;EACd,MAAM,IAAI,MAAM,4BAA4B;CAChD;CACA,mBAAmB;EACf,MAAM,IAAI,MAAM,6BAA6B;CACjD;CACA,kBAAkB;EACd,MAAM,IAAI,MAAM,4BAA4B;CAChD;CACA,gBAAgB;AACpB,CAAC;AAED,SAAgB,SAAS;CACrB,OAAO,MAAM,WAAW,UAAU;AACtC"}
@@ -483,7 +483,7 @@ var TableGridPicker = ({ hoveredRow, hoveredCol, onHover, onSelect }) => {
483
483
  children: Array.from({ length: 5 }).map((_, r) => /* @__PURE__ */ jsx("div", {
484
484
  className: "flex gap-1",
485
485
  children: Array.from({ length: 5 }).map((_, c) => /* @__PURE__ */ jsx("div", {
486
- className: cls("w-5 h-5 border rounded-sm cursor-pointer transition-colors duration-75", r <= hoveredRow && c <= hoveredCol ? "bg-blue-100 border-blue-400 dark:bg-blue-900 dark:border-blue-500" : "bg-surface-card border-gray-200 dark:border-gray-700 hover:border-blue-300"),
486
+ className: cls("w-5 h-5 border rounded-sm cursor-pointer transition-colors duration-75", r <= hoveredRow && c <= hoveredCol ? "bg-primary-bg border-primary" : "bg-surface-card border-gray-200 dark:border-gray-700 hover:border-primary/50"),
487
487
  onMouseEnter: () => onHover(r, c),
488
488
  onClick: () => onSelect(hoveredRow + 1, hoveredCol + 1)
489
489
  }, c))
@@ -1 +1 @@
1
- {"version":3,"file":"SlashCommandMenu.js","names":[],"sources":["../../../src/editor/components/SlashCommandMenu.tsx"],"sourcesContent":["\nimport React, { useEffect, useRef, useState, ReactNode } from \"react\";\nimport { Fragment, DOMParser } from \"prosemirror-model\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { autoUpdate, computePosition, flip, offset, shift, type VirtualElement } from \"@floating-ui/dom\";\nimport { SlashCommandPluginKey } from \"../plugins/slashCommandPlugin\";\nimport {\n CheckSquareIcon,\n cls,\n CodeIcon,\n defaultBorderMixin,\n Heading1Icon,\n Heading2Icon,\n Heading3Icon,\n iconSize,\n ImageIcon,\n ListIcon,\n ListOrderedIcon,\n QuoteIcon,\n TableIcon,\n TypeIcon,\n Wand2Icon\n} from \"@rebasepro/ui\";\nimport { setBlockType, wrapIn } from \"prosemirror-commands\";\nimport { wrapInList } from \"prosemirror-schema-list\";\nimport { schema } from \"../schema\";\nimport { EditorView } from \"prosemirror-view\";\nimport { TextSelection } from \"prosemirror-state\";\nimport type { EditorAIController } from \"../types\";\nimport { onFileRead, UploadFn } from \"../extensions/Image\";\nimport { textLoadingCommands } from \"../extensions/TextLoadingDecorationExtension\";\nimport { parser } from \"../markdown\";\nimport { parseSanitizedHtml } from \"../sanitize-html\";\n\ninterface SuggestionItem {\n title: string;\n description: string;\n icon: ReactNode;\n searchTerms?: string[];\n command: (\n view: EditorView,\n range: { from: number; to: number },\n upload: UploadFn,\n aiController?: EditorAIController,\n setSubView?: (viewId: string | null) => void\n ) => void;\n}\n\nconst suggestionItems: SuggestionItem[] = [\n {\n title: \"Text\",\n description: \"Just start typing with plain text.\",\n searchTerms: [\"p\", \"paragraph\"],\n icon: <TypeIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);\n }\n },\n {\n title: \"To-do List\",\n description: \"Track tasks with a to-do list.\",\n searchTerms: [\"todo\", \"task\", \"list\", \"check\", \"checkbox\"],\n icon: <CheckSquareIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.task_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 1\",\n description: \"Big section heading.\",\n searchTerms: [\"title\", \"big\", \"large\"],\n icon: <Heading1Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 1 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 2\",\n description: \"Medium section heading.\",\n searchTerms: [\"subtitle\", \"medium\"],\n icon: <Heading2Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 2 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 3\",\n description: \"Small section heading.\",\n searchTerms: [\"subtitle\", \"small\"],\n icon: <Heading3Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 3 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Bullet List\",\n description: \"Create a simple bullet list.\",\n searchTerms: [\"unordered\", \"point\"],\n icon: <ListIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.bullet_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Numbered List\",\n description: \"Create a list with numbering.\",\n searchTerms: [\"ordered\"],\n icon: <ListOrderedIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.ordered_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Quote\",\n description: \"Capture a quote.\",\n searchTerms: [\"blockquote\"],\n icon: <QuoteIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapIn(schema.nodes.blockquote)(view.state, view.dispatch);\n }\n },\n {\n title: \"Code\",\n description: \"Capture a code snippet.\",\n searchTerms: [\"codeblock\"],\n icon: <CodeIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.code_block)(view.state, view.dispatch);\n }\n },\n {\n title: \"Image\",\n description: \"Upload an image from your computer.\",\n searchTerms: [\"photo\", \"picture\", \"media\", \"upload\", \"file\"],\n icon: <ImageIcon size={iconSize.small}/>,\n command: (view, range, upload) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.accept = \"image/*\";\n input.onchange = async () => {\n if (input.files?.length) {\n const file = input.files[0];\n if (!file) return;\n const pos = view.state.selection.from;\n\n const images = Array.from(input.files).filter(f => /image/i.test(f.type));\n if (images.length === 0) return false;\n\n images.forEach(image => {\n const reader = new FileReader();\n reader.onload = async (readerEvent) => {\n await onFileRead(view, readerEvent, pos, upload, image);\n };\n reader.readAsDataURL(image);\n });\n }\n return true;\n };\n input.click();\n }\n },\n {\n title: \"Table\",\n description: \"Insert a custom grid table.\",\n searchTerms: [\"table\", \"grid\", \"row\", \"col\"],\n icon: <TableIcon size={iconSize.small}/>,\n command: (view, range, upload, aiController, setSubView) => {\n if (setSubView) setSubView(\"table-grid\");\n }\n }\n];\n\nconst autocompleteSuggestionItem: SuggestionItem = {\n title: \"Autocomplete\",\n description: \"Add text based on the context.\",\n searchTerms: [\"ai\"],\n icon: <Wand2Icon size={iconSize.small}/>,\n command: async (view, range, upload, aiController) => {\n if (!aiController) throw Error(\"No AiController\");\n\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);\n\n const { state } = view;\n const { from, to } = state.selection;\n\n const textBeforeCursor = state.doc.textBetween(0, from, \"\\n\");\n const textAfterCursor = state.doc.textBetween(to, state.doc.content.size, \"\\n\");\n\n let buffer = \"\";\n const result = await aiController.autocomplete(textBeforeCursor, textAfterCursor, (delta) => {\n buffer += delta;\n if (delta.length !== 0) {\n textLoadingCommands.toggleLoadingDecoration(view.state, view.dispatch, buffer);\n }\n });\n\n // Insert parsed text result at cursor natively\n try {\n // The AI controller might stream literal \"\\n\" characters depending on its JSON decoding layer.\n // We need to un-escape these back to genuine newlines so MarkdownIt block-parsing works.\n const unescapedResult = result.replace(/\\\\n/g, \"\\n\").replace(/\\\\t/g, \"\\t\");\n\n const isHTML = /<\\/?[a-z][\\s\\S]*>/i.test(unescapedResult);\n let parsedDoc;\n\n if (isHTML) {\n // Parsed inertly and reduced to the editor's own allowlist\n // before it touches the live document. `document.createElement`\n // plus `innerHTML` was the opposite: an element in this\n // document, so the content ran as it was assigned.\n //\n // ProseMirror's own parse drops nodes its schema does not know,\n // but that happens AFTER the browser has already executed\n // whatever it was handed — the schema is a shape filter, not a\n // security boundary.\n parsedDoc = DOMParser.fromSchema(view.state.schema).parse(parseSanitizedHtml(unescapedResult));\n } else {\n parsedDoc = parser.parse(unescapedResult);\n }\n\n if (parsedDoc) {\n const tr = view.state.tr.replaceWith(view.state.selection.from, view.state.selection.from, parsedDoc.content);\n view.dispatch(tr);\n } else {\n view.dispatch(view.state.tr.insertText(unescapedResult));\n }\n } catch (e) {\n console.error(e);\n view.dispatch(view.state.tr.insertText(result));\n }\n }\n};\n\nexport const SlashCommandMenu = ({ upload, aiController }: { upload: UploadFn, aiController?: EditorAIController }) => {\n const { view, state } = useProseMirrorContext();\n const menuRef = useRef<HTMLDivElement>(null);\n const [selectedIndex, setSelectedIndex] = useState(0);\n const [subView, setSubView] = useState<string | null>(null);\n const [tableGridCoords, setTableGridCoords] = useState({ r: 0,\nc: 0 });\n\n const pluginState = state ? SlashCommandPluginKey.getState(state) : null;\n const isActive = pluginState?.active;\n const query = pluginState?.query || \"\";\n const range = pluginState?.range;\n\n const filteredItems = React.useMemo(() => {\n if (!isActive) return [];\n const availableItems = [...suggestionItems];\n if (aiController) availableItems.push(autocompleteSuggestionItem);\n\n return availableItems.filter(item => {\n const inTitle = item.title.toLowerCase().includes(query.toLowerCase());\n if (inTitle) return inTitle;\n return item.searchTerms?.some(term => term.toLowerCase().includes(query.toLowerCase()));\n });\n }, [query, isActive, aiController]);\n\n useEffect(() => {\n setSelectedIndex(0);\n }, [query]);\n\n useEffect(() => {\n if (!isActive) setSubView(null);\n }, [isActive]);\n\n useEffect(() => {\n if (!view || !isActive || !range || !menuRef.current) return;\n\n const start = view.coordsAtPos(range.from);\n const virtualEl = {\n getBoundingClientRect() {\n return {\n width: 0,\n height: start.bottom - start.top,\n x: start.left,\n y: start.top,\n top: start.top,\n left: start.left,\n right: start.left,\n bottom: start.bottom\n };\n }\n };\n\n const cleanup = autoUpdate(virtualEl as VirtualElement, menuRef.current, () => {\n if (!menuRef.current) return;\n computePosition(virtualEl as VirtualElement, menuRef.current, {\n placement: \"bottom-start\",\n middleware: [offset(4), flip(), shift()],\n strategy: \"fixed\"\n }).then(({ x, y }) => {\n if (menuRef.current) {\n Object.assign(menuRef.current.style, {\n left: `${x}px`,\n top: `${y}px`,\n visibility: \"visible\"\n });\n }\n });\n });\n return () => cleanup();\n }, [view, isActive, range]);\n\n useEffect(() => {\n if (!isActive || !view) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (subView === \"table-grid\") {\n if (e.key === \"Escape\") {\n e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation();\n setSubView(null);\n setTableGridCoords({ r: 0,\nc: 0 });\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: Math.max(0, prev.r - 1),\nc: prev.c }));\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: Math.min(4, prev.r + 1),\nc: prev.c }));\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: prev.r,\nc: Math.max(0, prev.c - 1) }));\n } else if (e.key === \"ArrowRight\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: prev.r,\nc: Math.min(4, prev.c + 1) }));\n } else if (e.key === \"Enter\") {\n e.preventDefault(); e.stopPropagation();\n if (range) {\n const tableNode = createTableNode(view.state.schema, tableGridCoords.r + 1, tableGridCoords.c + 1);\n const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);\n try {\n const selection = TextSelection.create(tr.doc, range.from + 4);\n tr.setSelection(selection);\n } catch (e) {\n console.warn(\"Could not select first cell\", e);\n }\n tr.setMeta(SlashCommandPluginKey, { active: false });\n view.dispatch(tr);\n view.focus();\n setSubView(null);\n setTableGridCoords({ r: 0,\nc: 0 });\n }\n }\n return;\n }\n\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex(prev => (prev + filteredItems.length - 1) % filteredItems.length);\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex(prev => (prev + 1) % filteredItems.length);\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n e.stopPropagation();\n if (filteredItems[selectedIndex] && range) {\n filteredItems[selectedIndex].command(view, range, upload, aiController, setSubView);\n // Do not focus view if a subview opened\n setTimeout(() => {\n // Focus is managed by the caller\n }, 0);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n e.stopImmediatePropagation();\n // Close menu gracefully and keep it dismissed\n view.dispatch(view.state.tr.setMeta(SlashCommandPluginKey, { active: false,\ndismissed: true }));\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown, { capture: true });\n return () => window.removeEventListener(\"keydown\", handleKeyDown, { capture: true });\n }, [isActive, selectedIndex, filteredItems, view, range, upload, aiController, subView, tableGridCoords]);\n\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n\n useEffect(() => {\n if (itemRefs.current[selectedIndex]) {\n itemRefs.current[selectedIndex]?.scrollIntoView({ block: \"nearest\" });\n }\n }, [selectedIndex]);\n\n useEffect(() => {\n if (!subView) {\n setTableGridCoords({ r: 0,\nc: 0 });\n }\n }, [subView]);\n\n if (!isActive || filteredItems.length === 0) return null;\n\n if (subView === \"table-grid\" && range && view) {\n return (\n <div\n ref={menuRef}\n onMouseDown={(e) => e.preventDefault()}\n style={{ position: \"fixed\",\nzIndex: 9999,\nvisibility: \"hidden\" }}\n className={cls(\"text-surface-900 dark:text-white rounded-md border bg-surface-card p-2 shadow transition-none\", defaultBorderMixin)}\n >\n <TableGridPicker\n hoveredRow={tableGridCoords.r}\n hoveredCol={tableGridCoords.c}\n onHover={(r, c) => setTableGridCoords({ r,\nc })}\n onSelect={(rows, cols) => {\n const tableNode = createTableNode(view.state.schema, rows, cols);\n const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);\n try {\n const selection = TextSelection.create(tr.doc, range.from + 4);\n tr.setSelection(selection);\n } catch (e) {\n console.warn(\"Could not select first cell\", e);\n }\n tr.setMeta(SlashCommandPluginKey, { active: false });\n view.dispatch(tr);\n view.focus();\n setSubView(null);\n }}\n />\n </div>\n );\n }\n\n return (\n <div\n ref={menuRef}\n style={{ position: \"fixed\",\nzIndex: 9999,\nvisibility: \"hidden\" }}\n className={cls(\"text-surface-900 dark:text-white max-h-[280px] w-72 overflow-y-auto rounded-md border bg-surface-card px-1 py-2 shadow transition-none\", defaultBorderMixin)}\n >\n {filteredItems.map((item, index) => (\n <button\n key={item.title}\n ref={el => { itemRefs.current[index] = el; }}\n onClick={(e) => {\n e.preventDefault();\n if (range && view) {\n item.command(view, range, upload, aiController, setSubView);\n // Only focus back to editor if it didn't open a sub-view\n if (!subView) view.focus();\n }\n }}\n onMouseDown={(e) => e.preventDefault()}\n className={cls(\"flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-surface-hover\",\n index === selectedIndex ? \"bg-surface-active\" : \"\")}\n >\n <div className={cls(\"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border bg-surface-card\", defaultBorderMixin)}>\n {item.icon}\n </div>\n <div className=\"flex flex-col overflow-hidden\">\n <p className=\"font-medium truncate\">{item.title}</p>\n <p className=\"text-xs text-surface-700 dark:text-surface-accent-300 truncate\">\n {item.description}\n </p>\n </div>\n </button>\n ))}\n </div>\n );\n};\n\nconst createTableNode = (schema: import(\"prosemirror-model\").Schema, rowsCount: number, colsCount: number) => {\n const rows = [];\n for (let r = 0; r < rowsCount; r++) {\n const cells = [];\n for (let c = 0; c < colsCount; c++) {\n const isHeader = r === 0;\n const cellType = isHeader ? schema.nodes.table_header : schema.nodes.table_cell;\n const cell = cellType.createAndFill();\n if (cell) cells.push(cell);\n }\n const row = schema.nodes.table_row.create(null, Fragment.from(cells));\n rows.push(row);\n }\n return schema.nodes.table.create(null, Fragment.from(rows));\n};\n\nconst TableGridPicker = ({\n hoveredRow,\n hoveredCol,\n onHover,\n onSelect\n}: {\n hoveredRow: number;\n hoveredCol: number;\n onHover: (r: number, c: number) => void;\n onSelect: (r: number, c: number) => void;\n}) => {\n return (\n <div className=\"flex flex-col gap-1 items-center justify-center p-1 w-fit\">\n <span className=\"text-xs text-gray-500 font-medium mb-1\">\n {hoveredCol + 1} x {hoveredRow + 1} Table\n </span>\n <div className=\"flex flex-col gap-1\">\n {Array.from({ length: 5 }).map((_, r) => (\n <div key={r} className=\"flex gap-1\">\n {Array.from({ length: 5 }).map((_, c) => (\n <div\n key={c}\n className={cls(\n \"w-5 h-5 border rounded-sm cursor-pointer transition-colors duration-75\",\n r <= hoveredRow && c <= hoveredCol\n ? \"bg-blue-100 border-blue-400 dark:bg-blue-900 dark:border-blue-500\"\n : \"bg-surface-card border-gray-200 dark:border-gray-700 hover:border-blue-300\"\n )}\n onMouseEnter={() => onHover(r, c)}\n onClick={() => onSelect(hoveredRow + 1, hoveredCol + 1)}\n />\n ))}\n </div>\n ))}\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgDA,IAAM,kBAAoC;CACtC;EACI,OAAO;EACP,aAAa;EACb,aAAa,CAAC,KAAK,WAAW;EAC9B,MAAM,oBAAC,UAAD,EAAU,MAAM,SAAS,MAAO,CAAA;EACtC,UAAU,MAAM,UAAU;GACtB,KAAK,SAAS,KAAK,MAAM,GAAG,YAAY,MAAM,MAAM,MAAM,EAAE,CAAC;GAC7D,aAAa,OAAO,MAAM,SAAS,CAAC,CAAC,KAAK,OAAO,KAAK,QAAQ;EAClE;CACJ;CACA;EACI,OAAO;EACP,aAAa;EACb,aAAa;GAAC;GAAQ;GAAQ;GAAQ;GAAS;EAAU;EACzD,MAAM,oBAAC,iBAAD,EAAiB,MAAM,SAAS,MAAO,CAAA;EAC7C,UAAU,MAAM,UAAU;GACtB,KAAK,SAAS,KAAK,MAAM,GAAG,YAAY,MAAM,MAAM,MAAM,EAAE,CAAC;GAC7D,WAAW,OAAO,MAAM,SAAS,CAAC,CAAC,KAAK,OAAO,KAAK,QAAQ;EAChE;CACJ;CACA;EACI,OAAO;EACP,aAAa;EACb,aAAa;GAAC;GAAS;GAAO;EAAO;EACrC,MAAM,oBAAC,cAAD,EAAc,MAAM,SAAS,MAAO,CAAA;EAC1C,UAAU,MAAM,UAAU;GACtB,KAAK,SAAS,KAAK,MAAM,GAAG,YAAY,MAAM,MAAM,MAAM,EAAE,CAAC;GAC7D,aAAa,OAAO,MAAM,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,QAAQ;EAC9E;CACJ;CACA;EACI,OAAO;EACP,aAAa;EACb,aAAa,CAAC,YAAY,QAAQ;EAClC,MAAM,oBAAC,cAA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;;AAEb"}
1
+ {"version":3,"file":"SlashCommandMenu.js","names":[],"sources":["../../../src/editor/components/SlashCommandMenu.tsx"],"sourcesContent":["\nimport React, { useEffect, useRef, useState, ReactNode } from \"react\";\nimport { Fragment, DOMParser } from \"prosemirror-model\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { autoUpdate, computePosition, flip, offset, shift, type VirtualElement } from \"@floating-ui/dom\";\nimport { SlashCommandPluginKey } from \"../plugins/slashCommandPlugin\";\nimport {\n CheckSquareIcon,\n cls,\n CodeIcon,\n defaultBorderMixin,\n Heading1Icon,\n Heading2Icon,\n Heading3Icon,\n iconSize,\n ImageIcon,\n ListIcon,\n ListOrderedIcon,\n QuoteIcon,\n TableIcon,\n TypeIcon,\n Wand2Icon\n} from \"@rebasepro/ui\";\nimport { setBlockType, wrapIn } from \"prosemirror-commands\";\nimport { wrapInList } from \"prosemirror-schema-list\";\nimport { schema } from \"../schema\";\nimport { EditorView } from \"prosemirror-view\";\nimport { TextSelection } from \"prosemirror-state\";\nimport type { EditorAIController } from \"../types\";\nimport { onFileRead, UploadFn } from \"../extensions/Image\";\nimport { textLoadingCommands } from \"../extensions/TextLoadingDecorationExtension\";\nimport { parser } from \"../markdown\";\nimport { parseSanitizedHtml } from \"../sanitize-html\";\n\ninterface SuggestionItem {\n title: string;\n description: string;\n icon: ReactNode;\n searchTerms?: string[];\n command: (\n view: EditorView,\n range: { from: number; to: number },\n upload: UploadFn,\n aiController?: EditorAIController,\n setSubView?: (viewId: string | null) => void\n ) => void;\n}\n\nconst suggestionItems: SuggestionItem[] = [\n {\n title: \"Text\",\n description: \"Just start typing with plain text.\",\n searchTerms: [\"p\", \"paragraph\"],\n icon: <TypeIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);\n }\n },\n {\n title: \"To-do List\",\n description: \"Track tasks with a to-do list.\",\n searchTerms: [\"todo\", \"task\", \"list\", \"check\", \"checkbox\"],\n icon: <CheckSquareIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.task_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 1\",\n description: \"Big section heading.\",\n searchTerms: [\"title\", \"big\", \"large\"],\n icon: <Heading1Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 1 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 2\",\n description: \"Medium section heading.\",\n searchTerms: [\"subtitle\", \"medium\"],\n icon: <Heading2Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 2 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Heading 3\",\n description: \"Small section heading.\",\n searchTerms: [\"subtitle\", \"small\"],\n icon: <Heading3Icon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.heading, { level: 3 })(view.state, view.dispatch);\n }\n },\n {\n title: \"Bullet List\",\n description: \"Create a simple bullet list.\",\n searchTerms: [\"unordered\", \"point\"],\n icon: <ListIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.bullet_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Numbered List\",\n description: \"Create a list with numbering.\",\n searchTerms: [\"ordered\"],\n icon: <ListOrderedIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapInList(schema.nodes.ordered_list)(view.state, view.dispatch);\n }\n },\n {\n title: \"Quote\",\n description: \"Capture a quote.\",\n searchTerms: [\"blockquote\"],\n icon: <QuoteIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n wrapIn(schema.nodes.blockquote)(view.state, view.dispatch);\n }\n },\n {\n title: \"Code\",\n description: \"Capture a code snippet.\",\n searchTerms: [\"codeblock\"],\n icon: <CodeIcon size={iconSize.small}/>,\n command: (view, range) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.code_block)(view.state, view.dispatch);\n }\n },\n {\n title: \"Image\",\n description: \"Upload an image from your computer.\",\n searchTerms: [\"photo\", \"picture\", \"media\", \"upload\", \"file\"],\n icon: <ImageIcon size={iconSize.small}/>,\n command: (view, range, upload) => {\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.accept = \"image/*\";\n input.onchange = async () => {\n if (input.files?.length) {\n const file = input.files[0];\n if (!file) return;\n const pos = view.state.selection.from;\n\n const images = Array.from(input.files).filter(f => /image/i.test(f.type));\n if (images.length === 0) return false;\n\n images.forEach(image => {\n const reader = new FileReader();\n reader.onload = async (readerEvent) => {\n await onFileRead(view, readerEvent, pos, upload, image);\n };\n reader.readAsDataURL(image);\n });\n }\n return true;\n };\n input.click();\n }\n },\n {\n title: \"Table\",\n description: \"Insert a custom grid table.\",\n searchTerms: [\"table\", \"grid\", \"row\", \"col\"],\n icon: <TableIcon size={iconSize.small}/>,\n command: (view, range, upload, aiController, setSubView) => {\n if (setSubView) setSubView(\"table-grid\");\n }\n }\n];\n\nconst autocompleteSuggestionItem: SuggestionItem = {\n title: \"Autocomplete\",\n description: \"Add text based on the context.\",\n searchTerms: [\"ai\"],\n icon: <Wand2Icon size={iconSize.small}/>,\n command: async (view, range, upload, aiController) => {\n if (!aiController) throw Error(\"No AiController\");\n\n view.dispatch(view.state.tr.deleteRange(range.from, range.to));\n setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);\n\n const { state } = view;\n const { from, to } = state.selection;\n\n const textBeforeCursor = state.doc.textBetween(0, from, \"\\n\");\n const textAfterCursor = state.doc.textBetween(to, state.doc.content.size, \"\\n\");\n\n let buffer = \"\";\n const result = await aiController.autocomplete(textBeforeCursor, textAfterCursor, (delta) => {\n buffer += delta;\n if (delta.length !== 0) {\n textLoadingCommands.toggleLoadingDecoration(view.state, view.dispatch, buffer);\n }\n });\n\n // Insert parsed text result at cursor natively\n try {\n // The AI controller might stream literal \"\\n\" characters depending on its JSON decoding layer.\n // We need to un-escape these back to genuine newlines so MarkdownIt block-parsing works.\n const unescapedResult = result.replace(/\\\\n/g, \"\\n\").replace(/\\\\t/g, \"\\t\");\n\n const isHTML = /<\\/?[a-z][\\s\\S]*>/i.test(unescapedResult);\n let parsedDoc;\n\n if (isHTML) {\n // Parsed inertly and reduced to the editor's own allowlist\n // before it touches the live document. `document.createElement`\n // plus `innerHTML` was the opposite: an element in this\n // document, so the content ran as it was assigned.\n //\n // ProseMirror's own parse drops nodes its schema does not know,\n // but that happens AFTER the browser has already executed\n // whatever it was handed — the schema is a shape filter, not a\n // security boundary.\n parsedDoc = DOMParser.fromSchema(view.state.schema).parse(parseSanitizedHtml(unescapedResult));\n } else {\n parsedDoc = parser.parse(unescapedResult);\n }\n\n if (parsedDoc) {\n const tr = view.state.tr.replaceWith(view.state.selection.from, view.state.selection.from, parsedDoc.content);\n view.dispatch(tr);\n } else {\n view.dispatch(view.state.tr.insertText(unescapedResult));\n }\n } catch (e) {\n console.error(e);\n view.dispatch(view.state.tr.insertText(result));\n }\n }\n};\n\nexport const SlashCommandMenu = ({ upload, aiController }: { upload: UploadFn, aiController?: EditorAIController }) => {\n const { view, state } = useProseMirrorContext();\n const menuRef = useRef<HTMLDivElement>(null);\n const [selectedIndex, setSelectedIndex] = useState(0);\n const [subView, setSubView] = useState<string | null>(null);\n const [tableGridCoords, setTableGridCoords] = useState({ r: 0,\nc: 0 });\n\n const pluginState = state ? SlashCommandPluginKey.getState(state) : null;\n const isActive = pluginState?.active;\n const query = pluginState?.query || \"\";\n const range = pluginState?.range;\n\n const filteredItems = React.useMemo(() => {\n if (!isActive) return [];\n const availableItems = [...suggestionItems];\n if (aiController) availableItems.push(autocompleteSuggestionItem);\n\n return availableItems.filter(item => {\n const inTitle = item.title.toLowerCase().includes(query.toLowerCase());\n if (inTitle) return inTitle;\n return item.searchTerms?.some(term => term.toLowerCase().includes(query.toLowerCase()));\n });\n }, [query, isActive, aiController]);\n\n useEffect(() => {\n setSelectedIndex(0);\n }, [query]);\n\n useEffect(() => {\n if (!isActive) setSubView(null);\n }, [isActive]);\n\n useEffect(() => {\n if (!view || !isActive || !range || !menuRef.current) return;\n\n const start = view.coordsAtPos(range.from);\n const virtualEl = {\n getBoundingClientRect() {\n return {\n width: 0,\n height: start.bottom - start.top,\n x: start.left,\n y: start.top,\n top: start.top,\n left: start.left,\n right: start.left,\n bottom: start.bottom\n };\n }\n };\n\n const cleanup = autoUpdate(virtualEl as VirtualElement, menuRef.current, () => {\n if (!menuRef.current) return;\n computePosition(virtualEl as VirtualElement, menuRef.current, {\n placement: \"bottom-start\",\n middleware: [offset(4), flip(), shift()],\n strategy: \"fixed\"\n }).then(({ x, y }) => {\n if (menuRef.current) {\n Object.assign(menuRef.current.style, {\n left: `${x}px`,\n top: `${y}px`,\n visibility: \"visible\"\n });\n }\n });\n });\n return () => cleanup();\n }, [view, isActive, range]);\n\n useEffect(() => {\n if (!isActive || !view) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (subView === \"table-grid\") {\n if (e.key === \"Escape\") {\n e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation();\n setSubView(null);\n setTableGridCoords({ r: 0,\nc: 0 });\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: Math.max(0, prev.r - 1),\nc: prev.c }));\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: Math.min(4, prev.r + 1),\nc: prev.c }));\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: prev.r,\nc: Math.max(0, prev.c - 1) }));\n } else if (e.key === \"ArrowRight\") {\n e.preventDefault(); e.stopPropagation();\n setTableGridCoords(prev => ({ r: prev.r,\nc: Math.min(4, prev.c + 1) }));\n } else if (e.key === \"Enter\") {\n e.preventDefault(); e.stopPropagation();\n if (range) {\n const tableNode = createTableNode(view.state.schema, tableGridCoords.r + 1, tableGridCoords.c + 1);\n const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);\n try {\n const selection = TextSelection.create(tr.doc, range.from + 4);\n tr.setSelection(selection);\n } catch (e) {\n console.warn(\"Could not select first cell\", e);\n }\n tr.setMeta(SlashCommandPluginKey, { active: false });\n view.dispatch(tr);\n view.focus();\n setSubView(null);\n setTableGridCoords({ r: 0,\nc: 0 });\n }\n }\n return;\n }\n\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex(prev => (prev + filteredItems.length - 1) % filteredItems.length);\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex(prev => (prev + 1) % filteredItems.length);\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n e.stopPropagation();\n if (filteredItems[selectedIndex] && range) {\n filteredItems[selectedIndex].command(view, range, upload, aiController, setSubView);\n // Do not focus view if a subview opened\n setTimeout(() => {\n // Focus is managed by the caller\n }, 0);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n e.stopImmediatePropagation();\n // Close menu gracefully and keep it dismissed\n view.dispatch(view.state.tr.setMeta(SlashCommandPluginKey, { active: false,\ndismissed: true }));\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown, { capture: true });\n return () => window.removeEventListener(\"keydown\", handleKeyDown, { capture: true });\n }, [isActive, selectedIndex, filteredItems, view, range, upload, aiController, subView, tableGridCoords]);\n\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n\n useEffect(() => {\n if (itemRefs.current[selectedIndex]) {\n itemRefs.current[selectedIndex]?.scrollIntoView({ block: \"nearest\" });\n }\n }, [selectedIndex]);\n\n useEffect(() => {\n if (!subView) {\n setTableGridCoords({ r: 0,\nc: 0 });\n }\n }, [subView]);\n\n if (!isActive || filteredItems.length === 0) return null;\n\n if (subView === \"table-grid\" && range && view) {\n return (\n <div\n ref={menuRef}\n onMouseDown={(e) => e.preventDefault()}\n style={{ position: \"fixed\",\nzIndex: 9999,\nvisibility: \"hidden\" }}\n className={cls(\"text-surface-900 dark:text-white rounded-md border bg-surface-card p-2 shadow transition-none\", defaultBorderMixin)}\n >\n <TableGridPicker\n hoveredRow={tableGridCoords.r}\n hoveredCol={tableGridCoords.c}\n onHover={(r, c) => setTableGridCoords({ r,\nc })}\n onSelect={(rows, cols) => {\n const tableNode = createTableNode(view.state.schema, rows, cols);\n const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);\n try {\n const selection = TextSelection.create(tr.doc, range.from + 4);\n tr.setSelection(selection);\n } catch (e) {\n console.warn(\"Could not select first cell\", e);\n }\n tr.setMeta(SlashCommandPluginKey, { active: false });\n view.dispatch(tr);\n view.focus();\n setSubView(null);\n }}\n />\n </div>\n );\n }\n\n return (\n <div\n ref={menuRef}\n style={{ position: \"fixed\",\nzIndex: 9999,\nvisibility: \"hidden\" }}\n className={cls(\"text-surface-900 dark:text-white max-h-[280px] w-72 overflow-y-auto rounded-md border bg-surface-card px-1 py-2 shadow transition-none\", defaultBorderMixin)}\n >\n {filteredItems.map((item, index) => (\n <button\n key={item.title}\n ref={el => { itemRefs.current[index] = el; }}\n onClick={(e) => {\n e.preventDefault();\n if (range && view) {\n item.command(view, range, upload, aiController, setSubView);\n // Only focus back to editor if it didn't open a sub-view\n if (!subView) view.focus();\n }\n }}\n onMouseDown={(e) => e.preventDefault()}\n className={cls(\"flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-surface-hover\",\n index === selectedIndex ? \"bg-surface-active\" : \"\")}\n >\n <div className={cls(\"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border bg-surface-card\", defaultBorderMixin)}>\n {item.icon}\n </div>\n <div className=\"flex flex-col overflow-hidden\">\n <p className=\"font-medium truncate\">{item.title}</p>\n <p className=\"text-xs text-surface-700 dark:text-surface-accent-300 truncate\">\n {item.description}\n </p>\n </div>\n </button>\n ))}\n </div>\n );\n};\n\nconst createTableNode = (schema: import(\"prosemirror-model\").Schema, rowsCount: number, colsCount: number) => {\n const rows = [];\n for (let r = 0; r < rowsCount; r++) {\n const cells = [];\n for (let c = 0; c < colsCount; c++) {\n const isHeader = r === 0;\n const cellType = isHeader ? schema.nodes.table_header : schema.nodes.table_cell;\n const cell = cellType.createAndFill();\n if (cell) cells.push(cell);\n }\n const row = schema.nodes.table_row.create(null, Fragment.from(cells));\n rows.push(row);\n }\n return schema.nodes.table.create(null, Fragment.from(rows));\n};\n\nconst TableGridPicker = ({\n hoveredRow,\n hoveredCol,\n onHover,\n onSelect\n}: {\n hoveredRow: number;\n hoveredCol: number;\n onHover: (r: number, c: number) => void;\n onSelect: (r: number, c: number) => void;\n}) => {\n return (\n <div className=\"flex flex-col gap-1 items-center justify-center p-1 w-fit\">\n <span className=\"text-xs text-gray-500 font-medium mb-1\">\n {hoveredCol + 1} x {hoveredRow + 1} Table\n </span>\n <div className=\"flex flex-col gap-1\">\n {Array.from({ length: 5 }).map((_, r) => (\n <div key={r} className=\"flex gap-1\">\n {Array.from({ length: 5 }).map((_, c) => (\n <div\n key={c}\n className={cls(\n \"w-5 h-5 border rounded-sm cursor-pointer transition-colors duration-75\",\n r <= hoveredRow && c <= hoveredCol\n ? \"bg-primary-bg border-primary\"\n : \"bg-surface-card border-gray-200 dark:border-gray-700 hover:border-primary/50\"\n )}\n onMouseEnter={() => onHover(r, c)}\n onClick={() => onSelect(hoveredRow + 1, hoveredCol + 1)}\n />\n ))}\n </div>\n ))}\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgDA,IAAM,kBAAo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M,OAAO,CAAC;CACd,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAChC,MAAM,QAAQ,CAAC;EACf,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;GAGhC,MAAM,QAFW,MAAM,IACK,OAAO,MAAM,eAAe,OAAO,MAAM,WAAA,CAC/C,cAAc;GACpC,IAAI,MAAM,MAAM,KAAK,IAAI;EAC7B;EACA,MAAM,MAAM,OAAO,MAAM,UAAU,OAAO,MAAM,WAAS,KAAK,KAAK,CAAC;EACpE,KAAK,KAAK,GAAG;CACjB;CACA,OAAO,OAAO,MAAM,MAAM,OAAO,MAAM,WAAS,KAAK,IAAI,CAAC;AAC9D;AAEA,IAAM,mBAAmB,EACrB,YACA,YACA,SACA,eAME;CACF,OACI,qBAAC,OAAD;EAAK,WAAU;YAAf,CACI,qBAAC,QAAD;GAAM,WAAU;aAAhB;IACK,aAAa;IAAE;IAAI,aAAa;IAAE;GACjC;MACN,oBAAC,OAAD;GAAK,WAAU;aACV,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,MAC/B,oBAAC,OAAD;IAAa,WAAU;cAClB,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,MAC/B,oBAAC,OAAD;KAEI,WAAW,IACP,0EACA,KAAK,cAAc,KAAK,aAClB,iCACA,8EACV;KACA,oBAAoB,QAAQ,GAAG,CAAC;KAChC,eAAe,SAAS,aAAa,GAAG,aAAa,CAAC;IACzD,GATQ,CASR,CACJ;GACA,GAdK,CAcL,CACR;EACA,CAAA,CACJ;;AAEb"}
@@ -66,7 +66,7 @@ var LinkSelector = ({ open, onOpenChange }) => {
66
66
  className: "gap-2 rounded-none",
67
67
  color: "text",
68
68
  children: /* @__PURE__ */ jsx("p", {
69
- className: cls("underline decoration-stone-400 underline-offset-4", { "text-blue-500": isMarkActive(state, schema.marks.link) }),
69
+ className: cls("underline decoration-stone-400 underline-offset-4", { "text-primary": isMarkActive(state, schema.marks.link) }),
70
70
  children: t("editor_link")
71
71
  })
72
72
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"link-selector.js","names":[],"sources":["../../../src/editor/selectors/link-selector.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Button, CheckIcon, cls, focusedDisabled, iconSize, Popover, TextField, Trash2Icon, Typography } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { getMarkAttributes, isMarkActive, setMark, unsetMark } from \"../utils/prosemirror-utils\";\nimport { schema } from \"../schema\";\n\nexport function isValidUrl(url: string) {\n try {\n new URL(url);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport function getUrlFromString(str: string) {\n if (isValidUrl(str)) return str;\n try {\n if (str.includes(\".\") && !str.includes(\" \")) {\n return new URL(`https://${str}`).toString();\n }\n return null;\n } catch (e) {\n return null;\n }\n}\n\ninterface LinkSelectorProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n}\n\nexport const LinkSelector = ({\n open,\n onOpenChange\n}: LinkSelectorProps) => {\n const inputRef = useRef<HTMLInputElement>(null);\n const { state, view } = useProseMirrorContext();\n const { t } = useTranslation();\n\n const [error, setError] = useState<string | null>(null);\n // `TextField` is controlled: a `defaultValue` alone left the box reset to\n // empty on every keystroke, so no link could be typed into it.\n const [value, setValue] = useState(\"\");\n\n const href = state ? (getMarkAttributes(state, schema.marks.link).href || \"\") : \"\";\n\n // Opening the box shows the selection's link, with no error, and focuses it\n useEffect(() => {\n if (!open) return;\n setError(null);\n setValue(href);\n inputRef.current?.focus();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- seeded once per opening; the selection's link is read at that moment\n }, [open]);\n\n if (!state || !view) return null;\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n // The popover renders in a portal, but React still sends its events up\n // the component tree: without this the record form around the editor\n // receives the submit and saves.\n e.stopPropagation();\n if (!value) return;\n const url = getUrlFromString(value);\n if (!url) {\n setError(t(\"editor_invalid_url\"));\n return;\n }\n setError(null);\n setMark(schema.marks.link, { href: url })(view.state, view.dispatch);\n view.focus();\n onOpenChange(false);\n };\n\n const handleRemoveLink = () => {\n unsetMark(schema.marks.link)(view.state, view.dispatch);\n view.focus();\n onOpenChange(false);\n };\n\n const isActive = isMarkActive(state, schema.marks.link);\n\n return (\n <Popover modal={true}\n open={open}\n onOpenChange={onOpenChange}\n trigger={<Button variant=\"text\"\n type=\"button\"\n className=\"gap-2 rounded-none\"\n color={\"text\"}>\n <p className={cls(\"underline decoration-stone-400 underline-offset-4\", {\n \"text-blue-500\": isActive\n })}>\n {t(\"editor_link\")}\n </p>\n </Button>}>\n <form\n onSubmit={handleSubmit}\n className=\"flex flex-col p-1 gap-1\"\n >\n <div className=\"flex gap-1\">\n <TextField\n inputRef={inputRef}\n autoFocus={open}\n aria-label={t(\"editor_paste_or_type_link\")}\n placeholder={t(\"editor_paste_or_type_link\")}\n value={value}\n onChange={(e) => {\n setValue(e.target.value);\n if (error) setError(null);\n }}\n error={!!error}\n size=\"small\"\n className=\"flex-grow text-surface-900 dark:text-white\"\n inputClassName={cls(\"bg-transparent p-1 text-sm outline-none\", focusedDisabled)}\n />\n\n {href ? (\n <Button\n size={\"small\"}\n variant=\"text\"\n type=\"button\"\n color={\"text\"}\n className=\"flex items-center\"\n onClick={handleRemoveLink}\n >\n <Trash2Icon size={iconSize.small}/>\n </Button>\n ) : (\n <Button size={\"small\"}\n type=\"submit\"\n variant={\"text\"}>\n <CheckIcon size={iconSize.small}/>\n </Button>\n )}\n </div>\n {error && (\n <Typography variant=\"caption\" color=\"error\" className=\"px-1\">\n {error}\n </Typography>\n )}\n </form>\n </Popover>\n );\n};\n"],"mappings":";;;;;;;;AAOA,SAAgB,WAAW,KAAa;CACpC,IAAI;EACA,IAAI,IAAI,GAAG;EACX,OAAO;CACX,SAAS,GAAG;EACR,OAAO;CAC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,OAAO;EACN;EACQ;EACd,SAAS,oBAAC,QAAD;GAAQ,SAAQ;GACrB,MAAK;GACL,WAAU;GACV,OAAO;aACP,oBAAC,KAAD;IAAG,WAAW,IAAI,qDAAqD,EACnE,iBAXC,aAAa,OAAO,OAAO,MAAM,IAWjB,EACrB,CAAC;cACI,EAAE,aAAa;GACjB,CAAA;EACC,CAAA;YACR,qBAAC,QAAD;GACI,UAAU;GACV,WAAU;aAFd,CAII,qBAAC,OAAD;IAAK,WAAU;cAAf,CACA,oBAAC,WAAD;KACc;KACV,WAAW;KACX,cAAY,EAAE,2BAA2B;KACzC,aAAa,EAAE,2BAA2B;KACnC;KACP,WAAW,MAAM;MACb,SAAS,EAAE,OAAO,KAAK;MACvB,IAAI,OAAO,SAAS,IAAI;KAC5B;KACA,OAAO,CAAC,CAAC;KACT,MAAK;KACL,WAAU;KACV,gBAAgB,IAAI,2CAA2C,eAAe;IACjF,CAAA,GAEA,OACG,oBAAC,QAAD;KACI,MAAM;KACN,SAAQ;KACR,MAAK;KACL,OAAO;KACP,WAAU;KACV,SAAS;eAET,oBAAC,YAAD,EAAY,MAAM,SAAS,MAAO,CAAA;IAC9B,CAAA,IAER,oBAAC,QAAD;KAAQ,MAAM;KACV,MAAK;KACL,SAAS;eACT,oBAAC,WAAD,EAAW,MAAM,SAAS,MAAO,CAAA;IAC7B,CAAA,CAEP;OACJ,SACG,oBAAC,YAAD;IAAY,SAAQ;IAAU,OAAM;IAAQ,WAAU;cACjD;GACO,CAAA,CAEd;;CACD,CAAA;AAEjB"}
1
+ {"version":3,"file":"link-selector.js","names":[],"sources":["../../../src/editor/selectors/link-selector.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Button, CheckIcon, cls, focusedDisabled, iconSize, Popover, TextField, Trash2Icon, Typography } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { getMarkAttributes, isMarkActive, setMark, unsetMark } from \"../utils/prosemirror-utils\";\nimport { schema } from \"../schema\";\n\nexport function isValidUrl(url: string) {\n try {\n new URL(url);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport function getUrlFromString(str: string) {\n if (isValidUrl(str)) return str;\n try {\n if (str.includes(\".\") && !str.includes(\" \")) {\n return new URL(`https://${str}`).toString();\n }\n return null;\n } catch (e) {\n return null;\n }\n}\n\ninterface LinkSelectorProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n}\n\nexport const LinkSelector = ({\n open,\n onOpenChange\n}: LinkSelectorProps) => {\n const inputRef = useRef<HTMLInputElement>(null);\n const { state, view } = useProseMirrorContext();\n const { t } = useTranslation();\n\n const [error, setError] = useState<string | null>(null);\n // `TextField` is controlled: a `defaultValue` alone left the box reset to\n // empty on every keystroke, so no link could be typed into it.\n const [value, setValue] = useState(\"\");\n\n const href = state ? (getMarkAttributes(state, schema.marks.link).href || \"\") : \"\";\n\n // Opening the box shows the selection's link, with no error, and focuses it\n useEffect(() => {\n if (!open) return;\n setError(null);\n setValue(href);\n inputRef.current?.focus();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- seeded once per opening; the selection's link is read at that moment\n }, [open]);\n\n if (!state || !view) return null;\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n // The popover renders in a portal, but React still sends its events up\n // the component tree: without this the record form around the editor\n // receives the submit and saves.\n e.stopPropagation();\n if (!value) return;\n const url = getUrlFromString(value);\n if (!url) {\n setError(t(\"editor_invalid_url\"));\n return;\n }\n setError(null);\n setMark(schema.marks.link, { href: url })(view.state, view.dispatch);\n view.focus();\n onOpenChange(false);\n };\n\n const handleRemoveLink = () => {\n unsetMark(schema.marks.link)(view.state, view.dispatch);\n view.focus();\n onOpenChange(false);\n };\n\n const isActive = isMarkActive(state, schema.marks.link);\n\n return (\n <Popover modal={true}\n open={open}\n onOpenChange={onOpenChange}\n trigger={<Button variant=\"text\"\n type=\"button\"\n className=\"gap-2 rounded-none\"\n color={\"text\"}>\n <p className={cls(\"underline decoration-stone-400 underline-offset-4\", {\n \"text-primary\": isActive\n })}>\n {t(\"editor_link\")}\n </p>\n </Button>}>\n <form\n onSubmit={handleSubmit}\n className=\"flex flex-col p-1 gap-1\"\n >\n <div className=\"flex gap-1\">\n <TextField\n inputRef={inputRef}\n autoFocus={open}\n aria-label={t(\"editor_paste_or_type_link\")}\n placeholder={t(\"editor_paste_or_type_link\")}\n value={value}\n onChange={(e) => {\n setValue(e.target.value);\n if (error) setError(null);\n }}\n error={!!error}\n size=\"small\"\n className=\"flex-grow text-surface-900 dark:text-white\"\n inputClassName={cls(\"bg-transparent p-1 text-sm outline-none\", focusedDisabled)}\n />\n\n {href ? (\n <Button\n size={\"small\"}\n variant=\"text\"\n type=\"button\"\n color={\"text\"}\n className=\"flex items-center\"\n onClick={handleRemoveLink}\n >\n <Trash2Icon size={iconSize.small}/>\n </Button>\n ) : (\n <Button size={\"small\"}\n type=\"submit\"\n variant={\"text\"}>\n <CheckIcon size={iconSize.small}/>\n </Button>\n )}\n </div>\n {error && (\n <Typography variant=\"caption\" color=\"error\" className=\"px-1\">\n {error}\n </Typography>\n )}\n </form>\n </Popover>\n );\n};\n"],"mappings":";;;;;;;;AAOA,SAAgB,WAAW,KAAa;CACpC,IAAI;EACA,IAAI,IAAI,GAAG;EACX,OAAO;CACX,SAAS,GAAG;EACR,OAAO;CACX;AACJ;AAEA,SAAgB,iBAAiB,KAAa;CAC1C,IAAI,WAAW,GAAG,GAAG,OAAO;CAC5B,IAAI;EACA,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,GAAG,GACtC,OAAO,IAAI,IAAI,WAAW,KAAK,CAAC,CAAC,SAAS;EAE9C,OAAO;CACX,SAAS,GAAG;EACR,OAAO;CACX;AACJ;AAOA,IAAa,gBAAgB,EACzB,MACA,mBACqB;CACrB,MAAM,WAAW,OAAyB,IAAI;CAC9C,MAAM,EAAE,OAAO,SAAS,sBAAsB;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E,2BAA2B;KACzC,aAAa,EAAE,2BAA2B;KACnC;KACP,WAAW,MAAM;MACb,SAAS,EAAE,OAAO,KAAK;MACvB,IAAI,OAAO,SAAS,IAAI;KAC5B;KACA,OAAO,CAAC,CAAC;KACT,MAAK;KACL,WAAU;KACV,gBAAgB,IAAI,2CAA2C,eAAe;IACjF,CAAA,GAEA,OACG,oBAAC,QAAD;KACI,MAAM;KACN,SAAQ;KACR,MAAK;KACL,OAAO;KACP,WAAU;KACV,SAAS;eAET,oBAAC,YAAD,EAAY,MAAM,SAAS,MAAO,CAAA;IAC9B,CAAA,IAER,oBAAC,QAAD;KAAQ,MAAM;KACV,MAAK;KACL,SAAS;eACT,oBAAC,WAAD,EAAW,MAAM,SAAS,MAAO,CAAA;IAC7B,CAAA,CAEP;OACJ,SACG,oBAAC,YAAD;IAAY,SAAQ;IAAU,OAAM;IAAQ,WAAU;cACjD;GACO,CAAA,CAEd;;CACD,CAAA;AAEjB"}
@@ -59,7 +59,7 @@ var TextButtons = () => {
59
59
  variant: "text",
60
60
  children: /* @__PURE__ */ jsx(item.icon, { className: cls({
61
61
  "text-inherit": !item.isActive(state),
62
- "text-blue-500": item.isActive(state)
62
+ "text-primary": item.isActive(state)
63
63
  }) })
64
64
  })
65
65
  }, index))
@@ -1 +1 @@
1
- {"version":3,"file":"text-buttons.js","names":[],"sources":["../../../src/editor/selectors/text-buttons.tsx"],"sourcesContent":["\nimport { EditorState, Transaction } from \"prosemirror-state\";\nimport { EditorBubbleItem } from \"../components/editor-bubble-item\";\nimport type { SelectorItem } from \"./node-selector\";\nimport { BoldIcon, Button, cls, CodeIcon, ItalicIcon, StrikethroughIcon, UnderlineIcon } from \"@rebasepro/ui\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { isMarkActive } from \"../utils/prosemirror-utils\";\nimport { schema } from \"../schema\";\nimport { toggleMark } from \"prosemirror-commands\";\n\nexport const TextButtons = () => {\n const { state, view } = useProseMirrorContext();\n if (!state || !view) return null;\n\n // We pass state directly to isActive, and dispatch to command\n const items = [\n {\n name: \"bold\",\n labelKey: \"editor_bold\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.bold),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.bold)(s, dispatch),\n icon: BoldIcon\n },\n {\n name: \"italic\",\n labelKey: \"editor_italic\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.italic),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.italic)(s, dispatch),\n icon: ItalicIcon\n },\n {\n name: \"underline\",\n labelKey: \"editor_underline\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.underline),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.underline)(s, dispatch),\n icon: UnderlineIcon\n },\n {\n name: \"strike\",\n labelKey: \"editor_strikethrough\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.strike),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.strike)(s, dispatch),\n icon: StrikethroughIcon\n },\n {\n name: \"code\",\n labelKey: \"editor_code\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.code),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.code)(s, dispatch),\n icon: CodeIcon\n }\n ];\n\n return (\n <div className=\"flex\">\n {items.map((item, index) => (\n <EditorBubbleItem\n key={index}\n onSelect={() => {\n item.command(view.state, view.dispatch);\n view.focus();\n }}\n >\n <Button size={\"small\"}\n color=\"text\"\n className=\"gap-2 rounded-none h-full\"\n variant=\"text\">\n <item.icon\n className={cls({\n \"text-inherit\": !item.isActive(state),\n \"text-blue-500\": item.isActive(state)\n })}\n />\n </Button>\n </EditorBubbleItem>\n ))}\n </div>\n );\n};\n"],"mappings":";;;;;;;;AAUA,IAAa,oBAAoB;CAC7B,MAAM,EAAE,OAAO,SAAS,sBAAsB;CAC9C,IAAI,CAAC,SAAS,CAAC,MAAM,O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AAA;EACM,GAjBT,KAiBS,CACrB;CACA,CAAA;AAEb"}
1
+ {"version":3,"file":"text-buttons.js","names":[],"sources":["../../../src/editor/selectors/text-buttons.tsx"],"sourcesContent":["\nimport { EditorState, Transaction } from \"prosemirror-state\";\nimport { EditorBubbleItem } from \"../components/editor-bubble-item\";\nimport type { SelectorItem } from \"./node-selector\";\nimport { BoldIcon, Button, cls, CodeIcon, ItalicIcon, StrikethroughIcon, UnderlineIcon } from \"@rebasepro/ui\";\nimport { useProseMirrorContext } from \"../hooks/useProseMirrorContext\";\nimport { isMarkActive } from \"../utils/prosemirror-utils\";\nimport { schema } from \"../schema\";\nimport { toggleMark } from \"prosemirror-commands\";\n\nexport const TextButtons = () => {\n const { state, view } = useProseMirrorContext();\n if (!state || !view) return null;\n\n // We pass state directly to isActive, and dispatch to command\n const items = [\n {\n name: \"bold\",\n labelKey: \"editor_bold\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.bold),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.bold)(s, dispatch),\n icon: BoldIcon\n },\n {\n name: \"italic\",\n labelKey: \"editor_italic\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.italic),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.italic)(s, dispatch),\n icon: ItalicIcon\n },\n {\n name: \"underline\",\n labelKey: \"editor_underline\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.underline),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.underline)(s, dispatch),\n icon: UnderlineIcon\n },\n {\n name: \"strike\",\n labelKey: \"editor_strikethrough\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.strike),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.strike)(s, dispatch),\n icon: StrikethroughIcon\n },\n {\n name: \"code\",\n labelKey: \"editor_code\",\n isActive: (s: EditorState) => isMarkActive(s, schema.marks.code),\n command: (s: EditorState, dispatch: (tr: Transaction) => void) => toggleMark(schema.marks.code)(s, dispatch),\n icon: CodeIcon\n }\n ];\n\n return (\n <div className=\"flex\">\n {items.map((item, index) => (\n <EditorBubbleItem\n key={index}\n onSelect={() => {\n item.command(view.state, view.dispatch);\n view.focus();\n }}\n >\n <Button size={\"small\"}\n color=\"text\"\n className=\"gap-2 rounded-none h-full\"\n variant=\"text\">\n <item.icon\n className={cls({\n \"text-inherit\": !item.isActive(state),\n \"text-primary\": item.isActive(state)\n })}\n />\n </Button>\n </EditorBubbleItem>\n ))}\n </div>\n );\n};\n"],"mappings":";;;;;;;;AAUA,IAAa,oBAAoB;CAC7B,MAAM,EAAE,OAAO,SAAS,sBAAsB;CAC9C,IAAI,CAAC,SAAS,CAAC,MAAM,OAAO;CAyC5B,OACI,oBAAC,OAAD;EAAK,WAAU;YACV;GAvCL;IACI,MAAM;IACN,UAAU;IACV,WAAW,MAAmB,aAAa,GAAG,OAAO,MAAM,IAAI;IAC/D,UAAU,GAAgB,aAAwC,WAAW,OAAO,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ;IAC3G,MAAM;GACV;GACA;IACI,MAAM;IACN,UAAU;IACV,WAAW,MAAmB,aAAa,GAAG,OAAO,MAAM,MAAM;IACjE,UAAU,GAAgB,aAAwC,WAAW,OAAO,MAAM,MAAM,CAAC,CAAC,GAAG,QAAQ;IAC7G,MAAM;GACV;GACA;IACI,MAAM;IACN,UAAU;IACV,WAAW,MAAmB,aAAa,GAAG,OAAO,MAAM,SAAS;IACpE,UAAU,GAAgB,aAAwC,WAAW,OAAO,MAAM,SAAS,CAAC,CAAC,GAAG,QAAQ;IAChH,MAAM;GACV;GACA;IACI,MAAM;IACN,UAAU;IACV,WAAW,MAAmB,aAAa,GAAG,OAAO,MAAM,MAAM;IACjE,UAAU,GAAgB,aAAwC,WAAW,OAAO,MAAM,MAAM,CAAC,CAAC,GAAG,QAAQ;IAC7G,MAAM;GACV;GACA;IACI,MAAM;IACN,UAAU;IACV,WAAW,MAAmB,aAAa,GAAG,OAAO,MAAM,IAAI;IAC/D,UAAU,GAAgB,aAAwC,WAAW,OAAO,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ;IAC3G,MAAM;GACV;EAKK,CAAA,CAAM,KAAK,MAAM,UACd,oBAAC,kBAAD;GAEI,gBAAgB;IACZ,KAAK,QAAQ,KAAK,OAAO,KAAK,QAAQ;IACtC,KAAK,MAAM;GACf;aAEA,oBAAC,QAAD;IAAQ,MAAM;IACV,OAAM;IACN,WAAU;IACV,SAAQ;cACR,oBAAC,KAAK,MAAN,EACI,WAAW,IAAI;KACX,gBAAgB,CAAC,KAAK,SAAS,KAAK;KACpC,gBAAgB,KAAK,SAAS,KAAK;IACvC,CAAC,EACJ,CAAA;GACG,CAAA;EACM,GAjBT,KAiBS,CACrB;CACA,CAAA;AAEb"}
@@ -99,7 +99,7 @@ function VectorFieldBinding({ propertyKey, value, setValue, error, showError, di
99
99
  ]
100
100
  })]
101
101
  }), showValues && isPopulated && /* @__PURE__ */ jsx("div", {
102
- className: "mt-1 p-3 rounded-lg bg-surface-well border border-hairline max-h-36 overflow-y-auto font-mono text-[11px] leading-relaxed text-text-secondary dark:text-text-secondary-dark break-all selection:bg-primary/20",
102
+ className: "mt-1 p-3 rounded-lg bg-surface-well border border-hairline max-h-36 overflow-y-auto font-mono text-xs leading-relaxed text-text-secondary dark:text-text-secondary-dark break-all selection:bg-primary/20",
103
103
  children: arrayValue.join(", ")
104
104
  })]
105
105
  }) : /* @__PURE__ */ jsxs("div", {
@@ -1 +1 @@
1
- {"version":3,"file":"VectorFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/VectorFieldBinding.tsx"],"sourcesContent":["import { useTranslation } from \"@rebasepro/app\";\nimport type { FieldProps } from \"../../types/fields\";\nimport type { VectorProperty } from \"@rebasepro/cms-types\";\nimport React, { useState, useEffect, useCallback } from \"react\";\nimport {\n Button,\n CheckIcon,\n cls,\n defaultBorderMixin,\n EyeIcon,\n EyeOffIcon,\n IconButton,\n PencilIcon,\n TextField,\n Trash2Icon\n} from \"@rebasepro/ui\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/**\n * Custom field binding to render vector fields (e.g. for high-dimensional embeddings).\n * Shows a compact metadata card by default, and lets users expand values or edit them.\n *\n * Automatically parses inputs to number arrays and packages them into the canonical\n * Vector object structure expected by Rebase driver.\n * @group Form fields\n */\nexport function VectorFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<VectorProperty>) {\n const { t } = useTranslation();\n const isVectorObject = (val: unknown): val is { value: number[] } => {\n return typeof val === \"object\" && val !== null && \"value\" in val;\n };\n\n // Extract array value from the custom { __type: \"Vector\", value: number[] } wrapper\n const arrayValue = isVectorObject(value)\n ? value.value\n : (Array.isArray(value) ? value : []);\n\n const [textValue, setTextValue] = useState(() => arrayValue.join(\", \"));\n const [isEditing, setIsEditing] = useState(false);\n const [showValues, setShowValues] = useState(false);\n\n useEffect(() => {\n setTextValue(arrayValue.join(\", \"));\n }, [JSON.stringify(arrayValue)]);\n\n const handleClearClick = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setValue(null);\n setTextValue(\"\");\n }, [setValue]);\n\n const onChange = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const raw = event.target.value;\n setTextValue(raw);\n\n // Parse comma-separated string to number array\n const numbers = raw\n .split(\",\")\n .map(str => str.trim())\n .filter(str => str !== \"\")\n .map(Number);\n\n setValue({\n __type: \"Vector\",\n value: numbers\n });\n };\n\n const label = hideLabel ? null : (\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n );\n\n const isPopulated = arrayValue.length > 0;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Only when there is a label to put in it — an empty row still\n spends its `mb-1` and the column's `gap-2`, and the control ends\n up below the one beside it under a label at the same height. */}\n {label && <div className=\"flex items-center justify-between mb-1\">\n {label}\n </div>}\n\n <div className=\"w-full\">\n {!isEditing ? (\n /* Compact Preview Card */\n <div className={cls(\"flex flex-col gap-3 p-4 rounded-xl border bg-surface-field transition-all duration-200\", defaultBorderMixin)}>\n <div className=\"flex items-center justify-between flex-wrap gap-2\">\n <div className=\"flex items-center gap-2.5\">\n {/* Status Dot */}\n <div className={`w-2.5 h-2.5 rounded-full ${isPopulated ? \"bg-emerald-500 animate-pulse\" : \"bg-surface-300 dark:bg-surface-600\"}`} />\n <span className=\"text-sm font-semibold text-text-primary dark:text-text-primary-dark\">\n {isPopulated ? `${arrayValue.length} Dimensions` : \"Empty Vector\"}\n </span>\n {isPopulated && (\n <span className=\"text-xs text-text-secondary dark:text-text-secondary-dark px-2 py-0.5 rounded-full bg-surface-raised font-medium\">\n Embedding\n </span>\n )}\n </div>\n\n <div className=\"flex items-center gap-2\">\n {isPopulated && (\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setShowValues(!showValues)}\n startIcon={showValues ? <EyeOffIcon size={14} /> : <EyeIcon size={14} />}\n >\n {showValues ? \"Hide values\" : \"Show values\"}\n </Button>\n )}\n {!disabled && (\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(true)}\n startIcon={<PencilIcon size={14} />}\n >\n {isPopulated ? \"Edit values\" : \"Add values\"}\n </Button>\n )}\n {isPopulated && !disabled && (\n <IconButton aria-label={t(\"clear\")} size=\"small\" onClick={handleClearClick} className=\"text-text-secondary hover:text-red-500\">\n <Trash2Icon size={14} />\n </IconButton>\n )}\n </div>\n </div>\n\n {/* Collapsible scrollable numbers list */}\n {showValues && isPopulated && (\n <div className=\"mt-1 p-3 rounded-lg bg-surface-well border border-hairline max-h-36 overflow-y-auto font-mono text-[11px] leading-relaxed text-text-secondary dark:text-text-secondary-dark break-all selection:bg-primary/20\">\n {arrayValue.join(\", \")}\n </div>\n )}\n </div>\n ) : (\n /* Editing View: Text Input */\n <div className={cls(\"flex flex-col gap-2 p-4 rounded-xl border bg-surface-field\", defaultBorderMixin)}>\n <TextField\n size={size}\n aria-label={`${property.name ?? propertyKey} vector values`}\n value={textValue}\n onChange={onChange}\n autoFocus={true}\n placeholder={`e.g., 0.15, -0.42, 0.88 (Requires ${property.dimensions} dimensions)`}\n disabled={disabled}\n error={showError ? !!error : undefined}\n inputClassName={error ? \"text-red-500 dark:text-red-600 font-mono text-xs\" : \"font-mono text-xs\"}\n />\n <div className=\"flex justify-end gap-2 mt-2\">\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n >\n Cancel\n </Button>\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n startIcon={<CheckIcon size={14} />}\n >\n Done\n </Button>\n </div>\n </div>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,mBAAmB,EAC/B,aACA,OACA,UACA,OACA,WACA,UACA,WACA,UACA,oBACA,WACA,OAAO,WACoB;CAC3B,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,kBAAkB,QAA6C;EACjE,OAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,WAAW;CACjE;CAGA,MAAM,aAAa,eAAe,KAAK,IACjC,MAAM,QACL,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC;CAEvC,MAAM,CAAC,WAAW,gBAAgB,eAAe,WAAW,KAAK,IAAI,CAAC;CACtE,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAElD,gBAAgB;EACZ,aAAa,WAAW,KAAK,IAAI,CAAC;CACtC,GAAG,CAAC,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AA,IAAI,oBAAC,SAAD,EAAS,MAAM,GAAK,CAAA;mBAEtE,aAAa,gBAAgB;QAC1B,CAAA;QAEX,CAAC,YACE,oBAAC,QAAD;SACI,SAAQ;SACR,MAAK;SACL,eAAe,aAAa,IAAI;SAChC,WAAW,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA;mBAEjC,cAAc,gBAAgB;QAC3B,CAAA;QAEX,eAAe,CAAC,YACb,oBAAC,YAAD;SAAY,cAAY,EAAE,OAAO;SAAG,MAAK;SAAQ,SAAS;SAAkB,WAAU;mBAClF,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA;QACf,CAAA;OAEf;QACJ;SAGJ,cAAc,eACX,oBAAC,OAAD;MAAK,WAAU;gBACV,WAAW,KAAK,IAAI;KACpB,CAAA,CAER;SAGL,qBAAC,OAAD;KAAK,WAAW,IAAI,8DAA8D,kBAAkB;eAApG,CACI,oBAAC,WAAD;MACU;MACN,cAAY,GAAG,SAAS,QAAQ,YAAY;MAC5C,OAAO;MACG;MACV,WAAW;MACX,aAAa,qCAAqC,SAAS,WAAW;MAC5D;MACV,OAAO,YAAY,CAAC,CAAC,QAAQ,KAAA;MAC7B,gBAAgB,QAAQ,qDAAqD;KAChF,CAAA,GACD,qBAAC,OAAD;MAAK,WAAU;gBAAf,CACI,oBAAC,QAAD;OACI,SAAQ;OACR,MAAK;OACL,eAAe,aAAa,KAAK;iBACpC;MAEO,CAAA,GACR,oBAAC,QAAD;OACI,SAAQ;OACR,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,WAAW,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;iBACpC;MAEO,CAAA,CACP;OACJ;;GAER,CAAA;GAEL,oBAAC,iBAAD;IACwB;IACT;IACJ;IACG;IACA;GACb,CAAA;EACA;;AAEb"}
1
+ {"version":3,"file":"VectorFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/VectorFieldBinding.tsx"],"sourcesContent":["import { useTranslation } from \"@rebasepro/app\";\nimport type { FieldProps } from \"../../types/fields\";\nimport type { VectorProperty } from \"@rebasepro/cms-types\";\nimport React, { useState, useEffect, useCallback } from \"react\";\nimport {\n Button,\n CheckIcon,\n cls,\n defaultBorderMixin,\n EyeIcon,\n EyeOffIcon,\n IconButton,\n PencilIcon,\n TextField,\n Trash2Icon\n} from \"@rebasepro/ui\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/**\n * Custom field binding to render vector fields (e.g. for high-dimensional embeddings).\n * Shows a compact metadata card by default, and lets users expand values or edit them.\n *\n * Automatically parses inputs to number arrays and packages them into the canonical\n * Vector object structure expected by Rebase driver.\n * @group Form fields\n */\nexport function VectorFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<VectorProperty>) {\n const { t } = useTranslation();\n const isVectorObject = (val: unknown): val is { value: number[] } => {\n return typeof val === \"object\" && val !== null && \"value\" in val;\n };\n\n // Extract array value from the custom { __type: \"Vector\", value: number[] } wrapper\n const arrayValue = isVectorObject(value)\n ? value.value\n : (Array.isArray(value) ? value : []);\n\n const [textValue, setTextValue] = useState(() => arrayValue.join(\", \"));\n const [isEditing, setIsEditing] = useState(false);\n const [showValues, setShowValues] = useState(false);\n\n useEffect(() => {\n setTextValue(arrayValue.join(\", \"));\n }, [JSON.stringify(arrayValue)]);\n\n const handleClearClick = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setValue(null);\n setTextValue(\"\");\n }, [setValue]);\n\n const onChange = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const raw = event.target.value;\n setTextValue(raw);\n\n // Parse comma-separated string to number array\n const numbers = raw\n .split(\",\")\n .map(str => str.trim())\n .filter(str => str !== \"\")\n .map(Number);\n\n setValue({\n __type: \"Vector\",\n value: numbers\n });\n };\n\n const label = hideLabel ? null : (\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n );\n\n const isPopulated = arrayValue.length > 0;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Only when there is a label to put in it — an empty row still\n spends its `mb-1` and the column's `gap-2`, and the control ends\n up below the one beside it under a label at the same height. */}\n {label && <div className=\"flex items-center justify-between mb-1\">\n {label}\n </div>}\n\n <div className=\"w-full\">\n {!isEditing ? (\n /* Compact Preview Card */\n <div className={cls(\"flex flex-col gap-3 p-4 rounded-xl border bg-surface-field transition-all duration-200\", defaultBorderMixin)}>\n <div className=\"flex items-center justify-between flex-wrap gap-2\">\n <div className=\"flex items-center gap-2.5\">\n {/* Status Dot */}\n <div className={`w-2.5 h-2.5 rounded-full ${isPopulated ? \"bg-emerald-500 animate-pulse\" : \"bg-surface-300 dark:bg-surface-600\"}`} />\n <span className=\"text-sm font-semibold text-text-primary dark:text-text-primary-dark\">\n {isPopulated ? `${arrayValue.length} Dimensions` : \"Empty Vector\"}\n </span>\n {isPopulated && (\n <span className=\"text-xs text-text-secondary dark:text-text-secondary-dark px-2 py-0.5 rounded-full bg-surface-raised font-medium\">\n Embedding\n </span>\n )}\n </div>\n\n <div className=\"flex items-center gap-2\">\n {isPopulated && (\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setShowValues(!showValues)}\n startIcon={showValues ? <EyeOffIcon size={14} /> : <EyeIcon size={14} />}\n >\n {showValues ? \"Hide values\" : \"Show values\"}\n </Button>\n )}\n {!disabled && (\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(true)}\n startIcon={<PencilIcon size={14} />}\n >\n {isPopulated ? \"Edit values\" : \"Add values\"}\n </Button>\n )}\n {isPopulated && !disabled && (\n <IconButton aria-label={t(\"clear\")} size=\"small\" onClick={handleClearClick} className=\"text-text-secondary hover:text-red-500\">\n <Trash2Icon size={14} />\n </IconButton>\n )}\n </div>\n </div>\n\n {/* Collapsible scrollable numbers list */}\n {showValues && isPopulated && (\n <div className=\"mt-1 p-3 rounded-lg bg-surface-well border border-hairline max-h-36 overflow-y-auto font-mono text-xs leading-relaxed text-text-secondary dark:text-text-secondary-dark break-all selection:bg-primary/20\">\n {arrayValue.join(\", \")}\n </div>\n )}\n </div>\n ) : (\n /* Editing View: Text Input */\n <div className={cls(\"flex flex-col gap-2 p-4 rounded-xl border bg-surface-field\", defaultBorderMixin)}>\n <TextField\n size={size}\n aria-label={`${property.name ?? propertyKey} vector values`}\n value={textValue}\n onChange={onChange}\n autoFocus={true}\n placeholder={`e.g., 0.15, -0.42, 0.88 (Requires ${property.dimensions} dimensions)`}\n disabled={disabled}\n error={showError ? !!error : undefined}\n inputClassName={error ? \"text-red-500 dark:text-red-600 font-mono text-xs\" : \"font-mono text-xs\"}\n />\n <div className=\"flex justify-end gap-2 mt-2\">\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n >\n Cancel\n </Button>\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n startIcon={<CheckIcon size={14} />}\n >\n Done\n </Button>\n </div>\n </div>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,mBAAmB,EAC/B,aACA,OACA,UACA,OACA,WACA,UACA,WACA,UACA,oBACA,WACA,OAAO,WACoB;CAC3B,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,kBAAkB,QAA6C;EACjE,OAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,WAAW;CACjE;CAGA,MAAM,aAAa,eAAe,KAAK,IACjC,MAAM,QACL,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC;CAEvC,MAAM,CAAC,WAAW,gBAAgB,eAAe,WAAW,KAAK,IAAI,CAAC;CACtE,MAAM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ACA;GACb,CAAA;EACA;;AAEb"}
@@ -45,8 +45,9 @@ export interface CollectionSources {
45
45
  workspacePreferences?: UiPreferences;
46
46
  }
47
47
  /**
48
- * The collections the panel registers, in navigation order: the served tables,
49
- * then the external ones.
48
+ * The collections the panel registers, in navigation order: the served tables
49
+ * (in `tableCustomizations` order, then the rest as served), then the external
50
+ * ones.
50
51
  *
51
52
  * - **Tables**: every served table projected (`collectionsFromTables`), with
52
53
  * its `customizeTable` folded in (`applyTableCustomizations`), then the
@@ -8,8 +8,9 @@ function describe(collection) {
8
8
  return `"${collection.slug}"${name}`;
9
9
  }
10
10
  /**
11
- * The collections the panel registers, in navigation order: the served tables,
12
- * then the external ones.
11
+ * The collections the panel registers, in navigation order: the served tables
12
+ * (in `tableCustomizations` order, then the rest as served), then the external
13
+ * ones.
13
14
  *
14
15
  * - **Tables**: every served table projected (`collectionsFromTables`), with
15
16
  * its `customizeTable` folded in (`applyTableCustomizations`), then the
@@ -31,6 +32,7 @@ function composeCollections({ tables, tableCustomizations, externalCollections,
31
32
  disableDefaultPolicies: true
32
33
  } : collection) : [];
33
34
  for (const collection of projected) composedBySlug.set(collection.slug, collection);
35
+ const ordered = inCustomizationOrder(projected, tableCustomizations);
34
36
  const tableSlugs = new Map(projected.map((collection) => [collection.slug, collection]));
35
37
  const external = /* @__PURE__ */ new Map();
36
38
  for (const collection of externalCollections) {
@@ -40,7 +42,29 @@ function composeCollections({ tables, tableCustomizations, externalCollections,
40
42
  if (twin) throw new Error(`externalCollections: ${describe(twin)} and ${describe(collection)} have the same slug. Give one of them another slug: a slug names one collection only.`);
41
43
  external.set(collection.slug, collection);
42
44
  }
43
- return [...projected, ...external.values()];
45
+ return [...ordered, ...external.values()];
46
+ }
47
+ /**
48
+ * The tables in the order the project declares them: the order of
49
+ * `tableCustomizations`, then the tables without a customization, in the
50
+ * order served.
51
+ *
52
+ * The served order is no declaration: the server collects the tables from the
53
+ * `backend/schema/index` module namespace, which lists exports sorted by name.
54
+ * `tableCustomizations` is an array the project wrote in order (the codemod
55
+ * heads it "in the order the panel lists them"), so it decides. Navigation
56
+ * groups follow, since a group sits where its first table does;
57
+ * `navigationGroupMappings`, when given, still overrides both.
58
+ */
59
+ function inCustomizationOrder(collections, tableCustomizations) {
60
+ const rank = /* @__PURE__ */ new Map();
61
+ tableCustomizations.forEach((customization, index) => {
62
+ if (!rank.has(customization.table)) rank.set(customization.table, index);
63
+ });
64
+ if (rank.size === 0) return [...collections];
65
+ const customized = collections.filter((collection) => rank.has(collection.slug)).sort((a, b) => (rank.get(a.slug) ?? 0) - (rank.get(b.slug) ?? 0));
66
+ const rest = collections.filter((collection) => !rank.has(collection.slug));
67
+ return [...customized, ...rest];
44
68
  }
45
69
  //#endregion
46
70
  export { composeCollections };
@@ -1 +1 @@
1
- {"version":3,"file":"compose_collections.js","names":[],"sources":["../../../src/hooks/navigation/compose_collections.ts"],"sourcesContent":["/**\n * What `<RebaseCMS>` registers: the tables the server serves, projected and\n * customized, beside the collections whose rows live elsewhere (Firestore).\n *\n * ## The composition order\n *\n * A served table's collection is built in layers, each over the one before:\n *\n * 1. **the projected table** — `GET /api/schema/tables`, through the\n * projector: every column, relation and rule, with zero configuration;\n * 2. **code customizations** — `<RebaseCMS tableCustomizations>`, the\n * `customizeTable(...)` results written in the frontend (components,\n * actions, callbacks: everything that is code);\n * 3. **workspace preferences** — what the collection editor saved for\n * everybody: `<RebaseCMS uiConfig>` (`frontend/src/cms/ui-config.json`,\n * shipped with the frontend), then the preferences the server stores for\n * the workspace;\n * 4. **user preferences** — what the views remember for the signed-in user\n * (column widths, order, view mode), folded in by the collection registry\n * when a view resolves its collection (`useBuildCollectionRegistryController`).\n *\n * Layers 3 and 4 are data (`UiTablePreferences`): never a schema fact, never\n * code.\n */\nimport type { AdminCollection, TableCustomization } from \"@rebasepro/cms-types\";\nimport type { TableDescriptor, UiPreferences } from \"@rebasepro/types\";\nimport { collectionsFromTables } from \"../../tables/project_table\";\nimport { applyTableCustomizations, type TableCollection } from \"../../tables/apply_customization\";\nimport { applyUiPreferences, uiConfigPreferences } from \"./ui_preferences\";\nimport { registeredCollection } from \"./registered_collection\";\n\n/** What the composition produces: a served table's collection, or an external one. */\nexport type PanelCollection = TableCollection | AdminCollection;\n\n/** What {@link composeCollections} combines. */\nexport interface CollectionSources {\n /** The tables the server serves the caller. */\n tables: readonly TableDescriptor[];\n /** `<RebaseCMS tableCustomizations>`. */\n tableCustomizations: readonly TableCustomization[];\n /** `<RebaseCMS externalCollections>`. */\n externalCollections: readonly AdminCollection[];\n /** `<RebaseCMS uiConfig>`: the workspace's preferences shipped with the frontend, as imported (validated here). */\n uiConfig?: { tables?: { [slug: string]: object } };\n /** The workspace's preferences the server stores. */\n workspacePreferences?: UiPreferences;\n}\n\nfunction describe(collection: PanelCollection): string {\n const name = collection.name && collection.name !== collection.slug ? ` (\"${collection.name}\")` : \"\";\n return `\"${collection.slug}\"${name}`;\n}\n\n/**\n * The collections the panel registers, in navigation order: the served tables,\n * then the external ones.\n *\n * - **Tables**: every served table projected (`collectionsFromTables`), with\n * its `customizeTable` folded in (`applyTableCustomizations`), then the\n * workspace's preferences (see \"The composition order\" above).\n * - **External collections never share a slug.** One with the slug of a\n * served table or of another external collection throws, naming both: a\n * slug is a URL, a saved layout and a reference target, and two collections\n * cannot answer to one.\n */\nexport function composeCollections({ tables, tableCustomizations, externalCollections, uiConfig, workspacePreferences }: CollectionSources): PanelCollection[] {\n const shipped = uiConfigPreferences(uiConfig);\n // A relation opens its target as the panel registers it, not as it was\n // projected: the target's `customizeTable` (`hideFromEntityViews`, its\n // display, its columns) is what a tab, a picker or a preview of it must\n // read, as they read an authored collection's `target: () => other`. The\n // thunks are called after the composition below has filled this map, and\n // hand out the collection as the registry holds it (`registeredCollection`).\n const composedBySlug = new Map<string, TableCollection>();\n const targetCollection = (slug: string): AdminCollection | undefined => {\n const composed = composedBySlug.get(slug);\n return composed ? registeredCollection(composed) : undefined;\n };\n const projected = tables.length > 0 || tableCustomizations.length > 0\n ? applyTableCustomizations(collectionsFromTables(tables, { targetCollection }), tableCustomizations)\n .map(collection => applyUiPreferences(collection, shipped.tables[collection.slug]))\n .map(collection => applyUiPreferences(collection, workspacePreferences?.tables[collection.slug]))\n .map((collection, index) =>\n // The projected rules are already the effective ones. A table that\n // switches the admin baseline off says so here too, so the editors\n // that list what Postgres holds (`getEffectiveSecurityRulesOnce`)\n // do not offer the baseline it does not have.\n tables[index]?.kind === \"table\" && tables[index].rls.defaultPolicies === false\n ? { ...collection, disableDefaultPolicies: true }\n : collection)\n : [];\n\n for (const collection of projected) composedBySlug.set(collection.slug, collection);\n const tableSlugs = new Map(projected.map(collection => [collection.slug, collection]));\n\n const external = new Map<string, AdminCollection>();\n for (const collection of externalCollections) {\n const table = tableSlugs.get(collection.slug);\n if (table) {\n throw new Error(\n `externalCollections: ${describe(collection)} has the slug of the table ${describe(table)} the server serves. ` +\n \"Give the external collection another slug: a slug names one collection only.\"\n );\n }\n const twin = external.get(collection.slug);\n if (twin) {\n throw new Error(\n `externalCollections: ${describe(twin)} and ${describe(collection)} have the same slug. ` +\n \"Give one of them another slug: a slug names one collection only.\"\n );\n }\n external.set(collection.slug, collection);\n }\n\n return [...projected, ...external.values()];\n}\n"],"mappings":";;;;;AAgDA,SAAS,SAAS,YAAqC;CACnD,MAAM,OAAO,WAAW,QAAQ,WAAW,SAAS,WAAW,OAAO,MAAM,WAAW,KAAK,MAAM;CAClG,OAAO,IAAI,WAAW,KAAK,GAAG;AAClC;;;;;;;;;;;;;AAcA,SAAgB,mBAAmB,EAAE,QAAQ,qBAAqB,qBAAqB,UAAU,wBAA8D;CAC3J,MAAM,UAAU,oBAAoB,QAAQ;CAO5C,MAAM,iCAAiB,IAAI,IAA6B;CACxD,MAAM,oBAAoB,SAA8C;EACpE,MAAM,WAAW,eAAe,IAAI,IAAI;EACxC,OAAO,WAAW,qBAAqB,QAAQ,IAAI,KAAA;CACvD;CACA,MAAM,YAAY,OAAO,SAAS,KAAK,oBAAoB,SAAS,IAC9D,yBAAyB,sBAAsB,QAAQ,EAAE,iBAAiB,CAAC,GAAG,mBAAmB,CAAC,CAC/F,KAAI,eAAc,mBAAmB,YAAY,QAAQ,OAAO,WAAW,KAAK,CAAC,CAAC,CAClF,KAAI,eAAc,mBAAmB,YAAY,sBAAsB,OAAO,WAAW,KAAK,CAAC,CAAC,CAChG,KAAK,YAAY,UAKlB,OAAO,MAAM,EAAE,SAAS,WAAW,OAAO,MAAM,CAAC,IAAI,oBAAoB,QACnE;EAAE,GAAG;EAAY,wBAAwB;CAAK,IAC9C,UAAU,IAClB,CAAC;CAEP,KAAK,MAAM,cAAc,WAAW,eAAe,IAAI,WAAW,MAAM,UAAU;CAClF,MAAM,aAAa,IAAI,IAAI,UAAU,KAAI,eAAc,CAAC,WAAW,MAAM,UAAU,CAAC,CAAC;CAErF,MAAM,2BAAW,IAAI,IAA6B;CAClD,KAAK,MAAM,cAAc,qBAAqB;EAC1C,MAAM,QAAQ,WAAW,IAAI,WAAW,IAAI;EAC5C,IAAI,OACA,MAAM,IAAI,MACN,wBAAwB,SAAS,UAAU,EAAE,6BAA6B,SAAS,KAAK,EAAE,iGAE9F;EAEJ,MAAM,OAAO,SAAS,IAAI,WAAW,IAAI;EACzC,IAAI,MACA,MAAM,IAAI,MACN,wBAAwB,SAAS,IAAI,EAAE,OAAO,SAAS,UAAU,EAAE,sFAEvE;EAEJ,SAAS,IAAI,WAAW,MAAM,UAAU;CAC5C;CAEA,OAAO,CAAC,GAAG,WAAW,GAAG,SAAS,OAAO,CAAC;AAC9C"}
1
+ {"version":3,"file":"compose_collections.js","names":[],"sources":["../../../src/hooks/navigation/compose_collections.ts"],"sourcesContent":["/**\n * What `<RebaseCMS>` registers: the tables the server serves, projected and\n * customized, beside the collections whose rows live elsewhere (Firestore).\n *\n * ## The composition order\n *\n * A served table's collection is built in layers, each over the one before:\n *\n * 1. **the projected table** — `GET /api/schema/tables`, through the\n * projector: every column, relation and rule, with zero configuration;\n * 2. **code customizations** — `<RebaseCMS tableCustomizations>`, the\n * `customizeTable(...)` results written in the frontend (components,\n * actions, callbacks: everything that is code);\n * 3. **workspace preferences** — what the collection editor saved for\n * everybody: `<RebaseCMS uiConfig>` (`frontend/src/cms/ui-config.json`,\n * shipped with the frontend), then the preferences the server stores for\n * the workspace;\n * 4. **user preferences** — what the views remember for the signed-in user\n * (column widths, order, view mode), folded in by the collection registry\n * when a view resolves its collection (`useBuildCollectionRegistryController`).\n *\n * Layers 3 and 4 are data (`UiTablePreferences`): never a schema fact, never\n * code.\n */\nimport type { AdminCollection, TableCustomization } from \"@rebasepro/cms-types\";\nimport type { TableDescriptor, UiPreferences } from \"@rebasepro/types\";\nimport { collectionsFromTables } from \"../../tables/project_table\";\nimport { applyTableCustomizations, type TableCollection } from \"../../tables/apply_customization\";\nimport { applyUiPreferences, uiConfigPreferences } from \"./ui_preferences\";\nimport { registeredCollection } from \"./registered_collection\";\n\n/** What the composition produces: a served table's collection, or an external one. */\nexport type PanelCollection = TableCollection | AdminCollection;\n\n/** What {@link composeCollections} combines. */\nexport interface CollectionSources {\n /** The tables the server serves the caller. */\n tables: readonly TableDescriptor[];\n /** `<RebaseCMS tableCustomizations>`. */\n tableCustomizations: readonly TableCustomization[];\n /** `<RebaseCMS externalCollections>`. */\n externalCollections: readonly AdminCollection[];\n /** `<RebaseCMS uiConfig>`: the workspace's preferences shipped with the frontend, as imported (validated here). */\n uiConfig?: { tables?: { [slug: string]: object } };\n /** The workspace's preferences the server stores. */\n workspacePreferences?: UiPreferences;\n}\n\nfunction describe(collection: PanelCollection): string {\n const name = collection.name && collection.name !== collection.slug ? ` (\"${collection.name}\")` : \"\";\n return `\"${collection.slug}\"${name}`;\n}\n\n/**\n * The collections the panel registers, in navigation order: the served tables\n * (in `tableCustomizations` order, then the rest as served), then the external\n * ones.\n *\n * - **Tables**: every served table projected (`collectionsFromTables`), with\n * its `customizeTable` folded in (`applyTableCustomizations`), then the\n * workspace's preferences (see \"The composition order\" above).\n * - **External collections never share a slug.** One with the slug of a\n * served table or of another external collection throws, naming both: a\n * slug is a URL, a saved layout and a reference target, and two collections\n * cannot answer to one.\n */\nexport function composeCollections({ tables, tableCustomizations, externalCollections, uiConfig, workspacePreferences }: CollectionSources): PanelCollection[] {\n const shipped = uiConfigPreferences(uiConfig);\n // A relation opens its target as the panel registers it, not as it was\n // projected: the target's `customizeTable` (`hideFromEntityViews`, its\n // display, its columns) is what a tab, a picker or a preview of it must\n // read, as they read an authored collection's `target: () => other`. The\n // thunks are called after the composition below has filled this map, and\n // hand out the collection as the registry holds it (`registeredCollection`).\n const composedBySlug = new Map<string, TableCollection>();\n const targetCollection = (slug: string): AdminCollection | undefined => {\n const composed = composedBySlug.get(slug);\n return composed ? registeredCollection(composed) : undefined;\n };\n const projected = tables.length > 0 || tableCustomizations.length > 0\n ? applyTableCustomizations(collectionsFromTables(tables, { targetCollection }), tableCustomizations)\n .map(collection => applyUiPreferences(collection, shipped.tables[collection.slug]))\n .map(collection => applyUiPreferences(collection, workspacePreferences?.tables[collection.slug]))\n .map((collection, index) =>\n // The projected rules are already the effective ones. A table that\n // switches the admin baseline off says so here too, so the editors\n // that list what Postgres holds (`getEffectiveSecurityRulesOnce`)\n // do not offer the baseline it does not have.\n tables[index]?.kind === \"table\" && tables[index].rls.defaultPolicies === false\n ? { ...collection, disableDefaultPolicies: true }\n : collection)\n : [];\n\n for (const collection of projected) composedBySlug.set(collection.slug, collection);\n const ordered = inCustomizationOrder(projected, tableCustomizations);\n const tableSlugs = new Map(projected.map(collection => [collection.slug, collection]));\n\n const external = new Map<string, AdminCollection>();\n for (const collection of externalCollections) {\n const table = tableSlugs.get(collection.slug);\n if (table) {\n throw new Error(\n `externalCollections: ${describe(collection)} has the slug of the table ${describe(table)} the server serves. ` +\n \"Give the external collection another slug: a slug names one collection only.\"\n );\n }\n const twin = external.get(collection.slug);\n if (twin) {\n throw new Error(\n `externalCollections: ${describe(twin)} and ${describe(collection)} have the same slug. ` +\n \"Give one of them another slug: a slug names one collection only.\"\n );\n }\n external.set(collection.slug, collection);\n }\n\n return [...ordered, ...external.values()];\n}\n\n/**\n * The tables in the order the project declares them: the order of\n * `tableCustomizations`, then the tables without a customization, in the\n * order served.\n *\n * The served order is no declaration: the server collects the tables from the\n * `backend/schema/index` module namespace, which lists exports sorted by name.\n * `tableCustomizations` is an array the project wrote in order (the codemod\n * heads it \"in the order the panel lists them\"), so it decides. Navigation\n * groups follow, since a group sits where its first table does;\n * `navigationGroupMappings`, when given, still overrides both.\n */\nfunction inCustomizationOrder(collections: readonly TableCollection[], tableCustomizations: readonly TableCustomization[]): TableCollection[] {\n const rank = new Map<string, number>();\n tableCustomizations.forEach((customization, index) => {\n if (!rank.has(customization.table)) rank.set(customization.table, index);\n });\n if (rank.size === 0) return [...collections];\n const customized = collections\n .filter(collection => rank.has(collection.slug))\n .sort((a, b) => (rank.get(a.slug) ?? 0) - (rank.get(b.slug) ?? 0));\n const rest = collections.filter(collection => !rank.has(collection.slug));\n return [...customized, ...rest];\n}\n"],"mappings":";;;;;AAgDA,SAAS,SAAS,YAAqC;CACnD,MAAM,OAAO,WAAW,QAAQ,WAAW,SAAS,WAAW,OAAO,MAAM,WAAW,KAAK,MAAM;CAClG,OAAO,IAAI,WAAW,KAAK,GAAG;AAClC;;;;;;;;;;;;;;AAeA,SAAgB,mBAAmB,EAAE,QAAQ,qBAAqB,qBAAqB,UAAU,wBAA8D;CAC3J,MAAM,UAAU,oBAAoB,QAAQ;CAO5C,MAAM,iCAAiB,IAAI,IAA6B;CACxD,MAAM,oBAAoB,SAA8C;EACpE,MAAM,WAAW,eAAe,IAAI,IAAI;EACxC,OAAO,WAAW,qBAAqB,QAAQ,IAAI,KAAA;CACvD;CACA,MAAM,YAAY,OAAO,SAAS,KAAK,oBAAoB,SAAS,IAC9D,yBAAyB,sBAAsB,QAAQ,EAAE,iBAAiB,CAAC,GAAG,mBAAmB,CAAC,CAC/F,KAAI,eAAc,mBAAmB,YAAY,QAAQ,OAAO,WAAW,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