@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.
Files changed (166) hide show
  1. package/CHANGELOG.md +7 -73
  2. package/LICENSE +1 -1
  3. package/README.md +15 -340
  4. package/dist/assets.d.ts +70 -0
  5. package/dist/assets.js +31 -0
  6. package/dist/core/component-props.d.ts +87 -0
  7. package/dist/core/component-props.js +134 -0
  8. package/dist/core/convert.d.ts +24 -0
  9. package/dist/core/convert.js +278 -0
  10. package/dist/core/editor.d.ts +60 -0
  11. package/dist/core/editor.js +85 -0
  12. package/dist/core/extensions.d.ts +38 -0
  13. package/dist/core/extensions.js +444 -0
  14. package/dist/core/file-images.d.ts +9 -0
  15. package/dist/core/file-images.js +54 -0
  16. package/dist/core/image-frame.d.ts +23 -0
  17. package/dist/core/image-frame.js +24 -0
  18. package/dist/core/index.d.ts +17 -0
  19. package/dist/core/index.js +17 -0
  20. package/dist/core/link-card.d.ts +20 -0
  21. package/dist/core/link-card.js +70 -0
  22. package/dist/core/link.d.ts +3 -0
  23. package/dist/core/link.js +8 -0
  24. package/dist/core/move.d.ts +11 -0
  25. package/dist/core/move.js +37 -0
  26. package/dist/core/paste-html.d.ts +6 -0
  27. package/dist/core/paste-html.js +384 -0
  28. package/dist/core/paste.d.ts +21 -0
  29. package/dist/core/paste.js +108 -0
  30. package/dist/core/problems.d.ts +31 -0
  31. package/dist/core/problems.js +54 -0
  32. package/dist/core/search.d.ts +47 -0
  33. package/dist/core/search.js +148 -0
  34. package/dist/core/slash.d.ts +93 -0
  35. package/dist/core/slash.js +215 -0
  36. package/dist/core/table.d.ts +34 -0
  37. package/dist/core/table.js +141 -0
  38. package/dist/core/uploads.d.ts +23 -0
  39. package/dist/core/uploads.js +71 -0
  40. package/dist/core/use-editor.d.ts +19 -0
  41. package/dist/core/use-editor.js +53 -0
  42. package/dist/index.d.ts +6 -15
  43. package/dist/index.js +6 -5668
  44. package/dist/issues.d.ts +49 -0
  45. package/dist/issues.js +9 -0
  46. package/dist/today.d.ts +6 -0
  47. package/dist/today.js +19 -0
  48. package/dist/useUpload.d.ts +48 -0
  49. package/dist/useUpload.js +59 -0
  50. package/dist/values.d.ts +14 -0
  51. package/dist/values.js +36 -0
  52. package/package.json +35 -95
  53. package/dist/GinkoEditor.vue.d.ts +0 -96
  54. package/dist/GinkoImagePicker.vue.d.ts +0 -36
  55. package/dist/agent/AGENTS.md +0 -13
  56. package/dist/agent/pages/docs/getting-started/collaboration.md +0 -435
  57. package/dist/agent/pages/docs/getting-started/component-coverage.md +0 -107
  58. package/dist/agent/pages/docs/getting-started/customize.md +0 -384
  59. package/dist/agent/pages/docs/getting-started/images.md +0 -188
  60. package/dist/agent/pages/docs/getting-started/in-place-editing.md +0 -110
  61. package/dist/agent/pages/docs/getting-started/layout-blocks.md +0 -148
  62. package/dist/agent/pages/docs/getting-started/runtime.md +0 -111
  63. package/dist/agent/pages/docs/getting-started.md +0 -128
  64. package/dist/authoring-D7MJezVG.js +0 -1780
  65. package/dist/authoring-D7MJezVG.js.map +0 -1
  66. package/dist/authoring.d.ts +0 -122
  67. package/dist/authoring.js +0 -2
  68. package/dist/collaboration.d.ts +0 -14
  69. package/dist/collaboration.js +0 -907
  70. package/dist/collaboration.js.map +0 -1
  71. package/dist/composables/useAssetRequests.d.ts +0 -44
  72. package/dist/composables/useCollaborationBinding.d.ts +0 -59
  73. package/dist/composables/useDevice.d.ts +0 -10
  74. package/dist/composables/useInsertMenu.d.ts +0 -67
  75. package/dist/composables/useMarkdownSync.d.ts +0 -96
  76. package/dist/composables/useStableAuthoringKit.d.ts +0 -16
  77. package/dist/documentConfig-Z6LdrWZj.js +0 -2360
  78. package/dist/documentConfig-Z6LdrWZj.js.map +0 -1
  79. package/dist/editorProps.d.ts +0 -124
  80. package/dist/index.js.map +0 -1
  81. package/dist/layout-kit.d.ts +0 -922
  82. package/dist/lib/collaboration/presence-record.d.ts +0 -18
  83. package/dist/lib/collaboration/presence.d.ts +0 -103
  84. package/dist/lib/collaboration/protocol.d.ts +0 -133
  85. package/dist/lib/collaboration/recovery.d.ts +0 -45
  86. package/dist/lib/collaboration/session.d.ts +0 -163
  87. package/dist/lib/collaboration/validation.d.ts +0 -42
  88. package/dist/lib/component-converters.d.ts +0 -119
  89. package/dist/lib/config/documentConfig.d.ts +0 -19
  90. package/dist/lib/config/editorConfig.d.ts +0 -38
  91. package/dist/lib/container-items.d.ts +0 -55
  92. package/dist/lib/conversionInvariants.d.ts +0 -3
  93. package/dist/lib/conversionLogger.d.ts +0 -10
  94. package/dist/lib/conversionPipeline.d.ts +0 -17
  95. package/dist/lib/conversionState.d.ts +0 -10
  96. package/dist/lib/conversionTypes.d.ts +0 -50
  97. package/dist/lib/editor-operations.d.ts +0 -39
  98. package/dist/lib/environment.d.ts +0 -6
  99. package/dist/lib/extensions/code-block.d.ts +0 -18
  100. package/dist/lib/extensions/component-boundary.d.ts +0 -9
  101. package/dist/lib/extensions/container-items.d.ts +0 -29
  102. package/dist/lib/extensions/element.d.ts +0 -19
  103. package/dist/lib/extensions/file.d.ts +0 -24
  104. package/dist/lib/extensions/heading.d.ts +0 -5
  105. package/dist/lib/extensions/image-upload.d.ts +0 -39
  106. package/dist/lib/extensions/image.d.ts +0 -39
  107. package/dist/lib/extensions/index.d.ts +0 -10
  108. package/dist/lib/extensions/inline-element.d.ts +0 -13
  109. package/dist/lib/extensions/markdown-clipboard.d.ts +0 -21
  110. package/dist/lib/extensions/profile.d.ts +0 -11
  111. package/dist/lib/extensions/slot.d.ts +0 -16
  112. package/dist/lib/extensions/span-style.d.ts +0 -15
  113. package/dist/lib/extensions/video.d.ts +0 -15
  114. package/dist/lib/image-properties.d.ts +0 -20
  115. package/dist/lib/input-rules.d.ts +0 -7
  116. package/dist/lib/markdown.d.ts +0 -11
  117. package/dist/lib/marks.d.ts +0 -7
  118. package/dist/lib/mdcToTiptap.d.ts +0 -20
  119. package/dist/lib/mdcTypes.d.ts +0 -20
  120. package/dist/lib/nodes.d.ts +0 -57
  121. package/dist/lib/nodeviews/block-actions.d.ts +0 -7
  122. package/dist/lib/nodeviews/code.d.ts +0 -4
  123. package/dist/lib/nodeviews/columns.d.ts +0 -17
  124. package/dist/lib/nodeviews/component.d.ts +0 -6
  125. package/dist/lib/nodeviews/icons.d.ts +0 -26
  126. package/dist/lib/nodeviews/image.d.ts +0 -9
  127. package/dist/lib/nodeviews/items.d.ts +0 -15
  128. package/dist/lib/nodeviews/lifecycle.d.ts +0 -45
  129. package/dist/lib/nodeviews/popover.d.ts +0 -15
  130. package/dist/lib/nodeviews/settings.d.ts +0 -11
  131. package/dist/lib/nodeviews/table-operations.d.ts +0 -50
  132. package/dist/lib/nodeviews/table.d.ts +0 -4
  133. package/dist/lib/profiles.d.ts +0 -62
  134. package/dist/lib/property-input.d.ts +0 -10
  135. package/dist/lib/property-step.d.ts +0 -77
  136. package/dist/lib/props.d.ts +0 -13
  137. package/dist/lib/stripStyleNodes.d.ts +0 -2
  138. package/dist/lib/tiptapToMdc.d.ts +0 -18
  139. package/dist/presence-record-CLdPZWKC.js +0 -291
  140. package/dist/presence-record-CLdPZWKC.js.map +0 -1
  141. package/dist/runtime.d.ts +0 -13
  142. package/dist/runtime.js +0 -3
  143. package/dist/style.css +0 -2
  144. package/dist/types.d.ts +0 -126
  145. package/dist/ui/GinkoActionButton.vue.d.ts +0 -8
  146. package/dist/ui/GinkoInsertMenu.vue.d.ts +0 -49
  147. package/dist/ui/GinkoKeyboardDock.vue.d.ts +0 -15
  148. package/dist/ui/GinkoNodePopover.vue.d.ts +0 -21
  149. package/dist/ui/GinkoRecipeIcon.vue.d.ts +0 -6
  150. package/dist/ui/GinkoSelectionToolbar.vue.d.ts +0 -10
  151. package/dist/ui/GinkoToolbar.vue.d.ts +0 -26
  152. package/dist/ui/GinkoToolbarIcon.vue.d.ts +0 -6
  153. package/dist/ui/block-shortcuts.d.ts +0 -6
  154. package/dist/ui/commands.d.ts +0 -78
  155. package/dist/ui/context.d.ts +0 -23
  156. package/dist/ui/editor-keyboard.d.ts +0 -15
  157. package/dist/ui/messages.d.ts +0 -214
  158. package/dist/ui/messages.de.d.ts +0 -6
  159. package/dist/ui/recipe-command.d.ts +0 -14
  160. package/dist/ui/recipe-search.d.ts +0 -47
  161. package/dist/ui/slash-command.d.ts +0 -17
  162. package/dist/ui/writingRecipes.d.ts +0 -13
  163. package/skills/ginko-editor/SKILL.md +0 -40
  164. package/skills/ginko-editor/agents/openai.yaml +0 -4
  165. package/skills/ginko-editor/references/in-place-editing.md +0 -50
  166. package/skills/ginko-editor/references/quickstart.md +0 -55
@@ -0,0 +1,31 @@
1
+ import type { ComponentRegistry, Described, MarkdownProfile } from '@lupinum/ginko/internal';
2
+ import type { Node as PmNode } from '@tiptap/pm/model';
3
+ /** `message` is German (agents, logs); `key` + `params` are what the UI translates with `coreMessage(locale, key, params)`. */
4
+ export interface BlockProblem extends Described {
5
+ /** Index of the top-level block. */
6
+ index: number;
7
+ }
8
+ export interface SourceProblem extends BlockProblem {
9
+ /** Character offset in the text where the block starts, and its 1-based line. */
10
+ from: number;
11
+ line: number;
12
+ /** The first line of the block, cut short, so the message can say where it is. */
13
+ excerpt: string;
14
+ }
15
+ export interface DocProblem extends BlockProblem {
16
+ /** Position of the node the problem belongs to (a component or an image), in the ProseMirror document. */
17
+ pos: number;
18
+ kind: 'component' | 'image';
19
+ tag?: string;
20
+ }
21
+ /** The problems of `text` for the profile, per block. Empty when the text has none. */
22
+ export declare function sourceProblems(text: string, options: {
23
+ profile: MarkdownProfile;
24
+ components?: ComponentRegistry;
25
+ }): Promise<SourceProblem[]>;
26
+ /**
27
+ * The problems of the open document: components with invalid props, pictures without a description. `described` says
28
+ * whether a picture without its own text still has one (a Files library file with a description in the text's
29
+ * language), the same rule as the save (effective alt).
30
+ */
31
+ export declare function docProblems(doc: PmNode, registry: ComponentRegistry | undefined, described?: (src: string) => boolean): DocProblem[];
@@ -0,0 +1,54 @@
1
+ import { markdownBlocks, msg, parseMarkdown } from "@lupinum/ginko/internal";
2
+ import { propFields, propProblemMessage, readProp } from "./component-props.js";
3
+ export async function sourceProblems(text, options) {
4
+ const { profile, components } = options;
5
+ const whole = await parseMarkdown(text, { profile, components });
6
+ if (!whole.problems.length) return [];
7
+ const { blocks } = await markdownBlocks(text, { profile, components });
8
+ const found = [];
9
+ let cursor = 0;
10
+ for (const [index, block] of blocks.entries()) {
11
+ const at = text.indexOf(block.source, cursor);
12
+ const from = at < 0 ? cursor : at;
13
+ cursor = from + block.source.length;
14
+ const { problemMessages } = await parseMarkdown(block.source, { profile, components });
15
+ const line = text.slice(0, from).split("\n").length;
16
+ const excerpt = block.source.split("\n")[0].slice(0, 60);
17
+ for (const problem of problemMessages) found.push({ ...problem, index, from, line: problem.line === void 0 ? line : line + problem.line - 1, excerpt });
18
+ }
19
+ for (const problem of whole.problemMessages) {
20
+ if (!found.some((p) => p.message === problem.message)) found.push({ ...problem, index: 0, from: 0, line: problem.line ?? 1, excerpt: text.split("\n")[0].slice(0, 60) });
21
+ }
22
+ return found.sort((a, b) => a.index - b.index);
23
+ }
24
+ function componentMessage(registry, tag, props) {
25
+ const def = Object.hasOwn(registry, tag) ? registry[tag] : void 0;
26
+ if (!def) return msg("editor.component.unknown", { tag });
27
+ const problems = propFields(def).map(([key, field]) => propProblemMessage(registry, tag, key, readProp(field, props, key))).filter((m) => m !== void 0);
28
+ const [first, ...rest] = problems;
29
+ if (!first) return void 0;
30
+ if (!rest.length) return first;
31
+ return msg("editor.component.more", { first: { key: first.key, ...first.params ? { params: first.params } : {} }, count: rest.length });
32
+ }
33
+ export function docProblems(doc, registry, described) {
34
+ const found = [];
35
+ doc.forEach((top, offset, index) => {
36
+ top.descendants((node, pos) => {
37
+ const at = offset + pos;
38
+ if (node.type.name === "component" && registry) {
39
+ const tag = String(node.attrs.tag);
40
+ const problem = componentMessage(registry, tag, node.attrs.props ?? {});
41
+ if (problem) found.push({ ...problem, index, pos: at, kind: "component", tag });
42
+ } else if (node.type.name === "image" && !String(node.attrs.alt ?? "").trim() && !described?.(String(node.attrs.src ?? ""))) {
43
+ found.push({ ...msg("editor.problem.imageNoDescription"), index, pos: at, kind: "image" });
44
+ }
45
+ return true;
46
+ });
47
+ if (top.type.name === "component" && registry) {
48
+ const tag = String(top.attrs.tag);
49
+ const problem = componentMessage(registry, tag, top.attrs.props ?? {});
50
+ if (problem) found.push({ ...problem, index, pos: offset, kind: "component", tag });
51
+ }
52
+ });
53
+ return found;
54
+ }
@@ -0,0 +1,47 @@
1
+ import { Extension, type Editor } from '@tiptap/core';
2
+ import type { Node as PmNode } from '@tiptap/pm/model';
3
+ import { PluginKey, type EditorState } from '@tiptap/pm/state';
4
+ export interface SearchMatch {
5
+ from: number;
6
+ to: number;
7
+ }
8
+ export interface SearchState {
9
+ term: string;
10
+ caseSensitive: boolean;
11
+ matches: SearchMatch[];
12
+ /** Index into `matches` of the current match; -1 without matches. */
13
+ current: number;
14
+ }
15
+ export interface SearchOptions {
16
+ caseSensitive?: boolean;
17
+ }
18
+ /** The plugin's state: the search, and a count of the commands that went somewhere, which the plugin view scrolls to. */
19
+ interface PluginState extends SearchState {
20
+ reveals: number;
21
+ }
22
+ export declare const searchKey: PluginKey<PluginState>;
23
+ /** All matches in the text of each textblock. A match does not span two blocks; an inline atom (picture, box) counts as one character that never matches. */
24
+ export declare function findMatches(doc: PmNode, term: string, caseSensitive: boolean): SearchMatch[];
25
+ export declare const getSearch: (state: EditorState) => SearchState;
26
+ declare module '@tiptap/core' {
27
+ interface Commands<ReturnType> {
28
+ ginkoSearch: {
29
+ /** Sets the term (empty clears it). Case-insensitive unless `caseSensitive`. The current match is the first one at or after the cursor; it is selected and scrolled to. */
30
+ setSearch: (term: string, options?: SearchOptions) => ReturnType;
31
+ findNext: () => ReturnType;
32
+ findPrev: () => ReturnType;
33
+ /** Replaces the current match; the next match becomes current. */
34
+ replaceCurrent: (text: string) => ReturnType;
35
+ /** Replaces every match in one transaction: one undo step. The first replaced place is selected and scrolled to. */
36
+ replaceAll: (text: string) => ReturnType;
37
+ };
38
+ }
39
+ }
40
+ export declare const SearchExtension: Extension<any, any>;
41
+ /** Term, match count and current match (1-based, 0 without matches), for a counter like "3 von 7". */
42
+ export declare function searchInfo(editor: Editor): {
43
+ term: string;
44
+ total: number;
45
+ current: number;
46
+ };
47
+ export {};
@@ -0,0 +1,148 @@
1
+ import { Extension } from "@tiptap/core";
2
+ import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
3
+ import { Decoration, DecorationSet } from "@tiptap/pm/view";
4
+ const EMPTY = { term: "", caseSensitive: false, matches: [], current: -1, reveals: 0 };
5
+ export const searchKey = new PluginKey("ginkoSearch");
6
+ const REVEAL = "ginkoSearchReveal";
7
+ export function findMatches(doc, term, caseSensitive) {
8
+ if (!term) return [];
9
+ const needle = caseSensitive ? term : term.toLowerCase();
10
+ const found = [];
11
+ doc.descendants((node, pos) => {
12
+ if (!node.isTextblock) return true;
13
+ const text = node.textBetween(0, node.content.size, void 0, "\uFFFC");
14
+ const haystack = caseSensitive ? text : text.toLowerCase();
15
+ const hay = haystack.length === text.length ? haystack : text;
16
+ const pin = haystack.length === text.length ? needle : term;
17
+ for (let at = hay.indexOf(pin); at !== -1; at = hay.indexOf(pin, at + pin.length)) {
18
+ found.push({ from: pos + 1 + at, to: pos + 1 + at + pin.length });
19
+ }
20
+ return false;
21
+ });
22
+ return found;
23
+ }
24
+ const clamp = (index, total) => total === 0 ? -1 : Math.min(Math.max(index, 0), total - 1);
25
+ function build(doc, term, caseSensitive, current) {
26
+ const matches = findMatches(doc, term, caseSensitive);
27
+ return { term, caseSensitive, matches, current: clamp(current, matches.length) };
28
+ }
29
+ const nearest = (matches, from) => {
30
+ const i = matches.findIndex((m) => m.to > from);
31
+ return matches.length ? i === -1 ? 0 : i : -1;
32
+ };
33
+ export const getSearch = (state) => searchKey.getState(state) ?? EMPTY;
34
+ const selectRange = (tr, from, to) => tr.setSelection(TextSelection.create(tr.doc, from, to)).setMeta(REVEAL, true);
35
+ const select = (tr, match) => match ? selectRange(tr, match.from, match.to) : tr;
36
+ const side = (value, name, fallback) => value === void 0 ? fallback : typeof value === "number" ? value : value[name];
37
+ function scrollToPos(view, pos) {
38
+ let rect = view.coordsAtPos(pos);
39
+ const threshold = view.someProp("scrollThreshold");
40
+ const margin = view.someProp("scrollMargin");
41
+ const win = view.dom.ownerDocument.defaultView;
42
+ if (!win) return;
43
+ for (let el = view.dom.parentElement; el; el = el.parentElement) {
44
+ const atTop = el === win.document.body;
45
+ const box = atTop ? { top: 0, left: 0, bottom: win.innerHeight, right: win.innerWidth } : el.getBoundingClientRect();
46
+ const move = (start, end) => {
47
+ if (rect[start] < box[start] + side(threshold, start, 0)) return rect[start] - box[start] - side(margin, start, 5);
48
+ if (rect[end] > box[end] - side(threshold, end, 0)) return rect[end] - box[end] + side(margin, end, 5);
49
+ return 0;
50
+ };
51
+ const dy = move("top", "bottom");
52
+ const dx = move("left", "right");
53
+ if (atTop) {
54
+ if (dx || dy) win.scrollBy(dx, dy);
55
+ break;
56
+ }
57
+ const { scrollTop, scrollLeft } = el;
58
+ el.scrollTop += dy;
59
+ el.scrollLeft += dx;
60
+ const movedY = el.scrollTop - scrollTop;
61
+ const movedX = el.scrollLeft - scrollLeft;
62
+ rect = { top: rect.top - movedY, bottom: rect.bottom - movedY, left: rect.left - movedX, right: rect.right - movedX };
63
+ if (getComputedStyle(el).position === "fixed") break;
64
+ }
65
+ }
66
+ function go(state, tr, step, dispatch) {
67
+ const search = getSearch(state);
68
+ if (!search.matches.length) return false;
69
+ if (dispatch) {
70
+ const next = (search.current + step + search.matches.length) % search.matches.length;
71
+ select(tr.setMeta(searchKey, { current: next }), search.matches[next]);
72
+ }
73
+ return true;
74
+ }
75
+ export const SearchExtension = Extension.create({
76
+ name: "ginkoSearch",
77
+ addCommands() {
78
+ return {
79
+ setSearch: (term, options) => ({ tr, dispatch }) => {
80
+ if (dispatch) {
81
+ const caseSensitive = options?.caseSensitive ?? false;
82
+ const matches = findMatches(tr.doc, term, caseSensitive);
83
+ const current = nearest(matches, tr.selection.from);
84
+ select(tr.setMeta(searchKey, { term, caseSensitive, current }).setMeta("addToHistory", false), matches[current]);
85
+ }
86
+ return true;
87
+ },
88
+ findNext: () => ({ state, tr, dispatch }) => go(state, tr, 1, !!dispatch),
89
+ findPrev: () => ({ state, tr, dispatch }) => go(state, tr, -1, !!dispatch),
90
+ replaceCurrent: (text) => ({ state, tr, dispatch }) => {
91
+ const search = getSearch(state);
92
+ const match = search.matches[search.current];
93
+ if (!match) return false;
94
+ if (dispatch) {
95
+ tr.insertText(text, match.from, match.to);
96
+ const end = match.from + text.length;
97
+ const after = build(tr.doc, search.term, search.caseSensitive, 0);
98
+ const i = after.matches.findIndex((m) => m.from >= end);
99
+ tr.setMeta(searchKey, { term: search.term, caseSensitive: search.caseSensitive, current: i === -1 ? 0 : i });
100
+ select(tr, after.matches[i === -1 ? 0 : i]);
101
+ }
102
+ return true;
103
+ },
104
+ replaceAll: (text) => ({ state, tr, dispatch }) => {
105
+ const search = getSearch(state);
106
+ if (!search.matches.length) return false;
107
+ if (dispatch) {
108
+ for (const m of [...search.matches].reverse()) tr.insertText(text, m.from, m.to);
109
+ const first = search.matches[0];
110
+ selectRange(tr, first.from, first.from + text.length);
111
+ }
112
+ return true;
113
+ }
114
+ };
115
+ },
116
+ addProseMirrorPlugins() {
117
+ return [new Plugin({
118
+ key: searchKey,
119
+ state: {
120
+ init: () => EMPTY,
121
+ apply(tr, old, _before, after) {
122
+ const reveals = old.reveals + (tr.getMeta(REVEAL) ? 1 : 0);
123
+ const meta = tr.getMeta(searchKey);
124
+ if (meta && "term" in meta) return { ...build(after.doc, meta.term, meta.caseSensitive, meta.current), reveals };
125
+ if (meta) return { ...old, current: clamp(meta.current, old.matches.length), reveals };
126
+ if (tr.docChanged && old.term) return { ...build(after.doc, old.term, old.caseSensitive, old.current), reveals };
127
+ return reveals === old.reveals ? old : { ...old, reveals };
128
+ }
129
+ },
130
+ view: () => ({
131
+ update(view, before) {
132
+ if (searchKey.getState(view.state)?.reveals !== searchKey.getState(before)?.reveals) scrollToPos(view, view.state.selection.head);
133
+ }
134
+ }),
135
+ props: {
136
+ decorations(state) {
137
+ const { matches, current } = getSearch(state);
138
+ if (!matches.length) return null;
139
+ return DecorationSet.create(state.doc, matches.map((m, i) => Decoration.inline(m.from, m.to, { class: i === current ? "ginko-match ginko-match-current" : "ginko-match" })));
140
+ }
141
+ }
142
+ })];
143
+ }
144
+ });
145
+ export function searchInfo(editor) {
146
+ const { term, matches, current } = getSearch(editor.state);
147
+ return { term, total: matches.length, current: current + 1 };
148
+ }
@@ -0,0 +1,93 @@
1
+ import type { ComponentRegistry, MarkdownProfile } from '@lupinum/ginko/internal';
2
+ import type { Editor, Range } from '@tiptap/core';
3
+ import { type EditorState } from '@tiptap/pm/state';
4
+ export interface SlashItem {
5
+ /** Stable key: `heading2`, `bulletList`, ... and `component:<tag>`. */
6
+ id: string;
7
+ label: string;
8
+ /** One short line under the label. */
9
+ describe: string;
10
+ /** Heading of the group in the menu. */
11
+ group: string;
12
+ /** More words the filter finds this item by. */
13
+ keywords: string[];
14
+ /**
15
+ * `style` turns the block at the cursor into this one (a heading, a list); `insert` adds something new (a component, a
16
+ * table). From the toolbar an insert goes below a block that has text, like "/" on a new line would.
17
+ */
18
+ kind: 'style' | 'insert';
19
+ /** Changes the document at the cursor. The caller has already removed the typed `/query`. */
20
+ run(editor: Editor): void | Promise<void>;
21
+ }
22
+ export interface SlashItemsOptions {
23
+ profile: MarkdownProfile;
24
+ components?: ComponentRegistry;
25
+ /** The "Bild" item has no text to insert: the UI asks for a picture. Without it the item does nothing. */
26
+ pickImage?: (editor: Editor) => void;
27
+ /**
28
+ * Called after a component was inserted whose registry example leaves a required prop empty. The UI asks for
29
+ * those props right away. Not called when the example fills every required prop.
30
+ */
31
+ onNeedsProps?: (insert: InsertedComponent) => void;
32
+ /** The reader's language for the registry's labels, descriptions and groups (per-language texts). */
33
+ locale?: string;
34
+ }
35
+ export interface InsertedComponent {
36
+ editor: Editor;
37
+ tag: string;
38
+ /** Position of the component node in the document. */
39
+ pos: number;
40
+ /** Keys of the required props that have no valid value yet. */
41
+ missing: string[];
42
+ }
43
+ export declare const SLASH_TEXT_GROUP = "Text";
44
+ export declare const SLASH_COMPONENT_GROUP = "Komponenten";
45
+ /** The words for the three heading levels, here and in the toolbar of the Studio. */
46
+ export declare const HEADING_LABELS: {
47
+ readonly 2: "Überschrift";
48
+ readonly 3: "Unterüberschrift";
49
+ readonly 4: "Kleine Überschrift";
50
+ };
51
+ /** The entries for what `profile` allows, in menu order. The inline profile (one paragraph) has none. */
52
+ export declare function slashItems(options: SlashItemsOptions): SlashItem[];
53
+ /**
54
+ * The items that can go at the cursor, for the "/" menu and the toolbar alike. A GFM table cell holds one line of
55
+ * inline text, so there only the picture is offered: a heading, list or component there would not survive the save.
56
+ */
57
+ export declare function slashItemsAt(items: readonly SlashItem[], state: EditorState): SlashItem[];
58
+ /**
59
+ * Runs `item` from a menu that does not sit in an empty line (the toolbar). An insert in a block with text goes into a
60
+ * new empty paragraph below that block, so the text stays whole; everything else runs where the cursor is.
61
+ */
62
+ export declare function runSlashItem(editor: Editor, item: SlashItem): void | Promise<void>;
63
+ /**
64
+ * Takes back the empty paragraph `runSlashItem` added for an insert, when the insert did not happen (a component without
65
+ * an example, a closed picture dialog): the text is still the one it was made in. The cursor goes back where it was.
66
+ */
67
+ export declare function dropSlashBlank(editor: Editor): void;
68
+ export interface InsertComponentOptions {
69
+ tag: string;
70
+ profile: MarkdownProfile;
71
+ components: ComponentRegistry;
72
+ /** Where it goes: a position between blocks, or the range of the empty paragraph the menu was opened in (replaced). */
73
+ at: number | Range;
74
+ /**
75
+ * A child added inside its container (a tab in tabs): taken from the child's example, which may wrap it in its
76
+ * container. Its sample texts go like those of any insert (no second tab named "Erster"): the settings ask for them.
77
+ */
78
+ child?: boolean;
79
+ /** Called when the inserted component has required props without a valid value (see `SlashItemsOptions`). */
80
+ onNeedsProps?: (insert: InsertedComponent) => void;
81
+ }
82
+ /**
83
+ * Inserts the component `tag` as its registry example shows it, without the sample text (that shows as a placeholder).
84
+ * Without an example, the bare `::tag` (no text line). Then asks for missing required props, or puts the cursor in the
85
+ * first empty text block. Resolves to the inserted component.
86
+ */
87
+ export declare function insertComponent(editor: Editor, options: InsertComponentOptions): Promise<InsertedComponent | undefined>;
88
+ /**
89
+ * The items whose label, keywords or description contain every word of `query`, in the order the menus show them: by
90
+ * group, the group of the best match first, label matches first inside a group. So the first item is the best match,
91
+ * and the arrow keys walk the list as it is drawn.
92
+ */
93
+ export declare function filterSlashItems(items: readonly SlashItem[], query: string): SlashItem[];
@@ -0,0 +1,215 @@
1
+ import { labelOf, parseMarkdown, profileCovers, URL_PROPS } from "@lupinum/ginko/internal";
2
+ import { NodeSelection, TextSelection } from "@tiptap/pm/state";
3
+ import { editorMeta, missingRequired } from "./component-props.js";
4
+ import { toEditorDoc } from "./convert.js";
5
+ import { toggleTaskList } from "./extensions.js";
6
+ import { inTableCell } from "./table.js";
7
+ export const SLASH_TEXT_GROUP = "Text";
8
+ export const SLASH_COMPONENT_GROUP = "Komponenten";
9
+ export const HEADING_LABELS = { 2: "\xDCberschrift", 3: "Unter\xFCberschrift", 4: "Kleine \xDCberschrift" };
10
+ const heading = (level) => ({
11
+ id: `heading${level}`,
12
+ label: HEADING_LABELS[level],
13
+ describe: level === 2 ? "Gro\xDFe \xDCberschrift f\xFCr einen neuen Abschnitt" : level === 3 ? "Kleinere \xDCberschrift innerhalb eines Abschnitts" : "Kleinste \xDCberschrift",
14
+ group: SLASH_TEXT_GROUP,
15
+ // "Zwischenüberschrift" is the usual word for a section heading, so search finds level 2 with it.
16
+ keywords: ["titel", "heading", `h${level}`, ...level === 2 ? ["zwischen\xFCberschrift"] : []],
17
+ kind: "style",
18
+ // Toggles, so the toolbar's checked entry turns the block back into text; in an empty paragraph (the "/" menu) it is the same as set.
19
+ run: (editor) => {
20
+ editor.chain().focus().toggleHeading({ level }).run();
21
+ }
22
+ });
23
+ export function slashItems(options) {
24
+ const { profile, components, pickImage, onNeedsProps, locale = "" } = options;
25
+ const text = (label) => labelOf(label, locale, locale);
26
+ const covers = (narrow) => profileCovers(profile, narrow);
27
+ const items = [];
28
+ if (covers("basic")) {
29
+ items.push(
30
+ heading(2),
31
+ heading(3),
32
+ heading(4),
33
+ { id: "bulletList", label: "Aufz\xE4hlung", describe: "Liste mit Punkten", group: SLASH_TEXT_GROUP, keywords: ["liste", "punkte", "bullet"], kind: "style", run: (e) => {
34
+ e.chain().focus().toggleBulletList().run();
35
+ } },
36
+ { id: "orderedList", label: "Nummerierte Liste", describe: "Liste mit Zahlen", group: SLASH_TEXT_GROUP, keywords: ["liste", "zahlen", "schritte"], kind: "style", run: (e) => {
37
+ e.chain().focus().toggleOrderedList().run();
38
+ } },
39
+ { id: "taskList", label: "Checkliste", describe: "Liste mit K\xE4stchen zum Abhaken", group: SLASH_TEXT_GROUP, keywords: ["aufgaben", "todo", "checkbox", "k\xE4stchen"], kind: "style", run: (e) => {
40
+ toggleTaskList(e);
41
+ } },
42
+ { id: "blockquote", label: "Zitat", describe: "Einger\xFCckter Text, zum Beispiel eine Stimme", group: SLASH_TEXT_GROUP, keywords: ["quote", "zitieren"], kind: "style", run: (e) => {
43
+ e.chain().focus().toggleBlockquote().run();
44
+ } },
45
+ { id: "horizontalRule", label: "Trennlinie", describe: "Eine Linie zwischen zwei Abschnitten", group: SLASH_TEXT_GROUP, keywords: ["linie", "strich", "trenner"], kind: "insert", run: (e) => {
46
+ e.chain().focus().setHorizontalRule().run();
47
+ } }
48
+ );
49
+ }
50
+ if (covers("rich")) {
51
+ items.push(
52
+ { id: "table", label: "Tabelle", describe: "Zeilen und Spalten", group: SLASH_TEXT_GROUP, keywords: ["raster", "zeilen", "spalten"], kind: "insert", run: (e) => {
53
+ e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
54
+ } },
55
+ { id: "codeBlock", label: "Codeblock", describe: "Text in fester Schrift, f\xFCr Code", group: SLASH_TEXT_GROUP, keywords: ["code", "quelltext"], kind: "style", run: (e) => {
56
+ e.chain().focus().toggleCodeBlock().run();
57
+ } },
58
+ { id: "image", label: "Bild", describe: "Ein Bild mit Beschreibung einf\xFCgen", group: SLASH_TEXT_GROUP, keywords: ["foto", "grafik", "bild"], kind: "insert", run: (e) => {
59
+ pickImage?.(e);
60
+ } }
61
+ );
62
+ }
63
+ if (covers("page") && components) {
64
+ for (const [tag, def] of Object.entries(components)) {
65
+ if (def.kind !== "block" || def.parents?.length || editorMeta(def).hidden) continue;
66
+ items.push({
67
+ id: `component:${tag}`,
68
+ label: text(def.label),
69
+ describe: text(def.describe),
70
+ group: def.editor?.group === void 0 ? SLASH_COMPONENT_GROUP : text(def.editor.group),
71
+ keywords: [tag, ...editorMeta(def).keywords ?? []],
72
+ kind: "insert",
73
+ async run(editor) {
74
+ const { from, to } = editor.state.selection;
75
+ await insertComponent(editor, { tag, profile, components, at: { from, to }, onNeedsProps });
76
+ }
77
+ });
78
+ }
79
+ }
80
+ const seen = /* @__PURE__ */ new Set();
81
+ return items.filter((item) => {
82
+ const keys = [`id:${item.id}`, `label:${item.group}:${item.label.toLowerCase()}`];
83
+ if (keys.some((key) => seen.has(key))) return false;
84
+ keys.forEach((key) => seen.add(key));
85
+ return true;
86
+ });
87
+ }
88
+ export function slashItemsAt(items, state) {
89
+ return inTableCell(state) ? items.filter((item) => item.id === "image") : [...items];
90
+ }
91
+ export function runSlashItem(editor, item) {
92
+ const { selection } = editor.state;
93
+ const parent = selection.$from.parent;
94
+ const below = inTableCell(editor.state) ? void 0 : selection instanceof NodeSelection ? selection.to : parent.isTextblock && (parent.type.name !== "paragraph" || parent.content.size > 0) ? selection.$from.after() : void 0;
95
+ if (item.kind === "insert" && below !== void 0) {
96
+ const back = selection.getBookmark();
97
+ editor.chain().insertContentAt(below, { type: "paragraph" }).setTextSelection(below + 1).run();
98
+ blanks.set(editor, { doc: editor.state.doc, pos: below, back });
99
+ }
100
+ const done = item.run(editor);
101
+ if (item.id === "image") return done;
102
+ if (done instanceof Promise) return done.then(() => dropSlashBlank(editor));
103
+ dropSlashBlank(editor);
104
+ }
105
+ const blanks = /* @__PURE__ */ new WeakMap();
106
+ export function dropSlashBlank(editor) {
107
+ const blank = blanks.get(editor);
108
+ blanks.delete(editor);
109
+ if (!blank || editor.isDestroyed || editor.state.doc !== blank.doc) return;
110
+ const tr = editor.state.tr.delete(blank.pos, blank.pos + 2);
111
+ editor.view.dispatch(tr.setSelection(blank.back.resolve(tr.doc)));
112
+ }
113
+ export async function insertComponent(editor, options) {
114
+ const { tag, profile, components, at, child = false, onNeedsProps } = options;
115
+ const content = await componentSkeleton(tag, components, profile, child);
116
+ if (!content.length) return void 0;
117
+ editor.chain().focus().insertContentAt(at, content).run();
118
+ const inserted = firstComponentFrom(editor, typeof at === "number" ? at : at.from - 1);
119
+ if (!inserted) return void 0;
120
+ const missing = missingRequired(components, inserted.tag, inserted.props);
121
+ if (missing.length) onNeedsProps?.({ editor, tag: inserted.tag, pos: inserted.pos, missing });
122
+ else focusFirstBlank(editor, inserted.pos);
123
+ return { editor, tag: inserted.tag, pos: inserted.pos, missing };
124
+ }
125
+ async function componentSkeleton(tag, components, profile, child) {
126
+ const def = Object.hasOwn(components, tag) ? components[tag] : void 0;
127
+ const example = def?.editor?.example ?? `::${tag}
128
+ ::`;
129
+ const parsed = await parseMarkdown(example, { profile, components });
130
+ const nodes = toEditorDoc(parsed.value.nodes, { components }).content ?? [];
131
+ const own = child ? [findComponent(nodes, tag) ?? { type: "component", attrs: { tag, props: {} }, content: [] }] : nodes;
132
+ return own.map((node) => blankSample(node, components, false)).filter((node) => node !== void 0);
133
+ }
134
+ function findComponent(nodes, tag) {
135
+ for (const node of nodes) {
136
+ if (node.type === "component" && node.attrs?.tag === tag) return node;
137
+ const inner = findComponent(node.content ?? [], tag);
138
+ if (inner) return inner;
139
+ }
140
+ return void 0;
141
+ }
142
+ const isAddress = (key, field) => URL_PROPS.has(key) || field.type === "text" && field.format === "url";
143
+ const TEXTBLOCKS = /* @__PURE__ */ new Set(["paragraph", "heading"]);
144
+ const INLINE_LEAVES = /* @__PURE__ */ new Set(["text", "hardBreak", "image", "taskCheckbox", "mathInline", "inlineComponent"]);
145
+ const plainText = (node) => node.text ?? (node.content ?? []).map(plainText).join("");
146
+ function blankSample(node, registry, nested) {
147
+ if (INLINE_LEAVES.has(node.type)) return void 0;
148
+ if (TEXTBLOCKS.has(node.type)) {
149
+ const { content: _, ...rest } = node;
150
+ const text = plainText(node).trim();
151
+ return text ? { ...rest, attrs: { ...node.attrs, placeholder: text } } : rest;
152
+ }
153
+ if (node.type === "codeBlock" || node.type === "mathBlock" || node.type === "mermaid") {
154
+ const { content: _, ...rest } = node;
155
+ return rest;
156
+ }
157
+ const next = { ...node };
158
+ if (node.type === "component") {
159
+ const def = Object.hasOwn(registry, String(node.attrs?.tag)) ? registry[String(node.attrs?.tag)] : void 0;
160
+ const kept = {};
161
+ for (const [name, raw] of Object.entries(node.attrs?.props ?? {})) {
162
+ const key = name.replace(/^:/, "");
163
+ const field = def && Object.hasOwn(def.props, key) ? def.props[key] : void 0;
164
+ const prose = field !== void 0 && (field.type === "text" || field.type === "longtext") && !isAddress(key, field) && (!nested || field.optional);
165
+ if (!prose) kept[name] = raw;
166
+ }
167
+ next.attrs = { ...node.attrs, props: kept };
168
+ }
169
+ if (node.content) next.content = node.content.map((child) => blankSample(child, registry, nested || node.type === "component")).filter((child) => child !== void 0);
170
+ return next;
171
+ }
172
+ function focusFirstBlank(editor, pos) {
173
+ const { doc } = editor.state;
174
+ const node = doc.nodeAt(pos);
175
+ if (!node) return;
176
+ let target;
177
+ node.descendants((child, offset) => {
178
+ if (target !== void 0) return false;
179
+ if (child.isTextblock && child.content.size === 0) {
180
+ target = pos + 1 + offset + 1;
181
+ return false;
182
+ }
183
+ return true;
184
+ });
185
+ if (target !== void 0) editor.view.dispatch(editor.state.tr.setSelection(TextSelection.create(doc, target)));
186
+ }
187
+ function firstComponentFrom(editor, from) {
188
+ const { doc } = editor.state;
189
+ let found;
190
+ doc.nodesBetween(Math.max(0, from), doc.content.size, (node, pos) => {
191
+ if (found) return false;
192
+ if (node.type.name === "component" && pos >= from) found = { pos, tag: String(node.attrs.tag), props: node.attrs.props ?? {} };
193
+ return !found;
194
+ });
195
+ return found;
196
+ }
197
+ function fold(text) {
198
+ return text.toLowerCase().replace(/ß/g, "ss").normalize("NFD").replace(/\p{M}/gu, "").replace(/(a|o|u)e/g, "$1");
199
+ }
200
+ export function filterSlashItems(items, query) {
201
+ const words = fold(query).split(/\s+/).filter(Boolean);
202
+ if (!words.length) return byGroup(items);
203
+ const scored = [];
204
+ items.forEach((item, index) => {
205
+ const label = fold(item.label);
206
+ const rest = fold([...item.keywords, item.describe].join(" "));
207
+ if (!words.every((w) => label.includes(w) || rest.includes(w))) return;
208
+ scored.push({ item, rank: words.every((w) => label.startsWith(w) || label.includes(` ${w}`)) ? 0 : words.every((w) => label.includes(w)) ? 1 : 2, index });
209
+ });
210
+ return byGroup(scored.sort((a, b) => a.rank - b.rank || a.index - b.index).map((s) => s.item));
211
+ }
212
+ function byGroup(items) {
213
+ const groups = [...new Set(items.map((item) => item.group))];
214
+ return groups.flatMap((group) => items.filter((item) => item.group === group));
215
+ }
@@ -0,0 +1,34 @@
1
+ import { Extension, type Editor } from '@tiptap/core';
2
+ import { type EditorState } from '@tiptap/pm/state';
3
+ export type ColumnAlign = 'left' | 'center' | 'right';
4
+ export interface TableAt {
5
+ /** Row of the cursor; 0 is the header row. */
6
+ row: number;
7
+ column: number;
8
+ rows: number;
9
+ columns: number;
10
+ /** Alignment of the cursor's column, undefined for the default. */
11
+ align: ColumnAlign | undefined;
12
+ }
13
+ export declare function alignOf(props: unknown): ColumnAlign | undefined;
14
+ /** Whether the cursor is in a table cell (a header cell too). */
15
+ export declare function inTableCell(state: EditorState): boolean;
16
+ /** Where the cursor is in its table, or undefined outside one. */
17
+ export declare function tableAt(state: EditorState): TableAt | undefined;
18
+ /**
19
+ * A GFM cell holds one line. Enter and Shift+Enter in a cell do nothing: a second paragraph or a line break saved as
20
+ * spaces, so the cell's two lines became one. Tab goes on to the next cell.
21
+ */
22
+ export declare const TableKeys: Extension<any, any>;
23
+ /** Shows every column's alignment on all its cells, so the editor aligns as the site does. Display only; not saved. */
24
+ export declare const TableAlign: Extension<any, any>;
25
+ export type TableCommand = 'addRowBefore' | 'addRowAfter' | 'addColumnBefore' | 'addColumnAfter' | 'moveRowUp' | 'moveRowDown' | 'moveColumnLeft' | 'moveColumnRight' | 'deleteRow' | 'deleteColumn' | 'deleteTable';
26
+ /**
27
+ * Whether `command` keeps a valid GFM table at the cursor. The header row stays the first row and stays one: nothing
28
+ * goes above it, it does not move, and it is not deleted (a table without one gets an invented "Column 1" on save).
29
+ */
30
+ export declare function canRunTable(state: EditorState, command: TableCommand): boolean;
31
+ /** Runs `command` on the table at the cursor; false when `canRunTable` says no. */
32
+ export declare function runTable(editor: Editor, command: TableCommand): boolean;
33
+ /** Sets the alignment of the cursor's column, in every cell of it; undefined goes back to the default (`---`). */
34
+ export declare function setColumnAlign(editor: Editor, align: ColumnAlign | undefined): boolean;