@kidecms/core 0.1.11 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/admin/components/AssetsGrid.tsx +366 -173
- package/admin/components/BlockEditor.tsx +260 -679
- package/admin/components/CheckboxField.tsx +2 -2
- package/admin/components/CollaborationReviewBar.tsx +384 -0
- package/admin/components/ColorField.tsx +87 -0
- package/admin/components/CommandPalette.tsx +169 -0
- package/admin/components/ContentEditor.tsx +687 -0
- package/admin/components/DocumentActions.tsx +4 -2
- package/admin/components/DocumentsDataTable.tsx +91 -10
- package/admin/components/FieldControl.astro +151 -26
- package/admin/components/FocalPointSelector.tsx +27 -1
- package/admin/components/InternalLinkPicker.tsx +4 -3
- package/admin/components/LinkField.tsx +126 -0
- package/admin/components/RelationField.tsx +105 -26
- package/admin/components/RepeaterInput.tsx +46 -0
- package/admin/components/RichTextEditor.tsx +44 -9
- package/admin/components/SharedSectionBlockField.tsx +93 -0
- package/admin/components/SidebarUserMenu.tsx +1 -1
- package/admin/components/Toast.astro +1 -1
- package/admin/components/TreeItemsEditor.tsx +20 -19
- package/admin/components/TreeSelect.tsx +2 -2
- package/admin/components/YoutubeField.tsx +48 -0
- package/admin/components/block-fields.tsx +777 -0
- package/admin/components/content-block-spec.ts +114 -0
- package/admin/components/slash-command.tsx +242 -0
- package/admin/components/tree-utils.ts +14 -2
- package/admin/components/ui/badge.tsx +2 -3
- package/admin/components/ui/button.tsx +5 -4
- package/admin/components/ui/checkbox.tsx +1 -1
- package/admin/components/ui/input.tsx +1 -1
- package/admin/components/ui/select.tsx +1 -1
- package/admin/components/ui/table.tsx +1 -1
- package/admin/components/ui/textarea.tsx +1 -1
- package/admin/layouts/AdminLayout.astro +323 -123
- package/admin/lib/access.ts +54 -0
- package/admin/lib/collaboration.ts +178 -0
- package/admin/lib/edit-data.ts +448 -0
- package/admin/views/AccessDeniedView.astro +8 -0
- package/admin/views/EditView.astro +706 -0
- package/admin/views/ListView.astro +202 -0
- package/admin/views/RecentView.astro +76 -0
- package/admin/views/SinglesView.astro +65 -0
- package/admin/views/edit/EditScripts.astro +145 -0
- package/admin/views/edit/ReverseReferencesList.astro +68 -0
- package/core/admin.ts +193 -0
- package/core/ai.ts +87 -0
- package/core/api.ts +1392 -0
- package/core/assets.ts +336 -0
- package/core/audit.ts +84 -0
- package/core/auth-config.ts +44 -0
- package/core/auth.ts +303 -0
- package/core/collaboration.ts +276 -0
- package/core/content.ts +27 -0
- package/core/create-admin.ts +28 -0
- package/core/define.ts +625 -0
- package/core/field-model.ts +172 -0
- package/core/generator.ts +519 -0
- package/core/http.ts +42 -0
- package/core/image.ts +219 -0
- package/core/index.ts +211 -0
- package/core/locks.ts +52 -0
- package/core/log.ts +37 -0
- package/core/migrate.ts +278 -0
- package/core/rate-limit.ts +110 -0
- package/core/request-scope.ts +33 -0
- package/core/richtext.ts +1 -0
- package/core/runtime.ts +63 -0
- package/core/schema.ts +32 -0
- package/core/search.ts +489 -0
- package/core/seed.ts +101 -0
- package/core/shared-sections.ts +96 -0
- package/core/tasks.ts +176 -0
- package/core/values.ts +433 -0
- package/core/webhooks.ts +85 -0
- package/core/youtube.ts +39 -0
- package/internals/cli.mjs +34 -0
- package/internals/context.ts +67 -0
- package/internals/create-admin.ts +40 -0
- package/internals/describe.ts +25 -0
- package/internals/eject.ts +144 -0
- package/internals/generator.ts +11 -0
- package/internals/integration.ts +481 -0
- package/internals/mcp.ts +397 -0
- package/internals/project.ts +26 -0
- package/internals/push.ts +160 -0
- package/internals/reindex.ts +11 -0
- package/internals/restore.ts +257 -0
- package/internals/seed.data.ts +7 -0
- package/internals/seed.ts +11 -0
- package/internals/upgrade.ts +776 -0
- package/{virtual.d.ts → internals/virtual.d.ts} +39 -5
- package/middleware/auth.ts +130 -17
- package/middleware/push.ts +121 -0
- package/package.json +55 -67
- package/platform/cloudflare/cf-env.ts +60 -0
- package/platform/cloudflare/database.ts +28 -0
- package/platform/cloudflare/globals.d.ts +5 -0
- package/platform/cloudflare/storage.ts +33 -0
- package/platform/cloudflare/uploads-route.ts +37 -0
- package/platform/node/database.ts +39 -0
- package/platform/node/storage.ts +52 -0
- package/routes/admin/[...path].astro +71 -0
- package/routes/{pages/admin → admin}/assets/[id].astro +25 -19
- package/routes/admin/assets/index.astro +90 -0
- package/routes/{pages/admin/login.astro → admin/forgot-password.astro} +21 -19
- package/routes/{pages/admin → admin}/invite.astro +6 -6
- package/routes/admin/login.astro +103 -0
- package/routes/admin/reset-password.astro +73 -0
- package/routes/{pages/admin → admin}/setup.astro +31 -8
- package/routes/api/{cms/[collection] → [collection]}/[...path].ts +66 -14
- package/routes/api/admin/search.ts +89 -0
- package/routes/api/{cms/assets → assets}/[id].ts +24 -14
- package/routes/api/{cms/assets → assets}/index.ts +4 -2
- package/routes/api/assets/upload.ts +147 -0
- package/routes/api/auth/forgot-password.ts +77 -0
- package/routes/api/{cms/auth → auth}/invite.ts +41 -9
- package/routes/api/auth/login.ts +167 -0
- package/routes/api/{cms/auth → auth}/logout.ts +11 -2
- package/routes/api/auth/reset-password.ts +85 -0
- package/routes/api/auth/setup.ts +110 -0
- package/routes/api/auth/sso/[provider]/start.ts +34 -0
- package/routes/api/collaboration/index.ts +106 -0
- package/routes/api/cron/_authorize.ts +25 -0
- package/routes/api/{cms/cron → cron}/publish.ts +3 -9
- package/routes/api/cron/tasks.ts +33 -0
- package/routes/api/forms/submit/[slug].ts +143 -0
- package/routes/api/img/[...path].ts +65 -0
- package/routes/api/{cms/preview → preview}/render.ts +8 -3
- package/routes/api/{cms/references → references}/[collection]/[id].ts +31 -1
- package/routes/api/webhooks/[provider].ts +54 -0
- package/README.md +0 -28
- package/dist/admin.d.ts +0 -33
- package/dist/admin.js +0 -92
- package/dist/ai.d.ts +0 -15
- package/dist/ai.js +0 -70
- package/dist/api.d.ts +0 -14
- package/dist/api.js +0 -833
- package/dist/assets.d.ts +0 -51
- package/dist/assets.js +0 -163
- package/dist/auth.d.ts +0 -30
- package/dist/auth.js +0 -132
- package/dist/content.d.ts +0 -3
- package/dist/content.js +0 -29
- package/dist/create-admin.d.ts +0 -5
- package/dist/create-admin.js +0 -23
- package/dist/define.d.ts +0 -254
- package/dist/define.js +0 -36
- package/dist/generator.d.ts +0 -9
- package/dist/generator.js +0 -370
- package/dist/image.d.ts +0 -9
- package/dist/image.js +0 -69
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -16
- package/dist/integration.d.ts +0 -14
- package/dist/integration.js +0 -327
- package/dist/locks.d.ts +0 -7
- package/dist/locks.js +0 -37
- package/dist/richtext.d.ts +0 -1
- package/dist/richtext.js +0 -1
- package/dist/runtime.d.ts +0 -24
- package/dist/runtime.js +0 -26
- package/dist/schema.d.ts +0 -17
- package/dist/schema.js +0 -13
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -84
- package/dist/values.d.ts +0 -8
- package/dist/values.js +0 -102
- package/dist/webhooks.d.ts +0 -2
- package/dist/webhooks.js +0 -73
- package/routes/api/cms/assets/upload.ts +0 -112
- package/routes/api/cms/auth/login.ts +0 -124
- package/routes/api/cms/auth/setup.ts +0 -77
- package/routes/api/cms/img/[...path].ts +0 -24
- package/routes/pages/admin/[...path].astro +0 -1107
- package/routes/pages/admin/assets/index.astro +0 -63
- /package/routes/api/{cms/ai → ai}/alt-text.ts +0 -0
- /package/routes/api/{cms/ai → ai}/seo.ts +0 -0
- /package/routes/api/{cms/ai → ai}/translate.ts +0 -0
- /package/routes/api/{cms/assets → assets}/folders.ts +0 -0
- /package/routes/api/{cms/locks → locks}/[...path].ts +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { mergeAttributes, isNodeSelection, type Editor } from "@tiptap/core";
|
|
2
|
+
import { NodeSelection, TextSelection } from "@tiptap/pm/state";
|
|
3
|
+
import type { BlockTypesMeta, RelationOption } from "./block-fields";
|
|
4
|
+
import type { LinkOptionGroup } from "./InternalLinkPicker";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Schema/serialization spec for the inline `content` block node — kept free of React
|
|
8
|
+
* so it can be unit-tested against a headless Tiptap editor. ContentEditor.tsx spreads
|
|
9
|
+
* this into `Node.create({ ...blockNodeSpec, addNodeView })` to attach the React view.
|
|
10
|
+
*
|
|
11
|
+
* The per-attribute parse/render keep `blockType` + `fields` intact across the HTML
|
|
12
|
+
* round-trip ProseMirror performs on drag-and-drop and copy/paste.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// NOTE: must NOT be "block" — that collides with the ProseMirror content-group name
|
|
16
|
+
// "block" used in node content expressions (e.g. the doc's "block+"), which corrupts
|
|
17
|
+
// the schema and breaks text insertion. Use a distinct node name.
|
|
18
|
+
export const BLOCK_NODE_NAME = "cmsBlock";
|
|
19
|
+
|
|
20
|
+
// Discriminator for a shared-section reference block (mirrors core's SHARED_BLOCK_TYPE).
|
|
21
|
+
// Kept here so client components avoid importing the server-side `@/cms/core` barrel.
|
|
22
|
+
export const SHARED_BLOCK_TYPE = "__shared";
|
|
23
|
+
|
|
24
|
+
export type BlockNodeOptions = {
|
|
25
|
+
types: BlockTypesMeta;
|
|
26
|
+
blockRelationOptions: Record<string, RelationOption[]>;
|
|
27
|
+
linkOptions?: LinkOptionGroup[];
|
|
28
|
+
/** Name of the `content` field this editor belongs to — namespaces relation-option keys. */
|
|
29
|
+
fieldName: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const blockNodeSpec = {
|
|
33
|
+
name: BLOCK_NODE_NAME,
|
|
34
|
+
group: "block",
|
|
35
|
+
atom: true,
|
|
36
|
+
draggable: true,
|
|
37
|
+
selectable: true,
|
|
38
|
+
|
|
39
|
+
addOptions(): BlockNodeOptions {
|
|
40
|
+
return { types: {}, blockRelationOptions: {}, fieldName: "" };
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
addAttributes() {
|
|
44
|
+
return {
|
|
45
|
+
blockType: {
|
|
46
|
+
default: "",
|
|
47
|
+
parseHTML: (el: HTMLElement) => el.getAttribute("data-block-type") || "",
|
|
48
|
+
renderHTML: (attrs: Record<string, unknown>) =>
|
|
49
|
+
attrs.blockType ? { "data-block-type": String(attrs.blockType) } : {},
|
|
50
|
+
},
|
|
51
|
+
fields: {
|
|
52
|
+
default: {},
|
|
53
|
+
parseHTML: (el: HTMLElement) => {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(el.getAttribute("data-fields") || "{}");
|
|
56
|
+
} catch {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
renderHTML: (attrs: Record<string, unknown>) => ({ "data-fields": JSON.stringify(attrs.fields ?? {}) }),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
parseHTML() {
|
|
66
|
+
return [{ tag: "div[data-cms-block]" }];
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, unknown> }) {
|
|
70
|
+
return ["div", mergeAttributes({ "data-cms-block": "" }, HTMLAttributes)] as const;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Insert an inline component block, then guarantee an editable text block follows it with
|
|
76
|
+
* the caret inside — mirroring Tiptap's own setHorizontalRule so an atom block never leaves
|
|
77
|
+
* the user stranded with nowhere to type. Pass `range` to first delete a slash trigger.
|
|
78
|
+
* Shared by the toolbar "+ Block" inserter and the slash command.
|
|
79
|
+
*/
|
|
80
|
+
export function insertBlockNode(
|
|
81
|
+
editor: Editor,
|
|
82
|
+
blockType: string,
|
|
83
|
+
fields: Record<string, unknown>,
|
|
84
|
+
range?: { from: number; to: number },
|
|
85
|
+
) {
|
|
86
|
+
const content = { type: BLOCK_NODE_NAME, attrs: { blockType, fields } };
|
|
87
|
+
const chain = editor.chain().focus();
|
|
88
|
+
if (range) chain.deleteRange(range).insertContent(content);
|
|
89
|
+
else if (isNodeSelection(editor.state.selection)) chain.insertContentAt(editor.state.selection.$to.pos, content);
|
|
90
|
+
else chain.insertContent(content);
|
|
91
|
+
|
|
92
|
+
chain
|
|
93
|
+
.command(({ state, tr, dispatch }) => {
|
|
94
|
+
if (dispatch) {
|
|
95
|
+
const { $to } = tr.selection;
|
|
96
|
+
const posAfter = $to.end();
|
|
97
|
+
if ($to.nodeAfter) {
|
|
98
|
+
if ($to.nodeAfter.isTextblock) tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1));
|
|
99
|
+
else if ($to.nodeAfter.isBlock) tr.setSelection(NodeSelection.create(tr.doc, $to.pos));
|
|
100
|
+
else tr.setSelection(TextSelection.create(tr.doc, $to.pos));
|
|
101
|
+
} else {
|
|
102
|
+
const nodeType = state.schema.nodes.paragraph ?? $to.parent.type.contentMatch.defaultType;
|
|
103
|
+
const node = nodeType?.create();
|
|
104
|
+
if (node) {
|
|
105
|
+
tr.insert(posAfter, node);
|
|
106
|
+
tr.setSelection(TextSelection.create(tr.doc, posAfter + 1));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
tr.scrollIntoView();
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
})
|
|
113
|
+
.run();
|
|
114
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Extension, type Editor, type Range } from "@tiptap/core";
|
|
2
|
+
import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";
|
|
3
|
+
import { ReactRenderer } from "@tiptap/react";
|
|
4
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, type ComponentType } from "react";
|
|
5
|
+
import { Heading2, Heading3, List, ListOrdered, Quote, Blocks, Link2, type LucideProps } from "lucide-react";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { insertBlockNode, SHARED_BLOCK_TYPE } from "./content-block-spec";
|
|
8
|
+
import { blankBlockFields, humanize, type BlockTypesMeta } from "./block-fields";
|
|
9
|
+
|
|
10
|
+
export type SharedSectionOption = { id: string; title: string; blockType: string; status?: string };
|
|
11
|
+
|
|
12
|
+
// -----------------------------------------------
|
|
13
|
+
// Slash command — Notion/Gutenberg-style "/" inserter for headings, lists, quotes
|
|
14
|
+
// and the content field's component blocks.
|
|
15
|
+
// -----------------------------------------------
|
|
16
|
+
|
|
17
|
+
type SlashItem = {
|
|
18
|
+
title: string;
|
|
19
|
+
subtitle: string;
|
|
20
|
+
icon: ComponentType<LucideProps>;
|
|
21
|
+
run: (editor: Editor, range: Range) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const buildItems = (types: BlockTypesMeta, sharedSections: SharedSectionOption[], query: string): SlashItem[] => {
|
|
25
|
+
const formatting: SlashItem[] = [
|
|
26
|
+
{
|
|
27
|
+
title: "Heading 2",
|
|
28
|
+
subtitle: "Section heading",
|
|
29
|
+
icon: Heading2,
|
|
30
|
+
run: (e, r) => e.chain().focus().deleteRange(r).toggleHeading({ level: 2 }).run(),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: "Heading 3",
|
|
34
|
+
subtitle: "Subsection heading",
|
|
35
|
+
icon: Heading3,
|
|
36
|
+
run: (e, r) => e.chain().focus().deleteRange(r).toggleHeading({ level: 3 }).run(),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "Bullet list",
|
|
40
|
+
subtitle: "Unordered list",
|
|
41
|
+
icon: List,
|
|
42
|
+
run: (e, r) => e.chain().focus().deleteRange(r).toggleBulletList().run(),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: "Numbered list",
|
|
46
|
+
subtitle: "Ordered list",
|
|
47
|
+
icon: ListOrdered,
|
|
48
|
+
run: (e, r) => e.chain().focus().deleteRange(r).toggleOrderedList().run(),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: "Quote",
|
|
52
|
+
subtitle: "Blockquote",
|
|
53
|
+
icon: Quote,
|
|
54
|
+
run: (e, r) => e.chain().focus().deleteRange(r).toggleBlockquote().run(),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const blocks: SlashItem[] = Object.keys(types).map((typeName) => ({
|
|
59
|
+
title: humanize(typeName),
|
|
60
|
+
subtitle: "Component block",
|
|
61
|
+
icon: Blocks,
|
|
62
|
+
run: (e, r) => insertBlockNode(e, typeName, blankBlockFields(types[typeName] ?? {}), r),
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
const shared: SlashItem[] = sharedSections.map((section) => ({
|
|
66
|
+
title: section.title,
|
|
67
|
+
subtitle: `Shared section · ${humanize(section.blockType)}`,
|
|
68
|
+
icon: Link2,
|
|
69
|
+
run: (e, r) =>
|
|
70
|
+
insertBlockNode(e, SHARED_BLOCK_TYPE, { ref: section.id, title: section.title, blockType: section.blockType }, r),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
const all = [...formatting, ...blocks, ...shared];
|
|
74
|
+
const q = query.trim().toLowerCase();
|
|
75
|
+
return q ? all.filter((item) => item.title.toLowerCase().includes(q)) : all;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// -----------------------------------------------
|
|
79
|
+
// Menu component
|
|
80
|
+
// -----------------------------------------------
|
|
81
|
+
|
|
82
|
+
type SlashMenuRef = { onKeyDown: (props: { event: KeyboardEvent }) => boolean };
|
|
83
|
+
|
|
84
|
+
type SlashMenuProps = {
|
|
85
|
+
items: SlashItem[];
|
|
86
|
+
command: (item: SlashItem) => void;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const SlashMenu = forwardRef<SlashMenuRef, SlashMenuProps>(({ items, command }, ref) => {
|
|
90
|
+
const [selected, setSelected] = useState(0);
|
|
91
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
92
|
+
|
|
93
|
+
useEffect(() => setSelected(0), [items]);
|
|
94
|
+
|
|
95
|
+
// Keep the highlighted item visible when the list is height-constrained and scrolls.
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
(listRef.current?.children[selected] as HTMLElement | undefined)?.scrollIntoView({ block: "nearest" });
|
|
98
|
+
}, [selected]);
|
|
99
|
+
|
|
100
|
+
useImperativeHandle(ref, () => ({
|
|
101
|
+
onKeyDown: ({ event }) => {
|
|
102
|
+
if (event.key === "ArrowUp") {
|
|
103
|
+
setSelected((i) => (i + items.length - 1) % items.length);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (event.key === "ArrowDown") {
|
|
107
|
+
setSelected((i) => (i + 1) % items.length);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (event.key === "Enter") {
|
|
111
|
+
if (items[selected]) command(items[selected]);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
},
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
if (items.length === 0) {
|
|
119
|
+
return (
|
|
120
|
+
<div className="bg-popover text-muted-foreground w-64 rounded-md border p-2 text-sm shadow-md">No matches</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div ref={listRef} className="bg-popover max-h-72 w-64 overflow-y-auto rounded-md border p-1 shadow-md">
|
|
126
|
+
{items.map((item, index) => {
|
|
127
|
+
const Icon = item.icon;
|
|
128
|
+
return (
|
|
129
|
+
<button
|
|
130
|
+
key={item.title}
|
|
131
|
+
type="button"
|
|
132
|
+
onMouseEnter={() => setSelected(index)}
|
|
133
|
+
onClick={() => command(item)}
|
|
134
|
+
className={cn(
|
|
135
|
+
"flex w-full items-center gap-2.5 rounded-sm px-2 py-1.5 text-left text-sm transition-colors",
|
|
136
|
+
index === selected ? "bg-accent text-accent-foreground" : "text-foreground hover:bg-accent/60",
|
|
137
|
+
)}
|
|
138
|
+
>
|
|
139
|
+
<span className="bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded border">
|
|
140
|
+
<Icon className="size-4" />
|
|
141
|
+
</span>
|
|
142
|
+
<span className="min-w-0">
|
|
143
|
+
<span className="block truncate font-medium">{item.title}</span>
|
|
144
|
+
<span className="text-muted-foreground block truncate text-xs">{item.subtitle}</span>
|
|
145
|
+
</span>
|
|
146
|
+
</button>
|
|
147
|
+
);
|
|
148
|
+
})}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
SlashMenu.displayName = "SlashMenu";
|
|
153
|
+
|
|
154
|
+
// -----------------------------------------------
|
|
155
|
+
// Extension
|
|
156
|
+
// -----------------------------------------------
|
|
157
|
+
|
|
158
|
+
type SlashCommandOptions = { types: BlockTypesMeta; sharedSections: SharedSectionOption[] };
|
|
159
|
+
|
|
160
|
+
export const SlashCommand = Extension.create<SlashCommandOptions>({
|
|
161
|
+
name: "slashCommand",
|
|
162
|
+
|
|
163
|
+
addOptions() {
|
|
164
|
+
return { types: {}, sharedSections: [] };
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
addProseMirrorPlugins() {
|
|
168
|
+
const suggestion: Omit<SuggestionOptions<SlashItem>, "editor"> = {
|
|
169
|
+
char: "/",
|
|
170
|
+
startOfLine: false,
|
|
171
|
+
allowSpaces: false,
|
|
172
|
+
command: ({ editor, range, props }) => props.run(editor, range),
|
|
173
|
+
items: ({ query }) => buildItems(this.options.types, this.options.sharedSections, query),
|
|
174
|
+
render: () => {
|
|
175
|
+
let component: ReactRenderer<SlashMenuRef, SlashMenuProps> | null = null;
|
|
176
|
+
|
|
177
|
+
const place = (clientRect?: (() => DOMRect | null) | null) => {
|
|
178
|
+
const rect = clientRect?.();
|
|
179
|
+
if (!rect || !component) return;
|
|
180
|
+
const el = component.element as HTMLElement;
|
|
181
|
+
const menu = el.firstElementChild as HTMLElement | null;
|
|
182
|
+
el.style.position = "fixed";
|
|
183
|
+
el.style.zIndex = "50";
|
|
184
|
+
el.style.left = `${rect.left}px`;
|
|
185
|
+
|
|
186
|
+
const margin = 8;
|
|
187
|
+
const gap = 6;
|
|
188
|
+
const vh = window.innerHeight;
|
|
189
|
+
const spaceBelow = vh - rect.bottom - margin;
|
|
190
|
+
const spaceAbove = rect.top - margin;
|
|
191
|
+
const MAX = 288; // matches max-h-72
|
|
192
|
+
const needed = Math.min(menu?.scrollHeight || MAX, MAX);
|
|
193
|
+
|
|
194
|
+
// Open downward when it fits or there's more room below; otherwise flip above.
|
|
195
|
+
if (spaceBelow >= needed || spaceBelow >= spaceAbove) {
|
|
196
|
+
el.style.top = `${rect.bottom + gap}px`;
|
|
197
|
+
el.style.bottom = "auto";
|
|
198
|
+
if (menu) menu.style.maxHeight = `${Math.max(Math.min(needed, spaceBelow), 0)}px`;
|
|
199
|
+
} else {
|
|
200
|
+
el.style.top = "auto";
|
|
201
|
+
el.style.bottom = `${vh - rect.top + gap}px`;
|
|
202
|
+
if (menu) menu.style.maxHeight = `${Math.max(Math.min(needed, spaceAbove), 0)}px`;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Measure after paint so the menu's rendered height (scrollHeight) is accurate.
|
|
207
|
+
const position = (clientRect?: (() => DOMRect | null) | null) => requestAnimationFrame(() => place(clientRect));
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
onStart: (props) => {
|
|
211
|
+
component = new ReactRenderer(SlashMenu, {
|
|
212
|
+
props: { items: props.items, command: (item: SlashItem) => props.command(item) },
|
|
213
|
+
editor: props.editor,
|
|
214
|
+
});
|
|
215
|
+
document.body.appendChild(component.element);
|
|
216
|
+
position(props.clientRect);
|
|
217
|
+
},
|
|
218
|
+
onUpdate: (props) => {
|
|
219
|
+
component?.updateProps({ items: props.items, command: (item: SlashItem) => props.command(item) });
|
|
220
|
+
position(props.clientRect);
|
|
221
|
+
},
|
|
222
|
+
onKeyDown: (props) => {
|
|
223
|
+
if (props.event.key === "Escape") {
|
|
224
|
+
component?.element.remove();
|
|
225
|
+
component?.destroy();
|
|
226
|
+
component = null;
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
return component?.ref?.onKeyDown(props) ?? false;
|
|
230
|
+
},
|
|
231
|
+
onExit: () => {
|
|
232
|
+
component?.element.remove();
|
|
233
|
+
component?.destroy();
|
|
234
|
+
component = null;
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
return [Suggestion({ editor: this.editor, ...suggestion })];
|
|
241
|
+
},
|
|
242
|
+
});
|
|
@@ -70,7 +70,11 @@ export function findItemDepth(items: TreeItem[], id: string, depth = 0): number
|
|
|
70
70
|
return -1;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
/** Menu items render as root → section → link (see SiteHeader.tsx); a 4th level
|
|
74
|
+
* is accepted by the JSON field but never rendered, so the editor caps depth here. */
|
|
75
|
+
export const MENU_MAX_DEPTH = 2;
|
|
76
|
+
|
|
77
|
+
export function canIndent(items: TreeItem[], id: string, maxDepth?: number): boolean {
|
|
74
78
|
const check = (list: TreeItem[]): boolean => {
|
|
75
79
|
for (let i = 0; i < list.length; i++) {
|
|
76
80
|
if (list[i].id === id) return i > 0;
|
|
@@ -78,9 +82,17 @@ export function canIndent(items: TreeItem[], id: string): boolean {
|
|
|
78
82
|
}
|
|
79
83
|
return false;
|
|
80
84
|
};
|
|
81
|
-
|
|
85
|
+
if (!check(items)) return false;
|
|
86
|
+
if (maxDepth === undefined) return true;
|
|
87
|
+
// Indenting nests the item one level under its previous sibling.
|
|
88
|
+
return findItemDepth(items, id) + 1 <= maxDepth;
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
export function canOutdent(items: TreeItem[], id: string): boolean {
|
|
85
92
|
return findItemDepth(items, id) > 0;
|
|
86
93
|
}
|
|
94
|
+
|
|
95
|
+
export function canAddChild(items: TreeItem[], id: string, maxDepth?: number): boolean {
|
|
96
|
+
if (maxDepth === undefined) return true;
|
|
97
|
+
return findItemDepth(items, id) < maxDepth;
|
|
98
|
+
}
|
|
@@ -5,14 +5,13 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
5
5
|
import { cn } from "../../lib/utils";
|
|
6
6
|
|
|
7
7
|
const badgeVariants = cva(
|
|
8
|
-
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all
|
|
8
|
+
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
|
9
9
|
{
|
|
10
10
|
variants: {
|
|
11
11
|
variant: {
|
|
12
12
|
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
|
13
13
|
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
|
14
|
-
destructive:
|
|
15
|
-
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
|
|
14
|
+
destructive: "bg-destructive/10 text-destructive dark:bg-destructive/20 [a]:hover:bg-destructive/20",
|
|
16
15
|
outline: "border-foreground/20 text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
|
17
16
|
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
|
18
17
|
link: "text-primary underline-offset-4 hover:underline",
|
|
@@ -4,22 +4,23 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
4
4
|
import { cn } from "../../lib/utils";
|
|
5
5
|
|
|
6
6
|
const buttonVariants = cva(
|
|
7
|
-
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none
|
|
7
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none active:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
8
8
|
{
|
|
9
9
|
variants: {
|
|
10
10
|
variant: {
|
|
11
11
|
default:
|
|
12
12
|
"bg-indigo-100 hover:bg-indigo-200/70 text-indigo-900 border-indigo-300 dark:bg-indigo-500/30 dark:hover:bg-indigo-500/40 dark:border-indigo-600 dark:text-indigo-100",
|
|
13
13
|
outline:
|
|
14
|
-
"border-foreground/
|
|
14
|
+
"border-input hover:border-foreground/20 bg-muted-strong/40 hover:bg-muted-strong/60 hover:text-foreground aria-expanded:bg-muted-strong/60 aria-expanded:text-foreground dark:border-input dark:hover:border-foreground/20 dark:bg-input/30 dark:hover:bg-input/50",
|
|
15
|
+
input: "border-input hover:border-foreground/25 bg-muted/30 dark:bg-input/30 dark:hover:border-foreground/25",
|
|
15
16
|
secondary:
|
|
16
17
|
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
17
18
|
publish:
|
|
18
|
-
"bg-emerald-200/80 hover:bg-emerald-200
|
|
19
|
+
"bg-emerald-200/80 hover:bg-emerald-200 text-emerald-800 hover:text-emerald-900 border-emerald-400 dark:bg-emerald-500/30 dark:hover:bg-emerald-500/40 dark:border-emerald-700 dark:text-emerald-200 dark:hover:text-emerald-100",
|
|
19
20
|
ghost:
|
|
20
21
|
"border-transparent hover:bg-foreground/8 hover:text-foreground aria-expanded:bg-foreground/8 aria-expanded:text-foreground dark:hover:bg-foreground/15 dark:aria-expanded:bg-foreground/15",
|
|
21
22
|
destructive:
|
|
22
|
-
"border-transparent bg-destructive/10 text-destructive hover:bg-destructive/20
|
|
23
|
+
"border-transparent bg-destructive/10 text-destructive hover:bg-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30",
|
|
23
24
|
link: "border-transparent text-primary underline-offset-4 hover:underline",
|
|
24
25
|
},
|
|
25
26
|
size: {
|
|
@@ -10,7 +10,7 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
|
|
|
10
10
|
<CheckboxPrimitive.Root
|
|
11
11
|
data-slot="checkbox"
|
|
12
12
|
className={cn(
|
|
13
|
-
"peer border-
|
|
13
|
+
"peer border-foreground/35 hover:border-primary/60 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:border-foreground/40 dark:hover:border-primary/60 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary disabled:hover:border-foreground/35 relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
14
14
|
className,
|
|
15
15
|
)}
|
|
16
16
|
{...props}
|
|
@@ -9,7 +9,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
|
9
9
|
type={type}
|
|
10
10
|
data-slot="input"
|
|
11
11
|
className={cn(
|
|
12
|
-
"border-input hover:border-foreground/
|
|
12
|
+
"border-input hover:border-foreground/25 file:text-foreground placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 read-only:hover:border-input read-only:text-muted-foreground h-9 w-full min-w-0 rounded-lg border px-3 py-1.5 text-sm transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:font-medium read-only:cursor-not-allowed disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
13
13
|
className,
|
|
14
14
|
)}
|
|
15
15
|
{...props}
|
|
@@ -29,7 +29,7 @@ function SelectTrigger({
|
|
|
29
29
|
data-slot="select-trigger"
|
|
30
30
|
data-size={size}
|
|
31
31
|
className={cn(
|
|
32
|
-
"border-input hover:
|
|
32
|
+
"border-input hover:border-foreground/25 dark:hover:border-foreground/25 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 flex w-fit items-center justify-between gap-1.5 rounded-lg border py-1.5 pr-3 pl-3 text-sm whitespace-nowrap transition-colors outline-none select-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 data-[size=default]:h-9 data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
33
33
|
className,
|
|
34
34
|
)}
|
|
35
35
|
{...props}
|
|
@@ -15,7 +15,7 @@ function Table({ className, ...props }: React.ComponentProps<"table">) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
|
18
|
-
return <thead data-slot="table-header" className={cn("bg-muted
|
|
18
|
+
return <thead data-slot="table-header" className={cn("bg-muted [&_tr]:border-b", className)} {...props} />;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
|
@@ -7,7 +7,7 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
|
7
7
|
<textarea
|
|
8
8
|
data-slot="textarea"
|
|
9
9
|
className={cn(
|
|
10
|
-
"border-input hover:border-foreground/
|
|
10
|
+
"border-input hover:border-foreground/25 placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 read-only:hover:border-input read-only:text-muted-foreground flex field-sizing-content min-h-16 w-full rounded-lg border px-3 py-2.5 text-sm transition-colors outline-none read-only:cursor-not-allowed disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
11
11
|
className,
|
|
12
12
|
)}
|
|
13
13
|
{...props}
|