@mgamadeus/ddd-design-studio 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/canvas/index.js +85 -14
- package/dist/canvas/index.js.map +1 -1
- package/dist/{chunk-RFW6QPM3.js → chunk-ICDABLFY.js} +56 -2
- package/dist/chunk-ICDABLFY.js.map +1 -0
- package/dist/index.d.ts +68 -5
- package/dist/index.js +86 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
- package/dist/chunk-RFW6QPM3.js.map +0 -1
package/README.md
CHANGED
|
@@ -103,9 +103,10 @@ Pass one stable object (a module constant) to `DesignStudioProvider`. Entries na
|
|
|
103
103
|
| `api` | `DesignStudioApi` | the hooks from `createDesignStudioApi` |
|
|
104
104
|
| `apiBaseUrl` | `string` | origin prefixed to the delivery URLs of boards and thumbnails; `''` = same origin |
|
|
105
105
|
| `router.Link` | component `{ href, className, children }` | in-app link |
|
|
106
|
-
| `router.useSearchParams` | `() => { get(key) }` | the current search parameters (reactive); the canvas reads `?board=` |
|
|
106
|
+
| `router.useSearchParams` | `() => { get(key) }` | the current search parameters (reactive); the canvas reads `?board=` and `?code=`, the overview `?code=` |
|
|
107
107
|
| `router.useSearchParamsWriter` | `() => (updates) => void` | replaces search parameters of the current page: no history entry, no scroll jump, other parameters kept, same-tick writes merged; `null` removes one |
|
|
108
108
|
| `router.useUrlState` | `(keys, { stateId, debounceMs, uncounted }) => { values, debounced, setValue }` | the canvas state (`q`, `section`, `status`, `theme`, `mode`, `vp`) in the URL, restored from what the application remembered under `stateId` when the URL has none of the keys |
|
|
109
|
+
| `router.useNavigate` (optional) | `() => (href) => void` | client navigation to an in-app path (query allowed, with a history entry); the overview uses it to open a board code; without it the overview shows a link to click |
|
|
109
110
|
| `paths` | `overview()`, `project(projectKey)`, `canvas(projectKey, canvasKey)` | in-app paths of the studio's pages |
|
|
110
111
|
| `components` | `DesignStudioComponents` | UI slots: `Button`, `Badge`, `Card`, `CardHeader`, `CardTitle`, `CardContent`, `Skeleton`, `Checkbox`, `Label`, `Textarea`, `Dialog`, `DialogContent`, `DialogTitle`, `DialogDescription`, `Popover`, `PopoverTrigger`, `PopoverContent`, `Tooltip`, `TooltipTrigger`, `TooltipContent`, `DropdownMenu`, `DropdownMenuTrigger`, `DropdownMenuContent`, `DropdownMenuItem`, `DropdownMenuSeparator`, `Combobox`, `SearchField`, `QuickFilterPills`, `StatusBadge`, `PageHeader`, `StatusCallout`, `CardGrid`, `PageSections` — each typed with only the props the studio passes ([`src/provider/types.ts`](src/provider/types.ts), interface `DesignStudioComponents`) |
|
|
111
112
|
| `notify` | `success(message)`, `error(message)`, `info(message, { id, action })` | toasts |
|
|
@@ -143,11 +144,14 @@ Inside the package, components read it with `useDesignStudio()` or the narrower
|
|
|
143
144
|
| `themeWithoutDarkMode` | `This theme has no dark mode` |
|
|
144
145
|
| `thumbnailMissing` | `No thumbnail yet` |
|
|
145
146
|
| `referenceNotePlaceholder` | `What should change? (optional, goes into the reference)` |
|
|
147
|
+
| `boardCodeNotFound(code)` | `No board has the code <code>` |
|
|
148
|
+
| `boardLinkCopied(code)` | `Link to <code> copied` |
|
|
149
|
+
| `copyBoardLink` | `Copy link` |
|
|
146
150
|
|
|
147
151
|
```ts
|
|
148
152
|
const ENVIRONMENT: DesignStudioEnvironment = {
|
|
149
153
|
// …
|
|
150
|
-
texts: { reload: '
|
|
154
|
+
texts: { reload: 'Refresh (R)', boardsUpdated: count => `${count} screens changed` },
|
|
151
155
|
};
|
|
152
156
|
```
|
|
153
157
|
|
|
@@ -166,7 +170,7 @@ The package has no router. The application creates one page per screen and tells
|
|
|
166
170
|
| reviews (optional; an empty state in this version) | `DesignStudioReviewsScreen` | none: linked by the application's own navigation |
|
|
167
171
|
|
|
168
172
|
The canvas page keeps its state in search parameters: `board` (the focus view), `q`, `section`, `status`, `theme`,
|
|
169
|
-
`mode`, `vp`. Project and canvas keys in a URL should be validated by the application before a screen is rendered.
|
|
173
|
+
`mode`, `vp`. `code` opens a board by its code (see Board codes) and is removed from the URL once handled. Project and canvas keys in a URL should be validated by the application before a screen is rendered.
|
|
170
174
|
|
|
171
175
|
## Wiring with the Next.js App Router
|
|
172
176
|
|
|
@@ -318,6 +322,20 @@ export default async function DesignCanvasPage({
|
|
|
318
322
|
}
|
|
319
323
|
```
|
|
320
324
|
|
|
325
|
+
## Board codes
|
|
326
|
+
|
|
327
|
+
A canvas with a `code` in the backend config gives every board a short code (`APP ONB-W2`: project code, canvas code,
|
|
328
|
+
board part from the file name or `canvas.json`). The code is shown in the board header and in the selected board's
|
|
329
|
+
panel, the canvas search finds boards by it (`w2`, `ONB-W2`), and references carry it (`code APP ONB-W2`).
|
|
330
|
+
|
|
331
|
+
- **Code link of a canvas:** `<canvas page>?code=APP-ONB-W2` (also `ONB-W2` or `W2`). The canvas moves the view to the
|
|
332
|
+
board, selects it and shows its panel; the parameter is then removed (a reload keeps the place the viewer moved to).
|
|
333
|
+
"Copy link" in the panel copies this link with the current look.
|
|
334
|
+
- **Short link:** `<overview page>?code=APP-ONB-W2` finds the canvas by the code and opens it there (needs
|
|
335
|
+
`router.useNavigate`; without it the overview shows a link). The overview also has a field to type a code.
|
|
336
|
+
- Helpers (pure, exported from the main entry): `boardCodeMatches`, `findBoardForCode`, `codeBelongsToCanvas`,
|
|
337
|
+
`buildBoardCodeLink`, `boardCodeUrlValue`, `normalizeBoardCode`, `CODE_PARAM`.
|
|
338
|
+
|
|
321
339
|
## Reference helpers
|
|
322
340
|
|
|
323
341
|
`buildDesignReference(input)` builds the plain-text block that names one board (optionally a region, a comment thread,
|
package/dist/canvas/index.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import {
|
|
3
|
+
CODE_PARAM,
|
|
4
|
+
boardCodeOf,
|
|
5
|
+
buildBoardCodeLink,
|
|
3
6
|
buildBoardDeepLink,
|
|
4
7
|
buildDesignReference,
|
|
5
8
|
buildThemeReference,
|
|
6
9
|
copyTextToClipboard,
|
|
7
10
|
cx,
|
|
11
|
+
findBoardForCode,
|
|
12
|
+
normalizeBoardCode,
|
|
8
13
|
splitThemeReference,
|
|
9
14
|
useDesignStudio,
|
|
10
15
|
useDesignStudioComponents,
|
|
11
16
|
useDesignStudioTexts
|
|
12
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-ICDABLFY.js";
|
|
13
18
|
|
|
14
19
|
// src/canvas/DesignStudioCanvasScreen.tsx
|
|
15
20
|
import { normalizeDddError as normalizeDddError3 } from "@mgamadeus/ddd-web/api";
|
|
16
21
|
import {
|
|
17
22
|
ClipboardCopy as ClipboardCopy4,
|
|
18
23
|
ImageDown,
|
|
24
|
+
Link2,
|
|
19
25
|
ListFilter,
|
|
20
26
|
LoaderCircle,
|
|
21
27
|
Maximize,
|
|
@@ -427,9 +433,6 @@ var selectVisibleBoardIds = (boards, viewport, screen) => {
|
|
|
427
433
|
return boards.filter((board) => board.x < right && board.x + board.width > left && board.y < bottom && board.y + board.height > top).map((board) => ({ id: board.id, distance: Math.hypot(board.x + board.width / 2 - centreX, board.y + board.height / 2 - centreY) })).sort((first, second) => first.distance - second.distance).map((entry) => entry.id);
|
|
428
434
|
};
|
|
429
435
|
|
|
430
|
-
// src/canvas/boardKey.ts
|
|
431
|
-
var boardCodeOf = (boardKey) => boardKey.replace(/(?:\.dc)?\.html$/, "");
|
|
432
|
-
|
|
433
436
|
// src/canvas/canvasLayout.ts
|
|
434
437
|
var MAX_COLUMNS = 14;
|
|
435
438
|
var BOARD_GAP_X = 44;
|
|
@@ -869,7 +872,7 @@ var BoardNodeComponent = ({ id, data }) => {
|
|
|
869
872
|
if (!liveHtmlUrl) setLoadedFrameUrl(null);
|
|
870
873
|
}, [liveHtmlUrl]);
|
|
871
874
|
const title = board.title ?? board.boardKey ?? "";
|
|
872
|
-
const boardCode = boardCodeOf(board.boardKey ?? "");
|
|
875
|
+
const boardCode = board.code ?? boardCodeOf(board.boardKey ?? "");
|
|
873
876
|
const [isDownloadOpen, setIsDownloadOpen] = useState5(false);
|
|
874
877
|
const pressPointRef = useRef(null);
|
|
875
878
|
const isCompact = thumbnailVariant === "small";
|
|
@@ -2140,13 +2143,16 @@ var SelectedBoardPanel = ({
|
|
|
2140
2143
|
threads,
|
|
2141
2144
|
writesAllowed,
|
|
2142
2145
|
onOpen,
|
|
2146
|
+
onCopyLink,
|
|
2143
2147
|
onStatusChanged,
|
|
2144
2148
|
onCopyThreadReference
|
|
2145
2149
|
}) => {
|
|
2146
2150
|
const { Button } = useDesignStudioComponents();
|
|
2151
|
+
const texts = useDesignStudioTexts();
|
|
2147
2152
|
const [showResolved, setShowResolved] = useState8(false);
|
|
2148
2153
|
return /* @__PURE__ */ jsxs7("div", { className: "space-y-5", children: [
|
|
2149
2154
|
/* @__PURE__ */ jsxs7("div", { className: "space-y-1", children: [
|
|
2155
|
+
board.code && /* @__PURE__ */ jsx7("p", { className: "text-sm font-semibold tabular-nums text-foreground/70", children: board.code }),
|
|
2150
2156
|
/* @__PURE__ */ jsx7("h2", { className: "text-title-card font-semibold break-words", children: board.title }),
|
|
2151
2157
|
/* @__PURE__ */ jsxs7("p", { className: "text-xs text-muted-foreground", children: [
|
|
2152
2158
|
sectionTitle ? `${sectionTitle} \xB7 ` : "",
|
|
@@ -2164,9 +2170,16 @@ var SelectedBoardPanel = ({
|
|
|
2164
2170
|
onStatusChanged
|
|
2165
2171
|
}
|
|
2166
2172
|
),
|
|
2167
|
-
/* @__PURE__ */ jsxs7(
|
|
2168
|
-
/* @__PURE__ */
|
|
2169
|
-
|
|
2173
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex gap-2", children: [
|
|
2174
|
+
/* @__PURE__ */ jsxs7(Button, { variant: "outline", className: "flex-1", onClick: onOpen, children: [
|
|
2175
|
+
/* @__PURE__ */ jsx7(Maximize22, {}),
|
|
2176
|
+
" Open focus view"
|
|
2177
|
+
] }),
|
|
2178
|
+
onCopyLink && /* @__PURE__ */ jsxs7(Button, { variant: "outline", onClick: onCopyLink, "aria-label": `${texts.copyBoardLink}: ${board.code ?? ""}`, children: [
|
|
2179
|
+
/* @__PURE__ */ jsx7(Link2, {}),
|
|
2180
|
+
" ",
|
|
2181
|
+
texts.copyBoardLink
|
|
2182
|
+
] })
|
|
2170
2183
|
] }),
|
|
2171
2184
|
board.contentHash && /* @__PURE__ */ jsxs7("p", { className: "text-xs text-muted-foreground", title: `Content hash of the board file: ${board.contentHash}`, children: [
|
|
2172
2185
|
"Version ",
|
|
@@ -2230,7 +2243,9 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2230
2243
|
const [presentSectionId, setPresentSectionId] = useState8(null);
|
|
2231
2244
|
const [fitRequest, setFitRequest] = useState8(null);
|
|
2232
2245
|
const [tool, setTool] = useState8("hand");
|
|
2233
|
-
const [isCommentsPanelOpen, setIsCommentsPanelOpen] = useState8(
|
|
2246
|
+
const [isCommentsPanelOpen, setIsCommentsPanelOpen] = useState8(
|
|
2247
|
+
() => Boolean(searchParams.get(CODE_PARAM)) || storage.read("commentsPanelOpen") !== "0"
|
|
2248
|
+
);
|
|
2234
2249
|
const canvasState = router.useUrlState(CANVAS_STATE_KEYS, {
|
|
2235
2250
|
stateId: `designCanvas.${projectKey}.${canvasKey}`,
|
|
2236
2251
|
debounceMs: 250,
|
|
@@ -2250,7 +2265,10 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2250
2265
|
const [canvasAspectRatio, setCanvasAspectRatio] = useState8(null);
|
|
2251
2266
|
useCollapsedSidebarWhileMounted(shell?.useSidebarCollapsed);
|
|
2252
2267
|
const debouncedSearch = canvasState.debounced.q;
|
|
2253
|
-
const [
|
|
2268
|
+
const [codeAtLoad] = useState8(() => searchParams.get(CODE_PARAM));
|
|
2269
|
+
const [initialViewport] = useState8(
|
|
2270
|
+
() => codeAtLoad ? null : parseViewportParam(canvasState.values.vp)
|
|
2271
|
+
);
|
|
2254
2272
|
const [hasInitialFilterWithViewport] = useState8(
|
|
2255
2273
|
() => initialViewport !== null && Boolean(canvasState.values.q.trim() || canvasState.values.section || canvasState.values.status)
|
|
2256
2274
|
);
|
|
@@ -2473,12 +2491,13 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2473
2491
|
);
|
|
2474
2492
|
const matchingBoardIds = useMemo2(() => {
|
|
2475
2493
|
const searchText = debouncedSearch.trim().toLowerCase();
|
|
2494
|
+
const searchCode = normalizeBoardCode(searchText);
|
|
2476
2495
|
if (!searchText && !sectionFilter && !statusFilter) return null;
|
|
2477
2496
|
const matching = /* @__PURE__ */ new Set();
|
|
2478
2497
|
for (const board of boards) {
|
|
2479
2498
|
if (sectionFilter && (board.sectionKey ?? "") !== sectionFilter) continue;
|
|
2480
2499
|
if (statusFilter && board.status !== statusFilter) continue;
|
|
2481
|
-
if (searchText && !(board.title ?? "").toLowerCase().includes(searchText) && !(board.boardKey ?? "").toLowerCase().includes(searchText)) {
|
|
2500
|
+
if (searchText && !(board.title ?? "").toLowerCase().includes(searchText) && !(board.boardKey ?? "").toLowerCase().includes(searchText) && !(searchCode && normalizeBoardCode(board.code ?? "").includes(searchCode))) {
|
|
2482
2501
|
continue;
|
|
2483
2502
|
}
|
|
2484
2503
|
matching.add(boardNodeId(board.boardKey ?? ""));
|
|
@@ -2556,6 +2575,40 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2556
2575
|
setFocusedBoardId(nodeId);
|
|
2557
2576
|
if (!initialViewport) requestFit([nodeId]);
|
|
2558
2577
|
}, [boardParam, boards.length, boardsByNodeId, requestFit, initialViewport]);
|
|
2578
|
+
const codeParam = searchParams.get(CODE_PARAM);
|
|
2579
|
+
const handledCodeRef = useRef3(null);
|
|
2580
|
+
useEffect6(() => {
|
|
2581
|
+
if (!codeParam) {
|
|
2582
|
+
if (handledCodeRef.current !== null) handledCodeRef.current = "";
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
if (boards.length === 0 || handledCodeRef.current === codeParam) return;
|
|
2586
|
+
const isFirstView = handledCodeRef.current === null && codeParam === codeAtLoad;
|
|
2587
|
+
handledCodeRef.current = codeParam;
|
|
2588
|
+
writeSearchParams({ [CODE_PARAM]: null });
|
|
2589
|
+
const board = findBoardForCode(boards, codeParam);
|
|
2590
|
+
if (!board?.boardKey) {
|
|
2591
|
+
notify.error(texts.boardCodeNotFound(codeParam));
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
const nodeId = boardNodeId(board.boardKey);
|
|
2595
|
+
setSelectedBoardId(nodeId);
|
|
2596
|
+
setSelectedBoardIds(/* @__PURE__ */ new Set([nodeId]));
|
|
2597
|
+
if (isFirstView) return;
|
|
2598
|
+
if (isCommentsPanelOpen) {
|
|
2599
|
+
requestFit([nodeId]);
|
|
2600
|
+
} else {
|
|
2601
|
+
pendingCodeFitRef.current = nodeId;
|
|
2602
|
+
setIsCommentsPanelOpen(true);
|
|
2603
|
+
}
|
|
2604
|
+
}, [codeParam, codeAtLoad, boards, isCommentsPanelOpen, writeSearchParams, notify, texts, requestFit]);
|
|
2605
|
+
const pendingCodeFitRef = useRef3(null);
|
|
2606
|
+
useEffect6(() => {
|
|
2607
|
+
const nodeId = pendingCodeFitRef.current;
|
|
2608
|
+
if (!nodeId || layout.sections.length === 0) return;
|
|
2609
|
+
pendingCodeFitRef.current = null;
|
|
2610
|
+
requestFit([nodeId]);
|
|
2611
|
+
}, [layout, requestFit]);
|
|
2559
2612
|
const stepFocus = useCallback2(
|
|
2560
2613
|
(step) => {
|
|
2561
2614
|
if (!focusedBoardId || navigationOrder.length === 0) return;
|
|
@@ -2605,6 +2658,7 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2605
2658
|
canvasKey,
|
|
2606
2659
|
boardTitle: board.title ?? board.boardKey,
|
|
2607
2660
|
boardKey: board.boardKey,
|
|
2661
|
+
boardCode: board.code ?? null,
|
|
2608
2662
|
contentHash: board.contentHash ?? null,
|
|
2609
2663
|
themeReference: shownThemeReference,
|
|
2610
2664
|
url: buildBoardDeepLink(
|
|
@@ -2645,6 +2699,18 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2645
2699
|
]),
|
|
2646
2700
|
[copyReferences, buildReferenceFor]
|
|
2647
2701
|
);
|
|
2702
|
+
const copyBoardLink = useCallback2(
|
|
2703
|
+
async (board) => {
|
|
2704
|
+
if (!board.code || typeof window === "undefined") return;
|
|
2705
|
+
const link = buildBoardCodeLink(window.location.href, board.code, shownLook?.themeId ?? null, shownLook?.mode ?? "light");
|
|
2706
|
+
if (await copyTextToClipboard(link)) {
|
|
2707
|
+
notify.success(texts.boardLinkCopied(board.code));
|
|
2708
|
+
} else {
|
|
2709
|
+
notify.error("Could not copy to the clipboard");
|
|
2710
|
+
}
|
|
2711
|
+
},
|
|
2712
|
+
[shownLook, notify, texts]
|
|
2713
|
+
);
|
|
2648
2714
|
const seenRevisionRef = useRef3(null);
|
|
2649
2715
|
const revision = currentRevisionData?.revision;
|
|
2650
2716
|
const revisionLook = themeArgument ?? "";
|
|
@@ -2727,10 +2793,14 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2727
2793
|
const focusedBoard = focusedBoardId ? boardsByNodeId.get(focusedBoardId) ?? null : null;
|
|
2728
2794
|
const threadsOf = (nodeId) => nodeId ? buildCommentThreads(commentsByBoardNodeId.get(nodeId) ?? []) : [];
|
|
2729
2795
|
const boardsWithOpenThreads = layoutOrder.filter((nodeId) => openThreadCounts.has(nodeId));
|
|
2730
|
-
const
|
|
2731
|
-
() =>
|
|
2732
|
-
[
|
|
2796
|
+
const codeAtLoadBoard = useMemo2(
|
|
2797
|
+
() => codeAtLoad ? findBoardForCode(boards, codeAtLoad) : null,
|
|
2798
|
+
[codeAtLoad, boards]
|
|
2733
2799
|
);
|
|
2800
|
+
const initialFitNodeIds = useMemo2(() => {
|
|
2801
|
+
if (codeAtLoadBoard?.boardKey) return [boardNodeId(codeAtLoadBoard.boardKey)];
|
|
2802
|
+
return layout.sections[0] ? [sectionNodeId(layout.sections[0].id)] : [];
|
|
2803
|
+
}, [layout, codeAtLoadBoard]);
|
|
2734
2804
|
const sectionOptions = layout.sections.map((section) => ({ value: section.id, label: section.title }));
|
|
2735
2805
|
const presentedSectionTitle = presentSectionId ? layout.sections.find((section) => section.id === presentSectionId)?.title ?? null : null;
|
|
2736
2806
|
const copySelectedRef = useRef3(copySelectedReferences);
|
|
@@ -2999,6 +3069,7 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
|
|
|
2999
3069
|
threads: threadsOf(selectedBoardId),
|
|
3000
3070
|
writesAllowed,
|
|
3001
3071
|
onOpen: () => selectedBoardId && openBoardFromCanvas(selectedBoardId),
|
|
3072
|
+
onCopyLink: selectedBoard.code ? () => void copyBoardLink(selectedBoard) : void 0,
|
|
3002
3073
|
onStatusChanged: (status) => selectedBoardId && setBoardStatus(selectedBoardId, status),
|
|
3003
3074
|
onCopyThreadReference: copyThreadReference
|
|
3004
3075
|
},
|