@ggraphic/editor-chrome 0.0.0 → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Originally developed as part of netzbegruenung/Gruenerator (AGPL-3.0);
2
+ relicensed by the copyright holder under AGPL-3.0-only.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
1
  # @ggraphic/editor-chrome
2
2
 
3
- Placeholder without code, published once so the release workflow can be made its trusted publisher. Install `@ggraphic/editor-chrome@alpha`.
3
+ > **Alpha, untested.** Early work in progress: the API can change without notice. See the [repository README](../../README.md#ggraphic).
4
+
5
+ The sidebar shell of the ggraphic editor, without the canvas editor: a tab rail with a flyout panel on desktop, a bottom tab bar with a draggable sheet on mobile. No konva, tiptap, yjs or editor store. AGPL-3.0-only.
6
+
7
+ `@ggraphic/editor` builds its own sidebar from this package and re-exports it from `@ggraphic/editor/sidebar` with the editor's texts and save status. Use this package directly when a host needs the same chrome around something that is not a canvas.
8
+
9
+ ## Install
10
+
11
+ Inside the monorepo: `"@ggraphic/editor-chrome": "workspace:*"`. Peers: `react`, `react-dom` (19).
12
+
13
+ ## Use
14
+
15
+ ```css
16
+ /* A host on Tailwind v4 */
17
+ @import 'tailwindcss';
18
+ @import '@ggraphic/editor-chrome/tokens.css'; /* optional: neutral --editor-* defaults */
19
+ @import '@ggraphic/editor-chrome/styles.css'; /* sheet motion, thin scrollbar */
20
+ @import '@ggraphic/editor-chrome/tailwind.css'; /* scan + touch-target, kbd, canvas-mobile variants */
21
+ ```
22
+
23
+ `tokens.css` follows the system colour scheme like the editor's tokens: under `prefers-color-scheme: dark` the chrome turns dark unless `<html>` carries `data-theme="light"`. A light-only host sets `data-theme="light"`, or leaves `tokens.css` out and declares the `--editor-*` tokens itself.
24
+
25
+ A host with its own Tailwind theme that already defines `kbd`, `touch-target`, `max-canvas-mobile`/`canvas-mobile` and `animate-subsection-fade-in` adds only an `@source` for this package's `dist` instead of `tailwind.css`.
26
+
27
+ ```tsx
28
+ import { CHROME_ROOT_ATTR, SidebarPanel, SidebarTabBar } from '@ggraphic/editor-chrome';
29
+
30
+ <div
31
+ {...{ [CHROME_ROOT_ATTR]: '' }}
32
+ className="relative flex h-dvh flex-col canvas-mobile:flex-row"
33
+ >
34
+ <SidebarTabBar tabs={tabs} activeTab={active} onTabClick={toggle} ariaLabel="Bereiche" />
35
+ <main className="flex-1">…</main>
36
+ <SidebarPanel isOpen={active !== null} title={title} onClose={close}>
37
+ …
38
+ </SidebarPanel>
39
+ </div>;
40
+ ```
41
+
42
+ Layout contract:
43
+
44
+ - The root carries `data-editor-chrome-root` and is `position: relative`. On mobile the sheet sits in the flow between the content (`order` before it) and the tab bar (`order-2`); while it closes it leaves the flow and is positioned against this root.
45
+ - The desktop panel is absolutely positioned at `top: var(--editor-topbar-height)` and `left: var(--image-studio-tab-bar-width, 76px)` of that root, 348px wide. While it is open it writes `--canvas-panel-width: 348px` on `<html>`, so the content can make room.
46
+ - Mobile means: the box of an `EditorBoxProvider` narrower than 900px, otherwise the window (`(max-width: 899px)`). `useIsCanvasMobile` answers it.
47
+ - Texts default to German; pass `ariaLabel` (tab bar), `closeLabel` and `collapseLabel` (panel), `viewLabel` (`SubsectionTabBar`) to change them.
48
+ - One copy: `@ggraphic/editor` depends on this package with a caret range. A host that also depends on it directly keeps both on compatible versions, or the editor box context (`EditorBoxProvider`) splits across two copies.
49
+ - Keyboard focus rings (`kbd:`) need `data-focus-modality="keyboard"` on `<html>` while the last input was a key; the host sets it.
@@ -0,0 +1,4 @@
1
+ This package bundles no third-party components.
2
+
3
+ Its npm dependencies keep their own licenses: clsx (MIT), tailwind-merge (MIT)
4
+ and react-icons (MIT; the icon sets it ships carry their own licenses).
@@ -0,0 +1,2 @@
1
+ import type { SidebarPanelProps } from './types.js';
2
+ export declare function SidebarPanel({ isOpen, title, children, onClose, closeLabel, collapseLabel, }: SidebarPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,219 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
4
+ import { PiX } from 'react-icons/pi';
5
+ import { cn } from './cn.js';
6
+ import { CHROME_ROOT_ATTR, SIDEBAR_PANEL_ID } from './constants.js';
7
+ import { isFocusLost, isKeyboardModality } from './focus.js';
8
+ import { useIsCanvasMobile } from './hooks/useIsCanvasMobile.js';
9
+ import { useMobileSheet } from './hooks/useMobileSheet.js';
10
+ const CHROME_ROOT = `[${CHROME_ROOT_ATTR}]`;
11
+ /**
12
+ * Desktop-rail panel width in px. Mirrors the `348px` in the
13
+ * `canvas-mobile:w-[348px]`/`max-w-[348px]` classes below — kept as a separate
14
+ * literal because Tailwind's static scanner needs the class's arbitrary value
15
+ * to appear as literal text, so it can't be generated from this constant.
16
+ * Change both together.
17
+ */
18
+ const SIDEBAR_PANEL_DESKTOP_WIDTH_PX = 348;
19
+ /**
20
+ * Upper bound for one slide (enter 280 ms, exit 200 ms). `transitionend`
21
+ * never comes under reduced motion without a transform transition, while
22
+ * hidden, or in jsdom — the timer moves the phase on regardless.
23
+ */
24
+ const SHEET_TRANSITION_FALLBACK_MS = 350;
25
+ /** Die Tabs, die diesen Bereich öffnen (`SidebarTabBar`). */
26
+ const PANEL_TAB = `[aria-controls="${SIDEBAR_PANEL_ID}"]`;
27
+ const TABBABLE = 'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';
28
+ const FOCUS_RING = 'outline-none kbd:focus-visible:outline-2 kbd:focus-visible:outline-solid kbd:focus-visible:-outline-offset-2 kbd:focus-visible:outline-[var(--editor-accent)]';
29
+ const defaultCloseLabel = (title) => `${title ?? 'Bereich'} schließen`;
30
+ export function SidebarPanel({ isOpen, title, children, onClose, closeLabel = defaultCloseLabel, collapseLabel = 'Panel einklappen', }) {
31
+ const isDesktop = !useIsCanvasMobile();
32
+ // Reports the panel's desktop-rail width so CanvasEditorLayout can indent the
33
+ // stage clear of it (Befund 8: the panel otherwise sits on top of the stage).
34
+ // Cleared on close, unmount, and the switch to the mobile bottom-sheet layout.
35
+ useEffect(() => {
36
+ if (!isOpen || !isDesktop) {
37
+ document.documentElement.style.removeProperty('--canvas-panel-width');
38
+ return;
39
+ }
40
+ document.documentElement.style.setProperty('--canvas-panel-width', `${SIDEBAR_PANEL_DESKTOP_WIDTH_PX}px`);
41
+ return () => {
42
+ document.documentElement.style.removeProperty('--canvas-panel-width');
43
+ };
44
+ }, [isOpen, isDesktop]);
45
+ const [phase, setPhase] = useState(isOpen ? 'entering' : 'closed');
46
+ // Content stays mounted from the first `open` until the sheet is gone, so a
47
+ // reopen while it slides out does not blank it.
48
+ const [hasContent, setHasContent] = useState(false);
49
+ const [prevIsOpen, setPrevIsOpen] = useState(isOpen);
50
+ if (isOpen !== prevIsOpen) {
51
+ setPrevIsOpen(isOpen);
52
+ if (!isDesktop) {
53
+ if (isOpen)
54
+ setPhase('entering');
55
+ else if (phase !== 'closed')
56
+ setPhase('closing');
57
+ }
58
+ }
59
+ // Desktop has no slide: the phase mirrors `isOpen`, so crossing the
60
+ // breakpoint later never puts a half-finished sheet in the flow.
61
+ if (isDesktop && (phase !== (isOpen ? 'open' : 'closed') || hasContent !== isOpen)) {
62
+ setPhase(isOpen ? 'open' : 'closed');
63
+ setHasContent(isOpen);
64
+ }
65
+ // The editor clears the section (and title) in the same render that closes
66
+ // the panel; the sheet slides out with what it showed while open.
67
+ const [shown, setShown] = useState({ children, title });
68
+ if (isOpen && (shown.children !== children || shown.title !== title)) {
69
+ setShown({ children, title });
70
+ }
71
+ const sheetChildren = isOpen ? children : shown.children;
72
+ const sheetTitle = isOpen ? title : shown.title;
73
+ const finishEnter = useCallback(() => {
74
+ setPhase((p) => (p === 'entering' ? 'open' : p));
75
+ setHasContent(true);
76
+ }, []);
77
+ // Also the hook-in for a drag that already carried the sheet off-screen.
78
+ const finishClose = useCallback(() => {
79
+ setPhase('closed');
80
+ setHasContent(false);
81
+ }, []);
82
+ useEffect(() => {
83
+ if (isDesktop || (phase !== 'entering' && phase !== 'closing'))
84
+ return;
85
+ const t = window.setTimeout(phase === 'entering' ? finishEnter : finishClose, SHEET_TRANSITION_FALLBACK_MS);
86
+ return () => window.clearTimeout(t);
87
+ }, [isDesktop, phase, finishEnter, finishClose]);
88
+ const { handleRef, sheetRef, contentRef } = useMobileSheet({
89
+ isOpen: isOpen && !isDesktop,
90
+ onClose: onClose || (() => { }),
91
+ // The drag already carried the sheet off-screen: drop it without a second exit.
92
+ onDragClosed: finishClose,
93
+ // A tab switch during the drag's slide-out must not close the new tab.
94
+ closeKey: title ?? null,
95
+ threshold: 100,
96
+ velocityThreshold: 0.5,
97
+ });
98
+ // A snap-back leaves the drag hook's inline transition on the section; it
99
+ // would override the phase transition from canvas-editor.css.
100
+ useLayoutEffect(() => {
101
+ const sheet = sheetRef.current;
102
+ if (sheet && (phase === 'entering' || phase === 'closing'))
103
+ sheet.style.transition = '';
104
+ }, [phase, sheetRef]);
105
+ // Where the sheet rests in the flow, as a distance from the layout's bottom
106
+ // edge. A closing sheet leaves the flow there (absolute), so the canvas
107
+ // above grows and refits at once while the sheet slides out over it.
108
+ // Measured from offset boxes, which ignore the slide/drag transform, and
109
+ // already while entering: a close before the slide-in ends needs it too.
110
+ useLayoutEffect(() => {
111
+ const sheet = sheetRef.current;
112
+ if (isDesktop || (phase !== 'open' && phase !== 'entering') || !sheet)
113
+ return;
114
+ const measure = () => {
115
+ const layout = sheet.closest(CHROME_ROOT);
116
+ // The layout root is the containing block on mobile (max-canvas-mobile:relative).
117
+ if (!layout || sheet.offsetParent !== layout)
118
+ return;
119
+ const rest = layout.clientHeight - (sheet.offsetTop + sheet.offsetHeight);
120
+ sheet.style.setProperty('--sheet-rest-bottom', `${Math.max(0, rest)}px`);
121
+ };
122
+ measure();
123
+ window.addEventListener('resize', measure);
124
+ return () => window.removeEventListener('resize', measure);
125
+ }, [isDesktop, phase, sheetRef]);
126
+ // Like a dialog: focus goes back to what opened the sheet (its tab) once the
127
+ // sheet is gone — `inert` during the slide-out blurs whatever had focus inside
128
+ // it, which would otherwise drop focus to <body>. The opener follows tab
129
+ // switches: the last element focused outside the sheet while it is up.
130
+ const openerRef = useRef(null);
131
+ const isUp = !isDesktop && phase !== 'closed';
132
+ useEffect(() => {
133
+ if (!isUp)
134
+ return;
135
+ const remember = (el) => {
136
+ if (el instanceof HTMLElement && el !== document.body && !sheetRef.current?.contains(el)) {
137
+ openerRef.current = el;
138
+ }
139
+ };
140
+ remember(document.activeElement);
141
+ const onFocusIn = (e) => remember(e.target);
142
+ document.addEventListener('focusin', onFocusIn);
143
+ return () => document.removeEventListener('focusin', onFocusIn);
144
+ }, [isUp, sheetRef]);
145
+ useEffect(() => {
146
+ if (isDesktop || phase !== 'closed')
147
+ return;
148
+ const opener = openerRef.current;
149
+ openerRef.current = null;
150
+ const active = document.activeElement;
151
+ if (opener?.isConnected && (!active || active === document.body))
152
+ opener.focus();
153
+ }, [isDesktop, phase]);
154
+ // Öffnet ein Tab per Tastatur den Bereich (oder wechselt ihn), geht der
155
+ // Fokus hinein: mobil auf die Überschrift, auf dem Desktop auf das erste
156
+ // Bedienelement, solange keines da ist auf den Bereich selbst. Nach einem
157
+ // Klick bleibt er auf dem Tab — sonst schluckte etwa das Suchfeld der
158
+ // Elemente Entf und die Strg-Kürzel, die dem ausgewählten Element gelten.
159
+ // Öffnet ihn die Auswahl auf der Fläche, bleibt der Fokus ohnehin, wo er ist.
160
+ const headingRef = useRef(null);
161
+ const panelRef = useRef(null);
162
+ const panelTabRef = useRef(null);
163
+ useEffect(() => {
164
+ if (!isOpen)
165
+ return;
166
+ const active = document.activeElement;
167
+ if (!(active instanceof Element) || !active.closest(PANEL_TAB))
168
+ return;
169
+ if (!isKeyboardModality())
170
+ return;
171
+ if (!isDesktop) {
172
+ headingRef.current?.focus();
173
+ return;
174
+ }
175
+ const panel = panelRef.current;
176
+ if (!panel)
177
+ return;
178
+ const first = panel.querySelector(`.sidebar-panel__content :is(${TABBABLE})`);
179
+ (first ?? panel).focus();
180
+ }, [isOpen, title, isDesktop]);
181
+ // Desktop: zu wird der Bereich über seinen Tab, „Panel einklappen" oder von
182
+ // aussen. Ging der Fokus dabei mit dem Bereich verloren, bekommt ihn der Tab,
183
+ // der ihn zuletzt offen zeigte. Mobil erledigt das der Rückweg zum Öffner oben.
184
+ useEffect(() => {
185
+ if (!isDesktop)
186
+ return;
187
+ if (isOpen) {
188
+ const scope = panelRef.current?.closest(CHROME_ROOT) ?? document;
189
+ panelTabRef.current = scope.querySelector(`${PANEL_TAB}[aria-expanded="true"]`);
190
+ return;
191
+ }
192
+ const tab = panelTabRef.current;
193
+ panelTabRef.current = null;
194
+ if (tab?.isConnected && isFocusLost())
195
+ tab.focus();
196
+ }, [isOpen, title, isDesktop]);
197
+ if (!isDesktop) {
198
+ if (phase === 'closed')
199
+ return null;
200
+ // Mobiles Sheet: liegt im Fluss zwischen Canvas und Leiste (order-1), der
201
+ // Canvas darüber schrumpft und bleibt sichtbar. Beim Schließen verlässt es
202
+ // den Fluss (absolute, an seinem Ruheplatz), damit der Canvas sofort wächst.
203
+ // Jedes Sheet hat denselben Aufbau: Griff, Titel mit Schließen, dann der
204
+ // Inhalt des Bereichs.
205
+ return (_jsxs("section", { ref: sheetRef, id: SIDEBAR_PANEL_ID, "aria-label": sheetTitle, "data-state": phase, inert: phase === 'closing', onTransitionEnd: (e) => {
206
+ if (e.target !== e.currentTarget)
207
+ return;
208
+ if (e.propertyName !== 'transform' && e.propertyName !== 'opacity')
209
+ return;
210
+ if (phase === 'entering')
211
+ finishEnter();
212
+ else if (phase === 'closing')
213
+ finishClose();
214
+ }, className: cn('sidebar-panel order-1 flex-none flex flex-col h-[clamp(300px,48dvh,420px)] bg-[var(--editor-surface)] rounded-t-[20px] shadow-[0_-4px_24px_rgba(0,0,0,0.12)] overflow-hidden', phase === 'closing' && 'absolute inset-x-0 bottom-[var(--sheet-rest-bottom,0px)] z-[100]'), children: [_jsxs("div", { ref: handleRef, className: "flex-none touch-none", children: [_jsx("div", { className: "sidebar-panel__drag-handle h-5 -mb-1 flex items-center justify-center cursor-grab active:cursor-grabbing", children: _jsx("div", { className: "w-9 h-1 rounded-sm bg-[var(--editor-border-strong)]" }) }), _jsxs("div", { className: "h-8 max-canvas-mobile:h-11 px-5 flex items-center justify-between gap-3", children: [_jsx("h2", { ref: headingRef, tabIndex: -1, className: cn('m-0 text-[17px] font-bold text-[var(--editor-text)] truncate', FOCUS_RING), children: sheetTitle }), onClose && (_jsx("button", { type: "button", onClick: onClose, "aria-label": closeLabel(sheetTitle ?? null), className: "flex-none size-8 max-canvas-mobile:size-11 rounded-full border-none bg-[var(--editor-tile)] text-[var(--editor-text-secondary)] flex items-center justify-center cursor-pointer", children: _jsx(PiX, { size: 16 }) }))] })] }), _jsx("div", { ref: contentRef, className: cn('sidebar-panel__content flex-1 min-h-0 overflow-y-auto overscroll-contain px-5 pt-4 pb-5 flex flex-col gap-4', hasContent && 'sidebar-panel__content--in'), children: hasContent && sheetChildren })] }));
215
+ }
216
+ if (!isOpen)
217
+ return null;
218
+ return (_jsxs("div", { ref: panelRef, id: SIDEBAR_PANEL_ID, role: "region", "aria-label": title, tabIndex: -1, className: cn(FOCUS_RING, 'sidebar-panel absolute bg-[var(--editor-surface)] flex flex-col z-[101]', 'top-[var(--editor-topbar-height)] bottom-0 right-auto w-[348px] max-w-[348px] min-w-0 overflow-visible border-r border-[var(--editor-border)]', 'left-[var(--image-studio-tab-bar-width,76px)]'), children: [_jsx("div", { className: "sidebar-panel__content flex-1 min-h-0 overflow-y-auto scrollbar-thin p-3 flex flex-col gap-3", children: children }), onClose && (_jsx("button", { type: "button", onClick: onClose, "aria-label": collapseLabel, title: collapseLabel, className: "absolute top-1/2 -right-[13px] -translate-y-1/2 flex items-center justify-center w-[26px] h-[52px] rounded-r-lg border border-l-0 border-[var(--editor-border-soft)] bg-[var(--editor-surface)] text-[var(--editor-text-muted)] shadow-[2px_0_6px_rgba(0,0,0,0.05)] cursor-pointer transition-colors duration-150 hover:text-[var(--editor-active-fg)]", children: _jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M9.5 3 5 8l4.5 5" }) }) }))] }));
219
+ }
@@ -0,0 +1,7 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { SidebarTabBarProps } from './types.js';
3
+ /**
4
+ * The editor's section tabs: a vertical rail on desktop, a fixed bottom bar on mobile (the box
5
+ * of an `EditorBoxProvider` narrower than 900px, else the window).
6
+ */
7
+ export declare const SidebarTabBar: <Id extends string = string>(props: SidebarTabBarProps<Id>) => ReactElement;
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ import { memo, useCallback } from 'react';
4
+ import { cn } from './cn.js';
5
+ import { SIDEBAR_PANEL_ID } from './constants.js';
6
+ import { useIsCanvasMobile } from './hooks/useIsCanvasMobile.js';
7
+ const TabButton = memo(function TabButton({ tab, isActive, isDisabled, isMobile, onTabClick, }) {
8
+ const Icon = tab.icon;
9
+ const handleClick = useCallback(() => {
10
+ onTabClick(tab.id);
11
+ }, [onTabClick, tab.id]);
12
+ if (isMobile) {
13
+ return (_jsxs("button", { className: cn('flex-1 min-w-0 flex flex-col items-center gap-1 border-none bg-transparent p-0 cursor-pointer select-none', isActive ? 'text-[var(--editor-active-fg)]' : 'text-[var(--editor-text-secondary)]', isDisabled && 'opacity-40 cursor-not-allowed'), onClick: handleClick, disabled: isDisabled, "aria-label": tab.ariaLabel, "aria-expanded": isActive, "aria-controls": SIDEBAR_PANEL_ID, "data-tour": `canvas-tab-${tab.id}`, type: "button", children: [_jsx("span", { className: cn('flex items-center justify-center w-[52px] h-8 rounded-2xl transition-colors duration-150', isActive && 'bg-[var(--editor-active-bg)]'), children: _jsx(Icon, { size: 20 }) }), _jsx("span", { className: "text-[11px] font-bold tracking-[-0.01em] whitespace-nowrap overflow-hidden text-ellipsis max-w-full", children: tab.label })] }));
14
+ }
15
+ return (_jsxs("button", { className: cn('sidebar-tab-bar__tab w-[62px] py-[9px] flex flex-col items-center justify-center gap-1.5 border-none bg-transparent rounded-[10px] cursor-pointer text-[var(--editor-text-secondary)] transition-[background-color,color] duration-200 [&>svg]:size-[21px] [&>svg]:shrink-0 hover:enabled:bg-[var(--editor-surface-hover)] disabled:opacity-40 disabled:cursor-not-allowed', isActive &&
16
+ 'sidebar-tab-bar__tab--active bg-[var(--editor-active-bg)] text-[var(--editor-active-fg)] font-bold'), onClick: handleClick, disabled: isDisabled, "aria-label": tab.ariaLabel, "aria-expanded": isActive, "aria-controls": SIDEBAR_PANEL_ID, title: tab.label, "data-tour": `canvas-tab-${tab.id}`, type: "button", children: [_jsx(Icon, { size: 21 }), _jsx("span", { className: "sidebar-tab-bar__label text-[10.5px] font-semibold whitespace-nowrap overflow-hidden text-ellipsis max-w-full", children: tab.label })] }));
17
+ });
18
+ function SidebarTabBarImpl({ tabs, activeTab, onTabClick, disabledTabs = [], horizontal = false, ariaLabel = 'Editor-Bereiche', footer, }) {
19
+ // The buttons take any string id; the host's union comes back through its own callback.
20
+ const handleTabClick = onTabClick;
21
+ const isMobile = useIsCanvasMobile();
22
+ const isHorizontal = horizontal || isMobile;
23
+ // Eine feste Leiste: immer dieselben Einträge an derselben Stelle. Sie liegt
24
+ // im Fluss unter dem Sheet (order-2), damit der Canvas darüber schrumpft,
25
+ // statt verdeckt zu werden.
26
+ if (isMobile) {
27
+ return (_jsx("nav", { "aria-label": ariaLabel, "data-suppress-feedback-launcher": "", className: "order-2 flex-none flex h-[calc(64px+env(safe-area-inset-bottom))] pt-2 px-1 pb-[env(safe-area-inset-bottom)] bg-[var(--editor-surface)] border-t border-[var(--editor-border)]", children: tabs.map((tab) => (_jsx(TabButton, { tab: tab, isActive: activeTab === tab.id, isDisabled: disabledTabs.includes(tab.id), isMobile: isMobile, onTabClick: handleTabClick }, tab.id))) }));
28
+ }
29
+ return (_jsxs("nav", { "aria-label": ariaLabel, "data-tour": "canvas-tabs", className: cn('sidebar-tab-bar flex flex-col items-center justify-start gap-1 pt-2 shrink-0 w-[76px] h-full bg-[var(--editor-surface)] border-r border-[var(--editor-border)]', isHorizontal && 'flex-row'), children: [tabs.map((tab) => (_jsx(TabButton, { tab: tab, isActive: activeTab === tab.id, isDisabled: disabledTabs.includes(tab.id), isMobile: isMobile, onTabClick: handleTabClick }, tab.id))), footer != null && (_jsxs(_Fragment, { children: [_jsx("div", { className: "sidebar-tab-bar__separator w-8 h-px bg-[var(--editor-border-strong)] my-3" }), footer] }))] }));
30
+ }
31
+ /**
32
+ * The editor's section tabs: a vertical rail on desktop, a fixed bottom bar on mobile (the box
33
+ * of an `EditorBoxProvider` narrower than 900px, else the window).
34
+ */
35
+ export const SidebarTabBar = memo(SidebarTabBarImpl);
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { IconType } from 'react-icons';
3
+ export interface Subsection {
4
+ id: string;
5
+ icon: IconType;
6
+ label: string;
7
+ content: ReactNode;
8
+ }
9
+ export interface SubsectionTabBarProps {
10
+ subsections: Subsection[];
11
+ defaultSubsection?: string;
12
+ /** Accessible name of the mobile chip row. */
13
+ viewLabel?: string;
14
+ }
15
+ export declare function SubsectionTabBar({ subsections, defaultSubsection, viewLabel, }: SubsectionTabBarProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ import { useId, useState } from 'react';
4
+ import { cn } from './cn.js';
5
+ import { HIDDEN_SCROLLBAR } from './constants.js';
6
+ import { useIsCanvasMobile } from './hooks/useIsCanvasMobile.js';
7
+ import { useRovingToolbar } from './hooks/useRovingToolbar.js';
8
+ export function SubsectionTabBar({ subsections, defaultSubsection, viewLabel = 'Ansicht', }) {
9
+ const isMobile = useIsCanvasMobile();
10
+ const [localActiveSubsection, setLocalActiveSubsection] = useState(null);
11
+ const baseId = useId();
12
+ const roving = useRovingToolbar('[role="tab"]');
13
+ if (!isMobile) {
14
+ return (_jsx("div", { className: "flex flex-col gap-6", children: subsections.map((sub) => (_jsx("div", { children: sub.content }, sub.id))) }));
15
+ }
16
+ // Mobiles Sheet: Filter-Chips statt einer zweiten Tab-Reihe. Genau ein Chip
17
+ // ist immer aktiv — ein leeres Sheet ist kein gültiger Zustand.
18
+ const activeId = subsections.find((s) => s.id === localActiveSubsection)?.id ??
19
+ subsections.find((s) => s.id === defaultSubsection)?.id ??
20
+ subsections[0]?.id;
21
+ const activeContent = subsections.find((s) => s.id === activeId)?.content;
22
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [subsections.length > 1 && (_jsx("div", { ...roving, role: "tablist", "aria-label": viewLabel, className: cn('flex gap-2 overflow-x-auto -mx-5 px-5 py-1.5 -my-1.5', HIDDEN_SCROLLBAR), children: subsections.map((sub) => {
23
+ const isActive = activeId === sub.id;
24
+ return (_jsx("button", { type: "button", role: "tab", id: `${baseId}-tab-${sub.id}`, "aria-selected": isActive, "aria-controls": `${baseId}-panel`, className: cn('touch-target flex-none h-8 px-3.5 rounded-2xl border-none cursor-pointer text-sm whitespace-nowrap transition-colors duration-150', isActive
25
+ ? 'bg-[var(--editor-active-bg)] text-[var(--editor-active-fg)] font-bold'
26
+ : 'bg-[var(--editor-tile)] text-[var(--editor-text-secondary)] font-semibold'), onClick: () => setLocalActiveSubsection(sub.id), children: sub.label }, sub.id));
27
+ }) })), activeContent && (_jsx("div", { role: "tabpanel", id: `${baseId}-panel`, "aria-labelledby": `${baseId}-tab-${activeId}`, className: "[&>*]:animate-subsection-fade-in", children: activeContent }, activeId))] }));
28
+ }
package/dist/cn.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { type ClassValue } from 'clsx';
2
+ export declare function cn(...inputs: ClassValue[]): string;
package/dist/cn.js ADDED
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ import { clsx } from 'clsx';
3
+ import { extendTailwindMerge } from 'tailwind-merge';
4
+ const customTwMerge = extendTailwindMerge({
5
+ extend: {
6
+ classGroups: {
7
+ 'font-size': [{ text: ['xs', 'sm', 'base', 'lg', 'xl', '2xl'] }],
8
+ },
9
+ theme: {
10
+ spacing: [
11
+ 'xxs',
12
+ 'xs',
13
+ 'sm',
14
+ 'md',
15
+ 'lg',
16
+ 'xl',
17
+ '2xl',
18
+ 'header',
19
+ 'titlebar',
20
+ 'sidebar-collapsed',
21
+ 'sidebar-expanded',
22
+ ],
23
+ color: [
24
+ 'primary',
25
+ 'secondary',
26
+ 'grey',
27
+ 'neutral',
28
+ 'background',
29
+ 'background-pure',
30
+ 'background-alt',
31
+ 'background-sand',
32
+ 'foreground',
33
+ 'foreground-heading',
34
+ 'link',
35
+ 'error',
36
+ 'accent',
37
+ 'disabled',
38
+ 'button-bg',
39
+ 'button-text',
40
+ 'button-hover',
41
+ 'input-bg',
42
+ 'input-text',
43
+ 'input-placeholder',
44
+ 'text-green',
45
+ 'overlay-sm',
46
+ 'overlay-md',
47
+ 'overlay-lg',
48
+ 'hover-alt',
49
+ ],
50
+ radius: ['sm', 'md', 'lg'],
51
+ shadow: [
52
+ 'sm',
53
+ 'md',
54
+ 'lg',
55
+ 'xl',
56
+ 'card-subtle',
57
+ 'card-elevated',
58
+ 'card-floating',
59
+ 'card-dramatic',
60
+ ],
61
+ },
62
+ },
63
+ });
64
+ export function cn(...inputs) {
65
+ return customTwMerge(clsx(inputs));
66
+ }
@@ -0,0 +1,10 @@
1
+ /** Id of the open sidebar panel / mobile sheet; the tab buttons point at it via aria-controls. */
2
+ export declare const SIDEBAR_PANEL_ID = "canvas-sidebar-panel";
3
+ /**
4
+ * Marks the root the chrome lays out in. The mobile sheet measures its resting place against it
5
+ * and the desktop panel looks up its tab inside it. The canvas editor's layout root carries it;
6
+ * any other host puts it on the box that holds the tab bar and the panel.
7
+ */
8
+ export declare const CHROME_ROOT_ATTR = "data-editor-chrome-root";
9
+ /** Horizontal scroll container without a visible scrollbar */
10
+ export declare const HIDDEN_SCROLLBAR = "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden [-webkit-overflow-scrolling:touch]";
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ /** Id of the open sidebar panel / mobile sheet; the tab buttons point at it via aria-controls. */
3
+ export const SIDEBAR_PANEL_ID = 'canvas-sidebar-panel';
4
+ /**
5
+ * Marks the root the chrome lays out in. The mobile sheet measures its resting place against it
6
+ * and the desktop panel looks up its tab inside it. The canvas editor's layout root carries it;
7
+ * any other host puts it on the box that holds the tab bar and the panel.
8
+ */
9
+ export const CHROME_ROOT_ATTR = 'data-editor-chrome-root';
10
+ /** Horizontal scroll container without a visible scrollbar */
11
+ export const HIDDEN_SCROLLBAR = '[scrollbar-width:none] [&::-webkit-scrollbar]:hidden [-webkit-overflow-scrolling:touch]';
@@ -0,0 +1,3 @@
1
+ /** Kam die letzte Fokusbewegung von der Tastatur? (`data-focus-modality` am `<html>`, siehe `kbd:`) */
2
+ export declare function isKeyboardModality(): boolean;
3
+ export declare function isFocusLost(): boolean;
package/dist/focus.js ADDED
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ /** Kam die letzte Fokusbewegung von der Tastatur? (`data-focus-modality` am `<html>`, siehe `kbd:`) */
3
+ export function isKeyboardModality() {
4
+ return document.documentElement.dataset.focusModality === 'keyboard';
5
+ }
6
+ export function isFocusLost() {
7
+ const active = document.activeElement;
8
+ return active === null || active === document.body;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from 'react';
2
+ /** The part of the window the editor occupies: its root's size, clipped to the window. */
3
+ export interface EditorBox {
4
+ width: number;
5
+ height: number;
6
+ }
7
+ /**
8
+ * Measures the editor root (`useEditorBoxRef`) so layout and canvas fit follow the box the host
9
+ * gives the editor, not the window. Clipped to the window, a full-screen host measures exactly
10
+ * the window, also where `min-h-[500px]` makes the root taller than a landscape phone.
11
+ */
12
+ export declare function EditorBoxProvider({ children }: {
13
+ children: ReactNode;
14
+ }): import("react").JSX.Element;
15
+ /** Ref for the editor root; without an `EditorBoxProvider` it measures nothing. */
16
+ export declare function useEditorBoxRef(): ((root: HTMLElement | null) => (() => void) | undefined) | undefined;
17
+ /** The measured box, or `null` outside an editor or before its root mounted. */
18
+ export declare function useMeasuredEditorBox(): EditorBox | null;
19
+ /** The editor's box; the window where nothing was measured (a canvas outside the editor). */
20
+ export declare function useEditorBox(): EditorBox;
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ import { createContext, useCallback, useContext, useMemo, useState, useSyncExternalStore, } from 'react';
4
+ const EditorBoxContext = createContext(null);
5
+ /**
6
+ * Measures the editor root (`useEditorBoxRef`) so layout and canvas fit follow the box the host
7
+ * gives the editor, not the window. Clipped to the window, a full-screen host measures exactly
8
+ * the window, also where `min-h-[500px]` makes the root taller than a landscape phone.
9
+ */
10
+ export function EditorBoxProvider({ children }) {
11
+ const [box, setBox] = useState(null);
12
+ const measure = useCallback((root) => {
13
+ if (!root)
14
+ return undefined;
15
+ const update = () => {
16
+ const rect = root.getBoundingClientRect();
17
+ // A root without a box (hidden by the host, or no layout at all) says nothing about the
18
+ // space the editor will get; until it has one, the window decides.
19
+ if (rect.width === 0 || rect.height === 0) {
20
+ setBox(null);
21
+ return;
22
+ }
23
+ const width = Math.min(rect.width, window.innerWidth);
24
+ const height = Math.min(rect.height, window.innerHeight);
25
+ setBox((prev) => prev?.width === width && prev.height === height ? prev : { width, height });
26
+ };
27
+ // Measured while React commits, so the first paint already uses the box.
28
+ update();
29
+ const observer = new ResizeObserver(update);
30
+ observer.observe(root);
31
+ window.addEventListener('resize', update);
32
+ return () => {
33
+ observer.disconnect();
34
+ window.removeEventListener('resize', update);
35
+ };
36
+ }, []);
37
+ const value = useMemo(() => ({ box, measure }), [box, measure]);
38
+ return _jsx(EditorBoxContext.Provider, { value: value, children: children });
39
+ }
40
+ /** Ref for the editor root; without an `EditorBoxProvider` it measures nothing. */
41
+ export function useEditorBoxRef() {
42
+ return useContext(EditorBoxContext)?.measure;
43
+ }
44
+ /** The measured box, or `null` outside an editor or before its root mounted. */
45
+ export function useMeasuredEditorBox() {
46
+ return useContext(EditorBoxContext)?.box ?? null;
47
+ }
48
+ const SERVER_WINDOW = { width: Infinity, height: Infinity };
49
+ let windowBox = SERVER_WINDOW;
50
+ function readWindow() {
51
+ const { innerWidth: width, innerHeight: height } = window;
52
+ if (windowBox.width !== width || windowBox.height !== height)
53
+ windowBox = { width, height };
54
+ return windowBox;
55
+ }
56
+ function subscribeWindow(onChange) {
57
+ window.addEventListener('resize', onChange);
58
+ return () => window.removeEventListener('resize', onChange);
59
+ }
60
+ /** The editor's box; the window where nothing was measured (a canvas outside the editor). */
61
+ export function useEditorBox() {
62
+ const measured = useMeasuredEditorBox();
63
+ const viewport = useSyncExternalStore(subscribeWindow, readWindow, () => SERVER_WINDOW);
64
+ return measured ?? viewport;
65
+ }
@@ -0,0 +1,9 @@
1
+ /** Below this width (px) the editor's box uses the mobile layout. */
2
+ export declare const MOBILE_BREAKPOINT = 900;
3
+ /** Mirrors the `max-canvas-mobile:` variant for a window without a measured editor box. */
4
+ export declare const CANVAS_MOBILE_QUERY = "(max-width: 899px)";
5
+ /**
6
+ * Mobile layout: the editor's box (`EditorBoxProvider`) is narrower than 900px. Outside an editor,
7
+ * or before its root mounted, the window decides, like the `max-canvas-mobile:` media fallback.
8
+ */
9
+ export declare function useIsCanvasMobile(): boolean;
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ import { useCallback, useSyncExternalStore } from 'react';
3
+ import { useMeasuredEditorBox } from './editorBox.js';
4
+ /** Below this width (px) the editor's box uses the mobile layout. */
5
+ export const MOBILE_BREAKPOINT = 900;
6
+ /** Mirrors the `max-canvas-mobile:` variant for a window without a measured editor box. */
7
+ export const CANVAS_MOBILE_QUERY = '(max-width: 899px)';
8
+ // A `useMediaQuery` kept here so the editor needs nothing from the host.
9
+ // Fires only when the result changes.
10
+ function useMediaQuery(query) {
11
+ const subscribe = useCallback((onStoreChange) => {
12
+ const mql = window.matchMedia(query);
13
+ mql.addEventListener('change', onStoreChange);
14
+ return () => mql.removeEventListener('change', onStoreChange);
15
+ }, [query]);
16
+ const getSnapshot = useCallback(() => window.matchMedia(query).matches, [query]);
17
+ const getServerSnapshot = useCallback(() => false, []);
18
+ return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
19
+ }
20
+ /**
21
+ * Mobile layout: the editor's box (`EditorBoxProvider`) is narrower than 900px. Outside an editor,
22
+ * or before its root mounted, the window decides, like the `max-canvas-mobile:` media fallback.
23
+ */
24
+ export function useIsCanvasMobile() {
25
+ const box = useMeasuredEditorBox();
26
+ const narrowWindow = useMediaQuery(CANVAS_MOBILE_QUERY);
27
+ return box ? box.width < MOBILE_BREAKPOINT : narrowWindow;
28
+ }