@aicayzer/inkkit 0.0.18 → 0.1.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 (90) hide show
  1. package/NOTICE +4 -2
  2. package/README.md +11 -7
  3. package/dist/THIRD-PARTY-NOTICES.txt +2742 -0
  4. package/dist/chunks/core-vtCr4MBS.js +56503 -0
  5. package/dist/chunks/highlight-Daj2fv_u.js +14122 -0
  6. package/dist/core.d.ts +2 -5
  7. package/dist/core.js +2 -2
  8. package/dist/editor.d.ts +229 -47
  9. package/dist/index.js +5 -3
  10. package/dist/style.css +231 -202
  11. package/dist/types.d.ts +143 -18
  12. package/package.json +16 -13
  13. package/dist/autolink.d.ts +0 -1
  14. package/dist/autolink.js +0 -18
  15. package/dist/callouts.d.ts +0 -25
  16. package/dist/callouts.js +0 -288
  17. package/dist/clipboard.d.ts +0 -11
  18. package/dist/clipboard.js +0 -261
  19. package/dist/code-fences.d.ts +0 -8
  20. package/dist/code-fences.js +0 -171
  21. package/dist/comments.d.ts +0 -76
  22. package/dist/comments.js +0 -545
  23. package/dist/cursor.d.ts +0 -2
  24. package/dist/cursor.js +0 -40
  25. package/dist/decorations.d.ts +0 -2
  26. package/dist/decorations.js +0 -67
  27. package/dist/dialect.d.ts +0 -9
  28. package/dist/dialect.js +0 -446
  29. package/dist/drop-placement.d.ts +0 -19
  30. package/dist/drop-placement.js +0 -47
  31. package/dist/editor.js +0 -2673
  32. package/dist/files.d.ts +0 -40
  33. package/dist/files.js +0 -133
  34. package/dist/highlight.d.ts +0 -1
  35. package/dist/highlight.js +0 -136
  36. package/dist/html-import.d.ts +0 -13
  37. package/dist/html-import.js +0 -477
  38. package/dist/image-blocks.d.ts +0 -86
  39. package/dist/image-blocks.js +0 -329
  40. package/dist/images.d.ts +0 -51
  41. package/dist/images.js +0 -398
  42. package/dist/inline-highlight.d.ts +0 -6
  43. package/dist/inline-highlight.js +0 -112
  44. package/dist/labels.d.ts +0 -36
  45. package/dist/labels.js +0 -34
  46. package/dist/link-safety.d.ts +0 -17
  47. package/dist/link-safety.js +0 -29
  48. package/dist/linked-syntax.d.ts +0 -48
  49. package/dist/linked-syntax.js +0 -320
  50. package/dist/literals.d.ts +0 -20
  51. package/dist/literals.js +0 -216
  52. package/dist/mermaid.d.ts +0 -28
  53. package/dist/mermaid.js +0 -404
  54. package/dist/outline.d.ts +0 -22
  55. package/dist/outline.js +0 -79
  56. package/dist/paste-html.d.ts +0 -31
  57. package/dist/paste-html.js +0 -462
  58. package/dist/paste.d.ts +0 -33
  59. package/dist/paste.js +0 -591
  60. package/dist/portable-files.d.ts +0 -10
  61. package/dist/portable-files.js +0 -36
  62. package/dist/preserve.d.ts +0 -38
  63. package/dist/preserve.js +0 -1396
  64. package/dist/print.d.ts +0 -7
  65. package/dist/print.js +0 -406
  66. package/dist/reference-clipboard.d.ts +0 -8
  67. package/dist/reference-clipboard.js +0 -201
  68. package/dist/references.d.ts +0 -16
  69. package/dist/references.js +0 -418
  70. package/dist/scroll.d.ts +0 -15
  71. package/dist/scroll.js +0 -27
  72. package/dist/search.d.ts +0 -15
  73. package/dist/search.js +0 -202
  74. package/dist/selection.d.ts +0 -1
  75. package/dist/selection.js +0 -59
  76. package/dist/source.d.ts +0 -16
  77. package/dist/source.js +0 -57
  78. package/dist/spreadsheet.d.ts +0 -8
  79. package/dist/spreadsheet.js +0 -289
  80. package/dist/table-alignment.d.ts +0 -2
  81. package/dist/table-alignment.js +0 -46
  82. package/dist/tables.d.ts +0 -27
  83. package/dist/tables.js +0 -344
  84. package/dist/tasks.d.ts +0 -3
  85. package/dist/tasks.js +0 -51
  86. package/dist/text-ranges.d.ts +0 -29
  87. package/dist/text-ranges.js +0 -256
  88. package/dist/types.js +0 -8
  89. package/dist/wiki-view.d.ts +0 -21
  90. package/dist/wiki-view.js +0 -78
@@ -1,329 +0,0 @@
1
- import { keydownHandler } from '@milkdown/kit/prose/keymap';
2
- import { GapCursor } from '@milkdown/kit/prose/gapcursor';
3
- import { Fragment, } from '@milkdown/kit/prose/model';
4
- import { NodeSelection, Plugin, PluginKey, Selection, TextSelection, } from '@milkdown/kit/prose/state';
5
- import { CellSelection } from '@milkdown/kit/prose/tables';
6
- import { $nodeSchema, $prose } from '@milkdown/kit/utils';
7
- export const imageBlockName = 'image_block';
8
- /** Attributes shared by an inline image and a standalone image block. */
9
- export const imageAttrs = {
10
- src: { default: '', validate: 'string' },
11
- alt: { default: '', validate: 'string' },
12
- title: { default: '', validate: 'string' },
13
- inkkitFileRaw: { default: null },
14
- inkkitFileTarget: { default: null },
15
- inkkitFileFragment: { default: null },
16
- inkkitFileWidth: { default: null },
17
- inkkitFileInTable: { default: false },
18
- };
19
- // Remark represents a missing title as null; the image schema accepts strings.
20
- export function markdownImageAttrs(node) {
21
- return {
22
- src: String(node.url ?? ''),
23
- alt: String(node.alt ?? ''),
24
- title: String(node.title ?? ''),
25
- inkkitFileRaw: node.inkkitFileRaw ?? null,
26
- inkkitFileTarget: node.inkkitFileTarget ?? null,
27
- inkkitFileFragment: node.inkkitFileFragment ?? null,
28
- inkkitFileWidth: node.inkkitFileWidth ?? null,
29
- inkkitFileInTable: node.inkkitFileInTable ?? false,
30
- };
31
- }
32
- /** Whether a node displays an authored image, inline or as its own block. */
33
- export function isImage(node) {
34
- return node.type.name === 'image' || node.type.name === imageBlockName;
35
- }
36
- export function isImageBlock(node) {
37
- return node?.type.name === imageBlockName;
38
- }
39
- function accepts(parent, index, type) {
40
- return parent.canReplaceWith(index, index + 1, type);
41
- }
42
- const cellTypes = new Set(['table_cell', 'table_header']);
43
- function cellDepth($pos) {
44
- for (let depth = $pos.depth; depth > 0; depth--)
45
- if (cellTypes.has($pos.node(depth).type.name))
46
- return depth;
47
- return 0;
48
- }
49
- /** Where `insertImages` puts images for a selection. `blocks` replaces the selection with one block per
50
- * image. `inline` places them on the one line of a table cell, which cannot hold blocks. `after` puts
51
- * them below the nearest block that takes a following paragraph, leaving the selection and its
52
- * block as written: the selection is in source that cannot hold an image, such as code, a comment
53
- * or an unsupported literal block, or it spans table cells. Nothing is ever split or discarded. */
54
- export function imagePlacement(state) {
55
- const image = state.schema.nodes.image;
56
- const paragraph = state.schema.nodes.paragraph;
57
- const { selection } = state;
58
- const { $from, $to } = selection;
59
- const unfit = selection instanceof CellSelection ||
60
- [$from, $to].some(({ parent }) => parent.inlineContent &&
61
- !(image && parent.type.contentMatch.matchType(image)));
62
- const from = cellDepth($from);
63
- const to = cellDepth($to);
64
- if (!unfit && !from && !to)
65
- return { kind: 'blocks' };
66
- if (!unfit && from && to && $from.sameParent($to))
67
- return { kind: 'inline' };
68
- for (let depth = $to.depth; depth > 0; depth--) {
69
- const node = $to.node(depth);
70
- const parent = $to.node(depth - 1);
71
- if (node.isInline)
72
- continue;
73
- const index = $to.index(depth - 1) + 1;
74
- if (paragraph && parent.canReplaceWith(index, index, paragraph))
75
- return { kind: 'after', pos: $to.after(depth) };
76
- }
77
- return { kind: 'after', pos: state.doc.content.size };
78
- }
79
- /** The image a paragraph holds as its only content, without marks, which makes the paragraph a
80
- * standalone image block. A linked or emphasised image stays inline so its marks are kept. */
81
- export function standaloneImage(children) {
82
- const [image] = children;
83
- return children.length === 1 &&
84
- image.type.name === 'image' &&
85
- !image.marks.length
86
- ? image
87
- : undefined;
88
- }
89
- /** Reads a Markdown paragraph, as an image block when it holds a standalone image and the enclosing
90
- * block accepts one. */
91
- export function readParagraph(state, node, paragraph) {
92
- state.openNode(paragraph);
93
- if (node.children)
94
- state.next(node.children);
95
- else
96
- state.addText(String(node.value ?? ''));
97
- const type = state.schema.nodes[imageBlockName];
98
- const element = state.top();
99
- const image = standaloneImage(element.content);
100
- state.close();
101
- const parent = state.top();
102
- const content = Fragment.fromArray(parent?.content ?? []);
103
- // A parent that must open with other content, such as a list item that
104
- // opens with a code fence, is filled in front of it when it closes.
105
- const filler = parent?.type.contentMatch.fillBefore(content);
106
- if (image &&
107
- type &&
108
- filler &&
109
- parent?.type.contentMatch
110
- .matchFragment(filler.append(content))
111
- ?.matchType(type))
112
- state.addNode(type, image.attrs);
113
- else {
114
- state.openNode(paragraph);
115
- for (const child of element.content)
116
- state.top().push(child);
117
- state.closeNode();
118
- }
119
- }
120
- // A standalone image is a block with no inside, so no edit can put text beside it. In Markdown it
121
- // remains a paragraph holding the image, which is how it is read and written.
122
- export const imageBlockSchema = $nodeSchema(imageBlockName, () => ({
123
- group: 'block',
124
- atom: true,
125
- selectable: true,
126
- draggable: true,
127
- marks: '',
128
- attrs: imageAttrs,
129
- toDOM: (node) => [
130
- 'p',
131
- { class: 'inkkit-image-block' },
132
- [
133
- 'img',
134
- {
135
- src: String(node.attrs.src),
136
- alt: String(node.attrs.alt),
137
- title: String(node.attrs.title),
138
- },
139
- ],
140
- ],
141
- parseMarkdown: { match: () => false, runner: () => undefined },
142
- toMarkdown: {
143
- match: (node) => node.type.name === imageBlockName,
144
- runner: (state, node) => {
145
- state.openNode('paragraph');
146
- state.next(node.type.schema.nodes.image.create(node.attrs));
147
- state.closeNode();
148
- },
149
- },
150
- }));
151
- // An edit can leave a paragraph holding only an image, which reading its Markdown again would give
152
- // as an image block. The caret keeps its side of the image.
153
- const normalise = $prose(() => new Plugin({
154
- key: new PluginKey('inkkitImageBlockNormalise'),
155
- appendTransaction(transactions, old, state) {
156
- const type = state.schema.nodes[imageBlockName];
157
- if (!type || !transactions.some((tr) => tr.docChanged))
158
- return null;
159
- // Compare the documents, as mark and attribute steps change no positions.
160
- const start = old.doc.content.findDiffStart(state.doc.content);
161
- const end = old.doc.content.findDiffEnd(state.doc.content);
162
- if (start == null || !end)
163
- return null;
164
- const found = new Map();
165
- state.doc.nodesBetween(Math.min(start, end.b), Math.max(start, end.b), (node, pos, parent, index) => {
166
- if (!node.isTextblock)
167
- return true;
168
- const children = [];
169
- node.forEach((child) => children.push(child));
170
- if (node.type.name === 'paragraph' &&
171
- standaloneImage(children) &&
172
- parent &&
173
- accepts(parent, index, type))
174
- found.set(pos, node);
175
- return false;
176
- });
177
- if (!found.size)
178
- return null;
179
- const tr = state.tr;
180
- const { head } = state.selection;
181
- let caret;
182
- for (const [pos, node] of [...found].sort(([a], [b]) => b - a)) {
183
- const end = pos + node.nodeSize;
184
- if (head > pos && head < end)
185
- caret = head > pos + 1 ? { pos: end, side: 1 } : { pos, side: -1 };
186
- tr.replaceWith(pos, end, type.create(node.firstChild.attrs));
187
- }
188
- if (caret)
189
- tr.setSelection(new GapCursor(tr.doc.resolve(tr.mapping.map(caret.pos, caret.side))));
190
- return tr;
191
- },
192
- }));
193
- /** The image block a selection rests beside or selects, as the position for a new paragraph. */
194
- function newParagraphAt(state) {
195
- const { selection } = state;
196
- if (selection instanceof NodeSelection && isImageBlock(selection.node))
197
- return selection.to;
198
- if (selection instanceof GapCursor &&
199
- (isImageBlock(selection.$head.nodeBefore) ||
200
- isImageBlock(selection.$head.nodeAfter)))
201
- return selection.head;
202
- return undefined;
203
- }
204
- /** Opens an empty paragraph beside a selected image block, or at a gap beside one. */
205
- function openParagraph(state) {
206
- const pos = newParagraphAt(state);
207
- const paragraph = state.schema.nodes.paragraph;
208
- if (pos == null || !paragraph)
209
- return undefined;
210
- const $pos = state.doc.resolve(pos);
211
- if (!accepts($pos.parent, $pos.index(), paragraph))
212
- return undefined;
213
- const tr = state.tr.insert(pos, paragraph.create());
214
- return tr.setSelection(TextSelection.create(tr.doc, pos + 1));
215
- }
216
- const enter = (state, dispatch) => {
217
- const tr = openParagraph(state);
218
- if (!tr)
219
- return false;
220
- dispatch?.(tr.scrollIntoView());
221
- return true;
222
- };
223
- /** Backspace or Delete toward an image block selects it before anything is deleted; from a gap beside
224
- * one toward text, the caret moves into the text. An empty paragraph next to one is removed. */
225
- function towardImage(dir) {
226
- return (state, dispatch) => {
227
- const { selection, doc } = state;
228
- if (!selection.empty)
229
- return false;
230
- const $head = selection.$head;
231
- if (selection instanceof GapCursor) {
232
- const node = dir < 0 ? $head.nodeBefore : $head.nodeAfter;
233
- const other = dir < 0 ? $head.nodeAfter : $head.nodeBefore;
234
- if (!node || !(isImageBlock(other) || isImageBlock(node)))
235
- return false;
236
- const next = isImageBlock(node)
237
- ? NodeSelection.create(doc, dir < 0 ? $head.pos - 1 : $head.pos)
238
- : Selection.findFrom($head, dir, true);
239
- if (!next)
240
- return false;
241
- dispatch?.(state.tr.setSelection(next).scrollIntoView());
242
- return true;
243
- }
244
- if (!$head.parent.isTextblock || $head.depth === 0)
245
- return false;
246
- const atEdge = dir < 0
247
- ? $head.parentOffset === 0
248
- : $head.parentOffset === $head.parent.content.size;
249
- if (!atEdge)
250
- return false;
251
- const index = $head.index(-1) + dir;
252
- const parent = $head.node(-1);
253
- const neighbour = index >= 0 && index < parent.childCount ? parent.child(index) : undefined;
254
- if (!isImageBlock(neighbour))
255
- return false;
256
- const block = dir < 0 ? $head.before() - 1 : $head.after();
257
- // An empty paragraph goes, unless its parent needs it, such as a list item's first line.
258
- if ($head.parent.content.size === 0 &&
259
- $head.parent.type.name === 'paragraph' &&
260
- parent.canReplace($head.index(-1), $head.index(-1) + 1)) {
261
- const tr = state.tr.delete($head.before(), $head.after());
262
- dispatch?.(tr
263
- .setSelection(new GapCursor(tr.doc.resolve($head.before())))
264
- .scrollIntoView());
265
- return true;
266
- }
267
- if (!dispatch)
268
- return true;
269
- dispatch(state.tr.setSelection(NodeSelection.create(doc, block)).scrollIntoView());
270
- return true;
271
- };
272
- }
273
- const keys = keydownHandler({
274
- Enter: enter,
275
- 'Shift-Enter': enter,
276
- Backspace: towardImage(-1),
277
- Delete: towardImage(1),
278
- });
279
- const interaction = $prose(() => new Plugin({
280
- key: new PluginKey('inkkitImageBlocks'),
281
- props: {
282
- handleKeyDown: (view, event) => !view.composing && view.editable && keys(view, event),
283
- handleTextInput(view, _from, _to, text) {
284
- const tr = openParagraph(view.state);
285
- if (!tr)
286
- return false;
287
- view.dispatch(tr.insertText(text).scrollIntoView());
288
- return true;
289
- },
290
- // A click beside an image card, not on it, puts the caret after the image.
291
- handleClickOn(view, _pos, node, nodePos, event, direct) {
292
- if (!direct ||
293
- !view.editable ||
294
- !isImageBlock(node) ||
295
- !(event.target instanceof Element) ||
296
- event.target.closest('.image'))
297
- return false;
298
- view.dispatch(view.state.tr.setSelection(new GapCursor(view.state.doc.resolve(nodePos + node.nodeSize))));
299
- return true;
300
- },
301
- handleDOMEvents: {
302
- // ProseMirror replaces a selection when composition starts; a selected image is kept and
303
- // the composed text goes after it.
304
- compositionstart(view) {
305
- const { selection } = view.state;
306
- if (view.editable &&
307
- selection instanceof NodeSelection &&
308
- isImageBlock(selection.node))
309
- view.dispatch(view.state.tr.setSelection(new GapCursor(view.state.doc.resolve(selection.to))));
310
- return false;
311
- },
312
- // Composed text needs a paragraph to land in before the browser writes it, as the gap
313
- // cursor plugin does for its own gaps.
314
- beforeinput(view, event) {
315
- if (event.inputType !== 'insertCompositionText' || !view.editable)
316
- return false;
317
- const tr = openParagraph(view.state);
318
- if (tr)
319
- view.dispatch(tr);
320
- return false;
321
- },
322
- },
323
- },
324
- }));
325
- export const imageBlocks = [
326
- imageBlockSchema,
327
- normalise,
328
- interaction,
329
- ].flat();
package/dist/images.d.ts DELETED
@@ -1,51 +0,0 @@
1
- import type { Node as ProseNode } from '@milkdown/kit/prose/model';
2
- import type { EditorView, NodeView } from '@milkdown/kit/prose/view';
3
- import type { ImageAdapter } from './types.js';
4
- import { type FileViewRuntime } from './files.js';
5
- /** A width rides in the alt text, as `![a picture|400](images/….png)`. Other Markdown readers
6
- * show the picture and keep the number without requiring a private extension. */
7
- export declare function splitAlt(alt: string): {
8
- alt: string;
9
- width: number | null;
10
- };
11
- export declare function joinAlt(alt: string, width: number | null): string;
12
- declare class ImageView implements NodeView {
13
- private node;
14
- private readonly view;
15
- private readonly getPos;
16
- private readonly adapter;
17
- private readonly runtime?;
18
- private readonly canMutate;
19
- dom: HTMLElement;
20
- /** The card or picture, which a standalone image's block row holds. */
21
- private element;
22
- private image?;
23
- private media?;
24
- private pdf?;
25
- private width;
26
- private stopResize?;
27
- private resolution?;
28
- private previewFailed;
29
- constructor(node: ProseNode, view: EditorView, getPos: () => number | undefined, adapter: ImageAdapter | undefined, runtime?: FileViewRuntime | undefined, canMutate?: () => boolean);
30
- private reference;
31
- private active;
32
- update(node: ProseNode): boolean;
33
- stopEvent(event: Event): boolean;
34
- ignoreMutation(): boolean;
35
- private mediaPolicy;
36
- private cancelResize;
37
- private releaseMedia;
38
- destroy(): void;
39
- private button;
40
- private activate;
41
- private report;
42
- private card;
43
- private failPreview;
44
- private render;
45
- private renderImage;
46
- private startResize;
47
- private commit;
48
- private canResize;
49
- }
50
- export declare function imageView(adapter?: ImageAdapter, runtime?: FileViewRuntime, canMutate?: () => boolean): import("@milkdown/kit/utils").$View<import("@milkdown/kit/utils").$Node, (node: ProseNode, view: EditorView, getPos: () => number | undefined) => ImageView>[];
51
- export {};