@perkyzz/emvb 0.6.0 → 0.7.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/package.json +1 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +82 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +10 -0
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +130 -23
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +55 -19
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +11 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +7 -0
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- package/src/admin/media-api.ts +2 -1
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +73 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +27 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +15 -1
- package/src/core/limits.ts +12 -1
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +15 -6
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +31 -11
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +6 -1
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
import * as React from "react";
|
|
10
10
|
import type { Fetcher } from "../../api.ts";
|
|
11
11
|
import { BUTTON, SOLID_PRIMARY, UI_CSS } from "../../ui.ts";
|
|
12
|
-
import { ALL_ICONS, ICON_SETS, UPLOADS, type LibraryIcon } from "./library.ts";
|
|
12
|
+
import { ALL_ICONS, ICON_SETS, UPLOADS, type LibraryIcon, type loadIconSet } from "./library.ts";
|
|
13
13
|
import { fmt, useIconLibrary } from "./use-icon-library.ts";
|
|
14
|
+
import { isCommitEnter } from "../ime.ts";
|
|
14
15
|
|
|
15
16
|
/** Grid geometry, in px. Tiles stretch to fill the row; this is their narrowest. */
|
|
16
17
|
const TILE_MIN_WIDTH = 96;
|
|
@@ -221,7 +222,7 @@ function IconGrid({
|
|
|
221
222
|
if (event.target === event.currentTarget && active < 0 && icons.length > 0) onCursor(0);
|
|
222
223
|
}}
|
|
223
224
|
onKeyDown={(event) => {
|
|
224
|
-
if (event
|
|
225
|
+
if (isCommitEnter(event)) {
|
|
225
226
|
const icon = icons[active];
|
|
226
227
|
if (icon) {
|
|
227
228
|
event.preventDefault();
|
|
@@ -249,11 +250,13 @@ function IconGrid({
|
|
|
249
250
|
function IconLibrary({
|
|
250
251
|
currentId,
|
|
251
252
|
fetcher,
|
|
253
|
+
loadSet,
|
|
252
254
|
onInsert,
|
|
253
255
|
}: {
|
|
254
256
|
currentId: string | undefined;
|
|
255
257
|
/** With a fetcher, My uploads lists and adds uploaded SVGs (W-239). */
|
|
256
258
|
fetcher?: Fetcher;
|
|
259
|
+
loadSet?: typeof loadIconSet;
|
|
257
260
|
onInsert: (icon: LibraryIcon) => void;
|
|
258
261
|
}) {
|
|
259
262
|
const {
|
|
@@ -286,7 +289,8 @@ function IconLibrary({
|
|
|
286
289
|
uploadId,
|
|
287
290
|
renameUpload,
|
|
288
291
|
deleteUpload,
|
|
289
|
-
} = useIconLibrary({ currentId, fetcher });
|
|
292
|
+
} = useIconLibrary({ currentId, fetcher, loadSet });
|
|
293
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
290
294
|
return (
|
|
291
295
|
<div className="emvb-icon-library" data-emvb-dialog="icon-library">
|
|
292
296
|
<header className="emvb-icon-library-head">
|
|
@@ -354,15 +358,17 @@ function IconLibrary({
|
|
|
354
358
|
aria-hidden="true"
|
|
355
359
|
/>
|
|
356
360
|
<input
|
|
361
|
+
ref={searchRef}
|
|
357
362
|
id={searchId}
|
|
358
363
|
type="search"
|
|
359
|
-
// The dialog opens straight into the search, like a command palette.
|
|
364
|
+
// The dialog opens straight into the search, like a command palette.
|
|
360
365
|
autoFocus
|
|
361
366
|
value={query}
|
|
362
367
|
placeholder={`Search ${category.id === ALL_ICONS ? "all icons" : category.label}…`}
|
|
363
368
|
onChange={(event) => setQuery(event.target.value)}
|
|
364
369
|
onKeyDown={(event) => {
|
|
365
|
-
|
|
370
|
+
// W-682: not the Enter that confirms an IME word (W-606).
|
|
371
|
+
if ((event.key === "ArrowDown" || isCommitEnter(event)) && filtered.length > 0) {
|
|
366
372
|
event.preventDefault();
|
|
367
373
|
if (active < 0) setActive(0);
|
|
368
374
|
gridRef.current?.focus();
|
|
@@ -380,11 +386,18 @@ function IconLibrary({
|
|
|
380
386
|
size="sm"
|
|
381
387
|
className={BUTTON}
|
|
382
388
|
icon={<UploadSimpleIcon aria-hidden="true" />}
|
|
383
|
-
disabled
|
|
389
|
+
// W-827: focusable while uploading (aria-disabled, press ignored); disabling it
|
|
390
|
+
// dropped keyboard focus out of the modal to the page body.
|
|
391
|
+
aria-disabled={uploading}
|
|
384
392
|
data-emvb-icon-upload-btn=""
|
|
385
|
-
onClick={() =>
|
|
393
|
+
onClick={() => {
|
|
394
|
+
if (!uploading) fileRef.current?.click();
|
|
395
|
+
}}
|
|
386
396
|
>
|
|
387
|
-
|
|
397
|
+
<span className="emvb-icon-upload-label">
|
|
398
|
+
<span aria-hidden={uploading}>Upload SVG</span>
|
|
399
|
+
<span aria-hidden={!uploading}>Uploading…</span>
|
|
400
|
+
</span>
|
|
388
401
|
</Button>
|
|
389
402
|
<input
|
|
390
403
|
ref={fileRef}
|
|
@@ -399,7 +412,8 @@ function IconLibrary({
|
|
|
399
412
|
<span
|
|
400
413
|
className="emvb-helper"
|
|
401
414
|
data-emvb-icon-upload-note={uploadNote ? (uploadNote.error ? "error" : "ok") : ""}
|
|
402
|
-
role={uploadNote
|
|
415
|
+
role={uploadNote ? (uploadNote.error ? "alert" : "status") : undefined}
|
|
416
|
+
aria-live={uploadNote?.error ? "assertive" : "polite"}
|
|
403
417
|
>
|
|
404
418
|
{uploadNote?.text ??
|
|
405
419
|
"Up to 256 KB. Scripts, event handlers and outside images are removed or refused; the icon is saved with the page."}
|
|
@@ -414,6 +428,8 @@ function IconLibrary({
|
|
|
414
428
|
size="sm"
|
|
415
429
|
className={BUTTON}
|
|
416
430
|
onClick={() => {
|
|
431
|
+
// W-747: this button unmounts on retry; keep focus in the dialog.
|
|
432
|
+
searchRef.current?.focus();
|
|
417
433
|
setUploadsFailed(undefined);
|
|
418
434
|
setAttempt((n) => n + 1);
|
|
419
435
|
}}
|
|
@@ -428,7 +444,11 @@ function IconLibrary({
|
|
|
428
444
|
variant="secondary"
|
|
429
445
|
size="sm"
|
|
430
446
|
className={BUTTON}
|
|
431
|
-
onClick={() =>
|
|
447
|
+
onClick={() => {
|
|
448
|
+
// W-749: this button unmounts on retry; keep focus in the dialog.
|
|
449
|
+
searchRef.current?.focus();
|
|
450
|
+
setAttempt((n) => n + 1);
|
|
451
|
+
}}
|
|
432
452
|
>
|
|
433
453
|
Try again
|
|
434
454
|
</Button>
|
|
@@ -440,6 +460,19 @@ function IconLibrary({
|
|
|
440
460
|
) : filtered.length === 0 ? (
|
|
441
461
|
<div className="emvb-icon-library-empty">
|
|
442
462
|
<p>{status}</p>
|
|
463
|
+
{query.trim() && (
|
|
464
|
+
<Button
|
|
465
|
+
variant="secondary"
|
|
466
|
+
size="sm"
|
|
467
|
+
className={BUTTON}
|
|
468
|
+
onClick={() => {
|
|
469
|
+
setQuery("");
|
|
470
|
+
searchRef.current?.focus();
|
|
471
|
+
}}
|
|
472
|
+
>
|
|
473
|
+
Clear search
|
|
474
|
+
</Button>
|
|
475
|
+
)}
|
|
443
476
|
</div>
|
|
444
477
|
) : (
|
|
445
478
|
<IconGrid
|
|
@@ -535,6 +568,7 @@ export function IconLibraryDialog({
|
|
|
535
568
|
onOpenChange,
|
|
536
569
|
currentId,
|
|
537
570
|
fetcher,
|
|
571
|
+
loadSet,
|
|
538
572
|
onInsert,
|
|
539
573
|
onClosed,
|
|
540
574
|
}: {
|
|
@@ -543,6 +577,8 @@ export function IconLibraryDialog({
|
|
|
543
577
|
currentId: string | undefined;
|
|
544
578
|
/** Enables My uploads (W-239). */
|
|
545
579
|
fetcher?: Fetcher;
|
|
580
|
+
/** Replaces the icon-set loader (tests: a set that fails to download). */
|
|
581
|
+
loadSet?: typeof loadIconSet;
|
|
546
582
|
onInsert: (icon: LibraryIcon) => void;
|
|
547
583
|
/** After the close animation, once the focus trap has let go: the place to put focus back. */
|
|
548
584
|
onClosed?: () => void;
|
|
@@ -568,6 +604,7 @@ export function IconLibraryDialog({
|
|
|
568
604
|
<IconLibrary
|
|
569
605
|
currentId={currentId}
|
|
570
606
|
fetcher={fetcher}
|
|
607
|
+
loadSet={loadSet}
|
|
571
608
|
onInsert={(icon) => {
|
|
572
609
|
onInsert(icon);
|
|
573
610
|
onOpenChange(false);
|
|
@@ -592,9 +629,13 @@ const ICON_LIBRARY_CSS = `
|
|
|
592
629
|
font-size: 13px; line-height: 18px;
|
|
593
630
|
}
|
|
594
631
|
.emvb-icon-library-upload {
|
|
595
|
-
display:
|
|
632
|
+
display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 12px;
|
|
596
633
|
padding: 10px 16px; border-bottom: 1px solid var(--color-kumo-hairline);
|
|
597
634
|
}
|
|
635
|
+
.emvb-icon-upload-label { display: grid; }
|
|
636
|
+
.emvb-icon-upload-label > span { grid-area: 1 / 1; }
|
|
637
|
+
.emvb-icon-upload-label > span[aria-hidden="true"] { visibility: hidden; }
|
|
638
|
+
.emvb-icon-library-upload [data-emvb-icon-upload-note] { display: flex; align-items: center; min-height: 2lh; }
|
|
598
639
|
.emvb-icon-library-upload [data-emvb-icon-upload-note="error"] { color: var(--text-color-kumo-danger, #b91c1c); }
|
|
599
640
|
.emvb-icon-library-cat[data-uploads] { margin-top: 8px; border-top: 1px solid var(--color-kumo-hairline); padding-top: 8px; }
|
|
600
641
|
.emvb-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getBundledIcon, sanitizeSvgMarkup } from "../../../core/index.ts";
|
|
2
2
|
import { serialize } from "../../../core/render/vnode.ts";
|
|
3
3
|
import type { UploadedIconItem } from "../../icon-uploads-api.ts";
|
|
4
|
-
import { fold } from "../../
|
|
4
|
+
import { fold } from "../../search.ts";
|
|
5
5
|
import type { IconEntry, IconSetFile } from "./set-format.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -36,9 +36,12 @@ function initialCategory(currentId: string | undefined, uploads: boolean): strin
|
|
|
36
36
|
export function useIconLibrary({
|
|
37
37
|
currentId,
|
|
38
38
|
fetcher,
|
|
39
|
+
loadSet = loadIconSet,
|
|
39
40
|
}: {
|
|
40
41
|
currentId: string | undefined;
|
|
41
42
|
fetcher?: Fetcher;
|
|
43
|
+
/** Loads one icon set; replaceable so a failed download can be tested. */
|
|
44
|
+
loadSet?: typeof loadIconSet;
|
|
42
45
|
}) {
|
|
43
46
|
const [categoryId, setCategoryId] = React.useState(() =>
|
|
44
47
|
initialCategory(currentId, fetcher !== undefined),
|
|
@@ -95,7 +98,7 @@ export function useIconLibrary({
|
|
|
95
98
|
let live = true;
|
|
96
99
|
setFailed(undefined);
|
|
97
100
|
for (const id of (neededKey ? neededKey.split(",") : []) as IconSetId[]) {
|
|
98
|
-
|
|
101
|
+
loadSet(id).then(
|
|
99
102
|
(icons) => {
|
|
100
103
|
if (live) setSets((prev) => (prev[id] ? prev : { ...prev, [id]: icons }));
|
|
101
104
|
},
|
|
@@ -107,7 +110,7 @@ export function useIconLibrary({
|
|
|
107
110
|
return () => {
|
|
108
111
|
live = false;
|
|
109
112
|
};
|
|
110
|
-
}, [neededKey, attempt]);
|
|
113
|
+
}, [neededKey, attempt, loadSet]);
|
|
111
114
|
|
|
112
115
|
// All icons waits for the uploads list too, unless it failed (the sets still show, W-295).
|
|
113
116
|
const uploadsSettled = !fetcher || uploads !== undefined || uploadsFailed !== undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True for an Enter that commits a field: not the Enter that confirms an IME
|
|
3
|
+
* composition (Japanese, Chinese, Korean input), which must only finish the word (W-606).
|
|
4
|
+
*/
|
|
5
|
+
export function isCommitEnter(event: {
|
|
6
|
+
key: string;
|
|
7
|
+
keyCode?: number;
|
|
8
|
+
nativeEvent?: { isComposing?: boolean };
|
|
9
|
+
isComposing?: boolean;
|
|
10
|
+
}): boolean {
|
|
11
|
+
if (event.key !== "Enter") return false;
|
|
12
|
+
if (event.nativeEvent?.isComposing || event.isComposing) return false;
|
|
13
|
+
return event.keyCode !== 229;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* W-681: true for an Escape that cancels a field, not the Escape an input method uses to drop the
|
|
18
|
+
* word being composed. Fields cancelled on it threw away everything typed so far.
|
|
19
|
+
*/
|
|
20
|
+
export function isCancelEscape(event: {
|
|
21
|
+
key: string;
|
|
22
|
+
keyCode?: number;
|
|
23
|
+
nativeEvent?: { isComposing?: boolean };
|
|
24
|
+
isComposing?: boolean;
|
|
25
|
+
}): boolean {
|
|
26
|
+
if (event.key !== "Escape") return false;
|
|
27
|
+
if (event.nativeEvent?.isComposing || event.isComposing) return false;
|
|
28
|
+
return event.keyCode !== 229;
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ELEMENT_DESCRIPTORS,
|
|
3
3
|
SECTION_RECIPES,
|
|
4
|
+
clipText,
|
|
4
5
|
type DesignSystem,
|
|
5
6
|
type ElementType,
|
|
6
7
|
type Layout,
|
|
@@ -46,12 +47,18 @@ function textOf(node: LayoutNode): string {
|
|
|
46
47
|
const items = props["items"];
|
|
47
48
|
if (Array.isArray(items)) {
|
|
48
49
|
for (const item of items) {
|
|
50
|
+
// W-618: a List's items are plain strings.
|
|
51
|
+
if (typeof item === "string") {
|
|
52
|
+
if (item.trim()) parts.push(item.trim());
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
49
55
|
if (item && typeof item === "object" && "text" in item && typeof item.text === "string") {
|
|
50
56
|
parts.push(item.text.trim());
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
|
-
|
|
60
|
+
// W-556: the whole text, so Find text finds a word near the end of a long paragraph.
|
|
61
|
+
return parts.join(" ").replace(/\s+/g, " ");
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
/** Every palette command for the editor's current state (W-314). */
|
|
@@ -98,7 +105,7 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
|
|
|
98
105
|
id: `layer:${node.id}`,
|
|
99
106
|
group: "Jump to",
|
|
100
107
|
label: depth === 0 ? "Page (root)" : name,
|
|
101
|
-
...(text ? { hint: `“${text
|
|
108
|
+
...(text ? { hint: `“${clipText(text, 40)}”` } : {}),
|
|
102
109
|
keywords: `${node.type} ${text}`,
|
|
103
110
|
run: () => ctx.select(node.id),
|
|
104
111
|
});
|
|
@@ -106,7 +113,7 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
|
|
|
106
113
|
items.push({
|
|
107
114
|
id: `find:${node.id}`,
|
|
108
115
|
group: "Find text",
|
|
109
|
-
label: text.length > 80 ? `${text
|
|
116
|
+
label: text.length > 80 ? `${clipText(text, 77)}…` : text,
|
|
110
117
|
hint: name,
|
|
111
118
|
keywords: text,
|
|
112
119
|
run: () => ctx.select(node.id),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Input } from "@cloudflare/kumo";
|
|
1
|
+
import { Button, Input } from "@cloudflare/kumo";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { elementIcon } from "../element-chrome.ts";
|
|
4
4
|
import {
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
type ElementType,
|
|
9
9
|
} from "../../../core/index.ts";
|
|
10
10
|
import { NEW_ELEMENT_MIME } from "../dnd/drop-target.ts";
|
|
11
|
-
import { FIELD } from "../../ui.ts";
|
|
11
|
+
import { BUTTON, FIELD } from "../../ui.ts";
|
|
12
|
+
import { isCancelEscape } from "../ime.ts";
|
|
13
|
+
import { matchesSearch } from "../../search.ts";
|
|
12
14
|
import { dragStash } from "../dnd/drag-stash.ts";
|
|
13
15
|
|
|
14
16
|
const GROUPS = [
|
|
@@ -33,29 +35,48 @@ export function AddPanel({
|
|
|
33
35
|
formsAvailable?: boolean;
|
|
34
36
|
}) {
|
|
35
37
|
const [query, setQuery] = React.useState(defaultQuery);
|
|
36
|
-
const
|
|
38
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
39
|
+
const clear = () => {
|
|
40
|
+
setQuery("");
|
|
41
|
+
searchRef.current?.focus();
|
|
42
|
+
};
|
|
37
43
|
const matched = ELEMENT_DESCRIPTORS.filter(
|
|
38
44
|
(d) =>
|
|
39
45
|
d.type !== "tab-panel" &&
|
|
40
46
|
(formsAvailable || d.group !== "form") &&
|
|
41
|
-
(
|
|
47
|
+
matchesSearch(query, d.name, d.group),
|
|
42
48
|
);
|
|
43
49
|
const recipes = onRecipe
|
|
44
|
-
? SECTION_RECIPES.filter(
|
|
45
|
-
(r) => !q || `${r.name} ${r.description} recipe section`.toLowerCase().includes(q),
|
|
46
|
-
)
|
|
50
|
+
? SECTION_RECIPES.filter((r) => matchesSearch(query, r.name, r.description, "recipe section"))
|
|
47
51
|
: [];
|
|
48
52
|
return (
|
|
49
53
|
<div className="emvb-panel-body" data-emvb-panel="add">
|
|
54
|
+
{/* UX-053: named like the other searches; a visible heading only repeated the placeholder. */}
|
|
50
55
|
<Input
|
|
51
|
-
label="Search elements"
|
|
56
|
+
aria-label="Search elements"
|
|
57
|
+
type="search"
|
|
52
58
|
className={FIELD}
|
|
59
|
+
ref={searchRef}
|
|
53
60
|
value={query}
|
|
54
61
|
onChange={(event) => setQuery(event.target.value)}
|
|
55
|
-
|
|
62
|
+
onKeyDown={(event) => {
|
|
63
|
+
// UX-013: Escape clears a search first, as Site styles searches do.
|
|
64
|
+
if (isCancelEscape(event) && query) {
|
|
65
|
+
event.stopPropagation();
|
|
66
|
+
setQuery("");
|
|
67
|
+
}
|
|
68
|
+
}}
|
|
69
|
+
placeholder="Search elements…"
|
|
56
70
|
/>
|
|
57
71
|
{matched.length === 0 && recipes.length === 0 ? (
|
|
58
|
-
<
|
|
72
|
+
<div className="emvb-add-nomatch" data-emvb-add-nomatch="">
|
|
73
|
+
<p className="emvb-helper" role="status">
|
|
74
|
+
No elements match "{query.trim()}".
|
|
75
|
+
</p>
|
|
76
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={clear}>
|
|
77
|
+
Clear search
|
|
78
|
+
</Button>
|
|
79
|
+
</div>
|
|
59
80
|
) : (
|
|
60
81
|
GROUPS.map((group) => {
|
|
61
82
|
const tiles = matched.filter((d) => d.group === group.id);
|
|
@@ -72,6 +93,10 @@ export function AddPanel({
|
|
|
72
93
|
type="button"
|
|
73
94
|
className="emvb-element-tile"
|
|
74
95
|
data-emvb-add-tile={tile.type}
|
|
96
|
+
// UX-029: the JS badge is drawn for sighted users; this says the same aloud.
|
|
97
|
+
aria-description={
|
|
98
|
+
typeMayAddScript(tile.type) ? "Adds a small script to the page" : undefined
|
|
99
|
+
}
|
|
75
100
|
draggable
|
|
76
101
|
onDragStart={(event) => {
|
|
77
102
|
event.dataTransfer.setData(NEW_ELEMENT_MIME, tile.type);
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type StyleProps,
|
|
28
28
|
} from "../../../core/index.ts";
|
|
29
29
|
import { FIELD } from "../../ui.ts";
|
|
30
|
+
import { useEditedNoun } from "../edited-noun.ts";
|
|
30
31
|
import {
|
|
31
32
|
CreateRow,
|
|
32
33
|
matches,
|
|
@@ -86,7 +87,7 @@ function ClassStyleEditor({
|
|
|
86
87
|
}: {
|
|
87
88
|
cls: NonNullable<DesignSystem["classes"]>[number];
|
|
88
89
|
design: DesignSystem;
|
|
89
|
-
onSave: (design: DesignSystem) => Promise<void>;
|
|
90
|
+
onSave: (design: DesignSystem) => Promise<boolean | void>;
|
|
90
91
|
}) {
|
|
91
92
|
const [state, setState] = React.useState<StyleStateChoice>("normal");
|
|
92
93
|
const [section, setSection] = React.useState<StyleSectionId>("layout");
|
|
@@ -125,7 +126,7 @@ function ClassStyleEditor({
|
|
|
125
126
|
: patchClassState(design, cls.id, state, patch),
|
|
126
127
|
)
|
|
127
128
|
}
|
|
128
|
-
onDesignChange={onSave}
|
|
129
|
+
onDesignChange={async (next) => void (await onSave(next))}
|
|
129
130
|
/>
|
|
130
131
|
))}
|
|
131
132
|
</div>
|
|
@@ -143,9 +144,10 @@ export function ClassesSection({
|
|
|
143
144
|
}: {
|
|
144
145
|
design: DesignSystem;
|
|
145
146
|
layout: Layout | null;
|
|
146
|
-
onSave: (design: DesignSystem) => Promise<void>;
|
|
147
|
+
onSave: (design: DesignSystem) => Promise<boolean | void>;
|
|
147
148
|
onAskDelete: (id: string, name: string) => void;
|
|
148
149
|
}) {
|
|
150
|
+
const noun = useEditedNoun();
|
|
149
151
|
const classes = design.classes ?? [];
|
|
150
152
|
const [creating, setCreating] = React.useState(false);
|
|
151
153
|
const [name, setName] = React.useState("");
|
|
@@ -154,6 +156,12 @@ export function ClassesSection({
|
|
|
154
156
|
const [filter, setFilter] = React.useState("");
|
|
155
157
|
const [nameError, setNameError] = React.useState<string | null>(null);
|
|
156
158
|
const rows = React.useRef(new Map<string, HTMLButtonElement>());
|
|
159
|
+
// W-840: the create row goes away on Create or Cancel; focus lands on the new row or on New.
|
|
160
|
+
const section = React.useRef<HTMLElement | null>(null);
|
|
161
|
+
const focusNew = () =>
|
|
162
|
+
requestAnimationFrame(() =>
|
|
163
|
+
section.current?.querySelector<HTMLButtonElement>(".emvb-site-section-head button")?.focus(),
|
|
164
|
+
);
|
|
157
165
|
|
|
158
166
|
const q = filter.trim().toLowerCase();
|
|
159
167
|
const visible = q
|
|
@@ -174,10 +182,12 @@ export function ClassesSection({
|
|
|
174
182
|
classes.map((c) => c.id),
|
|
175
183
|
);
|
|
176
184
|
const next = { id, name: trimmed, style: {} as StyleProps };
|
|
177
|
-
|
|
185
|
+
// W-610: a failed save keeps the row and what was typed, so it can be retried.
|
|
186
|
+
if ((await onSave({ ...design, classes: [...classes, next] })) === false) return;
|
|
178
187
|
setCreating(false);
|
|
179
188
|
setName("");
|
|
180
189
|
setEditing(id);
|
|
190
|
+
requestAnimationFrame(() => rows.current.get(id)?.focus());
|
|
181
191
|
};
|
|
182
192
|
|
|
183
193
|
const rename = (id: string, next: string | null) => {
|
|
@@ -192,7 +202,7 @@ export function ClassesSection({
|
|
|
192
202
|
};
|
|
193
203
|
|
|
194
204
|
return (
|
|
195
|
-
<section className="emvb-site-section" data-emvb-classes="">
|
|
205
|
+
<section ref={section} className="emvb-site-section" data-emvb-classes="">
|
|
196
206
|
<p className="emvb-helper emvb-site-cascade" data-emvb-cascade-help="">
|
|
197
207
|
When two classes set the same property, the one lower in this list wins. Local styles on an
|
|
198
208
|
element still win. Editing a class updates every element that uses it. Tablet and mobile
|
|
@@ -209,7 +219,7 @@ export function ClassesSection({
|
|
|
209
219
|
This site has 100 classes, the most allowed. Delete one to add another.
|
|
210
220
|
</p>
|
|
211
221
|
) : null}
|
|
212
|
-
{classes.length > 3 && (
|
|
222
|
+
{(classes.length > 3 || filter.length > 0) && (
|
|
213
223
|
<SiteSearch label="Search classes" value={filter} onChange={setFilter} />
|
|
214
224
|
)}
|
|
215
225
|
{classes.length === 0 && !creating && (
|
|
@@ -291,7 +301,7 @@ export function ClassesSection({
|
|
|
291
301
|
)}
|
|
292
302
|
<span
|
|
293
303
|
className="emvb-site-usage"
|
|
294
|
-
title={`Used by ${count} ${count === 1 ? "element" : "elements"} on this
|
|
304
|
+
title={`Used by ${count} ${count === 1 ? "element" : "elements"} on this ${noun}`}
|
|
295
305
|
data-emvb-usage=""
|
|
296
306
|
>
|
|
297
307
|
{usageText(count)}
|
|
@@ -360,6 +370,7 @@ export function ClassesSection({
|
|
|
360
370
|
onCancel={() => {
|
|
361
371
|
setCreating(false);
|
|
362
372
|
setNameError(null);
|
|
373
|
+
focusNew();
|
|
363
374
|
}}
|
|
364
375
|
onCreate={() => void create()}
|
|
365
376
|
>
|