@perkyzz/emvb 0.6.0 → 0.8.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/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +7 -7
- 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/DialogCloseButton.tsx +16 -0
- package/src/admin/editor/Editor.tsx +115 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +92 -73
- package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
- package/src/admin/editor/ShareLink.tsx +102 -72
- package/src/admin/editor/ShortcutsDialog.tsx +37 -18
- package/src/admin/editor/Timeline.tsx +250 -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 +41 -28
- 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 +43 -7
- package/src/admin/editor/editor-commands.ts +17 -2
- package/src/admin/editor/editor-css.ts +75 -24
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +56 -14
- package/src/admin/editor/focus-when-lost.ts +23 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
- 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 +27 -3
- package/src/admin/editor/panels/AddPanel.tsx +44 -11
- 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 +61 -20
- package/src/admin/editor/panels/LeftPanel.tsx +9 -1
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
- package/src/admin/editor/panels/TokenScales.tsx +88 -48
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +23 -29
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
- 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 +33 -13
- 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/LoopItemBindControl.tsx +1 -1
- 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 +31 -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/editor/useSavedSections.ts +197 -0
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/Canvas.tsx +61 -17
- 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 +179 -8
- 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 +15 -10
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +69 -19
- package/src/admin/image-editor/save.ts +54 -8
- 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 +59 -11
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/saved-sections-api.ts +51 -0
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +16 -5
- package/src/admin/ui.ts +82 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +41 -9
- 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 +196 -24
- package/src/core/arrange.ts +48 -12
- 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/css/print.ts +5 -0
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +39 -16
- package/src/core/design/devices.ts +7 -13
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/states.ts +7 -13
- 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 +53 -14
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +84 -39
- package/src/core/elements/menu.ts +40 -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/animation-runs.ts +11 -0
- 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 +35 -1
- package/src/core/limits.ts +12 -1
- package/src/core/migrate/index.ts +3 -0
- 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 +44 -8
- 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 +29 -8
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/saved-sections.ts +318 -0
- package/src/core/schema/design.ts +1 -1
- package/src/core/schema/layout.ts +16 -7
- package/src/core/schema/style.ts +4 -2
- 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 +12 -2
- package/src/core/theme/pagination.ts +50 -29
- package/src/core/theme/part-types.ts +4 -4
- 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/ports.ts +22 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +15 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/sections.ts +183 -0
- package/src/mcp/tools.ts +44 -0
- package/src/mcp/write.ts +178 -14
- 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 +8 -1
- package/src/server/plugin.ts +14 -0
- package/src/server/saved-sections.ts +163 -0
|
@@ -9,8 +9,10 @@ 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";
|
|
15
|
+
import { DialogCloseButton } from "../DialogCloseButton.tsx";
|
|
14
16
|
|
|
15
17
|
/** Grid geometry, in px. Tiles stretch to fill the row; this is their narrowest. */
|
|
16
18
|
const TILE_MIN_WIDTH = 96;
|
|
@@ -221,7 +223,7 @@ function IconGrid({
|
|
|
221
223
|
if (event.target === event.currentTarget && active < 0 && icons.length > 0) onCursor(0);
|
|
222
224
|
}}
|
|
223
225
|
onKeyDown={(event) => {
|
|
224
|
-
if (event
|
|
226
|
+
if (isCommitEnter(event)) {
|
|
225
227
|
const icon = icons[active];
|
|
226
228
|
if (icon) {
|
|
227
229
|
event.preventDefault();
|
|
@@ -249,11 +251,13 @@ function IconGrid({
|
|
|
249
251
|
function IconLibrary({
|
|
250
252
|
currentId,
|
|
251
253
|
fetcher,
|
|
254
|
+
loadSet,
|
|
252
255
|
onInsert,
|
|
253
256
|
}: {
|
|
254
257
|
currentId: string | undefined;
|
|
255
258
|
/** With a fetcher, My uploads lists and adds uploaded SVGs (W-239). */
|
|
256
259
|
fetcher?: Fetcher;
|
|
260
|
+
loadSet?: typeof loadIconSet;
|
|
257
261
|
onInsert: (icon: LibraryIcon) => void;
|
|
258
262
|
}) {
|
|
259
263
|
const {
|
|
@@ -286,7 +290,8 @@ function IconLibrary({
|
|
|
286
290
|
uploadId,
|
|
287
291
|
renameUpload,
|
|
288
292
|
deleteUpload,
|
|
289
|
-
} = useIconLibrary({ currentId, fetcher });
|
|
293
|
+
} = useIconLibrary({ currentId, fetcher, loadSet });
|
|
294
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
290
295
|
return (
|
|
291
296
|
<div className="emvb-icon-library" data-emvb-dialog="icon-library">
|
|
292
297
|
<header className="emvb-icon-library-head">
|
|
@@ -354,15 +359,17 @@ function IconLibrary({
|
|
|
354
359
|
aria-hidden="true"
|
|
355
360
|
/>
|
|
356
361
|
<input
|
|
362
|
+
ref={searchRef}
|
|
357
363
|
id={searchId}
|
|
358
364
|
type="search"
|
|
359
|
-
// The dialog opens straight into the search, like a command palette.
|
|
365
|
+
// The dialog opens straight into the search, like a command palette.
|
|
360
366
|
autoFocus
|
|
361
367
|
value={query}
|
|
362
368
|
placeholder={`Search ${category.id === ALL_ICONS ? "all icons" : category.label}…`}
|
|
363
369
|
onChange={(event) => setQuery(event.target.value)}
|
|
364
370
|
onKeyDown={(event) => {
|
|
365
|
-
|
|
371
|
+
// W-682: not the Enter that confirms an IME word (W-606).
|
|
372
|
+
if ((event.key === "ArrowDown" || isCommitEnter(event)) && filtered.length > 0) {
|
|
366
373
|
event.preventDefault();
|
|
367
374
|
if (active < 0) setActive(0);
|
|
368
375
|
gridRef.current?.focus();
|
|
@@ -380,11 +387,18 @@ function IconLibrary({
|
|
|
380
387
|
size="sm"
|
|
381
388
|
className={BUTTON}
|
|
382
389
|
icon={<UploadSimpleIcon aria-hidden="true" />}
|
|
383
|
-
disabled
|
|
390
|
+
// W-827: focusable while uploading (aria-disabled, press ignored); disabling it
|
|
391
|
+
// dropped keyboard focus out of the modal to the page body.
|
|
392
|
+
aria-disabled={uploading}
|
|
384
393
|
data-emvb-icon-upload-btn=""
|
|
385
|
-
onClick={() =>
|
|
394
|
+
onClick={() => {
|
|
395
|
+
if (!uploading) fileRef.current?.click();
|
|
396
|
+
}}
|
|
386
397
|
>
|
|
387
|
-
|
|
398
|
+
<span className="emvb-icon-upload-label">
|
|
399
|
+
<span aria-hidden={uploading}>Upload SVG</span>
|
|
400
|
+
<span aria-hidden={!uploading}>Uploading…</span>
|
|
401
|
+
</span>
|
|
388
402
|
</Button>
|
|
389
403
|
<input
|
|
390
404
|
ref={fileRef}
|
|
@@ -399,7 +413,8 @@ function IconLibrary({
|
|
|
399
413
|
<span
|
|
400
414
|
className="emvb-helper"
|
|
401
415
|
data-emvb-icon-upload-note={uploadNote ? (uploadNote.error ? "error" : "ok") : ""}
|
|
402
|
-
role={uploadNote
|
|
416
|
+
role={uploadNote ? (uploadNote.error ? "alert" : "status") : undefined}
|
|
417
|
+
aria-live={uploadNote?.error ? "assertive" : "polite"}
|
|
403
418
|
>
|
|
404
419
|
{uploadNote?.text ??
|
|
405
420
|
"Up to 256 KB. Scripts, event handlers and outside images are removed or refused; the icon is saved with the page."}
|
|
@@ -414,6 +429,8 @@ function IconLibrary({
|
|
|
414
429
|
size="sm"
|
|
415
430
|
className={BUTTON}
|
|
416
431
|
onClick={() => {
|
|
432
|
+
// W-747: this button unmounts on retry; keep focus in the dialog.
|
|
433
|
+
searchRef.current?.focus();
|
|
417
434
|
setUploadsFailed(undefined);
|
|
418
435
|
setAttempt((n) => n + 1);
|
|
419
436
|
}}
|
|
@@ -428,7 +445,11 @@ function IconLibrary({
|
|
|
428
445
|
variant="secondary"
|
|
429
446
|
size="sm"
|
|
430
447
|
className={BUTTON}
|
|
431
|
-
onClick={() =>
|
|
448
|
+
onClick={() => {
|
|
449
|
+
// W-749: this button unmounts on retry; keep focus in the dialog.
|
|
450
|
+
searchRef.current?.focus();
|
|
451
|
+
setAttempt((n) => n + 1);
|
|
452
|
+
}}
|
|
432
453
|
>
|
|
433
454
|
Try again
|
|
434
455
|
</Button>
|
|
@@ -440,6 +461,19 @@ function IconLibrary({
|
|
|
440
461
|
) : filtered.length === 0 ? (
|
|
441
462
|
<div className="emvb-icon-library-empty">
|
|
442
463
|
<p>{status}</p>
|
|
464
|
+
{query.trim() && (
|
|
465
|
+
<Button
|
|
466
|
+
variant="secondary"
|
|
467
|
+
size="sm"
|
|
468
|
+
className={BUTTON}
|
|
469
|
+
onClick={() => {
|
|
470
|
+
setQuery("");
|
|
471
|
+
searchRef.current?.focus();
|
|
472
|
+
}}
|
|
473
|
+
>
|
|
474
|
+
Clear search
|
|
475
|
+
</Button>
|
|
476
|
+
)}
|
|
443
477
|
</div>
|
|
444
478
|
) : (
|
|
445
479
|
<IconGrid
|
|
@@ -502,13 +536,7 @@ function IconLibrary({
|
|
|
502
536
|
</Button>
|
|
503
537
|
</>
|
|
504
538
|
)}
|
|
505
|
-
<
|
|
506
|
-
render={(props) => (
|
|
507
|
-
<Button {...props} variant="secondary" className={BUTTON}>
|
|
508
|
-
Close
|
|
509
|
-
</Button>
|
|
510
|
-
)}
|
|
511
|
-
/>
|
|
539
|
+
<DialogCloseButton>Close</DialogCloseButton>
|
|
512
540
|
<Button
|
|
513
541
|
variant="primary"
|
|
514
542
|
className={`${BUTTON} ${SOLID_PRIMARY}`}
|
|
@@ -535,6 +563,7 @@ export function IconLibraryDialog({
|
|
|
535
563
|
onOpenChange,
|
|
536
564
|
currentId,
|
|
537
565
|
fetcher,
|
|
566
|
+
loadSet,
|
|
538
567
|
onInsert,
|
|
539
568
|
onClosed,
|
|
540
569
|
}: {
|
|
@@ -543,6 +572,8 @@ export function IconLibraryDialog({
|
|
|
543
572
|
currentId: string | undefined;
|
|
544
573
|
/** Enables My uploads (W-239). */
|
|
545
574
|
fetcher?: Fetcher;
|
|
575
|
+
/** Replaces the icon-set loader (tests: a set that fails to download). */
|
|
576
|
+
loadSet?: typeof loadIconSet;
|
|
546
577
|
onInsert: (icon: LibraryIcon) => void;
|
|
547
578
|
/** After the close animation, once the focus trap has let go: the place to put focus back. */
|
|
548
579
|
onClosed?: () => void;
|
|
@@ -568,6 +599,7 @@ export function IconLibraryDialog({
|
|
|
568
599
|
<IconLibrary
|
|
569
600
|
currentId={currentId}
|
|
570
601
|
fetcher={fetcher}
|
|
602
|
+
loadSet={loadSet}
|
|
571
603
|
onInsert={(icon) => {
|
|
572
604
|
onInsert(icon);
|
|
573
605
|
onOpenChange(false);
|
|
@@ -592,9 +624,13 @@ const ICON_LIBRARY_CSS = `
|
|
|
592
624
|
font-size: 13px; line-height: 18px;
|
|
593
625
|
}
|
|
594
626
|
.emvb-icon-library-upload {
|
|
595
|
-
display:
|
|
627
|
+
display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 12px;
|
|
596
628
|
padding: 10px 16px; border-bottom: 1px solid var(--color-kumo-hairline);
|
|
597
629
|
}
|
|
630
|
+
.emvb-icon-upload-label { display: grid; }
|
|
631
|
+
.emvb-icon-upload-label > span { grid-area: 1 / 1; }
|
|
632
|
+
.emvb-icon-upload-label > span[aria-hidden="true"] { visibility: hidden; }
|
|
633
|
+
.emvb-icon-library-upload [data-emvb-icon-upload-note] { display: flex; align-items: center; min-height: 2lh; }
|
|
598
634
|
.emvb-icon-library-upload [data-emvb-icon-upload-note="error"] { color: var(--text-color-kumo-danger, #b91c1c); }
|
|
599
635
|
.emvb-icon-library-cat[data-uploads] { margin-top: 8px; border-top: 1px solid var(--color-kumo-hairline); padding-top: 8px; }
|
|
600
636
|
.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,
|
|
@@ -17,6 +18,9 @@ export type PaletteActions = {
|
|
|
17
18
|
insert: (type: ElementType) => void;
|
|
18
19
|
/** Adds a section recipe (W-320). */
|
|
19
20
|
insertRecipe?: (id: string) => void;
|
|
21
|
+
/** My sections (W-876), inserted by id. */
|
|
22
|
+
savedSections?: readonly { id: string; name: string; damaged?: true }[];
|
|
23
|
+
insertSaved?: (id: string) => void;
|
|
20
24
|
select: (id: string) => void;
|
|
21
25
|
applyClass: (nodeId: string, classId: string) => void;
|
|
22
26
|
actions: { id: string; label: string; hint?: string; keywords?: string; run: () => void }[];
|
|
@@ -46,12 +50,18 @@ function textOf(node: LayoutNode): string {
|
|
|
46
50
|
const items = props["items"];
|
|
47
51
|
if (Array.isArray(items)) {
|
|
48
52
|
for (const item of items) {
|
|
53
|
+
// W-618: a List's items are plain strings.
|
|
54
|
+
if (typeof item === "string") {
|
|
55
|
+
if (item.trim()) parts.push(item.trim());
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
49
58
|
if (item && typeof item === "object" && "text" in item && typeof item.text === "string") {
|
|
50
59
|
parts.push(item.text.trim());
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
|
-
|
|
63
|
+
// W-556: the whole text, so Find text finds a word near the end of a long paragraph.
|
|
64
|
+
return parts.join(" ").replace(/\s+/g, " ");
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
/** Every palette command for the editor's current state (W-314). */
|
|
@@ -87,6 +97,20 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
|
|
|
87
97
|
});
|
|
88
98
|
}
|
|
89
99
|
}
|
|
100
|
+
const insertSaved = ctx.insertSaved;
|
|
101
|
+
if (insertSaved) {
|
|
102
|
+
for (const section of ctx.savedSections ?? []) {
|
|
103
|
+
if (section.damaged) continue;
|
|
104
|
+
items.push({
|
|
105
|
+
id: `saved:${section.id}`,
|
|
106
|
+
group: "Insert",
|
|
107
|
+
label: `Insert ${section.name}`,
|
|
108
|
+
hint: "My sections",
|
|
109
|
+
keywords: "my sections saved section block template segment",
|
|
110
|
+
run: () => insertSaved(section.id),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
90
114
|
if (ctx.layout) {
|
|
91
115
|
let count = 0;
|
|
92
116
|
const walk = (node: LayoutNode, depth: number): void => {
|
|
@@ -98,7 +122,7 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
|
|
|
98
122
|
id: `layer:${node.id}`,
|
|
99
123
|
group: "Jump to",
|
|
100
124
|
label: depth === 0 ? "Page (root)" : name,
|
|
101
|
-
...(text ? { hint: `“${text
|
|
125
|
+
...(text ? { hint: `“${clipText(text, 40)}”` } : {}),
|
|
102
126
|
keywords: `${node.type} ${text}`,
|
|
103
127
|
run: () => ctx.select(node.id),
|
|
104
128
|
});
|
|
@@ -106,7 +130,7 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
|
|
|
106
130
|
items.push({
|
|
107
131
|
id: `find:${node.id}`,
|
|
108
132
|
group: "Find text",
|
|
109
|
-
label: text.length > 80 ? `${text
|
|
133
|
+
label: text.length > 80 ? `${clipText(text, 77)}…` : text,
|
|
110
134
|
hint: name,
|
|
111
135
|
keywords: text,
|
|
112
136
|
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,8 +8,12 @@ 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";
|
|
15
|
+
import type { SavedSectionActions } from "../useSavedSections.ts";
|
|
16
|
+
import { matchingSections, SavedSectionsGroup } from "./SavedSectionsGroup.tsx";
|
|
13
17
|
|
|
14
18
|
const GROUPS = [
|
|
15
19
|
{ id: "layout", label: "Layout" },
|
|
@@ -21,41 +25,65 @@ const GROUPS = [
|
|
|
21
25
|
export function AddPanel({
|
|
22
26
|
onAdd,
|
|
23
27
|
onRecipe,
|
|
28
|
+
saved,
|
|
24
29
|
defaultQuery = "",
|
|
25
30
|
formsAvailable = true,
|
|
26
31
|
}: {
|
|
27
32
|
onAdd: (type: ElementType) => void;
|
|
28
33
|
/** Adds a section recipe (W-320); without it, recipes are not offered. */
|
|
29
34
|
onRecipe?: (id: string) => void;
|
|
35
|
+
/** My sections (W-876); without it the group is not shown. */
|
|
36
|
+
saved?: SavedSectionActions;
|
|
30
37
|
/** Test-only initial search string. */
|
|
31
38
|
defaultQuery?: string;
|
|
32
39
|
/** Hide the Form group when the forms plugin is missing (W-036). */
|
|
33
40
|
formsAvailable?: boolean;
|
|
34
41
|
}) {
|
|
35
42
|
const [query, setQuery] = React.useState(defaultQuery);
|
|
36
|
-
const
|
|
43
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
44
|
+
const clear = () => {
|
|
45
|
+
setQuery("");
|
|
46
|
+
searchRef.current?.focus();
|
|
47
|
+
};
|
|
37
48
|
const matched = ELEMENT_DESCRIPTORS.filter(
|
|
38
49
|
(d) =>
|
|
39
50
|
d.type !== "tab-panel" &&
|
|
40
51
|
(formsAvailable || d.group !== "form") &&
|
|
41
|
-
(
|
|
52
|
+
matchesSearch(query, d.name, d.group),
|
|
42
53
|
);
|
|
43
54
|
const recipes = onRecipe
|
|
44
|
-
? SECTION_RECIPES.filter(
|
|
45
|
-
(r) => !q || `${r.name} ${r.description} recipe section`.toLowerCase().includes(q),
|
|
46
|
-
)
|
|
55
|
+
? SECTION_RECIPES.filter((r) => matchesSearch(query, r.name, r.description, "recipe section"))
|
|
47
56
|
: [];
|
|
48
57
|
return (
|
|
49
58
|
<div className="emvb-panel-body" data-emvb-panel="add">
|
|
59
|
+
{/* UX-053: named like the other searches; a visible heading only repeated the placeholder. */}
|
|
50
60
|
<Input
|
|
51
|
-
label="Search elements"
|
|
61
|
+
aria-label="Search elements"
|
|
62
|
+
type="search"
|
|
52
63
|
className={FIELD}
|
|
64
|
+
ref={searchRef}
|
|
53
65
|
value={query}
|
|
54
66
|
onChange={(event) => setQuery(event.target.value)}
|
|
55
|
-
|
|
67
|
+
onKeyDown={(event) => {
|
|
68
|
+
// UX-013: Escape clears a search first, as Site styles searches do.
|
|
69
|
+
if (isCancelEscape(event) && query) {
|
|
70
|
+
event.stopPropagation();
|
|
71
|
+
setQuery("");
|
|
72
|
+
}
|
|
73
|
+
}}
|
|
74
|
+
placeholder="Search elements…"
|
|
56
75
|
/>
|
|
57
|
-
{matched.length === 0 &&
|
|
58
|
-
|
|
76
|
+
{matched.length === 0 &&
|
|
77
|
+
recipes.length === 0 &&
|
|
78
|
+
(!saved || matchingSections(saved, query).length === 0) ? (
|
|
79
|
+
<div className="emvb-add-nomatch" data-emvb-add-nomatch="">
|
|
80
|
+
<p className="emvb-helper" role="status">
|
|
81
|
+
No elements match "{query.trim()}".
|
|
82
|
+
</p>
|
|
83
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={clear}>
|
|
84
|
+
Clear search
|
|
85
|
+
</Button>
|
|
86
|
+
</div>
|
|
59
87
|
) : (
|
|
60
88
|
GROUPS.map((group) => {
|
|
61
89
|
const tiles = matched.filter((d) => d.group === group.id);
|
|
@@ -72,6 +100,10 @@ export function AddPanel({
|
|
|
72
100
|
type="button"
|
|
73
101
|
className="emvb-element-tile"
|
|
74
102
|
data-emvb-add-tile={tile.type}
|
|
103
|
+
// UX-029: the JS badge is drawn for sighted users; this says the same aloud.
|
|
104
|
+
aria-description={
|
|
105
|
+
typeMayAddScript(tile.type) ? "Adds a small script to the page" : undefined
|
|
106
|
+
}
|
|
75
107
|
draggable
|
|
76
108
|
onDragStart={(event) => {
|
|
77
109
|
event.dataTransfer.setData(NEW_ELEMENT_MIME, tile.type);
|
|
@@ -121,6 +153,7 @@ export function AddPanel({
|
|
|
121
153
|
</div>
|
|
122
154
|
</div>
|
|
123
155
|
)}
|
|
156
|
+
{saved && <SavedSectionsGroup saved={saved} query={query} />}
|
|
124
157
|
</div>
|
|
125
158
|
);
|
|
126
159
|
}
|
|
@@ -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
|
>
|