@mgamadeus/ddd-design-studio 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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: 'Neu laden (R)', boardsUpdated: count => `${count} aktualisiert` },
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,
@@ -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-RFW6QPM3.js";
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(Button, { variant: "outline", className: "w-full", onClick: onOpen, children: [
2168
- /* @__PURE__ */ jsx7(Maximize22, {}),
2169
- " Open focus view"
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 ",
@@ -2250,7 +2263,10 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2250
2263
  const [canvasAspectRatio, setCanvasAspectRatio] = useState8(null);
2251
2264
  useCollapsedSidebarWhileMounted(shell?.useSidebarCollapsed);
2252
2265
  const debouncedSearch = canvasState.debounced.q;
2253
- const [initialViewport] = useState8(() => parseViewportParam(canvasState.values.vp));
2266
+ const [codeAtLoad] = useState8(() => searchParams.get(CODE_PARAM));
2267
+ const [initialViewport] = useState8(
2268
+ () => codeAtLoad ? null : parseViewportParam(canvasState.values.vp)
2269
+ );
2254
2270
  const [hasInitialFilterWithViewport] = useState8(
2255
2271
  () => initialViewport !== null && Boolean(canvasState.values.q.trim() || canvasState.values.section || canvasState.values.status)
2256
2272
  );
@@ -2473,12 +2489,13 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2473
2489
  );
2474
2490
  const matchingBoardIds = useMemo2(() => {
2475
2491
  const searchText = debouncedSearch.trim().toLowerCase();
2492
+ const searchCode = normalizeBoardCode(searchText);
2476
2493
  if (!searchText && !sectionFilter && !statusFilter) return null;
2477
2494
  const matching = /* @__PURE__ */ new Set();
2478
2495
  for (const board of boards) {
2479
2496
  if (sectionFilter && (board.sectionKey ?? "") !== sectionFilter) continue;
2480
2497
  if (statusFilter && board.status !== statusFilter) continue;
2481
- if (searchText && !(board.title ?? "").toLowerCase().includes(searchText) && !(board.boardKey ?? "").toLowerCase().includes(searchText)) {
2498
+ if (searchText && !(board.title ?? "").toLowerCase().includes(searchText) && !(board.boardKey ?? "").toLowerCase().includes(searchText) && !(searchCode && normalizeBoardCode(board.code ?? "").includes(searchCode))) {
2482
2499
  continue;
2483
2500
  }
2484
2501
  matching.add(boardNodeId(board.boardKey ?? ""));
@@ -2556,6 +2573,28 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2556
2573
  setFocusedBoardId(nodeId);
2557
2574
  if (!initialViewport) requestFit([nodeId]);
2558
2575
  }, [boardParam, boards.length, boardsByNodeId, requestFit, initialViewport]);
2576
+ const codeParam = searchParams.get(CODE_PARAM);
2577
+ const handledCodeRef = useRef3(null);
2578
+ useEffect6(() => {
2579
+ if (!codeParam) {
2580
+ if (handledCodeRef.current !== null) handledCodeRef.current = "";
2581
+ return;
2582
+ }
2583
+ if (boards.length === 0 || handledCodeRef.current === codeParam) return;
2584
+ const isFirstView = handledCodeRef.current === null && codeParam === codeAtLoad;
2585
+ handledCodeRef.current = codeParam;
2586
+ writeSearchParams({ [CODE_PARAM]: null });
2587
+ const board = findBoardForCode(boards, codeParam);
2588
+ if (!board?.boardKey) {
2589
+ notify.error(texts.boardCodeNotFound(codeParam));
2590
+ return;
2591
+ }
2592
+ const nodeId = boardNodeId(board.boardKey);
2593
+ setSelectedBoardId(nodeId);
2594
+ setSelectedBoardIds(/* @__PURE__ */ new Set([nodeId]));
2595
+ setIsCommentsPanelOpen(true);
2596
+ if (!isFirstView) requestFit([nodeId]);
2597
+ }, [codeParam, codeAtLoad, boards, writeSearchParams, notify, texts, requestFit]);
2559
2598
  const stepFocus = useCallback2(
2560
2599
  (step) => {
2561
2600
  if (!focusedBoardId || navigationOrder.length === 0) return;
@@ -2605,6 +2644,7 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2605
2644
  canvasKey,
2606
2645
  boardTitle: board.title ?? board.boardKey,
2607
2646
  boardKey: board.boardKey,
2647
+ boardCode: board.code ?? null,
2608
2648
  contentHash: board.contentHash ?? null,
2609
2649
  themeReference: shownThemeReference,
2610
2650
  url: buildBoardDeepLink(
@@ -2645,6 +2685,18 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2645
2685
  ]),
2646
2686
  [copyReferences, buildReferenceFor]
2647
2687
  );
2688
+ const copyBoardLink = useCallback2(
2689
+ async (board) => {
2690
+ if (!board.code || typeof window === "undefined") return;
2691
+ const link = buildBoardCodeLink(window.location.href, board.code, shownLook?.themeId ?? null, shownLook?.mode ?? "light");
2692
+ if (await copyTextToClipboard(link)) {
2693
+ notify.success(texts.boardLinkCopied(board.code));
2694
+ } else {
2695
+ notify.error("Could not copy to the clipboard");
2696
+ }
2697
+ },
2698
+ [shownLook, notify, texts]
2699
+ );
2648
2700
  const seenRevisionRef = useRef3(null);
2649
2701
  const revision = currentRevisionData?.revision;
2650
2702
  const revisionLook = themeArgument ?? "";
@@ -2727,10 +2779,14 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2727
2779
  const focusedBoard = focusedBoardId ? boardsByNodeId.get(focusedBoardId) ?? null : null;
2728
2780
  const threadsOf = (nodeId) => nodeId ? buildCommentThreads(commentsByBoardNodeId.get(nodeId) ?? []) : [];
2729
2781
  const boardsWithOpenThreads = layoutOrder.filter((nodeId) => openThreadCounts.has(nodeId));
2730
- const initialFitNodeIds = useMemo2(
2731
- () => layout.sections[0] ? [sectionNodeId(layout.sections[0].id)] : [],
2732
- [layout]
2782
+ const codeAtLoadBoard = useMemo2(
2783
+ () => codeAtLoad ? findBoardForCode(boards, codeAtLoad) : null,
2784
+ [codeAtLoad, boards]
2733
2785
  );
2786
+ const initialFitNodeIds = useMemo2(() => {
2787
+ if (codeAtLoadBoard?.boardKey) return [boardNodeId(codeAtLoadBoard.boardKey)];
2788
+ return layout.sections[0] ? [sectionNodeId(layout.sections[0].id)] : [];
2789
+ }, [layout, codeAtLoadBoard]);
2734
2790
  const sectionOptions = layout.sections.map((section) => ({ value: section.id, label: section.title }));
2735
2791
  const presentedSectionTitle = presentSectionId ? layout.sections.find((section) => section.id === presentSectionId)?.title ?? null : null;
2736
2792
  const copySelectedRef = useRef3(copySelectedReferences);
@@ -2999,6 +3055,7 @@ var DesignStudioCanvasScreen = ({ projectKey, canvasKey }) => {
2999
3055
  threads: threadsOf(selectedBoardId),
3000
3056
  writesAllowed,
3001
3057
  onOpen: () => selectedBoardId && openBoardFromCanvas(selectedBoardId),
3058
+ onCopyLink: selectedBoard.code ? () => void copyBoardLink(selectedBoard) : void 0,
3002
3059
  onStatusChanged: (status) => selectedBoardId && setBoardStatus(selectedBoardId, status),
3003
3060
  onCopyThreadReference: copyThreadReference
3004
3061
  },