@diegopluna/narvi 0.3.1 → 0.3.3
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/components/activity/ActivityIcon.svelte +54 -0
- package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
- package/dist/components/activity/ActivityStep.svelte +47 -13
- package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
- package/dist/components/activity/ActivityThought.svelte +24 -5
- package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
- package/dist/components/activity/index.d.ts +3 -1
- package/dist/components/activity/index.js +2 -1
- package/dist/components/app-shell/AppShellHeader.svelte +18 -4
- package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
- package/dist/components/app-shell/AppShellMain.svelte +5 -1
- package/dist/components/approval/Approval.svelte +14 -1
- package/dist/components/approval/Approval.svelte.d.ts +5 -0
- package/dist/components/badge/Badge.svelte +19 -2
- package/dist/components/badge/Badge.svelte.d.ts +4 -1
- package/dist/components/button/Button.svelte +63 -13
- package/dist/components/composer/ComposerModelPicker.svelte +80 -13
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
- package/dist/components/composer/ComposerRoot.svelte +51 -12
- package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
- package/dist/components/composer/ComposerSubmit.svelte +19 -5
- package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
- package/dist/components/composer/ComposerToggle.svelte +18 -4
- package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
- package/dist/components/composer/ComposerTray.svelte +17 -3
- package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
- package/dist/components/composer/context.d.ts +4 -1
- package/dist/components/dialog/DialogContent.svelte +22 -12
- package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
- package/dist/components/divider/Divider.svelte +56 -14
- package/dist/components/divider/Divider.svelte.d.ts +13 -3
- package/dist/components/empty-state/EmptyState.svelte +12 -2
- package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
- package/dist/components/heading/Heading.svelte +15 -0
- package/dist/components/heading/Heading.svelte.d.ts +6 -0
- package/dist/components/hover-card/HoverCardContent.svelte +19 -3
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
- package/dist/components/input/Input.svelte +13 -3
- package/dist/components/input/Input.svelte.d.ts +10 -2
- package/dist/components/markdown/Markdown.svelte +22 -2
- package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
- package/dist/components/markdown/MarkdownFile.svelte +56 -10
- package/dist/components/markdown/MarkdownMath.svelte +6 -0
- package/dist/components/markdown/MarkdownTable.svelte +3 -4
- package/dist/components/markdown/context.d.ts +6 -0
- package/dist/components/markdown/labels.d.ts +7 -0
- package/dist/components/markdown/labels.js +2 -0
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -2
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/MenuCheckboxItem.svelte +50 -7
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +16 -0
- package/dist/components/menu/MenuContent.svelte +10 -2
- package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuGroup.svelte +16 -0
- package/dist/components/menu/MenuGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuItem.svelte +17 -2
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
- package/dist/components/menu/MenuLabel.svelte +22 -8
- package/dist/components/menu/MenuRadioGroup.svelte +16 -0
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuSubContent.svelte +10 -2
- package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuSubTrigger.svelte +19 -2
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
- package/dist/components/menu/group.d.ts +2 -0
- package/dist/components/menu/group.js +9 -0
- package/dist/components/menu/index.d.ts +4 -2
- package/dist/components/menu/index.js +2 -2
- package/dist/components/message/MessageBubble.svelte +40 -0
- package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
- package/dist/components/message/MessageContent.svelte +23 -14
- package/dist/components/message/MessageContent.svelte.d.ts +6 -0
- package/dist/components/message/MessageCopy.svelte +27 -15
- package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
- package/dist/components/message/MessageRoot.svelte +20 -3
- package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
- package/dist/components/message/context.d.ts +2 -0
- package/dist/components/message/index.d.ts +4 -1
- package/dist/components/message/index.js +3 -2
- package/dist/components/message/styles.d.ts +30 -0
- package/dist/components/message/styles.js +24 -0
- package/dist/components/notice/Notice.svelte +3 -3
- package/dist/components/popover/PopoverContent.svelte +27 -3
- package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
- package/dist/components/questionnaire/Questionnaire.svelte +103 -19
- package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
- package/dist/components/queued-message/QueuedMessage.svelte +44 -6
- package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
- package/dist/components/select/Select.svelte +18 -2
- package/dist/components/select/Select.svelte.d.ts +7 -0
- package/dist/components/sidebar/SidebarContent.svelte +59 -13
- package/dist/components/sidebar/SidebarContent.svelte.d.ts +6 -0
- package/dist/components/sidebar/SidebarFolder.svelte +29 -2
- package/dist/components/sidebar/SidebarGroup.svelte +50 -7
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +10 -1
- package/dist/components/sidebar/SidebarItem.svelte +136 -21
- package/dist/components/sidebar/SidebarItem.svelte.d.ts +22 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte +18 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte.d.ts +2 -0
- package/dist/components/sidebar/fold.d.ts +12 -0
- package/dist/components/sidebar/fold.js +8 -0
- package/dist/components/status-indicator/StatusDot.svelte +90 -0
- package/dist/components/status-indicator/StatusDot.svelte.d.ts +18 -0
- package/dist/components/toast/Toaster.svelte +1 -1
- package/dist/components/toggle/Toggle.svelte +12 -2
- package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
- package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
- package/dist/components/toggle-group/context.d.ts +2 -1
- package/dist/components/tooltip/TooltipContent.svelte +13 -1
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
- package/dist/components/work-fold/WorkFold.svelte +13 -4
- package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
- package/dist/focus-ring.d.ts +29 -0
- package/dist/focus-ring.js +42 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -2
- package/dist/internal/Collapse.svelte +15 -2
- package/dist/internal/Glyph.svelte +28 -0
- package/dist/internal/Glyph.svelte.d.ts +5 -0
- package/dist/internal/Tile.svelte +3 -2
- package/dist/internal/layer.d.ts +23 -0
- package/dist/internal/layer.js +19 -0
- package/dist/internal/toggle.d.ts +8 -1
- package/dist/internal/toggle.js +20 -2
- package/dist/markdown/file-paths.d.ts +7 -0
- package/dist/markdown/file-paths.js +29 -0
- package/dist/markdown/files.d.ts +22 -2
- package/dist/markdown/files.js +45 -14
- package/dist/tokens.stylex.d.ts +3 -0
- package/dist/tokens.stylex.js +5 -1
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +87 -8
- package/skills/building-ui/references/components.md +39 -38
- package/skills/markdown/SKILL.md +22 -6
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +10 -3
- package/skills/theming/SKILL.md +11 -4
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
import { measureScrollables } from './scrollable.js';
|
|
39
39
|
import { staticHtml, type StaticContext } from './static.js';
|
|
40
40
|
import { prose } from './styles.js';
|
|
41
|
+
import { visuallyHidden } from '../../visually-hidden.js';
|
|
41
42
|
|
|
42
43
|
export type MarkdownProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
43
44
|
/** The Markdown text: all of it so far, while it streams. */
|
|
@@ -479,8 +480,11 @@
|
|
|
479
480
|
if (block?.type === 'code') saveFile(codeFileName(codeTitle(block), block.lang), code);
|
|
480
481
|
} else
|
|
481
482
|
void navigator.clipboard.writeText(withoutControls(code)).then(
|
|
482
|
-
() =>
|
|
483
|
-
|
|
483
|
+
() => {
|
|
484
|
+
showCopied(button, words.copied);
|
|
485
|
+
announce(words.copied);
|
|
486
|
+
},
|
|
487
|
+
() => announce(words.copyFailed)
|
|
484
488
|
);
|
|
485
489
|
}
|
|
486
490
|
}
|
|
@@ -613,6 +617,7 @@
|
|
|
613
617
|
get labels() {
|
|
614
618
|
return words;
|
|
615
619
|
},
|
|
620
|
+
announce,
|
|
616
621
|
woken: (id) => woken.has(id),
|
|
617
622
|
task: () => ontaskchange,
|
|
618
623
|
math: {
|
|
@@ -654,6 +659,20 @@
|
|
|
654
659
|
}
|
|
655
660
|
};
|
|
656
661
|
setMarkdownContext(context);
|
|
662
|
+
|
|
663
|
+
/** What the document's status region says now: emptied a moment later, so it can say it again. */
|
|
664
|
+
let said = $state('');
|
|
665
|
+
let saidTimer: ReturnType<typeof setTimeout> | undefined;
|
|
666
|
+
function announce(message: string) {
|
|
667
|
+
clearTimeout(saidTimer);
|
|
668
|
+
// Emptied first, so the same words twice in a row are read twice
|
|
669
|
+
said = '';
|
|
670
|
+
saidTimer = setTimeout(() => {
|
|
671
|
+
said = message;
|
|
672
|
+
saidTimer = setTimeout(() => (said = ''), 2000);
|
|
673
|
+
}, 50);
|
|
674
|
+
}
|
|
675
|
+
$effect(() => () => clearTimeout(saidTimer));
|
|
657
676
|
</script>
|
|
658
677
|
|
|
659
678
|
<div
|
|
@@ -690,6 +709,7 @@
|
|
|
690
709
|
footnotes={before ? NO_FOOTNOTES : footnotes}
|
|
691
710
|
order={before ? NO_ORDER : footnoteOrder.order}
|
|
692
711
|
/>
|
|
712
|
+
<span role="status" data-markdown-status {...stylex.attrs(visuallyHidden)}>{said}</span>
|
|
693
713
|
</div>
|
|
694
714
|
|
|
695
715
|
<!--
|
|
@@ -168,6 +168,7 @@
|
|
|
168
168
|
let { node }: MarkdownDiagramProps = $props();
|
|
169
169
|
|
|
170
170
|
const md = getMarkdownContext();
|
|
171
|
+
const uid = $props.id();
|
|
171
172
|
|
|
172
173
|
const source = $derived(node.value.trim());
|
|
173
174
|
|
|
@@ -183,6 +184,29 @@
|
|
|
183
184
|
let expanded = $state(false);
|
|
184
185
|
let stage = $state<HTMLElement | null>(null);
|
|
185
186
|
|
|
187
|
+
// A diagram's name holds the first of its words: enough to know it by, not all it says
|
|
188
|
+
const NAMED_LABELS = 12;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Names the picture, which Pele leaves without a name unless its source gives a title:
|
|
192
|
+
* the words in it, so a screen reader can tell one diagram from the next.
|
|
193
|
+
*/
|
|
194
|
+
function name(element: HTMLElement) {
|
|
195
|
+
const svg = element.querySelector<SVGSVGElement>(':scope > svg');
|
|
196
|
+
if (!svg) return;
|
|
197
|
+
svg.setAttribute('role', 'img');
|
|
198
|
+
if (svg.hasAttribute('aria-labelledby')) return;
|
|
199
|
+
// Read once, while the name is written: nothing reacts to it
|
|
200
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
201
|
+
const words = new Set<string>();
|
|
202
|
+
for (const text of svg.querySelectorAll('text')) {
|
|
203
|
+
const word = text.textContent?.replace(/\s+/g, ' ').trim();
|
|
204
|
+
if (word) words.add(word);
|
|
205
|
+
if (words.size === NAMED_LABELS) break;
|
|
206
|
+
}
|
|
207
|
+
svg.setAttribute('aria-label', md.labels.diagramPicture([...words]));
|
|
208
|
+
}
|
|
209
|
+
|
|
186
210
|
/**
|
|
187
211
|
* Pele shrinks a diagram to the width it has. In a narrow column that makes its labels too
|
|
188
212
|
* small to read, so past three quarters of its own size the diagram scrolls instead.
|
|
@@ -204,6 +228,8 @@
|
|
|
204
228
|
([pele, sanitize]) => {
|
|
205
229
|
if (gone) return;
|
|
206
230
|
mounted = pele.mount(element, text, {
|
|
231
|
+
// Two drawings of one diagram, and two diagrams, keep the ids of their titles apart
|
|
232
|
+
idPrefix: `${md.id}-diagram-${uid}-${zoom ? 'zoom' : 'page'}`,
|
|
207
233
|
links: false,
|
|
208
234
|
images: false,
|
|
209
235
|
zoom: zoom
|
|
@@ -222,6 +248,7 @@
|
|
|
222
248
|
onRender: () => {
|
|
223
249
|
failure = null;
|
|
224
250
|
drawn = true;
|
|
251
|
+
name(element);
|
|
225
252
|
if (!zoom) keepLegible(element);
|
|
226
253
|
},
|
|
227
254
|
onError: (cause) =>
|
|
@@ -242,6 +269,9 @@
|
|
|
242
269
|
}
|
|
243
270
|
|
|
244
271
|
$effect(() => draw(canvas, false));
|
|
272
|
+
$effect(() => {
|
|
273
|
+
if (failure) md.announce(md.labels.diagramFailed(failure.message));
|
|
274
|
+
});
|
|
245
275
|
// The full-size view draws its own copy, which pans and zooms
|
|
246
276
|
$effect(() => draw(stage, true));
|
|
247
277
|
</script>
|
|
@@ -263,8 +293,9 @@
|
|
|
263
293
|
{/if}
|
|
264
294
|
</div>
|
|
265
295
|
{#if failure}
|
|
266
|
-
<!--
|
|
267
|
-
|
|
296
|
+
<!-- Read out through the reply's one status region (below), not a region of its own:
|
|
297
|
+
said, not shouted, as a thread can open with several of these -->
|
|
298
|
+
<p data-markdown-diagram-failure {...attrs([styles.failure])}>
|
|
268
299
|
{md.labels.diagramFailed(failure.message)}
|
|
269
300
|
</p>
|
|
270
301
|
{/if}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
A file named in a reply, as a chip:
|
|
3
|
-
|
|
2
|
+
A file named in a reply, as a chip: an icon for its kind (a folder, code, an image, text,
|
|
3
|
+
data) or the app's own, its name, with the whole path as its title. With a way to open
|
|
4
|
+
files it is a button; without one it only shows.
|
|
4
5
|
-->
|
|
5
6
|
<script lang="ts" module>
|
|
6
7
|
import * as stylex from '@stylexjs/stylex';
|
|
7
8
|
import type { Snippet } from 'svelte';
|
|
8
|
-
import Glyph, { glyphHtml } from '../../internal/Glyph.svelte';
|
|
9
|
+
import Glyph, { glyphHtml, type GlyphName } from '../../internal/Glyph.svelte';
|
|
9
10
|
import { attrs, classes } from '../../internal/sx.js';
|
|
10
11
|
import type { StaticTools } from '../../markdown/plugin.js';
|
|
11
12
|
import type { InlineCustom } from '../../markdown/ast.js';
|
|
12
|
-
import { formatPosition, type FileReference } from '../../markdown/file-paths.js';
|
|
13
|
+
import { formatPosition, type FileKind, type FileReference } from '../../markdown/file-paths.js';
|
|
13
14
|
import { colors, motion, radius } from '../../tokens.stylex.js';
|
|
14
15
|
import { media } from '../../media.stylex.js';
|
|
15
16
|
|
|
@@ -59,6 +60,18 @@
|
|
|
59
60
|
// A chip made from a link keeps the link's words, in the text's own face
|
|
60
61
|
words: { fontFamily: 'inherit', fontSize: '0.9375em' },
|
|
61
62
|
icon: { flexShrink: 0, color: colors.textSubtle },
|
|
63
|
+
// The app's own icon, an SVG drawn as a mask in the colour it gives, or the icon's
|
|
64
|
+
own: {
|
|
65
|
+
display: 'inline-block',
|
|
66
|
+
width: '12px',
|
|
67
|
+
height: '12px',
|
|
68
|
+
backgroundColor: 'currentColor',
|
|
69
|
+
maskImage: 'var(--narvi-file-icon)',
|
|
70
|
+
maskSize: 'contain',
|
|
71
|
+
maskRepeat: 'no-repeat',
|
|
72
|
+
maskPosition: 'center',
|
|
73
|
+
forcedColorAdjust: 'auto'
|
|
74
|
+
},
|
|
62
75
|
label: { minWidth: 0, overflowWrap: 'anywhere' }
|
|
63
76
|
});
|
|
64
77
|
|
|
@@ -69,6 +82,32 @@
|
|
|
69
82
|
buttonWords: classes(styles.chip, styles.button, styles.words)
|
|
70
83
|
};
|
|
71
84
|
const iconClass = classes(styles.icon);
|
|
85
|
+
const ownIconClass = classes(styles.icon, styles.own);
|
|
86
|
+
|
|
87
|
+
type ChipData = FileReference & {
|
|
88
|
+
source: string;
|
|
89
|
+
link?: boolean | undefined;
|
|
90
|
+
kind?: FileKind | undefined;
|
|
91
|
+
icon?: { url: string; color?: string | undefined } | undefined;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const KIND_GLYPHS: Record<FileKind, GlyphName> = {
|
|
95
|
+
folder: 'folder',
|
|
96
|
+
code: 'fileCode',
|
|
97
|
+
image: 'fileImage',
|
|
98
|
+
text: 'fileText',
|
|
99
|
+
data: 'fileData',
|
|
100
|
+
file: 'file'
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** The icon as markup: the app's own, or Narvi's for the kind. */
|
|
104
|
+
function iconHtml(file: ChipData, escape: (text: string) => string): string {
|
|
105
|
+
if (file.icon) {
|
|
106
|
+
const color = file.icon.color ? `; color: ${escape(file.icon.color)}` : '';
|
|
107
|
+
return `<span aria-hidden="true" class="${ownIconClass}" style="--narvi-file-icon: url("${escape(file.icon.url)}")${color}"></span>`;
|
|
108
|
+
}
|
|
109
|
+
return glyphHtml(KIND_GLYPHS[file.kind ?? 'file'], 12, 1.5, iconClass);
|
|
110
|
+
}
|
|
72
111
|
const labelClass = classes(styles.label);
|
|
73
112
|
|
|
74
113
|
/**
|
|
@@ -76,11 +115,11 @@
|
|
|
76
115
|
* file it names, for `chipFile` to read back when it is pressed.
|
|
77
116
|
*/
|
|
78
117
|
export function fileHtml(node: InlineCustom, opens: boolean, tools: StaticTools): string {
|
|
79
|
-
const file = node.data as
|
|
118
|
+
const file = node.data as ChipData;
|
|
80
119
|
const attributes =
|
|
81
120
|
` data-markdown-file="true" data-markdown-copy="${tools.escape(file.source)}"` +
|
|
82
121
|
` title="${tools.escape(file.path + formatPosition(file))}"`;
|
|
83
|
-
const inside = `${
|
|
122
|
+
const inside = `${iconHtml(file, tools.escape)}<span class="${labelClass}">${tools.children()}</span>`;
|
|
84
123
|
if (!opens)
|
|
85
124
|
return `<span${attributes} class="${file.link ? chipClass.shownWords : chipClass.shown}">${inside}</span>`;
|
|
86
125
|
const { path, line, column, endLine } = file;
|
|
@@ -102,14 +141,21 @@
|
|
|
102
141
|
<script lang="ts">
|
|
103
142
|
let { node, children, open }: MarkdownFileProps = $props();
|
|
104
143
|
|
|
105
|
-
const file = $derived(
|
|
106
|
-
node.data as FileReference & { source: string; link?: boolean | undefined }
|
|
107
|
-
);
|
|
144
|
+
const file = $derived(node.data as ChipData);
|
|
108
145
|
const title = $derived(file.path + formatPosition(file));
|
|
109
146
|
</script>
|
|
110
147
|
|
|
111
148
|
{#snippet content()}
|
|
112
|
-
|
|
149
|
+
{#if file.icon}
|
|
150
|
+
<span
|
|
151
|
+
aria-hidden="true"
|
|
152
|
+
style:--narvi-file-icon={`url("${file.icon.url}")`}
|
|
153
|
+
style:color={file.icon.color}
|
|
154
|
+
{...attrs([styles.icon, styles.own])}
|
|
155
|
+
></span>
|
|
156
|
+
{:else}
|
|
157
|
+
<Glyph name={KIND_GLYPHS[file.kind ?? 'file']} size={12} {...attrs([styles.icon])} />
|
|
158
|
+
{/if}
|
|
113
159
|
<span {...attrs([styles.label])}>{@render children?.()}</span>
|
|
114
160
|
{/snippet}
|
|
115
161
|
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
// characters takes seconds, and 85 KB of nested braces make 12 MB of markup. No formula a
|
|
38
38
|
// person reads is this long; a longer one shows as its source.
|
|
39
39
|
const MAX_TEX = 10_000;
|
|
40
|
+
// KaTeX escapes the TeX it writes here, so no `<` comes before the closing tag
|
|
41
|
+
const ANNOTATION = /<annotation encoding="application\/x-tex">[^<]*<\/annotation>/g;
|
|
40
42
|
const MAX_MARKUP = 200_000;
|
|
41
43
|
// Many formulas, each within those limits, could still fill the page with millions of
|
|
42
44
|
// elements. A document's formulas share this much markup; past it, they show as source.
|
|
@@ -63,6 +65,10 @@
|
|
|
63
65
|
} catch {
|
|
64
66
|
html = '';
|
|
65
67
|
}
|
|
68
|
+
// KaTeX keeps the formula's TeX in its MathML as an annotation. Hidden as it is, the
|
|
69
|
+
// page's find and a test's text search still find it, so the source reads as being
|
|
70
|
+
// on the page twice. A copy takes the TeX from `data-markdown-copy`, so it goes.
|
|
71
|
+
html = html.replace(ANNOTATION, '');
|
|
66
72
|
if (html.length > MAX_MARKUP) html = '';
|
|
67
73
|
while (cache.size >= CACHE_SIZE || (cached + html.length > CACHE_BYTES && cache.size > 0)) {
|
|
68
74
|
const oldest = cache.keys().next().value!;
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
on hover or focus, copies it as Markdown or CSV, or saves it as a CSV file.
|
|
4
4
|
-->
|
|
5
5
|
<script lang="ts" module>
|
|
6
|
-
import { visuallyHidden } from '../../visually-hidden.js';
|
|
7
6
|
import * as stylex from '@stylexjs/stylex';
|
|
8
7
|
import Glyph, { glyphHtml } from '../../internal/Glyph.svelte';
|
|
9
8
|
import { markdownTableMarker } from '../../internal/markers.stylex.js';
|
|
@@ -120,7 +119,7 @@
|
|
|
120
119
|
bare: true,
|
|
121
120
|
inner: glyphHtml('copy')
|
|
122
121
|
}) +
|
|
123
|
-
`</div
|
|
122
|
+
`</div></div>`
|
|
124
123
|
);
|
|
125
124
|
}
|
|
126
125
|
</script>
|
|
@@ -149,8 +148,10 @@
|
|
|
149
148
|
try {
|
|
150
149
|
await navigator.clipboard.writeText(text);
|
|
151
150
|
} catch {
|
|
151
|
+
md.announce(md.labels.copyFailed);
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
|
+
md.announce(md.labels.copied);
|
|
154
155
|
copied = true;
|
|
155
156
|
clearTimeout(timer);
|
|
156
157
|
timer = setTimeout(() => (copied = false), 2000);
|
|
@@ -252,7 +253,5 @@
|
|
|
252
253
|
</Menu.Root>
|
|
253
254
|
{/if}
|
|
254
255
|
</div>
|
|
255
|
-
<!-- Outside the button: a button's contents are not read out as they change -->
|
|
256
|
-
<span role="status" {...attrs([visuallyHidden])}>{copied ? md.labels.copied : ''}</span>
|
|
257
256
|
{/if}
|
|
258
257
|
</div>
|
|
@@ -35,6 +35,12 @@ export type MarkdownContext = {
|
|
|
35
35
|
breaks: () => boolean;
|
|
36
36
|
/** The words the controls show. */
|
|
37
37
|
labels: MarkdownLabels;
|
|
38
|
+
/**
|
|
39
|
+
* Says a short message to assistive technology, in the document's one status region:
|
|
40
|
+
* "Copied", or why a diagram could not be drawn. One region for the whole reply, not one
|
|
41
|
+
* per code block and table, so a long reply is not full of empty ones.
|
|
42
|
+
*/
|
|
43
|
+
announce: (message: string) => void;
|
|
38
44
|
/** Called when a task item's box is ticked or cleared, when the app takes that. */
|
|
39
45
|
task: () => ((item: ListItem, checked: boolean) => unknown) | undefined;
|
|
40
46
|
/** Whether a block that `static` wrote has been asked for as parts: a table whose menu is wanted. */
|
|
@@ -6,6 +6,8 @@ export type MarkdownLabels = {
|
|
|
6
6
|
copyCode: string;
|
|
7
7
|
downloadCode: string;
|
|
8
8
|
copied: string;
|
|
9
|
+
/** Said when the clipboard turned a copy away. */
|
|
10
|
+
copyFailed: string;
|
|
9
11
|
/** Names the table's menu button. */
|
|
10
12
|
tableActions: string;
|
|
11
13
|
copyAsMarkdown: string;
|
|
@@ -19,6 +21,11 @@ export type MarkdownLabels = {
|
|
|
19
21
|
zoomIn: string;
|
|
20
22
|
zoomOut: string;
|
|
21
23
|
resetZoom: string;
|
|
24
|
+
/**
|
|
25
|
+
* Names a diagram's picture for assistive technology, from the words in it, when its
|
|
26
|
+
* source gives it no title (`accTitle`).
|
|
27
|
+
*/
|
|
28
|
+
diagramPicture: (labels: string[]) => string;
|
|
22
29
|
/** Says a diagram could not be drawn, with the reason. */
|
|
23
30
|
diagramFailed: (reason: string) => string;
|
|
24
31
|
diagramNotLoaded: string;
|
|
@@ -2,6 +2,7 @@ export const defaultLabels = {
|
|
|
2
2
|
copyCode: 'Copy code',
|
|
3
3
|
downloadCode: 'Download code',
|
|
4
4
|
copied: 'Copied',
|
|
5
|
+
copyFailed: "Couldn't copy",
|
|
5
6
|
tableActions: 'Copy or save this table',
|
|
6
7
|
copyAsMarkdown: 'Copy as Markdown',
|
|
7
8
|
copyAsCsv: 'Copy as CSV',
|
|
@@ -14,6 +15,7 @@ export const defaultLabels = {
|
|
|
14
15
|
zoomIn: 'Zoom in',
|
|
15
16
|
zoomOut: 'Zoom out',
|
|
16
17
|
resetZoom: 'Reset zoom',
|
|
18
|
+
diagramPicture: (labels) => (labels.length ? `Diagram: ${labels.join(', ')}` : 'Diagram'),
|
|
17
19
|
diagramFailed: (reason) => `This diagram could not be drawn: ${reason}`,
|
|
18
20
|
diagramNotLoaded: 'What draws diagrams could not be loaded.',
|
|
19
21
|
diagramInvalid: 'It is not a diagram that can be drawn.',
|
|
@@ -9,19 +9,31 @@
|
|
|
9
9
|
sx?: Sx | undefined;
|
|
10
10
|
/** The region a right-click opens the menu over. */
|
|
11
11
|
children?: Snippet | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Opens the menu from Shift+F10 and the Menu key at the focused element. Pass `false`
|
|
14
|
+
* where the list's own keys already open it, or it would open twice.
|
|
15
|
+
*/
|
|
16
|
+
menuKey?: boolean | undefined;
|
|
12
17
|
}
|
|
13
18
|
>;
|
|
14
19
|
</script>
|
|
15
20
|
|
|
16
21
|
<script lang="ts">
|
|
17
|
-
let {
|
|
22
|
+
let {
|
|
23
|
+
sx,
|
|
24
|
+
class: className,
|
|
25
|
+
children,
|
|
26
|
+
onkeydown,
|
|
27
|
+
menuKey = true,
|
|
28
|
+
...rest
|
|
29
|
+
}: ContextMenuTriggerProps = $props();
|
|
18
30
|
|
|
19
31
|
// bits-ui opens a context menu only on the `contextmenu` event. Shift+F10 and
|
|
20
32
|
// the Menu key send one on Windows and Linux, but a Mac has neither, so the
|
|
21
33
|
// event is sent here, at the focused element, from the keyboard.
|
|
22
34
|
function openFromKeyboard(event: KeyboardEvent & { currentTarget: HTMLDivElement }) {
|
|
23
35
|
onkeydown?.(event);
|
|
24
|
-
if (event.defaultPrevented) return;
|
|
36
|
+
if (!menuKey || event.defaultPrevented) return;
|
|
25
37
|
if (!(event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey))) return;
|
|
26
38
|
event.preventDefault();
|
|
27
39
|
const target = (document.activeElement as HTMLElement | null) ?? event.currentTarget;
|
|
@@ -6,11 +6,21 @@ export type ContextMenuTriggerProps = Loose<Omit<ContextMenu.TriggerProps, 'chil
|
|
|
6
6
|
sx?: Sx | undefined;
|
|
7
7
|
/** The region a right-click opens the menu over. */
|
|
8
8
|
children?: Snippet | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Opens the menu from Shift+F10 and the Menu key at the focused element. Pass `false`
|
|
11
|
+
* where the list's own keys already open it, or it would open twice.
|
|
12
|
+
*/
|
|
13
|
+
menuKey?: boolean | undefined;
|
|
9
14
|
}>;
|
|
10
15
|
declare const ContextMenuTrigger: import("svelte").Component<Loose<Omit<ContextMenu.TriggerProps, "children"> & {
|
|
11
16
|
sx?: Sx | undefined;
|
|
12
17
|
/** The region a right-click opens the menu over. */
|
|
13
18
|
children?: Snippet | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Opens the menu from Shift+F10 and the Menu key at the focused element. Pass `false`
|
|
21
|
+
* where the list's own keys already open it, or it would open twice.
|
|
22
|
+
*/
|
|
23
|
+
menuKey?: boolean | undefined;
|
|
14
24
|
}>, {}, "">;
|
|
15
25
|
type ContextMenuTrigger = ReturnType<typeof ContextMenuTrigger>;
|
|
16
26
|
export default ContextMenuTrigger;
|
|
@@ -6,21 +6,45 @@
|
|
|
6
6
|
import Glyph from '../../internal/Glyph.svelte';
|
|
7
7
|
import { layer } from '../../internal/layer.js';
|
|
8
8
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
9
|
+
import { colors } from '../../tokens.stylex.js';
|
|
9
10
|
|
|
10
11
|
export type MenuCheckboxItemProps = Loose<
|
|
11
12
|
Omit<DropdownMenu.CheckboxItemProps, 'children' | 'child'> & {
|
|
13
|
+
/** The keys that do the same, shown at the end, such as "⌘D". */
|
|
12
14
|
shortcut?: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* A 16px icon before the label, where the other items' icons are. The tick then goes
|
|
17
|
+
* to the end of the row, so the icons line up down the menu.
|
|
18
|
+
*/
|
|
19
|
+
icon?: Snippet | undefined;
|
|
20
|
+
/** A line under the label, such as what the setting does. */
|
|
21
|
+
description?: string | undefined;
|
|
13
22
|
sx?: Sx | undefined;
|
|
14
23
|
children?: Snippet | undefined;
|
|
15
24
|
}
|
|
16
25
|
>;
|
|
26
|
+
|
|
27
|
+
const styles = stylex.create({
|
|
28
|
+
// At the end, the tick keeps its place whether shown or not, so the shortcuts line up
|
|
29
|
+
check: {
|
|
30
|
+
display: 'grid',
|
|
31
|
+
placeItems: 'center',
|
|
32
|
+
width: '1rem',
|
|
33
|
+
height: '1rem',
|
|
34
|
+
color: colors.text
|
|
35
|
+
}
|
|
36
|
+
});
|
|
17
37
|
</script>
|
|
18
38
|
|
|
19
39
|
<script lang="ts">
|
|
20
40
|
let {
|
|
21
41
|
checked = $bindable(false),
|
|
22
42
|
shortcut,
|
|
23
|
-
|
|
43
|
+
icon,
|
|
44
|
+
description,
|
|
45
|
+
// Picking it closes the menu, as a radio item's does: one left open takes the next click
|
|
46
|
+
// that was meant for the page. Pass `false` for a menu of settings set several at a time.
|
|
47
|
+
closeOnSelect = true,
|
|
24
48
|
sx,
|
|
25
49
|
class: className,
|
|
26
50
|
children: label,
|
|
@@ -28,7 +52,6 @@
|
|
|
28
52
|
}: MenuCheckboxItemProps = $props();
|
|
29
53
|
</script>
|
|
30
54
|
|
|
31
|
-
<!-- Stays open by default, so several can be set in one visit -->
|
|
32
55
|
<DropdownMenu.CheckboxItem
|
|
33
56
|
bind:checked
|
|
34
57
|
{closeOnSelect}
|
|
@@ -37,10 +60,30 @@
|
|
|
37
60
|
{...attrs([layer.item, sx], className)}
|
|
38
61
|
>
|
|
39
62
|
{#snippet children({ checked })}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
{#if icon}
|
|
64
|
+
<span data-icons {...stylex.attrs(layer.icon)}>{@render icon()}</span>
|
|
65
|
+
{:else}
|
|
66
|
+
<span {...stylex.attrs(layer.icon)}>
|
|
67
|
+
{#if checked}<Glyph name="check" stroke={1.75} />{/if}
|
|
68
|
+
</span>
|
|
69
|
+
{/if}
|
|
70
|
+
{#if description}
|
|
71
|
+
<span {...stylex.attrs(layer.text)}>
|
|
72
|
+
<span {...stylex.attrs(layer.label)}>{@render label?.()}</span>
|
|
73
|
+
<span {...stylex.attrs(layer.description)}>{description}</span>
|
|
74
|
+
</span>
|
|
75
|
+
{:else}
|
|
76
|
+
<span {...stylex.attrs(layer.label)}>{@render label?.()}</span>
|
|
77
|
+
{/if}
|
|
78
|
+
{#if shortcut || icon}
|
|
79
|
+
<span {...stylex.attrs(layer.trailing)}>
|
|
80
|
+
{shortcut}
|
|
81
|
+
{#if icon}
|
|
82
|
+
<span data-slot="menu-check" {...stylex.attrs(styles.check)}>
|
|
83
|
+
{#if checked}<Glyph name="check" stroke={1.75} />{/if}
|
|
84
|
+
</span>
|
|
85
|
+
{/if}
|
|
86
|
+
</span>
|
|
87
|
+
{/if}
|
|
45
88
|
{/snippet}
|
|
46
89
|
</DropdownMenu.CheckboxItem>
|
|
@@ -3,12 +3,28 @@ import { DropdownMenu } from 'bits-ui';
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import { type Sx } from '../../internal/sx.js';
|
|
5
5
|
export type MenuCheckboxItemProps = Loose<Omit<DropdownMenu.CheckboxItemProps, 'children' | 'child'> & {
|
|
6
|
+
/** The keys that do the same, shown at the end, such as "⌘D". */
|
|
6
7
|
shortcut?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* A 16px icon before the label, where the other items' icons are. The tick then goes
|
|
10
|
+
* to the end of the row, so the icons line up down the menu.
|
|
11
|
+
*/
|
|
12
|
+
icon?: Snippet | undefined;
|
|
13
|
+
/** A line under the label, such as what the setting does. */
|
|
14
|
+
description?: string | undefined;
|
|
7
15
|
sx?: Sx | undefined;
|
|
8
16
|
children?: Snippet | undefined;
|
|
9
17
|
}>;
|
|
10
18
|
declare const MenuCheckboxItem: import("svelte").Component<Loose<Omit<DropdownMenu.CheckboxItemProps, "children" | "child"> & {
|
|
19
|
+
/** The keys that do the same, shown at the end, such as "⌘D". */
|
|
11
20
|
shortcut?: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* A 16px icon before the label, where the other items' icons are. The tick then goes
|
|
23
|
+
* to the end of the row, so the icons line up down the menu.
|
|
24
|
+
*/
|
|
25
|
+
icon?: Snippet | undefined;
|
|
26
|
+
/** A line under the label, such as what the setting does. */
|
|
27
|
+
description?: string | undefined;
|
|
12
28
|
sx?: Sx | undefined;
|
|
13
29
|
children?: Snippet | undefined;
|
|
14
30
|
}>, {}, "checked">;
|
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
import type { Loose } from '../../internal/loose.js';
|
|
3
3
|
import { DropdownMenu } from 'bits-ui';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
|
-
import { layer } from '../../internal/layer.js';
|
|
5
|
+
import { layer, widthStyle } from '../../internal/layer.js';
|
|
6
6
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
7
7
|
|
|
8
8
|
export type MenuContentProps = Loose<
|
|
9
9
|
Omit<DropdownMenu.ContentProps, 'children' | 'child'> & {
|
|
10
|
+
/**
|
|
11
|
+
* A width of its own, such as `18rem`, in place of fitting its items (from 12rem, or
|
|
12
|
+
* the trigger's width, up to 22rem). It is still no wider than the window has room for.
|
|
13
|
+
*/
|
|
14
|
+
width?: string | undefined;
|
|
10
15
|
sx?: Sx | undefined;
|
|
11
16
|
children?: Snippet | undefined;
|
|
12
17
|
}
|
|
@@ -17,6 +22,8 @@
|
|
|
17
22
|
let {
|
|
18
23
|
sideOffset = 6,
|
|
19
24
|
collisionPadding = 8,
|
|
25
|
+
width,
|
|
26
|
+
style,
|
|
20
27
|
align = 'start',
|
|
21
28
|
sx,
|
|
22
29
|
class: className,
|
|
@@ -32,7 +39,8 @@
|
|
|
32
39
|
{align}
|
|
33
40
|
data-slot="menu-content"
|
|
34
41
|
{...rest}
|
|
35
|
-
{
|
|
42
|
+
style={widthStyle(width, style)}
|
|
43
|
+
{...attrs([layer.surface, !!width && layer.sized, sx], className)}
|
|
36
44
|
>
|
|
37
45
|
{@render children?.()}
|
|
38
46
|
</DropdownMenu.Content>
|
|
@@ -3,10 +3,20 @@ import { DropdownMenu } from 'bits-ui';
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import { type Sx } from '../../internal/sx.js';
|
|
5
5
|
export type MenuContentProps = Loose<Omit<DropdownMenu.ContentProps, 'children' | 'child'> & {
|
|
6
|
+
/**
|
|
7
|
+
* A width of its own, such as `18rem`, in place of fitting its items (from 12rem, or
|
|
8
|
+
* the trigger's width, up to 22rem). It is still no wider than the window has room for.
|
|
9
|
+
*/
|
|
10
|
+
width?: string | undefined;
|
|
6
11
|
sx?: Sx | undefined;
|
|
7
12
|
children?: Snippet | undefined;
|
|
8
13
|
}>;
|
|
9
14
|
declare const MenuContent: import("svelte").Component<Loose<Omit<DropdownMenu.ContentProps, "children" | "child"> & {
|
|
15
|
+
/**
|
|
16
|
+
* A width of its own, such as `18rem`, in place of fitting its items (from 12rem, or
|
|
17
|
+
* the trigger's width, up to 22rem). It is still no wider than the window has room for.
|
|
18
|
+
*/
|
|
19
|
+
width?: string | undefined;
|
|
10
20
|
sx?: Sx | undefined;
|
|
11
21
|
children?: Snippet | undefined;
|
|
12
22
|
}>, {}, "">;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Loose } from '../../internal/loose.js';
|
|
3
|
+
import { DropdownMenu } from 'bits-ui';
|
|
4
|
+
import { markMenuGroup } from './group.js';
|
|
5
|
+
|
|
6
|
+
export type MenuGroupProps = Loose<DropdownMenu.GroupProps>;
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
let { children, ...rest }: MenuGroupProps = $props();
|
|
11
|
+
|
|
12
|
+
// A Menu.Label in it names it
|
|
13
|
+
markMenuGroup();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<DropdownMenu.Group {...rest}>{@render children?.()}</DropdownMenu.Group>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Loose } from '../../internal/loose.js';
|
|
2
|
+
import { DropdownMenu } from 'bits-ui';
|
|
3
|
+
export type MenuGroupProps = Loose<DropdownMenu.GroupProps>;
|
|
4
|
+
declare const MenuGroup: import("svelte").Component<Loose<DropdownMenu.GroupProps>, {}, "">;
|
|
5
|
+
type MenuGroup = ReturnType<typeof MenuGroup>;
|
|
6
|
+
export default MenuGroup;
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
shortcut?: string | undefined;
|
|
15
15
|
/** A 16px icon before the label. */
|
|
16
16
|
icon?: Snippet | undefined;
|
|
17
|
+
/** A line under the label, such as what the action does. */
|
|
18
|
+
description?: string | undefined;
|
|
19
|
+
/** Something at the end, after the shortcut: a badge, a count, a status. */
|
|
20
|
+
trailing?: Snippet | undefined;
|
|
17
21
|
sx?: Sx | undefined;
|
|
18
22
|
children?: Snippet | undefined;
|
|
19
23
|
}
|
|
@@ -25,6 +29,8 @@
|
|
|
25
29
|
tone = 'default',
|
|
26
30
|
shortcut,
|
|
27
31
|
icon,
|
|
32
|
+
description,
|
|
33
|
+
trailing,
|
|
28
34
|
sx,
|
|
29
35
|
class: className,
|
|
30
36
|
children,
|
|
@@ -39,6 +45,15 @@
|
|
|
39
45
|
{...attrs([layer.item, tone === 'danger' && layer.danger, sx], className)}
|
|
40
46
|
>
|
|
41
47
|
{#if icon}<span data-icons {...stylex.attrs(layer.icon)}>{@render icon()}</span>{/if}
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
{#if description}
|
|
49
|
+
<span {...stylex.attrs(layer.text)}>
|
|
50
|
+
<span {...stylex.attrs(layer.label)}>{@render children?.()}</span>
|
|
51
|
+
<span {...stylex.attrs(layer.description)}>{description}</span>
|
|
52
|
+
</span>
|
|
53
|
+
{:else}
|
|
54
|
+
<span {...stylex.attrs(layer.label)}>{@render children?.()}</span>
|
|
55
|
+
{/if}
|
|
56
|
+
{#if shortcut || trailing}
|
|
57
|
+
<span {...stylex.attrs(layer.trailing)}>{shortcut}{@render trailing?.()}</span>
|
|
58
|
+
{/if}
|
|
44
59
|
</DropdownMenu.Item>
|