@lupinum/ginko-editor 0.1.0 → 0.18.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/CHANGELOG.md +7 -73
- package/LICENSE +1 -1
- package/README.md +15 -340
- package/dist/assets.d.ts +70 -0
- package/dist/assets.js +31 -0
- package/dist/core/component-props.d.ts +87 -0
- package/dist/core/component-props.js +134 -0
- package/dist/core/convert.d.ts +24 -0
- package/dist/core/convert.js +278 -0
- package/dist/core/editor.d.ts +60 -0
- package/dist/core/editor.js +85 -0
- package/dist/core/extensions.d.ts +38 -0
- package/dist/core/extensions.js +444 -0
- package/dist/core/file-images.d.ts +9 -0
- package/dist/core/file-images.js +54 -0
- package/dist/core/image-frame.d.ts +23 -0
- package/dist/core/image-frame.js +24 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +17 -0
- package/dist/core/link-card.d.ts +20 -0
- package/dist/core/link-card.js +70 -0
- package/dist/core/link.d.ts +3 -0
- package/dist/core/link.js +8 -0
- package/dist/core/move.d.ts +11 -0
- package/dist/core/move.js +37 -0
- package/dist/core/paste-html.d.ts +6 -0
- package/dist/core/paste-html.js +384 -0
- package/dist/core/paste.d.ts +21 -0
- package/dist/core/paste.js +108 -0
- package/dist/core/problems.d.ts +31 -0
- package/dist/core/problems.js +54 -0
- package/dist/core/search.d.ts +47 -0
- package/dist/core/search.js +148 -0
- package/dist/core/slash.d.ts +93 -0
- package/dist/core/slash.js +215 -0
- package/dist/core/table.d.ts +34 -0
- package/dist/core/table.js +141 -0
- package/dist/core/uploads.d.ts +23 -0
- package/dist/core/uploads.js +71 -0
- package/dist/core/use-editor.d.ts +19 -0
- package/dist/core/use-editor.js +53 -0
- package/dist/index.d.ts +6 -15
- package/dist/index.js +6 -5668
- package/dist/issues.d.ts +49 -0
- package/dist/issues.js +9 -0
- package/dist/today.d.ts +6 -0
- package/dist/today.js +19 -0
- package/dist/useUpload.d.ts +48 -0
- package/dist/useUpload.js +59 -0
- package/dist/values.d.ts +14 -0
- package/dist/values.js +36 -0
- package/package.json +35 -95
- package/dist/GinkoEditor.vue.d.ts +0 -96
- package/dist/GinkoImagePicker.vue.d.ts +0 -36
- package/dist/agent/AGENTS.md +0 -13
- package/dist/agent/pages/docs/getting-started/collaboration.md +0 -435
- package/dist/agent/pages/docs/getting-started/component-coverage.md +0 -107
- package/dist/agent/pages/docs/getting-started/customize.md +0 -384
- package/dist/agent/pages/docs/getting-started/images.md +0 -188
- package/dist/agent/pages/docs/getting-started/in-place-editing.md +0 -110
- package/dist/agent/pages/docs/getting-started/layout-blocks.md +0 -148
- package/dist/agent/pages/docs/getting-started/runtime.md +0 -111
- package/dist/agent/pages/docs/getting-started.md +0 -128
- package/dist/authoring-D7MJezVG.js +0 -1780
- package/dist/authoring-D7MJezVG.js.map +0 -1
- package/dist/authoring.d.ts +0 -122
- package/dist/authoring.js +0 -2
- package/dist/collaboration.d.ts +0 -14
- package/dist/collaboration.js +0 -907
- package/dist/collaboration.js.map +0 -1
- package/dist/composables/useAssetRequests.d.ts +0 -44
- package/dist/composables/useCollaborationBinding.d.ts +0 -59
- package/dist/composables/useDevice.d.ts +0 -10
- package/dist/composables/useInsertMenu.d.ts +0 -67
- package/dist/composables/useMarkdownSync.d.ts +0 -96
- package/dist/composables/useStableAuthoringKit.d.ts +0 -16
- package/dist/documentConfig-Z6LdrWZj.js +0 -2360
- package/dist/documentConfig-Z6LdrWZj.js.map +0 -1
- package/dist/editorProps.d.ts +0 -124
- package/dist/index.js.map +0 -1
- package/dist/layout-kit.d.ts +0 -922
- package/dist/lib/collaboration/presence-record.d.ts +0 -18
- package/dist/lib/collaboration/presence.d.ts +0 -103
- package/dist/lib/collaboration/protocol.d.ts +0 -133
- package/dist/lib/collaboration/recovery.d.ts +0 -45
- package/dist/lib/collaboration/session.d.ts +0 -163
- package/dist/lib/collaboration/validation.d.ts +0 -42
- package/dist/lib/component-converters.d.ts +0 -119
- package/dist/lib/config/documentConfig.d.ts +0 -19
- package/dist/lib/config/editorConfig.d.ts +0 -38
- package/dist/lib/container-items.d.ts +0 -55
- package/dist/lib/conversionInvariants.d.ts +0 -3
- package/dist/lib/conversionLogger.d.ts +0 -10
- package/dist/lib/conversionPipeline.d.ts +0 -17
- package/dist/lib/conversionState.d.ts +0 -10
- package/dist/lib/conversionTypes.d.ts +0 -50
- package/dist/lib/editor-operations.d.ts +0 -39
- package/dist/lib/environment.d.ts +0 -6
- package/dist/lib/extensions/code-block.d.ts +0 -18
- package/dist/lib/extensions/component-boundary.d.ts +0 -9
- package/dist/lib/extensions/container-items.d.ts +0 -29
- package/dist/lib/extensions/element.d.ts +0 -19
- package/dist/lib/extensions/file.d.ts +0 -24
- package/dist/lib/extensions/heading.d.ts +0 -5
- package/dist/lib/extensions/image-upload.d.ts +0 -39
- package/dist/lib/extensions/image.d.ts +0 -39
- package/dist/lib/extensions/index.d.ts +0 -10
- package/dist/lib/extensions/inline-element.d.ts +0 -13
- package/dist/lib/extensions/markdown-clipboard.d.ts +0 -21
- package/dist/lib/extensions/profile.d.ts +0 -11
- package/dist/lib/extensions/slot.d.ts +0 -16
- package/dist/lib/extensions/span-style.d.ts +0 -15
- package/dist/lib/extensions/video.d.ts +0 -15
- package/dist/lib/image-properties.d.ts +0 -20
- package/dist/lib/input-rules.d.ts +0 -7
- package/dist/lib/markdown.d.ts +0 -11
- package/dist/lib/marks.d.ts +0 -7
- package/dist/lib/mdcToTiptap.d.ts +0 -20
- package/dist/lib/mdcTypes.d.ts +0 -20
- package/dist/lib/nodes.d.ts +0 -57
- package/dist/lib/nodeviews/block-actions.d.ts +0 -7
- package/dist/lib/nodeviews/code.d.ts +0 -4
- package/dist/lib/nodeviews/columns.d.ts +0 -17
- package/dist/lib/nodeviews/component.d.ts +0 -6
- package/dist/lib/nodeviews/icons.d.ts +0 -26
- package/dist/lib/nodeviews/image.d.ts +0 -9
- package/dist/lib/nodeviews/items.d.ts +0 -15
- package/dist/lib/nodeviews/lifecycle.d.ts +0 -45
- package/dist/lib/nodeviews/popover.d.ts +0 -15
- package/dist/lib/nodeviews/settings.d.ts +0 -11
- package/dist/lib/nodeviews/table-operations.d.ts +0 -50
- package/dist/lib/nodeviews/table.d.ts +0 -4
- package/dist/lib/profiles.d.ts +0 -62
- package/dist/lib/property-input.d.ts +0 -10
- package/dist/lib/property-step.d.ts +0 -77
- package/dist/lib/props.d.ts +0 -13
- package/dist/lib/stripStyleNodes.d.ts +0 -2
- package/dist/lib/tiptapToMdc.d.ts +0 -18
- package/dist/presence-record-CLdPZWKC.js +0 -291
- package/dist/presence-record-CLdPZWKC.js.map +0 -1
- package/dist/runtime.d.ts +0 -13
- package/dist/runtime.js +0 -3
- package/dist/style.css +0 -2
- package/dist/types.d.ts +0 -126
- package/dist/ui/GinkoActionButton.vue.d.ts +0 -8
- package/dist/ui/GinkoInsertMenu.vue.d.ts +0 -49
- package/dist/ui/GinkoKeyboardDock.vue.d.ts +0 -15
- package/dist/ui/GinkoNodePopover.vue.d.ts +0 -21
- package/dist/ui/GinkoRecipeIcon.vue.d.ts +0 -6
- package/dist/ui/GinkoSelectionToolbar.vue.d.ts +0 -10
- package/dist/ui/GinkoToolbar.vue.d.ts +0 -26
- package/dist/ui/GinkoToolbarIcon.vue.d.ts +0 -6
- package/dist/ui/block-shortcuts.d.ts +0 -6
- package/dist/ui/commands.d.ts +0 -78
- package/dist/ui/context.d.ts +0 -23
- package/dist/ui/editor-keyboard.d.ts +0 -15
- package/dist/ui/messages.d.ts +0 -214
- package/dist/ui/messages.de.d.ts +0 -6
- package/dist/ui/recipe-command.d.ts +0 -14
- package/dist/ui/recipe-search.d.ts +0 -47
- package/dist/ui/slash-command.d.ts +0 -17
- package/dist/ui/writingRecipes.d.ts +0 -13
- package/skills/ginko-editor/SKILL.md +0 -40
- package/skills/ginko-editor/agents/openai.yaml +0 -4
- package/skills/ginko-editor/references/in-place-editing.md +0 -50
- package/skills/ginko-editor/references/quickstart.md +0 -55
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { componentPropMessage, msg, effectiveMax, fileRefOf, isSafeHref, labelOf, URL_PROPS } from "@lupinum/ginko/internal";
|
|
2
|
+
export const editorMeta = (def) => def?.editor ?? {};
|
|
3
|
+
export function aliasOf(registry, tag) {
|
|
4
|
+
const alias = registry && Object.hasOwn(registry, tag) ? editorMeta(registry[tag]).aliasOf : void 0;
|
|
5
|
+
const field = alias && registry && Object.hasOwn(registry, alias.tag) ? registry[alias.tag].props[alias.prop] : void 0;
|
|
6
|
+
return alias && field?.type === "choice" ? { ...alias, field } : void 0;
|
|
7
|
+
}
|
|
8
|
+
export function componentMode(tag, registry, liveTags) {
|
|
9
|
+
const def = registry && Object.hasOwn(registry, tag) ? registry[tag] : void 0;
|
|
10
|
+
if (!def || def.kind !== "block") return "card";
|
|
11
|
+
const live = Array.isArray(liveTags) ? liveTags.includes(tag) : liveTags.has(tag);
|
|
12
|
+
if (!live) return "card";
|
|
13
|
+
if (def.slots && Object.keys(def.slots).length) return "card";
|
|
14
|
+
if (def.children?.length || def.parents?.length) return "card";
|
|
15
|
+
return "live";
|
|
16
|
+
}
|
|
17
|
+
export function propFields(def) {
|
|
18
|
+
return Object.entries(def.props ?? {}).filter((entry) => !entry[1].retired && ["text", "longtext", "number", "boolean", "choice", "choices", "image", "ref"].includes(entry[1].type));
|
|
19
|
+
}
|
|
20
|
+
export function rawProp(props, key) {
|
|
21
|
+
if (!props) return void 0;
|
|
22
|
+
return Object.hasOwn(props, key) ? props[key] : props[`:${key}`];
|
|
23
|
+
}
|
|
24
|
+
const isOn = (raw) => raw === true || raw === "true" || raw === "";
|
|
25
|
+
export function readProp(field, props, key) {
|
|
26
|
+
const raw = rawProp(props, key);
|
|
27
|
+
switch (field.type) {
|
|
28
|
+
case "boolean":
|
|
29
|
+
return raw === void 0 ? field.default === true ? true : false : isOn(raw);
|
|
30
|
+
case "number": {
|
|
31
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
32
|
+
const n = Number(raw);
|
|
33
|
+
return Number.isFinite(n) ? n : void 0;
|
|
34
|
+
}
|
|
35
|
+
case "choices":
|
|
36
|
+
return typeof raw === "string" ? raw.split(",").map((v) => v.trim()).filter(Boolean) : void 0;
|
|
37
|
+
default:
|
|
38
|
+
return typeof raw === "string" ? raw : void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function rawOf(field, value) {
|
|
42
|
+
if (value === void 0) return void 0;
|
|
43
|
+
if (field.type === "boolean") return value === true ? "true" : "false";
|
|
44
|
+
if (Array.isArray(value)) return value.length ? value.join(",") : void 0;
|
|
45
|
+
const text2 = String(value);
|
|
46
|
+
return text2 === "" ? "" : text2;
|
|
47
|
+
}
|
|
48
|
+
export function writeProp(field, props, key, value) {
|
|
49
|
+
const out = { ...props ?? {} };
|
|
50
|
+
const name = Object.hasOwn(out, key) ? key : Object.hasOwn(out, `:${key}`) ? `:${key}` : void 0;
|
|
51
|
+
let raw = rawOf(field, value);
|
|
52
|
+
if (field.type === "boolean") {
|
|
53
|
+
const on = value === true;
|
|
54
|
+
const asDefault = on === (field.default === true);
|
|
55
|
+
if (asDefault) {
|
|
56
|
+
if (name) delete out[name];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
if (name) out[name] = on ? "true" : "false";
|
|
60
|
+
else if (on) out[`:${key}`] = "true";
|
|
61
|
+
else out[key] = "false";
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
if (raw === void 0) {
|
|
65
|
+
if (name) delete out[name];
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
if (name) out[name] = raw;
|
|
69
|
+
else out[key] = raw;
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
const text = (field) => labelOf(field.label, "", "");
|
|
73
|
+
export function propProblem(registry, tag, key, value) {
|
|
74
|
+
return propProblemMessage(registry, tag, key, value)?.message;
|
|
75
|
+
}
|
|
76
|
+
export function propProblemMessage(registry, tag, key, value) {
|
|
77
|
+
const field = registry[tag]?.props[key];
|
|
78
|
+
if (!field) return void 0;
|
|
79
|
+
const raw = rawOf(field, value);
|
|
80
|
+
const label = text(field);
|
|
81
|
+
if (raw === void 0) return field.optional ? void 0 : msg("editor.prop.missing", { label });
|
|
82
|
+
if (raw !== "" && (URL_PROPS.has(key) || field.type === "text" && field.format === "url") && !isSafeHref(raw)) return msg("markdown.unsafeLink");
|
|
83
|
+
if (!field.optional && (field.type === "text" || field.type === "longtext") && raw.trim() === "") return msg("editor.prop.empty", { label });
|
|
84
|
+
const problem = componentPropMessage(field, raw);
|
|
85
|
+
return problem === void 0 ? void 0 : msg("editor.prop.invalid", { label, problem: { key: problem.key, ...problem.params ? { params: problem.params } : {} } });
|
|
86
|
+
}
|
|
87
|
+
export function missingRequired(registry, tag, props) {
|
|
88
|
+
const def = registry[tag];
|
|
89
|
+
if (!def) return [];
|
|
90
|
+
return propFields(def).filter(([key, field]) => !field.optional && propProblem(registry, tag, key, readProp(field, props, key)) !== void 0).map(([key]) => key);
|
|
91
|
+
}
|
|
92
|
+
const TITLE_KEYS = ["caption", "title", "alt", "name", "label"];
|
|
93
|
+
const cut = (text2, max) => text2.length > max ? `${text2.slice(0, max - 1)}\u2026` : text2;
|
|
94
|
+
export function blockSummary(props, def, { label, fileName }) {
|
|
95
|
+
const fields = def ? propFields(def) : [];
|
|
96
|
+
const textOf = (key) => {
|
|
97
|
+
const raw = rawProp(props, key);
|
|
98
|
+
return typeof raw === "string" ? raw.trim() : "";
|
|
99
|
+
};
|
|
100
|
+
const texts = fields.filter(([, field]) => field.type === "text" && field.format !== "url" || field.type === "longtext").map(([key]) => key);
|
|
101
|
+
const titleKey = [...TITLE_KEYS.filter((key) => texts.includes(key) || !def && textOf(key)), ...texts].find((key) => textOf(key));
|
|
102
|
+
const pictures = fields.filter(([key, field]) => field.type === "image" && textOf(key)).map(([key]) => {
|
|
103
|
+
const src = textOf(key);
|
|
104
|
+
const file = fileRefOf(src);
|
|
105
|
+
return { key, src, ...file ? { file } : {} };
|
|
106
|
+
});
|
|
107
|
+
const nameOf = (picture) => (picture.file ? fileName?.(picture.file) : picture.src.split(/[?#]/)[0].split("/").pop()) || void 0;
|
|
108
|
+
const title = titleKey ? textOf(titleKey) : pictures[0] && nameOf(pictures[0]);
|
|
109
|
+
const one = pictures.length === 1 ? ["caption", "alt"].map(textOf).find((text2) => text2 && text2 !== title) ?? (titleKey ? nameOf(pictures[0]) : void 0) : void 0;
|
|
110
|
+
const facts = fields.flatMap(([key, field]) => {
|
|
111
|
+
if (field.type === "choice") {
|
|
112
|
+
const value = textOf(key);
|
|
113
|
+
const option = field.options.find((o) => o.value === value);
|
|
114
|
+
return value && value !== field.default && option ? [label(option.label)] : [];
|
|
115
|
+
}
|
|
116
|
+
if (field.type === "choices") {
|
|
117
|
+
const chosen = readProp(field, props, key);
|
|
118
|
+
return Array.isArray(chosen) && chosen.length ? [chosen.map((value) => label(field.options.find((o) => o.value === value)?.label ?? value)).join(", ")] : [];
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}).slice(0, 3);
|
|
122
|
+
return {
|
|
123
|
+
...title ? { title: cut(title, 80) } : {},
|
|
124
|
+
facts,
|
|
125
|
+
pictures: pictures.map((picture) => {
|
|
126
|
+
const note = pictures.length === 1 ? one : nameOf(picture);
|
|
127
|
+
return { ...picture, ...note && note !== title ? { note: cut(note, 120) } : {} };
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export const propMax = (field) => {
|
|
132
|
+
const max = field.type === "text" || field.type === "longtext" ? effectiveMax(field) : void 0;
|
|
133
|
+
return max !== void 0 && Number.isFinite(max) ? max : void 0;
|
|
134
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComponentRegistry } from '@lupinum/ginko/internal';
|
|
2
|
+
import type { Json } from '@lupinum/ginko';
|
|
3
|
+
/** A ProseMirror node as JSON (`editor.getJSON()`). */
|
|
4
|
+
export interface GinkoDocNode {
|
|
5
|
+
type: string;
|
|
6
|
+
attrs?: Record<string, any>;
|
|
7
|
+
content?: GinkoDocNode[];
|
|
8
|
+
marks?: Array<{
|
|
9
|
+
type: string;
|
|
10
|
+
attrs?: Record<string, any>;
|
|
11
|
+
}>;
|
|
12
|
+
text?: string;
|
|
13
|
+
}
|
|
14
|
+
export type GinkoDoc = GinkoDocNode & {
|
|
15
|
+
type: 'doc';
|
|
16
|
+
};
|
|
17
|
+
export interface ToDocOptions {
|
|
18
|
+
/** With a registry, a component of kind `inline` sits inside a paragraph, one of kind `block` stands alone. */
|
|
19
|
+
components?: ComponentRegistry;
|
|
20
|
+
/** The Markdown text of a node the editor cannot show (a `raw` node), for display. */
|
|
21
|
+
sourceOf?: (node: Json) => string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function toEditorDoc(nodes: readonly Json[], options?: ToDocOptions): GinkoDoc;
|
|
24
|
+
export declare function fromEditorDoc(doc: GinkoDocNode): Json[];
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const INLINE_TAGS = /* @__PURE__ */ new Set(["strong", "em", "del", "code", "a", "br", "img", "input"]);
|
|
2
|
+
const MARK_OF = { strong: "bold", em: "italic", del: "strike", code: "code", a: "link" };
|
|
3
|
+
const TAG_OF_MARK = { bold: "strong", italic: "em", strike: "del", code: "code", link: "a" };
|
|
4
|
+
const MARK_RANK = { link: 0, bold: 1, italic: 2, strike: 3, code: 4 };
|
|
5
|
+
const PLAIN_BLOCKS = /* @__PURE__ */ new Set(["li", "thead", "tbody", "tr", "th", "td", "sup", "section", "code"]);
|
|
6
|
+
const isTuple = (n) => Array.isArray(n);
|
|
7
|
+
const tagOf = (n) => isTuple(n) ? n[0] : void 0;
|
|
8
|
+
const propsOf = (n) => n[1] ?? {};
|
|
9
|
+
const childrenOf = (n) => n.slice(2);
|
|
10
|
+
const classes = (props) => String(props.class ?? "").split(/\s+/);
|
|
11
|
+
function split(props, keys) {
|
|
12
|
+
const rest = {};
|
|
13
|
+
const own = {};
|
|
14
|
+
for (const [k, v] of Object.entries(props)) (keys.includes(k) ? own : rest)[k] = v;
|
|
15
|
+
return [rest, own];
|
|
16
|
+
}
|
|
17
|
+
function join(props, own) {
|
|
18
|
+
const out = { ...props ?? {} };
|
|
19
|
+
for (const [k, v] of Object.entries(own)) if (v !== null && v !== void 0) out[k] = v;
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export function toEditorDoc(nodes, options = {}) {
|
|
23
|
+
const kindOf = (tag) => options.components && Object.hasOwn(options.components, tag) ? options.components[tag].kind : void 0;
|
|
24
|
+
const isInline = (n, inInline) => {
|
|
25
|
+
if (typeof n === "string") return true;
|
|
26
|
+
if (!isTuple(n)) return false;
|
|
27
|
+
const tag = n[0];
|
|
28
|
+
if (tag === null) return true;
|
|
29
|
+
if (INLINE_TAGS.has(tag)) return true;
|
|
30
|
+
if (tag === "math") return classes(propsOf(n)).includes("inline");
|
|
31
|
+
const kind = kindOf(tag);
|
|
32
|
+
if (kind) return kind === "inline";
|
|
33
|
+
return inInline && !PLAIN_BLOCKS.has(tag) && tag !== "template";
|
|
34
|
+
};
|
|
35
|
+
const marksWith = (marks, tag, props) => {
|
|
36
|
+
const type = MARK_OF[tag];
|
|
37
|
+
const [rest, own] = tag === "a" ? split(props, ["href", "title"]) : [props, {}];
|
|
38
|
+
const attrs = { props: rest, order: marks?.length ?? 0 };
|
|
39
|
+
if (tag === "a") {
|
|
40
|
+
attrs.href = own.href ?? "";
|
|
41
|
+
attrs.title = own.title ?? null;
|
|
42
|
+
}
|
|
43
|
+
return [...marks ?? [], { type, attrs }];
|
|
44
|
+
};
|
|
45
|
+
const inlines = (children, marks = void 0) => {
|
|
46
|
+
const out = [];
|
|
47
|
+
const put = (node) => {
|
|
48
|
+
if (marks?.length) node.marks = marks;
|
|
49
|
+
out.push(node);
|
|
50
|
+
};
|
|
51
|
+
for (const child of children) {
|
|
52
|
+
if (typeof child === "string") {
|
|
53
|
+
if (child !== "") put({ type: "text", text: child });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!isTuple(child) || child[0] === null) continue;
|
|
57
|
+
const tag = child[0];
|
|
58
|
+
const props = propsOf(child);
|
|
59
|
+
const kids = childrenOf(child);
|
|
60
|
+
if (tag === "br") put({ type: "hardBreak", attrs: { props } });
|
|
61
|
+
else if (tag === "img") {
|
|
62
|
+
const [rest, own] = split(props, ["src", "alt", "title"]);
|
|
63
|
+
put({ type: "image", attrs: { src: own.src ?? "", alt: own.alt ?? null, title: own.title ?? null, props: rest } });
|
|
64
|
+
} else if (tag === "input") {
|
|
65
|
+
const [rest] = split(props, [":checked"]);
|
|
66
|
+
put({ type: "taskCheckbox", attrs: { checked: ":checked" in props, props: rest } });
|
|
67
|
+
} else if (tag === "math") put({ type: "mathInline", attrs: { text: String(kids[0] ?? ""), props } });
|
|
68
|
+
else if (MARK_OF[tag]) out.push(...inlines(kids, marksWith(marks, tag, props)));
|
|
69
|
+
else {
|
|
70
|
+
const node = { type: "inlineComponent", attrs: { tag, props } };
|
|
71
|
+
const content = inlines(kids);
|
|
72
|
+
if (content.length) node.content = content;
|
|
73
|
+
put(node);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
};
|
|
78
|
+
const paragraph = (children, bare, props = {}) => {
|
|
79
|
+
const content = inlines(children);
|
|
80
|
+
return { type: "paragraph", attrs: { bare, props }, ...content.length ? { content } : {} };
|
|
81
|
+
};
|
|
82
|
+
const blocks = (children) => {
|
|
83
|
+
const out = [];
|
|
84
|
+
let run = [];
|
|
85
|
+
const flush = () => {
|
|
86
|
+
if (run.length) out.push(paragraph(run, true));
|
|
87
|
+
run = [];
|
|
88
|
+
};
|
|
89
|
+
for (const child of children) {
|
|
90
|
+
if (isInline(child, false)) {
|
|
91
|
+
run.push(child);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
flush();
|
|
95
|
+
out.push(block(child));
|
|
96
|
+
}
|
|
97
|
+
flush();
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
100
|
+
const raw = (node) => ({ type: "raw", attrs: { node, markdown: options.sourceOf?.(node) ?? "" } });
|
|
101
|
+
const block = (node) => {
|
|
102
|
+
if (!isTuple(node) || typeof node[0] !== "string") return raw(node);
|
|
103
|
+
const tag = node[0];
|
|
104
|
+
const props = propsOf(node);
|
|
105
|
+
const kids = childrenOf(node);
|
|
106
|
+
const withContent = (type, attrs, content) => ({ type, attrs, ...content.length ? { content } : {} });
|
|
107
|
+
if (tag === "p") return paragraph(kids, false, props);
|
|
108
|
+
if (/^h[1-6]$/.test(tag)) return withContent("heading", { level: Number(tag[1]), props }, inlines(kids));
|
|
109
|
+
if (tag === "hr") return { type: "horizontalRule", attrs: { props } };
|
|
110
|
+
if (tag === "ul" || tag === "ol") {
|
|
111
|
+
if (!kids.every((k) => tagOf(k) === "li")) return raw(node);
|
|
112
|
+
return withContent(tag === "ul" ? "bulletList" : "orderedList", { props }, kids.map((li) => {
|
|
113
|
+
const t = li;
|
|
114
|
+
return withContent("listItem", { props: propsOf(t) }, blocks(childrenOf(t)));
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
if (tag === "blockquote") {
|
|
118
|
+
if (typeof props.as === "string") {
|
|
119
|
+
const { as, ...rest } = props;
|
|
120
|
+
return withContent("alert", { type: as, props: rest }, blocks(kids));
|
|
121
|
+
}
|
|
122
|
+
return withContent("blockquote", { props }, blocks(kids));
|
|
123
|
+
}
|
|
124
|
+
if (tag === "pre") {
|
|
125
|
+
const code = kids[0];
|
|
126
|
+
if (kids.length !== 1 || tagOf(code) !== "code" || !childrenOf(code).every((c) => typeof c === "string")) return raw(node);
|
|
127
|
+
const [rest, own] = split(props, ["language", "filename"]);
|
|
128
|
+
const text = childrenOf(code).join("");
|
|
129
|
+
return withContent("codeBlock", { language: own.language ?? null, filename: own.filename ?? null, props: rest, codeProps: propsOf(code) }, text ? [{ type: "text", text }] : []);
|
|
130
|
+
}
|
|
131
|
+
if (tag === "mermaid") {
|
|
132
|
+
const text = String(props.content ?? "");
|
|
133
|
+
return withContent("mermaid", { props: split(props, ["content"])[0] }, text ? [{ type: "text", text }] : []);
|
|
134
|
+
}
|
|
135
|
+
if (tag === "math") {
|
|
136
|
+
const text = String(kids[0] ?? props.content ?? "");
|
|
137
|
+
return withContent("mathBlock", { props: split(props, ["content"])[0] }, text ? [{ type: "text", text }] : []);
|
|
138
|
+
}
|
|
139
|
+
if (tag === "table") {
|
|
140
|
+
const sections = kids.filter((k) => isTuple(k));
|
|
141
|
+
if (sections.length !== kids.length || sections.some((s) => s[0] !== "thead" && s[0] !== "tbody")) return raw(node);
|
|
142
|
+
const thead = sections.find((s) => s[0] === "thead");
|
|
143
|
+
const tbody = sections.find((s) => s[0] === "tbody");
|
|
144
|
+
const rows = [...thead ? childrenOf(thead) : [], ...tbody ? childrenOf(tbody) : []];
|
|
145
|
+
if (sections.length > 2 || !rows.every((r) => tagOf(r) === "tr")) return raw(node);
|
|
146
|
+
return withContent("table", { props, theadProps: thead ? propsOf(thead) : {}, tbodyProps: tbody ? propsOf(tbody) : {} }, rows.map((row) => {
|
|
147
|
+
const r = row;
|
|
148
|
+
return withContent("tableRow", { props: propsOf(r) }, childrenOf(r).map((cell) => {
|
|
149
|
+
const c = cell;
|
|
150
|
+
const content = blocks(childrenOf(c));
|
|
151
|
+
return withContent(c[0] === "th" ? "tableHeader" : "tableCell", { props: propsOf(c) }, content.length ? content : [{ type: "paragraph", attrs: { props: {}, bare: true } }]);
|
|
152
|
+
}));
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
if (tag === "template") {
|
|
156
|
+
const [rest, own] = split(props, ["name"]);
|
|
157
|
+
return withContent("slot", { name: String(own.name ?? "default"), props: rest }, blocks(kids));
|
|
158
|
+
}
|
|
159
|
+
if (PLAIN_BLOCKS.has(tag)) return raw(node);
|
|
160
|
+
return withContent("component", { tag, props }, blocks(kids));
|
|
161
|
+
};
|
|
162
|
+
return { type: "doc", content: blocks(nodes) };
|
|
163
|
+
}
|
|
164
|
+
export function fromEditorDoc(doc) {
|
|
165
|
+
const propsAttr = (n) => ({ ...n.attrs?.props ?? {} });
|
|
166
|
+
const inlines = (content = []) => {
|
|
167
|
+
const root = [null, {}];
|
|
168
|
+
let open = [];
|
|
169
|
+
for (const child of content) {
|
|
170
|
+
const marks = [...child.marks ?? []].sort((a, b) => (a.attrs?.order ?? 100 + (MARK_RANK[a.type] ?? 9)) - (b.attrs?.order ?? 100 + (MARK_RANK[b.type] ?? 9)));
|
|
171
|
+
const keys = marks.map((m) => `${m.type}${JSON.stringify([m.attrs?.href, m.attrs?.title, m.attrs?.props])}`);
|
|
172
|
+
let common = 0;
|
|
173
|
+
while (common < open.length && common < keys.length && open[common].key === keys[common]) common++;
|
|
174
|
+
open = open.slice(0, common);
|
|
175
|
+
for (let i = common; i < marks.length; i++) {
|
|
176
|
+
const m = marks[i];
|
|
177
|
+
const props = m.type === "link" ? join({ ...m.attrs?.props ?? {} }, { href: m.attrs?.href, title: m.attrs?.title }) : { ...m.attrs?.props ?? {} };
|
|
178
|
+
const node = [TAG_OF_MARK[m.type], props];
|
|
179
|
+
(open.length ? open[open.length - 1].node : root).push(node);
|
|
180
|
+
open.push({ key: keys[i], node });
|
|
181
|
+
}
|
|
182
|
+
const target = open.length ? open[open.length - 1].node : root;
|
|
183
|
+
target.push(leaf(child));
|
|
184
|
+
}
|
|
185
|
+
return childrenOf(root);
|
|
186
|
+
};
|
|
187
|
+
const leaf = (n) => {
|
|
188
|
+
const a = n.attrs ?? {};
|
|
189
|
+
switch (n.type) {
|
|
190
|
+
case "text":
|
|
191
|
+
return n.text ?? "";
|
|
192
|
+
case "hardBreak":
|
|
193
|
+
return ["br", propsAttr(n)];
|
|
194
|
+
// Address, description and title first, as the parser writes them; then the rest (a frame: `{aspect="4:3"}`).
|
|
195
|
+
case "image":
|
|
196
|
+
return ["img", { ...join(void 0, { src: a.src, alt: a.alt, title: a.title }), ...propsAttr(n) }];
|
|
197
|
+
case "taskCheckbox":
|
|
198
|
+
return ["input", { ...propsAttr(n), ...a.checked ? { ":checked": "true" } : {} }];
|
|
199
|
+
case "mathInline":
|
|
200
|
+
return ["math", { ...propsAttr(n), ..."content" in propsAttr(n) ? { content: a.text } : {} }, a.text ?? ""];
|
|
201
|
+
case "inlineComponent":
|
|
202
|
+
return [a.tag, propsAttr(n), ...inlines(n.content)];
|
|
203
|
+
default:
|
|
204
|
+
return ["span", {}, n.text ?? ""];
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const text = (n) => (n.content ?? []).map((c) => c.text ?? "").join("");
|
|
208
|
+
const blocks = (content = [], bareOk) => {
|
|
209
|
+
const out = [];
|
|
210
|
+
let prevBare = false;
|
|
211
|
+
for (const n of content) {
|
|
212
|
+
if (n.type === "paragraph" && n.attrs?.bare && bareOk && !prevBare && n.content?.length) {
|
|
213
|
+
out.push(...inlines(n.content));
|
|
214
|
+
prevBare = true;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
prevBare = false;
|
|
218
|
+
out.push(block(n));
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
};
|
|
222
|
+
const block = (n) => {
|
|
223
|
+
const a = n.attrs ?? {};
|
|
224
|
+
const props = propsAttr(n);
|
|
225
|
+
switch (n.type) {
|
|
226
|
+
case "paragraph":
|
|
227
|
+
return ["p", props, ...inlines(n.content)];
|
|
228
|
+
case "heading":
|
|
229
|
+
return [`h${a.level}`, props, ...inlines(n.content)];
|
|
230
|
+
case "horizontalRule":
|
|
231
|
+
return ["hr", props];
|
|
232
|
+
case "bulletList":
|
|
233
|
+
return ["ul", props, ...(n.content ?? []).map(block)];
|
|
234
|
+
case "orderedList":
|
|
235
|
+
return ["ol", props, ...(n.content ?? []).map(block)];
|
|
236
|
+
case "listItem":
|
|
237
|
+
return ["li", props, ...blocks(n.content, true)];
|
|
238
|
+
case "blockquote":
|
|
239
|
+
return ["blockquote", props, ...blocks(n.content, true)];
|
|
240
|
+
case "alert":
|
|
241
|
+
return ["blockquote", { ...props, as: a.type }, ...blocks(n.content, true)];
|
|
242
|
+
case "codeBlock":
|
|
243
|
+
return ["pre", join(props, { language: a.language, filename: a.filename }), ["code", { ...a.codeProps ?? {} }, text(n)]];
|
|
244
|
+
case "mermaid":
|
|
245
|
+
return ["mermaid", { ...props, content: text(n) }];
|
|
246
|
+
case "mathBlock":
|
|
247
|
+
return ["math", { ...props, content: text(n) }, text(n)];
|
|
248
|
+
case "table": {
|
|
249
|
+
const rows = n.content ?? [];
|
|
250
|
+
const head = rows.findIndex((r) => (r.content ?? []).some((c) => c.type !== "tableHeader"));
|
|
251
|
+
const headRows = rows.slice(0, head === -1 ? rows.length : head);
|
|
252
|
+
const bodyRows = rows.slice(headRows.length);
|
|
253
|
+
return [
|
|
254
|
+
"table",
|
|
255
|
+
props,
|
|
256
|
+
...headRows.length ? [["thead", { ...a.theadProps }, ...headRows.map(block)]] : [],
|
|
257
|
+
...bodyRows.length ? [["tbody", { ...a.tbodyProps }, ...bodyRows.map(block)]] : []
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
case "tableRow":
|
|
261
|
+
return ["tr", props, ...(n.content ?? []).map(block)];
|
|
262
|
+
// An empty paragraph is the room to type in an empty cell (see toEditorDoc), not text.
|
|
263
|
+
case "tableHeader":
|
|
264
|
+
return ["th", props, ...blocks(n.content?.filter((c) => c.type !== "paragraph" || c.content?.length), true)];
|
|
265
|
+
case "tableCell":
|
|
266
|
+
return ["td", props, ...blocks(n.content?.filter((c) => c.type !== "paragraph" || c.content?.length), true)];
|
|
267
|
+
case "component":
|
|
268
|
+
return [a.tag, props, ...blocks(n.content, true)];
|
|
269
|
+
case "slot":
|
|
270
|
+
return ["template", { ...props, name: a.name }, ...blocks(n.content, true)];
|
|
271
|
+
case "raw":
|
|
272
|
+
return a.node;
|
|
273
|
+
default:
|
|
274
|
+
return ["p", {}, ...inlines([n])];
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
return blocks(doc.content, false);
|
|
278
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ComponentRegistry, Described, MarkdownProfile } from '@lupinum/ginko/internal';
|
|
2
|
+
import { Editor, type AnyExtension } from '@tiptap/core';
|
|
3
|
+
import { type GinkoExtensionsOptions } from './extensions.js';
|
|
4
|
+
export interface GinkoEditorOptions {
|
|
5
|
+
/** The Markdown text of the field (a body, no frontmatter). */
|
|
6
|
+
text: string;
|
|
7
|
+
profile: MarkdownProfile;
|
|
8
|
+
components?: ComponentRegistry;
|
|
9
|
+
/** Where TipTap mounts. Without it the editor works on a detached element (tests, no UI yet). */
|
|
10
|
+
element?: HTMLElement;
|
|
11
|
+
/**
|
|
12
|
+
* Lets the UI add to or replace extensions (node views, key bindings, the slash menu). It must not change
|
|
13
|
+
* the schema: nodes and marks come from `ginkoExtensions`, an extension may only extend those.
|
|
14
|
+
*/
|
|
15
|
+
extend?: (extensions: AnyExtension[]) => AnyExtension[];
|
|
16
|
+
/** Pictures that were pasted or dropped (files, and the position they belong at). Return true when the UI takes them. */
|
|
17
|
+
onImageFiles?: GinkoExtensionsOptions['onImageFiles'];
|
|
18
|
+
/** A bare address was pasted on an empty line and became a link: the UI may offer to turn it into a link card. */
|
|
19
|
+
onUrlPasted?: GinkoExtensionsOptions['onUrlPasted'];
|
|
20
|
+
/** The library files of `$file.<id>` pictures, so the editor can show them (see `useFileImages`). */
|
|
21
|
+
fileImages?: GinkoExtensionsOptions['fileImages'];
|
|
22
|
+
/** Open as Markdown source although the text could be shown rich (the person chose the source view). */
|
|
23
|
+
forceSource?: boolean;
|
|
24
|
+
/** False shows the text without letting anyone change it (the main-language text beside a translation). Default true. */
|
|
25
|
+
editable?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface Base {
|
|
28
|
+
profile: MarkdownProfile;
|
|
29
|
+
/** Why the text is not opened as a rich document (source mode), or what the profile does not allow. Empty in rich mode. */
|
|
30
|
+
problems: string[];
|
|
31
|
+
/** The same problems with catalog key and parameters, in the same order: the UI translates them with `coreMessage(locale, key, params)`. */
|
|
32
|
+
problemMessages: Described[];
|
|
33
|
+
/** True once the content really differs from what was opened. Typing and undoing back to the start is not dirty. */
|
|
34
|
+
readonly dirty: boolean;
|
|
35
|
+
/** The Markdown for the field. Untouched top-level blocks are the original text, byte for byte. */
|
|
36
|
+
markdown(): Promise<string>;
|
|
37
|
+
/** Calls `listener` after every change of the content (and of `dirty`). Returns the function that stops it. */
|
|
38
|
+
onChange(listener: () => void): () => void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
}
|
|
41
|
+
/** The text opened as a TipTap document. */
|
|
42
|
+
export interface GinkoRichEditor extends Base {
|
|
43
|
+
mode: 'rich';
|
|
44
|
+
editor: Editor;
|
|
45
|
+
}
|
|
46
|
+
/** The text cannot be edited as a rich document without changing it: the UI shows a textarea bound to `source`. */
|
|
47
|
+
export interface GinkoSourceEditor extends Base {
|
|
48
|
+
mode: 'source';
|
|
49
|
+
editor?: undefined;
|
|
50
|
+
/** The current text. Set it from the textarea. */
|
|
51
|
+
source: string;
|
|
52
|
+
}
|
|
53
|
+
export type GinkoEditorHandle = GinkoRichEditor | GinkoSourceEditor;
|
|
54
|
+
/**
|
|
55
|
+
* Opens `text`. Rich mode needs three things: the text has no problems for the profile, it survives comark's
|
|
56
|
+
* renderer (`isStableMarkdown`), and it survives the trip into the editor document and back unchanged. If one
|
|
57
|
+
* of them fails, the result is in `source` mode: no document, the text is kept as it is.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createGinkoEditor(options: GinkoEditorOptions): Promise<GinkoEditorHandle>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isStableMarkdown, markdownBlocks, msg, parseMarkdown, serializeMarkdown } from "@lupinum/ginko/internal";
|
|
2
|
+
import { Editor, getSchema } from "@tiptap/core";
|
|
3
|
+
import { Node as PmNode } from "@tiptap/pm/model";
|
|
4
|
+
import { fromEditorDoc, toEditorDoc } from "./convert.js";
|
|
5
|
+
import { ginkoExtensions } from "./extensions.js";
|
|
6
|
+
const sameJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
7
|
+
export async function createGinkoEditor(options) {
|
|
8
|
+
const { text, profile, components, element, extend, onImageFiles, onUrlPasted, fileImages, forceSource, editable = true } = options;
|
|
9
|
+
const parseOptions = { profile, components };
|
|
10
|
+
const parsed = await parseMarkdown(text, parseOptions);
|
|
11
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
12
|
+
const onChange = (listener) => {
|
|
13
|
+
listeners.add(listener);
|
|
14
|
+
return () => {
|
|
15
|
+
listeners.delete(listener);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const notify = () => listeners.forEach((l) => l());
|
|
19
|
+
const toSource = (problemMessages) => {
|
|
20
|
+
let source = text;
|
|
21
|
+
return {
|
|
22
|
+
mode: "source",
|
|
23
|
+
profile,
|
|
24
|
+
problems: problemMessages.map((p) => p.message),
|
|
25
|
+
problemMessages,
|
|
26
|
+
get source() {
|
|
27
|
+
return source;
|
|
28
|
+
},
|
|
29
|
+
set source(value) {
|
|
30
|
+
source = value;
|
|
31
|
+
notify();
|
|
32
|
+
},
|
|
33
|
+
get dirty() {
|
|
34
|
+
return source !== text;
|
|
35
|
+
},
|
|
36
|
+
markdown: async () => source,
|
|
37
|
+
onChange,
|
|
38
|
+
destroy: () => listeners.clear()
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
if (forceSource || parsed.problems.length) return toSource(parsed.problemMessages);
|
|
42
|
+
if (!await isStableMarkdown(text, parseOptions)) return toSource([msg("editor.source.unstable")]);
|
|
43
|
+
const original = await markdownBlocks(text, parseOptions);
|
|
44
|
+
const nodes = original.nodes;
|
|
45
|
+
const sources = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const block of original.blocks) if (block.nodes.length === 1) sources.set(block.nodes[0], block.source);
|
|
47
|
+
const extensions = (extend ?? ((list) => list))(ginkoExtensions({ profile, components, onImageFiles, onUrlPasted, fileImages }));
|
|
48
|
+
let doc;
|
|
49
|
+
try {
|
|
50
|
+
doc = toEditorDoc(nodes, { components, sourceOf: (node) => sources.get(node) });
|
|
51
|
+
if (nodes.length === 0) doc = { type: "doc", content: [{ type: "paragraph" }] };
|
|
52
|
+
const checked = PmNode.fromJSON(getSchema(extensions), doc);
|
|
53
|
+
checked.check();
|
|
54
|
+
if (nodes.length > 0 && !sameJson(fromEditorDoc(checked.toJSON()), nodes)) return toSource([msg("editor.source.lossy")]);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return toSource([msg("editor.source.failed", { reason: error instanceof Error ? error.message : String(error) })]);
|
|
57
|
+
}
|
|
58
|
+
if (profile !== "inline" && doc.content?.at(-1)?.type !== "paragraph") doc = { ...doc, content: [...doc.content ?? [], { type: "paragraph" }] };
|
|
59
|
+
const editor = new Editor({ element, extensions, content: doc, editable });
|
|
60
|
+
const initial = editor.state.doc;
|
|
61
|
+
editor.on("update", notify);
|
|
62
|
+
return {
|
|
63
|
+
mode: "rich",
|
|
64
|
+
profile,
|
|
65
|
+
problems: [],
|
|
66
|
+
problemMessages: [],
|
|
67
|
+
editor,
|
|
68
|
+
get dirty() {
|
|
69
|
+
return !editor.state.doc.eq(initial);
|
|
70
|
+
},
|
|
71
|
+
async markdown() {
|
|
72
|
+
const current = editor.state.doc;
|
|
73
|
+
if (nodes.length === 0 && current.childCount === 1 && current.firstChild.content.size === 0) return text;
|
|
74
|
+
const json = current.toJSON();
|
|
75
|
+
const content = [...json.content ?? []];
|
|
76
|
+
while (content.length > 1 && content.at(-1).type === "paragraph" && !content.at(-1).content?.length) content.pop();
|
|
77
|
+
return serializeMarkdown(fromEditorDoc({ ...json, content }), { original });
|
|
78
|
+
},
|
|
79
|
+
onChange,
|
|
80
|
+
destroy() {
|
|
81
|
+
listeners.clear();
|
|
82
|
+
editor.destroy();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ComponentRegistry, MarkdownProfile } from '@lupinum/ginko/internal';
|
|
2
|
+
import { type AnyExtension, type Editor } from '@tiptap/core';
|
|
3
|
+
import { type EditorState, type Transaction } from '@tiptap/pm/state';
|
|
4
|
+
import type { FileImages } from '../assets.js';
|
|
5
|
+
import { type PasteOptions } from './paste.js';
|
|
6
|
+
export interface GinkoExtensionsOptions {
|
|
7
|
+
profile: MarkdownProfile;
|
|
8
|
+
/** The site's component registry (`page` profile). The generic component nodes keep it as an option for the UI. */
|
|
9
|
+
components?: ComponentRegistry;
|
|
10
|
+
/** What the UI does with pasted or dropped pictures and a pasted bare address (see ./paste.ts). */
|
|
11
|
+
onImageFiles?: PasteOptions['onImageFiles'];
|
|
12
|
+
onUrlPasted?: PasteOptions['onUrlPasted'];
|
|
13
|
+
/** The library files of `$file.<id>` pictures: with it, a picture shows its file (the text keeps the reference). */
|
|
14
|
+
fileImages?: FileImages;
|
|
15
|
+
}
|
|
16
|
+
export interface ComponentNodeOptions {
|
|
17
|
+
components?: ComponentRegistry;
|
|
18
|
+
}
|
|
19
|
+
/** The checkbox of a task list item (`- [ ] text`), as the parser writes it. A new one from the slash menu or Enter copies it. */
|
|
20
|
+
export declare const TASK_CHECKBOX_PROPS: {
|
|
21
|
+
class: string;
|
|
22
|
+
type: string;
|
|
23
|
+
':disabled': string;
|
|
24
|
+
};
|
|
25
|
+
/** Whether the cursor is in a checklist item. */
|
|
26
|
+
export declare const isTaskItem: (state: EditorState) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Turns the block at the cursor into a checklist, or a checklist back into a bulleted list. Text or a bulleted list gets an empty
|
|
29
|
+
* box in front of each item; the node shapes are the parser's, so the text reads `- [ ] item`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toggleTaskList(editor: Editor): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* ArrowDown at the end of the text, or Enter in an empty last paragraph, leaves the component: the cursor goes to
|
|
34
|
+
* the next block (a paragraph is added when there is none). Without it the cursor cannot leave a box at the end of a text.
|
|
35
|
+
*/
|
|
36
|
+
export declare function leaveComponent(state: EditorState, key: 'ArrowDown' | 'Enter'): ((tr: Transaction) => void) | undefined;
|
|
37
|
+
/** The extensions for exactly what `profile` allows (see `describeProfile` in @lupinum/ginko). */
|
|
38
|
+
export declare function ginkoExtensions(options: GinkoExtensionsOptions): AnyExtension[];
|