@bettercms-ai/kit 4.1.1 → 4.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/dist/adapters/lossy.d.ts +1 -1
- package/dist/adapters/lossy.js +1 -1
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/schema.js +1 -1
- package/dist/adapters/schema.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.js.map +1 -1
- package/dist/controls/index.js +2 -2
- package/dist/controls/media-v16.d.ts +3 -1
- package/dist/controls/media-v16.js +3 -1
- package/dist/controls/media-v16.js.map +1 -1
- package/dist/controls/media.d.ts +5 -1
- package/dist/controls/media.js +25 -7
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/rich-text/block-tool.d.ts +1 -1
- package/dist/controls/rich-text/block-tool.js +1 -1
- package/dist/controls/rich-text/block-tool.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +3 -1
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/catalog.d.ts +26 -3
- package/dist/controls/rich-text/catalog.js +239 -58
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/codec.d.ts +7 -1
- package/dist/controls/rich-text/codec.js +2 -1
- package/dist/controls/rich-text/codec.js.map +1 -1
- package/dist/controls/rich-text/control.js +2 -1
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/dom.js +8 -3
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.d.ts +3 -1
- package/dist/controls/rich-text/editor.js +160 -44
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/rewriteSelection.d.ts +25 -0
- package/dist/controls/rich-text/rewriteSelection.js +28 -0
- package/dist/controls/rich-text/rewriteSelection.js.map +1 -0
- package/dist/controls/rich-text/slash-preview.js +18 -5
- package/dist/controls/rich-text/slash-preview.js.map +1 -1
- package/dist/controls/rich-text/table-grid.js +28 -21
- package/dist/controls/rich-text/table-grid.js.map +1 -1
- package/dist/controls/rich-text/toolbar.d.ts +6 -2
- package/dist/controls/rich-text/toolbar.js +205 -4
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/text.d.ts +1 -1
- package/dist/controls/text.js +10 -7
- package/dist/controls/text.js.map +1 -1
- package/dist/engine/field-shell.js +8 -4
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +9 -2
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.js +4 -3
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +2 -2
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/schema-form.d.ts +2 -0
- package/dist/engine/schema-form.js +2 -0
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/kit.css +6 -32
- package/dist/lib/reduced-motion.d.ts +1 -0
- package/dist/lib/reduced-motion.js +19 -0
- package/dist/lib/reduced-motion.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/theme.css +101 -0
- package/dist/tokens.css +9 -0
- package/dist/ui/content-fields.js +3 -2
- package/dist/ui/content-fields.js.map +1 -1
- package/dist/ui/controls.js +3 -2
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/floating-panel.js +3 -2
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/foundations.js +3 -2
- package/dist/ui/foundations.js.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/ui/inspector.d.ts +23 -5
- package/dist/ui/inspector.js +75 -30
- package/dist/ui/inspector.js.map +1 -1
- package/dist/ui/overlay.js +2 -2
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/tab.js +3 -2
- package/dist/ui/tab.js.map +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,8 @@ export interface CatalogItem {
|
|
|
43
43
|
/** look "v16": what to type in the body to get it ("##", "```"), shown at the end of its row */
|
|
44
44
|
hint?: string;
|
|
45
45
|
}
|
|
46
|
+
/** A key hint as this platform writes it ("⌘⌥0" → "Ctrl+Alt+0" off Apple; Markdown hints are unchanged). */
|
|
47
|
+
export declare const hintText: (hint: string) => string;
|
|
46
48
|
/** The components this field may embed, as the host answered (KitServices.useInsertableComponents). */
|
|
47
49
|
export interface CatalogComponents {
|
|
48
50
|
components: KitInsertableComponent[];
|
|
@@ -62,7 +64,8 @@ export interface CatalogSection {
|
|
|
62
64
|
/**
|
|
63
65
|
* `folder`: the More components view (its way back first, then the components, searched by `query`).
|
|
64
66
|
* `aiOffered`: the "BetterCMS AI" Featured row leads the list (look "v16", the host has an AI command service);
|
|
65
|
-
* `aiView`: its view (the way back, then the seven
|
|
67
|
+
* `aiView`: its view (the way back, then the commands: all seven, or the host's `KitServices.aiCommandKinds` in
|
|
68
|
+
* AI_COMMANDS order; when that leaves none there is no AI row at all).
|
|
66
69
|
*/
|
|
67
70
|
export declare function useCatalog(query: string, allows: (f: RichTextFeature) => boolean, folder?: boolean, own?: CatalogComponents | null, aiOffered?: boolean, aiView?: boolean): {
|
|
68
71
|
sections: CatalogSection[];
|
|
@@ -71,7 +74,19 @@ export declare function useCatalog(query: string, allows: (f: RichTextFeature) =
|
|
|
71
74
|
noMatch: boolean;
|
|
72
75
|
emptyText: string;
|
|
73
76
|
};
|
|
74
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Look "v16" Insert ▾ (prototype content.jsx:1263-1306): no search. "Site blocks · Sections built for this site" first,
|
|
79
|
+
* only when the host has site blocks (its component list has some, or is still loading); then Media; then Data and
|
|
80
|
+
* layout. Rows the field does not allow are left out.
|
|
81
|
+
*/
|
|
82
|
+
export declare function insertCatalog(allows: (f: RichTextFeature) => boolean, lib: CatalogComponents | null): {
|
|
83
|
+
sections: CatalogSection[];
|
|
84
|
+
flat: CatalogItem[];
|
|
85
|
+
empty: boolean;
|
|
86
|
+
noMatch: boolean;
|
|
87
|
+
emptyText: string;
|
|
88
|
+
};
|
|
89
|
+
export declare function CatalogList({ sections, flat, active, onHover, onPick, empty, emptyText, noMatch, detail, listId, className, query, playIcon, onListKeyDown, listRef, }: {
|
|
75
90
|
sections: CatalogSection[];
|
|
76
91
|
flat: CatalogItem[];
|
|
77
92
|
active: number;
|
|
@@ -87,16 +102,24 @@ export declare function CatalogList({ sections, flat, active, onHover, onPick, e
|
|
|
87
102
|
className?: string;
|
|
88
103
|
/** look "v16": the search text, echoed in the empty line (Nothing matches “…”) */
|
|
89
104
|
query?: string;
|
|
105
|
+
/** look "v16": the row whose AI icon plays once now (the row the AI view opens on); hover plays the rest */
|
|
106
|
+
playIcon?: number | null;
|
|
107
|
+
/** a menu with no search box: the list itself takes focus and the keys (it points at the active row) */
|
|
108
|
+
onListKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
|
|
109
|
+
listRef?: React.RefObject<HTMLDivElement | null>;
|
|
90
110
|
}): import("react/jsx-runtime").JSX.Element;
|
|
91
111
|
/** Shared keyboard model: ↑↓ wrap, Home/End, Enter / Tab, → into More components. Returns true when handled. */
|
|
92
112
|
export declare function catalogKey(e: React.KeyboardEvent | KeyboardEvent, flat: CatalogItem[], active: number, setActive: (i: number) => void, pick: (it: CatalogItem) => void, homeEnd?: boolean): boolean;
|
|
93
|
-
export declare function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align, side, }: {
|
|
113
|
+
export declare function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align, side, list, }: {
|
|
94
114
|
onInsert: (it: CatalogItem) => void;
|
|
95
115
|
allows: (f: RichTextFeature) => boolean;
|
|
96
116
|
/** after an insert the caret stays in the editor: the menu gives no focus back to its trigger */
|
|
97
117
|
keepFocusOnClose?: () => boolean;
|
|
98
118
|
align?: "start" | "center" | "end";
|
|
99
119
|
side?: "top" | "bottom" | "left" | "right";
|
|
120
|
+
/** look "v16": "curated" is the toolbar's Insert ▾ (prototype content.jsx:1263-1306: no search, Site blocks, Media,
|
|
121
|
+
* Data and layout); "full" (default) is the whole searchable catalogue. Other looks always show the full one. */
|
|
122
|
+
list?: "full" | "curated";
|
|
100
123
|
}): import("react/jsx-runtime").JSX.Element;
|
|
101
124
|
export declare function SlashMenuPanel({ query, folder, active, setActive, onPick, allows, maxHeight, aiOffered, aiView, }: {
|
|
102
125
|
/** look "v16": the "BetterCMS AI" Featured row is offered (the host has an AI command service) */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { cn } from "../../lib/cn.js";
|
|
2
|
-
import { AI_COMMANDS, useKitLook } from "../../context.js";
|
|
2
|
+
import { AI_COMMANDS, useKitLook, useKitServices } from "../../context.js";
|
|
3
|
+
import { platformKeys } from "../../ui/shortcut-hint.js";
|
|
4
|
+
import { useKitReducedMotion } from "../../lib/reduced-motion.js";
|
|
3
5
|
import { PopoverContent } from "../../ui/overlay.js";
|
|
4
6
|
import { SlashPreviewCard } from "./slash-preview.js";
|
|
5
7
|
import * as React from "react";
|
|
6
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
9
|
import { IconArrowLeft, IconBlockquote, IconChartBar, IconChevronLeft, IconChevronRight, IconClick, IconCode, IconColumns2, IconComponents, IconFileText, IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconInfoCircle, IconLayoutGrid, IconLayoutNavbarCollapse, IconList, IconListCheck, IconListDetails, IconListNumbers, IconListTree, IconNews, IconPhoto, IconPilcrow, IconQuote, IconSearch, IconSeparatorHorizontal, IconSuperscript, IconTable, IconTerminal2, IconUserCircle, IconVideo } from "@tabler/icons-react";
|
|
10
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
8
11
|
//#region src/controls/rich-text/catalog.tsx
|
|
9
12
|
/**
|
|
10
13
|
* RICH TEXT · the block catalogue shared by the toolbar Insert menu, the gutter "+" and the "/" slash menu (V2 HEAD
|
|
@@ -26,8 +29,11 @@ import { IconArrowLeft, IconBlockquote, IconChartBar, IconChevronLeft, IconChevr
|
|
|
26
29
|
* "Components" group (V2: "Article" and "Page sections"), and no live preview flyout is drawn beside a row.
|
|
27
30
|
*/
|
|
28
31
|
var i = (I) => /* @__PURE__ */ jsx(I, { stroke: 1.5 });
|
|
29
|
-
/** The Markdown the editor turns into each block as it is typed (ops.ts liveMarkdown, enterCodeFence)
|
|
32
|
+
/** The Markdown the editor turns into each block as it is typed (ops.ts liveMarkdown, enterCodeFence), or the key that
|
|
33
|
+
* makes it: the row's key hint. Only shortcuts the editor really has: "[] " (checklist.tsx checklistShortcut, when the
|
|
34
|
+
* field allows a checklist; the row is listed only then) and ⌘⌥0 (editor.tsx onKeyDown Digit0, always a paragraph). */
|
|
30
35
|
var HINTS = {
|
|
36
|
+
p: "⌘⌥0",
|
|
31
37
|
h1: "#",
|
|
32
38
|
h2: "##",
|
|
33
39
|
h3: "###",
|
|
@@ -38,8 +44,11 @@ var HINTS = {
|
|
|
38
44
|
ol: "1.",
|
|
39
45
|
quote: ">",
|
|
40
46
|
code: "```",
|
|
41
|
-
hr: "---"
|
|
47
|
+
hr: "---",
|
|
48
|
+
task: "[]"
|
|
42
49
|
};
|
|
50
|
+
/** A key hint as this platform writes it ("⌘⌥0" → "Ctrl+Alt+0" off Apple; Markdown hints are unchanged). */
|
|
51
|
+
var hintText = (hint) => platformKeys(hint);
|
|
43
52
|
var rows = (list) => list.map(([id, label, description, icon, aliases]) => ({
|
|
44
53
|
key: id,
|
|
45
54
|
id,
|
|
@@ -402,6 +411,60 @@ var BACK = {
|
|
|
402
411
|
description: "",
|
|
403
412
|
icon: i(IconArrowLeft)
|
|
404
413
|
};
|
|
414
|
+
var INSERT_MEDIA = [
|
|
415
|
+
[
|
|
416
|
+
"image",
|
|
417
|
+
"Image",
|
|
418
|
+
"Upload or pick from Media"
|
|
419
|
+
],
|
|
420
|
+
[
|
|
421
|
+
"video",
|
|
422
|
+
"Video",
|
|
423
|
+
"YouTube, Vimeo or a file"
|
|
424
|
+
],
|
|
425
|
+
[
|
|
426
|
+
"file",
|
|
427
|
+
"File",
|
|
428
|
+
"A download link"
|
|
429
|
+
]
|
|
430
|
+
];
|
|
431
|
+
var INSERT_DATA = [
|
|
432
|
+
[
|
|
433
|
+
"table",
|
|
434
|
+
"Table",
|
|
435
|
+
"Rows and columns"
|
|
436
|
+
],
|
|
437
|
+
[
|
|
438
|
+
"stats",
|
|
439
|
+
"Stats",
|
|
440
|
+
"Big numbers in a row"
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
"code",
|
|
444
|
+
"Code block",
|
|
445
|
+
"Code with highlighting"
|
|
446
|
+
],
|
|
447
|
+
[
|
|
448
|
+
"callout",
|
|
449
|
+
"Callout",
|
|
450
|
+
"A highlighted note"
|
|
451
|
+
],
|
|
452
|
+
[
|
|
453
|
+
"toggle",
|
|
454
|
+
"Toggle",
|
|
455
|
+
"Hide details under a heading"
|
|
456
|
+
],
|
|
457
|
+
[
|
|
458
|
+
"hr",
|
|
459
|
+
"Divider",
|
|
460
|
+
"A line between parts"
|
|
461
|
+
]
|
|
462
|
+
];
|
|
463
|
+
var SITE_BLOCKS = {
|
|
464
|
+
...MORE,
|
|
465
|
+
label: "Site blocks",
|
|
466
|
+
description: "Sections built for this site"
|
|
467
|
+
};
|
|
405
468
|
var AI_PATHS = {
|
|
406
469
|
ai: [
|
|
407
470
|
["star", "M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"],
|
|
@@ -436,6 +499,21 @@ var DRAWN = /* @__PURE__ */ new Set([
|
|
|
436
499
|
"l3",
|
|
437
500
|
"ck"
|
|
438
501
|
]);
|
|
502
|
+
/** kit-ai-move's offset per stroke (prototype content.css:247-278), set on the path itself: component-local, not a token. */
|
|
503
|
+
var MOVE = {
|
|
504
|
+
"prompt.pen": ["1.7px", "-1.7px"],
|
|
505
|
+
"continue.arr": ["2.5px", "0px"],
|
|
506
|
+
"shorter.tr": ["-1.7px", "1.7px"],
|
|
507
|
+
"shorter.bl": ["1.7px", "-1.7px"],
|
|
508
|
+
"summarize.l1": ["0px", "-1.7px"],
|
|
509
|
+
"summarize.l2": ["0px", "-1.7px"],
|
|
510
|
+
"summarize.l3": ["0px", "-1.7px"],
|
|
511
|
+
"summarize.l4": ["0px", "-1.7px"],
|
|
512
|
+
"summarize.arr": ["0px", "2px"],
|
|
513
|
+
"translate.g": ["-1px", "-1.7px"],
|
|
514
|
+
"translate.a": ["1px", "1.7px"],
|
|
515
|
+
"spelling.a": ["0px", "-1.4px"]
|
|
516
|
+
};
|
|
439
517
|
var AiIcon = ({ n }) => /* @__PURE__ */ jsx("svg", {
|
|
440
518
|
className: `kit-aii kit-aii-${n}`,
|
|
441
519
|
width: "16",
|
|
@@ -447,11 +525,18 @@ var AiIcon = ({ n }) => /* @__PURE__ */ jsx("svg", {
|
|
|
447
525
|
strokeLinecap: "round",
|
|
448
526
|
strokeLinejoin: "round",
|
|
449
527
|
"aria-hidden": true,
|
|
450
|
-
children: AI_PATHS[n].map(([c, d]) =>
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
528
|
+
children: AI_PATHS[n].map(([c, d]) => {
|
|
529
|
+
const move = MOVE[`${n}.${c}`];
|
|
530
|
+
return /* @__PURE__ */ jsx("path", {
|
|
531
|
+
className: c,
|
|
532
|
+
d,
|
|
533
|
+
pathLength: DRAWN.has(c) ? 1 : void 0,
|
|
534
|
+
style: move ? {
|
|
535
|
+
"--dx": move[0],
|
|
536
|
+
"--dy": move[1]
|
|
537
|
+
} : void 0
|
|
538
|
+
}, c);
|
|
539
|
+
})
|
|
455
540
|
});
|
|
456
541
|
/** The slash menu's Featured row: opens the AI view. */
|
|
457
542
|
var AI_ROW = {
|
|
@@ -548,10 +633,14 @@ var rank = (q, list, recent) => list.map((it, i) => {
|
|
|
548
633
|
/**
|
|
549
634
|
* `folder`: the More components view (its way back first, then the components, searched by `query`).
|
|
550
635
|
* `aiOffered`: the "BetterCMS AI" Featured row leads the list (look "v16", the host has an AI command service);
|
|
551
|
-
* `aiView`: its view (the way back, then the seven
|
|
636
|
+
* `aiView`: its view (the way back, then the commands: all seven, or the host's `KitServices.aiCommandKinds` in
|
|
637
|
+
* AI_COMMANDS order; when that leaves none there is no AI row at all).
|
|
552
638
|
*/
|
|
553
639
|
function useCatalog(query, allows, folder = false, own, aiOffered = false, aiView = false) {
|
|
554
640
|
const recent = useRecents();
|
|
641
|
+
const kinds = useKitServices().aiCommandKinds;
|
|
642
|
+
const aiItems = React.useMemo(() => kinds ? AI_ITEMS.filter((it) => kinds.includes(it.ai)) : AI_ITEMS, [kinds]);
|
|
643
|
+
const ai = aiOffered && aiItems.length > 0;
|
|
555
644
|
const provided = React.useContext(ComponentsContext);
|
|
556
645
|
const lib = own === void 0 ? provided : own;
|
|
557
646
|
return React.useMemo(() => {
|
|
@@ -562,12 +651,12 @@ function useCatalog(query, allows, folder = false, own, aiOffered = false, aiVie
|
|
|
562
651
|
let sections;
|
|
563
652
|
let noMatch = false;
|
|
564
653
|
let emptyText = "No match.";
|
|
565
|
-
if (aiView) sections = [{
|
|
654
|
+
if (aiView && ai) sections = [{
|
|
566
655
|
title: null,
|
|
567
656
|
items: [BACK]
|
|
568
657
|
}, {
|
|
569
658
|
title: "BetterCMS AI",
|
|
570
|
-
items:
|
|
659
|
+
items: aiItems
|
|
571
660
|
}];
|
|
572
661
|
else if (folder) {
|
|
573
662
|
const found = q ? rank(q, comps, recent) : comps;
|
|
@@ -582,7 +671,7 @@ function useCatalog(query, allows, folder = false, own, aiOffered = false, aiVie
|
|
|
582
671
|
}];
|
|
583
672
|
} else if (q) {
|
|
584
673
|
const found = rank(q, [
|
|
585
|
-
...
|
|
674
|
+
...ai ? [AI_ROW] : [],
|
|
586
675
|
...keep(TEXT),
|
|
587
676
|
...keep(MEDIA),
|
|
588
677
|
...keep(DATA),
|
|
@@ -598,7 +687,7 @@ function useCatalog(query, allows, folder = false, own, aiOffered = false, aiVie
|
|
|
598
687
|
} else sections = [
|
|
599
688
|
{
|
|
600
689
|
title: "Featured",
|
|
601
|
-
items:
|
|
690
|
+
items: ai ? [AI_ROW] : []
|
|
602
691
|
},
|
|
603
692
|
{
|
|
604
693
|
title: "Text",
|
|
@@ -640,13 +729,56 @@ function useCatalog(query, allows, folder = false, own, aiOffered = false, aiVie
|
|
|
640
729
|
recent,
|
|
641
730
|
lib,
|
|
642
731
|
folder,
|
|
643
|
-
|
|
732
|
+
ai,
|
|
733
|
+
aiItems,
|
|
644
734
|
aiView
|
|
645
735
|
]);
|
|
646
736
|
}
|
|
647
|
-
|
|
737
|
+
/**
|
|
738
|
+
* Look "v16" Insert ▾ (prototype content.jsx:1263-1306): no search. "Site blocks · Sections built for this site" first,
|
|
739
|
+
* only when the host has site blocks (its component list has some, or is still loading); then Media; then Data and
|
|
740
|
+
* layout. Rows the field does not allow are left out.
|
|
741
|
+
*/
|
|
742
|
+
function insertCatalog(allows, lib) {
|
|
743
|
+
const byId = new Map([
|
|
744
|
+
...TEXT,
|
|
745
|
+
...MEDIA,
|
|
746
|
+
...DATA,
|
|
747
|
+
...ARTICLE,
|
|
748
|
+
...SEARCH_ONLY
|
|
749
|
+
].map((it) => [it.id, it]));
|
|
750
|
+
const pick = (list) => list.filter(([id]) => byId.has(id) && blockAllowed(id, allows)).map(([id, label, description]) => ({
|
|
751
|
+
...byId.get(id),
|
|
752
|
+
label,
|
|
753
|
+
description
|
|
754
|
+
}));
|
|
755
|
+
const sections = [
|
|
756
|
+
{
|
|
757
|
+
title: null,
|
|
758
|
+
items: !!lib && (!!lib.components.length || !!lib.loading) ? [SITE_BLOCKS] : []
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
title: "Media",
|
|
762
|
+
items: pick(INSERT_MEDIA)
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
title: "Data and layout",
|
|
766
|
+
items: pick(INSERT_DATA)
|
|
767
|
+
}
|
|
768
|
+
].filter((sec) => sec.items.length);
|
|
769
|
+
const flat = sections.flatMap((sec) => sec.items);
|
|
770
|
+
return {
|
|
771
|
+
sections,
|
|
772
|
+
flat,
|
|
773
|
+
empty: !flat.length,
|
|
774
|
+
noMatch: false,
|
|
775
|
+
emptyText: "This field takes no blocks."
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function CatalogList({ sections, flat, active, onHover, onPick, empty, emptyText = "No match.", noMatch, detail, listId, className, query, playIcon = null, onListKeyDown, listRef }) {
|
|
648
779
|
const v16 = useKitLook() === "v16";
|
|
649
|
-
const
|
|
780
|
+
const own = React.useRef(null);
|
|
781
|
+
const box = listRef ?? own;
|
|
650
782
|
React.useEffect(() => {
|
|
651
783
|
const b = box.current;
|
|
652
784
|
const row = b?.querySelector(`[data-idx="${active}"]`);
|
|
@@ -659,7 +791,12 @@ function CatalogList({ sections, flat, active, onHover, onPick, empty, emptyText
|
|
|
659
791
|
id: listId,
|
|
660
792
|
role: "listbox",
|
|
661
793
|
"aria-label": "Blocks",
|
|
662
|
-
|
|
794
|
+
...onListKeyDown ? {
|
|
795
|
+
tabIndex: -1,
|
|
796
|
+
onKeyDown: onListKeyDown,
|
|
797
|
+
"aria-activedescendant": flat.length ? `${listId}-${active}` : void 0
|
|
798
|
+
} : {},
|
|
799
|
+
className: cn("relative overflow-y-auto", v16 ? "max-h-[344px] px-1 pb-1 [scrollbar-width:thin]" : "max-h-[320px] p-1.5", onListKeyDown && "outline-none", className),
|
|
663
800
|
children: [
|
|
664
801
|
noMatch ? /* @__PURE__ */ jsx("div", {
|
|
665
802
|
className: v16 ? "px-2 py-3 text-[13px] text-kit-group-sub" : "px-2 pb-1 pt-1.5 text-kit-sm text-kit-fg-3",
|
|
@@ -683,6 +820,7 @@ function CatalogList({ sections, flat, active, onHover, onPick, empty, emptyText
|
|
|
683
820
|
"aria-selected": on,
|
|
684
821
|
"aria-disabled": it.disabled ? true : void 0,
|
|
685
822
|
"data-idx": idx,
|
|
823
|
+
"data-aii-entry": idx === playIcon ? "" : void 0,
|
|
686
824
|
id: `${listId}-${idx}`,
|
|
687
825
|
onMouseDown: (e) => e.preventDefault(),
|
|
688
826
|
onMouseMove: () => !on && onHover(idx),
|
|
@@ -724,8 +862,9 @@ function CatalogList({ sections, flat, active, onHover, onPick, empty, emptyText
|
|
|
724
862
|
className: "size-3.5 shrink-0 text-kit-insp-faint",
|
|
725
863
|
stroke: 1.8
|
|
726
864
|
}) : it.hint ? /* @__PURE__ */ jsx("kbd", {
|
|
865
|
+
"data-hint": "shortcuts",
|
|
727
866
|
className: "shrink-0 font-kit-sans text-[12px] leading-4 text-kit-group-sub",
|
|
728
|
-
children: it.hint
|
|
867
|
+
children: hintText(it.hint)
|
|
729
868
|
}) : null
|
|
730
869
|
]
|
|
731
870
|
}, it.key);
|
|
@@ -801,22 +940,32 @@ function catalogKey(e, flat, active, setActive, pick, homeEnd = true) {
|
|
|
801
940
|
}
|
|
802
941
|
return false;
|
|
803
942
|
}
|
|
804
|
-
function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start", side = "bottom" }) {
|
|
943
|
+
function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start", side = "bottom", list = "full" }) {
|
|
805
944
|
const [q, setQ] = React.useState("");
|
|
806
945
|
const [active, setActive] = React.useState(0);
|
|
807
946
|
const input = React.useRef(null);
|
|
947
|
+
const listRef = React.useRef(null);
|
|
808
948
|
const listId = React.useId();
|
|
809
949
|
const [folder, setFolder] = React.useState(false);
|
|
810
|
-
const
|
|
950
|
+
const full = useCatalog(q, allows, folder);
|
|
811
951
|
const v16 = useKitLook() === "v16";
|
|
952
|
+
const curated = v16 && list === "curated";
|
|
953
|
+
const lib = React.useContext(ComponentsContext);
|
|
954
|
+
const { sections, flat, empty, emptyText, noMatch } = React.useMemo(() => curated ? insertCatalog(allows, lib) : null, [
|
|
955
|
+
curated,
|
|
956
|
+
allows,
|
|
957
|
+
lib
|
|
958
|
+
]) ?? full;
|
|
959
|
+
const reduce = !!useKitReducedMotion();
|
|
812
960
|
const [sideOpen, setSideOpen] = React.useState(false);
|
|
813
961
|
const [sideFlip, setSideFlip] = React.useState(false);
|
|
814
|
-
const sideRef = React.useCallback((el) => {
|
|
815
|
-
const menu = el?.parentElement;
|
|
816
|
-
if (!menu) return;
|
|
817
|
-
setSideFlip(menu.getBoundingClientRect().right + 6 + 300 > window.innerWidth - 8);
|
|
818
|
-
}, []);
|
|
819
962
|
const [sActive, setSActive] = React.useState(0);
|
|
963
|
+
const openSide = () => {
|
|
964
|
+
const menu = document.getElementById(listId)?.parentElement;
|
|
965
|
+
if (menu) setSideFlip(menu.getBoundingClientRect().right + 6 + 300 > window.innerWidth - 8);
|
|
966
|
+
setSideOpen(true);
|
|
967
|
+
setSActive(0);
|
|
968
|
+
};
|
|
820
969
|
const sideCat = useCatalog("", allows, true);
|
|
821
970
|
const sideFlat = sideCat.flat.filter((it) => it.kind !== "back");
|
|
822
971
|
const sideId = React.useId();
|
|
@@ -828,21 +977,39 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
828
977
|
input.current?.focus();
|
|
829
978
|
};
|
|
830
979
|
const pick = (it) => {
|
|
831
|
-
if (it.kind === "folder" && useSide)
|
|
832
|
-
|
|
833
|
-
setSActive(0);
|
|
834
|
-
} else if (it.kind === "folder") {
|
|
980
|
+
if (it.kind === "folder" && useSide) openSide();
|
|
981
|
+
else if (it.kind === "folder") {
|
|
835
982
|
setFolder(true);
|
|
836
983
|
setQ("");
|
|
837
984
|
input.current?.focus();
|
|
838
985
|
} else if (it.kind === "back") leave();
|
|
839
986
|
else onInsert(it);
|
|
840
987
|
};
|
|
988
|
+
const onKey = (e) => {
|
|
989
|
+
if (useSide && sideOpen) {
|
|
990
|
+
if (e.key === "ArrowLeft") {
|
|
991
|
+
e.preventDefault();
|
|
992
|
+
setSideOpen(false);
|
|
993
|
+
} else if (catalogKey(e, sideFlat, sActive, setSActive, pick, true)) e.preventDefault();
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (useSide && e.key === "ArrowRight" && flat[active]?.kind === "folder") {
|
|
997
|
+
e.preventDefault();
|
|
998
|
+
openSide();
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (folder && e.key === "Backspace" && !q) {
|
|
1002
|
+
e.preventDefault();
|
|
1003
|
+
e.stopPropagation();
|
|
1004
|
+
leave();
|
|
1005
|
+
} else if (catalogKey(e, flat, active, setActive, pick, !q)) e.preventDefault();
|
|
1006
|
+
};
|
|
1007
|
+
const sideX = reduce ? 0 : sideFlip ? 4 : -4;
|
|
841
1008
|
return /* @__PURE__ */ jsxs(PopoverContent, {
|
|
842
1009
|
side,
|
|
843
1010
|
align,
|
|
844
1011
|
className: v16 ? "relative flex max-h-[420px] w-[280px] flex-col rounded-[10px] !border-0 !bg-kit-insp-tip-bg p-0 !shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_12px_28px_rgb(0_0_0/0.12)] ![backdrop-filter:none]" : "flex max-h-[420px] w-[320px] flex-col overflow-hidden p-0",
|
|
845
|
-
initialFocus: input,
|
|
1012
|
+
initialFocus: curated ? listRef : input,
|
|
846
1013
|
finalFocus: keepFocusOnClose ? () => !keepFocusOnClose() : void 0,
|
|
847
1014
|
onKeyDownCapture: (e) => {
|
|
848
1015
|
if (useSide && sideOpen && e.key === "Escape") {
|
|
@@ -857,7 +1024,7 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
857
1024
|
leave();
|
|
858
1025
|
},
|
|
859
1026
|
children: [
|
|
860
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1027
|
+
curated ? null : /* @__PURE__ */ jsxs("div", {
|
|
861
1028
|
className: cn("flex h-10 shrink-0 items-center gap-2 border-b px-3", v16 ? "border-kit-insp-divider" : "border-kit-line"),
|
|
862
1029
|
children: [/* @__PURE__ */ jsx(IconSearch, {
|
|
863
1030
|
className: v16 ? "size-3.5 shrink-0 text-kit-group-sub" : "size-4 shrink-0 text-kit-fg-3",
|
|
@@ -867,26 +1034,7 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
867
1034
|
ref: input,
|
|
868
1035
|
value: q,
|
|
869
1036
|
onChange: (e) => setQ(e.target.value),
|
|
870
|
-
onKeyDown:
|
|
871
|
-
if (useSide && sideOpen) {
|
|
872
|
-
if (e.key === "ArrowLeft") {
|
|
873
|
-
e.preventDefault();
|
|
874
|
-
setSideOpen(false);
|
|
875
|
-
} else if (catalogKey(e, sideFlat, sActive, setSActive, pick, true)) e.preventDefault();
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
if (useSide && e.key === "ArrowRight" && flat[active]?.kind === "folder") {
|
|
879
|
-
e.preventDefault();
|
|
880
|
-
setSideOpen(true);
|
|
881
|
-
setSActive(0);
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
|
-
if (folder && e.key === "Backspace" && !q) {
|
|
885
|
-
e.preventDefault();
|
|
886
|
-
e.stopPropagation();
|
|
887
|
-
leave();
|
|
888
|
-
} else if (catalogKey(e, flat, active, setActive, pick, !q)) e.preventDefault();
|
|
889
|
-
},
|
|
1037
|
+
onKeyDown: onKey,
|
|
890
1038
|
role: "combobox",
|
|
891
1039
|
"aria-expanded": true,
|
|
892
1040
|
"aria-controls": listId,
|
|
@@ -902,7 +1050,9 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
902
1050
|
active,
|
|
903
1051
|
onHover: (i) => {
|
|
904
1052
|
setActive(i);
|
|
905
|
-
if (useSide)
|
|
1053
|
+
if (!useSide) return;
|
|
1054
|
+
if (flat[i]?.kind !== "folder") setSideOpen(false);
|
|
1055
|
+
else if (!sideOpen) openSide();
|
|
906
1056
|
},
|
|
907
1057
|
onPick: pick,
|
|
908
1058
|
empty,
|
|
@@ -911,14 +1061,37 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
911
1061
|
detail: !!q || folder,
|
|
912
1062
|
listId,
|
|
913
1063
|
query: q,
|
|
914
|
-
className: "min-h-0 flex-1"
|
|
1064
|
+
className: cn("min-h-0 flex-1", curated && "pt-1"),
|
|
1065
|
+
...curated ? {
|
|
1066
|
+
onListKeyDown: onKey,
|
|
1067
|
+
listRef
|
|
1068
|
+
} : {}
|
|
915
1069
|
}),
|
|
916
1070
|
v16 ? null : /* @__PURE__ */ jsx(Footer, {}),
|
|
917
|
-
useSide && sideOpen ? /* @__PURE__ */ jsx(
|
|
918
|
-
ref: sideRef,
|
|
1071
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: useSide && sideOpen ? /* @__PURE__ */ jsx(motion.div, {
|
|
919
1072
|
role: "menu",
|
|
920
1073
|
"aria-label": "Blocks for this site",
|
|
921
|
-
|
|
1074
|
+
initial: {
|
|
1075
|
+
opacity: 0,
|
|
1076
|
+
x: sideX
|
|
1077
|
+
},
|
|
1078
|
+
animate: {
|
|
1079
|
+
opacity: 1,
|
|
1080
|
+
x: 0,
|
|
1081
|
+
transition: {
|
|
1082
|
+
duration: .15,
|
|
1083
|
+
ease: "easeOut"
|
|
1084
|
+
}
|
|
1085
|
+
},
|
|
1086
|
+
exit: {
|
|
1087
|
+
opacity: 0,
|
|
1088
|
+
x: sideX,
|
|
1089
|
+
transition: {
|
|
1090
|
+
duration: .1,
|
|
1091
|
+
ease: "easeIn"
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
className: cn("absolute top-0 flex max-h-[420px] w-[300px] flex-col overflow-hidden rounded-[10px] bg-kit-insp-tip-bg shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_12px_28px_rgb(0_0_0/0.12)]", sideFlip ? "right-full mr-1.5" : "left-full ml-1.5"),
|
|
922
1095
|
children: /* @__PURE__ */ jsx(CatalogList, {
|
|
923
1096
|
sections: [{
|
|
924
1097
|
title: "Blocks for this site",
|
|
@@ -934,7 +1107,7 @@ function InsertMenuContent({ onInsert, allows, keepFocusOnClose, align = "start"
|
|
|
934
1107
|
listId: sideId,
|
|
935
1108
|
className: "min-h-0 flex-1"
|
|
936
1109
|
})
|
|
937
|
-
}) : null
|
|
1110
|
+
}, "side") : null })
|
|
938
1111
|
]
|
|
939
1112
|
});
|
|
940
1113
|
}
|
|
@@ -942,6 +1115,13 @@ function SlashMenuPanel({ query, folder = false, active, setActive, onPick, allo
|
|
|
942
1115
|
const listId = React.useId();
|
|
943
1116
|
const { sections, flat, empty, emptyText, noMatch } = useCatalog(query, allows, folder, void 0, aiOffered, aiView);
|
|
944
1117
|
const v16 = useKitLook() === "v16";
|
|
1118
|
+
const reduce = !!useKitReducedMotion();
|
|
1119
|
+
const [wasAi, setWasAi] = React.useState(aiView);
|
|
1120
|
+
const [aiEntry, setAiEntry] = React.useState(null);
|
|
1121
|
+
if (wasAi !== aiView) {
|
|
1122
|
+
setWasAi(aiView);
|
|
1123
|
+
setAiEntry(aiView && !reduce ? active : null);
|
|
1124
|
+
}
|
|
945
1125
|
const panelRef = React.useRef(null);
|
|
946
1126
|
const [pvTop, setPvTop] = React.useState(0);
|
|
947
1127
|
React.useLayoutEffect(() => {
|
|
@@ -990,6 +1170,7 @@ function SlashMenuPanel({ query, folder = false, active, setActive, onPick, allo
|
|
|
990
1170
|
detail: true,
|
|
991
1171
|
listId,
|
|
992
1172
|
query,
|
|
1173
|
+
playIcon: aiEntry,
|
|
993
1174
|
className: "min-h-0 flex-1"
|
|
994
1175
|
})]
|
|
995
1176
|
}), /* @__PURE__ */ jsx(SlashPreviewCard, {
|
|
@@ -1032,6 +1213,6 @@ function SlashMenuPanel({ query, folder = false, active, setActive, onPick, allo
|
|
|
1032
1213
|
});
|
|
1033
1214
|
}
|
|
1034
1215
|
//#endregion
|
|
1035
|
-
export { CatalogComponentsProvider, CatalogList, InsertMenuContent, SlashMenuPanel, blockAllowed, catalogKey, noteRecent, useCatalog, useCatalogComponents };
|
|
1216
|
+
export { CatalogComponentsProvider, CatalogList, InsertMenuContent, SlashMenuPanel, blockAllowed, catalogKey, hintText, insertCatalog, noteRecent, useCatalog, useCatalogComponents };
|
|
1036
1217
|
|
|
1037
1218
|
//# sourceMappingURL=catalog.js.map
|