@slotform/react-ui 0.0.0-stage → 0.1.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.
Files changed (280) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/density.d.ts +4 -0
  4. package/dist/density.d.ts.map +1 -0
  5. package/dist/density.js +8 -0
  6. package/dist/density.js.map +1 -0
  7. package/dist/index.d.ts +400 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +388 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/node/canvas.d.ts +3 -0
  12. package/dist/node/canvas.d.ts.map +1 -0
  13. package/dist/node/canvas.js +13 -0
  14. package/dist/node/canvas.js.map +1 -0
  15. package/dist/node/codegen.d.ts +6 -0
  16. package/dist/node/codegen.d.ts.map +1 -0
  17. package/dist/node/codegen.js +70 -0
  18. package/dist/node/codegen.js.map +1 -0
  19. package/dist/node/css-escape.d.ts +8 -0
  20. package/dist/node/css-escape.d.ts.map +1 -0
  21. package/dist/node/css-escape.js +12 -0
  22. package/dist/node/css-escape.js.map +1 -0
  23. package/dist/node/fonts.d.ts +6 -0
  24. package/dist/node/fonts.d.ts.map +1 -0
  25. package/dist/node/fonts.js +219 -0
  26. package/dist/node/fonts.js.map +1 -0
  27. package/dist/node/lint.d.ts +3 -0
  28. package/dist/node/lint.d.ts.map +1 -0
  29. package/dist/node/lint.js +23 -0
  30. package/dist/node/lint.js.map +1 -0
  31. package/dist/node/mode.d.ts +9 -0
  32. package/dist/node/mode.d.ts.map +1 -0
  33. package/dist/node/mode.js +38 -0
  34. package/dist/node/mode.js.map +1 -0
  35. package/dist/node/theme.d.ts +13 -0
  36. package/dist/node/theme.d.ts.map +1 -0
  37. package/dist/node/theme.js +160 -0
  38. package/dist/node/theme.js.map +1 -0
  39. package/dist/types.d.ts +250 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +80 -0
  42. package/dist/types.js.map +1 -0
  43. package/guide/acts.md +61 -0
  44. package/guide/audio.md +77 -0
  45. package/guide/blocks.md +82 -0
  46. package/guide/canvas-choosing.md +34 -0
  47. package/guide/canvas-editing.md +36 -0
  48. package/guide/canvas-layout.md +46 -0
  49. package/guide/canvas-opening.md +47 -0
  50. package/guide/canvas-overview.md +24 -0
  51. package/guide/canvas-states.md +37 -0
  52. package/guide/canvas-view.md +46 -0
  53. package/guide/canvas.md +94 -0
  54. package/guide/containers.md +60 -0
  55. package/guide/content.md +40 -0
  56. package/guide/controls.md +89 -0
  57. package/guide/density.md +48 -0
  58. package/guide/dock.md +42 -0
  59. package/guide/drag.md +38 -0
  60. package/guide/figures.md +25 -0
  61. package/guide/forms.md +82 -0
  62. package/guide/pane-bar.md +11 -0
  63. package/guide/pane.md +50 -0
  64. package/guide/reference.md +74 -0
  65. package/guide/rules.md +109 -0
  66. package/guide/section.md +29 -0
  67. package/guide/shell.md +26 -0
  68. package/guide/shots.md +37 -0
  69. package/guide/sidebar.md +30 -0
  70. package/guide/table.md +119 -0
  71. package/lint/no-arbitrary-value.grit +9 -0
  72. package/lint/no-class-on-component.grit +12 -0
  73. package/lint/no-density.grit +8 -0
  74. package/lint/no-host-look.grit +38 -0
  75. package/lint/no-img.grit +10 -0
  76. package/lint/no-navigate-act.grit +22 -0
  77. package/lint/no-raw-style.grit +8 -0
  78. package/package.json +150 -3
  79. package/src/density.ts +9 -0
  80. package/src/index.ts +503 -0
  81. package/src/node/canvas.ts +14 -0
  82. package/src/node/codegen.ts +100 -0
  83. package/src/node/css-escape.ts +27 -0
  84. package/src/node/fonts.ts +260 -0
  85. package/src/node/lint.ts +25 -0
  86. package/src/node/mode.ts +64 -0
  87. package/src/node/theme.ts +232 -0
  88. package/src/types.ts +120 -0
  89. package/src/ui/atoms/avatar/base.tsx +42 -0
  90. package/src/ui/atoms/button/glyph.tsx +244 -0
  91. package/src/ui/atoms/button/link.tsx +81 -0
  92. package/src/ui/atoms/button/look.ts +32 -0
  93. package/src/ui/atoms/button/reason.tsx +69 -0
  94. package/src/ui/atoms/chip/base.tsx +85 -0
  95. package/src/ui/atoms/count/base.tsx +27 -0
  96. package/src/ui/atoms/icon/index.tsx +51 -0
  97. package/src/ui/atoms/message/waiting.tsx +19 -0
  98. package/src/ui/atoms/prose/painted.tsx +35 -0
  99. package/src/ui/atoms/row/badges.tsx +226 -0
  100. package/src/ui/atoms/row/leading.tsx +166 -0
  101. package/src/ui/atoms/row/lock.tsx +17 -0
  102. package/src/ui/atoms/row/marks.tsx +79 -0
  103. package/src/ui/atoms/section/card.tsx +27 -0
  104. package/src/ui/atoms/spinner/index.tsx +42 -0
  105. package/src/ui/atoms/status/base.tsx +51 -0
  106. package/src/ui/atoms/status/change.tsx +29 -0
  107. package/src/ui/atoms/status/dot.tsx +45 -0
  108. package/src/ui/atoms/switch/checkbox.tsx +121 -0
  109. package/src/ui/atoms/turn.tsx +28 -0
  110. package/src/ui/components/action-bar/base.tsx +276 -0
  111. package/src/ui/components/action-bar/index.tsx +20 -0
  112. package/src/ui/components/avatar/index.tsx +21 -0
  113. package/src/ui/components/banner/index.tsx +207 -0
  114. package/src/ui/components/banner/pending.tsx +109 -0
  115. package/src/ui/components/bar-chart/index.tsx +701 -0
  116. package/src/ui/components/button/base.tsx +214 -0
  117. package/src/ui/components/button/face.tsx +84 -0
  118. package/src/ui/components/button/index.tsx +206 -0
  119. package/src/ui/components/canvas/connection.tsx +26 -0
  120. package/src/ui/components/canvas/edges.tsx +116 -0
  121. package/src/ui/components/canvas/elk.ts +260 -0
  122. package/src/ui/components/canvas/floor.ts +173 -0
  123. package/src/ui/components/canvas/geometry.ts +772 -0
  124. package/src/ui/components/canvas/ground.tsx +97 -0
  125. package/src/ui/components/canvas/group.tsx +156 -0
  126. package/src/ui/components/canvas/hit.ts +40 -0
  127. package/src/ui/components/canvas/index.tsx +497 -0
  128. package/src/ui/components/canvas/label.tsx +53 -0
  129. package/src/ui/components/canvas/layout.ts +543 -0
  130. package/src/ui/components/canvas/lift.ts +272 -0
  131. package/src/ui/components/canvas/look.ts +129 -0
  132. package/src/ui/components/canvas/node.tsx +689 -0
  133. package/src/ui/components/canvas/open.ts +243 -0
  134. package/src/ui/components/canvas/opening.ts +240 -0
  135. package/src/ui/components/canvas/view.ts +621 -0
  136. package/src/ui/components/canvas/viewport.ts +417 -0
  137. package/src/ui/components/canvas/zoom.tsx +113 -0
  138. package/src/ui/components/card/index.tsx +20 -0
  139. package/src/ui/components/chip/index.tsx +24 -0
  140. package/src/ui/components/code/frame.ts +2 -0
  141. package/src/ui/components/code/index.tsx +234 -0
  142. package/src/ui/components/columns/index.tsx +51 -0
  143. package/src/ui/components/count/index.tsx +17 -0
  144. package/src/ui/components/diff/index.tsx +249 -0
  145. package/src/ui/components/diff/word.tsx +104 -0
  146. package/src/ui/components/dock/index.tsx +262 -0
  147. package/src/ui/components/file-row/index.tsx +213 -0
  148. package/src/ui/components/form/base.tsx +280 -0
  149. package/src/ui/components/form/derive.tsx +269 -0
  150. package/src/ui/components/form/index.tsx +49 -0
  151. package/src/ui/components/form/saved.tsx +39 -0
  152. package/src/ui/components/form-field/index.tsx +658 -0
  153. package/src/ui/components/gallery/index.tsx +83 -0
  154. package/src/ui/components/gate/index.tsx +183 -0
  155. package/src/ui/components/image/base.tsx +245 -0
  156. package/src/ui/components/image/index.tsx +58 -0
  157. package/src/ui/components/input/base.tsx +246 -0
  158. package/src/ui/components/input/code.tsx +108 -0
  159. package/src/ui/components/input/drop.ts +37 -0
  160. package/src/ui/components/input/file.tsx +154 -0
  161. package/src/ui/components/input/index.tsx +132 -0
  162. package/src/ui/components/input/prose.tsx +107 -0
  163. package/src/ui/components/input/refusal.tsx +30 -0
  164. package/src/ui/components/item-header/base.tsx +410 -0
  165. package/src/ui/components/menu/base.tsx +319 -0
  166. package/src/ui/components/message/attachments.tsx +101 -0
  167. package/src/ui/components/message/base.tsx +266 -0
  168. package/src/ui/components/message-input/index.tsx +377 -0
  169. package/src/ui/components/missing/base.tsx +45 -0
  170. package/src/ui/components/pane/head.tsx +399 -0
  171. package/src/ui/components/pane/index.tsx +325 -0
  172. package/src/ui/components/picker/base.tsx +1551 -0
  173. package/src/ui/components/picker/index.tsx +224 -0
  174. package/src/ui/components/picker/list.tsx +423 -0
  175. package/src/ui/components/picker/segments.tsx +183 -0
  176. package/src/ui/components/prose/index.tsx +259 -0
  177. package/src/ui/components/qr-code/index.tsx +65 -0
  178. package/src/ui/components/row/acts.tsx +126 -0
  179. package/src/ui/components/row/fact.tsx +54 -0
  180. package/src/ui/components/row/index.tsx +1370 -0
  181. package/src/ui/components/row/progress.tsx +38 -0
  182. package/src/ui/components/row/status.tsx +54 -0
  183. package/src/ui/components/row/title.ts +7 -0
  184. package/src/ui/components/rules/index.tsx +290 -0
  185. package/src/ui/components/section/band.tsx +39 -0
  186. package/src/ui/components/section/head.tsx +267 -0
  187. package/src/ui/components/section/index.tsx +409 -0
  188. package/src/ui/components/section/rows.tsx +356 -0
  189. package/src/ui/components/sheet/base.tsx +272 -0
  190. package/src/ui/components/sheet/confirm.tsx +79 -0
  191. package/src/ui/components/sheet/docked.tsx +218 -0
  192. package/src/ui/components/sheet/form.tsx +76 -0
  193. package/src/ui/components/sheet/head.tsx +120 -0
  194. package/src/ui/components/sheet/index.tsx +45 -0
  195. package/src/ui/components/sheet/layer.tsx +168 -0
  196. package/src/ui/components/sheet/outlet.tsx +58 -0
  197. package/src/ui/components/sheet/task.tsx +41 -0
  198. package/src/ui/components/shell/cut.tsx +116 -0
  199. package/src/ui/components/shell/drag.tsx +45 -0
  200. package/src/ui/components/shell/host.tsx +71 -0
  201. package/src/ui/components/shell/index.tsx +737 -0
  202. package/src/ui/components/shell/panes.tsx +76 -0
  203. package/src/ui/components/shell/preview.ts +230 -0
  204. package/src/ui/components/shell/rail.tsx +163 -0
  205. package/src/ui/components/shell/row.ts +11 -0
  206. package/src/ui/components/shell/switcher.tsx +143 -0
  207. package/src/ui/components/shell/tree.tsx +252 -0
  208. package/src/ui/components/slider/base.tsx +139 -0
  209. package/src/ui/components/slider/index.tsx +57 -0
  210. package/src/ui/components/stages/index.tsx +198 -0
  211. package/src/ui/components/stats/count-links.tsx +47 -0
  212. package/src/ui/components/stats/index.tsx +203 -0
  213. package/src/ui/components/stats/meter.tsx +213 -0
  214. package/src/ui/components/stats/parts.ts +10 -0
  215. package/src/ui/components/step-count/index.tsx +45 -0
  216. package/src/ui/components/switch/base.tsx +86 -0
  217. package/src/ui/components/switch/index.tsx +38 -0
  218. package/src/ui/components/table/columns.tsx +131 -0
  219. package/src/ui/components/table/index.tsx +2215 -0
  220. package/src/ui/components/text/index.tsx +37 -0
  221. package/src/ui/components/thread/index.tsx +503 -0
  222. package/src/ui/components/thread/latest.tsx +59 -0
  223. package/src/ui/components/toast/index.tsx +113 -0
  224. package/src/ui/components/toast/layer.tsx +26 -0
  225. package/src/ui/components/toolbar/filters.tsx +161 -0
  226. package/src/ui/components/toolbar/index.tsx +125 -0
  227. package/src/ui/components/waveform/index.tsx +205 -0
  228. package/src/ui/globals.css +427 -0
  229. package/src/ui/lib/act.ts +60 -0
  230. package/src/ui/lib/age.ts +49 -0
  231. package/src/ui/lib/bound.ts +16 -0
  232. package/src/ui/lib/canvas-layout.ts +11 -0
  233. package/src/ui/lib/caret.ts +9 -0
  234. package/src/ui/lib/chip-lines.ts +3 -0
  235. package/src/ui/lib/closed.ts +8 -0
  236. package/src/ui/lib/code.tsx +184 -0
  237. package/src/ui/lib/columns.ts +39 -0
  238. package/src/ui/lib/commit.ts +24 -0
  239. package/src/ui/lib/container.ts +112 -0
  240. package/src/ui/lib/copy.ts +29 -0
  241. package/src/ui/lib/drag.ts +575 -0
  242. package/src/ui/lib/empty.tsx +85 -0
  243. package/src/ui/lib/field.ts +39 -0
  244. package/src/ui/lib/focus.ts +175 -0
  245. package/src/ui/lib/folds.ts +67 -0
  246. package/src/ui/lib/follow.ts +220 -0
  247. package/src/ui/lib/form.ts +19 -0
  248. package/src/ui/lib/guards.ts +38 -0
  249. package/src/ui/lib/heading.ts +14 -0
  250. package/src/ui/lib/ink.ts +26 -0
  251. package/src/ui/lib/lang.ts +7 -0
  252. package/src/ui/lib/leave.ts +14 -0
  253. package/src/ui/lib/lockup.tsx +145 -0
  254. package/src/ui/lib/measure.ts +22 -0
  255. package/src/ui/lib/media.ts +63 -0
  256. package/src/ui/lib/modality.ts +69 -0
  257. package/src/ui/lib/moment.ts +13 -0
  258. package/src/ui/lib/more.tsx +76 -0
  259. package/src/ui/lib/navigate.ts +210 -0
  260. package/src/ui/lib/noop.ts +3 -0
  261. package/src/ui/lib/not-found.tsx +40 -0
  262. package/src/ui/lib/paint.tsx +55 -0
  263. package/src/ui/lib/parts-line.tsx +54 -0
  264. package/src/ui/lib/picked.ts +18 -0
  265. package/src/ui/lib/player-store.ts +38 -0
  266. package/src/ui/lib/player.ts +139 -0
  267. package/src/ui/lib/portal.ts +12 -0
  268. package/src/ui/lib/read.tsx +269 -0
  269. package/src/ui/lib/region.tsx +49 -0
  270. package/src/ui/lib/reorder.ts +154 -0
  271. package/src/ui/lib/rest.ts +16 -0
  272. package/src/ui/lib/saved.ts +29 -0
  273. package/src/ui/lib/scramble.tsx +147 -0
  274. package/src/ui/lib/scrolls.ts +70 -0
  275. package/src/ui/lib/style.ts +6 -0
  276. package/src/ui/lib/swap.tsx +107 -0
  277. package/src/ui/lib/toast.ts +39 -0
  278. package/src/ui/lib/walk-classes.ts +16 -0
  279. package/src/ui/lib/window.tsx +376 -0
  280. package/src/ui/worker.d.ts +4 -0
package/src/index.ts ADDED
@@ -0,0 +1,503 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { auth } from "@slotform/auth";
3
+ import type { ContributionCtx } from "@slotform/cli";
4
+ import { GENERATED_DIR, plugin, slot, slotformSpec } from "@slotform/cli";
5
+ import {
6
+ literalToProps,
7
+ type ProviderSpec,
8
+ type TsExpression,
9
+ type TsImportSpec,
10
+ } from "@slotform/cli/ast";
11
+ import { cliSlots, emitArtifact } from "@slotform/cli/cli-slots";
12
+ import { react } from "@slotform/react";
13
+ import { type PreviewGlobal, screens } from "@slotform/screens";
14
+ import { deriveTheme } from "@slotform/ui-core/derive";
15
+ import { uiCoreGuide } from "@slotform/ui-core/manifest";
16
+ import { vite } from "@slotform/vite";
17
+ import { z } from "zod";
18
+ import { aggregateAppCss } from "./node/codegen.ts";
19
+ import { defaultFonts, type FontEntry } from "./node/fonts.ts";
20
+ import { lintPlugins } from "./node/lint.ts";
21
+ import { modeScriptPolicy } from "./node/mode.ts";
22
+ import {
23
+ densityLayer,
24
+ modeLayer,
25
+ motionLayer,
26
+ pageVariants,
27
+ rootLayer,
28
+ safeAreaUtilities,
29
+ shadowBlocks,
30
+ themeBlock,
31
+ tokenSources,
32
+ touchVariant,
33
+ } from "./node/theme.ts";
34
+ import {
35
+ type CssBlock,
36
+ type CssImport,
37
+ type CssLayer,
38
+ type CssSourceInline,
39
+ type ReactUiOptions,
40
+ reactUiOptionsSchema,
41
+ } from "./types.ts";
42
+
43
+ const SOURCE = "react-ui";
44
+
45
+ // The Tailwind ranges an app installs are this package's optional peers, read from its
46
+ // own package.json, one level above `src/` and `dist/` alike.
47
+ const tailwindPeers = z
48
+ .object({
49
+ peerDependencies: z.object({
50
+ tailwindcss: z.string(),
51
+ "@tailwindcss/vite": z.string(),
52
+ }),
53
+ })
54
+ .parse(
55
+ JSON.parse(
56
+ readFileSync(new URL("../package.json", import.meta.url), "utf8"),
57
+ ),
58
+ ).peerDependencies;
59
+
60
+ // ── Slot declarations ──────────────────────────────────────────────
61
+
62
+ const appCssImports = slot.list<CssImport>({
63
+ source: SOURCE,
64
+ name: "appCssImports",
65
+ });
66
+
67
+ const appCssSources = slot.list<CssSourceInline>({
68
+ source: SOURCE,
69
+ name: "appCssSources",
70
+ });
71
+
72
+ // Top-level `@theme` / `@utility` blocks. Separate from `appCssLayers`
73
+ // because neither at-rule may sit inside a `@layer`.
74
+ const appCssBlocks = slot.list<CssBlock>({
75
+ source: SOURCE,
76
+ name: "appCssBlocks",
77
+ });
78
+
79
+ const appCssLayers = slot.list<CssLayer>({
80
+ source: SOURCE,
81
+ name: "appCssLayers",
82
+ });
83
+
84
+ // Resolved fonts: docs/architecture/plugins/react-ui.md, "Fonts".
85
+ // The `??` is load-bearing: `fonts: []` means none, an omitted option means `defaultFonts`.
86
+ const fonts = slot.derived({
87
+ source: SOURCE,
88
+ name: "fonts",
89
+ compute: (_inp, ctx: ContributionCtx<ReactUiOptions>): FontEntry[] =>
90
+ ctx.options.fonts ?? defaultFonts,
91
+ });
92
+
93
+ // The design contract, resolved once, so knob resolution and validation
94
+ // happen exactly one time.
95
+ const resolvedTheme = slot.derived({
96
+ source: SOURCE,
97
+ name: "resolvedTheme",
98
+ compute: (_inp, ctx: ContributionCtx<ReactUiOptions>) =>
99
+ deriveTheme(ctx.options.theme),
100
+ });
101
+
102
+ // Rendered `.slotform/app.css`, null when nothing landed.
103
+ const appCssSource = slot.derived({
104
+ source: SOURCE,
105
+ name: "appCssSource",
106
+ inputs: {
107
+ imports: appCssImports,
108
+ sources: appCssSources,
109
+ blocks: appCssBlocks,
110
+ layers: appCssLayers,
111
+ },
112
+ compute: (inp): string | null => aggregateAppCss(inp),
113
+ });
114
+
115
+ export const reactUi = plugin("react-ui", {
116
+ label: "Design System",
117
+
118
+ schema: reactUiOptionsSchema,
119
+
120
+ requires: ["react", "vite"],
121
+
122
+ dependencies: {
123
+ // The guide's index points into the consumer's node_modules for
124
+ // ui-core's pages.
125
+ "@slotform/ui-core": slotformSpec(),
126
+ tailwindcss: tailwindPeers.tailwindcss,
127
+ },
128
+ devDependencies: {
129
+ "@tailwindcss/vite": tailwindPeers["@tailwindcss/vite"],
130
+ },
131
+
132
+ guide: [
133
+ { page: "rules", trigger: "Writing or editing any `.tsx` of the web app" },
134
+ {
135
+ page: "reference",
136
+ trigger:
137
+ "Importing a web component, or setting the theme, words, fonts or mode",
138
+ },
139
+ {
140
+ page: "density",
141
+ trigger:
142
+ "Reasoning about density, a screen read from across a room, the page container or a phone's safe areas",
143
+ },
144
+ {
145
+ page: "shots",
146
+ trigger: "Shooting or auditing the app's screens with a browser driver",
147
+ },
148
+ { page: "shell", trigger: "Giving a `Shell` or `Panes` a prop" },
149
+ {
150
+ page: "sidebar",
151
+ trigger:
152
+ "Nesting places with `children`, or reviewing how the sidebar's groups open and fold",
153
+ },
154
+ {
155
+ page: "pane",
156
+ trigger:
157
+ "Giving a `Pane` a prop, its record's head, its body or its foot",
158
+ },
159
+ {
160
+ page: "pane-bar",
161
+ trigger: "Giving a `Pane` its acts, its context pick or its way back",
162
+ },
163
+ {
164
+ page: "containers",
165
+ trigger: "Giving a `Gate`, `Sheet`, `Banner`, `Columns` or `Card` a prop",
166
+ },
167
+ {
168
+ page: "controls",
169
+ trigger:
170
+ "Giving a `Button`, `Input`, `Picker`, `Switch` or `Slider` a prop",
171
+ },
172
+ { page: "section", trigger: "Giving a `Section` a prop or its rows" },
173
+ {
174
+ page: "table",
175
+ trigger: "Giving a `Table` a prop, its columns or its row regions",
176
+ },
177
+ {
178
+ page: "content",
179
+ trigger: "Giving a `Toolbar`, `Rules` or `Thread` a prop",
180
+ },
181
+ { page: "drag", trigger: "Making rows drag, drop or reorder" },
182
+ {
183
+ page: "blocks",
184
+ trigger:
185
+ "Giving a `Text`, `Prose`, `Code`, `Diff`, `Stages`, `Image`, `Gallery` or `QrCode` a prop",
186
+ },
187
+ { page: "figures", trigger: "Giving a `Stats` or `BarChart` a prop" },
188
+ {
189
+ page: "forms",
190
+ trigger: "Writing a `Form`, its fields, its steps or how it commits",
191
+ },
192
+ {
193
+ page: "acts",
194
+ trigger:
195
+ "Giving an `ActionBar` its acts, a `Table`'s chosen bar, or calling `toast()` or `confirm()`",
196
+ },
197
+ {
198
+ page: "canvas",
199
+ trigger: "Drawing a graph of nodes and edges, a workflow or a journey",
200
+ },
201
+ {
202
+ page: "canvas-view",
203
+ trigger:
204
+ "Reviewing how a canvas pans and zooms by pointer, wheel or touch",
205
+ },
206
+ {
207
+ page: "canvas-opening",
208
+ trigger:
209
+ "Reviewing where a canvas's view opens, or keeping a chosen node in view as the canvas resizes",
210
+ },
211
+ {
212
+ page: "canvas-overview",
213
+ trigger:
214
+ "Giving canvas nodes their titles, or reviewing a canvas zoomed out",
215
+ },
216
+ {
217
+ page: "canvas-layout",
218
+ trigger:
219
+ "Placing a canvas's nodes, standing a canvas in a `Pane`, or giving it a read",
220
+ },
221
+ {
222
+ page: "canvas-editing",
223
+ trigger: "Giving a canvas `onMove` or `onConnect`",
224
+ },
225
+ {
226
+ page: "canvas-states",
227
+ trigger:
228
+ "Giving a canvas node `off`, a `warning`, a `status`, or a run's `path`",
229
+ },
230
+ {
231
+ page: "canvas-choosing",
232
+ trigger: "Giving a canvas `onSelect`, `selected`, groups or an `act`",
233
+ },
234
+ { page: "audio", trigger: "Playing sound or reading what is playing" },
235
+ {
236
+ page: "dock",
237
+ trigger: "Placing the `Dock` or drawing a track's waveform",
238
+ },
239
+ ],
240
+
241
+ slots: {
242
+ appCssImports,
243
+ appCssSources,
244
+ appCssBlocks,
245
+ appCssLayers,
246
+ fonts,
247
+ resolvedTheme,
248
+ appCssSource,
249
+ },
250
+
251
+ contributes: (self) => [
252
+ // ── Vite integration ────────────────────────────────────────────
253
+ vite.slots.configImports.contribute(
254
+ (): TsImportSpec => ({
255
+ source: "@tailwindcss/vite",
256
+ default: "tailwindcss",
257
+ }),
258
+ ),
259
+ vite.slots.pluginCalls.contribute(
260
+ (): TsExpression => ({
261
+ kind: "call",
262
+ callee: { kind: "identifier", name: "tailwindcss" },
263
+ args: [],
264
+ }),
265
+ ),
266
+ vite.slots.configImports.contribute(
267
+ (): TsImportSpec => ({
268
+ source: "@slotform/react-ui/node/fonts",
269
+ named: ["themeFontsPlugin"],
270
+ }),
271
+ ),
272
+ // The mode before first paint, with the theme's `defaultMode` baked in
273
+ // as the fallback for a viewer with no stored choice.
274
+ vite.slots.configImports.contribute(
275
+ (): TsImportSpec => ({
276
+ source: "@slotform/react-ui/node/mode",
277
+ named: ["themeModePlugin"],
278
+ }),
279
+ ),
280
+ vite.slots.pluginCalls.contribute(async (ctx): Promise<TsExpression> => {
281
+ const { defaultMode, loading } = await ctx.resolve(
282
+ self.slots.resolvedTheme,
283
+ );
284
+ return {
285
+ kind: "call",
286
+ callee: { kind: "identifier", name: "themeModePlugin" },
287
+ args: Object.values(literalToProps({ defaultMode, loading })),
288
+ };
289
+ }),
290
+ // The mode script's hash in the CSP: docs/architecture/plugins/react-ui.md, "Mode script and CSP".
291
+ vite.slots.clientHeaders.contribute(async (ctx) => {
292
+ const { defaultMode, loading } = await ctx.resolve(
293
+ self.slots.resolvedTheme,
294
+ );
295
+ return {
296
+ "Content-Security-Policy": modeScriptPolicy(defaultMode, loading),
297
+ };
298
+ }),
299
+ // The canvas layout module is served as source: docs/architecture/plugins/react-ui.md, "Canvas serving".
300
+ vite.slots.configImports.contribute(
301
+ (): TsImportSpec => ({
302
+ source: "@slotform/react-ui/node/canvas",
303
+ named: ["canvasPlugin"],
304
+ }),
305
+ ),
306
+ vite.slots.pluginCalls.contribute(
307
+ (): TsExpression => ({
308
+ kind: "call",
309
+ callee: { kind: "identifier", name: "canvasPlugin" },
310
+ args: [],
311
+ }),
312
+ ),
313
+ vite.slots.configImports.contribute(
314
+ (): TsImportSpec => ({ source: "node:url", named: ["fileURLToPath"] }),
315
+ ),
316
+ // Fonts are served from this package's node_modules: docs/architecture/plugins/react-ui.md, "Fonts".
317
+ vite.slots.fsAllow.contribute(
318
+ (): TsExpression => ({
319
+ kind: "call",
320
+ callee: { kind: "identifier", name: "searchForWorkspaceRoot" },
321
+ args: [
322
+ {
323
+ kind: "call",
324
+ callee: { kind: "identifier", name: "fileURLToPath" },
325
+ args: [
326
+ {
327
+ kind: "call",
328
+ callee: {
329
+ kind: "member",
330
+ object: { kind: "identifier", name: "import.meta" },
331
+ property: "resolve",
332
+ },
333
+ args: [{ kind: "string", value: "@slotform/react-ui" }],
334
+ },
335
+ ],
336
+ },
337
+ ],
338
+ }),
339
+ ),
340
+ // The array is passed even when empty, so `fonts: []` stays "no fonts"
341
+ // all the way to the Vite plugin.
342
+ vite.slots.pluginCalls.contribute(async (ctx): Promise<TsExpression> => {
343
+ const entries = await ctx.resolve(self.slots.fonts);
344
+ return {
345
+ kind: "call",
346
+ callee: { kind: "identifier", name: "themeFontsPlugin" },
347
+ args: Object.values(literalToProps({ entries })),
348
+ };
349
+ }),
350
+
351
+ // Top-level routes are reserved slugs: docs/architecture/plugins/react-ui.md, "Organization routes".
352
+ auth.slots.reservedSlugs.contribute((ctx) =>
353
+ ctx.resolve(react.slots.topLevelRoutes),
354
+ ),
355
+
356
+ // The consumer's words, mounted once; absent, the context speaks English.
357
+ react.slots.providers.contribute((): ProviderSpec | undefined => {
358
+ const words = self.options.words;
359
+ if (!words) return undefined;
360
+ return {
361
+ imports: [
362
+ {
363
+ source: "@slotform/ui-core/react/words",
364
+ named: ["WordsProvider"],
365
+ },
366
+ ],
367
+ wrap: {
368
+ identifier: "WordsProvider",
369
+ props: Object.entries(literalToProps({ words })).map(
370
+ ([name, value]) => ({ name, value }),
371
+ ),
372
+ },
373
+ order: 1,
374
+ };
375
+ }),
376
+
377
+ // The app's lockup: docs/architecture/plugins/react-ui.md, "App lockup".
378
+ react.slots.providers.contribute(
379
+ async (ctx): Promise<ProviderSpec | undefined> => {
380
+ const icon = await ctx.resolve(react.slots.icon);
381
+ if (icon === null) return undefined;
382
+ const lockup = {
383
+ src: icon.light,
384
+ ...(icon.dark === undefined ? {} : { dark: icon.dark }),
385
+ ...(icon.logo === undefined
386
+ ? {}
387
+ : {
388
+ logo: icon.logo.light,
389
+ ...(icon.logo.dark === undefined
390
+ ? {}
391
+ : { logoDark: icon.logo.dark }),
392
+ }),
393
+ name: ctx.app.name,
394
+ };
395
+ return {
396
+ imports: [
397
+ {
398
+ source: "@slotform/react-ui/lib/lockup",
399
+ named: ["LockupProvider"],
400
+ },
401
+ ],
402
+ wrap: {
403
+ identifier: "LockupProvider",
404
+ props: Object.entries(literalToProps({ lockup })).map(
405
+ ([name, value]) => ({ name, value }),
406
+ ),
407
+ },
408
+ order: 1,
409
+ };
410
+ },
411
+ ),
412
+
413
+ cliSlots.lintPlugins.contribute(async (ctx) =>
414
+ lintPlugins(await ctx.resolve(react.slots.routesDir)),
415
+ ),
416
+
417
+ // ── App CSS ─────────────────────────────────────────────────────
418
+ self.slots.appCssImports.contribute(() => ({
419
+ url: "tailwindcss",
420
+ source: "none",
421
+ })),
422
+ self.slots.appCssImports.contribute(() => "@slotform/react-ui/globals.css"),
423
+ self.slots.appCssSources.contribute(() => tokenSources()),
424
+ self.slots.appCssBlocks.contribute(async (ctx) =>
425
+ themeBlock(await ctx.resolve(self.slots.resolvedTheme)),
426
+ ),
427
+ self.slots.appCssBlocks.contribute(() => shadowBlocks()),
428
+ self.slots.appCssBlocks.contribute(() => touchVariant()),
429
+ self.slots.appCssBlocks.contribute(async (ctx) =>
430
+ pageVariants(await ctx.resolve(self.slots.resolvedTheme)),
431
+ ),
432
+ self.slots.appCssBlocks.contribute(() => safeAreaUtilities()),
433
+ self.slots.appCssLayers.contribute(async (ctx) =>
434
+ rootLayer(await ctx.resolve(self.slots.resolvedTheme)),
435
+ ),
436
+ self.slots.appCssLayers.contribute(async (ctx) =>
437
+ modeLayer(await ctx.resolve(self.slots.resolvedTheme)),
438
+ ),
439
+ self.slots.appCssLayers.contribute(() => motionLayer()),
440
+ self.slots.appCssLayers.contribute(async (ctx) =>
441
+ densityLayer(await ctx.resolve(self.slots.resolvedTheme)),
442
+ ),
443
+
444
+ // The entry imports the sheet: docs/architecture/plugins/react-ui.md, "Generated files".
445
+ react.slots.entryImports.contribute(
446
+ (): TsImportSpec => ({ source: "./app.css", sideEffect: true }),
447
+ ),
448
+ // The app's router, handed to react-ui's navigation so an act opens a route
449
+ // in place, and the default not-found page: docs/architecture/plugins/react-ui.md, "Router bindings".
450
+ // With routing off the entry has no router to hand over.
451
+ react.slots.routerBindings.contribute(
452
+ async (ctx): Promise<TsImportSpec[] | undefined> => {
453
+ if ((await ctx.resolve(react.slots.routesDir)) === null)
454
+ return undefined;
455
+ return [
456
+ {
457
+ source: "@slotform/react-ui/lib/navigate",
458
+ named: ["bindRouter"],
459
+ },
460
+ {
461
+ source: "@slotform/react-ui/lib/not-found",
462
+ named: ["bindNotFound"],
463
+ },
464
+ ];
465
+ },
466
+ ),
467
+ // Mode and density as workbench toolbars: docs/architecture/plugins/react-ui.md, "Screens workbench".
468
+ screens.slots.previewGlobals.contribute(
469
+ async (ctx): Promise<PreviewGlobal[]> => {
470
+ const { defaultMode } = await ctx.resolve(self.slots.resolvedTheme);
471
+ return [
472
+ {
473
+ name: "mode",
474
+ title: "Mode",
475
+ values: ["light", "dark"],
476
+ default: defaultMode ?? "light",
477
+ checked: ["light", "dark"],
478
+ apply: { classes: { dark: "dark" } },
479
+ },
480
+ {
481
+ name: "density",
482
+ title: "Density",
483
+ values: ["desktop", "touch"],
484
+ default: "desktop",
485
+ // The density pin at each width: docs/architecture/plugins/react-ui.md, "Screens workbench".
486
+ byViewport: true,
487
+ apply: { attribute: "data-density" },
488
+ },
489
+ ];
490
+ },
491
+ ),
492
+ emitArtifact(`${GENERATED_DIR}/app.css`, self.slots.appCssSource),
493
+ // ui-core is no plugin: each UI plugin indexes its guide pages.
494
+ cliSlots.guide.contribute(() => uiCoreGuide),
495
+ ],
496
+ });
497
+
498
+ export type {
499
+ FontEntry,
500
+ ReactUiOptions,
501
+ Theme,
502
+ Words,
503
+ } from "./types.ts";
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ // The canvas layout module stays out of the pre-bundle: docs/architecture/plugins/react-ui.md, "Canvas serving".
4
+ export function canvasPlugin(): Plugin {
5
+ return {
6
+ name: "fcalell:canvas",
7
+ config: () => ({
8
+ optimizeDeps: {
9
+ exclude: ["@slotform/react-ui/lib/canvas-layout"],
10
+ include: ["@slotform/react-ui > elkjs/lib/elk-api.js"],
11
+ },
12
+ }),
13
+ };
14
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ type CodegenAppCssPayload,
3
+ type CssImport,
4
+ cssBlockSchema,
5
+ cssImportSchema,
6
+ cssLayerSchema,
7
+ cssSourceInlineSchema,
8
+ } from "../types.ts";
9
+ import {
10
+ cssIdent,
11
+ cssProperty,
12
+ cssString,
13
+ cssSupportsExpression,
14
+ cssTokenValue,
15
+ } from "./css-escape.ts";
16
+
17
+ // The app's source root, relative to the project: the sheet scans it and the lint rules run on it
18
+ // with file routing off.
19
+ export const APP_SOURCE_DIR = "src";
20
+
21
+ // The `.slotform/app.css` render, escaped and validated: docs/architecture/codegen.md, "CSS escape boundary".
22
+ export function aggregateAppCss(payload: CodegenAppCssPayload): string | null {
23
+ if (
24
+ payload.imports.length === 0 &&
25
+ payload.sources.length === 0 &&
26
+ payload.blocks.length === 0 &&
27
+ payload.layers.length === 0
28
+ ) {
29
+ return null;
30
+ }
31
+
32
+ const lines: string[] = [];
33
+ for (const imp of payload.imports) {
34
+ lines.push(renderImport(cssImportSchema.parse(imp)));
35
+ }
36
+ // `source(none)` roots the scan at declared sources: docs/architecture/plugins/react-ui.md, "Stylesheet assembly".
37
+ lines.push(`@source "../${APP_SOURCE_DIR}";`);
38
+ for (const pattern of payload.sources) {
39
+ lines.push(
40
+ `@source inline(${cssString(cssSourceInlineSchema.parse(pattern))});`,
41
+ );
42
+ }
43
+
44
+ for (const raw of payload.blocks) {
45
+ const block = cssBlockSchema.parse(raw);
46
+ lines.push("");
47
+ if (block.kind === "variant") {
48
+ lines.push(`@custom-variant ${cssIdent(block.name)} {`);
49
+ lines.push(block.content.trim());
50
+ } else {
51
+ lines.push(
52
+ block.kind === "theme"
53
+ ? "@theme {"
54
+ : `@utility ${cssIdent(block.name)} {`,
55
+ );
56
+ lines.push(...renderDeclarations(block.declarations));
57
+ }
58
+ lines.push("}");
59
+ }
60
+
61
+ for (const raw of payload.layers) {
62
+ const layer = cssLayerSchema.parse(raw);
63
+ lines.push("");
64
+ lines.push(`@layer ${cssIdent(layer.name)} {`);
65
+ lines.push(layer.content.trim());
66
+ lines.push("}");
67
+ }
68
+
69
+ return `${lines.join("\n")}\n`;
70
+ }
71
+
72
+ // A rule whose declarations cross the render boundary: docs/architecture/codegen.md, "CSS escape boundary".
73
+ export function renderRule(
74
+ selector: string,
75
+ declarations: Record<string, string>,
76
+ ): string {
77
+ return [`${selector} {`, ...renderDeclarations(declarations), "}"].join("\n");
78
+ }
79
+
80
+ export function renderMediaRule(query: string, rule: string): string {
81
+ return [`@media ${query} {`, rule, "}"].join("\n");
82
+ }
83
+
84
+ function renderDeclarations(declarations: Record<string, string>): string[] {
85
+ return Object.entries(declarations).map(
86
+ ([property, value]) =>
87
+ `\t${cssProperty(property)}: ${cssTokenValue(value)};`,
88
+ );
89
+ }
90
+
91
+ function renderImport(imp: CssImport): string {
92
+ if (typeof imp === "string") return `@import ${cssString(imp)};`;
93
+ const parts = [`@import ${cssString(imp.url)}`];
94
+ if (imp.layer !== undefined) parts.push(`layer(${cssIdent(imp.layer)})`);
95
+ if (imp.supports !== undefined) {
96
+ parts.push(`supports(${cssSupportsExpression(imp.supports)})`);
97
+ }
98
+ if (imp.source !== undefined) parts.push(`source(${imp.source})`);
99
+ return `${parts.join(" ")};`;
100
+ }
@@ -0,0 +1,27 @@
1
+ // The CSS escape policy, a label over `@slotform/cli/css`: docs/architecture/codegen.md, "CSS escape boundary".
2
+ import {
3
+ cssIdent as cssIdentBase,
4
+ cssString,
5
+ cssSupportsExpression as cssSupportsExpressionBase,
6
+ cssTokenValue as cssTokenValueBase,
7
+ cssUrl as cssUrlBase,
8
+ cssVarName as cssVarNameBase,
9
+ isCssIdent,
10
+ isCssSupportsExpression,
11
+ } from "@slotform/cli/css";
12
+
13
+ const LABEL = "react-ui";
14
+
15
+ export { cssString, isCssIdent, isCssSupportsExpression };
16
+
17
+ export const cssUrl = (value: string): string => cssUrlBase(value, LABEL);
18
+ export const cssIdent = (value: string): string => cssIdentBase(value, LABEL);
19
+ export const cssSupportsExpression = (value: string): string =>
20
+ cssSupportsExpressionBase(value, LABEL);
21
+ const cssVarName = (value: string): string => cssVarNameBase(value, LABEL);
22
+ export const cssTokenValue = (value: string): string =>
23
+ cssTokenValueBase(value, LABEL);
24
+
25
+ // A declaration's property name: docs/architecture/codegen.md, "CSS escape boundary".
26
+ export const cssProperty = (value: string): string =>
27
+ value.startsWith("--") ? cssVarName(value) : cssIdent(value);