@dudousxd/nestjs-catalog-react 0.16.0 → 0.18.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 (52) hide show
  1. package/README.md +39 -13
  2. package/dist/ConnectionPanel.d.ts +11 -7
  3. package/dist/ConnectionPanel.js +65 -28
  4. package/dist/ObjectExplorer.js +424 -48
  5. package/dist/PipelineConsole.d.ts +23 -126
  6. package/dist/PipelineConsole.js +39 -551
  7. package/dist/QueryConsole.js +25 -17
  8. package/dist/SavedQueryPanel.js +1 -1
  9. package/dist/TransformEditor.js +12 -3
  10. package/dist/WorkflowCanvas.js +401 -29
  11. package/dist/bundler/index.d.ts +20 -0
  12. package/dist/bundler/index.js +20 -0
  13. package/dist/bundler/shiki-subset.d.ts +83 -0
  14. package/dist/bundler/shiki-subset.js +196 -0
  15. package/dist/context.d.ts +181 -38
  16. package/dist/context.js +44 -11
  17. package/dist/diff/RevisionDiff.d.ts +67 -4
  18. package/dist/diff/RevisionDiff.js +126 -91
  19. package/dist/index.d.ts +8 -5
  20. package/dist/index.js +56 -20
  21. package/dist/routes.d.ts +54 -13
  22. package/dist/routes.js +5 -4
  23. package/dist/schema-discovery.d.ts +216 -0
  24. package/dist/schema-discovery.js +225 -0
  25. package/dist/source-fields.d.ts +1 -12
  26. package/dist/source-fields.js +13 -16
  27. package/dist/ui/code-editor.d.ts +196 -8
  28. package/dist/ui/code-editor.js +184 -72
  29. package/dist/ui/code-languages.d.ts +80 -0
  30. package/dist/ui/code-languages.js +76 -0
  31. package/dist/ui/code-theme.d.ts +25 -0
  32. package/dist/ui/code-theme.js +26 -0
  33. package/dist/ui/dialog.d.ts +13 -1
  34. package/dist/ui/dialog.js +13 -2
  35. package/dist/workflow/graph.js +31 -9
  36. package/dist/workflow/index.d.ts +2 -0
  37. package/dist/workflow/index.js +7 -0
  38. package/dist/workflow/lifecycle.d.ts +164 -0
  39. package/dist/workflow/lifecycle.js +249 -0
  40. package/dist/workflow/model.d.ts +1 -1
  41. package/dist/workflow/nodes.js +10 -1
  42. package/dist/workflow/runs.d.ts +38 -0
  43. package/dist/workflow/runs.js +101 -0
  44. package/dist/workflow/shape.d.ts +169 -0
  45. package/dist/workflow/shape.js +249 -0
  46. package/dist/workflow/templates.d.ts +623 -0
  47. package/dist/workflow/templates.js +1092 -0
  48. package/dist/workflow/validate.d.ts +20 -1
  49. package/dist/workflow/validate.js +41 -3
  50. package/package.json +21 -17
  51. package/dist/diff/line-diff.d.ts +0 -124
  52. package/dist/diff/line-diff.js +0 -318
@@ -1,81 +1,193 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Highlight } from 'prism-react-renderer';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Editor } from '@pierre/diffs/edit';
3
+ import { EditProvider, File } from '@pierre/diffs/react';
4
+ import { useImperativeHandle, useRef } from 'react';
3
5
  import { cn } from '../cn';
6
+ import { useCodeThemeType } from './code-theme';
4
7
  /**
5
- * A code editor: a transparent `<textarea>` over a highlighted `<pre>`.
8
+ * The options every code surface in this package shares.
6
9
  *
7
- * Written out once here because it was written out twice — the query console
8
- * and the transform editor each carried their own copy, with the same two boxes
9
- * and the same three comments, and only one of them had been taught about JSON.
10
+ * `overflow: 'scroll'` is the fix this file's header describes and must not
11
+ * become `'wrap'` without re-reading it. It is an option about WRAPPING, so what
12
+ * it settles is the horizontal axis and the meaning of `End`; the vertical one
13
+ * is the wrapper's job and is not decided here. Line numbers are the other half and are
14
+ * conspicuously ABSENT from this object: they are on unless `disableLineNumbers`
15
+ * turns them off, so the way to keep them is to not write it. `code-editor.spec`
16
+ * asserts both, because "an option nobody added" is not something a reader can
17
+ * see here.
10
18
  *
11
- * Not CodeMirror, and that is a decision rather than an omission. A textarea is
12
- * already the best plain-text input the platform has: it has the caret, the
13
- * selection, undo, IME, autofill and every accessibility affordance for free,
14
- * and a controlled editor built on a document model has to reimplement the lot
15
- * — the classic symptom being a caret that jumps to the end whenever the value
16
- * is updated from outside. What is missing here is autocomplete and bracket
17
- * matching, which nothing in this console asks for.
19
+ * The file header is off because every caller draws its own — the query
20
+ * console's toolbar, the transform editor's "Code" strip — and a second filename
21
+ * bar inside those says nothing new.
18
22
  */
19
- /**
20
- * The palette, from the console's own surface tokens.
21
- *
22
- * The previous copies both passed `themes.github`, which is a LIGHT theme — its
23
- * plain text is near-black. That was invisible for as long as the console was
24
- * light, and turned the SQL box into dark-on-dark the day the console became
25
- * dark. So the theme is defined against the same variables the shell sets
26
- * rather than picked from a list, and the two cannot drift again.
27
- */
28
- const CONSOLE_THEME = {
29
- plain: { color: 'var(--text, #e7e7ea)', backgroundColor: 'transparent' },
30
- styles: [
31
- { types: ['comment', 'prolog', 'doctype', 'cdata'], style: { color: 'var(--muted, #76767f)' } },
32
- { types: ['punctuation'], style: { color: 'var(--muted, #76767f)' } },
33
- {
34
- types: ['keyword', 'operator', 'rule', 'important', 'atrule'],
35
- style: { color: 'var(--accent, #38bdf8)' },
23
+ export function codeOptions(themeType) {
24
+ return { overflow: 'scroll', disableFileHeader: true, themeType };
25
+ }
26
+ export function CodeEditor({ value, onChange, language, label, onKeyDown, handleRef, className, readOnly, }) {
27
+ const editorRef = useRef(null);
28
+ const wrapperRef = useRef(null);
29
+ const themeType = useCodeThemeType();
30
+ /**
31
+ * The last text this editor and this prop agreed on, and how many times the
32
+ * PROP has moved on its own.
33
+ *
34
+ * The editor owns a document once it is attached, and it substitutes its own
35
+ * cached text for whatever `contents` it is handed — which is right for
36
+ * typing, and wrong for the two moments a caller genuinely replaces the body:
37
+ * opening a saved query, and switching a transform's language. Those bump the
38
+ * revision, which keys the editor, which gives the new body a fresh document.
39
+ * An echo of what the editor itself just reported does not, so typing never
40
+ * remounts.
41
+ *
42
+ * Written during render deliberately: `contents` and `key` have to agree in
43
+ * the SAME render, and an effect would ship one render showing the old body.
44
+ */
45
+ const agreed = useRef(value);
46
+ const revision = useRef(0);
47
+ if (agreed.current !== value) {
48
+ agreed.current = value;
49
+ revision.current += 1;
50
+ }
51
+ useImperativeHandle(handleRef, () => ({
52
+ focus: () => editorRef.current?.focus(),
53
+ insertAtCursor: (text) => {
54
+ const editor = editorRef.current;
55
+ const selection = editor?.getState().selections?.[0];
56
+ if (!editor || !selection) {
57
+ // No caret: nobody has focused the editor yet. Appending is what the
58
+ // old implementation did in the same case, and it is the only place a
59
+ // click on a relation name can honestly put the text.
60
+ onChange(`${value}${text}`);
61
+ return;
62
+ }
63
+ editor.applyEdits([{ range: selection, newText: text }]);
64
+ editor.focus();
36
65
  },
37
- { types: ['string', 'char', 'attr-value', 'regex'], style: { color: '#34d399' } },
38
- { types: ['number', 'boolean', 'constant', 'symbol'], style: { color: '#fbbf24' } },
39
- { types: ['function', 'class-name', 'builtin'], style: { color: '#a78bfa' } },
40
- { types: ['variable', 'attr-name', 'property', 'tag'], style: { color: '#7dd3fc' } },
41
- { types: ['deleted'], style: { color: '#f87171' } },
42
- ],
43
- };
44
- export function CodeEditor({ value, onChange, language, label, onKeyDown, textareaRef, className, padding = 'p-3', fontSize = 'text-[12px]', readOnly, }) {
45
- // Every property that affects where a glyph lands has to be identical on both
46
- // layers, or the caret drifts from the text it is supposed to be inside — one
47
- // character further off with every line.
48
- //
49
- // `leading` comes AFTER `fontSize` deliberately: tailwind-merge knows a
50
- // `text-{size}` utility can carry a line-height, so a `leading-*` written
51
- // before it is dropped as superseded — silently, and the browser default
52
- // applies to both layers instead of 1.5.
53
- const shared = cn('m-0 font-mono whitespace-pre-wrap break-words', padding, fontSize, 'leading-[1.5]');
66
+ }), [onChange, value]);
67
+ /**
68
+ * The escape hatch, and it is not optional.
69
+ *
70
+ * The editor binds `Tab` to "indent", which is what a code editor should do
71
+ * and also means Tab no longer leaves the control. Without something else that
72
+ * does, a keyboard user who focuses this box cannot get out of it — a keyboard
73
+ * trap, WCAG 2.1.2, and the one accessibility failure in this swap serious
74
+ * enough to repair rather than merely record.
75
+ *
76
+ * Escape parks focus on the wrapper, which is `tabIndex={-1}` so it can hold
77
+ * focus without joining the tab order, and Tab from THERE leaves. Tab has to
78
+ * be handled too, and that is the part that was wrong the first time: focus
79
+ * sitting on the wrapper with the editor inside it means the browser's next
80
+ * tab stop is the editor again, so Escape-then-Tab put you straight back where
81
+ * you started. Verified in Chrome, not assumed. So the Tab is taken over and
82
+ * focus is moved to the first tab stop OUTSIDE this component — which is what
83
+ * Tab was going to mean anyway.
84
+ *
85
+ * The cost is the editor's own Escape binding, "simplify selection", which
86
+ * never arrives. Collapsing a multi-cursor is worth less than being able to
87
+ * leave.
88
+ */
89
+ function onWrapperKeyDown(event) {
90
+ onKeyDown?.(event);
91
+ const wrapper = wrapperRef.current;
92
+ if (event.key === 'Escape' && !event.defaultPrevented && wrapper) {
93
+ event.preventDefault();
94
+ wrapper.focus();
95
+ }
96
+ else if (event.key === 'Tab' &&
97
+ !event.defaultPrevented &&
98
+ wrapper &&
99
+ // Only once focus has been parked. While the caret is in the editor, Tab
100
+ // still indents — that is the behaviour the hatch exists to make safe, not
101
+ // one to undo.
102
+ document.activeElement === wrapper) {
103
+ event.preventDefault();
104
+ focusOutside(wrapper, event.shiftKey ? 'backward' : 'forward');
105
+ }
106
+ // A host that claimed the key gets it exclusively — see `onKeyDown`.
107
+ if (event.defaultPrevented)
108
+ event.stopPropagation();
109
+ }
54
110
  return (
55
- // Two boxes, and the division between them is the whole point.
111
+ // Capture, not bubble, and on the wrapper rather than on the editable
112
+ // element, which is not ours to attach to. See `onKeyDown`.
56
113
  //
57
- // The outer one is the ONLY thing that scrolls. The inner one has no height
58
- // of its own, so it grows to whatever the highlighted code needs — which is
59
- // what lets the textarea be `inset-0` and still cover every line rather than
60
- // only the visible ones. When both scrolled, a long query produced two
61
- // scrollbars and scrolling the outer one left the caret over the wrong line,
62
- // because the highlight moved and the input did not.
63
- _jsx("div", { className: cn('relative overflow-auto', className), children: _jsxs("div", { className: "relative min-h-full w-full", children: [_jsx(Highlight, { code: value, language: language, theme: CONSOLE_THEME, children: ({ style, tokens, getLineProps, getTokenProps }) => (
64
- // `style` carries the theme's `plain`, which is what anything Prism
65
- // did NOT tokenise falls back to. Dropping it leaves that text
66
- // inheriting from whatever is above, which happens to be right on
67
- // this console and would not be on another.
68
- _jsx("pre", { style: style, className: cn(shared, 'pointer-events-none min-h-full'), "aria-hidden": true, children: tokens.map((line, i) => (
69
- // biome-ignore lint/suspicious/noArrayIndexKey: lines have no id
70
- _jsx("div", { ...getLineProps({ line }), children: line.map((token, key) => (
71
- // biome-ignore lint/suspicious/noArrayIndexKey: tokens have no id
72
- _jsx("span", { ...getTokenProps({ token }) }, key))) }, i))) })) }), _jsx("textarea", { ref: textareaRef, value: value, onChange: (event) => onChange(event.target.value), onKeyDown: onKeyDown, spellCheck: false, readOnly: readOnly, "aria-label": label, className: cn(shared,
73
- // `overflow-hidden`, not `auto`: this layer is as tall as the code
74
- // it holds, so it has nothing to scroll — and giving it the option
75
- // back is what produced the second scrollbar.
76
- 'absolute inset-0 h-full w-full resize-none overflow-hidden bg-transparent',
77
- // Transparent text over the highlighted copy, but a VISIBLE caret
78
- // and a visible selection — those are the two things the `<pre>`
79
- // underneath cannot draw.
80
- 'text-transparent caret-zinc-900 outline-none dark:caret-zinc-100', 'selection:bg-sky-500/30 selection:text-transparent') })] }) }));
114
+ // `overflow-y-auto` is the vertical viewport — see this file's header for
115
+ // why it has to live out here — and `overflow-x-hidden` is not decoration:
116
+ // the horizontal scroller is `[data-code]` inside the shadow root, and
117
+ // leaving this axis `visible` beside a scrolling one would compute it to
118
+ // `auto` and stack a second, empty scrollbar on top of it.
119
+ _jsx("div", { ref: wrapperRef, tabIndex: -1, className: cn('relative overflow-x-hidden overflow-y-auto outline-none', className), onKeyDownCapture: onWrapperKeyDown, children: _jsx(EditProvider, { createEditor: (options) => new Editor(options), children: _jsx(File, { edit: !readOnly, file: { name: label, contents: value, lang: language, cacheKey: label }, options: codeOptions(themeType), editorOptions: {
120
+ onAttach: (instance) => {
121
+ editorRef.current = instance;
122
+ },
123
+ onChange: (next) => {
124
+ agreed.current = next.contents;
125
+ onChange(next.contents);
126
+ },
127
+ }, style: { height: '100%' } }, revision.current) }) }));
128
+ }
129
+ /**
130
+ * Everything the browser would stop at on the way through a document.
131
+ *
132
+ * Deliberately a DOCUMENT query, which cannot see inside the editor's shadow
133
+ * root — so the editor's own contenteditable is excluded for free rather than by
134
+ * a rule that could drift. `[tabindex="-1"]` is excluded because that is exactly
135
+ * what "focusable, but not a tab stop" means, and it is what the wrapper is.
136
+ */
137
+ const TAB_STOPS = [
138
+ 'a[href]',
139
+ 'button:not([disabled])',
140
+ 'input:not([disabled])',
141
+ 'select:not([disabled])',
142
+ 'textarea:not([disabled])',
143
+ 'audio[controls]',
144
+ 'video[controls]',
145
+ '[contenteditable]:not([contenteditable="false"])',
146
+ '[tabindex]:not([tabindex="-1"])',
147
+ ].join(',');
148
+ /**
149
+ * Move focus to the tab stop before or after `wrapper`, skipping its contents.
150
+ *
151
+ * Document order, from `compareDocumentPosition`, rather than `tabindex` order.
152
+ * They differ only for positive `tabindex` values, which this package never
153
+ * produces and which are a bug wherever they appear; modelling them here would
154
+ * be more code for a case that would be wrong anyway.
155
+ *
156
+ * Nothing to move to is a real answer — an editor last on the page — and it
157
+ * leaves focus on the wrapper rather than throwing it somewhere arbitrary.
158
+ */
159
+ function focusOutside(wrapper, direction) {
160
+ const stops = [...document.querySelectorAll(TAB_STOPS)].filter((node) => node instanceof HTMLElement && !wrapper.contains(node));
161
+ const after = direction === 'forward';
162
+ const found = (after ? stops : [...stops].reverse()).find((node) => {
163
+ const position = wrapper.compareDocumentPosition(node);
164
+ const mask = after ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
165
+ return (position & mask) !== 0;
166
+ });
167
+ if (found instanceof HTMLElement)
168
+ found.focus();
169
+ }
170
+ /**
171
+ * The shadow root a code surface renders into.
172
+ *
173
+ * Exported from the component rather than rewritten in every spec, because the
174
+ * boundary is a property of the dependency and not of any one test: Testing
175
+ * Library's queries stop at the host element, so `getByLabelText` and
176
+ * `getByText` cannot see a single line of code. Everything that asserts on
177
+ * rendered code goes through here, and the day the tag name changes there is one
178
+ * place to fix.
179
+ */
180
+ export function codeEditorRoot(container) {
181
+ return container.querySelector('diffs-container')?.shadowRoot ?? null;
182
+ }
183
+ /**
184
+ * The code a surface is showing, as text.
185
+ *
186
+ * `[data-content]` rather than the whole `<pre>`, which also holds the line
187
+ * numbers — reading those back would make `'1select 1'` the expected value of a
188
+ * one-line query, and the first person to add a line would not know why the
189
+ * assertion moved.
190
+ */
191
+ export function codeEditorText(container) {
192
+ return codeEditorRoot(container)?.querySelector('[data-content]')?.textContent ?? '';
81
193
  }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Every Shiki grammar and theme a code surface in this package can ask for.
3
+ *
4
+ * WHY A LIST EXISTS AT ALL
5
+ * ------------------------
6
+ * `@pierre/diffs` resolves a language through Shiki's `bundledLanguages`, which
7
+ * is a map of ~240 dynamic imports, and a theme through `@pierre/theming`'s
8
+ * collections, which are another ~75. A bundler cannot tree-shake a dynamic
9
+ * import behind a runtime key, so it emits a chunk for every one of them:
10
+ * measured on `packages/dashboard`'s SPA, 242 language chunks totalling 7.47 MB
11
+ * minified and 75 theme chunks totalling 1.58 MB, against four grammars and two
12
+ * themes this console will ever render. None of it is in the entry path — see
13
+ * `bundler/shiki-subset.ts` for what that does and does not buy — but a
14
+ * `dist/spa` where nine tenths of the files are grammars for languages the
15
+ * catalog cannot execute is not a thing to ship to a host.
16
+ *
17
+ * So the set is stated here, once, and `shikiSubset()` prunes the registries
18
+ * down to it at build time.
19
+ *
20
+ * WHY THIS LIST CANNOT GO QUIET
21
+ * -----------------------------
22
+ * A hand-maintained list of "languages we support" is exactly the shape that
23
+ * stops being true the day somebody adds a case, and the failure is silent: an
24
+ * unpruned grammar renders, a pruned one does not, and both look like code in a
25
+ * box. Three things make that impossible here rather than merely unlikely.
26
+ *
27
+ * 1. {@link CatalogCodeLanguage} is derived from this array, and it is the type
28
+ * of `CodeEditor`'s `language` prop and `DiffBody`'s. A `language` this
29
+ * bundle does not carry is a COMPILE error at the call site.
30
+ * 2. {@link TRANSFORM_HIGHLIGHTED_AS} `satisfies Record<TransformLanguage, …>`,
31
+ * so a language added to `TRANSFORM_LANGUAGES` in `@dudousxd/nestjs-catalog`
32
+ * is a compile error here until somebody says what it is highlighted as —
33
+ * and can only be answered with a grammar named above.
34
+ * 3. `shikiSubset()` fails the BUILD if any name below is absent from the
35
+ * registry it prunes, so a typo, a rename, or a Shiki release that drops a
36
+ * grammar stops the build rather than quietly shipping plain text.
37
+ */
38
+ export declare const CATALOG_CODE_LANGUAGES: readonly ["sql", "json", "tsx", "python"];
39
+ /** Anything a code surface in this package may be told to highlight. */
40
+ export type CatalogCodeLanguage = (typeof CATALOG_CODE_LANGUAGES)[number];
41
+ /**
42
+ * The two themes, and there are only ever two.
43
+ *
44
+ * `@pierre/diffs` picks between a `dark` and a `light` theme from its own
45
+ * `DEFAULT_THEMES`, which this package never overrides — `codeOptions` passes
46
+ * `themeType` (which SIDE to paint) and no `theme` (which PALETTE), so the pair
47
+ * is always Pierre's own. Both are loaded on every mount, because the editor
48
+ * hands both to the highlighter and lets CSS choose; that is why this is a pair
49
+ * rather than the one in force.
50
+ *
51
+ * The other eight `@pierre/theme` palettes — soft, vibrant, and the two colour
52
+ * vision variants of each side — are real themes that nothing here selects.
53
+ * They are named in `@pierre/theming`'s collection all the same, so they are
54
+ * eight more chunks unless they are pruned.
55
+ */
56
+ export declare const CATALOG_CODE_THEMES: readonly ["pierre-light", "pierre-dark"];
57
+ /** One of the two palettes a code surface in this package is painted with. */
58
+ export type CatalogCodeTheme = (typeof CATALOG_CODE_THEMES)[number];
59
+ /**
60
+ * What each language a transform can be WRITTEN in is HIGHLIGHTED as.
61
+ *
62
+ * The two vocabularies are not the same and should not be conflated. A
63
+ * transform's language is what the runtime executes — `TRANSFORM_LANGUAGES`,
64
+ * answered by the deployment's `/capabilities` — while a grammar is what the
65
+ * editor tokenises with, and TSX is deliberately the answer for both JavaScript
66
+ * and TypeScript: it is a superset of each, so it colours a plain `.js` body
67
+ * correctly while also surviving the type annotations in the TypeScript starter.
68
+ * Shipping `javascript` and `typescript` beside it would be another 366 KB of
69
+ * `@shikijs/langs` (181 + 186) for output no reader could tell apart.
70
+ *
71
+ * The `satisfies` is the load-bearing part. It is what turns "somebody added a
72
+ * fourth transform language" from a pane that silently loses its colours into
73
+ * two compile errors: a missing key here, and — if the answer names a grammar
74
+ * the bundle does not carry — a value that is not a {@link CatalogCodeLanguage}.
75
+ */
76
+ export declare const TRANSFORM_HIGHLIGHTED_AS: {
77
+ javascript: "tsx";
78
+ typescript: "tsx";
79
+ python: "python";
80
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Every Shiki grammar and theme a code surface in this package can ask for.
3
+ *
4
+ * WHY A LIST EXISTS AT ALL
5
+ * ------------------------
6
+ * `@pierre/diffs` resolves a language through Shiki's `bundledLanguages`, which
7
+ * is a map of ~240 dynamic imports, and a theme through `@pierre/theming`'s
8
+ * collections, which are another ~75. A bundler cannot tree-shake a dynamic
9
+ * import behind a runtime key, so it emits a chunk for every one of them:
10
+ * measured on `packages/dashboard`'s SPA, 242 language chunks totalling 7.47 MB
11
+ * minified and 75 theme chunks totalling 1.58 MB, against four grammars and two
12
+ * themes this console will ever render. None of it is in the entry path — see
13
+ * `bundler/shiki-subset.ts` for what that does and does not buy — but a
14
+ * `dist/spa` where nine tenths of the files are grammars for languages the
15
+ * catalog cannot execute is not a thing to ship to a host.
16
+ *
17
+ * So the set is stated here, once, and `shikiSubset()` prunes the registries
18
+ * down to it at build time.
19
+ *
20
+ * WHY THIS LIST CANNOT GO QUIET
21
+ * -----------------------------
22
+ * A hand-maintained list of "languages we support" is exactly the shape that
23
+ * stops being true the day somebody adds a case, and the failure is silent: an
24
+ * unpruned grammar renders, a pruned one does not, and both look like code in a
25
+ * box. Three things make that impossible here rather than merely unlikely.
26
+ *
27
+ * 1. {@link CatalogCodeLanguage} is derived from this array, and it is the type
28
+ * of `CodeEditor`'s `language` prop and `DiffBody`'s. A `language` this
29
+ * bundle does not carry is a COMPILE error at the call site.
30
+ * 2. {@link TRANSFORM_HIGHLIGHTED_AS} `satisfies Record<TransformLanguage, …>`,
31
+ * so a language added to `TRANSFORM_LANGUAGES` in `@dudousxd/nestjs-catalog`
32
+ * is a compile error here until somebody says what it is highlighted as —
33
+ * and can only be answered with a grammar named above.
34
+ * 3. `shikiSubset()` fails the BUILD if any name below is absent from the
35
+ * registry it prunes, so a typo, a rename, or a Shiki release that drops a
36
+ * grammar stops the build rather than quietly shipping plain text.
37
+ */
38
+ export const CATALOG_CODE_LANGUAGES = ['sql', 'json', 'tsx', 'python'];
39
+ /**
40
+ * The two themes, and there are only ever two.
41
+ *
42
+ * `@pierre/diffs` picks between a `dark` and a `light` theme from its own
43
+ * `DEFAULT_THEMES`, which this package never overrides — `codeOptions` passes
44
+ * `themeType` (which SIDE to paint) and no `theme` (which PALETTE), so the pair
45
+ * is always Pierre's own. Both are loaded on every mount, because the editor
46
+ * hands both to the highlighter and lets CSS choose; that is why this is a pair
47
+ * rather than the one in force.
48
+ *
49
+ * The other eight `@pierre/theme` palettes — soft, vibrant, and the two colour
50
+ * vision variants of each side — are real themes that nothing here selects.
51
+ * They are named in `@pierre/theming`'s collection all the same, so they are
52
+ * eight more chunks unless they are pruned.
53
+ */
54
+ export const CATALOG_CODE_THEMES = ['pierre-light', 'pierre-dark'];
55
+ /**
56
+ * What each language a transform can be WRITTEN in is HIGHLIGHTED as.
57
+ *
58
+ * The two vocabularies are not the same and should not be conflated. A
59
+ * transform's language is what the runtime executes — `TRANSFORM_LANGUAGES`,
60
+ * answered by the deployment's `/capabilities` — while a grammar is what the
61
+ * editor tokenises with, and TSX is deliberately the answer for both JavaScript
62
+ * and TypeScript: it is a superset of each, so it colours a plain `.js` body
63
+ * correctly while also surviving the type annotations in the TypeScript starter.
64
+ * Shipping `javascript` and `typescript` beside it would be another 366 KB of
65
+ * `@shikijs/langs` (181 + 186) for output no reader could tell apart.
66
+ *
67
+ * The `satisfies` is the load-bearing part. It is what turns "somebody added a
68
+ * fourth transform language" from a pane that silently loses its colours into
69
+ * two compile errors: a missing key here, and — if the answer names a grammar
70
+ * the bundle does not carry — a value that is not a {@link CatalogCodeLanguage}.
71
+ */
72
+ export const TRANSFORM_HIGHLIGHTED_AS = {
73
+ javascript: 'tsx',
74
+ typescript: 'tsx',
75
+ python: 'python',
76
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Which way round every code surface in this package should be painted.
3
+ *
4
+ * WHY THIS IS NOT JUST `themeType: 'system'`
5
+ * -----------------------------------------
6
+ * `@pierre/diffs` paints itself from a Shiki theme and takes a `themeType` of
7
+ * `'system' | 'light' | 'dark'`, where `'system'` means `prefers-color-scheme`.
8
+ * Everything else in this package is painted by Tailwind's `dark:` variant, and
9
+ * Tailwind supports TWO strategies for that: `media` (which is
10
+ * `prefers-color-scheme`, and matches `'system'`) and `class` (which is a `dark`
11
+ * class the host toggles, and does not).
12
+ *
13
+ * This package ships no Tailwind config — the host owns it — so it cannot know
14
+ * which one is in play, and guessing wrong is the failure the old Prism theme
15
+ * had: a code box painted for one surface sitting on the other, which reads as
16
+ * dark-on-dark rather than as a bug. So both are honoured. A `dark` class on
17
+ * `<html>` or `<body>` is a deliberate statement and wins; with no class the
18
+ * question falls back to the media query, which is what `'system'` already does.
19
+ *
20
+ * The class is watched rather than read once, because a theme toggle is a
21
+ * runtime event and a code editor that keeps yesterday's palette until a reload
22
+ * is the same complaint in a slower form.
23
+ */
24
+ export type CodeThemeType = 'system' | 'light' | 'dark';
25
+ export declare function useCodeThemeType(): CodeThemeType;
@@ -0,0 +1,26 @@
1
+ import { useEffect, useState } from 'react';
2
+ /** The class Tailwind's `class` strategy toggles, and every host that uses it toggles. */
3
+ const DARK_CLASS = 'dark';
4
+ function readThemeType() {
5
+ if (typeof document === 'undefined')
6
+ return 'system';
7
+ const marked = document.documentElement.classList.contains(DARK_CLASS) ||
8
+ document.body?.classList.contains(DARK_CLASS);
9
+ return marked ? 'dark' : 'system';
10
+ }
11
+ export function useCodeThemeType() {
12
+ const [themeType, setThemeType] = useState(readThemeType);
13
+ useEffect(() => {
14
+ const sync = () => setThemeType(readThemeType());
15
+ sync();
16
+ const observer = new MutationObserver(sync);
17
+ // `class` only. Observing everything would re-run this on every attribute
18
+ // React writes to `<body>`, and the answer can only change with the class.
19
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
20
+ if (document.body) {
21
+ observer.observe(document.body, { attributes: true, attributeFilter: ['class'] });
22
+ }
23
+ return () => observer.disconnect();
24
+ }, []);
25
+ return themeType;
26
+ }
@@ -12,7 +12,18 @@ import type { ReactNode } from 'react';
12
12
  * these screens need is "are you sure, and here is what you would break", and a
13
13
  * generic Dialog would have every call site rebuild that.
14
14
  */
15
- export declare function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel, onConfirm, pending, error,
15
+ export declare function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel, onConfirm, pending,
16
+ /**
17
+ * Held back for a reason that is not "a request is in flight".
18
+ *
19
+ * Separate from `pending` because the two look different and mean different
20
+ * things: `pending` spins, and this simply does not act. A dialog whose
21
+ * description contains a field the action needs — the acknowledgement a
22
+ * shrinking load has to carry a reason for — would otherwise have to fake it
23
+ * by passing `pending`, which puts a spinner beside an empty box and implies
24
+ * something is happening.
25
+ */
26
+ confirmDisabled, error,
16
27
  /** Set for anything unrecoverable. Colours the action, and nothing else. */
17
28
  destructive, }: {
18
29
  open: boolean;
@@ -22,6 +33,7 @@ destructive, }: {
22
33
  confirmLabel: string;
23
34
  onConfirm: () => void;
24
35
  pending?: boolean;
36
+ confirmDisabled?: boolean;
25
37
  error?: ReactNode;
26
38
  destructive?: boolean;
27
39
  }): import("react/jsx-runtime").JSX.Element;
package/dist/ui/dialog.js CHANGED
@@ -15,10 +15,21 @@ import { cn } from '../cn';
15
15
  * these screens need is "are you sure, and here is what you would break", and a
16
16
  * generic Dialog would have every call site rebuild that.
17
17
  */
18
- export function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel, onConfirm, pending, error,
18
+ export function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel, onConfirm, pending,
19
+ /**
20
+ * Held back for a reason that is not "a request is in flight".
21
+ *
22
+ * Separate from `pending` because the two look different and mean different
23
+ * things: `pending` spins, and this simply does not act. A dialog whose
24
+ * description contains a field the action needs — the acknowledgement a
25
+ * shrinking load has to carry a reason for — would otherwise have to fake it
26
+ * by passing `pending`, which puts a spinner beside an empty box and implies
27
+ * something is happening.
28
+ */
29
+ confirmDisabled, error,
19
30
  /** Set for anything unrecoverable. Colours the action, and nothing else. */
20
31
  destructive = true, }) {
21
- return (_jsx(BaseDialog.Root, { open: open, onOpenChange: onOpenChange, children: _jsxs(BaseDialog.Portal, { children: [_jsx(BaseDialog.Backdrop, { className: cn('fixed inset-0 z-50 bg-zinc-950/30 backdrop-blur-[1px] dark:bg-zinc-950/60', 'transition-opacity duration-150', 'data-[starting-style]:opacity-0 data-[ending-style]:opacity-0') }), _jsxs(BaseDialog.Popup, { className: cn('fixed left-1/2 top-1/2 z-50 w-[min(28rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2', 'rounded-lg border p-5 shadow-lg outline-none', 'border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-900', 'transition-[opacity,transform] duration-150 ease-out', 'data-[starting-style]:scale-95 data-[starting-style]:opacity-0', 'data-[ending-style]:scale-95 data-[ending-style]:opacity-0'), children: [_jsx(BaseDialog.Title, { className: "text-sm font-semibold tracking-tight", children: title }), _jsx(BaseDialog.Description, { className: "mt-1.5 text-xs leading-relaxed text-zinc-500 dark:text-zinc-400", children: description }), error && (_jsx("p", { className: "mt-3 rounded-md border border-red-200 bg-red-50 px-2.5 py-1.5 text-[11px] text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: error })), _jsxs("div", { className: "mt-5 flex justify-end gap-2", children: [_jsx(BaseDialog.Close, { className: cn('rounded-md border px-3 py-1.5 text-xs', 'border-zinc-200 hover:bg-zinc-50', 'dark:border-zinc-800 dark:hover:bg-zinc-800'), children: "Cancel" }), _jsxs("button", { type: "button", onClick: onConfirm, disabled: pending, className: cn('flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs text-white disabled:opacity-40', destructive
32
+ return (_jsx(BaseDialog.Root, { open: open, onOpenChange: onOpenChange, children: _jsxs(BaseDialog.Portal, { children: [_jsx(BaseDialog.Backdrop, { className: cn('fixed inset-0 z-50 bg-zinc-950/30 backdrop-blur-[1px] dark:bg-zinc-950/60', 'transition-opacity duration-150', 'data-[starting-style]:opacity-0 data-[ending-style]:opacity-0') }), _jsxs(BaseDialog.Popup, { className: cn('fixed left-1/2 top-1/2 z-50 w-[min(28rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2', 'rounded-lg border p-5 shadow-lg outline-none', 'border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-900', 'transition-[opacity,transform] duration-150 ease-out', 'data-[starting-style]:scale-95 data-[starting-style]:opacity-0', 'data-[ending-style]:scale-95 data-[ending-style]:opacity-0'), children: [_jsx(BaseDialog.Title, { className: "text-sm font-semibold tracking-tight", children: title }), _jsx(BaseDialog.Description, { className: "mt-1.5 text-xs leading-relaxed text-zinc-500 dark:text-zinc-400", children: description }), error && (_jsx("p", { className: "mt-3 rounded-md border border-red-200 bg-red-50 px-2.5 py-1.5 text-[11px] text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: error })), _jsxs("div", { className: "mt-5 flex justify-end gap-2", children: [_jsx(BaseDialog.Close, { className: cn('rounded-md border px-3 py-1.5 text-xs', 'border-zinc-200 hover:bg-zinc-50', 'dark:border-zinc-800 dark:hover:bg-zinc-800'), children: "Cancel" }), _jsxs("button", { type: "button", onClick: onConfirm, disabled: pending || confirmDisabled, className: cn('flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs text-white disabled:opacity-40', destructive
22
33
  ? 'bg-red-600 hover:bg-red-700'
23
34
  : 'bg-zinc-950 hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-950'), children: [pending && _jsx(Loader2, { size: 12, className: "animate-spin" }), confirmLabel] })] })] })] }) }));
24
35
  }
@@ -33,21 +33,41 @@ const ROW_GAP = 32;
33
33
  * circular, since a connector references a workflow.
34
34
  */
35
35
  function subtitleFor(node, describe) {
36
- if (node.kind === 'source') {
37
- const kind = typeof node.sourceKind === 'string' ? node.sourceKind : '';
38
- if (kind.length === 0)
39
- return 'no source kind chosen';
40
- const connection = describe.connectionName(node.connectionId);
41
- if (connection)
42
- return `${kind} · ${connection}`;
43
- return node.mode === 'incremental' ? `${kind} · incremental` : kind;
44
- }
36
+ if (node.kind === 'source')
37
+ return sourceSubtitle(node, describe);
45
38
  if (node.kind === 'sink') {
46
39
  const type = typeof node.targetType === 'string' ? node.targetType.trim() : '';
47
40
  return type.length > 0 ? `commits ${type}` : 'no object type chosen';
48
41
  }
42
+ if (node.kind === 'call')
43
+ return callSubtitle(node);
49
44
  return describe.transformName(node.transformId) ?? 'no transform chosen';
50
45
  }
46
+ /** What a source reads from: its kind, and the connection or mode that narrows it. */
47
+ function sourceSubtitle(node, describe) {
48
+ const kind = typeof node.sourceKind === 'string' ? node.sourceKind : '';
49
+ if (kind.length === 0)
50
+ return 'no source kind chosen';
51
+ const connection = describe.connectionName(node.connectionId);
52
+ if (connection)
53
+ return `${kind} · ${connection}`;
54
+ return node.mode === 'incremental' ? `${kind} · incremental` : kind;
55
+ }
56
+ /**
57
+ * `name@version`, and the version is on the face of the node deliberately.
58
+ *
59
+ * It is the half that decides which code actually runs and the half people
60
+ * forget is there: a node reading `billing` and a node reading `billing@2` are
61
+ * different loads, and only one of them is pinned. So an unpinned call says so
62
+ * on the canvas rather than only in the inspector nobody has open.
63
+ */
64
+ function callSubtitle(node) {
65
+ const name = typeof node.callName === 'string' ? node.callName.trim() : '';
66
+ const version = typeof node.callVersion === 'string' ? node.callVersion.trim() : '';
67
+ if (name.length === 0)
68
+ return 'no workflow chosen';
69
+ return version.length > 0 ? `${name}@${version}` : `${name} · no version pinned`;
70
+ }
51
71
  /**
52
72
  * The sentence a screen reader reads when a node takes focus.
53
73
  *
@@ -111,6 +131,8 @@ export function defaultLabel(kind) {
111
131
  return 'Source';
112
132
  if (kind === 'sink')
113
133
  return 'Sink';
134
+ if (kind === 'call')
135
+ return 'Call';
114
136
  return 'Transform';
115
137
  }
116
138
  export function toFlowEdges(edges, nodes, brokenEdgeIds) {
@@ -14,3 +14,5 @@
14
14
  */
15
15
  export { WorkflowCanvas, type WorkflowCanvasProps } from '../WorkflowCanvas';
16
16
  export { layout, layoutIfUnarranged, NODE_HEIGHT, NODE_WIDTH, type WorkflowFlowEdge, type WorkflowFlowNode, type WorkflowNodeData, } from './graph';
17
+ export { AdoptionNote, PublishControls, refusedForShrink, RunControls, SchedulePanel, ShrinkRefusalNote, wasAdopted, WORKFLOW_ADOPTION_ACTOR, WorkflowStatusBadge, } from './lifecycle';
18
+ export { RunsAsPanel } from './runs';
@@ -14,3 +14,10 @@
14
14
  */
15
15
  export { WorkflowCanvas } from '../WorkflowCanvas';
16
16
  export { layout, layoutIfUnarranged, NODE_HEIGHT, NODE_WIDTH, } from './graph';
17
+ // What happens to a graph once it is drawn. Here rather than on the root entry
18
+ // because a host reaching for these is already mounting the canvas — and here
19
+ // rather than nowhere because `wasAdopted` and `refusedForShrink` are the two
20
+ // judgements a host might want to make outside a canvas: "did anybody actually
21
+ // draw this" and "was that failure the row-count bound".
22
+ export { AdoptionNote, PublishControls, refusedForShrink, RunControls, SchedulePanel, ShrinkRefusalNote, wasAdopted, WORKFLOW_ADOPTION_ACTOR, WorkflowStatusBadge, } from './lifecycle';
23
+ export { RunsAsPanel } from './runs';