@placeholderco/placeholder-ui 3.2.7 → 3.2.9
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/editors/tiptap/extensions/CodeBlockEditor.d.ts +0 -1
- package/dist/editors/tiptap/extensions/CodeBlockEditor.js +0 -1
- package/dist/editors/tiptap/extensions/codeBlockEditor.css +3 -1
- package/dist/editors/tiptap/extensions/codeBlockLanguages.d.ts +1 -0
- package/dist/editors/tiptap/extensions/codeBlockLanguages.js +4 -0
- package/dist/ui/ContextMenu.svelte +35 -1
- package/dist/ui/ContextMenu.svelte.d.ts +1 -1
- package/dist/ui/ContextMenuList.svelte +98 -8
- package/dist/ui/ContextMenuList.svelte.d.ts +2 -0
- package/package.json +4 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type CodeBlockOptions } from '@tiptap/extension-code-block';
|
|
2
2
|
import { type CodeBlockLanguageId } from './codeBlockLanguages.js';
|
|
3
|
-
import './codeBlockEditor.css';
|
|
4
3
|
/** Configuration accepted by the `codeBlocks` prop on TipTap / TipTapBubble */
|
|
5
4
|
export interface CodeBlocksOptions {
|
|
6
5
|
/** Languages offered in the code block language picker (default: all registered) */
|
|
@@ -8,7 +8,6 @@ import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap }
|
|
|
8
8
|
import { bracketMatching, indentOnInput, syntaxHighlighting } from '@codemirror/language';
|
|
9
9
|
import { classHighlighter } from '@lezer/highlight';
|
|
10
10
|
import { codeBlockLanguages, resolveCodeBlockLanguage } from './codeBlockLanguages.js';
|
|
11
|
-
import './codeBlockEditor.css';
|
|
12
11
|
/**
|
|
13
12
|
* Renders each code block as an embedded CodeMirror editor, following the
|
|
14
13
|
* ProseMirror codemirror node view pattern: CodeMirror owns the block's text and
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/* Styles for the CodeBlockEditor TipTap extension
|
|
1
|
+
/* Styles for CodeMirror-powered code blocks (the CodeBlockEditor TipTap extension and
|
|
2
|
+
read-only renderers built on resolveCodeBlockLanguage). Loaded via codeBlockLanguages.ts,
|
|
3
|
+
or import '@placeholderco/placeholder-ui/code-block.css' directly.
|
|
2
4
|
Syntax colors target the stable tok-* classes emitted by @lezer/highlight's
|
|
3
5
|
classHighlighter: light palette follows CodeMirror's default highlight style,
|
|
4
6
|
dark palette follows One Dark. Dark mode uses the library's `.dark` root class. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Extension } from '@codemirror/state';
|
|
2
|
+
import './codeBlockEditor.css';
|
|
2
3
|
/** Language identifiers supported by the rich code block editor */
|
|
3
4
|
export type CodeBlockLanguageId = 'plaintext' | 'javascript' | 'typescript' | 'html' | 'css' | 'json' | 'markdown' | 'sql' | 'csharp' | 'powershell';
|
|
4
5
|
export interface CodeBlockLanguageDef {
|
|
@@ -8,6 +8,10 @@ import { LanguageSupport, StreamLanguage } from '@codemirror/language';
|
|
|
8
8
|
import { completeAnyWord, completeFromList } from '@codemirror/autocomplete';
|
|
9
9
|
import { csharp } from '@codemirror/legacy-modes/mode/clike';
|
|
10
10
|
import { powerShell } from '@codemirror/legacy-modes/mode/powershell';
|
|
11
|
+
// Code block styles are imported here rather than in CodeBlockEditor so that read-only
|
|
12
|
+
// renderers using only resolveCodeBlockLanguage still load them. Production builds split
|
|
13
|
+
// CSS per chunk, so an import that lives only in the editor would not reach those routes.
|
|
14
|
+
import './codeBlockEditor.css';
|
|
11
15
|
// C# and PowerShell have no native CodeMirror 6 packages, so they use legacy stream
|
|
12
16
|
// parsers. Those provide highlighting only, so keyword/cmdlet lists plus word matching
|
|
13
17
|
// stand in for the scope-aware completions the native language packages ship with.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
separator?: boolean;
|
|
15
15
|
/** Right-aligned shortcut hint (e.g. `⌘C`, `Del`). Purely visual. */
|
|
16
16
|
shortcut?: string;
|
|
17
|
-
/** Nested submenu items — opens on hover. */
|
|
17
|
+
/** Nested submenu items — opens on hover, click, Enter/Space or ArrowRight. */
|
|
18
18
|
children?: ContextMenuItem[];
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
</script>
|
|
38
38
|
|
|
39
39
|
<script lang="ts">
|
|
40
|
+
import { tick } from 'svelte';
|
|
40
41
|
import ContextMenuList from './ContextMenuList.svelte';
|
|
41
42
|
import { topLayer } from '../util/Floating.js';
|
|
42
43
|
|
|
@@ -87,6 +88,32 @@
|
|
|
87
88
|
placed = true;
|
|
88
89
|
});
|
|
89
90
|
|
|
91
|
+
// Move focus into the menu once it is visible (hidden elements can't take focus), and hand it
|
|
92
|
+
// back to whatever had it before when the menu closes — however it closes. Keyed on `placed`
|
|
93
|
+
// rather than x/y so repositioning an open menu doesn't yank focus back to the first item.
|
|
94
|
+
$effect(() => {
|
|
95
|
+
if (!open || !placed || !menuEl) return;
|
|
96
|
+
const node = menuEl;
|
|
97
|
+
const previous = document.activeElement;
|
|
98
|
+
let active = true;
|
|
99
|
+
void tick().then(() => {
|
|
100
|
+
if (!active) return;
|
|
101
|
+
node
|
|
102
|
+
.querySelector<HTMLButtonElement>('button:not(:disabled)')
|
|
103
|
+
?.focus({ preventScroll: true });
|
|
104
|
+
});
|
|
105
|
+
return () => {
|
|
106
|
+
active = false;
|
|
107
|
+
// Only restore if focus is still in (or was dropped by) the menu; an outside click
|
|
108
|
+
// that focused something else keeps that focus.
|
|
109
|
+
const current = document.activeElement;
|
|
110
|
+
const lost = !current || current === document.body || node.contains(current);
|
|
111
|
+
if (lost && previous instanceof HTMLElement && previous.isConnected) {
|
|
112
|
+
previous.focus({ preventScroll: true });
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
90
117
|
// Dismiss the menu on outside interaction while it's open.
|
|
91
118
|
$effect(() => {
|
|
92
119
|
if (!open) return;
|
|
@@ -94,9 +121,16 @@
|
|
|
94
121
|
if (menuEl && !menuEl.contains(e.target as Node)) close();
|
|
95
122
|
};
|
|
96
123
|
const onKey = (e: KeyboardEvent) => {
|
|
124
|
+
const target = e.target instanceof Element ? e.target : null;
|
|
125
|
+
const inMenu = !!(target && menuEl?.contains(target));
|
|
97
126
|
if (e.key === 'Escape') {
|
|
127
|
+
// Inside a submenu, Escape closes just that level (handled by ContextMenuList).
|
|
128
|
+
if (inMenu && target?.closest('.pui-ctxmenu-submenu')) return;
|
|
98
129
|
e.preventDefault();
|
|
99
130
|
close();
|
|
131
|
+
} else if (e.key === 'Tab' && inMenu) {
|
|
132
|
+
// Let Tab proceed: focus is restored to the trigger first, so Tab moves on from there.
|
|
133
|
+
close();
|
|
100
134
|
}
|
|
101
135
|
};
|
|
102
136
|
const onScroll = (e: Event) => {
|
|
@@ -13,7 +13,7 @@ export interface ContextMenuItem {
|
|
|
13
13
|
separator?: boolean;
|
|
14
14
|
/** Right-aligned shortcut hint (e.g. `⌘C`, `Del`). Purely visual. */
|
|
15
15
|
shortcut?: string;
|
|
16
|
-
/** Nested submenu items — opens on hover. */
|
|
16
|
+
/** Nested submenu items — opens on hover, click, Enter/Space or ArrowRight. */
|
|
17
17
|
children?: ContextMenuItem[];
|
|
18
18
|
}
|
|
19
19
|
export interface ContextMenuProps {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script lang="ts">
|
|
6
|
+
import { tick } from 'svelte';
|
|
6
7
|
import Icon from '../icon/Icon.svelte';
|
|
7
8
|
import { iconChevronRight } from '../icon/index.js';
|
|
8
9
|
import Self from './ContextMenuList.svelte';
|
|
@@ -14,24 +15,94 @@
|
|
|
14
15
|
/** Nesting level — only the top level applies `minWidth`. */
|
|
15
16
|
depth?: number;
|
|
16
17
|
minWidth?: string;
|
|
18
|
+
/** Set on submenus: closes this level and returns focus to its parent item. */
|
|
19
|
+
onBack?: () => void;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
let { items, onSelect, depth = 0, minWidth = '' }: Props = $props();
|
|
22
|
+
let { items, onSelect, depth = 0, minWidth = '', onBack }: Props = $props();
|
|
23
|
+
let listEl = $state<HTMLUListElement | null>(null);
|
|
20
24
|
|
|
21
|
-
// Only one submenu per list can be open at a time
|
|
25
|
+
// Only one submenu per list can be open at a time.
|
|
22
26
|
let hoverIndex = $state<number | null>(null);
|
|
23
27
|
let submenuEl = $state<HTMLElement | null>(null);
|
|
24
28
|
let flipLeft = $state(false);
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
const focusOpts = { preventScroll: true };
|
|
31
|
+
|
|
32
|
+
function onItemEnter(i: number, item: ContextMenuItem, li: HTMLElement) {
|
|
27
33
|
hoverIndex = item.children?.length ? i : null;
|
|
34
|
+
// Keep focus with the pointer so a submenu closing under it never drops focus to <body>.
|
|
35
|
+
// Disabled rows can't take focus, so park it on the list itself.
|
|
36
|
+
const button = li.querySelector<HTMLButtonElement>(':scope > button');
|
|
37
|
+
(button && !button.disabled ? button : listEl)?.focus(focusOpts);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function openSubmenu(i: number) {
|
|
41
|
+
hoverIndex = i;
|
|
42
|
+
await tick();
|
|
43
|
+
submenuEl?.querySelector<HTMLButtonElement>('button:not(:disabled)')?.focus(focusOpts);
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
function
|
|
31
|
-
|
|
46
|
+
function closeSubmenu(i: number) {
|
|
47
|
+
hoverIndex = null;
|
|
48
|
+
listEl?.children.item(i)?.querySelector<HTMLButtonElement>(':scope > button')?.focus(focusOpts);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function handleClick(item: ContextMenuItem, i: number) {
|
|
52
|
+
if (item.disabled || item.separator) return;
|
|
53
|
+
if (item.children?.length) {
|
|
54
|
+
void openSubmenu(i);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
32
57
|
onSelect(item);
|
|
33
58
|
}
|
|
34
59
|
|
|
60
|
+
function onKey(event: KeyboardEvent) {
|
|
61
|
+
const target = event.target;
|
|
62
|
+
// Only handle keys aimed at this level (the list itself or one of its own items);
|
|
63
|
+
// nested lists handle their own.
|
|
64
|
+
if (
|
|
65
|
+
!listEl ||
|
|
66
|
+
!(target instanceof HTMLElement) ||
|
|
67
|
+
(target !== listEl && target.closest('[role="menu"]') !== listEl)
|
|
68
|
+
)
|
|
69
|
+
return;
|
|
70
|
+
|
|
71
|
+
const handled = () => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (event.key === 'ArrowRight') {
|
|
77
|
+
const index = Array.from(listEl.children).indexOf(target.parentElement as Element);
|
|
78
|
+
if (!items[index]?.children?.length) return;
|
|
79
|
+
handled();
|
|
80
|
+
void openSubmenu(index);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if ((event.key === 'ArrowLeft' || event.key === 'Escape') && onBack) {
|
|
84
|
+
handled();
|
|
85
|
+
onBack();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const buttons = Array.from(
|
|
90
|
+
listEl.querySelectorAll<HTMLButtonElement>(':scope > li > button:not(:disabled)')
|
|
91
|
+
);
|
|
92
|
+
if (!buttons.length) return;
|
|
93
|
+
const last = buttons.length - 1;
|
|
94
|
+
const current = buttons.indexOf(target as HTMLButtonElement);
|
|
95
|
+
let next: number;
|
|
96
|
+
if (event.key === 'ArrowDown') next = current < 0 || current === last ? 0 : current + 1;
|
|
97
|
+
else if (event.key === 'ArrowUp') next = current <= 0 ? last : current - 1;
|
|
98
|
+
else if (event.key === 'Home') next = 0;
|
|
99
|
+
else if (event.key === 'End') next = last;
|
|
100
|
+
else return;
|
|
101
|
+
handled();
|
|
102
|
+
hoverIndex = null;
|
|
103
|
+
buttons[next].focus(focusOpts);
|
|
104
|
+
}
|
|
105
|
+
|
|
35
106
|
// Decide whether the open submenu should flip to the left edge of its parent.
|
|
36
107
|
// Measured from the parent <li> right edge so the result is stable once flipped.
|
|
37
108
|
$effect(() => {
|
|
@@ -47,6 +118,9 @@
|
|
|
47
118
|
<ul
|
|
48
119
|
class="pui-ctxmenu-list"
|
|
49
120
|
role="menu"
|
|
121
|
+
tabindex="-1"
|
|
122
|
+
bind:this={listEl}
|
|
123
|
+
onkeydown={onKey}
|
|
50
124
|
style={depth === 0 && minWidth ? `min-width: ${minWidth};` : ''}
|
|
51
125
|
>
|
|
52
126
|
{#each items as item, i (i)}
|
|
@@ -54,14 +128,21 @@
|
|
|
54
128
|
<li class="pui-ctxmenu-sep" role="separator"></li>
|
|
55
129
|
{:else}
|
|
56
130
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
57
|
-
<li
|
|
131
|
+
<li
|
|
132
|
+
class="pui-ctxmenu-li"
|
|
133
|
+
role="none"
|
|
134
|
+
onmouseenter={(e) => onItemEnter(i, item, e.currentTarget)}
|
|
135
|
+
>
|
|
58
136
|
<button
|
|
59
137
|
type="button"
|
|
60
138
|
role="menuitem"
|
|
61
139
|
class="pui-ctxmenu-item"
|
|
62
140
|
class:danger={item.danger}
|
|
141
|
+
tabindex="-1"
|
|
142
|
+
aria-haspopup={item.children?.length ? 'menu' : undefined}
|
|
143
|
+
aria-expanded={item.children?.length ? hoverIndex === i : undefined}
|
|
63
144
|
disabled={item.disabled}
|
|
64
|
-
onclick={() => handleClick(item)}
|
|
145
|
+
onclick={() => handleClick(item, i)}
|
|
65
146
|
>
|
|
66
147
|
<span class="pui-ctxmenu-ico">
|
|
67
148
|
{#if item.icon}<Icon svg={item.icon} size="1rem" />{/if}
|
|
@@ -77,7 +158,12 @@
|
|
|
77
158
|
|
|
78
159
|
{#if item.children?.length && hoverIndex === i}
|
|
79
160
|
<div class="pui-ctxmenu-submenu" class:flip-left={flipLeft} bind:this={submenuEl}>
|
|
80
|
-
<Self
|
|
161
|
+
<Self
|
|
162
|
+
items={item.children}
|
|
163
|
+
{onSelect}
|
|
164
|
+
depth={depth + 1}
|
|
165
|
+
onBack={() => closeSubmenu(i)}
|
|
166
|
+
/>
|
|
81
167
|
</div>
|
|
82
168
|
{/if}
|
|
83
169
|
</li>
|
|
@@ -99,6 +185,10 @@
|
|
|
99
185
|
user-select: none;
|
|
100
186
|
}
|
|
101
187
|
|
|
188
|
+
.pui-ctxmenu-list:focus {
|
|
189
|
+
outline: none;
|
|
190
|
+
}
|
|
191
|
+
|
|
102
192
|
.pui-ctxmenu-li {
|
|
103
193
|
position: relative;
|
|
104
194
|
}
|
|
@@ -6,6 +6,8 @@ interface Props {
|
|
|
6
6
|
/** Nesting level — only the top level applies `minWidth`. */
|
|
7
7
|
depth?: number;
|
|
8
8
|
minWidth?: string;
|
|
9
|
+
/** Set on submenus: closes this level and returns focus to its parent item. */
|
|
10
|
+
onBack?: () => void;
|
|
9
11
|
}
|
|
10
12
|
declare const ContextMenuList: import("svelte").Component<Props, {}, "">;
|
|
11
13
|
type ContextMenuList = ReturnType<typeof ContextMenuList>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placeholderco/placeholder-ui",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.9",
|
|
4
4
|
"description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Placeholderco",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"default": "./dist/codemirror/highlight.js"
|
|
62
62
|
},
|
|
63
63
|
"./app.css": "./dist/app.css",
|
|
64
|
-
"./styles.css": "./dist/styles.css"
|
|
64
|
+
"./styles.css": "./dist/styles.css",
|
|
65
|
+
"./code-block.css": "./dist/editors/tiptap/extensions/codeBlockEditor.css"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
68
|
"@sveltejs/kit": "^2.26.0 || ^3.0.0",
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"prettier": "^3.9.10",
|
|
78
79
|
"prettier-plugin-svelte": "^4.1.1",
|
|
79
80
|
"publint": "^0.3.25",
|
|
80
|
-
"rimraf": "^6.1.
|
|
81
|
+
"rimraf": "^6.1.4",
|
|
81
82
|
"svelte": "^5.57.3",
|
|
82
83
|
"svelte-check": "^4.7.8",
|
|
83
84
|
"typescript": "^6.0.3",
|