@charcuterie/ui 3.17.0 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Combobox/Combobox.d.ts +14 -1
- package/dist/Combobox/Combobox.d.ts.map +1 -1
- package/dist/Combobox/Combobox.js +124 -56
- package/dist/Combobox/Combobox.js.map +1 -1
- package/dist/Combobox/ComboboxOption.d.ts +4 -1
- package/dist/Combobox/ComboboxOption.d.ts.map +1 -1
- package/dist/Combobox/ComboboxOption.js +8 -2
- package/dist/Combobox/ComboboxOption.js.map +1 -1
- package/dist/Listbox/Listbox.d.ts +13 -1
- package/dist/Listbox/Listbox.d.ts.map +1 -1
- package/dist/Listbox/Listbox.js +4 -2
- package/dist/Listbox/Listbox.js.map +1 -1
- package/dist/Listbox/ListboxOption.d.ts +4 -1
- package/dist/Listbox/ListboxOption.d.ts.map +1 -1
- package/dist/Listbox/ListboxOption.js +7 -2
- package/dist/Listbox/ListboxOption.js.map +1 -1
- package/dist/Menu/Menu.d.ts +15 -1
- package/dist/Menu/Menu.d.ts.map +1 -1
- package/dist/Menu/Menu.js +39 -5
- package/dist/Menu/Menu.js.map +1 -1
- package/dist/Menu/MenuAction.d.ts +4 -1
- package/dist/Menu/MenuAction.d.ts.map +1 -1
- package/dist/Menu/MenuAction.js +22 -4
- package/dist/Menu/MenuAction.js.map +1 -1
- package/dist/Overlay/useAnchoredOverlay.d.ts +25 -1
- package/dist/Overlay/useAnchoredOverlay.d.ts.map +1 -1
- package/dist/Overlay/useAnchoredOverlay.js +8 -4
- package/dist/Overlay/useAnchoredOverlay.js.map +1 -1
- package/dist/Overlay/usePanelItemSize.d.ts +3 -0
- package/dist/Overlay/usePanelItemSize.d.ts.map +1 -0
- package/dist/Overlay/usePanelItemSize.js +59 -0
- package/dist/Overlay/usePanelItemSize.js.map +1 -0
- package/dist/controlStyles.d.ts +30 -0
- package/dist/controlStyles.d.ts.map +1 -1
- package/dist/controlStyles.js +34 -0
- package/dist/controlStyles.js.map +1 -1
- package/dist/markdownEditorCodeMirror/MarkdownEditorCodeMirror.d.ts.map +1 -1
- package/dist/markdownEditorCodeMirror/MarkdownEditorCodeMirror.js +1 -1
- package/dist/markdownEditorCodeMirror/MarkdownEditorCodeMirror.js.map +1 -1
- package/dist/markdownEditorCodeMirror/MarkdownView.d.ts +24 -1
- package/dist/markdownEditorCodeMirror/MarkdownView.d.ts.map +1 -1
- package/dist/markdownEditorCodeMirror/MarkdownView.js +14 -2
- package/dist/markdownEditorCodeMirror/MarkdownView.js.map +1 -1
- package/dist/markdownEditorCodeMirror/livePreview.d.ts +7 -0
- package/dist/markdownEditorCodeMirror/livePreview.d.ts.map +1 -1
- package/dist/markdownEditorCodeMirror/livePreview.js +28 -2
- package/dist/markdownEditorCodeMirror/livePreview.js.map +1 -1
- package/dist/markdownEditorCodeMirror/livePreviewRanges.d.ts +22 -2
- package/dist/markdownEditorCodeMirror/livePreviewRanges.d.ts.map +1 -1
- package/dist/markdownEditorCodeMirror/livePreviewRanges.js +26 -7
- package/dist/markdownEditorCodeMirror/livePreviewRanges.js.map +1 -1
- package/dist/viewport.testHelpers.d.ts +18 -4
- package/dist/viewport.testHelpers.d.ts.map +1 -1
- package/dist/viewport.testHelpers.js +18 -6
- package/dist/viewport.testHelpers.js.map +1 -1
- package/package.json +2 -2
- package/src/Combobox/Combobox.mdx +26 -0
- package/src/Combobox/Combobox.stories.tsx +65 -0
- package/src/Combobox/Combobox.test.tsx +135 -0
- package/src/Combobox/Combobox.tsx +176 -83
- package/src/Combobox/ComboboxOption.tsx +11 -1
- package/src/Listbox/Listbox.mdx +24 -0
- package/src/Listbox/Listbox.stories.tsx +81 -5
- package/src/Listbox/Listbox.tsx +17 -0
- package/src/Listbox/ListboxOption.tsx +10 -1
- package/src/Menu/Menu.mdx +49 -0
- package/src/Menu/Menu.stories.tsx +113 -2
- package/src/Menu/Menu.test.tsx +129 -0
- package/src/Menu/Menu.tsx +62 -3
- package/src/Menu/MenuAction.tsx +29 -4
- package/src/Overlay/useAnchoredOverlay.ts +33 -5
- package/src/Overlay/usePanelItemSize.ts +71 -0
- package/src/controlStyles.ts +38 -0
- package/src/markdownEditorCodeMirror/MarkdownEditorCodeMirror.test.tsx +185 -0
- package/src/markdownEditorCodeMirror/MarkdownEditorCodeMirror.tsx +42 -1
- package/src/markdownEditorCodeMirror/MarkdownView.tsx +40 -1
- package/src/markdownEditorCodeMirror/livePreview.ts +40 -3
- package/src/markdownEditorCodeMirror/livePreviewRanges.test.ts +137 -0
- package/src/markdownEditorCodeMirror/livePreviewRanges.ts +50 -6
- package/src/sourceRules.test.ts +9 -0
- package/src/viewport.testHelpers.ts +21 -6
|
@@ -225,6 +225,26 @@ export type ToLivePreviewRangesOptions = {
|
|
|
225
225
|
* the toggle is to see the markup, not to lose the highlighting.
|
|
226
226
|
*/
|
|
227
227
|
isRawMode?: boolean
|
|
228
|
+
/**
|
|
229
|
+
* Re-point a link before it becomes an `href`.
|
|
230
|
+
*
|
|
231
|
+
* The document's own URL goes through `toSafeLinkUrl` first, so
|
|
232
|
+
* what arrives here has already been refused if it named an
|
|
233
|
+
* executable scheme. What comes BACK is the consumer's own string
|
|
234
|
+
* and is used as given — an app that returns a route is trusted
|
|
235
|
+
* about its own routes.
|
|
236
|
+
*
|
|
237
|
+
* Return `undefined` to leave the link alone, which is also what
|
|
238
|
+
* omitting this does. **Links only**: an image's `src` is not
|
|
239
|
+
* offered, because a consumer that maps a document path to a page
|
|
240
|
+
* URL would turn a working image into a broken one.
|
|
241
|
+
*
|
|
242
|
+
* The case it exists for: a relative path in a fetched or imported
|
|
243
|
+
* document. `[the runbook](../docs/runbook.md)` resolves against
|
|
244
|
+
* the page the reader is on, which is the consuming app, and lands
|
|
245
|
+
* on nothing. Only the app knows what that path means.
|
|
246
|
+
*/
|
|
247
|
+
resolveUrl?: (url: string) => string | undefined
|
|
228
248
|
selections: readonly LivePreviewSelection[]
|
|
229
249
|
text: string
|
|
230
250
|
to?: number
|
|
@@ -912,13 +932,27 @@ const isTableRendered = ({
|
|
|
912
932
|
*/
|
|
913
933
|
const toWalker = ({
|
|
914
934
|
isRawMode,
|
|
935
|
+
resolveUrl,
|
|
915
936
|
selections,
|
|
916
937
|
text,
|
|
917
938
|
}: {
|
|
918
939
|
isRawMode: boolean
|
|
940
|
+
resolveUrl:
|
|
941
|
+
| ((url: string) => string | undefined)
|
|
942
|
+
| undefined
|
|
919
943
|
selections: readonly LivePreviewSelection[]
|
|
920
944
|
text: string
|
|
921
945
|
}) => {
|
|
946
|
+
/**
|
|
947
|
+
* The consumer's answer, or the document's own URL.
|
|
948
|
+
*
|
|
949
|
+
* Applied at the two places a LINK's URL is pushed, and nowhere
|
|
950
|
+
* else, so every downstream consumer — the anchor's `href`, the
|
|
951
|
+
* span the editor opens from, a link inside a table cell — gets
|
|
952
|
+
* the same answer without knowing this exists.
|
|
953
|
+
*/
|
|
954
|
+
const toHref = (url: string) => resolveUrl?.(url) ?? url
|
|
955
|
+
|
|
922
956
|
const toEnter = (ranges: LivePreviewRange[]) => {
|
|
923
957
|
const pushMarker = (
|
|
924
958
|
from: number,
|
|
@@ -1149,7 +1183,7 @@ const toWalker = ({
|
|
|
1149
1183
|
markKind: "linkText",
|
|
1150
1184
|
to: closeMark.from,
|
|
1151
1185
|
type: "mark",
|
|
1152
|
-
url: safeUrl,
|
|
1186
|
+
url: toHref(safeUrl),
|
|
1153
1187
|
})
|
|
1154
1188
|
}
|
|
1155
1189
|
|
|
@@ -1189,7 +1223,7 @@ const toWalker = ({
|
|
|
1189
1223
|
markKind: "autolink",
|
|
1190
1224
|
to: nodeRef.to,
|
|
1191
1225
|
type: "mark",
|
|
1192
|
-
url: safeUrl,
|
|
1226
|
+
url: toHref(safeUrl),
|
|
1193
1227
|
})
|
|
1194
1228
|
} else {
|
|
1195
1229
|
ranges.push({
|
|
@@ -1316,6 +1350,7 @@ const toWalker = ({
|
|
|
1316
1350
|
export const toLivePreviewRanges = ({
|
|
1317
1351
|
from,
|
|
1318
1352
|
isRawMode = false,
|
|
1353
|
+
resolveUrl,
|
|
1319
1354
|
selections,
|
|
1320
1355
|
text,
|
|
1321
1356
|
to,
|
|
@@ -1326,9 +1361,12 @@ export const toLivePreviewRanges = ({
|
|
|
1326
1361
|
tree.iterate({
|
|
1327
1362
|
from,
|
|
1328
1363
|
to,
|
|
1329
|
-
enter: toWalker({
|
|
1330
|
-
|
|
1331
|
-
|
|
1364
|
+
enter: toWalker({
|
|
1365
|
+
isRawMode,
|
|
1366
|
+
resolveUrl,
|
|
1367
|
+
selections,
|
|
1368
|
+
text,
|
|
1369
|
+
})(ranges),
|
|
1332
1370
|
})
|
|
1333
1371
|
|
|
1334
1372
|
return ranges
|
|
@@ -1361,6 +1399,7 @@ const TABLE_CONTAINER_NAMES = new Set([
|
|
|
1361
1399
|
*/
|
|
1362
1400
|
export const toLivePreviewTableRanges = ({
|
|
1363
1401
|
isRawMode = false,
|
|
1402
|
+
resolveUrl,
|
|
1364
1403
|
selections,
|
|
1365
1404
|
text,
|
|
1366
1405
|
tree,
|
|
@@ -1370,7 +1409,12 @@ export const toLivePreviewTableRanges = ({
|
|
|
1370
1409
|
>): LivePreviewTableRange[] => {
|
|
1371
1410
|
const ranges: LivePreviewTableRange[] = []
|
|
1372
1411
|
|
|
1373
|
-
const toEnter = toWalker({
|
|
1412
|
+
const toEnter = toWalker({
|
|
1413
|
+
isRawMode,
|
|
1414
|
+
resolveUrl,
|
|
1415
|
+
selections,
|
|
1416
|
+
text,
|
|
1417
|
+
})
|
|
1374
1418
|
|
|
1375
1419
|
tree.iterate({
|
|
1376
1420
|
enter: (nodeRef) => {
|
package/src/sourceRules.test.ts
CHANGED
|
@@ -613,6 +613,15 @@ const ENTRY_POINT_RUNTIMES: Record<
|
|
|
613
613
|
// and stays the default.
|
|
614
614
|
"./markdown-editor-codemirror": [
|
|
615
615
|
"@charcuterie/logic",
|
|
616
|
+
// The editor's toolbar renders a `Menu`, and every panel row now
|
|
617
|
+
// asks `usePanelItemSize` whether the window is short enough to
|
|
618
|
+
// step down — which is a `matchMedia` read, and `matchMedia` is
|
|
619
|
+
// behind this subpath by the same rule that keeps it out of
|
|
620
|
+
// `@charcuterie/logic`'s main entry. The main `ui` entry already
|
|
621
|
+
// reached it (`ColorSchemeSwitcher`); this one now does too. It is
|
|
622
|
+
// ~1 KB of feature-detected wrapper, not a runtime the subpath
|
|
623
|
+
// exists to keep out — that is the `@codemirror/*` set below.
|
|
624
|
+
"@charcuterie/logic/browser",
|
|
616
625
|
"@charcuterie/tokens",
|
|
617
626
|
"@codemirror/commands",
|
|
618
627
|
"@codemirror/lang-markdown",
|
|
@@ -12,10 +12,15 @@ import { page } from "@vitest/browser/context"
|
|
|
12
12
|
* fails intermittently — which is the worst possible property for
|
|
13
13
|
* the one gate that says the shell does not scroll sideways.
|
|
14
14
|
*
|
|
15
|
-
* Polling `innerWidth` is the honest wait:
|
|
16
|
-
* the media queries and the layout resolved against, so
|
|
17
|
-
*
|
|
18
|
-
* claims.
|
|
15
|
+
* Polling `innerWidth`/`innerHeight` is the honest wait: they are the
|
|
16
|
+
* same numbers the media queries and the layout resolved against, so
|
|
17
|
+
* when they match, the thing under test really is at the size the
|
|
18
|
+
* test claims.
|
|
19
|
+
*
|
|
20
|
+
* **Height counts too**, and it did not used to. A panel row's size
|
|
21
|
+
* steps down under `(height <= 40rem)` (`usePanelItemSize`), so a test
|
|
22
|
+
* that shrinks only the height would have raced the resize with
|
|
23
|
+
* nothing to wait on and measured the tall rows about half the time.
|
|
19
24
|
*/
|
|
20
25
|
export const setViewport = async ({
|
|
21
26
|
height,
|
|
@@ -28,10 +33,13 @@ export const setViewport = async ({
|
|
|
28
33
|
|
|
29
34
|
const deadline = Date.now() + 2000
|
|
30
35
|
|
|
31
|
-
while (
|
|
36
|
+
while (
|
|
37
|
+
globalThis.innerWidth !== width ||
|
|
38
|
+
globalThis.innerHeight !== height
|
|
39
|
+
) {
|
|
32
40
|
if (Date.now() > deadline) {
|
|
33
41
|
throw new Error(
|
|
34
|
-
`The viewport never reached ${width}px — it is ${globalThis.innerWidth}px. Every
|
|
42
|
+
`The viewport never reached ${width}x${height}px — it is ${globalThis.innerWidth}x${globalThis.innerHeight}px. Every size assertion after this point would be measuring the wrong page.`,
|
|
35
43
|
)
|
|
36
44
|
}
|
|
37
45
|
|
|
@@ -45,3 +53,10 @@ export const setViewport = async ({
|
|
|
45
53
|
export const PHONE = { height: 844, width: 390 }
|
|
46
54
|
|
|
47
55
|
export const DESKTOP = { height: 900, width: 1440 }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A window short enough to trip `usePanelItemSize`'s first step-down
|
|
59
|
+
* (`height <= 40rem`, so 640px) and wide enough that nothing else
|
|
60
|
+
* about the layout changes with it.
|
|
61
|
+
*/
|
|
62
|
+
export const SHORT_WINDOW = { height: 600, width: 1440 }
|