@perkyzz/emvb 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import { MagnifyingGlassIcon, UploadSimpleIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Fetcher } from "../../api.ts";
|
|
5
|
+
import { listUploadedIcons, uploadIconFile } from "../../icon-uploads-api.ts";
|
|
6
|
+
import { BUTTON, SOLID_PRIMARY, UI_CSS } from "../../ui.ts";
|
|
7
|
+
import {
|
|
8
|
+
ALL_ICONS,
|
|
9
|
+
filterIcons,
|
|
10
|
+
ICON_CATEGORIES,
|
|
11
|
+
ICON_SETS,
|
|
12
|
+
loadIconSet,
|
|
13
|
+
locateIcon,
|
|
14
|
+
setsFor,
|
|
15
|
+
uploadedIcons,
|
|
16
|
+
UPLOADS,
|
|
17
|
+
UPLOADS_CATEGORY,
|
|
18
|
+
type IconCategory,
|
|
19
|
+
type IconSetId,
|
|
20
|
+
type LibraryIcon,
|
|
21
|
+
} from "./library.ts";
|
|
22
|
+
|
|
23
|
+
/** Grid geometry, in px. Tiles stretch to fill the row; this is their narrowest. */
|
|
24
|
+
const TILE_MIN_WIDTH = 96;
|
|
25
|
+
export const TILE_HEIGHT = 88;
|
|
26
|
+
export const GAP = 8;
|
|
27
|
+
const ROW = TILE_HEIGHT + GAP;
|
|
28
|
+
const PAD = 12;
|
|
29
|
+
const OVERSCAN = 2;
|
|
30
|
+
/** happy-dom and a first paint before layout report 0; assume a typical dialog until measured. */
|
|
31
|
+
const FALLBACK = { width: 760, height: 480 };
|
|
32
|
+
|
|
33
|
+
/** How many tiles fit across `width`. */
|
|
34
|
+
export const columnsFor = (width: number) =>
|
|
35
|
+
Math.max(1, Math.floor((width + GAP) / (TILE_MIN_WIDTH + GAP)));
|
|
36
|
+
|
|
37
|
+
/** The rows to render for a scroll position: what is on screen plus a little either side. */
|
|
38
|
+
export function visibleRows(
|
|
39
|
+
scrollTop: number,
|
|
40
|
+
height: number,
|
|
41
|
+
rowCount: number,
|
|
42
|
+
): { first: number; last: number } {
|
|
43
|
+
// A stale offset from a longer list must not point past the end of this one.
|
|
44
|
+
const top = Math.min(Math.max(0, scrollTop - PAD), Math.max(0, rowCount * ROW - height));
|
|
45
|
+
return {
|
|
46
|
+
first: Math.max(0, Math.floor(top / ROW) - OVERSCAN),
|
|
47
|
+
last: Math.min(rowCount - 1, Math.ceil((top + height) / ROW) + OVERSCAN),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Where a key moves the active tile in a grid of `count` tiles, or undefined if it isn't a move. */
|
|
52
|
+
export function moveActive(
|
|
53
|
+
key: string,
|
|
54
|
+
index: number,
|
|
55
|
+
count: number,
|
|
56
|
+
columns: number,
|
|
57
|
+
pageRows: number,
|
|
58
|
+
): number | undefined {
|
|
59
|
+
if (count === 0) return undefined;
|
|
60
|
+
const last = count - 1;
|
|
61
|
+
if (index < 0) {
|
|
62
|
+
return [
|
|
63
|
+
"ArrowRight",
|
|
64
|
+
"ArrowLeft",
|
|
65
|
+
"ArrowDown",
|
|
66
|
+
"ArrowUp",
|
|
67
|
+
"Home",
|
|
68
|
+
"PageDown",
|
|
69
|
+
"PageUp",
|
|
70
|
+
].includes(key)
|
|
71
|
+
? 0
|
|
72
|
+
: key === "End"
|
|
73
|
+
? last
|
|
74
|
+
: undefined;
|
|
75
|
+
}
|
|
76
|
+
const row = Math.floor(index / columns);
|
|
77
|
+
const lastRow = Math.floor(last / columns);
|
|
78
|
+
switch (key) {
|
|
79
|
+
case "ArrowRight":
|
|
80
|
+
return Math.min(last, index + 1);
|
|
81
|
+
case "ArrowLeft":
|
|
82
|
+
return Math.max(0, index - 1);
|
|
83
|
+
case "ArrowDown":
|
|
84
|
+
// From the row above a short last row, land on its last tile rather than staying put.
|
|
85
|
+
return index + columns <= last ? index + columns : row < lastRow ? last : index;
|
|
86
|
+
case "ArrowUp":
|
|
87
|
+
return index - columns >= 0 ? index - columns : index;
|
|
88
|
+
case "Home":
|
|
89
|
+
return 0;
|
|
90
|
+
case "End":
|
|
91
|
+
return last;
|
|
92
|
+
case "PageDown":
|
|
93
|
+
return Math.min(last, index + columns * pageRows);
|
|
94
|
+
case "PageUp":
|
|
95
|
+
return index - columns * pageRows >= 0 ? index - columns * pageRows : index % columns;
|
|
96
|
+
default:
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const optionId = (base: string, index: number) => `${base}-${index}`;
|
|
102
|
+
|
|
103
|
+
/** "Font Awesome Solid", or just "Lucide" for a set with one style. */
|
|
104
|
+
const iconSource = (icon: LibraryIcon) =>
|
|
105
|
+
icon.styleLabel === icon.setLabel ? icon.setLabel : `${icon.setLabel} ${icon.styleLabel}`;
|
|
106
|
+
|
|
107
|
+
/** What a screen reader hears for a tile: "Rocket, Font Awesome Solid". */
|
|
108
|
+
const iconSpokenName = (icon: LibraryIcon) => `${icon.label}, ${iconSource(icon)}`;
|
|
109
|
+
|
|
110
|
+
function IconGrid({
|
|
111
|
+
icons,
|
|
112
|
+
selectedId,
|
|
113
|
+
active,
|
|
114
|
+
label,
|
|
115
|
+
gridRef,
|
|
116
|
+
onActive,
|
|
117
|
+
onCursor,
|
|
118
|
+
onInsert,
|
|
119
|
+
}: {
|
|
120
|
+
icons: readonly LibraryIcon[];
|
|
121
|
+
selectedId: string | undefined;
|
|
122
|
+
active: number;
|
|
123
|
+
label: string;
|
|
124
|
+
gridRef: React.RefObject<HTMLDivElement | null>;
|
|
125
|
+
/** Moves the keyboard cursor and selects that icon. */
|
|
126
|
+
onActive: (index: number) => void;
|
|
127
|
+
/** Moves only the keyboard cursor (tabbing in), leaving the selection alone. */
|
|
128
|
+
onCursor: (index: number) => void;
|
|
129
|
+
onInsert: (icon: LibraryIcon) => void;
|
|
130
|
+
}) {
|
|
131
|
+
const base = React.useId();
|
|
132
|
+
const [box, setBox] = React.useState(FALLBACK);
|
|
133
|
+
const [scrollTop, setScrollTop] = React.useState(0);
|
|
134
|
+
|
|
135
|
+
React.useLayoutEffect(() => {
|
|
136
|
+
const el = gridRef.current;
|
|
137
|
+
if (!el) return undefined;
|
|
138
|
+
const measure = () =>
|
|
139
|
+
setBox({
|
|
140
|
+
width: el.clientWidth > 0 ? el.clientWidth - PAD * 2 : FALLBACK.width,
|
|
141
|
+
height: el.clientHeight > 0 ? el.clientHeight : FALLBACK.height,
|
|
142
|
+
});
|
|
143
|
+
measure();
|
|
144
|
+
if (typeof ResizeObserver === "undefined") return undefined;
|
|
145
|
+
const observer = new ResizeObserver(measure);
|
|
146
|
+
observer.observe(el);
|
|
147
|
+
return () => observer.disconnect();
|
|
148
|
+
}, [gridRef]);
|
|
149
|
+
|
|
150
|
+
const columns = columnsFor(box.width);
|
|
151
|
+
const tileWidth = (box.width - GAP * (columns - 1)) / columns;
|
|
152
|
+
const rows = Math.ceil(icons.length / columns);
|
|
153
|
+
const pageRows = Math.max(1, Math.floor(box.height / ROW));
|
|
154
|
+
const { first, last } = visibleRows(scrollTop, box.height, rows);
|
|
155
|
+
|
|
156
|
+
// A new list starts at the top; then the active tile is kept in view as the keyboard moves it
|
|
157
|
+
// (and on opening, the current icon is scrolled to).
|
|
158
|
+
const shownList = React.useRef(icons);
|
|
159
|
+
React.useEffect(() => {
|
|
160
|
+
const el = gridRef.current;
|
|
161
|
+
if (!el) return;
|
|
162
|
+
if (shownList.current !== icons) {
|
|
163
|
+
shownList.current = icons;
|
|
164
|
+
el.scrollTop = 0;
|
|
165
|
+
}
|
|
166
|
+
if (active >= 0) {
|
|
167
|
+
const top = PAD + Math.floor(active / columns) * ROW;
|
|
168
|
+
if (top < el.scrollTop) el.scrollTop = top - PAD;
|
|
169
|
+
else if (top + TILE_HEIGHT > el.scrollTop + box.height)
|
|
170
|
+
el.scrollTop = top + TILE_HEIGHT + PAD - box.height;
|
|
171
|
+
}
|
|
172
|
+
setScrollTop(el.scrollTop);
|
|
173
|
+
}, [icons, active, columns, box.height, gridRef]);
|
|
174
|
+
|
|
175
|
+
const tiles: React.ReactNode[] = [];
|
|
176
|
+
for (let row = first; row <= last; row += 1) {
|
|
177
|
+
for (let col = 0; col < columns; col += 1) {
|
|
178
|
+
const index = row * columns + col;
|
|
179
|
+
const icon = icons[index];
|
|
180
|
+
if (!icon) break;
|
|
181
|
+
const selected = icon.id === selectedId;
|
|
182
|
+
tiles.push(
|
|
183
|
+
<div
|
|
184
|
+
key={icon.id}
|
|
185
|
+
id={optionId(base, index)}
|
|
186
|
+
role="option"
|
|
187
|
+
aria-selected={selected}
|
|
188
|
+
aria-setsize={icons.length}
|
|
189
|
+
aria-posinset={index + 1}
|
|
190
|
+
aria-label={iconSpokenName(icon)}
|
|
191
|
+
title={`${icon.label} (${icon.id})`}
|
|
192
|
+
className="emvb-icon-library-tile"
|
|
193
|
+
data-emvb-icon-id={icon.id}
|
|
194
|
+
data-selected={selected ? "true" : undefined}
|
|
195
|
+
data-active={index === active ? "true" : undefined}
|
|
196
|
+
style={{ top: row * ROW, left: col * (tileWidth + GAP), width: tileWidth }}
|
|
197
|
+
onClick={() => {
|
|
198
|
+
gridRef.current?.focus({ preventScroll: true });
|
|
199
|
+
onActive(index);
|
|
200
|
+
}}
|
|
201
|
+
onDoubleClick={() => onInsert(icon)}
|
|
202
|
+
>
|
|
203
|
+
<span
|
|
204
|
+
className="emvb-icon-library-glyph"
|
|
205
|
+
aria-hidden="true"
|
|
206
|
+
// Generated from the official packages and checked against the SVG allowlist (W-235).
|
|
207
|
+
dangerouslySetInnerHTML={{ __html: icon.markup }}
|
|
208
|
+
/>
|
|
209
|
+
<span className="emvb-icon-library-name">{icon.label}</span>
|
|
210
|
+
</div>,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<div
|
|
217
|
+
ref={gridRef}
|
|
218
|
+
role="listbox"
|
|
219
|
+
tabIndex={0}
|
|
220
|
+
aria-label={label}
|
|
221
|
+
aria-activedescendant={
|
|
222
|
+
active >= 0 && active < icons.length ? optionId(base, active) : undefined
|
|
223
|
+
}
|
|
224
|
+
className="emvb-icon-library-grid"
|
|
225
|
+
data-emvb-icon-grid=""
|
|
226
|
+
data-columns={columns}
|
|
227
|
+
onScroll={(event) => setScrollTop(event.currentTarget.scrollTop)}
|
|
228
|
+
onFocus={(event) => {
|
|
229
|
+
if (event.target === event.currentTarget && active < 0 && icons.length > 0) onCursor(0);
|
|
230
|
+
}}
|
|
231
|
+
onKeyDown={(event) => {
|
|
232
|
+
if (event.key === "Enter") {
|
|
233
|
+
const icon = icons[active];
|
|
234
|
+
if (icon) {
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
onInsert(icon);
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const next = moveActive(event.key, active, icons.length, columns, pageRows);
|
|
241
|
+
if (next === undefined) return;
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
onActive(next);
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
<div
|
|
247
|
+
role="presentation"
|
|
248
|
+
className="emvb-icon-library-rows"
|
|
249
|
+
style={{ height: Math.max(0, rows * ROW - GAP) }}
|
|
250
|
+
>
|
|
251
|
+
{tiles}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function initialCategory(currentId: string | undefined, uploads: boolean): string {
|
|
258
|
+
const at = currentId ? locateIcon(currentId) : undefined;
|
|
259
|
+
if (!at) return ALL_ICONS;
|
|
260
|
+
if (at.set === UPLOADS) return uploads ? UPLOADS : ALL_ICONS;
|
|
261
|
+
const style = ICON_CATEGORIES.find((category) => category.id === `${at.set}/${at.style}`);
|
|
262
|
+
return style?.id ?? at.set;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const fmt = (count: number) => count.toLocaleString("en-US");
|
|
266
|
+
|
|
267
|
+
function IconLibrary({
|
|
268
|
+
currentId,
|
|
269
|
+
fetcher,
|
|
270
|
+
onInsert,
|
|
271
|
+
}: {
|
|
272
|
+
currentId: string | undefined;
|
|
273
|
+
/** With a fetcher, My uploads lists and adds uploaded SVGs (W-239). */
|
|
274
|
+
fetcher?: Fetcher;
|
|
275
|
+
onInsert: (icon: LibraryIcon) => void;
|
|
276
|
+
}) {
|
|
277
|
+
const [categoryId, setCategoryId] = React.useState(() =>
|
|
278
|
+
initialCategory(currentId, fetcher !== undefined),
|
|
279
|
+
);
|
|
280
|
+
const categories = React.useMemo(
|
|
281
|
+
() => (fetcher ? [...ICON_CATEGORIES, UPLOADS_CATEGORY] : ICON_CATEGORIES),
|
|
282
|
+
[fetcher],
|
|
283
|
+
);
|
|
284
|
+
const [uploads, setUploads] = React.useState<LibraryIcon[]>();
|
|
285
|
+
const [uploadsFailed, setUploadsFailed] = React.useState<string>();
|
|
286
|
+
const [uploading, setUploading] = React.useState(false);
|
|
287
|
+
const [uploadNote, setUploadNote] = React.useState<{ error: boolean; text: string }>();
|
|
288
|
+
const fileRef = React.useRef<HTMLInputElement | null>(null);
|
|
289
|
+
const [query, setQuery] = React.useState("");
|
|
290
|
+
const [selectedId, setSelectedId] = React.useState(
|
|
291
|
+
() => (currentId ? locateIcon(currentId)?.id : undefined) ?? currentId,
|
|
292
|
+
);
|
|
293
|
+
const [sets, setSets] = React.useState<Partial<Record<IconSetId, LibraryIcon[]>>>({});
|
|
294
|
+
const [failed, setFailed] = React.useState<string>();
|
|
295
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
296
|
+
const gridRef = React.useRef<HTMLDivElement | null>(null);
|
|
297
|
+
const searchId = React.useId();
|
|
298
|
+
|
|
299
|
+
const category: IconCategory =
|
|
300
|
+
categories.find((item) => item.id === categoryId) ?? (ICON_CATEGORIES[0] as IconCategory);
|
|
301
|
+
const inUploads = category.id === UPLOADS;
|
|
302
|
+
const needed = inUploads ? [] : setsFor(category);
|
|
303
|
+
const neededKey = needed.join(",");
|
|
304
|
+
|
|
305
|
+
// My uploads loads when first needed: its category, All icons (which lists them first, W-295),
|
|
306
|
+
// or a stored upload to show as picked.
|
|
307
|
+
const inAll = category.id === ALL_ICONS;
|
|
308
|
+
const wantUploads =
|
|
309
|
+
fetcher !== undefined && (inUploads || inAll || locateIcon(currentId ?? "")?.set === UPLOADS);
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
if (!wantUploads || !fetcher || uploads) return undefined;
|
|
312
|
+
let live = true;
|
|
313
|
+
setUploadsFailed(undefined);
|
|
314
|
+
listUploadedIcons(fetcher).then(
|
|
315
|
+
(items) => {
|
|
316
|
+
if (live) setUploads(uploadedIcons(items));
|
|
317
|
+
},
|
|
318
|
+
(caught: unknown) => {
|
|
319
|
+
if (live)
|
|
320
|
+
setUploadsFailed(caught instanceof Error ? caught.message : "Couldn't load uploads.");
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
return () => {
|
|
324
|
+
live = false;
|
|
325
|
+
};
|
|
326
|
+
}, [wantUploads, fetcher, uploads, attempt]);
|
|
327
|
+
|
|
328
|
+
React.useEffect(() => {
|
|
329
|
+
let live = true;
|
|
330
|
+
setFailed(undefined);
|
|
331
|
+
for (const id of (neededKey ? neededKey.split(",") : []) as IconSetId[]) {
|
|
332
|
+
loadIconSet(id).then(
|
|
333
|
+
(icons) => {
|
|
334
|
+
if (live) setSets((prev) => (prev[id] ? prev : { ...prev, [id]: icons }));
|
|
335
|
+
},
|
|
336
|
+
() => {
|
|
337
|
+
if (live) setFailed(ICON_SETS.find((set) => set.id === id)?.label ?? id);
|
|
338
|
+
},
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
return () => {
|
|
342
|
+
live = false;
|
|
343
|
+
};
|
|
344
|
+
}, [neededKey, attempt]);
|
|
345
|
+
|
|
346
|
+
// All icons waits for the uploads list too, unless it failed (the sets still show, W-295).
|
|
347
|
+
const uploadsSettled = !fetcher || uploads !== undefined || uploadsFailed !== undefined;
|
|
348
|
+
const ready = inUploads
|
|
349
|
+
? uploads !== undefined
|
|
350
|
+
: needed.every((id) => sets[id]) && (!inAll || uploadsSettled);
|
|
351
|
+
const filtered = React.useMemo(
|
|
352
|
+
() =>
|
|
353
|
+
ready
|
|
354
|
+
? filterIcons(
|
|
355
|
+
inUploads
|
|
356
|
+
? (uploads ?? [])
|
|
357
|
+
: [...(inAll ? (uploads ?? []) : []), ...needed.flatMap((id) => sets[id] ?? [])],
|
|
358
|
+
category,
|
|
359
|
+
query,
|
|
360
|
+
)
|
|
361
|
+
: [],
|
|
362
|
+
// `needed` follows `category`; `ready` follows `sets` and `uploads`.
|
|
363
|
+
[ready, sets, uploads, category, query, inAll],
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
// Matches per sidebar entry, for the sets loaded so far (a search shows where its hits are).
|
|
367
|
+
const counts = React.useMemo(() => {
|
|
368
|
+
const loaded = Object.values(sets).flat();
|
|
369
|
+
const tally = new Map<string, number>();
|
|
370
|
+
for (const icon of filterIcons(loaded, ICON_CATEGORIES[0] as IconCategory, query)) {
|
|
371
|
+
tally.set(icon.set, (tally.get(icon.set) ?? 0) + 1);
|
|
372
|
+
tally.set(`${icon.set}/${icon.style}`, (tally.get(`${icon.set}/${icon.style}`) ?? 0) + 1);
|
|
373
|
+
}
|
|
374
|
+
if (uploads) tally.set(UPLOADS, filterIcons(uploads, UPLOADS_CATEGORY, query).length);
|
|
375
|
+
const allLoaded = ICON_SETS.every((set) => sets[set.id]);
|
|
376
|
+
if (allLoaded)
|
|
377
|
+
tally.set(
|
|
378
|
+
ALL_ICONS,
|
|
379
|
+
[...ICON_SETS].reduce((n, s) => n + (tally.get(s.id) ?? 0), 0) + (tally.get(UPLOADS) ?? 0),
|
|
380
|
+
);
|
|
381
|
+
return tally;
|
|
382
|
+
}, [sets, uploads, query]);
|
|
383
|
+
|
|
384
|
+
// The keyboard cursor belongs to one list. A new list (search, category) starts from the picked
|
|
385
|
+
// icon if it is in it, else nowhere, in the same render: an index left over from the last list
|
|
386
|
+
// would scroll this one to a tile it doesn't have.
|
|
387
|
+
const [cursor, setCursor] = React.useState<{ list: readonly LibraryIcon[]; index: number }>({
|
|
388
|
+
list: [],
|
|
389
|
+
index: -1,
|
|
390
|
+
});
|
|
391
|
+
const active =
|
|
392
|
+
cursor.list === filtered ? cursor.index : filtered.findIndex((icon) => icon.id === selectedId);
|
|
393
|
+
const setActive = (index: number) => setCursor({ list: filtered, index });
|
|
394
|
+
|
|
395
|
+
const selected = React.useMemo(() => {
|
|
396
|
+
if (!selectedId) return undefined;
|
|
397
|
+
for (const icons of [...Object.values(sets), uploads]) {
|
|
398
|
+
const found = icons?.find((icon) => icon.id === selectedId);
|
|
399
|
+
if (found) return found;
|
|
400
|
+
}
|
|
401
|
+
return undefined;
|
|
402
|
+
}, [sets, uploads, selectedId]);
|
|
403
|
+
|
|
404
|
+
const onUpload = async (file: File | undefined) => {
|
|
405
|
+
if (!file || !fetcher) return;
|
|
406
|
+
setUploading(true);
|
|
407
|
+
setUploadNote(undefined);
|
|
408
|
+
try {
|
|
409
|
+
const result = await uploadIconFile(fetcher, file, (svg) => {
|
|
410
|
+
const [probe] = uploadedIcons([{ id: "new", name: "", svg, uploadedAt: "" }]);
|
|
411
|
+
return uploads?.find((other) => other.markup === probe?.markup)?.id;
|
|
412
|
+
});
|
|
413
|
+
setQuery("");
|
|
414
|
+
setCursor({ list: [], index: -1 });
|
|
415
|
+
if ("existingId" in result) {
|
|
416
|
+
const known = uploads?.find((other) => other.id === result.existingId);
|
|
417
|
+
setSelectedId(result.existingId);
|
|
418
|
+
setUploadNote({
|
|
419
|
+
error: false,
|
|
420
|
+
text: `You already uploaded this SVG as ${known?.label ?? "an icon"}, so it's selected. Insert adds it to the page.`,
|
|
421
|
+
});
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const { item, imagesLeftOut } = result;
|
|
425
|
+
const [icon] = uploadedIcons([item]);
|
|
426
|
+
if (!icon) throw new Error("The uploaded SVG couldn't be shown. Try another file.");
|
|
427
|
+
setUploads((prev) => [icon, ...(prev ?? []).filter((other) => other.id !== icon.id)]);
|
|
428
|
+
setSelectedId(icon.id);
|
|
429
|
+
setUploadNote({
|
|
430
|
+
error: false,
|
|
431
|
+
text: `Uploaded ${icon.label}. Insert adds it to the page.${
|
|
432
|
+
imagesLeftOut > 0
|
|
433
|
+
? ` ${imagesLeftOut} outside image${imagesLeftOut === 1 ? " was" : "s were"} left out.`
|
|
434
|
+
: ""
|
|
435
|
+
}`,
|
|
436
|
+
});
|
|
437
|
+
} catch (caught) {
|
|
438
|
+
setUploadNote({
|
|
439
|
+
error: true,
|
|
440
|
+
text: caught instanceof Error ? caught.message : "The upload failed. Try again.",
|
|
441
|
+
});
|
|
442
|
+
} finally {
|
|
443
|
+
setUploading(false);
|
|
444
|
+
if (fileRef.current) fileRef.current.value = "";
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const activate = (index: number) => {
|
|
449
|
+
setActive(index);
|
|
450
|
+
const icon = filtered[index];
|
|
451
|
+
if (icon) setSelectedId(icon.id);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const status = failed
|
|
455
|
+
? `${failed} didn't load.`
|
|
456
|
+
: inUploads && uploadsFailed
|
|
457
|
+
? "Uploads didn't load."
|
|
458
|
+
: !ready
|
|
459
|
+
? "Loading icons…"
|
|
460
|
+
: filtered.length === 0
|
|
461
|
+
? query.trim()
|
|
462
|
+
? `No icons match "${query.trim()}" in ${category.label}.`
|
|
463
|
+
: inUploads
|
|
464
|
+
? "No uploads yet."
|
|
465
|
+
: "No icons here."
|
|
466
|
+
: `${fmt(filtered.length)} icon${filtered.length === 1 ? "" : "s"}`;
|
|
467
|
+
|
|
468
|
+
return (
|
|
469
|
+
<div className="emvb-icon-library" data-emvb-dialog="icon-library">
|
|
470
|
+
<header className="emvb-icon-library-head">
|
|
471
|
+
<div>
|
|
472
|
+
<Dialog.Title className="emvb-icon-library-title">Icon library</Dialog.Title>
|
|
473
|
+
<Dialog.Description className="emvb-helper">
|
|
474
|
+
Lucide, Font Awesome Free, Tabler and Remix. The icon you insert is saved into the page
|
|
475
|
+
as SVG, so visitors never download an icon set.
|
|
476
|
+
</Dialog.Description>
|
|
477
|
+
</div>
|
|
478
|
+
<Dialog.Close
|
|
479
|
+
render={(props) => (
|
|
480
|
+
<Button
|
|
481
|
+
{...props}
|
|
482
|
+
variant="ghost"
|
|
483
|
+
shape="square"
|
|
484
|
+
size="sm"
|
|
485
|
+
aria-label="Close icon library"
|
|
486
|
+
className="emvb-icon-btn"
|
|
487
|
+
>
|
|
488
|
+
<XIcon size={16} aria-hidden="true" />
|
|
489
|
+
</Button>
|
|
490
|
+
)}
|
|
491
|
+
/>
|
|
492
|
+
</header>
|
|
493
|
+
|
|
494
|
+
<nav className="emvb-icon-library-nav" aria-label="Icon sets">
|
|
495
|
+
<ul>
|
|
496
|
+
{categories.map((item) => {
|
|
497
|
+
const count = counts.get(item.id);
|
|
498
|
+
const current = item.id === categoryId;
|
|
499
|
+
return (
|
|
500
|
+
<li key={item.id}>
|
|
501
|
+
<button
|
|
502
|
+
type="button"
|
|
503
|
+
className="emvb-icon-library-cat"
|
|
504
|
+
data-emvb-icon-category={item.id}
|
|
505
|
+
data-sub={item.style ? "true" : undefined}
|
|
506
|
+
data-uploads={item.id === UPLOADS ? "true" : undefined}
|
|
507
|
+
aria-current={current ? "true" : undefined}
|
|
508
|
+
onClick={() => setCategoryId(item.id)}
|
|
509
|
+
>
|
|
510
|
+
<span>{item.label}</span>
|
|
511
|
+
{count !== undefined ? (
|
|
512
|
+
<span className="emvb-icon-library-count">{fmt(count)}</span>
|
|
513
|
+
) : null}
|
|
514
|
+
</button>
|
|
515
|
+
</li>
|
|
516
|
+
);
|
|
517
|
+
})}
|
|
518
|
+
</ul>
|
|
519
|
+
<p className="emvb-icon-library-licenses">
|
|
520
|
+
{ICON_SETS.map((set) => `${set.label} · ${set.license}`).join("\n")}
|
|
521
|
+
</p>
|
|
522
|
+
</nav>
|
|
523
|
+
|
|
524
|
+
<div className="emvb-icon-library-main">
|
|
525
|
+
<div className="emvb-icon-library-search">
|
|
526
|
+
<label htmlFor={searchId} className="emvb-sr-only">
|
|
527
|
+
Search icons
|
|
528
|
+
</label>
|
|
529
|
+
<MagnifyingGlassIcon
|
|
530
|
+
size={16}
|
|
531
|
+
className="emvb-icon-library-search-glyph"
|
|
532
|
+
aria-hidden="true"
|
|
533
|
+
/>
|
|
534
|
+
<input
|
|
535
|
+
id={searchId}
|
|
536
|
+
type="search"
|
|
537
|
+
// The dialog opens straight into the search, like a command palette.11y/no-autofocus
|
|
538
|
+
autoFocus
|
|
539
|
+
value={query}
|
|
540
|
+
placeholder={`Search ${category.id === ALL_ICONS ? "all icons" : category.label}…`}
|
|
541
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
542
|
+
onKeyDown={(event) => {
|
|
543
|
+
if ((event.key === "ArrowDown" || event.key === "Enter") && filtered.length > 0) {
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
if (active < 0) setActive(0);
|
|
546
|
+
gridRef.current?.focus();
|
|
547
|
+
}
|
|
548
|
+
}}
|
|
549
|
+
/>
|
|
550
|
+
<span className="emvb-icon-library-status" role="status" aria-live="polite">
|
|
551
|
+
{status}
|
|
552
|
+
</span>
|
|
553
|
+
</div>
|
|
554
|
+
{inUploads && (
|
|
555
|
+
<div className="emvb-icon-library-upload" data-emvb-icon-upload="">
|
|
556
|
+
<Button
|
|
557
|
+
variant="secondary"
|
|
558
|
+
size="sm"
|
|
559
|
+
className={BUTTON}
|
|
560
|
+
icon={<UploadSimpleIcon aria-hidden="true" />}
|
|
561
|
+
disabled={uploading}
|
|
562
|
+
data-emvb-icon-upload-btn=""
|
|
563
|
+
onClick={() => fileRef.current?.click()}
|
|
564
|
+
>
|
|
565
|
+
{uploading ? "Uploading…" : "Upload SVG"}
|
|
566
|
+
</Button>
|
|
567
|
+
<input
|
|
568
|
+
ref={fileRef}
|
|
569
|
+
type="file"
|
|
570
|
+
accept=".svg,image/svg+xml"
|
|
571
|
+
className="emvb-sr-only"
|
|
572
|
+
tabIndex={-1}
|
|
573
|
+
aria-hidden="true"
|
|
574
|
+
data-emvb-icon-upload-input=""
|
|
575
|
+
onChange={(event) => void onUpload(event.target.files?.[0])}
|
|
576
|
+
/>
|
|
577
|
+
<span
|
|
578
|
+
className="emvb-helper"
|
|
579
|
+
data-emvb-icon-upload-note={uploadNote ? (uploadNote.error ? "error" : "ok") : ""}
|
|
580
|
+
role={uploadNote?.error ? "alert" : undefined}
|
|
581
|
+
>
|
|
582
|
+
{uploadNote?.text ??
|
|
583
|
+
"Up to 256 KB. Scripts, event handlers and outside images are removed or refused; the icon is saved with the page."}
|
|
584
|
+
</span>
|
|
585
|
+
</div>
|
|
586
|
+
)}
|
|
587
|
+
{inUploads && uploadsFailed ? (
|
|
588
|
+
<div className="emvb-icon-library-empty">
|
|
589
|
+
<p>Your uploads didn't load: {uploadsFailed}</p>
|
|
590
|
+
<Button
|
|
591
|
+
variant="secondary"
|
|
592
|
+
size="sm"
|
|
593
|
+
className={BUTTON}
|
|
594
|
+
onClick={() => {
|
|
595
|
+
setUploadsFailed(undefined);
|
|
596
|
+
setAttempt((n) => n + 1);
|
|
597
|
+
}}
|
|
598
|
+
>
|
|
599
|
+
Try again
|
|
600
|
+
</Button>
|
|
601
|
+
</div>
|
|
602
|
+
) : failed ? (
|
|
603
|
+
<div className="emvb-icon-library-empty">
|
|
604
|
+
<p>The {failed} icons didn't load. Check the connection and try again.</p>
|
|
605
|
+
<Button
|
|
606
|
+
variant="secondary"
|
|
607
|
+
size="sm"
|
|
608
|
+
className={BUTTON}
|
|
609
|
+
onClick={() => setAttempt((n) => n + 1)}
|
|
610
|
+
>
|
|
611
|
+
Try again
|
|
612
|
+
</Button>
|
|
613
|
+
</div>
|
|
614
|
+
) : !ready ? (
|
|
615
|
+
<div className="emvb-icon-library-empty" aria-busy="true">
|
|
616
|
+
<span className="emvb-icon-library-spinner" aria-hidden="true" />
|
|
617
|
+
</div>
|
|
618
|
+
) : filtered.length === 0 ? (
|
|
619
|
+
<div className="emvb-icon-library-empty">
|
|
620
|
+
<p>{status}</p>
|
|
621
|
+
</div>
|
|
622
|
+
) : (
|
|
623
|
+
<IconGrid
|
|
624
|
+
icons={filtered}
|
|
625
|
+
selectedId={selectedId}
|
|
626
|
+
active={active}
|
|
627
|
+
label={`${category.label} icons`}
|
|
628
|
+
gridRef={gridRef}
|
|
629
|
+
onActive={activate}
|
|
630
|
+
onCursor={setActive}
|
|
631
|
+
onInsert={onInsert}
|
|
632
|
+
/>
|
|
633
|
+
)}
|
|
634
|
+
</div>
|
|
635
|
+
|
|
636
|
+
<footer className="emvb-icon-library-foot">
|
|
637
|
+
<div className="emvb-icon-library-picked" data-emvb-icon-picked={selected?.id ?? ""}>
|
|
638
|
+
{selected ? (
|
|
639
|
+
<>
|
|
640
|
+
<span
|
|
641
|
+
className="emvb-icon-library-picked-glyph"
|
|
642
|
+
aria-hidden="true"
|
|
643
|
+
dangerouslySetInnerHTML={{ __html: selected.markup }}
|
|
644
|
+
/>
|
|
645
|
+
<span className="emvb-icon-library-picked-text">
|
|
646
|
+
<strong>{selected.label}</strong>
|
|
647
|
+
<span>
|
|
648
|
+
{iconSource(selected)} · <code className="emvb-mono">{selected.id}</code>
|
|
649
|
+
</span>
|
|
650
|
+
</span>
|
|
651
|
+
</>
|
|
652
|
+
) : (
|
|
653
|
+
<span className="emvb-helper">
|
|
654
|
+
Pick an icon, then Insert. Double-click or Enter inserts at once.
|
|
655
|
+
</span>
|
|
656
|
+
)}
|
|
657
|
+
</div>
|
|
658
|
+
<div className="emvb-icon-library-actions">
|
|
659
|
+
<Dialog.Close
|
|
660
|
+
render={(props) => (
|
|
661
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
662
|
+
Close
|
|
663
|
+
</Button>
|
|
664
|
+
)}
|
|
665
|
+
/>
|
|
666
|
+
<Button
|
|
667
|
+
variant="primary"
|
|
668
|
+
className={`${BUTTON} ${SOLID_PRIMARY}`}
|
|
669
|
+
disabled={!selected}
|
|
670
|
+
data-emvb-icon-insert=""
|
|
671
|
+
onClick={() => {
|
|
672
|
+
if (selected) onInsert(selected);
|
|
673
|
+
}}
|
|
674
|
+
>
|
|
675
|
+
Insert
|
|
676
|
+
</Button>
|
|
677
|
+
</div>
|
|
678
|
+
</footer>
|
|
679
|
+
</div>
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* The icon library (W-236): sets in a sidebar, a word search and a virtualized grid of every
|
|
685
|
+
* icon. Sets load on first view; inserting hands back the icon with its complete SVG.
|
|
686
|
+
*/
|
|
687
|
+
export function IconLibraryDialog({
|
|
688
|
+
open,
|
|
689
|
+
onOpenChange,
|
|
690
|
+
currentId,
|
|
691
|
+
fetcher,
|
|
692
|
+
onInsert,
|
|
693
|
+
onClosed,
|
|
694
|
+
}: {
|
|
695
|
+
open: boolean;
|
|
696
|
+
onOpenChange: (open: boolean) => void;
|
|
697
|
+
currentId: string | undefined;
|
|
698
|
+
/** Enables My uploads (W-239). */
|
|
699
|
+
fetcher?: Fetcher;
|
|
700
|
+
onInsert: (icon: LibraryIcon) => void;
|
|
701
|
+
/** After the close animation, once the focus trap has let go: the place to put focus back. */
|
|
702
|
+
onClosed?: () => void;
|
|
703
|
+
}) {
|
|
704
|
+
return (
|
|
705
|
+
<Dialog.Root
|
|
706
|
+
open={open}
|
|
707
|
+
onOpenChange={onOpenChange}
|
|
708
|
+
onOpenChangeComplete={(next) => {
|
|
709
|
+
if (!next) onClosed?.();
|
|
710
|
+
}}
|
|
711
|
+
>
|
|
712
|
+
<Dialog
|
|
713
|
+
size="xl"
|
|
714
|
+
className="emvb-icon-library-popup"
|
|
715
|
+
style={{
|
|
716
|
+
width: "min(1080px, calc(100vw - 32px))",
|
|
717
|
+
height: "min(760px, calc(100vh - 48px))",
|
|
718
|
+
}}
|
|
719
|
+
>
|
|
720
|
+
<style>{UI_CSS + ICON_LIBRARY_CSS}</style>
|
|
721
|
+
{open ? (
|
|
722
|
+
<IconLibrary
|
|
723
|
+
currentId={currentId}
|
|
724
|
+
fetcher={fetcher}
|
|
725
|
+
onInsert={(icon) => {
|
|
726
|
+
onInsert(icon);
|
|
727
|
+
onOpenChange(false);
|
|
728
|
+
}}
|
|
729
|
+
/>
|
|
730
|
+
) : null}
|
|
731
|
+
</Dialog>
|
|
732
|
+
</Dialog.Root>
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const ICON_LIBRARY_CSS = `
|
|
737
|
+
.emvb-icon-library-popup.emvb-icon-library-popup { padding: 0; display: flex; }
|
|
738
|
+
.emvb-icon-library {
|
|
739
|
+
--emvb-tile-bg: color-mix(in oklab, var(--color-kumo-elevated) 60%, var(--color-kumo-base));
|
|
740
|
+
flex: 1; min-height: 0; min-width: 0;
|
|
741
|
+
display: grid;
|
|
742
|
+
grid-template-columns: 208px minmax(0, 1fr);
|
|
743
|
+
grid-template-rows: auto minmax(0, 1fr) auto;
|
|
744
|
+
grid-template-areas: "head head" "nav main" "foot foot";
|
|
745
|
+
color: var(--text-color-kumo-default);
|
|
746
|
+
font-size: 13px; line-height: 18px;
|
|
747
|
+
}
|
|
748
|
+
.emvb-icon-library-upload {
|
|
749
|
+
display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
|
|
750
|
+
padding: 10px 16px; border-bottom: 1px solid var(--color-kumo-hairline);
|
|
751
|
+
}
|
|
752
|
+
.emvb-icon-library-upload [data-emvb-icon-upload-note="error"] { color: var(--text-color-kumo-danger, #b91c1c); }
|
|
753
|
+
.emvb-icon-library-cat[data-uploads] { margin-top: 8px; border-top: 1px solid var(--color-kumo-hairline); padding-top: 8px; }
|
|
754
|
+
.emvb-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
755
|
+
.emvb-icon-library-head {
|
|
756
|
+
grid-area: head; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
|
|
757
|
+
padding: 16px 16px 14px 20px; border-bottom: 1px solid var(--color-kumo-hairline);
|
|
758
|
+
}
|
|
759
|
+
.emvb-icon-library-title { margin: 0 0 2px; font-size: 16px; line-height: 22px; font-weight: 600; }
|
|
760
|
+
.emvb-icon-library-nav {
|
|
761
|
+
grid-area: nav; display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
|
|
762
|
+
min-height: 0; overflow: auto; padding: 12px 10px;
|
|
763
|
+
border-right: 1px solid var(--color-kumo-hairline);
|
|
764
|
+
background: color-mix(in oklab, var(--color-kumo-recessed) 45%, var(--color-kumo-base));
|
|
765
|
+
}
|
|
766
|
+
.emvb-icon-library-nav ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 1px; }
|
|
767
|
+
.emvb-icon-library-cat {
|
|
768
|
+
display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px;
|
|
769
|
+
height: 30px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent;
|
|
770
|
+
color: var(--text-color-kumo-default); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
|
|
771
|
+
}
|
|
772
|
+
.emvb-icon-library-cat[data-sub="true"] { height: 26px; padding-left: 24px; font-weight: 400; color: var(--text-color-kumo-subtle); }
|
|
773
|
+
.emvb-icon-library-cat:hover { background: var(--color-kumo-tint); }
|
|
774
|
+
.emvb-icon-library-cat[aria-current="true"] {
|
|
775
|
+
background: color-mix(in oklab, var(--color-kumo-brand) 12%, transparent);
|
|
776
|
+
color: var(--text-color-kumo-default);
|
|
777
|
+
box-shadow: inset 2px 0 0 var(--color-kumo-brand);
|
|
778
|
+
}
|
|
779
|
+
.emvb-icon-library-cat:focus-visible, .emvb-icon-library-grid:focus-visible, .emvb-icon-library-search input:focus-visible {
|
|
780
|
+
outline: 2px solid var(--color-kumo-brand); outline-offset: -2px;
|
|
781
|
+
}
|
|
782
|
+
.emvb-icon-library-count { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); }
|
|
783
|
+
/* W-244: on the current entry's tinted background the subtle grey is 4.1:1. */
|
|
784
|
+
.emvb-icon-library-cat[aria-current="true"] .emvb-icon-library-count { color: var(--text-color-kumo-default); }
|
|
785
|
+
.emvb-icon-library-licenses { margin: 0; padding: 0 10px; white-space: pre-line; font-size: 11px; line-height: 16px; color: var(--text-color-kumo-subtle); }
|
|
786
|
+
.emvb-icon-library-main { grid-area: main; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
|
|
787
|
+
.emvb-icon-library-search {
|
|
788
|
+
position: relative; display: flex; align-items: center; gap: 12px;
|
|
789
|
+
padding: 12px 16px; border-bottom: 1px solid var(--color-kumo-hairline);
|
|
790
|
+
}
|
|
791
|
+
.emvb-icon-library-search input {
|
|
792
|
+
flex: 1; min-width: 0; height: 36px; padding: 0 12px 0 36px;
|
|
793
|
+
border: 1px solid var(--color-kumo-line); border-radius: 8px;
|
|
794
|
+
background: var(--color-kumo-control, var(--color-kumo-base)); color: inherit; font: inherit; font-size: 14px;
|
|
795
|
+
}
|
|
796
|
+
.emvb-icon-library-search-glyph { position: absolute; left: 28px; width: 16px; height: 16px; color: var(--text-color-kumo-subtle); pointer-events: none; }
|
|
797
|
+
.emvb-icon-library-status { flex: none; min-width: 88px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); }
|
|
798
|
+
.emvb-icon-library-grid { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: ${PAD}px; }
|
|
799
|
+
.emvb-icon-library-rows { position: relative; }
|
|
800
|
+
.emvb-icon-library-tile {
|
|
801
|
+
position: absolute; height: ${TILE_HEIGHT}px; box-sizing: border-box;
|
|
802
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
|
|
803
|
+
padding: 10px 6px 8px; border-radius: 8px; border: 1px solid transparent;
|
|
804
|
+
background: var(--emvb-tile-bg); color: var(--text-color-kumo-default); cursor: pointer; user-select: none;
|
|
805
|
+
}
|
|
806
|
+
.emvb-icon-library-tile:hover { border-color: var(--color-kumo-line); }
|
|
807
|
+
.emvb-icon-library-tile[data-active="true"] { border-color: var(--color-kumo-line); background: var(--color-kumo-tint); }
|
|
808
|
+
.emvb-icon-library-grid:focus-visible .emvb-icon-library-tile[data-active="true"] { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
|
|
809
|
+
.emvb-icon-library-tile[data-selected="true"] {
|
|
810
|
+
border-color: var(--color-kumo-brand);
|
|
811
|
+
background: color-mix(in oklab, var(--color-kumo-brand) 10%, var(--color-kumo-base));
|
|
812
|
+
color: var(--color-kumo-brand);
|
|
813
|
+
}
|
|
814
|
+
.emvb-icon-library-tile[data-selected="true"]::after {
|
|
815
|
+
content: ""; position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 9999px; background: var(--color-kumo-brand);
|
|
816
|
+
}
|
|
817
|
+
.emvb-icon-library-glyph { display: flex; width: 26px; height: 26px; }
|
|
818
|
+
.emvb-icon-library-glyph svg { width: 26px; height: 26px; }
|
|
819
|
+
.emvb-icon-library-name {
|
|
820
|
+
max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
821
|
+
font-size: 11px; line-height: 14px; color: var(--text-color-kumo-subtle);
|
|
822
|
+
}
|
|
823
|
+
.emvb-icon-library-tile[data-selected="true"] .emvb-icon-library-name { color: var(--text-color-kumo-default); }
|
|
824
|
+
.emvb-icon-library-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; color: var(--text-color-kumo-subtle); }
|
|
825
|
+
.emvb-icon-library-empty p { margin: 0; }
|
|
826
|
+
.emvb-icon-library-spinner { width: 22px; height: 22px; border-radius: 9999px; border: 2px solid var(--color-kumo-line); border-top-color: var(--color-kumo-brand); animation: emvb-icon-spin 0.8s linear infinite; }
|
|
827
|
+
@keyframes emvb-icon-spin { to { transform: rotate(360deg); } }
|
|
828
|
+
.emvb-icon-library-foot {
|
|
829
|
+
grid-area: foot; display: flex; align-items: center; justify-content: space-between; gap: 16px;
|
|
830
|
+
padding: 12px 16px 12px 20px; border-top: 1px solid var(--color-kumo-hairline);
|
|
831
|
+
}
|
|
832
|
+
.emvb-icon-library-picked { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
|
833
|
+
.emvb-icon-library-picked-glyph {
|
|
834
|
+
flex: none; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px;
|
|
835
|
+
border-radius: 8px; color: var(--color-kumo-brand);
|
|
836
|
+
background: color-mix(in oklab, var(--color-kumo-brand) 10%, var(--color-kumo-base));
|
|
837
|
+
}
|
|
838
|
+
.emvb-icon-library-picked-glyph svg { width: 22px; height: 22px; }
|
|
839
|
+
.emvb-icon-library-picked-text { display: flex; flex-direction: column; min-width: 0; }
|
|
840
|
+
.emvb-icon-library-picked-text span { font-size: 12px; color: var(--text-color-kumo-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
841
|
+
.emvb-icon-library-actions { display: flex; gap: 8px; flex: none; }
|
|
842
|
+
@media (max-width: 640px) {
|
|
843
|
+
.emvb-icon-library { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "nav" "main" "foot"; grid-template-rows: auto auto minmax(0, 1fr) auto; }
|
|
844
|
+
.emvb-icon-library-nav { border-right: 0; border-bottom: 1px solid var(--color-kumo-hairline); max-height: 96px; }
|
|
845
|
+
.emvb-icon-library-nav ul { flex-direction: row; flex-wrap: wrap; }
|
|
846
|
+
.emvb-icon-library-cat, .emvb-icon-library-cat[data-sub="true"] { width: auto; padding: 0 10px; }
|
|
847
|
+
.emvb-icon-library-licenses { display: none; }
|
|
848
|
+
}
|
|
849
|
+
@media (prefers-reduced-motion: reduce) { .emvb-icon-library-spinner { animation: none; } }
|
|
850
|
+
`;
|