@aicayzer/inkkit 0.0.17 → 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 (81) hide show
  1. package/NOTICE +4 -2
  2. package/README.md +12 -6
  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 +4 -0
  7. package/dist/core.js +2 -0
  8. package/dist/editor.d.ts +261 -48
  9. package/dist/index.d.ts +1 -7
  10. package/dist/index.js +5 -2
  11. package/dist/style.css +242 -221
  12. package/dist/types.d.ts +143 -18
  13. package/package.json +26 -15
  14. package/dist/autolink.d.ts +0 -1
  15. package/dist/autolink.js +0 -18
  16. package/dist/callouts.d.ts +0 -26
  17. package/dist/callouts.js +0 -311
  18. package/dist/clipboard.d.ts +0 -11
  19. package/dist/clipboard.js +0 -261
  20. package/dist/code-fences.d.ts +0 -8
  21. package/dist/code-fences.js +0 -166
  22. package/dist/comments.d.ts +0 -55
  23. package/dist/comments.js +0 -494
  24. package/dist/decorations.d.ts +0 -2
  25. package/dist/decorations.js +0 -67
  26. package/dist/dialect.d.ts +0 -9
  27. package/dist/dialect.js +0 -358
  28. package/dist/editor.js +0 -2441
  29. package/dist/files.d.ts +0 -40
  30. package/dist/files.js +0 -133
  31. package/dist/highlight.d.ts +0 -1
  32. package/dist/highlight.js +0 -136
  33. package/dist/image-blocks.d.ts +0 -71
  34. package/dist/image-blocks.js +0 -286
  35. package/dist/images.d.ts +0 -51
  36. package/dist/images.js +0 -398
  37. package/dist/inline-highlight.d.ts +0 -6
  38. package/dist/inline-highlight.js +0 -112
  39. package/dist/labels.d.ts +0 -36
  40. package/dist/labels.js +0 -34
  41. package/dist/linked-syntax.d.ts +0 -48
  42. package/dist/linked-syntax.js +0 -320
  43. package/dist/literals.d.ts +0 -19
  44. package/dist/literals.js +0 -211
  45. package/dist/mermaid.d.ts +0 -8
  46. package/dist/mermaid.js +0 -321
  47. package/dist/outline.d.ts +0 -22
  48. package/dist/outline.js +0 -79
  49. package/dist/paste-html.d.ts +0 -23
  50. package/dist/paste-html.js +0 -441
  51. package/dist/paste.d.ts +0 -26
  52. package/dist/paste.js +0 -482
  53. package/dist/portable-files.d.ts +0 -10
  54. package/dist/portable-files.js +0 -36
  55. package/dist/preserve.d.ts +0 -21
  56. package/dist/preserve.js +0 -757
  57. package/dist/print.d.ts +0 -7
  58. package/dist/print.js +0 -409
  59. package/dist/reference-clipboard.d.ts +0 -8
  60. package/dist/reference-clipboard.js +0 -201
  61. package/dist/references.d.ts +0 -14
  62. package/dist/references.js +0 -368
  63. package/dist/search.d.ts +0 -15
  64. package/dist/search.js +0 -202
  65. package/dist/selection.d.ts +0 -1
  66. package/dist/selection.js +0 -59
  67. package/dist/source.d.ts +0 -16
  68. package/dist/source.js +0 -57
  69. package/dist/spreadsheet.d.ts +0 -3
  70. package/dist/spreadsheet.js +0 -275
  71. package/dist/table-alignment.d.ts +0 -2
  72. package/dist/table-alignment.js +0 -46
  73. package/dist/tables.d.ts +0 -27
  74. package/dist/tables.js +0 -322
  75. package/dist/tasks.d.ts +0 -3
  76. package/dist/tasks.js +0 -51
  77. package/dist/text-ranges.d.ts +0 -29
  78. package/dist/text-ranges.js +0 -256
  79. package/dist/types.js +0 -8
  80. package/dist/wiki-view.d.ts +0 -21
  81. package/dist/wiki-view.js +0 -78
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 {};
package/dist/images.js DELETED
@@ -1,398 +0,0 @@
1
- import { imageSchema } from '@milkdown/kit/preset/commonmark';
2
- import { closeHistory } from '@milkdown/kit/prose/history';
3
- import { $view } from '@milkdown/kit/utils';
4
- import { FileResolution } from './files.js';
5
- import { fileReference } from './linked-syntax.js';
6
- import { imageBlockSchema } from './image-blocks.js';
7
- /** A width rides in the alt text, as `![a picture|400](images/….png)`. Other Markdown readers
8
- * show the picture and keep the number without requiring a private extension. */
9
- export function splitAlt(alt) {
10
- const match = /^([\s\S]*)\|(\d{1,5})$/.exec(alt);
11
- if (!match)
12
- return { alt, width: null };
13
- return { alt: match[1] ?? '', width: Number(match[2]) };
14
- }
15
- export function joinAlt(alt, width) {
16
- return width == null ? alt : `${alt}|${width}`;
17
- }
18
- const minimumWidth = 48;
19
- class ImageView {
20
- node;
21
- view;
22
- getPos;
23
- adapter;
24
- runtime;
25
- canMutate;
26
- dom;
27
- /** The card or picture, which a standalone image's block row holds. */
28
- element;
29
- image;
30
- media;
31
- pdf;
32
- width = null;
33
- stopResize;
34
- resolution;
35
- previewFailed = false;
36
- constructor(node, view, getPos, adapter, runtime, canMutate = () => true) {
37
- this.node = node;
38
- this.view = view;
39
- this.getPos = getPos;
40
- this.adapter = adapter;
41
- this.runtime = runtime;
42
- this.canMutate = canMutate;
43
- this.element = document.createElement('span');
44
- this.element.className = 'image';
45
- if (node.isBlock) {
46
- this.dom = document.createElement('div');
47
- this.dom.className = 'inkkit-image-block';
48
- this.dom.append(this.element);
49
- }
50
- else
51
- this.dom = this.element;
52
- this.view.dom.addEventListener('inkkit-cancel-resize', this.cancelResize);
53
- this.view.dom.addEventListener('inkkit-media-policy', this.mediaPolicy);
54
- if (runtime) {
55
- this.resolution = new FileResolution({ ...runtime, active: () => this.active() }, () => {
56
- this.previewFailed = false;
57
- this.render();
58
- });
59
- this.resolution.update(this.reference());
60
- }
61
- this.render();
62
- }
63
- reference() {
64
- return fileReference(this.node);
65
- }
66
- active() {
67
- return (!!this.runtime?.active() &&
68
- !this.dom.closest('[data-inkkit-folded="true"], [hidden]'));
69
- }
70
- update(node) {
71
- if (node.type !== this.node.type)
72
- return false;
73
- if (node.sameMarkup(this.node)) {
74
- this.node = node;
75
- return true;
76
- }
77
- this.node = node;
78
- this.previewFailed = false;
79
- this.resolution?.update(this.reference());
80
- this.render();
81
- return true;
82
- }
83
- stopEvent(event) {
84
- return (event.target instanceof Element &&
85
- !!event.target.closest('.image-handle, .inkkit-file-control, audio, video, iframe'));
86
- }
87
- ignoreMutation() {
88
- return true;
89
- }
90
- mediaPolicy = () => {
91
- if (!this.runtime)
92
- return;
93
- if (!this.active()) {
94
- this.stopResize?.();
95
- this.stopResize = undefined;
96
- this.resolution?.cancel();
97
- this.releaseMedia();
98
- this.render();
99
- }
100
- else
101
- this.resolution?.update(this.reference());
102
- };
103
- cancelResize = () => {
104
- if (!this.stopResize)
105
- return;
106
- this.stopResize?.();
107
- this.stopResize = undefined;
108
- this.render();
109
- };
110
- releaseMedia() {
111
- const media = this.media;
112
- this.media = undefined;
113
- if (media) {
114
- media.pause();
115
- media.removeAttribute('src');
116
- media.load();
117
- }
118
- this.pdf?.removeAttribute('src');
119
- this.pdf = undefined;
120
- }
121
- destroy() {
122
- this.view.dom.removeEventListener('inkkit-cancel-resize', this.cancelResize);
123
- this.view.dom.removeEventListener('inkkit-media-policy', this.mediaPolicy);
124
- this.stopResize?.();
125
- this.stopResize = undefined;
126
- this.resolution?.destroy();
127
- this.releaseMedia();
128
- }
129
- button(label, action) {
130
- const button = document.createElement('button');
131
- button.type = 'button';
132
- button.className = 'inkkit-file-control';
133
- button.textContent = label;
134
- button.addEventListener('click', (event) => {
135
- event.preventDefault();
136
- action();
137
- });
138
- return button;
139
- }
140
- activate = () => {
141
- if (!this.runtime || !this.active())
142
- return;
143
- const captured = this.runtime.capture();
144
- try {
145
- if (captured.isCurrent())
146
- this.runtime.adapter.open?.(this.reference(), captured.context);
147
- }
148
- catch (error) {
149
- this.report(error);
150
- }
151
- };
152
- report(error) {
153
- this.runtime?.error?.(error instanceof Error ? error : new Error(String(error)));
154
- }
155
- card(label, status, retry = false) {
156
- const footer = document.createElement('span');
157
- footer.className = 'inkkit-file-footer';
158
- const name = document.createElement('span');
159
- name.className = 'inkkit-file-name';
160
- const text = document.createElement('span');
161
- text.className = 'inkkit-file-label';
162
- text.textContent = label;
163
- text.title = label;
164
- name.append(text);
165
- if (this.runtime?.adapter.open) {
166
- const open = this.button('', this.activate);
167
- open.classList.add('inkkit-file-open');
168
- open.setAttribute('aria-label', `${this.runtime.labels.fileOpen} ${label}`);
169
- open.title = this.runtime.labels.fileOpen;
170
- open.append(openArrow());
171
- name.append(open);
172
- }
173
- footer.append(name);
174
- if (status) {
175
- const description = document.createElement('span');
176
- description.className = 'inkkit-file-status';
177
- description.setAttribute('role', 'status');
178
- description.textContent = status;
179
- footer.append(description);
180
- }
181
- if (retry && this.runtime)
182
- footer.append(this.button(this.runtime.labels.fileRetry, () => this.resolution?.retry()));
183
- this.element.append(footer);
184
- }
185
- failPreview() {
186
- this.previewFailed = true;
187
- this.runtime?.error?.(new Error(this.runtime.labels.filePreviewUnavailable));
188
- this.render();
189
- }
190
- render() {
191
- this.stopResize?.();
192
- this.stopResize = undefined;
193
- this.releaseMedia();
194
- const reference = this.reference();
195
- const { alt, width } = this.node.attrs.inkkitFileRaw
196
- ? {
197
- alt: reference.label ?? reference.reference,
198
- width: reference.width ?? null,
199
- }
200
- : splitAlt(String(this.node.attrs.alt ?? ''));
201
- this.width = width;
202
- this.element.textContent = '';
203
- this.image = undefined;
204
- if (this.runtime) {
205
- this.element.classList.add('inkkit-file');
206
- this.element.oncontextmenu = (event) => {
207
- if (!this.runtime?.adapter.contextMenu || !this.active())
208
- return;
209
- const captured = this.runtime.capture();
210
- if (!captured.isCurrent())
211
- return;
212
- event.preventDefault();
213
- try {
214
- this.runtime.adapter.contextMenu(this.reference(), { clientX: event.clientX, clientY: event.clientY }, captured.context);
215
- }
216
- catch (error) {
217
- this.report(error);
218
- }
219
- };
220
- const state = this.resolution.state;
221
- const label = state.status === 'resolved'
222
- ? state.presentation.label || alt || reference.reference
223
- : alt || reference.reference;
224
- this.element.setAttribute('aria-label', label);
225
- this.element.dataset.inkkitFileState = this.previewFailed
226
- ? 'error'
227
- : state.status;
228
- this.element.dataset.inkkitFileKind =
229
- state.status === 'resolved' ? state.presentation.kind : 'file';
230
- if (this.previewFailed) {
231
- this.card(label, this.runtime.labels.filePreviewUnavailable, true);
232
- return;
233
- }
234
- if (state.status === 'loading' || state.status === 'idle') {
235
- this.card(label, this.runtime.labels.fileLoading, true);
236
- return;
237
- }
238
- if (state.status === 'failed') {
239
- this.card(label, this.runtime.labels.fileError, true);
240
- return;
241
- }
242
- const presentation = state.presentation;
243
- if (presentation.kind === 'missing' || presentation.kind === 'error') {
244
- this.card(label, presentation.kind === 'missing'
245
- ? this.runtime.labels.fileMissing
246
- : this.runtime.labels.fileError, true);
247
- }
248
- else if (presentation.kind === 'image') {
249
- this.renderImage(presentation.url, label, width);
250
- this.card(label);
251
- }
252
- else if (presentation.kind === 'audio' ||
253
- presentation.kind === 'video') {
254
- const media = document.createElement(presentation.kind);
255
- media.controls = true;
256
- media.preload = 'metadata';
257
- if (width != null)
258
- media.style.width = `${width}px`;
259
- media.setAttribute('aria-label', label);
260
- media.addEventListener('error', () => {
261
- if (this.media === media)
262
- this.failPreview();
263
- });
264
- media.src = presentation.url;
265
- this.media = media;
266
- this.element.append(media);
267
- this.card(label);
268
- }
269
- else if (presentation.kind === 'pdf') {
270
- const pdf = document.createElement('iframe');
271
- pdf.title = label;
272
- pdf.setAttribute('sandbox', '');
273
- pdf.referrerPolicy = 'no-referrer';
274
- if (width != null)
275
- pdf.style.width = `${width}px`;
276
- pdf.addEventListener('error', () => {
277
- if (this.pdf === pdf)
278
- this.failPreview();
279
- });
280
- pdf.src = presentation.url;
281
- this.pdf = pdf;
282
- this.element.append(pdf);
283
- this.card(label, this.runtime.labels.filePDFPreview);
284
- }
285
- else
286
- this.card(label);
287
- return;
288
- }
289
- const presentation = this.adapter?.presentation(String(this.node.attrs.src ?? ''));
290
- if (!presentation) {
291
- this.element.classList.add('image-absent');
292
- this.element.textContent = alt || String(this.node.attrs.src ?? '');
293
- return;
294
- }
295
- this.element.classList.remove('image-absent');
296
- this.renderImage(presentation.url, alt, width);
297
- }
298
- renderImage(url, alt, width) {
299
- const image = document.createElement('img');
300
- image.alt = alt;
301
- if (this.node.attrs.title)
302
- image.title = String(this.node.attrs.title);
303
- if (width != null)
304
- image.style.width = `${width}px`;
305
- if (this.runtime)
306
- image.addEventListener('error', () => {
307
- if (this.image === image)
308
- this.failPreview();
309
- });
310
- image.src = url;
311
- this.image = image;
312
- const preview = document.createElement('span');
313
- preview.className = 'inkkit-image-preview';
314
- preview.append(image);
315
- // The grip sits on the whole card, so it centres on the picture and its name together.
316
- const handle = document.createElement('span');
317
- handle.className = 'image-handle';
318
- handle.addEventListener('pointerdown', this.startResize);
319
- this.element.append(preview, handle);
320
- }
321
- startResize = (event) => {
322
- event.preventDefault();
323
- const image = this.image;
324
- if (!image || !this.canResize())
325
- return;
326
- const handle = event.currentTarget;
327
- const startX = event.clientX;
328
- const startWidth = image.getBoundingClientRect().width;
329
- const limit = this.view.dom.clientWidth;
330
- handle.setPointerCapture?.(event.pointerId);
331
- const move = (moved) => {
332
- if (!this.canResize()) {
333
- this.cancelResize();
334
- return;
335
- }
336
- this.width = Math.round(Math.min(limit, Math.max(minimumWidth, startWidth + moved.clientX - startX)));
337
- image.style.width = `${this.width}px`;
338
- };
339
- const cleanup = () => {
340
- handle.removeEventListener('pointermove', move);
341
- handle.removeEventListener('pointerup', done);
342
- handle.removeEventListener('pointercancel', cancel);
343
- };
344
- const done = () => {
345
- cleanup();
346
- this.stopResize = undefined;
347
- this.commit();
348
- };
349
- const cancel = () => {
350
- cleanup();
351
- this.stopResize = undefined;
352
- this.render();
353
- };
354
- this.stopResize = cleanup;
355
- handle.addEventListener('pointermove', move);
356
- handle.addEventListener('pointerup', done);
357
- handle.addEventListener('pointercancel', cancel);
358
- };
359
- commit() {
360
- if (!this.canResize()) {
361
- this.render();
362
- return;
363
- }
364
- const pos = this.getPos();
365
- if (pos == null)
366
- return;
367
- const alt = this.node.attrs.inkkitFileRaw
368
- ? (this.reference().label ?? this.reference().reference)
369
- : splitAlt(String(this.node.attrs.alt ?? '')).alt;
370
- const next = joinAlt(alt, this.width);
371
- if (next === this.node.attrs.alt)
372
- return;
373
- const { state } = this.view;
374
- this.view.dispatch(closeHistory(state.tr.setNodeMarkup(pos, undefined, {
375
- ...this.node.attrs,
376
- alt: next,
377
- })));
378
- this.view.dispatch(closeHistory(this.view.state.tr));
379
- }
380
- canResize() {
381
- return this.view.editable && !this.view.composing && this.canMutate();
382
- }
383
- }
384
- const svg = 'http://www.w3.org/2000/svg';
385
- function openArrow() {
386
- const icon = document.createElementNS(svg, 'svg');
387
- icon.setAttribute('viewBox', '0 0 12 12');
388
- icon.setAttribute('aria-hidden', 'true');
389
- icon.setAttribute('focusable', 'false');
390
- const path = document.createElementNS(svg, 'path');
391
- path.setAttribute('d', 'M4 2.5h5.5V8M9.5 2.5 2.5 9.5');
392
- icon.append(path);
393
- return icon;
394
- }
395
- export function imageView(adapter, runtime, canMutate = () => true) {
396
- const view = (schema) => $view(schema.node, () => (node, view, getPos) => new ImageView(node, view, getPos, adapter, runtime, canMutate));
397
- return [view(imageSchema), view(imageBlockSchema)];
398
- }
@@ -1,6 +0,0 @@
1
- export declare const remarkInlineHighlightPlugin: import("@milkdown/kit/utils").$Remark<"inkkitInlineHighlight", unknown>;
2
- export declare const highlightSchema: import("@milkdown/kit/utils").$MarkSchema<"highlight">;
3
- export declare const toggleHighlightCommand: import("@milkdown/kit/utils").$Command<unknown>;
4
- export declare const highlightInputRule: import("@milkdown/kit/utils").$InputRule;
5
- export declare const highlightKeymap: import("@milkdown/kit/utils").$UserKeymap<"highlightKeymap", "ToggleHighlight">;
6
- export declare const inlineHighlight: (import("@milkdown/kit/utils").$Command<unknown> | import("@milkdown/kit/utils").$Ctx<unknown, "inkkitInlineHighlight"> | import("@milkdown/kit/utils").$Ctx<import("@milkdown/kit/utils").GetMarkSchema, "highlight"> | import("@milkdown/kit/utils").$Ctx<import("@milkdown/kit/utils").KeymapConfig<"ToggleHighlight">, "highlightKeymapKeymap"> | import("@milkdown/kit/utils").$InputRule | import("@milkdown/kit/utils").$Mark | import("@milkdown/kit/utils").$Shortcut | import("@milkdown/kit/ctx").MilkdownPlugin)[];
@@ -1,112 +0,0 @@
1
- import { commandsCtx, remarkCtx } from '@milkdown/kit/core';
2
- import { markRule } from '@milkdown/kit/prose';
3
- import { toggleMark } from '@milkdown/kit/prose/commands';
4
- import { InputRule } from '@milkdown/kit/prose/inputrules';
5
- import { EditorState, TextSelection } from '@milkdown/kit/prose/state';
6
- import { $command, $inputRule, $markSchema, $remark, $useKeymap, } from '@milkdown/kit/utils';
7
- import { highlightMark } from 'micromark-extension-highlight-mark';
8
- import { highlightMarkFromMarkdown, highlightMarkToMarkdown, } from 'mdast-util-highlight-mark';
9
- // The current serializer's attention handling encodes ambiguous whitespace and
10
- // punctuation boundaries; the highlight provider predates that API.
11
- const highlight = (node, _parent, state, info) => {
12
- const exit = state.enter('phrasing');
13
- const value = state.containerPhrasing({ type: 'root', children: [node] }, info);
14
- exit();
15
- return value;
16
- };
17
- highlight.attention = () => ({
18
- construct: 'highlight',
19
- markers: ['='],
20
- sizes: [2],
21
- });
22
- highlight.peek = () => '=';
23
- function remarkInlineHighlight() {
24
- const data = this.data();
25
- (data.micromarkExtensions ??= []).push(highlightMark());
26
- (data.fromMarkdownExtensions ??= []).push(highlightMarkFromMarkdown);
27
- (data.toMarkdownExtensions ??= []).push({
28
- ...highlightMarkToMarkdown,
29
- handlers: { highlight },
30
- });
31
- }
32
- export const remarkInlineHighlightPlugin = $remark('inkkitInlineHighlight', () => remarkInlineHighlight);
33
- export const highlightSchema = $markSchema('highlight', () => ({
34
- priority: 45,
35
- parseDOM: [{ tag: 'mark' }],
36
- toDOM: () => ['mark', 0],
37
- parseMarkdown: {
38
- match: (node) => node.type === 'highlight',
39
- runner(state, node, type) {
40
- state.openMark(type);
41
- state.next(node.children);
42
- state.closeMark(type);
43
- },
44
- },
45
- toMarkdown: {
46
- match: (mark) => mark.type.name === 'highlight',
47
- runner(state, mark, node) {
48
- if (node.isText && /^\s*$/.test(node.text ?? '')) {
49
- return;
50
- }
51
- state.withMark(mark, 'highlight');
52
- },
53
- },
54
- }));
55
- export const toggleHighlightCommand = $command('ToggleHighlight', (ctx) => () => toggleMark(highlightSchema.type(ctx)));
56
- export const highlightInputRule = $inputRule((ctx) => {
57
- const pattern = /==([^\n]+)==$/;
58
- const rule = markRule(pattern, highlightSchema.type(ctx));
59
- const apply = rule.handler;
60
- return new InputRule(pattern, (state, match, start, end) => {
61
- const parentStart = state.selection.$from.start();
62
- const prefix = state.selection.$from.parent.textBetween(0, start - parentStart);
63
- const source = prefix + match[0];
64
- const tree = ctx.get(remarkCtx).parse(source);
65
- let valid = false;
66
- const walk = (node) => {
67
- if (node.type === 'highlight' &&
68
- node.position?.start.offset === prefix.length &&
69
- node.position.end.offset === source.length)
70
- valid = true;
71
- if ('children' in node)
72
- node.children.forEach(walk);
73
- };
74
- walk(tree);
75
- if (!valid)
76
- return null;
77
- const { from, to } = state.selection;
78
- const typed = match[0].slice(from - start);
79
- if (typed.length <= 1 && state.selection.empty)
80
- return apply(state, match, start, end);
81
- // Milkdown's mark rule expects only the final character to be absent.
82
- // Prepare buffered input without applying plugins or dispatching twice.
83
- const tr = state.tr.insertText(typed.slice(0, -1), from, to);
84
- const preparedEnd = from + typed.length - 1;
85
- const prepared = EditorState.create({
86
- schema: state.schema,
87
- doc: tr.doc,
88
- selection: TextSelection.create(tr.doc, preparedEnd),
89
- storedMarks: state.storedMarks,
90
- });
91
- const transformed = apply(prepared, match, start, preparedEnd);
92
- if (!transformed)
93
- return null;
94
- transformed.steps.forEach((step) => tr.step(step));
95
- tr.setSelection(TextSelection.create(tr.doc, transformed.selection.from, transformed.selection.to));
96
- tr.setStoredMarks(transformed.storedMarks);
97
- return tr;
98
- });
99
- });
100
- export const highlightKeymap = $useKeymap('highlightKeymap', {
101
- ToggleHighlight: {
102
- shortcuts: ['Mod-Shift-h'],
103
- command: (ctx) => () => ctx.get(commandsCtx).call(toggleHighlightCommand.key),
104
- },
105
- });
106
- export const inlineHighlight = [
107
- remarkInlineHighlightPlugin,
108
- highlightSchema,
109
- toggleHighlightCommand,
110
- highlightInputRule,
111
- highlightKeymap,
112
- ].flat();
package/dist/labels.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { Ctx } from '@milkdown/kit/ctx';
2
- /** Built-in editor text. Hosts can override individual labels at mount time. */
3
- export interface EditorLabels {
4
- formattedEditor: string;
5
- plainTextEditor: string;
6
- sourceEditor: string;
7
- placeholder: string;
8
- copyCode: string;
9
- expandCallout: string;
10
- collapseCallout: string;
11
- diagramRendering: string;
12
- /** Prefix shown before the renderer's diagnostic message. */
13
- diagramUnavailable: string;
14
- /** Prefix followed by the authored footnote label. */
15
- footnote: string;
16
- tableAddRow: string;
17
- tableAddColumn: string;
18
- tableDeleteRow: string;
19
- tableDeleteColumn: string;
20
- tableAlignLeft: string;
21
- tableAlignCenter: string;
22
- tableAlignRight: string;
23
- tableMoveColumn: string;
24
- tableMoveRow: string;
25
- fileLoading: string;
26
- fileMissing: string;
27
- fileError: string;
28
- fileRetry: string;
29
- fileOpen: string;
30
- filePreviewUnavailable: string;
31
- filePDFPreview: string;
32
- wikiMissing: string;
33
- }
34
- export declare const defaultLabels: Readonly<EditorLabels>;
35
- export declare const labelsCtx: import("@milkdown/kit/utils").$Ctx<Readonly<EditorLabels>, "inkkitLabels">;
36
- export declare function editorLabels(ctx: Ctx): Readonly<EditorLabels>;
package/dist/labels.js DELETED
@@ -1,34 +0,0 @@
1
- import { $ctx } from '@milkdown/kit/utils';
2
- export const defaultLabels = {
3
- formattedEditor: 'Formatted Markdown editor',
4
- plainTextEditor: 'Plain text editor',
5
- sourceEditor: 'Markdown source editor',
6
- placeholder: 'Start typing…',
7
- copyCode: 'Copy',
8
- expandCallout: 'Expand',
9
- collapseCallout: 'Collapse',
10
- diagramRendering: 'Rendering diagram…',
11
- diagramUnavailable: 'Diagram unavailable:',
12
- footnote: 'Footnote',
13
- tableAddRow: 'Add row',
14
- tableAddColumn: 'Add column',
15
- tableDeleteRow: 'Delete row',
16
- tableDeleteColumn: 'Delete column',
17
- tableAlignLeft: 'Align left',
18
- tableAlignCenter: 'Align center',
19
- tableAlignRight: 'Align right',
20
- tableMoveColumn: 'Move column',
21
- tableMoveRow: 'Move row',
22
- fileLoading: 'Loading file…',
23
- fileMissing: 'File unavailable',
24
- fileError: 'File could not be loaded',
25
- fileRetry: 'Retry',
26
- fileOpen: 'Open',
27
- filePreviewUnavailable: 'Preview unavailable',
28
- filePDFPreview: 'Open to view this PDF',
29
- wikiMissing: 'Link unavailable',
30
- };
31
- export const labelsCtx = $ctx(defaultLabels, 'inkkitLabels');
32
- export function editorLabels(ctx) {
33
- return ctx.isInjected(labelsCtx.key) ? ctx.get(labelsCtx.key) : defaultLabels;
34
- }
@@ -1,48 +0,0 @@
1
- import type { Node as ProseNode } from '@milkdown/kit/prose/model';
2
- import type { Literal } from 'mdast';
3
- import type { FileReference, WikiLinkReference } from './types.js';
4
- interface WikiLink extends Literal {
5
- type: 'inkkitWikiLink';
6
- raw: string;
7
- target: string;
8
- fragment: string | null;
9
- label: string;
10
- inTable: boolean;
11
- }
12
- declare module 'mdast' {
13
- interface PhrasingContentMap {
14
- inkkitWikiLink: WikiLink;
15
- }
16
- interface RootContentMap {
17
- inkkitWikiLink: WikiLink;
18
- }
19
- interface Image {
20
- inkkitFileRaw?: string;
21
- inkkitFileTarget?: string;
22
- inkkitFileFragment?: string | null;
23
- inkkitFileWidth?: number | null;
24
- inkkitFileInTable?: boolean;
25
- }
26
- }
27
- declare module 'micromark-util-types' {
28
- interface TokenTypeMap {
29
- inkkitLinkedSyntax: 'inkkitLinkedSyntax';
30
- }
31
- }
32
- export interface LinkedSyntax {
33
- raw: string;
34
- target: string;
35
- fragment: string | null;
36
- label: string;
37
- width: number | null;
38
- embed: boolean;
39
- inTable: boolean;
40
- }
41
- export declare function parseLinkedSyntax(raw: string, inTable?: boolean): LinkedSyntax | undefined;
42
- export declare function wikiMarkdown(node: ProseNode, inTable?: boolean): string;
43
- export declare function wikiReference(node: ProseNode): WikiLinkReference;
44
- export declare function fileReference(node: ProseNode): FileReference;
45
- export declare function namedFileMarkdown(node: ProseNode, inTable?: boolean): string | undefined;
46
- export declare const wikiLinkSchema: import("@milkdown/kit/utils").$Node;
47
- export declare function linkedSyntax(wikiLinks: boolean, files: boolean): import("@milkdown/kit/utils").$Remark<"inkkitLinkedSyntax", unknown>;
48
- export {};