@dudousxd/nestjs-catalog-react 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ObjectExplorer.js +424 -48
- package/dist/QueryConsole.js +25 -17
- package/dist/SavedQueryPanel.js +1 -1
- package/dist/TransformEditor.js +12 -3
- package/dist/bundler/index.d.ts +20 -0
- package/dist/bundler/index.js +20 -0
- package/dist/bundler/shiki-subset.d.ts +83 -0
- package/dist/bundler/shiki-subset.js +196 -0
- package/dist/context.d.ts +20 -1
- package/dist/context.js +9 -0
- package/dist/diff/RevisionDiff.d.ts +67 -4
- package/dist/diff/RevisionDiff.js +126 -91
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -6
- package/dist/ui/code-editor.d.ts +154 -8
- package/dist/ui/code-editor.js +176 -72
- package/dist/ui/code-languages.d.ts +80 -0
- package/dist/ui/code-languages.js +76 -0
- package/dist/ui/code-theme.d.ts +25 -0
- package/dist/ui/code-theme.js +26 -0
- package/package.json +21 -17
- package/dist/diff/line-diff.d.ts +0 -124
- package/dist/diff/line-diff.js +0 -318
package/dist/ui/code-editor.js
CHANGED
|
@@ -1,81 +1,185 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
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
|
-
*
|
|
8
|
+
* The options every code surface in this package shares.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* `overflow: 'scroll'` is the fix this file's header describes and must not
|
|
11
|
+
* become `'wrap'` without re-reading it. Line numbers are the other half and are
|
|
12
|
+
* conspicuously ABSENT from this object: they are on unless `disableLineNumbers`
|
|
13
|
+
* turns them off, so the way to keep them is to not write it. `code-editor.spec`
|
|
14
|
+
* asserts both, because "an option nobody added" is not something a reader can
|
|
15
|
+
* see here.
|
|
10
16
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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.
|
|
17
|
+
* The file header is off because every caller draws its own — the query
|
|
18
|
+
* console's toolbar, the transform editor's "Code" strip — and a second filename
|
|
19
|
+
* bar inside those says nothing new.
|
|
18
20
|
*/
|
|
21
|
+
export function codeOptions(themeType) {
|
|
22
|
+
return { overflow: 'scroll', disableFileHeader: true, themeType };
|
|
23
|
+
}
|
|
24
|
+
export function CodeEditor({ value, onChange, language, label, onKeyDown, handleRef, className, readOnly, }) {
|
|
25
|
+
const editorRef = useRef(null);
|
|
26
|
+
const wrapperRef = useRef(null);
|
|
27
|
+
const themeType = useCodeThemeType();
|
|
28
|
+
/**
|
|
29
|
+
* The last text this editor and this prop agreed on, and how many times the
|
|
30
|
+
* PROP has moved on its own.
|
|
31
|
+
*
|
|
32
|
+
* The editor owns a document once it is attached, and it substitutes its own
|
|
33
|
+
* cached text for whatever `contents` it is handed — which is right for
|
|
34
|
+
* typing, and wrong for the two moments a caller genuinely replaces the body:
|
|
35
|
+
* opening a saved query, and switching a transform's language. Those bump the
|
|
36
|
+
* revision, which keys the editor, which gives the new body a fresh document.
|
|
37
|
+
* An echo of what the editor itself just reported does not, so typing never
|
|
38
|
+
* remounts.
|
|
39
|
+
*
|
|
40
|
+
* Written during render deliberately: `contents` and `key` have to agree in
|
|
41
|
+
* the SAME render, and an effect would ship one render showing the old body.
|
|
42
|
+
*/
|
|
43
|
+
const agreed = useRef(value);
|
|
44
|
+
const revision = useRef(0);
|
|
45
|
+
if (agreed.current !== value) {
|
|
46
|
+
agreed.current = value;
|
|
47
|
+
revision.current += 1;
|
|
48
|
+
}
|
|
49
|
+
useImperativeHandle(handleRef, () => ({
|
|
50
|
+
focus: () => editorRef.current?.focus(),
|
|
51
|
+
insertAtCursor: (text) => {
|
|
52
|
+
const editor = editorRef.current;
|
|
53
|
+
const selection = editor?.getState().selections?.[0];
|
|
54
|
+
if (!editor || !selection) {
|
|
55
|
+
// No caret: nobody has focused the editor yet. Appending is what the
|
|
56
|
+
// old implementation did in the same case, and it is the only place a
|
|
57
|
+
// click on a relation name can honestly put the text.
|
|
58
|
+
onChange(`${value}${text}`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
editor.applyEdits([{ range: selection, newText: text }]);
|
|
62
|
+
editor.focus();
|
|
63
|
+
},
|
|
64
|
+
}), [onChange, value]);
|
|
65
|
+
/**
|
|
66
|
+
* The escape hatch, and it is not optional.
|
|
67
|
+
*
|
|
68
|
+
* The editor binds `Tab` to "indent", which is what a code editor should do
|
|
69
|
+
* and also means Tab no longer leaves the control. Without something else that
|
|
70
|
+
* does, a keyboard user who focuses this box cannot get out of it — a keyboard
|
|
71
|
+
* trap, WCAG 2.1.2, and the one accessibility failure in this swap serious
|
|
72
|
+
* enough to repair rather than merely record.
|
|
73
|
+
*
|
|
74
|
+
* Escape parks focus on the wrapper, which is `tabIndex={-1}` so it can hold
|
|
75
|
+
* focus without joining the tab order, and Tab from THERE leaves. Tab has to
|
|
76
|
+
* be handled too, and that is the part that was wrong the first time: focus
|
|
77
|
+
* sitting on the wrapper with the editor inside it means the browser's next
|
|
78
|
+
* tab stop is the editor again, so Escape-then-Tab put you straight back where
|
|
79
|
+
* you started. Verified in Chrome, not assumed. So the Tab is taken over and
|
|
80
|
+
* focus is moved to the first tab stop OUTSIDE this component — which is what
|
|
81
|
+
* Tab was going to mean anyway.
|
|
82
|
+
*
|
|
83
|
+
* The cost is the editor's own Escape binding, "simplify selection", which
|
|
84
|
+
* never arrives. Collapsing a multi-cursor is worth less than being able to
|
|
85
|
+
* leave.
|
|
86
|
+
*/
|
|
87
|
+
function onWrapperKeyDown(event) {
|
|
88
|
+
onKeyDown?.(event);
|
|
89
|
+
const wrapper = wrapperRef.current;
|
|
90
|
+
if (event.key === 'Escape' && !event.defaultPrevented && wrapper) {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
wrapper.focus();
|
|
93
|
+
}
|
|
94
|
+
else if (event.key === 'Tab' &&
|
|
95
|
+
!event.defaultPrevented &&
|
|
96
|
+
wrapper &&
|
|
97
|
+
// Only once focus has been parked. While the caret is in the editor, Tab
|
|
98
|
+
// still indents — that is the behaviour the hatch exists to make safe, not
|
|
99
|
+
// one to undo.
|
|
100
|
+
document.activeElement === wrapper) {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
focusOutside(wrapper, event.shiftKey ? 'backward' : 'forward');
|
|
103
|
+
}
|
|
104
|
+
// A host that claimed the key gets it exclusively — see `onKeyDown`.
|
|
105
|
+
if (event.defaultPrevented)
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
}
|
|
108
|
+
return (
|
|
109
|
+
// Capture, not bubble, and on the wrapper rather than on the editable
|
|
110
|
+
// element, which is not ours to attach to. See `onKeyDown`.
|
|
111
|
+
_jsx("div", { ref: wrapperRef, tabIndex: -1, className: cn('relative overflow-hidden 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: {
|
|
112
|
+
onAttach: (instance) => {
|
|
113
|
+
editorRef.current = instance;
|
|
114
|
+
},
|
|
115
|
+
onChange: (next) => {
|
|
116
|
+
agreed.current = next.contents;
|
|
117
|
+
onChange(next.contents);
|
|
118
|
+
},
|
|
119
|
+
}, style: { height: '100%' } }, revision.current) }) }));
|
|
120
|
+
}
|
|
19
121
|
/**
|
|
20
|
-
*
|
|
122
|
+
* Everything the browser would stop at on the way through a document.
|
|
21
123
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* rather than picked from a list, and the two cannot drift again.
|
|
124
|
+
* Deliberately a DOCUMENT query, which cannot see inside the editor's shadow
|
|
125
|
+
* root — so the editor's own contenteditable is excluded for free rather than by
|
|
126
|
+
* a rule that could drift. `[tabindex="-1"]` is excluded because that is exactly
|
|
127
|
+
* what "focusable, but not a tab stop" means, and it is what the wrapper is.
|
|
27
128
|
*/
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
129
|
+
const TAB_STOPS = [
|
|
130
|
+
'a[href]',
|
|
131
|
+
'button:not([disabled])',
|
|
132
|
+
'input:not([disabled])',
|
|
133
|
+
'select:not([disabled])',
|
|
134
|
+
'textarea:not([disabled])',
|
|
135
|
+
'audio[controls]',
|
|
136
|
+
'video[controls]',
|
|
137
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
138
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
139
|
+
].join(',');
|
|
140
|
+
/**
|
|
141
|
+
* Move focus to the tab stop before or after `wrapper`, skipping its contents.
|
|
142
|
+
*
|
|
143
|
+
* Document order, from `compareDocumentPosition`, rather than `tabindex` order.
|
|
144
|
+
* They differ only for positive `tabindex` values, which this package never
|
|
145
|
+
* produces and which are a bug wherever they appear; modelling them here would
|
|
146
|
+
* be more code for a case that would be wrong anyway.
|
|
147
|
+
*
|
|
148
|
+
* Nothing to move to is a real answer — an editor last on the page — and it
|
|
149
|
+
* leaves focus on the wrapper rather than throwing it somewhere arbitrary.
|
|
150
|
+
*/
|
|
151
|
+
function focusOutside(wrapper, direction) {
|
|
152
|
+
const stops = [...document.querySelectorAll(TAB_STOPS)].filter((node) => node instanceof HTMLElement && !wrapper.contains(node));
|
|
153
|
+
const after = direction === 'forward';
|
|
154
|
+
const found = (after ? stops : [...stops].reverse()).find((node) => {
|
|
155
|
+
const position = wrapper.compareDocumentPosition(node);
|
|
156
|
+
const mask = after ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
|
|
157
|
+
return (position & mask) !== 0;
|
|
158
|
+
});
|
|
159
|
+
if (found instanceof HTMLElement)
|
|
160
|
+
found.focus();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The shadow root a code surface renders into.
|
|
164
|
+
*
|
|
165
|
+
* Exported from the component rather than rewritten in every spec, because the
|
|
166
|
+
* boundary is a property of the dependency and not of any one test: Testing
|
|
167
|
+
* Library's queries stop at the host element, so `getByLabelText` and
|
|
168
|
+
* `getByText` cannot see a single line of code. Everything that asserts on
|
|
169
|
+
* rendered code goes through here, and the day the tag name changes there is one
|
|
170
|
+
* place to fix.
|
|
171
|
+
*/
|
|
172
|
+
export function codeEditorRoot(container) {
|
|
173
|
+
return container.querySelector('diffs-container')?.shadowRoot ?? null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The code a surface is showing, as text.
|
|
177
|
+
*
|
|
178
|
+
* `[data-content]` rather than the whole `<pre>`, which also holds the line
|
|
179
|
+
* numbers — reading those back would make `'1select 1'` the expected value of a
|
|
180
|
+
* one-line query, and the first person to add a line would not know why the
|
|
181
|
+
* assertion moved.
|
|
182
|
+
*/
|
|
183
|
+
export function codeEditorText(container) {
|
|
184
|
+
return codeEditorRoot(container)?.querySelector('[data-content]')?.textContent ?? '';
|
|
81
185
|
}
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-catalog-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"./workflow": {
|
|
36
36
|
"types": "./dist/workflow/index.d.ts",
|
|
37
37
|
"default": "./dist/workflow/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./bundler": {
|
|
40
|
+
"types": "./dist/bundler/index.d.ts",
|
|
41
|
+
"default": "./dist/bundler/index.js"
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"files": [
|
|
@@ -43,10 +47,17 @@
|
|
|
43
47
|
],
|
|
44
48
|
"peerDependencies": {
|
|
45
49
|
"@base-ui/react": ">=1.6.0",
|
|
50
|
+
"@pierre/diffs": ">=1.3.3",
|
|
46
51
|
"@dnd-kit/core": ">=6",
|
|
47
52
|
"@dnd-kit/sortable": ">=10",
|
|
48
53
|
"@dnd-kit/utilities": ">=3",
|
|
54
|
+
"@dudousxd/nestjs-catalog": ">=0.1.0",
|
|
49
55
|
"@tanstack/react-query": ">=5",
|
|
56
|
+
"@tanstack/react-table": ">=9",
|
|
57
|
+
"@tiptap/core": ">=3",
|
|
58
|
+
"@tiptap/pm": ">=3",
|
|
59
|
+
"@tiptap/react": ">=3",
|
|
60
|
+
"@tiptap/starter-kit": ">=3",
|
|
50
61
|
"@visx/curve": "4.0.1-alpha.0",
|
|
51
62
|
"@visx/event": "4.0.1-alpha.0",
|
|
52
63
|
"@visx/grid": "4.0.1-alpha.0",
|
|
@@ -59,24 +70,23 @@
|
|
|
59
70
|
"d3-shape": ">=3",
|
|
60
71
|
"lucide-react": ">=0.400.0",
|
|
61
72
|
"motion": ">=11",
|
|
62
|
-
"prism-react-renderer": ">=2.4.0",
|
|
63
73
|
"react": ">=18",
|
|
64
74
|
"react-dom": ">=18",
|
|
65
75
|
"recharts": ">=2.12.0",
|
|
66
|
-
"
|
|
67
|
-
"@tanstack/react-table": ">=9",
|
|
68
|
-
"@tiptap/react": ">=3",
|
|
69
|
-
"@tiptap/starter-kit": ">=3",
|
|
70
|
-
"@tiptap/pm": ">=3",
|
|
71
|
-
"tiptap-markdown": ">=0.9",
|
|
72
|
-
"@tiptap/core": ">=3"
|
|
76
|
+
"tiptap-markdown": ">=0.9"
|
|
73
77
|
},
|
|
74
78
|
"devDependencies": {
|
|
75
79
|
"@base-ui/react": "1.6.0",
|
|
76
80
|
"@dnd-kit/core": "6.3.1",
|
|
77
81
|
"@dnd-kit/sortable": "10.0.0",
|
|
78
82
|
"@dnd-kit/utilities": "3.2.2",
|
|
83
|
+
"@pierre/diffs": "1.3.3",
|
|
79
84
|
"@tanstack/react-query": "5.99.2",
|
|
85
|
+
"@tanstack/react-table": "9.0.0",
|
|
86
|
+
"@tiptap/core": "3.29.2",
|
|
87
|
+
"@tiptap/pm": "3.29.2",
|
|
88
|
+
"@tiptap/react": "3.29.2",
|
|
89
|
+
"@tiptap/starter-kit": "3.29.2",
|
|
80
90
|
"@types/d3-array": "^3.2.2",
|
|
81
91
|
"@types/d3-shape": "^3.1.8",
|
|
82
92
|
"@types/react": "19.2.14",
|
|
@@ -94,19 +104,13 @@
|
|
|
94
104
|
"d3-shape": "^3.2.0",
|
|
95
105
|
"lucide-react": "0.552.0",
|
|
96
106
|
"motion": "^12.43.0",
|
|
97
|
-
"prism-react-renderer": "2.4.1",
|
|
98
107
|
"react": "19.2.0",
|
|
99
108
|
"react-dom": "19.2.0",
|
|
100
109
|
"recharts": "2.15.4",
|
|
101
110
|
"tailwind-merge": "3.4.1",
|
|
102
|
-
"typescript": "5.9.3",
|
|
103
|
-
"@tanstack/react-table": "9.0.0",
|
|
104
|
-
"@tiptap/react": "3.29.2",
|
|
105
|
-
"@tiptap/starter-kit": "3.29.2",
|
|
106
|
-
"@tiptap/pm": "3.29.2",
|
|
107
111
|
"tiptap-markdown": "0.9.0",
|
|
108
|
-
"
|
|
109
|
-
"@dudousxd/nestjs-catalog": "0.
|
|
112
|
+
"typescript": "5.9.3",
|
|
113
|
+
"@dudousxd/nestjs-catalog": "0.14.0"
|
|
110
114
|
},
|
|
111
115
|
"dependencies": {
|
|
112
116
|
"clsx": "2.1.1",
|