@ai-matrx/summon 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/README.md +22 -2
- package/dist/dock.cjs +552 -0
- package/dist/dock.cjs.map +1 -0
- package/dist/dock.d.cts +224 -0
- package/dist/dock.d.ts +224 -0
- package/dist/dock.js +537 -0
- package/dist/dock.js.map +1 -0
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/persistence-data.cjs +9 -0
- package/dist/persistence-data.cjs.map +1 -1
- package/dist/persistence-data.d.cts +2 -1
- package/dist/persistence-data.d.ts +2 -1
- package/dist/persistence-data.js +9 -0
- package/dist/persistence-data.js.map +1 -1
- package/dist/persistence.cjs +6 -4
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +6 -4
- package/dist/persistence.js.map +1 -1
- package/dist/react.cjs +19 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +8 -1
- package/dist/react.d.ts +8 -1
- package/dist/react.js +19 -0
- package/dist/react.js.map +1 -1
- package/dist/url.cjs +32 -50
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.cts +2 -8
- package/dist/url.d.ts +2 -8
- package/dist/url.js +8 -24
- package/dist/url.js.map +1 -1
- package/dist/window-host.cjs +43 -1
- package/dist/window-host.cjs.map +1 -1
- package/dist/window-host.d.cts +45 -1
- package/dist/window-host.d.ts +45 -1
- package/dist/window-host.js +44 -2
- package/dist/window-host.js.map +1 -1
- package/dist/window.cjs +127 -149
- package/dist/window.cjs.map +1 -1
- package/dist/window.d.cts +2 -46
- package/dist/window.d.ts +2 -46
- package/dist/window.js +14 -34
- package/dist/window.js.map +1 -1
- package/package.json +14 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dock.ts","../src/dock/Dock.tsx","../src/dock/useDock.ts","../src/dock/geometry.ts","../src/dock/store.ts"],"sourcesContent":["// @ai-matrx/summon/dock — the one primitive for floating chrome-less cards, pills and docks:\n// pointer drag that never re-renders while moving (CSS translate in one rAF, one commit on release),\n// corner-relative positions clamped to the viewport with an optional nearest-corner snap, a position\n// remembered per dock id (host store via DockProvider, else localStorage) or reported to a controlled\n// host, the window manager's z-order lane on press, THE CURSOR LAW drag hold. Zero cost until mounted.\nexport { Dock, DockHandle, useDockContext, type DockProps, type DockHandleProps } from \"./dock/Dock\";\nexport {\n useDock,\n DEFAULT_DOCK_IGNORE,\n type UseDockOptions,\n type DockApi,\n type DockAnchor,\n type DockHandleBindings,\n} from \"./dock/useDock\";\nexport {\n DockProvider,\n useDockStore,\n createLocalDockStore,\n memoryOnlyDockStore,\n parseDockPosition,\n DOCK_STORAGE_PREFIX,\n type DockPositionStore,\n type DockProviderProps,\n} from \"./dock/store\";\nexport {\n clampOffset,\n toScreen,\n fromScreen,\n nearestCorner,\n avoidExclusions,\n DEFAULT_DOCK_MARGIN,\n DEFAULT_DRAG_THRESHOLD,\n type DockCorner,\n type DockOffset,\n type DockPosition,\n type DockSize,\n type DockClamp,\n type ScreenPoint,\n type ScreenRect,\n} from \"./dock/geometry\";\n","/**\n * `<Dock>` — the component form of `useDock()`: a fixed, chrome-less element that\n * moves. Drag it by a `<DockHandle>` inside it, or by the whole dock with\n * `handle=\"self\"`. `useDockContext()` reaches the dock's API from anywhere inside\n * (a \"Move back to the corner\" menu item calls `reset()`).\n */\n\nimport { createContext, useContext, type CSSProperties, type HTMLAttributes, type ReactNode } from \"react\";\nimport { useDock, type DockApi, type UseDockOptions } from \"./useDock\";\n\nconst DockContext = createContext<DockApi | null>(null);\n\n/** The enclosing dock's API; throws outside a `<Dock>`. */\nexport function useDockContext(): DockApi {\n const dock = useContext(DockContext);\n if (!dock) throw new Error(\"[summon] useDockContext() must be used inside <Dock>\");\n return dock;\n}\n\nexport interface DockProps extends UseDockOptions, Omit<HTMLAttributes<HTMLDivElement>, \"id\" | \"children\" | \"draggable\"> {\n /** \"self\": the whole dock is the drag handle. Default: only `<DockHandle>`s drag. */\n handle?: \"self\" | \"inner\";\n children?: ReactNode | ((dock: DockApi) => ReactNode);\n}\n\nconst OPTION_KEYS = [\n \"id\", \"corner\", \"defaultPosition\", \"anchor\", \"position\", \"onPositionChange\", \"persist\", \"store\", \"draggable\",\n \"touch\", \"threshold\", \"clamp\", \"avoid\", \"snapToCorner\", \"zIndex\", \"raiseOnPress\", \"ignore\",\n] as const satisfies readonly (keyof UseDockOptions)[];\n\nexport function Dock(props: DockProps): ReactNode {\n const options = {} as UseDockOptions;\n const rest: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n if ((OPTION_KEYS as readonly string[]).includes(key)) (options as unknown as Record<string, unknown>)[key] = value;\n else if (key !== \"handle\" && key !== \"children\" && key !== \"style\") rest[key] = value;\n }\n const dock = useDock(options);\n const self = props.handle === \"self\";\n const style: CSSProperties = { ...props.style, ...dock.style, ...(self ? dock.handleProps.style : {}) };\n return (\n <DockContext.Provider value={dock}>\n <div\n {...(rest as HTMLAttributes<HTMLDivElement>)}\n ref={dock.ref}\n data-dock={props.id}\n data-dragging={dock.dragging ? \"\" : undefined}\n style={style}\n {...(self ? { onPointerDown: dock.handleProps.onPointerDown, \"data-dock-handle\": \"\" } : {})}\n >\n {typeof props.children === \"function\" ? props.children(dock) : props.children}\n </div>\n </DockContext.Provider>\n );\n}\n\nexport interface DockHandleProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The part of a `<Dock>` you drag it by. Buttons and fields inside stay controls. */\nexport function DockHandle({ style, onPointerDown, ...rest }: DockHandleProps): ReactNode {\n const dock = useDockContext();\n return (\n <div\n {...rest}\n {...dock.handleProps}\n style={{ ...style, ...dock.handleProps.style }}\n onPointerDown={(event) => {\n onPointerDown?.(event);\n dock.handleProps.onPointerDown(event);\n }}\n />\n );\n}\n","/**\n * `useDock()` — the one primitive for floating chrome-less cards, pills and docks.\n *\n * THE RULE (paid for in the Workflow Studio's FloatingChatPanel and chat's\n * ChatPanel): a pointer move paints the CSS `translate` property inside ONE\n * requestAnimationFrame and React state is committed EXACTLY ONCE, on release.\n * Writing state per pointer event re-renders whatever streams inside the dock\n * sixty times a second. `translate` composes with the host's own `transform`\n * and with any `left/right/top/bottom` it computes, so a host that builds its\n * own placement (CSS variables, lifts) still drags without re-rendering.\n *\n * What else it carries:\n * - a drag is never a click: below `threshold` px the gesture stays a click;\n * past it the trailing click is swallowed once;\n * - the position is an offset from a corner, clamped to the viewport on every\n * render (a position saved on a wide monitor never strands the dock), and\n * can snap to the nearest corner on release;\n * - it remembers its place per dock id (the store chain in ./store) or reports\n * it to a controlled host (`position` + `onPositionChange`, e.g. per-user sync);\n * - it joins the window manager's z-order lane on press (raised above every\n * window, below modals) when a SummonProvider is present;\n * - THE CURSOR LAW: the drag holds `grabbing` with design-system `holdDragCursor`;\n * - zero cost until mounted: no listener exists outside an active press.\n */\n\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n type CSSProperties,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { holdDragCursor } from \"@ai-matrx/design-system\";\nimport { raiseTransientWindow, releaseTransientWindow } from \"@ai-matrx/summon\";\nimport { useOptionalSummonStore } from \"@ai-matrx/summon/react\";\nimport {\n avoidExclusions,\n clampOffset,\n DEFAULT_DOCK_MARGIN,\n DEFAULT_DRAG_THRESHOLD,\n fromScreen,\n nearestCorner,\n samePosition,\n toScreen,\n type DockClamp,\n type DockCorner,\n type DockOffset,\n type DockPosition,\n type DockSize,\n type ScreenPoint,\n type ScreenRect,\n} from \"./geometry\";\nimport { memoryOnlyDockStore, useDockStore, type DockPositionStore } from \"./store\";\n\n/** CSS placement used while the dock has no position (never moved, no `defaultPosition`). */\nexport interface DockAnchor {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n /** Centre horizontally (`left: 50%` + translateX(-50%)). */\n centerX?: boolean;\n}\n\n/** Controls inside the handle that stay controls — a press there never starts a drag. */\nexport const DEFAULT_DOCK_IGNORE = \"button,a,input,select,textarea,[contenteditable='true'],[data-no-drag]\";\n\nexport interface UseDockOptions {\n /** Identity: the remembered position, the z-order lane entry. Unique per dock. */\n id: string;\n /** The corner positions are measured from. Default \"bottom-right\". */\n corner?: DockCorner;\n /** Resting offset from `corner` before the person moves it. Omit to rest on `anchor`. */\n defaultPosition?: DockOffset | null;\n /** CSS resting place when there is no position at all. */\n anchor?: DockAnchor;\n /** Controlled position (the host owns storage, e.g. a per-user preference). `null` = resting. */\n position?: DockPosition | null;\n /** Told once per drag, on release, and on `reset()` (with `null`). */\n onPositionChange?: (position: DockPosition | null) => void;\n /** Remember the position across reloads (uncontrolled only). Default true. */\n persist?: boolean;\n /** This dock's own store; otherwise the nearest `<DockProvider>`, else localStorage. */\n store?: DockPositionStore;\n /** Default true. Pass false on surfaces that must not move (a phone sheet). */\n draggable?: boolean;\n /** Allow touch drags. Default true; a dock that fights page scroll passes false. */\n touch?: boolean;\n /** Px a pointer must travel before a press becomes a drag. Default 4. */\n threshold?: number;\n clamp?: DockClamp;\n /** Fixed controls the dock must stay off (nearest clear spot wins). */\n avoid?: { selector: string; gap?: number };\n /** On release, re-anchor to the nearest corner. Default false. */\n snapToCorner?: boolean;\n /** z-index before the first press raises it into the window lane. */\n zIndex?: number;\n /** Raise into the window manager's z-order lane on press. Default true. */\n raiseOnPress?: boolean;\n /** Selector of controls inside the handle that never start a drag. `null` = every press may drag. */\n ignore?: string | null;\n}\n\nexport interface DockHandleBindings {\n onPointerDown(event: ReactPointerEvent<HTMLElement>): void;\n style: CSSProperties;\n \"data-dock-handle\": \"\";\n}\n\nexport interface DockApi {\n /** Attach to the element that MOVES. */\n ref: (element: HTMLElement | null) => void;\n element: HTMLElement | null;\n /** Spread onto the moving element: fixed placement (placed or anchored) + z-index. */\n style: CSSProperties;\n /** Spread onto the element you drag BY (or the whole dock). */\n handleProps: DockHandleBindings;\n /** The clamped offset from `corner`; null while resting on `anchor`. */\n offset: DockOffset | null;\n /** The corner `offset` is measured from. */\n corner: DockCorner;\n /** True from the moment a press passes the threshold until release. */\n dragging: boolean;\n /** The person has moved it (a remembered or controlled position exists). */\n moved: boolean;\n /** Current z-index: the lane's once raised, else the `zIndex` option. */\n zIndex: number | undefined;\n /** Forget the position; the dock returns to its resting place. */\n reset(): void;\n}\n\nconst SSR_VIEWPORT: DockSize = { width: 1280, height: 800 };\nconst noopSubscribe = () => () => undefined;\n\ninterface Geometry {\n viewport: DockSize;\n size: DockSize;\n}\n\ninterface Press {\n pointerId: number;\n startX: number;\n startY: number;\n /** The dock's top-left when pressed. */\n origin: ScreenPoint;\n size: DockSize;\n viewport: DockSize;\n active: boolean;\n latest: ScreenPoint;\n release: (() => void) | null;\n cleanup: () => void;\n}\n\nfunction readViewport(): DockSize {\n return typeof window === \"undefined\" ? SSR_VIEWPORT : { width: window.innerWidth, height: window.innerHeight };\n}\n\nfunction measure(element: HTMLElement | null): DockSize {\n return { width: element?.offsetWidth ?? 0, height: element?.offsetHeight ?? 0 };\n}\n\nfunction excludedRects(avoid: UseDockOptions[\"avoid\"], self: HTMLElement | null): ScreenRect[] {\n if (!avoid || typeof document === \"undefined\") return [];\n return [...document.querySelectorAll<HTMLElement>(avoid.selector)]\n .filter((target) => target !== self && !self?.contains(target))\n .map((target) => target.getBoundingClientRect())\n .filter((rect) => rect.width > 0 && rect.height > 0);\n}\n\nexport function useDock(options: UseDockOptions): DockApi {\n const {\n id,\n corner = \"bottom-right\",\n defaultPosition = null,\n anchor,\n position: controlled,\n onPositionChange,\n persist = true,\n draggable = true,\n touch = true,\n threshold = DEFAULT_DRAG_THRESHOLD,\n clamp,\n avoid,\n snapToCorner = false,\n zIndex: baseZ,\n raiseOnPress = true,\n ignore = DEFAULT_DOCK_IGNORE,\n } = options;\n const isControlled = controlled !== undefined;\n const providedStore = useDockStore(options.store);\n const store = persist && !isControlled ? providedStore : memoryOnlyDockStore;\n\n const [element, setElement] = useState<HTMLElement | null>(null);\n const [local, setLocal] = useState<DockPosition | null>(null);\n /** A controlled commit, shown until the host's `position` changes (it may update async). */\n const [pending, setPending] = useState<{ value: DockPosition | null; forProp: DockPosition | null } | null>(null);\n const [geometry, setGeometry] = useState<Geometry>({ viewport: SSR_VIEWPORT, size: { width: 0, height: 0 } });\n const [nudge, setNudge] = useState<ScreenPoint | null>(null);\n const [dragging, setDragging] = useState(false);\n const pressRef = useRef<Press | null>(null);\n const frameRef = useRef<number | null>(null);\n const adoptingRef = useRef(false);\n const restoredRef = useRef<string | null>(null);\n\n // ── The position, resolved ───────────────────────────────────────────────\n const chosen: DockPosition | null = isControlled\n ? pending && samePosition(pending.forProp, controlled) ? pending.value : controlled\n : local;\n const raw: DockPosition | null = chosen ?? defaultPosition;\n const rawCorner = raw?.corner ?? corner;\n const offset = raw ? clampOffset(raw, rawCorner, geometry.size, geometry.viewport, clamp) : null;\n\n // Live refs for the press listeners (written in effects, never during render).\n const live = useRef({ offset, rawCorner, clamp, avoid, threshold, snapToCorner, onPositionChange, isControlled, controlled, store, id });\n useEffect(() => {\n live.current = { offset, rawCorner, clamp, avoid, threshold, snapToCorner, onPositionChange, isControlled, controlled, store, id };\n });\n\n // Restore the remembered position BEFORE paint, once per id, as soon as the element exists.\n useLayoutEffect(() => {\n if (!element || restoredRef.current === id) return;\n restoredRef.current = id;\n if (isControlled) return;\n setLocal(store.read(id));\n }, [element, id, isControlled, store]);\n\n // Track the viewport and the dock's own size (expanded/collapsed content), re-clamping on change.\n useLayoutEffect(() => {\n if (!element) return undefined;\n let frame: number | null = null;\n const read = () => {\n const next: Geometry = { viewport: readViewport(), size: measure(element) };\n setGeometry((current) =>\n current.viewport.width === next.viewport.width &&\n current.viewport.height === next.viewport.height &&\n current.size.width === next.size.width &&\n current.size.height === next.size.height\n ? current\n : next,\n );\n };\n const schedule = () => {\n if (frame !== null) return;\n frame = window.requestAnimationFrame(() => {\n frame = null;\n read();\n });\n };\n read();\n const observer = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule);\n observer?.observe(element);\n window.addEventListener(\"resize\", schedule);\n return () => {\n observer?.disconnect();\n window.removeEventListener(\"resize\", schedule);\n if (frame !== null) window.cancelAnimationFrame(frame);\n };\n }, [element]);\n\n // Exclusions: a placed dock is moved to the nearest clear spot at render; a resting (anchored)\n // dock gets a measured nudge, re-read whenever the page under it changes.\n const avoidSelector = avoid?.selector;\n const avoidGap = avoid?.gap;\n useLayoutEffect(() => {\n if (!element || !avoidSelector || offset) {\n setNudge((current) => (current === null ? current : null));\n return undefined;\n }\n let frame: number | null = null;\n let applied: ScreenPoint | null = null;\n const reconcile = () => {\n const rect = element.getBoundingClientRect();\n const size = measure(element);\n const viewport = readViewport();\n const base = { left: rect.left - (applied?.left ?? 0), top: rect.top - (applied?.top ?? 0) };\n const keep = (p: ScreenPoint) => {\n const o = clampOffset(fromScreen(p, \"top-left\", size, viewport), \"top-left\", size, viewport, live.current.clamp);\n return toScreen(o, \"top-left\", size, viewport);\n };\n const clear = avoidExclusions(base, size, excludedRects({ selector: avoidSelector }, element), avoidGap ?? DEFAULT_DOCK_MARGIN, keep);\n const next = { left: Math.round(clear.left - base.left), top: Math.round(clear.top - base.top) };\n applied = next.left === 0 && next.top === 0 ? null : next;\n setNudge((current) =>\n (current === null && applied === null) || (current && applied && current.left === applied.left && current.top === applied.top)\n ? current\n : applied,\n );\n };\n const schedule = () => {\n if (frame !== null) return;\n frame = window.requestAnimationFrame(() => {\n frame = null;\n reconcile();\n });\n };\n reconcile();\n const mutations = typeof MutationObserver === \"undefined\" ? null : new MutationObserver(schedule);\n mutations?.observe(document.body, { childList: true, subtree: true });\n window.addEventListener(\"resize\", schedule);\n window.addEventListener(\"scroll\", schedule, true);\n return () => {\n mutations?.disconnect();\n window.removeEventListener(\"resize\", schedule);\n window.removeEventListener(\"scroll\", schedule, true);\n if (frame !== null) window.cancelAnimationFrame(frame);\n };\n }, [element, avoidSelector, avoidGap, offset === null]); // eslint-disable-line react-hooks/exhaustive-deps\n\n /** A placed dock that would cover an excluded control renders at the nearest clear spot. */\n let placed: ScreenPoint | null = null;\n if (offset) {\n placed = toScreen(offset, rawCorner, geometry.size, geometry.viewport);\n if (avoid && element) {\n const size = geometry.size;\n const viewport = geometry.viewport;\n const keep = (p: ScreenPoint) =>\n toScreen(clampOffset(fromScreen(p, \"top-left\", size, viewport), \"top-left\", size, viewport, clamp), \"top-left\", size, viewport);\n placed = avoidExclusions(placed, size, excludedRects(avoid, element), avoid.gap ?? DEFAULT_DOCK_MARGIN, keep);\n }\n }\n const renderedOffset = placed && offset ? fromScreen(placed, rawCorner, geometry.size, geometry.viewport) : offset;\n\n // The committed position replaces the paint offset in the SAME commit: clear `translate` now.\n useLayoutEffect(() => {\n if (!adoptingRef.current) return;\n adoptingRef.current = false;\n element?.style.removeProperty(\"translate\");\n });\n\n // ── The z-order lane ────────────────────────────────────────────────────\n const summonStore = useOptionalSummonStore();\n const laneZ = useSyncExternalStore(\n summonStore ? summonStore.subscribe : noopSubscribe,\n () => (summonStore ? (summonStore.getState() as { windowManager?: { transientZ?: Record<string, number> } }).windowManager?.transientZ?.[id] : undefined),\n () => undefined,\n );\n useEffect(() => {\n if (!summonStore) return undefined;\n return () => {\n const state = summonStore.getState() as { windowManager?: { transientZ?: Record<string, number> } };\n if (state.windowManager?.transientZ?.[id] !== undefined) summonStore.dispatch(releaseTransientWindow(id));\n };\n }, [summonStore, id]);\n const zIndex = laneZ ?? baseZ;\n\n // ── The drag ────────────────────────────────────────────────────────────\n useEffect(\n () => () => {\n pressRef.current?.cleanup();\n pressRef.current = null;\n },\n [],\n );\n\n const commit = useCallback((next: DockPosition | null) => {\n const current = live.current;\n adoptingRef.current = true;\n if (current.isControlled) setPending({ value: next, forProp: current.controlled ?? null });\n else {\n setLocal(next);\n current.store.write(current.id, next);\n }\n current.onPositionChange?.(next);\n }, []);\n\n const onPointerDown = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n if (!draggable || event.button !== 0 || !element) return;\n if (!touch && event.pointerType === \"touch\") return;\n const target = event.target as HTMLElement | null;\n if (ignore && target) {\n const hit = target.closest(ignore);\n if (hit && hit !== event.currentTarget && event.currentTarget.contains(hit)) return;\n }\n pressRef.current?.cleanup();\n if (raiseOnPress && summonStore) summonStore.dispatch(raiseTransientWindow(id));\n // A press on bare chrome must not start a text selection; a press on a control keeps its default.\n if (!target?.closest(\"button,a,input,select,textarea,label,[role=button]\")) event.preventDefault();\n\n const rect = element.getBoundingClientRect();\n const viewport = readViewport();\n const size = measure(element);\n const press: Press = {\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n origin: { left: rect.left, top: rect.top },\n size,\n viewport,\n active: false,\n latest: { left: rect.left, top: rect.top },\n release: null,\n cleanup: () => undefined,\n };\n // A placed dock starts from its committed offset (the host may add lifts on top of it);\n // a resting dock starts from where it is on screen.\n const startOffset: DockOffset =\n live.current.offset ?? fromScreen(press.origin, live.current.rawCorner, size, viewport);\n const startCorner = live.current.rawCorner;\n const startScreen = toScreen(startOffset, startCorner, size, viewport);\n\n const paint = () => {\n frameRef.current = null;\n const active = pressRef.current;\n if (!active || !active.active) return;\n element.style.translate = `${active.latest.left - startScreen.left}px ${active.latest.top - startScreen.top}px`;\n };\n const move = (e: PointerEvent) => {\n if (e.pointerId !== press.pointerId) return;\n const dx = e.clientX - press.startX;\n const dy = e.clientY - press.startY;\n const opts = live.current;\n if (!press.active) {\n if (Math.abs(dx) < opts.threshold && Math.abs(dy) < opts.threshold) return;\n press.active = true;\n press.release = holdDragCursor(\"grabbing\");\n setDragging(true);\n }\n const desired = fromScreen({ left: startScreen.left + dx, top: startScreen.top + dy }, startCorner, size, viewport);\n let next = toScreen(clampOffset(desired, startCorner, size, viewport, opts.clamp), startCorner, size, viewport);\n if (opts.avoid) {\n const keep = (p: ScreenPoint) =>\n toScreen(clampOffset(fromScreen(p, \"top-left\", size, viewport), \"top-left\", size, viewport, opts.clamp), \"top-left\", size, viewport);\n next = avoidExclusions(next, size, excludedRects(opts.avoid, element), opts.avoid.gap ?? DEFAULT_DOCK_MARGIN, keep);\n }\n press.latest = next;\n if (frameRef.current === null) {\n if (typeof window.requestAnimationFrame === \"function\") frameRef.current = window.requestAnimationFrame(paint);\n else paint();\n }\n };\n const end = (e: PointerEvent) => {\n if (e.pointerId !== press.pointerId) return;\n press.cleanup();\n pressRef.current = null;\n if (!press.active) return;\n press.release?.();\n setDragging(false);\n const opts = live.current;\n const finalCorner = opts.snapToCorner ? nearestCorner(press.latest, size, viewport) : startCorner;\n const finalOffset = clampOffset(fromScreen(press.latest, finalCorner, size, viewport), finalCorner, size, viewport, opts.clamp);\n commit(finalCorner === corner ? { x: finalOffset.x, y: finalOffset.y } : { ...finalOffset, corner: finalCorner });\n // The click the browser fires next is the tail of this drag, never an intent.\n const swallow = (click: MouseEvent) => {\n click.stopPropagation();\n click.preventDefault();\n };\n window.addEventListener(\"click\", swallow, { capture: true, once: true });\n window.setTimeout(() => window.removeEventListener(\"click\", swallow, { capture: true }), 0);\n };\n press.cleanup = () => {\n window.removeEventListener(\"pointermove\", move);\n window.removeEventListener(\"pointerup\", end);\n window.removeEventListener(\"pointercancel\", end);\n if (frameRef.current !== null) {\n window.cancelAnimationFrame?.(frameRef.current);\n frameRef.current = null;\n }\n if (!press.active) return;\n press.release?.();\n press.release = null;\n };\n pressRef.current = press;\n window.addEventListener(\"pointermove\", move);\n window.addEventListener(\"pointerup\", end);\n window.addEventListener(\"pointercancel\", end);\n },\n [commit, corner, draggable, element, id, ignore, raiseOnPress, summonStore, touch],\n );\n\n const reset = useCallback(() => {\n adoptingRef.current = true;\n commit(null);\n }, [commit]);\n\n // ── Placement ───────────────────────────────────────────────────────────\n let style: CSSProperties;\n if (renderedOffset) {\n const left = rawCorner.endsWith(\"left\");\n const top = rawCorner.startsWith(\"top\");\n style = {\n position: \"fixed\",\n left: left ? renderedOffset.x : \"auto\",\n right: left ? \"auto\" : renderedOffset.x,\n top: top ? renderedOffset.y : \"auto\",\n bottom: top ? \"auto\" : renderedOffset.y,\n };\n } else {\n const transform = [anchor?.centerX ? \"translateX(-50%)\" : null, nudge ? `translate(${nudge.left}px, ${nudge.top}px)` : null]\n .filter(Boolean)\n .join(\" \");\n style = {\n position: \"fixed\",\n top: anchor?.top,\n bottom: anchor?.bottom,\n left: anchor?.centerX ? \"50%\" : anchor?.left,\n right: anchor?.right,\n ...(transform ? { transform } : {}),\n };\n }\n if (zIndex !== undefined) style.zIndex = zIndex;\n\n return {\n ref: setElement,\n element,\n style,\n handleProps: {\n onPointerDown,\n style: draggable ? { cursor: \"grab\", touchAction: touch ? \"none\" : \"auto\" } : {},\n \"data-dock-handle\": \"\",\n },\n offset: renderedOffset,\n corner: rawCorner,\n dragging,\n moved: chosen !== null,\n zIndex,\n reset,\n };\n}\n","/**\n * Dock geometry — the pure half of a dock: corner-relative offsets, the clamp\n * that keeps a dock reachable, the nearest-corner snap and the exclusion\n * avoidance. No DOM reads except `avoidExclusions`, which is handed the\n * rectangles it must stay off.\n *\n * A dock's position is stored as an OFFSET FROM A CORNER, not as left/top: a\n * dock resting 12px from the bottom-right keeps that relationship when the\n * window is resized, and a position saved on a wide monitor comes back next to\n * the same corner on a laptop.\n */\n\nexport type DockCorner = \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n\n/** Distance in px from the corner's horizontal (`x`) and vertical (`y`) edges. */\nexport interface DockOffset {\n x: number;\n y: number;\n}\n\n/** A remembered position: an offset and the corner it is measured from (the dock's corner when omitted). */\nexport interface DockPosition extends DockOffset {\n corner?: DockCorner;\n}\n\nexport interface DockSize {\n width: number;\n height: number;\n}\n\nexport interface DockClamp {\n /** Smallest gap kept between the dock and the viewport edge. Default 8. */\n margin?: number;\n /**\n * How much of the dock must stay on screen. Default: all of it. A dock that\n * may hang off an edge (a pill you can park half-hidden) passes its grab area.\n */\n minVisible?: DockSize;\n}\n\nexport interface ScreenPoint {\n left: number;\n top: number;\n}\n\nexport interface ScreenRect extends ScreenPoint {\n right: number;\n bottom: number;\n}\n\nexport const DEFAULT_DOCK_MARGIN = 8;\n\n/** A pointer that moved less than this is a click, not a drag. */\nexport const DEFAULT_DRAG_THRESHOLD = 4;\n\nconst fromLeft = (corner: DockCorner): boolean => corner.endsWith(\"left\");\nconst fromTop = (corner: DockCorner): boolean => corner.startsWith(\"top\");\n\n/** The offset → the dock's top-left in viewport px. */\nexport function toScreen(offset: DockOffset, corner: DockCorner, size: DockSize, viewport: DockSize): ScreenPoint {\n return {\n left: fromLeft(corner) ? offset.x : viewport.width - size.width - offset.x,\n top: fromTop(corner) ? offset.y : viewport.height - size.height - offset.y,\n };\n}\n\n/** A top-left in viewport px → the offset from `corner`. */\nexport function fromScreen(point: ScreenPoint, corner: DockCorner, size: DockSize, viewport: DockSize): DockOffset {\n return {\n x: fromLeft(corner) ? point.left : viewport.width - size.width - point.left,\n y: fromTop(corner) ? point.top : viewport.height - size.height - point.top,\n };\n}\n\n/**\n * Keep the offset inside the viewport. When the dock is larger than the room\n * there is, its TOP and LEFT stay visible — that is where a header, a grip\n * and a close button live, and an unreachable close button is how a movable\n * notice turns into an unclosable one.\n */\nexport function clampOffset(\n offset: DockOffset,\n corner: DockCorner,\n size: DockSize,\n viewport: DockSize,\n clamp: DockClamp = {},\n): DockOffset {\n const margin = clamp.margin ?? DEFAULT_DOCK_MARGIN;\n const visible = clamp.minVisible ?? size;\n const axis = (value: number, room: number, extent: number, nearIsStart: boolean): number => {\n const min = margin;\n const max = room - extent - margin;\n if (max < min) return Math.round(nearIsStart ? min : max);\n return Math.round(Math.min(Math.max(value, min), max));\n };\n return {\n x: axis(offset.x, viewport.width, visible.width, fromLeft(corner)),\n y: axis(offset.y, viewport.height, visible.height, fromTop(corner)),\n };\n}\n\n/** The corner nearest the dock's centre — where a dropped dock re-anchors when snapping is on. */\nexport function nearestCorner(point: ScreenPoint, size: DockSize, viewport: DockSize): DockCorner {\n const top = point.top + size.height / 2 < viewport.height / 2;\n const left = point.left + size.width / 2 < viewport.width / 2;\n return `${top ? \"top\" : \"bottom\"}-${left ? \"left\" : \"right\"}`;\n}\n\nfunction overlaps(a: ScreenRect, b: ScreenRect): boolean {\n return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;\n}\n\n/**\n * Keep the dock off fixed controls it must never cover (a table's pager, a\n * composer) without reserving page space. A clear position is returned\n * untouched; a covering one moves to the NEAREST clear candidate — never\n * further than it has to.\n */\nexport function avoidExclusions(\n point: ScreenPoint,\n size: DockSize,\n excluded: readonly ScreenRect[],\n gap: number,\n keepOnScreen: (point: ScreenPoint) => ScreenPoint,\n): ScreenPoint {\n const bounded = keepOnScreen(point);\n if (excluded.length === 0) return bounded;\n const rectFor = (candidate: ScreenPoint): ScreenRect => ({\n left: candidate.left,\n top: candidate.top,\n right: candidate.left + size.width,\n bottom: candidate.top + size.height,\n });\n const isClear = (candidate: ScreenPoint) => !excluded.some((target) => overlaps(rectFor(candidate), target));\n if (isClear(bounded)) return bounded;\n const clear = excluded\n .flatMap((target) => [\n { left: bounded.left, top: target.top - size.height - gap },\n { left: bounded.left, top: target.bottom + gap },\n { left: target.left - size.width - gap, top: bounded.top },\n { left: target.right + gap, top: bounded.top },\n ])\n .map(keepOnScreen)\n .filter(isClear);\n if (clear.length === 0) return bounded;\n const distance = (candidate: ScreenPoint) => Math.hypot(candidate.left - bounded.left, candidate.top - bounded.top);\n return clear.reduce((nearest, candidate) => (distance(candidate) < distance(nearest) ? candidate : nearest));\n}\n\nexport function samePosition(a: DockPosition | null | undefined, b: DockPosition | null | undefined): boolean {\n if (!a || !b) return a === b || (!a && !b);\n return a.x === b.x && a.y === b.y && a.corner === b.corner;\n}\n","/**\n * Where a dock remembers its position.\n *\n * The package never decides WHICH storage a host uses: a host that keeps\n * browser state behind its own declared keys (or syncs it per user) hands a\n * `DockPositionStore` to `<DockProvider>`, or to one dock through its `store`\n * option. With neither, positions live in this browser's localStorage under\n * `matrx:summon:dock:<id>` — every read and write is SSR-safe and never throws\n * (private mode, quota and disabled storage degrade to \"nothing stored\").\n */\n\nimport { createContext, createElement, useContext, type ReactNode } from \"react\";\nimport type { DockCorner, DockPosition } from \"./geometry\";\n\nexport interface DockPositionStore {\n read(id: string): DockPosition | null;\n /** `null` forgets the position (the dock goes back to its resting place). */\n write(id: string, position: DockPosition | null): void;\n}\n\nexport const DOCK_STORAGE_PREFIX = \"matrx:summon:dock:\";\n\nconst CORNERS: readonly DockCorner[] = [\"top-left\", \"top-right\", \"bottom-left\", \"bottom-right\"];\n\n/** Accept only a well-formed position; anything else reads as \"nothing stored\". */\nexport function parseDockPosition(value: unknown): DockPosition | null {\n if (!value || typeof value !== \"object\") return null;\n const { x, y, corner } = value as Record<string, unknown>;\n if (typeof x !== \"number\" || typeof y !== \"number\" || !Number.isFinite(x) || !Number.isFinite(y)) return null;\n if (corner !== undefined && !CORNERS.includes(corner as DockCorner)) return null;\n return corner === undefined ? { x, y } : { x, y, corner: corner as DockCorner };\n}\n\nfunction storage(): Storage | null {\n try {\n return typeof window === \"undefined\" ? null : window.localStorage;\n } catch {\n return null;\n }\n}\n\n/** The default store: one localStorage key per dock id. */\nexport function createLocalDockStore(prefix: string = DOCK_STORAGE_PREFIX): DockPositionStore {\n return {\n read(id) {\n try {\n const raw = storage()?.getItem(prefix + id);\n return raw ? parseDockPosition(JSON.parse(raw)) : null;\n } catch {\n return null;\n }\n },\n write(id, position) {\n try {\n const area = storage();\n if (!area) return;\n if (position) area.setItem(prefix + id, JSON.stringify(position));\n else area.removeItem(prefix + id);\n } catch {\n // Storage refused: the in-memory position still applies for this page.\n }\n },\n };\n}\n\n/** A store that remembers nothing — for docks whose place is per-moment (a toast, a stacked widget). */\nexport const memoryOnlyDockStore: DockPositionStore = { read: () => null, write: () => undefined };\n\nconst defaultStore = createLocalDockStore();\n\nconst DockStoreContext = createContext<DockPositionStore | null>(null);\n\nexport interface DockProviderProps {\n store: DockPositionStore;\n children?: ReactNode;\n}\n\n/** Hand every dock below one position store (the host's declared keys, a per-user sync). */\nexport function DockProvider({ store, children }: DockProviderProps): ReactNode {\n return createElement(DockStoreContext.Provider, { value: store }, children);\n}\n\n/** The store a dock uses: its own option, else the nearest provider, else localStorage. */\nexport function useDockStore(own?: DockPositionStore): DockPositionStore {\n const provided = useContext(DockStoreContext);\n return own ?? provided ?? defaultStore;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAAA,gBAAmG;;;ACkBnG,IAAAC,gBASO;AACP,2BAA+B;AAC/B,oBAA6D;AAC7D,IAAAA,gBAAuC;;;ACahC,IAAM,sBAAsB;AAG5B,IAAM,yBAAyB;AAEtC,IAAM,WAAW,CAAC,WAAgC,OAAO,SAAS,MAAM;AACxE,IAAM,UAAU,CAAC,WAAgC,OAAO,WAAW,KAAK;AAGjE,SAAS,SAAS,QAAoB,QAAoB,MAAgB,UAAiC;AAChH,SAAO;AAAA,IACL,MAAM,SAAS,MAAM,IAAI,OAAO,IAAI,SAAS,QAAQ,KAAK,QAAQ,OAAO;AAAA,IACzE,KAAK,QAAQ,MAAM,IAAI,OAAO,IAAI,SAAS,SAAS,KAAK,SAAS,OAAO;AAAA,EAC3E;AACF;AAGO,SAAS,WAAW,OAAoB,QAAoB,MAAgB,UAAgC;AACjH,SAAO;AAAA,IACL,GAAG,SAAS,MAAM,IAAI,MAAM,OAAO,SAAS,QAAQ,KAAK,QAAQ,MAAM;AAAA,IACvE,GAAG,QAAQ,MAAM,IAAI,MAAM,MAAM,SAAS,SAAS,KAAK,SAAS,MAAM;AAAA,EACzE;AACF;AAQO,SAAS,YACd,QACA,QACA,MACA,UACA,QAAmB,CAAC,GACR;AACZ,QAAM,SAAS,MAAM,UAAU;AAC/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AQ,YAAY,QAAQ,cAAc,QAAQ,QAAS,MAAK,GAAG,IAAI;AAAA,EAClF;AACA,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,MAAM,WAAW;AAC9B,QAAM,QAAuB,EAAE,GAAG,MAAM,OAAO,GAAG,KAAK,OAAO,GAAI,OAAO,KAAK,YAAY,QAAQ,CAAC,EAAG;AACtG,SACE,4CAAC,YAAY,UAAZ,EAAqB,OAAO,MAC3B;AAAA,IAAC;AAAA;AAAA,MACE,GAAI;AAAA,MACL,KAAK,KAAK;AAAA,MACV,aAAW,MAAM;AAAA,MACjB,iBAAe,KAAK,WAAW,KAAK;AAAA,MACpC;AAAA,MACC,GAAI,OAAO,EAAE,eAAe,KAAK,YAAY,eAAe,oBAAoB,GAAG,IAAI,CAAC;AAAA,MAExF,iBAAO,MAAM,aAAa,aAAa,MAAM,SAAS,IAAI,IAAI,MAAM;AAAA;AAAA,EACvE,GACF;AAEJ;AAOO,SAAS,WAAW,EAAE,OAAO,eAAe,GAAG,KAAK,GAA+B;AACxF,QAAM,OAAO,eAAe;AAC5B,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAG,KAAK;AAAA,MACT,OAAO,EAAE,GAAG,OAAO,GAAG,KAAK,YAAY,MAAM;AAAA,MAC7C,eAAe,CAAC,UAAU;AACxB,wBAAgB,KAAK;AACrB,aAAK,YAAY,cAAc,KAAK;AAAA,MACtC;AAAA;AAAA,EACF;AAEJ;","names":["import_react","import_react"]}
|
package/dist/dock.d.cts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties, PointerEvent, HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dock geometry — the pure half of a dock: corner-relative offsets, the clamp
|
|
5
|
+
* that keeps a dock reachable, the nearest-corner snap and the exclusion
|
|
6
|
+
* avoidance. No DOM reads except `avoidExclusions`, which is handed the
|
|
7
|
+
* rectangles it must stay off.
|
|
8
|
+
*
|
|
9
|
+
* A dock's position is stored as an OFFSET FROM A CORNER, not as left/top: a
|
|
10
|
+
* dock resting 12px from the bottom-right keeps that relationship when the
|
|
11
|
+
* window is resized, and a position saved on a wide monitor comes back next to
|
|
12
|
+
* the same corner on a laptop.
|
|
13
|
+
*/
|
|
14
|
+
type DockCorner = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
15
|
+
/** Distance in px from the corner's horizontal (`x`) and vertical (`y`) edges. */
|
|
16
|
+
interface DockOffset {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}
|
|
20
|
+
/** A remembered position: an offset and the corner it is measured from (the dock's corner when omitted). */
|
|
21
|
+
interface DockPosition extends DockOffset {
|
|
22
|
+
corner?: DockCorner;
|
|
23
|
+
}
|
|
24
|
+
interface DockSize {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
interface DockClamp {
|
|
29
|
+
/** Smallest gap kept between the dock and the viewport edge. Default 8. */
|
|
30
|
+
margin?: number;
|
|
31
|
+
/**
|
|
32
|
+
* How much of the dock must stay on screen. Default: all of it. A dock that
|
|
33
|
+
* may hang off an edge (a pill you can park half-hidden) passes its grab area.
|
|
34
|
+
*/
|
|
35
|
+
minVisible?: DockSize;
|
|
36
|
+
}
|
|
37
|
+
interface ScreenPoint {
|
|
38
|
+
left: number;
|
|
39
|
+
top: number;
|
|
40
|
+
}
|
|
41
|
+
interface ScreenRect extends ScreenPoint {
|
|
42
|
+
right: number;
|
|
43
|
+
bottom: number;
|
|
44
|
+
}
|
|
45
|
+
declare const DEFAULT_DOCK_MARGIN = 8;
|
|
46
|
+
/** A pointer that moved less than this is a click, not a drag. */
|
|
47
|
+
declare const DEFAULT_DRAG_THRESHOLD = 4;
|
|
48
|
+
/** The offset → the dock's top-left in viewport px. */
|
|
49
|
+
declare function toScreen(offset: DockOffset, corner: DockCorner, size: DockSize, viewport: DockSize): ScreenPoint;
|
|
50
|
+
/** A top-left in viewport px → the offset from `corner`. */
|
|
51
|
+
declare function fromScreen(point: ScreenPoint, corner: DockCorner, size: DockSize, viewport: DockSize): DockOffset;
|
|
52
|
+
/**
|
|
53
|
+
* Keep the offset inside the viewport. When the dock is larger than the room
|
|
54
|
+
* there is, its TOP and LEFT stay visible — that is where a header, a grip
|
|
55
|
+
* and a close button live, and an unreachable close button is how a movable
|
|
56
|
+
* notice turns into an unclosable one.
|
|
57
|
+
*/
|
|
58
|
+
declare function clampOffset(offset: DockOffset, corner: DockCorner, size: DockSize, viewport: DockSize, clamp?: DockClamp): DockOffset;
|
|
59
|
+
/** The corner nearest the dock's centre — where a dropped dock re-anchors when snapping is on. */
|
|
60
|
+
declare function nearestCorner(point: ScreenPoint, size: DockSize, viewport: DockSize): DockCorner;
|
|
61
|
+
/**
|
|
62
|
+
* Keep the dock off fixed controls it must never cover (a table's pager, a
|
|
63
|
+
* composer) without reserving page space. A clear position is returned
|
|
64
|
+
* untouched; a covering one moves to the NEAREST clear candidate — never
|
|
65
|
+
* further than it has to.
|
|
66
|
+
*/
|
|
67
|
+
declare function avoidExclusions(point: ScreenPoint, size: DockSize, excluded: readonly ScreenRect[], gap: number, keepOnScreen: (point: ScreenPoint) => ScreenPoint): ScreenPoint;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Where a dock remembers its position.
|
|
71
|
+
*
|
|
72
|
+
* The package never decides WHICH storage a host uses: a host that keeps
|
|
73
|
+
* browser state behind its own declared keys (or syncs it per user) hands a
|
|
74
|
+
* `DockPositionStore` to `<DockProvider>`, or to one dock through its `store`
|
|
75
|
+
* option. With neither, positions live in this browser's localStorage under
|
|
76
|
+
* `matrx:summon:dock:<id>` — every read and write is SSR-safe and never throws
|
|
77
|
+
* (private mode, quota and disabled storage degrade to "nothing stored").
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
interface DockPositionStore {
|
|
81
|
+
read(id: string): DockPosition | null;
|
|
82
|
+
/** `null` forgets the position (the dock goes back to its resting place). */
|
|
83
|
+
write(id: string, position: DockPosition | null): void;
|
|
84
|
+
}
|
|
85
|
+
declare const DOCK_STORAGE_PREFIX = "matrx:summon:dock:";
|
|
86
|
+
/** Accept only a well-formed position; anything else reads as "nothing stored". */
|
|
87
|
+
declare function parseDockPosition(value: unknown): DockPosition | null;
|
|
88
|
+
/** The default store: one localStorage key per dock id. */
|
|
89
|
+
declare function createLocalDockStore(prefix?: string): DockPositionStore;
|
|
90
|
+
/** A store that remembers nothing — for docks whose place is per-moment (a toast, a stacked widget). */
|
|
91
|
+
declare const memoryOnlyDockStore: DockPositionStore;
|
|
92
|
+
interface DockProviderProps {
|
|
93
|
+
store: DockPositionStore;
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
/** Hand every dock below one position store (the host's declared keys, a per-user sync). */
|
|
97
|
+
declare function DockProvider({ store, children }: DockProviderProps): ReactNode;
|
|
98
|
+
/** The store a dock uses: its own option, else the nearest provider, else localStorage. */
|
|
99
|
+
declare function useDockStore(own?: DockPositionStore): DockPositionStore;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* `useDock()` — the one primitive for floating chrome-less cards, pills and docks.
|
|
103
|
+
*
|
|
104
|
+
* THE RULE (paid for in the Workflow Studio's FloatingChatPanel and chat's
|
|
105
|
+
* ChatPanel): a pointer move paints the CSS `translate` property inside ONE
|
|
106
|
+
* requestAnimationFrame and React state is committed EXACTLY ONCE, on release.
|
|
107
|
+
* Writing state per pointer event re-renders whatever streams inside the dock
|
|
108
|
+
* sixty times a second. `translate` composes with the host's own `transform`
|
|
109
|
+
* and with any `left/right/top/bottom` it computes, so a host that builds its
|
|
110
|
+
* own placement (CSS variables, lifts) still drags without re-rendering.
|
|
111
|
+
*
|
|
112
|
+
* What else it carries:
|
|
113
|
+
* - a drag is never a click: below `threshold` px the gesture stays a click;
|
|
114
|
+
* past it the trailing click is swallowed once;
|
|
115
|
+
* - the position is an offset from a corner, clamped to the viewport on every
|
|
116
|
+
* render (a position saved on a wide monitor never strands the dock), and
|
|
117
|
+
* can snap to the nearest corner on release;
|
|
118
|
+
* - it remembers its place per dock id (the store chain in ./store) or reports
|
|
119
|
+
* it to a controlled host (`position` + `onPositionChange`, e.g. per-user sync);
|
|
120
|
+
* - it joins the window manager's z-order lane on press (raised above every
|
|
121
|
+
* window, below modals) when a SummonProvider is present;
|
|
122
|
+
* - THE CURSOR LAW: the drag holds `grabbing` with design-system `holdDragCursor`;
|
|
123
|
+
* - zero cost until mounted: no listener exists outside an active press.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/** CSS placement used while the dock has no position (never moved, no `defaultPosition`). */
|
|
127
|
+
interface DockAnchor {
|
|
128
|
+
top?: string;
|
|
129
|
+
bottom?: string;
|
|
130
|
+
left?: string;
|
|
131
|
+
right?: string;
|
|
132
|
+
/** Centre horizontally (`left: 50%` + translateX(-50%)). */
|
|
133
|
+
centerX?: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** Controls inside the handle that stay controls — a press there never starts a drag. */
|
|
136
|
+
declare const DEFAULT_DOCK_IGNORE = "button,a,input,select,textarea,[contenteditable='true'],[data-no-drag]";
|
|
137
|
+
interface UseDockOptions {
|
|
138
|
+
/** Identity: the remembered position, the z-order lane entry. Unique per dock. */
|
|
139
|
+
id: string;
|
|
140
|
+
/** The corner positions are measured from. Default "bottom-right". */
|
|
141
|
+
corner?: DockCorner;
|
|
142
|
+
/** Resting offset from `corner` before the person moves it. Omit to rest on `anchor`. */
|
|
143
|
+
defaultPosition?: DockOffset | null;
|
|
144
|
+
/** CSS resting place when there is no position at all. */
|
|
145
|
+
anchor?: DockAnchor;
|
|
146
|
+
/** Controlled position (the host owns storage, e.g. a per-user preference). `null` = resting. */
|
|
147
|
+
position?: DockPosition | null;
|
|
148
|
+
/** Told once per drag, on release, and on `reset()` (with `null`). */
|
|
149
|
+
onPositionChange?: (position: DockPosition | null) => void;
|
|
150
|
+
/** Remember the position across reloads (uncontrolled only). Default true. */
|
|
151
|
+
persist?: boolean;
|
|
152
|
+
/** This dock's own store; otherwise the nearest `<DockProvider>`, else localStorage. */
|
|
153
|
+
store?: DockPositionStore;
|
|
154
|
+
/** Default true. Pass false on surfaces that must not move (a phone sheet). */
|
|
155
|
+
draggable?: boolean;
|
|
156
|
+
/** Allow touch drags. Default true; a dock that fights page scroll passes false. */
|
|
157
|
+
touch?: boolean;
|
|
158
|
+
/** Px a pointer must travel before a press becomes a drag. Default 4. */
|
|
159
|
+
threshold?: number;
|
|
160
|
+
clamp?: DockClamp;
|
|
161
|
+
/** Fixed controls the dock must stay off (nearest clear spot wins). */
|
|
162
|
+
avoid?: {
|
|
163
|
+
selector: string;
|
|
164
|
+
gap?: number;
|
|
165
|
+
};
|
|
166
|
+
/** On release, re-anchor to the nearest corner. Default false. */
|
|
167
|
+
snapToCorner?: boolean;
|
|
168
|
+
/** z-index before the first press raises it into the window lane. */
|
|
169
|
+
zIndex?: number;
|
|
170
|
+
/** Raise into the window manager's z-order lane on press. Default true. */
|
|
171
|
+
raiseOnPress?: boolean;
|
|
172
|
+
/** Selector of controls inside the handle that never start a drag. `null` = every press may drag. */
|
|
173
|
+
ignore?: string | null;
|
|
174
|
+
}
|
|
175
|
+
interface DockHandleBindings {
|
|
176
|
+
onPointerDown(event: PointerEvent<HTMLElement>): void;
|
|
177
|
+
style: CSSProperties;
|
|
178
|
+
"data-dock-handle": "";
|
|
179
|
+
}
|
|
180
|
+
interface DockApi {
|
|
181
|
+
/** Attach to the element that MOVES. */
|
|
182
|
+
ref: (element: HTMLElement | null) => void;
|
|
183
|
+
element: HTMLElement | null;
|
|
184
|
+
/** Spread onto the moving element: fixed placement (placed or anchored) + z-index. */
|
|
185
|
+
style: CSSProperties;
|
|
186
|
+
/** Spread onto the element you drag BY (or the whole dock). */
|
|
187
|
+
handleProps: DockHandleBindings;
|
|
188
|
+
/** The clamped offset from `corner`; null while resting on `anchor`. */
|
|
189
|
+
offset: DockOffset | null;
|
|
190
|
+
/** The corner `offset` is measured from. */
|
|
191
|
+
corner: DockCorner;
|
|
192
|
+
/** True from the moment a press passes the threshold until release. */
|
|
193
|
+
dragging: boolean;
|
|
194
|
+
/** The person has moved it (a remembered or controlled position exists). */
|
|
195
|
+
moved: boolean;
|
|
196
|
+
/** Current z-index: the lane's once raised, else the `zIndex` option. */
|
|
197
|
+
zIndex: number | undefined;
|
|
198
|
+
/** Forget the position; the dock returns to its resting place. */
|
|
199
|
+
reset(): void;
|
|
200
|
+
}
|
|
201
|
+
declare function useDock(options: UseDockOptions): DockApi;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* `<Dock>` — the component form of `useDock()`: a fixed, chrome-less element that
|
|
205
|
+
* moves. Drag it by a `<DockHandle>` inside it, or by the whole dock with
|
|
206
|
+
* `handle="self"`. `useDockContext()` reaches the dock's API from anywhere inside
|
|
207
|
+
* (a "Move back to the corner" menu item calls `reset()`).
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/** The enclosing dock's API; throws outside a `<Dock>`. */
|
|
211
|
+
declare function useDockContext(): DockApi;
|
|
212
|
+
interface DockProps extends UseDockOptions, Omit<HTMLAttributes<HTMLDivElement>, "id" | "children" | "draggable"> {
|
|
213
|
+
/** "self": the whole dock is the drag handle. Default: only `<DockHandle>`s drag. */
|
|
214
|
+
handle?: "self" | "inner";
|
|
215
|
+
children?: ReactNode | ((dock: DockApi) => ReactNode);
|
|
216
|
+
}
|
|
217
|
+
declare function Dock(props: DockProps): ReactNode;
|
|
218
|
+
interface DockHandleProps extends HTMLAttributes<HTMLDivElement> {
|
|
219
|
+
children?: ReactNode;
|
|
220
|
+
}
|
|
221
|
+
/** The part of a `<Dock>` you drag it by. Buttons and fields inside stay controls. */
|
|
222
|
+
declare function DockHandle({ style, onPointerDown, ...rest }: DockHandleProps): ReactNode;
|
|
223
|
+
|
|
224
|
+
export { DEFAULT_DOCK_IGNORE, DEFAULT_DOCK_MARGIN, DEFAULT_DRAG_THRESHOLD, DOCK_STORAGE_PREFIX, Dock, type DockAnchor, type DockApi, type DockClamp, type DockCorner, DockHandle, type DockHandleBindings, type DockHandleProps, type DockOffset, type DockPosition, type DockPositionStore, type DockProps, DockProvider, type DockProviderProps, type DockSize, type ScreenPoint, type ScreenRect, type UseDockOptions, avoidExclusions, clampOffset, createLocalDockStore, fromScreen, memoryOnlyDockStore, nearestCorner, parseDockPosition, toScreen, useDock, useDockContext, useDockStore };
|
package/dist/dock.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties, PointerEvent, HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dock geometry — the pure half of a dock: corner-relative offsets, the clamp
|
|
5
|
+
* that keeps a dock reachable, the nearest-corner snap and the exclusion
|
|
6
|
+
* avoidance. No DOM reads except `avoidExclusions`, which is handed the
|
|
7
|
+
* rectangles it must stay off.
|
|
8
|
+
*
|
|
9
|
+
* A dock's position is stored as an OFFSET FROM A CORNER, not as left/top: a
|
|
10
|
+
* dock resting 12px from the bottom-right keeps that relationship when the
|
|
11
|
+
* window is resized, and a position saved on a wide monitor comes back next to
|
|
12
|
+
* the same corner on a laptop.
|
|
13
|
+
*/
|
|
14
|
+
type DockCorner = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
15
|
+
/** Distance in px from the corner's horizontal (`x`) and vertical (`y`) edges. */
|
|
16
|
+
interface DockOffset {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}
|
|
20
|
+
/** A remembered position: an offset and the corner it is measured from (the dock's corner when omitted). */
|
|
21
|
+
interface DockPosition extends DockOffset {
|
|
22
|
+
corner?: DockCorner;
|
|
23
|
+
}
|
|
24
|
+
interface DockSize {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
interface DockClamp {
|
|
29
|
+
/** Smallest gap kept between the dock and the viewport edge. Default 8. */
|
|
30
|
+
margin?: number;
|
|
31
|
+
/**
|
|
32
|
+
* How much of the dock must stay on screen. Default: all of it. A dock that
|
|
33
|
+
* may hang off an edge (a pill you can park half-hidden) passes its grab area.
|
|
34
|
+
*/
|
|
35
|
+
minVisible?: DockSize;
|
|
36
|
+
}
|
|
37
|
+
interface ScreenPoint {
|
|
38
|
+
left: number;
|
|
39
|
+
top: number;
|
|
40
|
+
}
|
|
41
|
+
interface ScreenRect extends ScreenPoint {
|
|
42
|
+
right: number;
|
|
43
|
+
bottom: number;
|
|
44
|
+
}
|
|
45
|
+
declare const DEFAULT_DOCK_MARGIN = 8;
|
|
46
|
+
/** A pointer that moved less than this is a click, not a drag. */
|
|
47
|
+
declare const DEFAULT_DRAG_THRESHOLD = 4;
|
|
48
|
+
/** The offset → the dock's top-left in viewport px. */
|
|
49
|
+
declare function toScreen(offset: DockOffset, corner: DockCorner, size: DockSize, viewport: DockSize): ScreenPoint;
|
|
50
|
+
/** A top-left in viewport px → the offset from `corner`. */
|
|
51
|
+
declare function fromScreen(point: ScreenPoint, corner: DockCorner, size: DockSize, viewport: DockSize): DockOffset;
|
|
52
|
+
/**
|
|
53
|
+
* Keep the offset inside the viewport. When the dock is larger than the room
|
|
54
|
+
* there is, its TOP and LEFT stay visible — that is where a header, a grip
|
|
55
|
+
* and a close button live, and an unreachable close button is how a movable
|
|
56
|
+
* notice turns into an unclosable one.
|
|
57
|
+
*/
|
|
58
|
+
declare function clampOffset(offset: DockOffset, corner: DockCorner, size: DockSize, viewport: DockSize, clamp?: DockClamp): DockOffset;
|
|
59
|
+
/** The corner nearest the dock's centre — where a dropped dock re-anchors when snapping is on. */
|
|
60
|
+
declare function nearestCorner(point: ScreenPoint, size: DockSize, viewport: DockSize): DockCorner;
|
|
61
|
+
/**
|
|
62
|
+
* Keep the dock off fixed controls it must never cover (a table's pager, a
|
|
63
|
+
* composer) without reserving page space. A clear position is returned
|
|
64
|
+
* untouched; a covering one moves to the NEAREST clear candidate — never
|
|
65
|
+
* further than it has to.
|
|
66
|
+
*/
|
|
67
|
+
declare function avoidExclusions(point: ScreenPoint, size: DockSize, excluded: readonly ScreenRect[], gap: number, keepOnScreen: (point: ScreenPoint) => ScreenPoint): ScreenPoint;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Where a dock remembers its position.
|
|
71
|
+
*
|
|
72
|
+
* The package never decides WHICH storage a host uses: a host that keeps
|
|
73
|
+
* browser state behind its own declared keys (or syncs it per user) hands a
|
|
74
|
+
* `DockPositionStore` to `<DockProvider>`, or to one dock through its `store`
|
|
75
|
+
* option. With neither, positions live in this browser's localStorage under
|
|
76
|
+
* `matrx:summon:dock:<id>` — every read and write is SSR-safe and never throws
|
|
77
|
+
* (private mode, quota and disabled storage degrade to "nothing stored").
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
interface DockPositionStore {
|
|
81
|
+
read(id: string): DockPosition | null;
|
|
82
|
+
/** `null` forgets the position (the dock goes back to its resting place). */
|
|
83
|
+
write(id: string, position: DockPosition | null): void;
|
|
84
|
+
}
|
|
85
|
+
declare const DOCK_STORAGE_PREFIX = "matrx:summon:dock:";
|
|
86
|
+
/** Accept only a well-formed position; anything else reads as "nothing stored". */
|
|
87
|
+
declare function parseDockPosition(value: unknown): DockPosition | null;
|
|
88
|
+
/** The default store: one localStorage key per dock id. */
|
|
89
|
+
declare function createLocalDockStore(prefix?: string): DockPositionStore;
|
|
90
|
+
/** A store that remembers nothing — for docks whose place is per-moment (a toast, a stacked widget). */
|
|
91
|
+
declare const memoryOnlyDockStore: DockPositionStore;
|
|
92
|
+
interface DockProviderProps {
|
|
93
|
+
store: DockPositionStore;
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
/** Hand every dock below one position store (the host's declared keys, a per-user sync). */
|
|
97
|
+
declare function DockProvider({ store, children }: DockProviderProps): ReactNode;
|
|
98
|
+
/** The store a dock uses: its own option, else the nearest provider, else localStorage. */
|
|
99
|
+
declare function useDockStore(own?: DockPositionStore): DockPositionStore;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* `useDock()` — the one primitive for floating chrome-less cards, pills and docks.
|
|
103
|
+
*
|
|
104
|
+
* THE RULE (paid for in the Workflow Studio's FloatingChatPanel and chat's
|
|
105
|
+
* ChatPanel): a pointer move paints the CSS `translate` property inside ONE
|
|
106
|
+
* requestAnimationFrame and React state is committed EXACTLY ONCE, on release.
|
|
107
|
+
* Writing state per pointer event re-renders whatever streams inside the dock
|
|
108
|
+
* sixty times a second. `translate` composes with the host's own `transform`
|
|
109
|
+
* and with any `left/right/top/bottom` it computes, so a host that builds its
|
|
110
|
+
* own placement (CSS variables, lifts) still drags without re-rendering.
|
|
111
|
+
*
|
|
112
|
+
* What else it carries:
|
|
113
|
+
* - a drag is never a click: below `threshold` px the gesture stays a click;
|
|
114
|
+
* past it the trailing click is swallowed once;
|
|
115
|
+
* - the position is an offset from a corner, clamped to the viewport on every
|
|
116
|
+
* render (a position saved on a wide monitor never strands the dock), and
|
|
117
|
+
* can snap to the nearest corner on release;
|
|
118
|
+
* - it remembers its place per dock id (the store chain in ./store) or reports
|
|
119
|
+
* it to a controlled host (`position` + `onPositionChange`, e.g. per-user sync);
|
|
120
|
+
* - it joins the window manager's z-order lane on press (raised above every
|
|
121
|
+
* window, below modals) when a SummonProvider is present;
|
|
122
|
+
* - THE CURSOR LAW: the drag holds `grabbing` with design-system `holdDragCursor`;
|
|
123
|
+
* - zero cost until mounted: no listener exists outside an active press.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/** CSS placement used while the dock has no position (never moved, no `defaultPosition`). */
|
|
127
|
+
interface DockAnchor {
|
|
128
|
+
top?: string;
|
|
129
|
+
bottom?: string;
|
|
130
|
+
left?: string;
|
|
131
|
+
right?: string;
|
|
132
|
+
/** Centre horizontally (`left: 50%` + translateX(-50%)). */
|
|
133
|
+
centerX?: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** Controls inside the handle that stay controls — a press there never starts a drag. */
|
|
136
|
+
declare const DEFAULT_DOCK_IGNORE = "button,a,input,select,textarea,[contenteditable='true'],[data-no-drag]";
|
|
137
|
+
interface UseDockOptions {
|
|
138
|
+
/** Identity: the remembered position, the z-order lane entry. Unique per dock. */
|
|
139
|
+
id: string;
|
|
140
|
+
/** The corner positions are measured from. Default "bottom-right". */
|
|
141
|
+
corner?: DockCorner;
|
|
142
|
+
/** Resting offset from `corner` before the person moves it. Omit to rest on `anchor`. */
|
|
143
|
+
defaultPosition?: DockOffset | null;
|
|
144
|
+
/** CSS resting place when there is no position at all. */
|
|
145
|
+
anchor?: DockAnchor;
|
|
146
|
+
/** Controlled position (the host owns storage, e.g. a per-user preference). `null` = resting. */
|
|
147
|
+
position?: DockPosition | null;
|
|
148
|
+
/** Told once per drag, on release, and on `reset()` (with `null`). */
|
|
149
|
+
onPositionChange?: (position: DockPosition | null) => void;
|
|
150
|
+
/** Remember the position across reloads (uncontrolled only). Default true. */
|
|
151
|
+
persist?: boolean;
|
|
152
|
+
/** This dock's own store; otherwise the nearest `<DockProvider>`, else localStorage. */
|
|
153
|
+
store?: DockPositionStore;
|
|
154
|
+
/** Default true. Pass false on surfaces that must not move (a phone sheet). */
|
|
155
|
+
draggable?: boolean;
|
|
156
|
+
/** Allow touch drags. Default true; a dock that fights page scroll passes false. */
|
|
157
|
+
touch?: boolean;
|
|
158
|
+
/** Px a pointer must travel before a press becomes a drag. Default 4. */
|
|
159
|
+
threshold?: number;
|
|
160
|
+
clamp?: DockClamp;
|
|
161
|
+
/** Fixed controls the dock must stay off (nearest clear spot wins). */
|
|
162
|
+
avoid?: {
|
|
163
|
+
selector: string;
|
|
164
|
+
gap?: number;
|
|
165
|
+
};
|
|
166
|
+
/** On release, re-anchor to the nearest corner. Default false. */
|
|
167
|
+
snapToCorner?: boolean;
|
|
168
|
+
/** z-index before the first press raises it into the window lane. */
|
|
169
|
+
zIndex?: number;
|
|
170
|
+
/** Raise into the window manager's z-order lane on press. Default true. */
|
|
171
|
+
raiseOnPress?: boolean;
|
|
172
|
+
/** Selector of controls inside the handle that never start a drag. `null` = every press may drag. */
|
|
173
|
+
ignore?: string | null;
|
|
174
|
+
}
|
|
175
|
+
interface DockHandleBindings {
|
|
176
|
+
onPointerDown(event: PointerEvent<HTMLElement>): void;
|
|
177
|
+
style: CSSProperties;
|
|
178
|
+
"data-dock-handle": "";
|
|
179
|
+
}
|
|
180
|
+
interface DockApi {
|
|
181
|
+
/** Attach to the element that MOVES. */
|
|
182
|
+
ref: (element: HTMLElement | null) => void;
|
|
183
|
+
element: HTMLElement | null;
|
|
184
|
+
/** Spread onto the moving element: fixed placement (placed or anchored) + z-index. */
|
|
185
|
+
style: CSSProperties;
|
|
186
|
+
/** Spread onto the element you drag BY (or the whole dock). */
|
|
187
|
+
handleProps: DockHandleBindings;
|
|
188
|
+
/** The clamped offset from `corner`; null while resting on `anchor`. */
|
|
189
|
+
offset: DockOffset | null;
|
|
190
|
+
/** The corner `offset` is measured from. */
|
|
191
|
+
corner: DockCorner;
|
|
192
|
+
/** True from the moment a press passes the threshold until release. */
|
|
193
|
+
dragging: boolean;
|
|
194
|
+
/** The person has moved it (a remembered or controlled position exists). */
|
|
195
|
+
moved: boolean;
|
|
196
|
+
/** Current z-index: the lane's once raised, else the `zIndex` option. */
|
|
197
|
+
zIndex: number | undefined;
|
|
198
|
+
/** Forget the position; the dock returns to its resting place. */
|
|
199
|
+
reset(): void;
|
|
200
|
+
}
|
|
201
|
+
declare function useDock(options: UseDockOptions): DockApi;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* `<Dock>` — the component form of `useDock()`: a fixed, chrome-less element that
|
|
205
|
+
* moves. Drag it by a `<DockHandle>` inside it, or by the whole dock with
|
|
206
|
+
* `handle="self"`. `useDockContext()` reaches the dock's API from anywhere inside
|
|
207
|
+
* (a "Move back to the corner" menu item calls `reset()`).
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/** The enclosing dock's API; throws outside a `<Dock>`. */
|
|
211
|
+
declare function useDockContext(): DockApi;
|
|
212
|
+
interface DockProps extends UseDockOptions, Omit<HTMLAttributes<HTMLDivElement>, "id" | "children" | "draggable"> {
|
|
213
|
+
/** "self": the whole dock is the drag handle. Default: only `<DockHandle>`s drag. */
|
|
214
|
+
handle?: "self" | "inner";
|
|
215
|
+
children?: ReactNode | ((dock: DockApi) => ReactNode);
|
|
216
|
+
}
|
|
217
|
+
declare function Dock(props: DockProps): ReactNode;
|
|
218
|
+
interface DockHandleProps extends HTMLAttributes<HTMLDivElement> {
|
|
219
|
+
children?: ReactNode;
|
|
220
|
+
}
|
|
221
|
+
/** The part of a `<Dock>` you drag it by. Buttons and fields inside stay controls. */
|
|
222
|
+
declare function DockHandle({ style, onPointerDown, ...rest }: DockHandleProps): ReactNode;
|
|
223
|
+
|
|
224
|
+
export { DEFAULT_DOCK_IGNORE, DEFAULT_DOCK_MARGIN, DEFAULT_DRAG_THRESHOLD, DOCK_STORAGE_PREFIX, Dock, type DockAnchor, type DockApi, type DockClamp, type DockCorner, DockHandle, type DockHandleBindings, type DockHandleProps, type DockOffset, type DockPosition, type DockPositionStore, type DockProps, DockProvider, type DockProviderProps, type DockSize, type ScreenPoint, type ScreenRect, type UseDockOptions, avoidExclusions, clampOffset, createLocalDockStore, fromScreen, memoryOnlyDockStore, nearestCorner, parseDockPosition, toScreen, useDock, useDockContext, useDockStore };
|