@alecsibilia/ui-kit 0.0.0-stage → 0.1.0-alpha.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.
Files changed (283) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +201 -0
  3. package/README.md +233 -2
  4. package/bin/ui-kit.js +12 -0
  5. package/dist/alchemy/app.d.ts +34 -0
  6. package/dist/alchemy/app.js +88 -0
  7. package/dist/alchemy/index.d.ts +11 -0
  8. package/dist/alchemy/index.js +11 -0
  9. package/dist/alchemy/live-rooms.d.ts +21 -0
  10. package/dist/alchemy/live-rooms.js +31 -0
  11. package/dist/alchemy/migrations.d.ts +28 -0
  12. package/dist/alchemy/migrations.js +56 -0
  13. package/dist/alchemy/stage.d.ts +20 -0
  14. package/dist/alchemy/stage.js +20 -0
  15. package/dist/alchemy/wrangler-config.d.ts +76 -0
  16. package/dist/alchemy/wrangler-config.js +82 -0
  17. package/dist/build/app-modules.d.ts +11 -0
  18. package/dist/build/app-modules.js +40 -0
  19. package/dist/build/check.d.ts +4 -0
  20. package/dist/build/check.js +170 -0
  21. package/dist/build/cli.d.ts +1 -0
  22. package/dist/build/cli.js +79 -0
  23. package/dist/build/feature.d.ts +8 -0
  24. package/dist/build/feature.js +24 -0
  25. package/dist/build/index.d.ts +13 -0
  26. package/dist/build/index.js +13 -0
  27. package/dist/build/measure-cpu.d.ts +2 -0
  28. package/dist/build/measure-cpu.js +196 -0
  29. package/dist/build/prerender.d.ts +5 -0
  30. package/dist/build/prerender.js +109 -0
  31. package/dist/build/preview.d.ts +7 -0
  32. package/dist/build/preview.js +41 -0
  33. package/dist/build/seo-files.d.ts +27 -0
  34. package/dist/build/seo-files.js +24 -0
  35. package/dist/client/head-swap.d.ts +45 -0
  36. package/dist/client/head-swap.js +183 -0
  37. package/dist/client/hydration-pass.d.ts +56 -0
  38. package/dist/client/hydration-pass.js +186 -0
  39. package/dist/client/hydration-reset.d.ts +82 -0
  40. package/dist/client/hydration-reset.js +154 -0
  41. package/dist/client/index.d.ts +37 -0
  42. package/dist/client/index.js +65 -0
  43. package/dist/client/nav-client.d.ts +35 -0
  44. package/dist/client/nav-client.js +371 -0
  45. package/dist/live/collab/doc-provider.d.ts +74 -0
  46. package/dist/live/collab/doc-provider.js +412 -0
  47. package/dist/live/collab/index.d.ts +51 -0
  48. package/dist/live/collab/index.jsx +142 -0
  49. package/dist/live/collab-status.d.ts +25 -0
  50. package/dist/live/collab-status.js +17 -0
  51. package/dist/live/cursors/cursor-engine.d.ts +57 -0
  52. package/dist/live/cursors/cursor-engine.js +243 -0
  53. package/dist/live/cursors/index.d.ts +46 -0
  54. package/dist/live/cursors/index.jsx +110 -0
  55. package/dist/live/declaration.d.ts +113 -0
  56. package/dist/live/declaration.js +94 -0
  57. package/dist/live/index.d.ts +8 -0
  58. package/dist/live/index.js +8 -0
  59. package/dist/live/protocol.d.ts +224 -0
  60. package/dist/live/protocol.js +272 -0
  61. package/dist/live/server/doc-store.d.ts +68 -0
  62. package/dist/live/server/doc-store.js +187 -0
  63. package/dist/live/server/index.d.ts +60 -0
  64. package/dist/live/server/index.js +77 -0
  65. package/dist/live/server/room-presence.d.ts +24 -0
  66. package/dist/live/server/room-presence.js +123 -0
  67. package/dist/live/server/room-sockets.d.ts +65 -0
  68. package/dist/live/server/room-sockets.js +97 -0
  69. package/dist/live/server/room.d.ts +20 -0
  70. package/dist/live/server/room.js +348 -0
  71. package/dist/live/server/route.d.ts +56 -0
  72. package/dist/live/server/route.js +159 -0
  73. package/dist/live/server/types.d.ts +163 -0
  74. package/dist/live/server/types.js +2 -0
  75. package/dist/logic/agent-actions.d.ts +133 -0
  76. package/dist/logic/agent-actions.js +150 -0
  77. package/dist/logic/command-types.d.ts +53 -0
  78. package/dist/logic/command-types.js +0 -0
  79. package/dist/logic/dev.d.ts +9 -0
  80. package/dist/logic/dev.js +10 -0
  81. package/dist/logic/draft-rebase.d.ts +59 -0
  82. package/dist/logic/draft-rebase.js +71 -0
  83. package/dist/logic/form-state.d.ts +105 -0
  84. package/dist/logic/form-state.js +93 -0
  85. package/dist/logic/head.d.ts +145 -0
  86. package/dist/logic/head.js +140 -0
  87. package/dist/logic/index.d.ts +27 -0
  88. package/dist/logic/index.js +25 -0
  89. package/dist/logic/island-def.d.ts +89 -0
  90. package/dist/logic/island-def.js +59 -0
  91. package/dist/logic/kit-commands.d.ts +104 -0
  92. package/dist/logic/kit-commands.js +72 -0
  93. package/dist/logic/kit-errors.d.ts +25 -0
  94. package/dist/logic/kit-errors.js +6 -0
  95. package/dist/logic/listen.d.ts +99 -0
  96. package/dist/logic/listen.js +92 -0
  97. package/dist/logic/mutation-def.d.ts +65 -0
  98. package/dist/logic/mutation-def.js +43 -0
  99. package/dist/logic/navigation-data.d.ts +50 -0
  100. package/dist/logic/navigation-data.js +55 -0
  101. package/dist/logic/navigation-policy.d.ts +74 -0
  102. package/dist/logic/navigation-policy.js +127 -0
  103. package/dist/logic/page-model-def.d.ts +108 -0
  104. package/dist/logic/page-model-def.js +31 -0
  105. package/dist/logic/path.d.ts +31 -0
  106. package/dist/logic/path.js +48 -0
  107. package/dist/logic/query-def.d.ts +56 -0
  108. package/dist/logic/query-def.js +37 -0
  109. package/dist/logic/query-key.d.ts +24 -0
  110. package/dist/logic/query-key.js +35 -0
  111. package/dist/logic/query-types.d.ts +28 -0
  112. package/dist/logic/query-types.js +2 -0
  113. package/dist/logic/resources.d.ts +163 -0
  114. package/dist/logic/resources.js +62 -0
  115. package/dist/logic/result.d.ts +30 -0
  116. package/dist/logic/result.js +23 -0
  117. package/dist/logic/route-model.d.ts +139 -0
  118. package/dist/logic/route-model.js +207 -0
  119. package/dist/logic/route-params.d.ts +80 -0
  120. package/dist/logic/route-params.js +114 -0
  121. package/dist/logic/route-table.d.ts +308 -0
  122. package/dist/logic/route-table.js +206 -0
  123. package/dist/logic/seo.d.ts +61 -0
  124. package/dist/logic/seo.js +101 -0
  125. package/dist/logic/site.d.ts +12 -0
  126. package/dist/logic/site.js +0 -0
  127. package/dist/logic/subscriptions.d.ts +177 -0
  128. package/dist/logic/subscriptions.js +152 -0
  129. package/dist/render/index.d.ts +32 -0
  130. package/dist/render/index.js +52 -0
  131. package/dist/runtime/island-wake.d.ts +38 -0
  132. package/dist/runtime/island-wake.js +147 -0
  133. package/dist/runtime/query-scope.d.ts +224 -0
  134. package/dist/runtime/query-scope.js +222 -0
  135. package/dist/runtime/room-hub.d.ts +107 -0
  136. package/dist/runtime/room-hub.js +307 -0
  137. package/dist/runtime/subscription-runner.d.ts +71 -0
  138. package/dist/runtime/subscription-runner.js +240 -0
  139. package/dist/server/bindings.d.ts +41 -0
  140. package/dist/server/bindings.js +74 -0
  141. package/dist/server/browser.d.ts +9 -0
  142. package/dist/server/browser.js +9 -0
  143. package/dist/server/edge-cache.d.ts +28 -0
  144. package/dist/server/edge-cache.js +35 -0
  145. package/dist/server/errors.d.ts +45 -0
  146. package/dist/server/errors.js +36 -0
  147. package/dist/server/form-actions-setup.d.ts +1 -0
  148. package/dist/server/form-actions-setup.js +15 -0
  149. package/dist/server/form-actions.d.ts +121 -0
  150. package/dist/server/form-actions.js +211 -0
  151. package/dist/server/index.d.ts +36 -0
  152. package/dist/server/index.js +35 -0
  153. package/dist/server/inputs.d.ts +45 -0
  154. package/dist/server/inputs.js +77 -0
  155. package/dist/server/rate-limit.d.ts +29 -0
  156. package/dist/server/rate-limit.js +32 -0
  157. package/dist/server/read-cache.d.ts +74 -0
  158. package/dist/server/read-cache.js +58 -0
  159. package/dist/server/request-info.d.ts +17 -0
  160. package/dist/server/request-info.js +11 -0
  161. package/dist/server/request.d.ts +52 -0
  162. package/dist/server/request.js +73 -0
  163. package/dist/server/response-cookies.d.ts +23 -0
  164. package/dist/server/response-cookies.js +24 -0
  165. package/dist/server/run-effect.d.ts +42 -0
  166. package/dist/server/run-effect.js +92 -0
  167. package/dist/server/run.d.ts +63 -0
  168. package/dist/server/run.js +66 -0
  169. package/dist/server/session.d.ts +125 -0
  170. package/dist/server/session.js +247 -0
  171. package/dist/test/fake-bindings.d.ts +32 -0
  172. package/dist/test/fake-bindings.js +108 -0
  173. package/dist/test/fake-room.d.ts +66 -0
  174. package/dist/test/fake-room.js +216 -0
  175. package/dist/test/index.d.ts +19 -0
  176. package/dist/test/index.js +44 -0
  177. package/dist/test/probe.d.ts +11 -0
  178. package/dist/test/probe.js +11 -0
  179. package/dist/test/solid-jsx.d.ts +23 -0
  180. package/dist/test/solid-jsx.js +28 -0
  181. package/dist/test/solid-preload.d.ts +1 -0
  182. package/dist/test/solid-preload.js +29 -0
  183. package/dist/ui/code-editor/index.d.ts +21 -0
  184. package/dist/ui/code-editor/index.jsx +286 -0
  185. package/dist/ui/collab-text/index.d.ts +29 -0
  186. package/dist/ui/collab-text/index.jsx +96 -0
  187. package/dist/ui/components/controls.d.ts +69 -0
  188. package/dist/ui/components/controls.jsx +81 -0
  189. package/dist/ui/components/feedback.d.ts +26 -0
  190. package/dist/ui/components/feedback.jsx +80 -0
  191. package/dist/ui/components/layout.d.ts +74 -0
  192. package/dist/ui/components/layout.jsx +146 -0
  193. package/dist/ui/components/lists.d.ts +69 -0
  194. package/dist/ui/components/lists.jsx +133 -0
  195. package/dist/ui/components/navigation.d.ts +73 -0
  196. package/dist/ui/components/navigation.jsx +112 -0
  197. package/dist/ui/components/text.d.ts +34 -0
  198. package/dist/ui/components/text.jsx +163 -0
  199. package/dist/ui/index.d.ts +7 -0
  200. package/dist/ui/index.js +7 -0
  201. package/dist/ui/jsx-runtime.d.ts +19 -0
  202. package/dist/ui/jsx-runtime.js +0 -0
  203. package/dist/ui/list-keys.d.ts +31 -0
  204. package/dist/ui/list-keys.js +45 -0
  205. package/dist/ui/styles/base.css +38 -0
  206. package/dist/ui/styles/components.css +608 -0
  207. package/dist/ui/styles/tokens.css +27 -0
  208. package/dist/ui/styles/transitions.css +23 -0
  209. package/dist/ui/styles/workbench.css +428 -0
  210. package/dist/ui/styles.css +9 -0
  211. package/dist/view/agent-actions-view.d.ts +30 -0
  212. package/dist/view/agent-actions-view.js +27 -0
  213. package/dist/view/agent-surface.d.ts +42 -0
  214. package/dist/view/agent-surface.js +123 -0
  215. package/dist/view/app-scope.d.ts +51 -0
  216. package/dist/view/app-scope.js +75 -0
  217. package/dist/view/boundary.d.ts +18 -0
  218. package/dist/view/boundary.jsx +26 -0
  219. package/dist/view/command-runner.d.ts +16 -0
  220. package/dist/view/command-runner.js +245 -0
  221. package/dist/view/form.d.ts +82 -0
  222. package/dist/view/form.jsx +109 -0
  223. package/dist/view/head-view.d.ts +31 -0
  224. package/dist/view/head-view.js +46 -0
  225. package/dist/view/index.d.ts +41 -0
  226. package/dist/view/index.js +40 -0
  227. package/dist/view/island-root.d.ts +30 -0
  228. package/dist/view/island-root.js +36 -0
  229. package/dist/view/island.d.ts +102 -0
  230. package/dist/view/island.jsx +154 -0
  231. package/dist/view/match.d.ts +41 -0
  232. package/dist/view/match.js +111 -0
  233. package/dist/view/model.d.ts +92 -0
  234. package/dist/view/model.js +162 -0
  235. package/dist/view/navigation-head.d.ts +29 -0
  236. package/dist/view/navigation-head.jsx +38 -0
  237. package/dist/view/page-model.d.ts +46 -0
  238. package/dist/view/page-model.js +146 -0
  239. package/dist/view/query-effects.d.ts +87 -0
  240. package/dist/view/query-effects.js +147 -0
  241. package/dist/view/query-ok.d.ts +45 -0
  242. package/dist/view/query-ok.js +96 -0
  243. package/dist/view/query.d.ts +115 -0
  244. package/dist/view/query.jsx +179 -0
  245. package/dist/view/result-view.d.ts +14 -0
  246. package/dist/view/result-view.jsx +15 -0
  247. package/dist/view/route-pages.d.ts +43 -0
  248. package/dist/view/route-pages.js +59 -0
  249. package/dist/view/router.d.ts +44 -0
  250. package/dist/view/router.js +123 -0
  251. package/dist/vite/dev-middleware.d.ts +12 -0
  252. package/dist/vite/dev-middleware.js +39 -0
  253. package/dist/vite/dev-objects.d.ts +25 -0
  254. package/dist/vite/dev-objects.js +127 -0
  255. package/dist/vite/dev-platform.d.ts +19 -0
  256. package/dist/vite/dev-platform.js +77 -0
  257. package/dist/vite/dev-seo-files.d.ts +11 -0
  258. package/dist/vite/dev-seo-files.js +40 -0
  259. package/dist/vite/index.d.ts +53 -0
  260. package/dist/vite/index.js +148 -0
  261. package/dist/vite/local-config.d.ts +34 -0
  262. package/dist/vite/local-config.js +72 -0
  263. package/dist/vite/worker-build.d.ts +24 -0
  264. package/dist/vite/worker-build.js +84 -0
  265. package/dist/worker/create-worker.d.ts +52 -0
  266. package/dist/worker/create-worker.js +90 -0
  267. package/dist/worker/index.d.ts +12 -0
  268. package/dist/worker/index.js +12 -0
  269. package/dist/worker/page-routes.d.ts +88 -0
  270. package/dist/worker/page-routes.js +100 -0
  271. package/dist/worker/page-status.d.ts +41 -0
  272. package/dist/worker/page-status.js +23 -0
  273. package/dist/worker/request-prelude.d.ts +69 -0
  274. package/dist/worker/request-prelude.js +107 -0
  275. package/dist/worker/security.d.ts +76 -0
  276. package/dist/worker/security.js +137 -0
  277. package/dist/worker/server-app.d.ts +54 -0
  278. package/dist/worker/server-app.js +76 -0
  279. package/guards/browser-only.js +5 -0
  280. package/guards/node-only.js +6 -0
  281. package/guards/server-only.js +5 -0
  282. package/migrations/0001-sessions.sql +22 -0
  283. package/package.json +233 -5
@@ -0,0 +1,44 @@
1
+ import { expect } from 'bun:test';
2
+ function isCommandTuple(result) {
3
+ return (Array.isArray(result) && result.length === 2 && Array.isArray(result[1]));
4
+ }
5
+ export function story(update, init) {
6
+ let current = init;
7
+ let last = [];
8
+ const all = [];
9
+ const api = {
10
+ send(msg) {
11
+ const out = update(current, msg);
12
+ if (isCommandTuple(out)) {
13
+ current = out[0];
14
+ last = out[1];
15
+ all.push(...out[1]);
16
+ }
17
+ else {
18
+ current = out;
19
+ last = [];
20
+ }
21
+ return api;
22
+ },
23
+ expectModel(check) {
24
+ check(current);
25
+ return api;
26
+ },
27
+ expectCommands(expected) {
28
+ expect(last).toEqual(expected);
29
+ return api;
30
+ },
31
+ model() {
32
+ return current;
33
+ },
34
+ lastCommands() {
35
+ return last;
36
+ },
37
+ allCommands() {
38
+ return all;
39
+ },
40
+ };
41
+ return api;
42
+ }
43
+ export * from './fake-bindings.js';
44
+ export * from './fake-room.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@alecsibilia/ui-kit/test/probe`: the kit runtime pieces an app's browser
3
+ * probes drive directly under Solid's client build (`bun
4
+ * --conditions=browser <name>.probe.ts`). JSX-free on purpose: Bun can't
5
+ * load the kit's `.tsx` view parts outside a Solid compiler, so a probe
6
+ * imports these instead of `/view`.
7
+ */
8
+ export { createKitScope, type KitScope } from '../runtime/query-scope.ts';
9
+ export { createModel } from '../view/model.ts';
10
+ export { pageModelIn } from '../view/page-model.ts';
11
+ export { byId, liveView } from '../ui/list-keys.ts';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@alecsibilia/ui-kit/test/probe`: the kit runtime pieces an app's browser
3
+ * probes drive directly under Solid's client build (`bun
4
+ * --conditions=browser <name>.probe.ts`). JSX-free on purpose: Bun can't
5
+ * load the kit's `.tsx` view parts outside a Solid compiler, so a probe
6
+ * imports these instead of `/view`.
7
+ */
8
+ export { createKitScope } from '../runtime/query-scope.js';
9
+ export { createModel } from '../view/model.js';
10
+ export { pageModelIn } from '../view/page-model.js';
11
+ export { byId, liveView } from '../ui/list-keys.js';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Compiles one Solid JSX module to plain JS with Solid's compiler, for a
3
+ * runtime that has no Solid build step (plain Bun: `bun test`, `bun run`).
4
+ *
5
+ * The published kit keeps its views as `.jsx` (`/view`, `/ui`, and the
6
+ * browser-only `/ui/code-editor`, `/ui/collab-text`, `/live/cursors`,
7
+ * `/live/collab`) so the app's Vite build compiles them with its own Solid
8
+ * settings. Bun can't run Solid JSX on its own; `solid-preload.ts` uses this
9
+ * to compile it on load. Output is server-side (`ssr`, hydratable), which is
10
+ * what a test or script under Bun renders.
11
+ *
12
+ * @param source - the module's JSX source
13
+ * @param path - its file path, for the compiler's source names
14
+ * @returns the compiled JS
15
+ *
16
+ * @example
17
+ * compileSolidJsx({ source: 'export const A = () => <b>hi</b>', path: 'a.jsx' })
18
+ * // 'import { ssr as _$ssr } from "@solidjs/web"; ...'
19
+ */
20
+ export declare function compileSolidJsx({ source, path, }: {
21
+ source: string;
22
+ path: string;
23
+ }): string;
@@ -0,0 +1,28 @@
1
+ import { transform } from '@solidjs/compiler';
2
+ /**
3
+ * Compiles one Solid JSX module to plain JS with Solid's compiler, for a
4
+ * runtime that has no Solid build step (plain Bun: `bun test`, `bun run`).
5
+ *
6
+ * The published kit keeps its views as `.jsx` (`/view`, `/ui`, and the
7
+ * browser-only `/ui/code-editor`, `/ui/collab-text`, `/live/cursors`,
8
+ * `/live/collab`) so the app's Vite build compiles them with its own Solid
9
+ * settings. Bun can't run Solid JSX on its own; `solid-preload.ts` uses this
10
+ * to compile it on load. Output is server-side (`ssr`, hydratable), which is
11
+ * what a test or script under Bun renders.
12
+ *
13
+ * @param source - the module's JSX source
14
+ * @param path - its file path, for the compiler's source names
15
+ * @returns the compiled JS
16
+ *
17
+ * @example
18
+ * compileSolidJsx({ source: 'export const A = () => <b>hi</b>', path: 'a.jsx' })
19
+ * // 'import { ssr as _$ssr } from "@solidjs/web"; ...'
20
+ */
21
+ export function compileSolidJsx({ source, path, }) {
22
+ const out = transform(source, {
23
+ filename: path,
24
+ generate: 'ssr',
25
+ hydratable: true,
26
+ });
27
+ return typeof out === 'string' ? out : out.code;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { plugin } from 'bun';
2
+ import { compileSolidJsx } from './solid-jsx.js';
3
+ /**
4
+ * A Bun preload that compiles Solid JSX (`.jsx`) as it loads, so plain Bun
5
+ * can import the kit's view subpaths from the published package.
6
+ *
7
+ * An app's Vite build doesn't need it: the Solid plugin compiles the kit.
8
+ * Add it where Bun imports a view without Vite, such as `bun test`:
9
+ *
10
+ * ```toml
11
+ * # bunfig.toml
12
+ * [test]
13
+ * preload = ["@alecsibilia/ui-kit/test/solid-preload"]
14
+ * ```
15
+ *
16
+ * It needs `@solidjs/compiler` (an optional peer dependency of the kit).
17
+ */
18
+ plugin({
19
+ name: 'ui-kit-solid-jsx',
20
+ setup(build) {
21
+ build.onLoad({ filter: /\.jsx$/ }, async ({ path }) => ({
22
+ contents: compileSolidJsx({
23
+ source: await Bun.file(path).text(),
24
+ path,
25
+ }),
26
+ loader: 'js',
27
+ }));
28
+ },
29
+ });
@@ -0,0 +1,21 @@
1
+ /** @jsxImportSource @solidjs/web */
2
+ import { type Element as SolidElement } from 'solid-js';
3
+ export interface CodeEditorSurfaceProps {
4
+ readonly snippetId: string;
5
+ readonly filename: string;
6
+ readonly value: string;
7
+ readonly startLine?: number;
8
+ readonly modified: boolean;
9
+ readonly feedbackCount: number;
10
+ readonly onChange: (nextCode: string) => void;
11
+ readonly onReset: () => void;
12
+ }
13
+ /**
14
+ * Editable CodeMirror 6 TSX snippet surface with amber `// FEEDBACK:` line
15
+ * highlighting, Tab/Shift-Tab indentation, Escape-then-Tab keyboard exit,
16
+ * `+ // FEEDBACK:` insertion, Reset, and Copy actions.
17
+ *
18
+ * Exported exclusively via `@alecsibilia/ui-kit/ui/code-editor` so it stays isolated inside
19
+ * lazy client `<Island>` chunks and never bloats the main app bundle.
20
+ */
21
+ export declare function CodeEditorSurface(props: CodeEditorSurfaceProps): SolidElement;
@@ -0,0 +1,286 @@
1
+ /** @jsxImportSource @solidjs/web */
2
+ import { defaultKeymap, history, historyKeymap, indentLess, insertTab, } from '@codemirror/commands';
3
+ import { javascript } from '@codemirror/lang-javascript';
4
+ import { bracketMatching, HighlightStyle, indentUnit, syntaxHighlighting, } from '@codemirror/language';
5
+ import { EditorState, RangeSetBuilder } from '@codemirror/state';
6
+ import { Decoration, EditorView, highlightActiveLine, keymap, lineNumbers, drawSelection, ViewPlugin, } from '@codemirror/view';
7
+ import { tags as t } from '@lezer/highlight';
8
+ import { createEffect, createSignal, onSettled, Show, untrack, } from 'solid-js';
9
+ import { Badge, Button } from '../index.js';
10
+ const highlightStyle = HighlightStyle.define([
11
+ {
12
+ tag: [t.keyword, t.modifier, t.operatorKeyword, t.controlKeyword],
13
+ color: '#c792ea',
14
+ },
15
+ { tag: [t.string, t.special(t.string), t.regexp], color: '#a5d6a7' },
16
+ { tag: [t.number, t.bool, t.null, t.atom], color: '#f78c6c' },
17
+ {
18
+ tag: [t.lineComment, t.blockComment],
19
+ color: '#6b7589',
20
+ fontStyle: 'italic',
21
+ },
22
+ {
23
+ tag: [t.function(t.variableName), t.function(t.propertyName)],
24
+ color: '#7aa2ff',
25
+ },
26
+ { tag: [t.typeName, t.className, t.namespace], color: '#ffcb6b' },
27
+ { tag: t.tagName, color: '#f07178' },
28
+ { tag: t.angleBracket, color: '#89a0c4' },
29
+ { tag: t.attributeName, color: '#ffcb6b' },
30
+ { tag: [t.propertyName, t.definition(t.variableName)], color: '#82aaff' },
31
+ { tag: [t.operator, t.punctuation, t.bracket], color: '#9aa3b5' },
32
+ ]);
33
+ const editorTheme = EditorView.theme({
34
+ '&': {
35
+ color: '#e6e8ee',
36
+ backgroundColor: '#0b0d11',
37
+ width: '100%',
38
+ minWidth: '0',
39
+ fontSize: '12.5px',
40
+ },
41
+ '&.cm-focused': { outline: 'none' },
42
+ '.cm-content:focus, .cm-content:focus-visible': { outline: 'none' },
43
+ '.cm-scroller': {
44
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
45
+ lineHeight: '20px',
46
+ overflowX: 'auto',
47
+ overflowY: 'visible',
48
+ },
49
+ '.cm-content': { caretColor: '#e6e8ee', padding: '8px 0' },
50
+ '.cm-cursor': { borderLeftColor: '#e6e8ee' },
51
+ '.cm-gutters': {
52
+ backgroundColor: '#0b0d11',
53
+ color: '#5b6475',
54
+ border: 'none',
55
+ },
56
+ '.cm-activeLine': { backgroundColor: '#ffffff08' },
57
+ '.cm-activeLineGutter': {
58
+ backgroundColor: 'transparent',
59
+ color: '#9aa3b5',
60
+ },
61
+ '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': { backgroundColor: '#2d4fa8aa' },
62
+ '.cm-feedback-line': {
63
+ backgroundColor: '#e0a93b24',
64
+ boxShadow: 'inset 3px 0 0 #e0a93b',
65
+ fontWeight: '700',
66
+ },
67
+ '.cm-feedback-line span': {
68
+ color: '#ffd37a !important',
69
+ fontStyle: 'normal !important',
70
+ },
71
+ }, { dark: true });
72
+ const FEEDBACK_LINE_RE = /\/\/\s*FEEDBACK:|\{\/\*\s*FEEDBACK:/;
73
+ const feedbackMark = Decoration.line({ class: 'cm-feedback-line' });
74
+ function feedbackDecorations(view) {
75
+ const builder = new RangeSetBuilder();
76
+ for (const { from, to } of view.visibleRanges) {
77
+ for (let pos = from; pos <= to;) {
78
+ const line = view.state.doc.lineAt(pos);
79
+ if (FEEDBACK_LINE_RE.test(line.text)) {
80
+ builder.add(line.from, line.from, feedbackMark);
81
+ }
82
+ pos = line.to + 1;
83
+ }
84
+ }
85
+ return builder.finish();
86
+ }
87
+ const feedbackPlugin = ViewPlugin.fromClass(class {
88
+ decorations;
89
+ constructor(view) {
90
+ this.decorations = feedbackDecorations(view);
91
+ }
92
+ update(update) {
93
+ if (update.docChanged || update.viewportChanged) {
94
+ this.decorations = feedbackDecorations(update.view);
95
+ }
96
+ }
97
+ }, { decorations: (v) => v.decorations });
98
+ /**
99
+ * The page's CSP nonce, read from a nonce'd script the server rendered
100
+ * (Solid's hydration script carries the per-request nonce). Browsers hide
101
+ * the `nonce` attribute value from the DOM, but expose it on the element's
102
+ * `nonce` property to same-origin script. Returns `""` when there is none
103
+ * (dev, or a hash-based prerendered page).
104
+ */
105
+ function pageNonce() {
106
+ if (typeof document === 'undefined')
107
+ return '';
108
+ const script = document.querySelector('script[nonce]');
109
+ return script?.nonce ?? '';
110
+ }
111
+ /**
112
+ * Editable CodeMirror 6 TSX snippet surface with amber `// FEEDBACK:` line
113
+ * highlighting, Tab/Shift-Tab indentation, Escape-then-Tab keyboard exit,
114
+ * `+ // FEEDBACK:` insertion, Reset, and Copy actions.
115
+ *
116
+ * Exported exclusively via `@alecsibilia/ui-kit/ui/code-editor` so it stays isolated inside
117
+ * lazy client `<Island>` chunks and never bloats the main app bundle.
118
+ */
119
+ export function CodeEditorSurface(props) {
120
+ const [copied, setCopied] = createSignal(false);
121
+ let hostEl;
122
+ let view;
123
+ let silent = false;
124
+ /**
125
+ * Creates the CodeMirror view for the current snippet. Re-run when
126
+ * `snippetId` changes (the surface stays mounted; only the editor, its
127
+ * history and line numbering are rebuilt for the new file).
128
+ *
129
+ * CSP: CodeMirror injects its theme as a `<style>` element (or a
130
+ * constructed stylesheet where `adoptedStyleSheets` exists, which CSP does
131
+ * not govern). `EditorView.cspNonce` stamps that element with the page
132
+ * nonce, so a strict `style-src 'self' 'nonce-…'` allows it.
133
+ */
134
+ const mount = (parent) => {
135
+ // One-time capture of the snippet this editor is built for (re-run on
136
+ // snippet change); later value changes go through the sync effect.
137
+ const initial = untrack(() => ({
138
+ doc: props.value,
139
+ filename: props.filename,
140
+ baseLine: props.startLine ?? 1,
141
+ }));
142
+ let tabReleased = false;
143
+ const baseLine = initial.baseLine;
144
+ const nonce = pageNonce();
145
+ const cmView = new EditorView({
146
+ parent,
147
+ state: EditorState.create({
148
+ doc: initial.doc,
149
+ extensions: [
150
+ lineNumbers({
151
+ formatNumber: (lineNo) => String(lineNo + baseLine - 1),
152
+ }),
153
+ history(),
154
+ drawSelection(),
155
+ highlightActiveLine(),
156
+ bracketMatching(),
157
+ indentUnit.of(' '),
158
+ EditorState.tabSize.of(2),
159
+ javascript({ jsx: true, typescript: true }),
160
+ syntaxHighlighting(highlightStyle),
161
+ editorTheme,
162
+ ...(nonce ? [EditorView.cspNonce.of(nonce)] : []),
163
+ feedbackPlugin,
164
+ keymap.of([
165
+ {
166
+ key: 'Escape',
167
+ run: () => {
168
+ tabReleased = true;
169
+ return true;
170
+ },
171
+ },
172
+ {
173
+ key: 'Tab',
174
+ run: (v) => (tabReleased ? false : insertTab(v)),
175
+ shift: (v) => (tabReleased ? false : indentLess(v)),
176
+ },
177
+ ...defaultKeymap,
178
+ ...historyKeymap,
179
+ ]),
180
+ EditorView.contentAttributes.of({
181
+ 'aria-label': `${initial.filename} code editor (TSX). Press Escape then Tab to leave the editor.`,
182
+ }),
183
+ EditorView.domEventHandlers({
184
+ keydown: (e) => {
185
+ if (e.key !== 'Escape' && e.key !== 'Tab')
186
+ tabReleased = false;
187
+ },
188
+ blur: () => {
189
+ tabReleased = false;
190
+ },
191
+ }),
192
+ EditorView.updateListener.of((u) => {
193
+ if (u.docChanged && !silent) {
194
+ const next = u.state.doc.toString();
195
+ untrack(() => props.onChange(next));
196
+ }
197
+ }),
198
+ ],
199
+ }),
200
+ });
201
+ view = cmView;
202
+ };
203
+ onSettled(() => {
204
+ const parent = hostEl;
205
+ if (!parent || typeof window === 'undefined')
206
+ return;
207
+ mount(parent);
208
+ return () => {
209
+ view?.destroy();
210
+ view = undefined;
211
+ };
212
+ });
213
+ // Another snippet in the same surface: rebuild the editor for it.
214
+ createEffect(() => props.snippetId, () => {
215
+ if (!view || !hostEl)
216
+ return;
217
+ view.destroy();
218
+ view = undefined;
219
+ mount(hostEl);
220
+ }, { defer: true });
221
+ // Sync external updates (e.g. Reset button or localStorage hydration) cleanly
222
+ createEffect(() => props.value, (nextVal) => {
223
+ if (!view)
224
+ return;
225
+ const current = view.state.doc.toString();
226
+ if (current === nextVal)
227
+ return;
228
+ silent = true;
229
+ view.dispatch({
230
+ changes: { from: 0, to: current.length, insert: nextVal },
231
+ });
232
+ silent = false;
233
+ }, { defer: true });
234
+ const insertFeedback = () => {
235
+ if (!view)
236
+ return;
237
+ const line = view.state.doc.lineAt(view.state.selection.main.head);
238
+ const ins = '\n// FEEDBACK: ';
239
+ view.dispatch({
240
+ changes: { from: line.to, insert: ins },
241
+ selection: { anchor: line.to + ins.length },
242
+ scrollIntoView: true,
243
+ });
244
+ view.focus();
245
+ };
246
+ const copyCode = () => {
247
+ const text = view ? view.state.doc.toString() : props.value;
248
+ if (typeof navigator !== 'undefined' && navigator.clipboard) {
249
+ void navigator.clipboard.writeText(text).then(() => {
250
+ setCopied(true);
251
+ setTimeout(() => setCopied(false), 1600);
252
+ });
253
+ }
254
+ };
255
+ return (<div class={[
256
+ 'ui-codeblock',
257
+ { 'ui-codeblock--modified': props.modified },
258
+ ]} data-testid={`editor-${props.snippetId}`}>
259
+ <div class="ui-codeblock-head">
260
+ <span class="ui-codeblock-file">{props.filename}</span>
261
+ <div class="ui-codeblock-actions">
262
+ <Badge tone="violet">CodeMirror · Active</Badge>
263
+ <Show when={props.feedbackCount > 0}>
264
+ <Badge tone="warning">
265
+ {`${props.feedbackCount} feedback`}
266
+ </Badge>
267
+ </Show>
268
+ <Show when={props.modified}>
269
+ <Badge tone="info">Edited</Badge>
270
+ </Show>
271
+ <Button size="sm" variant="primary" testId={`insert-feedback-${props.snippetId}`} onClick={insertFeedback}>
272
+ + // FEEDBACK:
273
+ </Button>
274
+ <Button size="sm" variant="ghost" testId={`reset-snippet-${props.snippetId}`} disabled={!props.modified} onClick={() => props.onReset()}>
275
+ Reset
276
+ </Button>
277
+ <Button size="sm" variant="ghost" onClick={copyCode}>
278
+ {copied() ? 'Copied' : 'Copy'}
279
+ </Button>
280
+ </div>
281
+ </div>
282
+ <div class="ui-codeeditor-host" ref={(el) => {
283
+ hostEl = el;
284
+ }}/>
285
+ </div>);
286
+ }
@@ -0,0 +1,29 @@
1
+ /** @jsxImportSource @solidjs/web */
2
+ /**
3
+ * A collaborative plain-text editor surface (`@alecsibilia/ui-kit/ui/collab-text`):
4
+ * CodeMirror 6 bound to a Yjs `Y.Text` through `y-codemirror.next` (remote
5
+ * carets and selections from Yjs awareness). Client only: loaded by the
6
+ * kit's collab part (`@alecsibilia/ui-kit/live/collab`) inside a client-only island, never
7
+ * in the server bundle or the shared client entry.
8
+ *
9
+ * It owns no document and no socket: the kit's collab part creates the
10
+ * `Y.Doc`, the awareness and the doc socket, and passes the text in. CSP:
11
+ * CodeMirror's injected styles (the theme and y-codemirror's caret styles)
12
+ * carry the page's nonce (`EditorView.cspNonce`), as in the code editor.
13
+ */
14
+ import { type Element as SolidElement } from 'solid-js';
15
+ import type { Awareness } from 'y-protocols/awareness';
16
+ import * as Y from 'yjs';
17
+ export interface CollabTextSurfaceProps {
18
+ readonly text: Y.Text;
19
+ readonly awareness: Awareness;
20
+ /** Whether the viewer may type (reactive: access can change while open). */
21
+ readonly editable: boolean;
22
+ /** Accessible name of the editor. */
23
+ readonly label: string;
24
+ /** Shown while the text is empty (editable / read-only). */
25
+ readonly placeholder: string;
26
+ readonly readOnlyPlaceholder: string;
27
+ readonly testId?: string;
28
+ }
29
+ export declare function CollabTextSurface(props: CollabTextSurfaceProps): SolidElement;
@@ -0,0 +1,96 @@
1
+ /** @jsxImportSource @solidjs/web */
2
+ import { defaultKeymap } from '@codemirror/commands';
3
+ import { Compartment, EditorState } from '@codemirror/state';
4
+ import { EditorView, keymap, placeholder as placeholderText, } from '@codemirror/view';
5
+ /**
6
+ * A collaborative plain-text editor surface (`@alecsibilia/ui-kit/ui/collab-text`):
7
+ * CodeMirror 6 bound to a Yjs `Y.Text` through `y-codemirror.next` (remote
8
+ * carets and selections from Yjs awareness). Client only: loaded by the
9
+ * kit's collab part (`@alecsibilia/ui-kit/live/collab`) inside a client-only island, never
10
+ * in the server bundle or the shared client entry.
11
+ *
12
+ * It owns no document and no socket: the kit's collab part creates the
13
+ * `Y.Doc`, the awareness and the doc socket, and passes the text in. CSP:
14
+ * CodeMirror's injected styles (the theme and y-codemirror's caret styles)
15
+ * carry the page's nonce (`EditorView.cspNonce`), as in the code editor.
16
+ */
17
+ import { createEffect, onCleanup, onSettled, } from 'solid-js';
18
+ import { yCollab, yUndoManagerKeymap } from 'y-codemirror.next';
19
+ import * as Y from 'yjs';
20
+ const theme = EditorView.theme({
21
+ '&': {
22
+ fontSize: '14px',
23
+ border: '1px solid #2a2f3a',
24
+ borderRadius: '8px',
25
+ background: '#0b0d11',
26
+ color: '#e6e8ee',
27
+ },
28
+ '&.cm-focused': { outline: '2px solid #4c6ef5' },
29
+ '.cm-content': {
30
+ padding: '10px 12px',
31
+ minHeight: '96px',
32
+ caretColor: '#e6e8ee',
33
+ fontFamily: 'system-ui, sans-serif',
34
+ lineHeight: '1.5',
35
+ },
36
+ '.cm-placeholder': { color: '#6b7589' },
37
+ '.cm-ySelectionInfo': {
38
+ fontSize: '11px',
39
+ padding: '1px 4px',
40
+ fontFamily: 'system-ui, sans-serif',
41
+ },
42
+ });
43
+ /** The page's CSP nonce (see `code-editor-surface.tsx`). */
44
+ function pageNonce() {
45
+ if (typeof document === 'undefined')
46
+ return '';
47
+ return (document.querySelector('script[nonce]')?.nonce ?? '');
48
+ }
49
+ function accessExtensions(editable, props) {
50
+ return [
51
+ EditorState.readOnly.of(!editable),
52
+ EditorView.editable.of(editable),
53
+ placeholderText(editable ? props.placeholder : props.readOnlyPlaceholder),
54
+ ];
55
+ }
56
+ export function CollabTextSurface(props) {
57
+ let host;
58
+ let view;
59
+ const access = new Compartment();
60
+ onSettled(() => {
61
+ if (!host)
62
+ return;
63
+ const undo = new Y.UndoManager(props.text);
64
+ view = new EditorView({
65
+ parent: host,
66
+ state: EditorState.create({
67
+ doc: props.text.toString(),
68
+ extensions: [
69
+ EditorView.cspNonce.of(pageNonce()),
70
+ theme,
71
+ EditorView.lineWrapping,
72
+ EditorView.contentAttributes.of({
73
+ 'aria-label': props.label,
74
+ }),
75
+ access.of(accessExtensions(props.editable, props)),
76
+ keymap.of([...yUndoManagerKeymap, ...defaultKeymap]),
77
+ yCollab(props.text, props.awareness, { undoManager: undo }),
78
+ ],
79
+ }),
80
+ });
81
+ return () => {
82
+ view?.destroy();
83
+ view = undefined;
84
+ undo.destroy();
85
+ };
86
+ });
87
+ createEffect(() => props.editable, (editable) => {
88
+ view?.dispatch({
89
+ effects: access.reconfigure(accessExtensions(editable, props)),
90
+ });
91
+ }, { defer: true });
92
+ onCleanup(() => view?.destroy());
93
+ return (<div class="ui-collab-text" data-testid={props.testId} data-editable={props.editable ? 'true' : 'false'} ref={(el) => {
94
+ host = el;
95
+ }}/>);
96
+ }
@@ -0,0 +1,69 @@
1
+ /** @jsxImportSource @solidjs/web */
2
+ import { type Element as SolidElement } from 'solid-js';
3
+ export declare function Button(props: {
4
+ readonly variant?: 'default' | 'primary' | 'danger' | 'ghost';
5
+ readonly size?: 'md' | 'sm';
6
+ readonly disabled?: boolean;
7
+ readonly onClick?: () => void;
8
+ readonly testId?: string;
9
+ readonly children: SolidElement;
10
+ }): SolidElement;
11
+ export declare function TextArea(props: {
12
+ readonly label: string;
13
+ readonly value: string;
14
+ readonly placeholder?: string;
15
+ readonly rows?: number;
16
+ readonly testId?: string;
17
+ readonly onInput: (value: string) => void;
18
+ }): SolidElement;
19
+ /**
20
+ * A `<form method="post">` to `action` (a server function's form address).
21
+ * Without JS the browser posts it; with JS a submit calls `onSubmit` with
22
+ * the form's data instead. Used by the kit's `<Form>`; app code uses that.
23
+ */
24
+ export declare function FormFrame(props: {
25
+ readonly action: string;
26
+ readonly onSubmit: (data: FormData) => void;
27
+ readonly testId?: string;
28
+ readonly busy?: boolean;
29
+ readonly children: SolidElement;
30
+ }): SolidElement;
31
+ /** A hidden form value (e.g. where to go after a no-JS submit). */
32
+ export declare function HiddenInput(props: {
33
+ readonly name: string;
34
+ readonly value: string;
35
+ }): SolidElement;
36
+ /**
37
+ * A labelled form field: label, the control (`children`), an optional
38
+ * hint, and an error slot (`role="alert"`) shown when `error` is set.
39
+ */
40
+ export declare function Field(props: {
41
+ readonly label: string;
42
+ /** Ties the label to the control (`TextInput`'s `id`). */
43
+ readonly for: string;
44
+ readonly hint?: string;
45
+ readonly error?: string;
46
+ readonly children: SolidElement;
47
+ }): SolidElement;
48
+ /**
49
+ * A single-line text input. Uncontrolled: `defaultValue` is what the server
50
+ * rendered (a re-rendered no-JS form keeps the typed value); the browser
51
+ * owns what the user types until the form submits.
52
+ */
53
+ export declare function TextInput(props: {
54
+ readonly id: string;
55
+ readonly name: string;
56
+ readonly type?: 'text' | 'email' | 'password' | 'search';
57
+ readonly defaultValue?: string;
58
+ readonly autocomplete?: string;
59
+ readonly required?: boolean;
60
+ readonly invalid?: boolean;
61
+ readonly testId?: string;
62
+ }): SolidElement;
63
+ /** The form's submit button; `disabled` while the submission runs. */
64
+ export declare function SubmitButton(props: {
65
+ readonly variant?: 'primary' | 'default' | 'danger';
66
+ readonly disabled?: boolean;
67
+ readonly testId?: string;
68
+ readonly children: SolidElement;
69
+ }): SolidElement;