@mgamadeus/ddd-design-studio 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ddd-framework
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,359 @@
1
- # Temporary Holding Version
1
+ # @mgamadeus/ddd-design-studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The React frontend of the design review studio for backends built with
4
+ [mgamadeus/ddd](https://github.com/ddd-framework/ddd): an overview of design projects, the canvas of a project (every
5
+ board laid out per section, live sandboxed HTML at close zoom, thumbnails further out), the focus view of one board,
6
+ comment threads with pins, review statuses and plain-text design references for agents.
7
+
8
+ It talks to the API of the Composer package
9
+ [`mgamadeus/ddd-design-studio`](https://github.com/ddd-framework/ddd-design-studio) (same repository, same version
10
+ number). Whatever it needs from the application around it (API client, router, UI primitives, session, storage, texts)
11
+ comes in through one provider; it contains no application code.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @mgamadeus/ddd-design-studio
17
+ # or
18
+ pnpm add @mgamadeus/ddd-design-studio
19
+ ```
20
+
21
+ ESM only. Peer dependencies (installed by the application):
22
+
23
+ | Package | Range |
24
+ |---|---|
25
+ | `react`, `react-dom` | `^19.3.1` |
26
+ | `@reduxjs/toolkit` | `^2.13.0` |
27
+ | `react-redux` | `^9.3.1` |
28
+ | `@mgamadeus/ddd-web` | `^0.3.0` |
29
+ | `@xyflow/react` | `^12.12.1` (loaded only by the `/canvas` entry) |
30
+ | `lucide-react` | `^1.66.0` |
31
+
32
+ `clsx` and `tailwind-merge` are regular dependencies.
33
+
34
+ ## Entries
35
+
36
+ | Import | Content | Loads `@xyflow/react` |
37
+ |---|---|---|
38
+ | `@mgamadeus/ddd-design-studio` | `createDesignStudioApi`, `DesignStudioProvider` and its hooks, `DesignStudioOverviewScreen`, `DesignStudioProjectScreen`, `DesignStudioReviewsScreen`, the reference and theme helpers, the default texts, all types | no |
39
+ | `@mgamadeus/ddd-design-studio/canvas` | `DesignStudioCanvasScreen` | yes, with its stylesheet (`@xyflow/react/dist/style.css`) |
40
+
41
+ Every file of the package starts with `'use client'`: all exports are client code, including the pure helpers. The
42
+ canvas entry imports a stylesheet, so it needs a bundler that handles CSS imports from packages (Next.js, Vite and
43
+ webpack with a CSS loader do). It measures the DOM and renders sandboxed iframes: load it client-only and lazily.
44
+
45
+ ## Requirements of the application
46
+
47
+ - **Tailwind 4 with shadcn tokens.** The package ships no CSS of its own. Its class names are Tailwind utilities, so
48
+ Tailwind must scan the package's build output. In the application's main stylesheet (path relative to that file):
49
+
50
+ ```css
51
+ @import 'tailwindcss';
52
+ @source '../node_modules/@mgamadeus/ddd-design-studio/dist';
53
+ ```
54
+
55
+ The class names use the shadcn colour tokens (`bg-card`, `bg-popover`, `text-muted-foreground`, `bg-primary`,
56
+ `text-primary-foreground`, `border-border`, `ring-ring`, `bg-destructive`, …) and these additional names, which the
57
+ application's stylesheet defines:
58
+ - colours: `brand`, `brand-light`, `brand-emphasis`, `tint`, `tint-strong`, `info`, `success`, `warning`
59
+ - utilities / tokens: `surface-glass-strong`, `shadow-surface-raised`, `text-title-card`, `--nav-h` (height of the
60
+ shell's top bar; the canvas fills `100dvh - var(--nav-h)`)
61
+ - **One RTK Query api** created with `createApi` from `@reduxjs/toolkit/query/react` on a fetch-style base query
62
+ (`createDddBaseQuery` of `@mgamadeus/ddd-web/api`), its reducer and middleware in the store.
63
+ - **UI primitives** with shadcn "new-york" names and behaviour, plus a few page blocks (see
64
+ [Environment](#environment-designstudioenvironment)).
65
+ - **Routes** for the studio's pages (see [Routes](#routes-the-application-creates)).
66
+
67
+ ## API
68
+
69
+ ```ts
70
+ const designStudioApi = createDesignStudioApi({ baseApi, apiPrefix: '/api/admin/designStudio' });
71
+ ```
72
+
73
+ `createDesignStudioApi` calls `baseApi.enhanceEndpoints({ addTagTypes: ['DesignStudio'] }).injectEndpoints(…)` once and
74
+ returns the hooks. One cache tag: every query provides it, every mutation invalidates it.
75
+
76
+ | Hook | Request (below `apiPrefix`) |
77
+ |---|---|
78
+ | `useOverviewQuery` | `GET /overview` |
79
+ | `useThemesQuery` | `GET /themes` |
80
+ | `useCanvasQuery` | `GET /canvases/{projectKey}/{canvasKey}` |
81
+ | `useCanvasRevisionQuery` | `GET /canvases/{projectKey}/{canvasKey}/revision` |
82
+ | `useCanvasCommentsQuery` | `GET /canvases/{projectKey}/{canvasKey}/comments` |
83
+ | `useExpiringCommentsQuery` | `GET /comments/expiring` |
84
+ | `useRequestThumbnailRenderingMutation` | `POST /canvases/{projectKey}/{canvasKey}/thumbnailRenderRequests` |
85
+ | `useSetBoardStatusMutation` | `PATCH /canvases/{projectKey}/{canvasKey}/boards/{boardKey}/status` |
86
+ | `useCreateCommentMutation` | `POST /canvases/{projectKey}/{canvasKey}/boards/{boardKey}/comments` |
87
+ | `useReplyToCommentMutation` | `POST /comments/{designStudioCommentId}/replies` |
88
+ | `usePatchCommentMutation` | `PATCH /comments/{designStudioCommentId}` |
89
+ | `useDeleteCommentMutation` | `DELETE /comments/{designStudioCommentId}` |
90
+ | `useResolveCommentMutation` | `POST /comments/{designStudioCommentId}/resolve` |
91
+ | `useReopenCommentMutation` | `POST /comments/{designStudioCommentId}/reopen` |
92
+ | `useKeepCommentMutation` | `POST /comments/{designStudioCommentId}/keep` |
93
+
94
+ Request bodies are passed as `body`; the canvas, revision, comments and render-request operations take the optional
95
+ `theme` query parameter (`<themeId>[:<mode>]`).
96
+
97
+ ## Environment (`DesignStudioEnvironment`)
98
+
99
+ Pass one stable object (a module constant) to `DesignStudioProvider`. Entries named `use…` are hooks.
100
+
101
+ | Entry | Type | Purpose |
102
+ |---|---|---|
103
+ | `api` | `DesignStudioApi` | the hooks from `createDesignStudioApi` |
104
+ | `apiBaseUrl` | `string` | origin prefixed to the delivery URLs of boards and thumbnails; `''` = same origin |
105
+ | `router.Link` | component `{ href, className, children }` | in-app link |
106
+ | `router.useSearchParams` | `() => { get(key) }` | the current search parameters (reactive); the canvas reads `?board=` |
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
+ | `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
+ | `paths` | `overview()`, `project(projectKey)`, `canvas(projectKey, canvasKey)` | in-app paths of the studio's pages |
110
+ | `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
+ | `notify` | `success(message)`, `error(message)`, `info(message, { id, action })` | toasts |
112
+ | `formatDateTime` | `(value) => string` | a backend date-time for the viewer |
113
+ | `storage` | `read(key)`, `write(key, value)` | per-viewer persistence; keys: `commentsPanelOpen` |
114
+ | `useCanWrite` | `() => boolean` | enables the write controls |
115
+ | `useCurrentAccountId` | `() => number \| null` | the signed-in account (own comments can be deleted) |
116
+ | `shell.useSidebarCollapsed` | optional `() => [isCollapsed, toggle]` | the canvas collapses the shell's sidebar while it is open |
117
+ | `statuses` | `{ [statusKey]: { label, tone, icon?, description? } }` | presentation per review status; an unknown key shows as it is |
118
+ | `statusColors` | optional `{ [statusKey]: cssColour }` | minimap colour per review status |
119
+ | `texts` | optional `Partial<DesignStudioTexts>` | replacements for UI texts (see [Texts](#texts-designstudiotexts)) |
120
+
121
+ Inside the package, components read it with `useDesignStudio()` or the narrower `useDesignStudioApi()`,
122
+ `useDesignStudioComponents()`, `useDesignStudioRouter()`, `useDesignStudioPaths()`, `useDesignStudioNotify()`,
123
+ `useDesignStudioTexts()`.
124
+
125
+ ## Texts (`DesignStudioTexts`)
126
+
127
+ `environment.texts` replaces UI texts of the canvas; an entry left out keeps its English default
128
+ (`DEFAULT_DESIGN_STUDIO_TEXTS`, [`src/provider/texts.ts`](src/provider/texts.ts)). Entries with parameters are functions.
129
+
130
+ | Entry | Default |
131
+ |---|---|
132
+ | `referencesCopied(count)` | `Reference copied` / `References copied (3)` |
133
+ | `boardsUpdated(count)` | `1 board updated` / `3 boards updated` |
134
+ | `showUpdatedBoard` | `Show` |
135
+ | `canvasUpToDate` | `Canvas is up to date` |
136
+ | `reload` | `Reload (R)` |
137
+ | `thumbnailsFailed` | `Thumbnails failed · try again` |
138
+ | `thumbnailsWaitingForRenderer(themeLabel)` | `Thumbnails for <theme> are waiting for the renderer` |
139
+ | `thumbnailsRendering(themeLabel)` | `Thumbnails for <theme> are being rendered` |
140
+ | `thumbnailsFallbackThemeLabel` | `this look` (stands in for a theme without a label) |
141
+ | `thumbnailsMissing(count)` | `3 boards have no thumbnail in this look yet; they appear as soon as they are rendered.` |
142
+ | `thumbnailsLastError(error)` | `Last error: <error>` |
143
+ | `themeWithoutDarkMode` | `This theme has no dark mode` |
144
+ | `thumbnailMissing` | `No thumbnail yet` |
145
+ | `referenceNotePlaceholder` | `What should change? (optional, goes into the reference)` |
146
+
147
+ ```ts
148
+ const ENVIRONMENT: DesignStudioEnvironment = {
149
+ // …
150
+ texts: { reload: 'Neu laden (R)', boardsUpdated: count => `${count} aktualisiert` },
151
+ };
152
+ ```
153
+
154
+ The other texts of the studio are fixed English strings.
155
+
156
+ ## Routes the application creates
157
+
158
+ The package has no router. The application creates one page per screen and tells the studio their paths through
159
+ `environment.paths`:
160
+
161
+ | Page | Screen | `paths` entry |
162
+ |---|---|---|
163
+ | overview of the projects | `DesignStudioOverviewScreen` | `overview()` |
164
+ | one project and its canvases | `DesignStudioProjectScreen` (`projectKey`) | `project(projectKey)` |
165
+ | one canvas | `DesignStudioCanvasScreen` (`projectKey`, `canvasKey`) from `/canvas` | `canvas(projectKey, canvasKey)` |
166
+ | reviews (optional; an empty state in this version) | `DesignStudioReviewsScreen` | none: linked by the application's own navigation |
167
+
168
+ 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.
170
+
171
+ ## Wiring with the Next.js App Router
172
+
173
+ A minimal example. `@/…` stands for the application's own modules.
174
+
175
+ ```ts
176
+ // src/design-studio/designStudioApi.ts: once, at module scope
177
+ import { createDesignStudioApi } from '@mgamadeus/ddd-design-studio';
178
+
179
+ import { baseApi } from '@/api/baseApi';
180
+
181
+ export const designStudioApi = createDesignStudioApi({ baseApi, apiPrefix: '/api/admin/designStudio' });
182
+ ```
183
+
184
+ ```tsx
185
+ // src/design-studio/AppDesignStudioProvider.tsx: the environment built from the application's own pieces
186
+ 'use client';
187
+
188
+ import { DesignStudioProvider, type DesignStudioEnvironment } from '@mgamadeus/ddd-design-studio';
189
+ import Link from 'next/link';
190
+ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
191
+ import { type ReactNode, useCallback } from 'react';
192
+
193
+ import { designStudioApi } from './designStudioApi';
194
+
195
+ /**
196
+ * Replaces search parameters of the current page; `null` removes one. Simplified: the contract also asks for writes
197
+ * made in the same tick to be merged into one navigation (queue them and flush in a microtask).
198
+ */
199
+ const useSearchParamsWriter = () => {
200
+ const pathname = usePathname();
201
+ const router = useRouter();
202
+ return useCallback(
203
+ (updates: Readonly<Record<string, string | null>>) => {
204
+ const next = new URLSearchParams(window.location.search);
205
+ for (const [key, value] of Object.entries(updates)) {
206
+ if (value) next.set(key, value);
207
+ else next.delete(key);
208
+ }
209
+ const query = next.toString();
210
+ router.replace(query ? `${pathname}?${query}` : pathname, { scroll: false });
211
+ },
212
+ [pathname, router]
213
+ );
214
+ };
215
+
216
+ const ENVIRONMENT: DesignStudioEnvironment = {
217
+ api: designStudioApi,
218
+ apiBaseUrl: '',
219
+ // useUrlState: the application's hook for list state in the URL (see the contract of `router.useUrlState`)
220
+ router: { Link, useSearchParams, useSearchParamsWriter, useUrlState: useAppUrlState },
221
+ paths: {
222
+ overview: () => '/design',
223
+ project: projectKey => `/design/${projectKey}`,
224
+ canvas: (projectKey, canvasKey) => `/design/${projectKey}/canvases/${canvasKey}`,
225
+ },
226
+ components: { Button, Badge, Card /* … every slot of DesignStudioComponents */ },
227
+ notify: { success: toast.success, error: toast.error, info: toast.info },
228
+ formatDateTime,
229
+ storage: {
230
+ read: key => readLocal(`app.designStudio.${key}`),
231
+ write: (key, value) => writeLocal(`app.designStudio.${key}`, value),
232
+ },
233
+ useCanWrite: () => useAppSelector(selectCanWrite),
234
+ useCurrentAccountId: () => useAppSelector(selectAccountId),
235
+ statuses: {
236
+ DRAFT: { label: 'Draft', tone: 'neutral' },
237
+ IN_REVIEW: { label: 'In review', tone: 'info' },
238
+ CHOSEN: { label: 'Chosen', tone: 'success' },
239
+ REJECTED: { label: 'Rejected', tone: 'danger' },
240
+ },
241
+ };
242
+
243
+ export const AppDesignStudioProvider = ({ children }: { children: ReactNode }) => (
244
+ <DesignStudioProvider environment={ENVIRONMENT}>{children}</DesignStudioProvider>
245
+ );
246
+ ```
247
+
248
+ ```tsx
249
+ // src/app/design/page.tsx
250
+ import { DesignStudioOverviewScreen } from '@mgamadeus/ddd-design-studio';
251
+
252
+ import { AppDesignStudioProvider } from '@/design-studio/AppDesignStudioProvider';
253
+
254
+ export default function DesignOverviewPage() {
255
+ return (
256
+ <AppDesignStudioProvider>
257
+ <DesignStudioOverviewScreen />
258
+ </AppDesignStudioProvider>
259
+ );
260
+ }
261
+ ```
262
+
263
+ ```tsx
264
+ // src/app/design/[projectKey]/page.tsx
265
+ import { DesignStudioProjectScreen } from '@mgamadeus/ddd-design-studio';
266
+
267
+ import { AppDesignStudioProvider } from '@/design-studio/AppDesignStudioProvider';
268
+
269
+ export default async function DesignProjectPage({ params }: { params: Promise<{ projectKey: string }> }) {
270
+ const { projectKey } = await params;
271
+ return (
272
+ <AppDesignStudioProvider>
273
+ <DesignStudioProjectScreen projectKey={projectKey} />
274
+ </AppDesignStudioProvider>
275
+ );
276
+ }
277
+ ```
278
+
279
+ ```tsx
280
+ // src/design-studio/DesignCanvasLoader.tsx: the canvas, client-only and lazy
281
+ 'use client';
282
+
283
+ import dynamic from 'next/dynamic';
284
+
285
+ import { AppDesignStudioProvider } from './AppDesignStudioProvider';
286
+
287
+ const DesignStudioCanvasScreen = dynamic(
288
+ () => import('@mgamadeus/ddd-design-studio/canvas').then(module => module.DesignStudioCanvasScreen),
289
+ { ssr: false }
290
+ );
291
+
292
+ export const DesignCanvasLoader = ({ projectKey, canvasKey }: { projectKey: string; canvasKey: string }) => (
293
+ <AppDesignStudioProvider>
294
+ {/* `key`: one canvas keeps nothing of another */}
295
+ <DesignStudioCanvasScreen key={`${projectKey}/${canvasKey}`} projectKey={projectKey} canvasKey={canvasKey} />
296
+ </AppDesignStudioProvider>
297
+ );
298
+ ```
299
+
300
+ ```tsx
301
+ // src/app/design/[projectKey]/canvases/[canvasKey]/page.tsx
302
+ import { Suspense } from 'react';
303
+
304
+ import { DesignCanvasLoader } from '@/design-studio/DesignCanvasLoader';
305
+
306
+ export default async function DesignCanvasPage({
307
+ params,
308
+ }: {
309
+ params: Promise<{ projectKey: string; canvasKey: string }>;
310
+ }) {
311
+ const { projectKey, canvasKey } = await params;
312
+ return (
313
+ // the canvas screen reads search parameters
314
+ <Suspense>
315
+ <DesignCanvasLoader projectKey={projectKey} canvasKey={canvasKey} />
316
+ </Suspense>
317
+ );
318
+ }
319
+ ```
320
+
321
+ ## Reference helpers
322
+
323
+ `buildDesignReference(input)` builds the plain-text block that names one board (optionally a region, a comment thread,
324
+ a note) for an agent; `buildBoardDeepLink(pageUrl, boardKey, themeId, mode, viewport?)` the link that reopens the board
325
+ in the focus view. Both are pure and exported from the main entry.
326
+
327
+ ## Development
328
+
329
+ ```bash
330
+ pnpm install
331
+ pnpm typecheck
332
+ pnpm test # node:test on src/**/*.test.ts (Node 22.6 or newer)
333
+ pnpm build # tsup -> dist (ESM + .d.ts), then scripts/check-package.mjs
334
+ ```
335
+
336
+ | Path | Content |
337
+ |---|---|
338
+ | `src/index.ts` | the main entry (does not load `@xyflow/react`) |
339
+ | `src/canvas/index.ts` | the `/canvas` entry: `DesignStudioCanvasScreen` |
340
+ | `src/api/` | `createDesignStudioApi` and the types of the backend contract (maintained by hand) |
341
+ | `src/provider/` | `DesignStudioProvider`, its hooks, the `DesignStudioEnvironment` types, the default texts |
342
+ | `src/screens/` | overview, project and reviews screens |
343
+ | `src/canvas/` | the canvas screen, the canvas engine, focus view, comments, and the pure modules with their tests |
344
+ | `scripts/check-package.mjs` | checks a build or an extracted tarball: export targets, the entry split, `'use client'` |
345
+ | `test/consumer/` | installs the packed tarball into a fresh project and type-checks a strict consumer |
346
+
347
+ Source files import only `react`, `react-dom`, `@xyflow/react`, `lucide-react`, `@reduxjs/toolkit`, `react-redux`,
348
+ `@mgamadeus/ddd-web/*`, `clsx`, `tailwind-merge` and relative files; only files below `src/canvas/` that the main
349
+ entry does not reach may import `@xyflow/react`. The published package contains `dist` only (no sources, no tests).
350
+
351
+ ## Release
352
+
353
+ The version in `package.json` equals the version in the repository's `composer.json`. Pushing the tag `v<version>`
354
+ runs `.github/workflows/release.yml`, which verifies both versions against the tag, builds, checks the tarball and
355
+ publishes it to npm through trusted publishing.
356
+
357
+ ## License
358
+
359
+ MIT
@@ -0,0 +1,18 @@
1
+ import * as react from 'react';
2
+
3
+ interface DesignStudioCanvasScreenProps {
4
+ projectKey: string;
5
+ canvasKey: string;
6
+ }
7
+ /**
8
+ * Design studio canvas: every board of a canvas laid out per section (a bold title
9
+ * line, then rows of nine boards with a header each), a toolbar on the canvas (select / hand, theme + light / dark
10
+ * mode, comments panel, present, zoom), search and filters by section and status, a collapsible comments panel and
11
+ * the focus view. Rendering stays proportional to what is on screen (boardDetail.ts):
12
+ * only nodes in the viewport mount, far zoom uses the 120 px thumbnails, live HTML only for ≤ 6 large boards after a
13
+ * pan / zoom ends.
14
+ */
15
+ declare const DesignStudioCanvasScreen: ({ projectKey, canvasKey }: DesignStudioCanvasScreenProps) => react.JSX.Element;
16
+
17
+ export { DesignStudioCanvasScreen };
18
+ export type { DesignStudioCanvasScreenProps };