@1agh/maude 2.0.6 → 2.0.8

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.
Files changed (177) hide show
  1. package/apps/studio/access/closure.ts +156 -16
  2. package/apps/studio/access/filters.ts +27 -0
  3. package/apps/studio/actions/agents.ts +54 -0
  4. package/apps/studio/actions/ctx.ts +3 -0
  5. package/apps/studio/actions/defs/sync.ts +13 -0
  6. package/apps/studio/actions/defs/view.ts +59 -3
  7. package/apps/studio/actions/keymap.gen.ts +35 -0
  8. package/apps/studio/actions/menu.ts +2 -0
  9. package/apps/studio/actions/types.ts +3 -1
  10. package/apps/studio/actions.manifest.json +136 -1
  11. package/apps/studio/actions.parity.json +25 -1
  12. package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
  13. package/apps/studio/annotations/ui/ride.ts +2 -1
  14. package/apps/studio/annotations-context-toolbar.tsx +5 -4
  15. package/apps/studio/annotations-layer.tsx +4 -3
  16. package/apps/studio/api.ts +383 -128
  17. package/apps/studio/artboard-activity-overlay.tsx +4 -4
  18. package/apps/studio/artboard-ai-copies.tsx +4 -4
  19. package/apps/studio/artboard-freeze.ts +108 -0
  20. package/apps/studio/artboard-live-gate.tsx +414 -45
  21. package/apps/studio/artboard-live.ts +526 -31
  22. package/apps/studio/artboard-placeholder.ts +197 -0
  23. package/apps/studio/artboard-still-raster.ts +485 -0
  24. package/apps/studio/artboard-still-warmup.ts +221 -0
  25. package/apps/studio/artboard-still.ts +1188 -0
  26. package/apps/studio/artboard-webgl.ts +2 -1
  27. package/apps/studio/asset-placeholder.tsx +237 -132
  28. package/apps/studio/asset-upload-bars.tsx +4 -4
  29. package/apps/studio/bin/_perf-probe-open.mjs +364 -0
  30. package/apps/studio/bin/_perf-shared.mjs +12 -7
  31. package/apps/studio/bin/_pw-launch.mjs +26 -1
  32. package/apps/studio/bin/perf.sh +19 -0
  33. package/apps/studio/bridge/dgn-protocol.ts +35 -0
  34. package/apps/studio/canvas-build-sandbox.ts +69 -13
  35. package/apps/studio/canvas-camera.ts +90 -0
  36. package/apps/studio/canvas-comment-mount.tsx +9 -9
  37. package/apps/studio/canvas-lib.tsx +160 -34
  38. package/apps/studio/canvas-pages-view.tsx +465 -0
  39. package/apps/studio/canvas-pages.ts +305 -0
  40. package/apps/studio/canvas-rows.ts +62 -0
  41. package/apps/studio/canvas-shell.tsx +62 -16
  42. package/apps/studio/canvas-theme-icons.tsx +41 -0
  43. package/apps/studio/canvas-theme-pill.tsx +15 -6
  44. package/apps/studio/canvas-theme.ts +12 -11
  45. package/apps/studio/client/app.jsx +7 -0
  46. package/apps/studio/client/canvas-url.js +23 -1
  47. package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
  48. package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
  49. package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
  50. package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
  51. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
  52. package/apps/studio/client/hooks/use-project-data.jsx +11 -2
  53. package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
  54. package/apps/studio/client/index-loader.ts +41 -21
  55. package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
  56. package/apps/studio/client/shell/viewport.jsx +32 -16
  57. package/apps/studio/client/tree/tree.jsx +17 -0
  58. package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
  59. package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
  60. package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
  61. package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
  62. package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
  63. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
  64. package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
  65. package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
  66. package/apps/studio/client/v2/code/code-consent.js +67 -0
  67. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
  68. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
  69. package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
  70. package/apps/studio/client/v2/layers/layers-request.js +49 -0
  71. package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
  72. package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
  73. package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
  74. package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
  75. package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
  76. package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
  77. package/apps/studio/client/v2/shell/floating-panels.css +37 -1
  78. package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
  79. package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
  80. package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
  81. package/apps/studio/client/v2/shell/pages-pick.js +49 -0
  82. package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
  83. package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
  84. package/apps/studio/client/v2/shell/shell-parity.json +8 -0
  85. package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
  86. package/apps/studio/comments-overlay.tsx +12 -11
  87. package/apps/studio/config-reload-wire.ts +4 -1
  88. package/apps/studio/config.schema.json +6 -0
  89. package/apps/studio/context.ts +37 -1
  90. package/apps/studio/dist/client.bundle.js +720 -720
  91. package/apps/studio/dist/comment-mount.js +2 -2
  92. package/apps/studio/dist/styles.css +1 -1
  93. package/apps/studio/ds/board/board.css +6 -0
  94. package/apps/studio/ds/board/ds-bar.tsx +21 -3
  95. package/apps/studio/ds/board/specimen.tsx +6 -3
  96. package/apps/studio/ds/board/template.ts +39 -19
  97. package/apps/studio/ds/cli.ts +7 -1
  98. package/apps/studio/ds/component-list.ts +2 -1
  99. package/apps/studio/ds/default.ts +6 -1
  100. package/apps/studio/ds/ds-resolver.ts +58 -8
  101. package/apps/studio/ds/engine.ts +3 -1
  102. package/apps/studio/ds/folder-systems.ts +199 -0
  103. package/apps/studio/ds/pairing-css.ts +2 -1
  104. package/apps/studio/ds/rename.ts +10 -3
  105. package/apps/studio/ds/shell-fallbacks.ts +2 -1
  106. package/apps/studio/ds/upgrade-stage.ts +6 -2
  107. package/apps/studio/editing/ai-point-ring.tsx +4 -4
  108. package/apps/studio/editing/ai-scope-outline.tsx +4 -4
  109. package/apps/studio/editing/align-bar.tsx +4 -4
  110. package/apps/studio/editing/anchor-report.ts +3 -2
  111. package/apps/studio/editing/artboard-handles.tsx +4 -4
  112. package/apps/studio/editing/corner-dots.tsx +4 -4
  113. package/apps/studio/editing/crop-mode.tsx +4 -4
  114. package/apps/studio/editing/drop-chip.tsx +4 -4
  115. package/apps/studio/editing/empty-report.ts +3 -2
  116. package/apps/studio/editing/focus-model.tsx +4 -4
  117. package/apps/studio/editing/gap-bands.tsx +3 -3
  118. package/apps/studio/editing/hold-rings.tsx +4 -4
  119. package/apps/studio/editing/lock-badge.tsx +3 -3
  120. package/apps/studio/editing/long-page.ts +23 -1
  121. package/apps/studio/editing/nudge.tsx +2 -2
  122. package/apps/studio/editing/page-activity.ts +4 -3
  123. package/apps/studio/editing/paste-bar.tsx +4 -4
  124. package/apps/studio/editing/pen/overlay.tsx +4 -3
  125. package/apps/studio/editing/place-freely.tsx +3 -3
  126. package/apps/studio/editing/reorder-slot.tsx +3 -3
  127. package/apps/studio/editing/selection.tsx +4 -4
  128. package/apps/studio/editing/size-ghost.tsx +4 -4
  129. package/apps/studio/editing/tab-order.tsx +4 -4
  130. package/apps/studio/editing/text-in-place.tsx +4 -4
  131. package/apps/studio/editing/undo-preview.tsx +3 -3
  132. package/apps/studio/equal-spacing-handles.tsx +3 -3
  133. package/apps/studio/frame-clock.ts +89 -0
  134. package/apps/studio/http.ts +66 -32
  135. package/apps/studio/index/ds-usage.ts +4 -1
  136. package/apps/studio/index-cache.ts +272 -0
  137. package/apps/studio/inspect-overlay.tsx +4 -3
  138. package/apps/studio/inspect.ts +7 -2
  139. package/apps/studio/link-chip-overlay.tsx +4 -3
  140. package/apps/studio/measure-overlay.tsx +4 -3
  141. package/apps/studio/present/pointer-dot.tsx +3 -2
  142. package/apps/studio/present/present-media.ts +6 -2
  143. package/apps/studio/present/present-stage.tsx +3 -2
  144. package/apps/studio/preview/preview-camera.tsx +3 -2
  145. package/apps/studio/routes/sync.ts +176 -0
  146. package/apps/studio/safe-zones-overlay.tsx +3 -2
  147. package/apps/studio/skip-dirs.ts +103 -47
  148. package/apps/studio/studio-page-host.ts +70 -0
  149. package/apps/studio/sync/code-module-consent.ts +86 -0
  150. package/apps/studio/sync/file-ledger.ts +24 -0
  151. package/apps/studio/sync/file-plane.ts +458 -53
  152. package/apps/studio/sync/held-deletes.ts +230 -0
  153. package/apps/studio/sync/hubs-config.ts +59 -2
  154. package/apps/studio/sync/index.ts +99 -15
  155. package/apps/studio/sync/seed-progress.ts +92 -2
  156. package/apps/studio/sync/settings.ts +36 -1
  157. package/apps/studio/sync/status.ts +15 -1
  158. package/apps/studio/sync/writer-registry.ts +5 -0
  159. package/apps/studio/text-caret.ts +5 -3
  160. package/apps/studio/toolbars/toolbar-rect.ts +3 -2
  161. package/apps/studio/use-annotation-resize.tsx +4 -3
  162. package/apps/studio/use-artboard-drag.tsx +3 -2
  163. package/apps/studio/use-element-resize.tsx +7 -6
  164. package/apps/studio/use-grid-track-handles.tsx +5 -4
  165. package/apps/studio/use-selection-set.tsx +64 -4
  166. package/apps/studio/use-spacing-handles.tsx +7 -6
  167. package/apps/studio/video-comp.tsx +55 -42
  168. package/apps/studio/video-play-overlay.tsx +4 -3
  169. package/apps/studio/whats-new.json +27 -0
  170. package/cli/commands/design.mjs +5 -2
  171. package/cli/commands/hub.mjs +10 -1
  172. package/cli/lib/bash-guard.mjs +14 -0
  173. package/cli/lib/design-help.gen.mjs +1 -1
  174. package/cli/lib/design-link.mjs +42 -17
  175. package/cli/lib/hub-purge.mjs +183 -0
  176. package/package.json +8 -8
  177. package/plugins/design/templates/_shell.html +164 -1
@@ -510,6 +510,12 @@
510
510
  var(--maude-hud-shadow-md),
511
511
  inset 0 0 0 1px var(--maude-hud-accent);
512
512
  }
513
+ .ds-bar-b--ic {
514
+ display: grid;
515
+ place-items: center;
516
+ padding-inline: 7px;
517
+ }
518
+
513
519
  .ds-bar-b:disabled {
514
520
  opacity: 0.4;
515
521
  cursor: default;
@@ -6,10 +6,15 @@
6
6
  // system's tokens and never CSS system colours: it is Maude's bar over the user's design, so a locked or
7
7
  // garish brand must not restyle it, and it follows the APP theme (a `Canvas` bar was white in the dark app).
8
8
  // 13 `DsBar`: island · 24 px `system` glyph tile · name · `.seg` Light | Dark · Review… as the primary button.
9
+ // 2.0.7 polish (decision `v2-207-pages-on-ds-canvas`): Canvas | Pages and, in Pages, ‹ n / N › after Light | Dark —
10
+ // the switch every ordinary canvas has on its pill (canvas-pages-view.tsx), which this canvas does not draw.
9
11
 
12
+ import type { ReactNode } from 'react';
10
13
  import { createPortal } from 'react-dom';
11
14
  import { DsIcon } from '../../canvas-ds-icons.tsx';
15
+ import { CanvasPagesSwitch } from '../../canvas-pages-view.tsx';
12
16
  import { setCanvasTheme } from '../../canvas-theme.ts';
17
+ import { THEME_WORD, ThemeIcon } from '../../canvas-theme-icons.tsx';
13
18
  import { isEmbedCanvas } from '../../read-only-mode.ts';
14
19
  import { useBoardMode, useBoardModel } from './state.ts';
15
20
  import type { BoardMode, BoardModel } from './types.ts';
@@ -26,11 +31,14 @@ export function DsBarView({
26
31
  mode,
27
32
  onMode,
28
33
  onReview,
34
+ pages = null,
29
35
  }: {
30
36
  model: BoardModel;
31
37
  mode: BoardMode;
32
38
  onMode: (m: BoardMode) => void;
33
39
  onReview?: () => void;
40
+ /** Canvas | Pages (the connected bar passes `CanvasPagesSwitch variant="ds"`) */
41
+ pages?: ReactNode;
34
42
  }) {
35
43
  const linked = !!model.library;
36
44
  // a linked library takes no edits here: nothing waits, so there is nothing to Review…
@@ -47,16 +55,20 @@ export function DsBarView({
47
55
  <button
48
56
  key={m}
49
57
  type="button"
50
- className="ds-bar-b k-seg-b"
58
+ className="ds-bar-b ds-bar-b--ic k-seg-b"
51
59
  data-testid={`ds-bar-mode-${m}`}
52
60
  aria-pressed={mode === m}
61
+ aria-label={THEME_WORD[m]}
53
62
  disabled={m === 'dark' && !hasDark}
63
+ // 2.0.7 — icons only, like the canvas pill; the name (or what's missing) is the tooltip
64
+ title={m === 'dark' && !hasDark ? 'This design system has no Dark' : THEME_WORD[m]}
54
65
  onClick={() => onMode(m)}
55
66
  >
56
- {m === 'light' ? 'Light' : 'Dark'}
67
+ <ThemeIcon mode={m} />
57
68
  </button>
58
69
  ))}
59
70
  </fieldset>
71
+ {pages}
60
72
  {linked ? (
61
73
  <>
62
74
  <span className="ds-bar-sep" />
@@ -101,7 +113,13 @@ export function DsBar({ onReview, portal = true }: { onReview?: () => void; port
101
113
  // an embed (the reach view's Patterns frame, DDR-247) shows the design alone: the bar is Maude's chrome
102
114
  if (!model || isEmbedCanvas()) return null;
103
115
  const bar = (
104
- <DsBarView model={model} mode={mode} onMode={(m) => setCanvasTheme(m)} onReview={ask} />
116
+ <DsBarView
117
+ model={model}
118
+ mode={mode}
119
+ onMode={(m) => setCanvasTheme(m)}
120
+ onReview={ask}
121
+ pages={<CanvasPagesSwitch variant="ds" />}
122
+ />
105
123
  );
106
124
  return portal && typeof document !== 'undefined' ? createPortal(bar, document.body) : bar;
107
125
  }
@@ -46,10 +46,14 @@ export function Specimen({ src, mode: modeProp }: { src: string; mode?: 'light'
46
46
  // 2.0.5 — a specimen page mounts once its artboard first comes near the viewport (a board of 58 built
47
47
  // every page at open). The artboard keeps its size meanwhile; captures and exports mount all of them.
48
48
  const seen = useArtboardSeen();
49
+ const mode = modeProp ?? stored;
50
+ // 2.0.7 — the pending page carries the system's root class and theme like the page itself: without them its
51
+ // `var(--bg-1)` fell back to the `Canvas` system colour, which in a dark scheme is a black box.
49
52
  if (!seen)
50
53
  return (
51
- <div
52
- className="ds-board ds-specimen ds-specimen-pending"
54
+ <DSRoot
55
+ theme={model ? themeFor(model, mode) : undefined}
56
+ className={`ds-board ds-specimen ds-specimen-pending${model?.rootClass ? ` ${model.rootClass}` : ''}${mode === 'dark' ? ' ds-dark' : ''}`}
53
57
  data-ds-specimen={src}
54
58
  aria-hidden="true"
55
59
  />
@@ -57,7 +61,6 @@ export function Specimen({ src, mode: modeProp }: { src: string; mode?: 'light'
57
61
  const mod = getSpecimen(src) as { default?: ComponentType } | ComponentType | undefined;
58
62
  const Comp = (typeof mod === 'function' ? mod : mod?.default) as ComponentType | undefined;
59
63
  if (!Comp) return <Missing src={src} why="is not loaded" />;
60
- const mode = modeProp ?? stored;
61
64
  return (
62
65
  <DSRoot
63
66
  theme={model ? themeFor(model, mode) : undefined}
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { readFileSync } from 'node:fs';
6
6
  import path from 'node:path';
7
- import { ROW_GAP } from '../../canvas-rows.ts';
7
+ import { MAX_ROW_COLUMNS, ROW_GAP } from '../../canvas-rows.ts';
8
8
  import { DEV_SERVER_ROOT } from '../../paths.ts';
9
9
  import { SECTIONS, type SectionKind } from './types.ts';
10
10
 
@@ -22,9 +22,9 @@ export interface OwnSpecimenArtboard {
22
22
  }
23
23
 
24
24
  /**
25
- * Own artboards sit below the seven sections at a showcase's size (V2-1.6 §5.2's example): one row
26
- * per section, in the order the artboards come (convert-map.ts gives them in section order), each
27
- * row `rowGap` below the last. A specimen page grows past `h` (the artboard hugs its content, 1 500–4 750
25
+ * Own artboards sit below the seven sections at a showcase's size (V2-1.6 §5.2's example): each
26
+ * section starts a row, in the order the artboards come (convert-map.ts gives them in section order),
27
+ * wraps after `MAX_ROW_COLUMNS` pages (2.0.7 fix #6), and each row sits `rowGap` below the last. A specimen page grows past `h` (the artboard hugs its content, 1 500–4 750
28
28
  * px measured live on this repo's two systems, 2026-10-31), and the height is only known once the page
29
29
  * is on screen — so the generator writes the COMPACT pitch (`h + ROW_GAP`) and the open canvas re-pitches
30
30
  * the rows from the measured heights (`canvas-rows.ts` `flowRows`, r3-ds-rows): a row is as tall as its
@@ -33,22 +33,42 @@ export interface OwnSpecimenArtboard {
33
33
  */
34
34
  export const OWN_ARTBOARD = { w: 1440, h: 900, y: 1860, gap: 48, rowGap: ROW_GAP } as const;
35
35
 
36
- /** The design-px box of each own artboard: one row per section, in first-seen order. */
36
+ /**
37
+ * The design-px box of each own artboard: each section starts a row, in first-seen order, and wraps
38
+ * onto the next row after `MAX_ROW_COLUMNS` pages (2.0.7 fix #6 — one row per section made StudyFi's
39
+ * 29 component pages a 43 000 px row and the canvas fitted at 2 %).
40
+ */
37
41
  function ownLayout(own: readonly OwnSpecimenArtboard[]) {
38
- const rows: Array<string | undefined> = [];
39
- const col = new Map<string | undefined, number>();
40
- return own.map((o) => {
41
- if (!rows.includes(o.section)) rows.push(o.section);
42
- const i = col.get(o.section) ?? 0;
43
- col.set(o.section, i + 1);
44
- return {
45
- id: o.id,
46
- x: i * (OWN_ARTBOARD.w + OWN_ARTBOARD.gap),
47
- y: OWN_ARTBOARD.y + rows.indexOf(o.section) * (OWN_ARTBOARD.h + OWN_ARTBOARD.rowGap),
48
- w: OWN_ARTBOARD.w,
49
- h: OWN_ARTBOARD.h,
50
- };
51
- });
42
+ const sections: Array<string | undefined> = [];
43
+ const bySection = new Map<string | undefined, OwnSpecimenArtboard[]>();
44
+ for (const o of own) {
45
+ if (!bySection.has(o.section)) {
46
+ sections.push(o.section);
47
+ bySection.set(o.section, []);
48
+ }
49
+ bySection.get(o.section)?.push(o);
50
+ }
51
+ const place = new Map<string, { x: number; y: number }>();
52
+ let row = 0;
53
+ for (const s of sections) {
54
+ const pages = bySection.get(s) ?? [];
55
+ pages.forEach((o, i) => {
56
+ const col = i % MAX_ROW_COLUMNS;
57
+ place.set(o.id, {
58
+ x: col * (OWN_ARTBOARD.w + OWN_ARTBOARD.gap),
59
+ y:
60
+ OWN_ARTBOARD.y +
61
+ (row + Math.floor(i / MAX_ROW_COLUMNS)) * (OWN_ARTBOARD.h + OWN_ARTBOARD.rowGap),
62
+ });
63
+ });
64
+ row += Math.ceil(pages.length / MAX_ROW_COLUMNS);
65
+ }
66
+ return own.map((o) => ({
67
+ id: o.id,
68
+ ...(place.get(o.id) as { x: number; y: number }),
69
+ w: OWN_ARTBOARD.w,
70
+ h: OWN_ARTBOARD.h,
71
+ }));
52
72
  }
53
73
 
54
74
  /**
@@ -6,6 +6,7 @@ import { join, resolve } from 'node:path';
6
6
  import { runCanvasModes } from './canvas-cli.ts';
7
7
  import { checkSystem, type SystemReport } from './check.ts';
8
8
  import { emitTokensJson } from './emit.ts';
9
+ import { withFolderSystems } from './folder-systems.ts';
9
10
  import type { PostBuild } from './post-build.ts';
10
11
  import { indexRegistry, loadRegistry } from './registry.ts';
11
12
  import {
@@ -135,7 +136,12 @@ export function loadProject(
135
136
  const cfgPath = join(designRoot, 'config.json');
136
137
  if (!existsSync(cfgPath)) throw new UsageError(`no .design/config.json under ${root}`);
137
138
  const config = JSON.parse(readFileSync(cfgPath, 'utf8')) as Record<string, unknown>;
138
- return { root, designRoot, config, systems: systemConfigsFrom(config) };
139
+ return {
140
+ root,
141
+ designRoot,
142
+ config,
143
+ systems: systemConfigsFrom(withFolderSystems(config, designRoot)),
144
+ };
139
145
  }
140
146
 
141
147
  export function selectSystems(project: Project, names: string[]): SystemConfig[] {
@@ -13,6 +13,7 @@ import path from 'node:path';
13
13
 
14
14
  import { RECIPES } from '../edit-ops/insert-component.ts';
15
15
  import { canvasSystemFor } from './ds-resolver.ts';
16
+ import { withFolderSystems } from './folder-systems.ts';
16
17
  import { readHead } from './head.ts';
17
18
  import { type SystemConfig, systemConfigsFrom } from './system.ts';
18
19
 
@@ -76,7 +77,7 @@ function readJson(abs: string): Record<string, unknown> | null {
76
77
  export function systemForPicker(designRoot: string, canvasAbs: string | null): SystemConfig | null {
77
78
  if (canvasAbs) return canvasSystemFor(designRoot, canvasAbs);
78
79
  const config = readJson(path.join(designRoot, 'config.json')) ?? {};
79
- const systems = systemConfigsFrom(config);
80
+ const systems = systemConfigsFrom(withFolderSystems(config, designRoot));
80
81
  const def = typeof config.defaultDesignSystem === 'string' ? config.defaultDesignSystem : null;
81
82
  return systems.find((s) => s.name === def) ?? systems[0] ?? null;
82
83
  }
@@ -9,6 +9,8 @@
9
9
  import { readFileSync, renameSync, writeFileSync } from 'node:fs';
10
10
  import path from 'node:path';
11
11
 
12
+ import { adoptFolderSystem } from './folder-systems.ts';
13
+
12
14
  /** Same shape as the engine's refusals (`code` + `status`), so the route answers it the same way. */
13
15
  class DefaultError extends Error {
14
16
  constructor(
@@ -39,6 +41,9 @@ export function setDefaultSystem(designRoot: string, ds: string): DefaultResult
39
41
  } catch {
40
42
  throw new DefaultError('ds-config-unreadable', 'The project’s config could not be read.', 500);
41
43
  }
44
+ // 2.0.7 — a folder-owned system (not in config.json yet, ds/folder-systems.ts) is adopted first: its entry is
45
+ // appended, then the default is set as for a configured system
46
+ const adopted = adoptFolderSystem(designRoot, cfg, ds);
42
47
  const systems = Array.isArray(cfg.designSystems) ? (cfg.designSystems as unknown[]) : [];
43
48
  const names = systems.map((s) =>
44
49
  s && typeof s === 'object' ? (s as { name?: unknown }).name : null
@@ -46,7 +51,7 @@ export function setDefaultSystem(designRoot: string, ds: string): DefaultResult
46
51
  if (!names.includes(ds))
47
52
  throw new DefaultError('ds-unknown-system', `no design system named ${ds.slice(0, 64)}`, 404);
48
53
  const previous = typeof cfg.defaultDesignSystem === 'string' ? cfg.defaultDesignSystem : null;
49
- if (previous === ds) return { changed: false, previous, default: ds };
54
+ if (previous === ds && !adopted) return { changed: false, previous, default: ds };
50
55
  cfg.defaultDesignSystem = ds;
51
56
  // keep the file's own indentation and final newline
52
57
  const indent = /^\{\n( +|\t)"/.exec(text)?.[1] ?? ' ';
@@ -14,6 +14,12 @@ import path from 'node:path';
14
14
  import type { BunPlugin } from 'bun';
15
15
  import { DEV_SERVER_ROOT } from '../paths.ts';
16
16
  import { boardDeps, buildBoardModel } from './board/build-model.ts';
17
+ import {
18
+ folderOwnedSystems,
19
+ folderSystemEntry,
20
+ folderSystemOf,
21
+ pinnedFolderSystem,
22
+ } from './folder-systems.ts';
17
23
  import { type SystemConfig, systemConfigsFrom } from './system.ts';
18
24
 
19
25
  export const DS_SPECIFIER = '@maude/ds';
@@ -84,19 +90,52 @@ function readJson(abs: string): Record<string, unknown> | null {
84
90
 
85
91
  const metaPathFor = (canvasAbs: string) => canvasAbs.replace(/\.tsx$/, '.meta.json');
86
92
 
87
- /** The design system a canvas renders under, or null when the project declares none. */
93
+ // the one rule, re-exported for the callers that import it from here
94
+ export { folderSystemOf };
95
+
96
+ /** The `SystemConfig` of a folder-owned system: its themes and root class read from its tokens. */
97
+ function folderSystemConfig(
98
+ designRoot: string,
99
+ config: Record<string, unknown>,
100
+ folder: { name: string; path: string }
101
+ ): SystemConfig {
102
+ const [sys] = systemConfigsFrom({
103
+ ...config,
104
+ designSystems: [folderSystemEntry(designRoot, folder)],
105
+ });
106
+ return sys as SystemConfig;
107
+ }
108
+
109
+ /**
110
+ * The design system a canvas renders under, or null when the project has none. Owner by path →
111
+ * 2.0.7 owner by its own folder → `meta.designSystem` (a configured system, else a folder system
112
+ * of exactly that name) → `defaultDesignSystem` → the first system of the merged list (the first
113
+ * configured one whenever the config lists any). A pin to a name with no system stays at the
114
+ * default: a name never invents a path.
115
+ */
88
116
  export function canvasSystemFor(designRoot: string, canvasAbs: string): SystemConfig | null {
89
- const systems = systemConfigsFrom(readJson(path.join(designRoot, 'config.json')) ?? {});
90
- if (!systems.length) return null;
117
+ const config = readJson(path.join(designRoot, 'config.json')) ?? {};
118
+ const systems = systemConfigsFrom(config);
91
119
  const rel = path.relative(designRoot, canvasAbs).split(path.sep).join('/');
92
120
  const owner = systems.find((s) => rel.startsWith(`${s.path}/`));
93
121
  if (owner) return owner;
94
- const declared = readJson(metaPathFor(canvasAbs))?.designSystem;
95
- const byMeta = typeof declared === 'string' ? systems.find((s) => s.name === declared) : null;
122
+ const hasFile = (r: string) => existsSync(path.join(designRoot, ...r.split('/')));
123
+ const folder = folderSystemOf(rel, systems, hasFile);
124
+ if (folder) return folderSystemConfig(designRoot, config, folder);
125
+ const named = (name: unknown): SystemConfig | null => {
126
+ if (typeof name !== 'string' || !name) return null;
127
+ const configured = systems.find((s) => s.name === name);
128
+ if (configured) return configured;
129
+ const pinned = pinnedFolderSystem(name, systems, hasFile);
130
+ return pinned ? folderSystemConfig(designRoot, config, pinned) : null;
131
+ };
132
+ const byMeta = named(readJson(metaPathFor(canvasAbs))?.designSystem);
96
133
  if (byMeta) return byMeta;
97
- const config = readJson(path.join(designRoot, 'config.json')) ?? {};
98
- const def = typeof config.defaultDesignSystem === 'string' ? config.defaultDesignSystem : null;
99
- return systems.find((s) => s.name === def) ?? systems[0];
134
+ const byDefault = named(config.defaultDesignSystem);
135
+ if (byDefault) return byDefault;
136
+ if (systems.length) return systems[0] as SystemConfig;
137
+ const [first] = folderOwnedSystems(designRoot, systems);
138
+ return first ? folderSystemConfig(designRoot, config, first) : null;
100
139
  }
101
140
 
102
141
  const overridePath = (designRoot: string, sys: SystemConfig) =>
@@ -194,6 +233,17 @@ export function dsResolver(designRoot: string, canvasAbs: string): BunPlugin {
194
233
  export function dsDepsFor(source: string, canvasAbs: string, designRoot: string): string[] {
195
234
  if (!usesDs(source)) return [];
196
235
  const deps = [metaPathFor(canvasAbs), path.join(designRoot, 'config.json')];
236
+ // 2.0.7 — a pin to a system the config does not list resolves once its folder's Design system
237
+ // canvas arrives (a cell gets it as files), so that file appearing is a change too
238
+ const declared = readJson(metaPathFor(canvasAbs))?.designSystem;
239
+ if (
240
+ typeof declared === 'string' &&
241
+ /^[^/\\._][^/\\]*$/.test(declared) &&
242
+ !systemConfigsFrom(readJson(path.join(designRoot, 'config.json')) ?? {}).some(
243
+ (s) => s.name === declared
244
+ )
245
+ )
246
+ deps.push(path.join(designRoot, 'system', declared, 'design-system.tsx'));
197
247
  const sys = canvasSystemFor(designRoot, canvasAbs);
198
248
  if (sys && importsDs(source)) deps.push(overridePath(designRoot, sys));
199
249
  if (sys && importsDsBoard(source)) {
@@ -38,6 +38,7 @@ import { atomicWrite } from '../sync/atomic-write.ts';
38
38
  import { modesOf } from './board/types.ts';
39
39
  import { followedDark } from './contrast.ts';
40
40
  import { canvasSystemFor } from './ds-resolver.ts';
41
+ import { withFolderSystems } from './folder-systems.ts';
41
42
  import {
42
43
  type ComponentEdit,
43
44
  emitTokensJson,
@@ -419,8 +420,9 @@ export function createDsEngine(opts: EngineOptions) {
419
420
  return readJsonObj(path.join(designRoot, 'config.json')) ?? {};
420
421
  }
421
422
 
423
+ // 2.0.7 — the configured systems, then the folder-owned ones (ds/folder-systems.ts)
422
424
  function systems(): SystemConfig[] {
423
- return systemConfigsFrom(config());
425
+ return systemConfigsFrom(withFolderSystems(config(), designRoot));
424
426
  }
425
427
 
426
428
  function system(ds: string): SystemConfig {
@@ -0,0 +1,199 @@
1
+ // 2.0.7 — the design systems a project has: the configured ones, then the folder-owned ones.
2
+ //
3
+ // A cell's `config.json` never travels on the file plane (file-membership `never`) and is filled in
4
+ // only when the owner's desktop pushes its systems, so a system converted on a desktop can reach the
5
+ // cell as files alone: `system/<ds>/` with its own Design system canvas (`design-system.tsx`). Such a
6
+ // folder owns its canvases (`folderSystemOf`), and it is a system in every list too — `/_api/ds/*`,
7
+ // `/_config` (the Design system panel, the left panel's rows), the usage index — and a `ui/` canvas
8
+ // whose `.meta.json` names it renders with it.
9
+ //
10
+ // One merged list, one order: the configured systems first, exactly as configured, then the folder
11
+ // systems by name. So the default (the configured `defaultDesignSystem`, else the first configured
12
+ // system) never changes while the config lists a system. A name never invents a path: a folder system
13
+ // exists only where `system/<name>/design-system.tsx` is a real file in a real folder; a pin to any
14
+ // other name the config does not list stays at the default.
15
+ //
16
+ // A leaf: node built-ins only, so `context.ts` (loadConfig) can merge with it.
17
+
18
+ import { lstatSync, readdirSync, readFileSync } from 'node:fs';
19
+ import path from 'node:path';
20
+
21
+ /** What a folder name must look like to be a system (the hub door's `designSystems[].name` rule). */
22
+ const FOLDER_NAME = /^[\w .-]{1,64}$/;
23
+
24
+ /**
25
+ * The system folder a designRoot-relative path sits in when the config lists no system for it:
26
+ * `system/<ds>/…` whose folder holds its own Design system canvas (`design-system.tsx`). `hasFile`
27
+ * is the caller's reader (the disk, the closure's listing). A name the config already gives another
28
+ * folder is never taken over. One rule for the build (`canvasSystemFor`), the closure
29
+ * (`access/closure.ts`), the tree's map (`api.ts`) and the merged list below.
30
+ */
31
+ export function folderSystemOf(
32
+ rel: string,
33
+ configured: ReadonlyArray<{ name: string; path: string }>,
34
+ hasFile: (rel: string) => boolean
35
+ ): { name: string; path: string } | null {
36
+ const m = /^system\/([^/]+)\//.exec(rel);
37
+ const seg = m?.[1];
38
+ if (!seg || seg.startsWith('_') || seg.startsWith('.') || !FOLDER_NAME.test(seg)) return null;
39
+ const dir = `system/${seg}`;
40
+ if (configured.some((s) => s.path === dir || s.name === seg)) return null;
41
+ return hasFile(`${dir}/design-system.tsx`) ? { name: seg, path: dir } : null;
42
+ }
43
+
44
+ /**
45
+ * The folder system a canvas's `meta.designSystem` pin names, or null. Only a plain folder name
46
+ * counts (no `/`, never a path), so a pin can reach `system/<name>/` and nothing else.
47
+ */
48
+ export function pinnedFolderSystem(
49
+ declared: unknown,
50
+ configured: ReadonlyArray<{ name: string; path: string }>,
51
+ hasFile: (rel: string) => boolean
52
+ ): { name: string; path: string } | null {
53
+ if (typeof declared !== 'string' || !declared || /[/\\]/.test(declared)) return null;
54
+ const f = folderSystemOf(`system/${declared}/design-system.tsx`, configured, hasFile);
55
+ return f && f.name === declared ? f : null;
56
+ }
57
+
58
+ /** A folder system's config entry: its tokens CSS, and its themes + root class guessed from it. */
59
+ export interface FolderSystemEntry {
60
+ name: string;
61
+ path: string;
62
+ tokensCssRel: string;
63
+ themes?: string[];
64
+ themeDefault?: string;
65
+ rootClass?: string;
66
+ /** Not in the config: discovered from its folder. Never written back to config.json. */
67
+ folderOwned: true;
68
+ }
69
+
70
+ export function folderSystemEntry(
71
+ designRoot: string,
72
+ folder: { name: string; path: string }
73
+ ): FolderSystemEntry {
74
+ const tokensCssRel = `${folder.path}/colors_and_type.css`;
75
+ let css = '';
76
+ try {
77
+ css = readFileSync(path.join(designRoot, ...tokensCssRel.split('/')), 'utf8');
78
+ } catch {
79
+ /* no tokens yet: the defaults */
80
+ }
81
+ const themes: string[] = [];
82
+ for (const m of css.matchAll(/\[data-theme\s*=\s*["']?([a-z][a-z0-9-]*)["']?\s*\]/gi))
83
+ if (!themes.includes(m[1] as string)) themes.push(m[1] as string);
84
+ const esc = folder.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
85
+ const rootClass = new RegExp(`\\.${esc}\\[data-theme`).test(css) ? folder.name : null;
86
+ return {
87
+ name: folder.name,
88
+ path: folder.path,
89
+ tokensCssRel,
90
+ ...(themes.length
91
+ ? { themes, themeDefault: themes.includes('light') ? 'light' : (themes[0] as string) }
92
+ : {}),
93
+ ...(rootClass ? { rootClass } : {}),
94
+ folderOwned: true,
95
+ };
96
+ }
97
+
98
+ /** `rel` (designRoot-relative) is a regular file on disk — a symlink never counts. */
99
+ export function isRealFile(designRoot: string, rel: string): boolean {
100
+ try {
101
+ return lstatSync(path.join(designRoot, ...rel.split('/'))).isFile();
102
+ } catch {
103
+ return false;
104
+ }
105
+ }
106
+
107
+ /** The folder-owned systems on disk under `<designRoot>/system/`, by name. */
108
+ export function folderOwnedSystems(
109
+ designRoot: string,
110
+ configured: ReadonlyArray<{ name: string; path: string }>
111
+ ): FolderSystemEntry[] {
112
+ let dirs: string[];
113
+ try {
114
+ dirs = readdirSync(path.join(designRoot, 'system'), { withFileTypes: true })
115
+ .filter((d) => d.isDirectory())
116
+ .map((d) => d.name)
117
+ .sort();
118
+ } catch {
119
+ return [];
120
+ }
121
+ const out: FolderSystemEntry[] = [];
122
+ for (const seg of dirs) {
123
+ const f = folderSystemOf(`system/${seg}/design-system.tsx`, configured, (r) =>
124
+ isRealFile(designRoot, r)
125
+ );
126
+ if (f) out.push(folderSystemEntry(designRoot, f));
127
+ }
128
+ return out;
129
+ }
130
+
131
+ function configuredOf(config: Record<string, unknown>): Array<{ name: string; path: string }> {
132
+ const list = Array.isArray(config.designSystems) ? config.designSystems : [];
133
+ return (list as Array<Record<string, unknown> | null>)
134
+ .filter((e) => !!e && typeof e.name === 'string' && typeof e.path === 'string')
135
+ .map((e) => ({
136
+ name: (e as { name: string }).name,
137
+ path: (e as { path: string }).path.replace(/^\/+|\/+$/g, ''),
138
+ }));
139
+ }
140
+
141
+ /**
142
+ * `config` with its `designSystems` extended by the folder-owned systems on disk (after the
143
+ * configured ones). The same object back when there are none. For READING only: a writer of
144
+ * `config.json` reads the file itself, so a folder system is never persisted into it.
145
+ */
146
+ export function withFolderSystems<T extends Record<string, unknown>>(
147
+ config: T,
148
+ designRoot: string
149
+ ): T {
150
+ const folders = folderOwnedSystems(designRoot, configuredOf(config));
151
+ if (!folders.length) return config;
152
+ const list = Array.isArray(config.designSystems) ? (config.designSystems as unknown[]) : [];
153
+ return { ...config, designSystems: [...list, ...folders] };
154
+ }
155
+
156
+ /**
157
+ * The `config.json` entry that adopts folder system `ds`: what the merged list shows for it (name,
158
+ * path, the themes and root class guessed from its tokens), without the `folderOwned` mark — so
159
+ * the system reads the same once it is configured. Null when `ds` is not a folder system here.
160
+ */
161
+ export function adoptionEntry(
162
+ designRoot: string,
163
+ config: Record<string, unknown>,
164
+ ds: string
165
+ ): Record<string, unknown> | null {
166
+ const f = folderOwnedSystems(designRoot, configuredOf(config)).find((s) => s.name === ds);
167
+ if (!f) return null;
168
+ const { folderOwned: _mark, tokensCssRel, ...entry } = f;
169
+ // the tokens CSS is the default one (`<path>/colors_and_type.css`): no key, as a made system has
170
+ return tokensCssRel === `${f.path}/colors_and_type.css` ? entry : { ...entry, tokensCssRel };
171
+ }
172
+
173
+ /**
174
+ * A DS write that edits a system's `config.json` entry (default, rename, the schema flag) on a
175
+ * folder-owned system adopts it first: its entry is appended to `config.designSystems` (mutated in
176
+ * place, the caller writes the file as for a configured system). True when it adopted one.
177
+ */
178
+ export function adoptFolderSystem(
179
+ designRoot: string,
180
+ config: Record<string, unknown>,
181
+ ds: string
182
+ ): boolean {
183
+ if (configuredOf(config).some((s) => s.name === ds)) return false;
184
+ const entry = adoptionEntry(designRoot, config, ds);
185
+ if (!entry) return false;
186
+ const list = Array.isArray(config.designSystems) ? (config.designSystems as unknown[]) : [];
187
+ config.designSystems = [...list, entry];
188
+ return true;
189
+ }
190
+
191
+ /** The files whose change can add, drop or retheme a folder system. */
192
+ export function isFolderSystemFile(rel: unknown): boolean {
193
+ return (
194
+ typeof rel === 'string' &&
195
+ /^system\/[^/]+\/(design-system\.tsx|colors_and_type\.css)$/.test(
196
+ rel.replace(/\\/g, '/').replace(/^\/+/, '')
197
+ )
198
+ );
199
+ }
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { readFileSync } from 'node:fs';
23
23
  import path from 'node:path';
24
+ import { withFolderSystems } from './folder-systems.ts';
24
25
  import { type SystemConfig, systemConfigsFrom } from './system.ts';
25
26
 
26
27
  const NAME_RE = /^--[A-Za-z0-9_-]{1,64}$/;
@@ -113,7 +114,7 @@ export function pairingCssFor(
113
114
  ): string {
114
115
  if (!query) return '';
115
116
  const tokensRel = query.get('tokens');
116
- const sys = systemForTokens(config, tokensRel);
117
+ const sys = systemForTokens(withFolderSystems(config, designRoot), tokensRel);
117
118
  if (!sys || !tokensRel) return '';
118
119
  const rel = canvasRelOf(designRoot, query);
119
120
  if (!rel) return '';
@@ -14,6 +14,7 @@ import { readFileSync, renameSync, writeFileSync } from 'node:fs';
14
14
  import path from 'node:path';
15
15
 
16
16
  import { stripSpoofChars } from '../spoof-chars.ts';
17
+ import { adoptFolderSystem, withFolderSystems } from './folder-systems.ts';
17
18
 
18
19
  export const SYSTEM_LABEL_MAX = 64;
19
20
 
@@ -64,6 +65,9 @@ export function renameSystem(designRoot: string, ds: string, raw: string | null)
64
65
  } catch {
65
66
  throw new RenameError('ds-config-unreadable', 'The project’s config could not be read.', 500);
66
67
  }
68
+ // 2.0.7 — a folder-owned system (not in config.json yet, ds/folder-systems.ts) is adopted first: its entry is
69
+ // appended, then labelled as a configured system is
70
+ const adopted = adoptFolderSystem(designRoot, cfg, ds);
67
71
  const systems = (Array.isArray(cfg.designSystems) ? cfg.designSystems : []) as unknown[];
68
72
  const entry = systems.find(
69
73
  (s): s is Record<string, unknown> =>
@@ -80,8 +84,11 @@ export function renameSystem(designRoot: string, ds: string, raw: string | null)
80
84
  );
81
85
  if (label !== null) {
82
86
  const fold = label.toLowerCase();
83
- const clash = systems.some((s) => {
84
- if (!s || typeof s !== 'object' || s === entry) return false;
87
+ // every system the person can see: configured ones and the folder-owned ones not adopted yet
88
+ const shown = (withFolderSystems(cfg, designRoot).designSystems ?? []) as unknown[];
89
+ const clash = shown.some((s) => {
90
+ if (!s || typeof s !== 'object' || s === entry || (s as { name?: unknown }).name === ds)
91
+ return false;
85
92
  const o = s as { name?: unknown; label?: unknown };
86
93
  return [o.label, o.name].some(
87
94
  (v) => typeof v === 'string' && v.trim().toLowerCase() === fold
@@ -91,7 +98,7 @@ export function renameSystem(designRoot: string, ds: string, raw: string | null)
91
98
  throw new RenameError('ds-name-taken', 'Another design system already has that name.', 409);
92
99
  }
93
100
  const previous = typeof entry.label === 'string' ? entry.label : null;
94
- if (previous === label) return { changed: false, previous, label };
101
+ if (previous === label && !adopted) return { changed: false, previous, label };
95
102
  if (label === null) delete entry.label;
96
103
  else entry.label = label;
97
104
  // keep the file's own indentation and final newline
@@ -13,6 +13,7 @@ import { createHash } from 'node:crypto';
13
13
  import { readFileSync } from 'node:fs';
14
14
  import { join } from 'node:path';
15
15
  import { declaredBy, renderFallbacks } from './fallbacks.ts';
16
+ import { withFolderSystems } from './folder-systems.ts';
16
17
  import { pairingCssFor, systemForTokens } from './pairing-css.ts';
17
18
  import { loadRegistry } from './registry.ts';
18
19
  import { diskFs, loadSystem } from './system.ts';
@@ -40,7 +41,7 @@ export function fallbacksFor(
40
41
  config: Record<string, unknown>,
41
42
  tokensRel: string | null
42
43
  ): string {
43
- const sys = systemForTokens(config, tokensRel);
44
+ const sys = systemForTokens(withFolderSystems(config, designRoot), tokensRel);
44
45
  if (!sys) return '';
45
46
  const rels = [sys.tokensCssRel, `${sys.path}/preview/_components.css`];
46
47
  const digest = `${digestOf(designRoot, rels)}:${JSON.stringify(sys)}`;