@aicayzer/inkkit 0.0.7 → 0.0.8

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/dist/images.d.ts CHANGED
@@ -23,6 +23,7 @@ declare class ImageView implements NodeView {
23
23
  update(node: ProseNode): boolean;
24
24
  stopEvent(event: Event): boolean;
25
25
  ignoreMutation(): boolean;
26
+ private cancelResize;
26
27
  destroy(): void;
27
28
  private render;
28
29
  private startResize;
package/dist/images.js CHANGED
@@ -30,6 +30,7 @@ class ImageView {
30
30
  this.adapter = adapter;
31
31
  this.dom = document.createElement('span');
32
32
  this.dom.className = 'image';
33
+ this.view.dom.addEventListener('inkkit-cancel-resize', this.cancelResize);
33
34
  this.render();
34
35
  }
35
36
  update(node) {
@@ -47,7 +48,13 @@ class ImageView {
47
48
  ignoreMutation() {
48
49
  return true;
49
50
  }
51
+ cancelResize = () => {
52
+ this.stopResize?.();
53
+ this.stopResize = undefined;
54
+ this.render();
55
+ };
50
56
  destroy() {
57
+ this.view.dom.removeEventListener('inkkit-cancel-resize', this.cancelResize);
51
58
  this.stopResize?.();
52
59
  this.stopResize = undefined;
53
60
  }
@@ -91,6 +98,10 @@ class ImageView {
91
98
  const limit = this.view.dom.clientWidth;
92
99
  handle.setPointerCapture?.(event.pointerId);
93
100
  const move = (moved) => {
101
+ if (!this.view.editable) {
102
+ this.cancelResize();
103
+ return;
104
+ }
94
105
  const next = Math.round(Math.min(limit, Math.max(minimumWidth, startWidth + (moved.clientX - startX))));
95
106
  this.width = next;
96
107
  image.style.width = `${next}px`;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { InkKitEditor } from './editor.js';
2
- export type { EditorEvents, EditingMode, CaretState, Mark, Block, FormatCommand, Keymap, } from './editor.js';
2
+ export type { EditorEvents, EditorOptions, TextInputPreferences, CommandState, EditingMode, CaretState, Mark, Block, FormatCommand, Keymap, } from './editor.js';
3
3
  export type { TableCommand, TableOptions } from './tables.js';
4
4
  export type { Heading } from './outline.js';
5
5
  export { InkKitError } from './types.js';
6
6
  export type { DocumentFormat, DocumentContext, DocumentInput, DocumentSnapshot, EditorErrorCode, ImageAdapter, CapturedImage, PortableImage, ClipboardInput, ClipboardOutput, ClipboardImage, ClipboardDiagram, PrintableDocument, PrintableWarning, } from './types.js';
7
+ export type { EditorLabels } from './labels.js';
@@ -0,0 +1,28 @@
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
+ }
26
+ export declare const defaultLabels: Readonly<EditorLabels>;
27
+ export declare const labelsCtx: import("@milkdown/kit/utils").$Ctx<Readonly<EditorLabels>, "inkkitLabels">;
28
+ export declare function editorLabels(ctx: Ctx): Readonly<EditorLabels>;
package/dist/labels.js ADDED
@@ -0,0 +1,26 @@
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
+ };
23
+ export const labelsCtx = $ctx(defaultLabels, 'inkkitLabels');
24
+ export function editorLabels(ctx) {
25
+ return ctx.isInjected(labelsCtx.key) ? ctx.get(labelsCtx.key) : defaultLabels;
26
+ }
package/dist/mermaid.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { editorLabels } from './labels.js';
1
2
  import mermaid from 'mermaid';
2
3
  import DOMPurify from 'dompurify';
3
4
  import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
@@ -166,7 +167,7 @@ export async function diagramImage(source) {
166
167
  }
167
168
  }
168
169
  export function mermaidPreview(onError) {
169
- return $prose(() => new Plugin({
170
+ return $prose((ctx) => new Plugin({
170
171
  key: new PluginKey('mermaidPreview'),
171
172
  props: {
172
173
  decorations(state) {
@@ -179,7 +180,9 @@ export function mermaidPreview(onError) {
179
180
  const preview = document.createElement('div');
180
181
  preview.className = 'inkkit-mermaid-preview';
181
182
  preview.contentEditable = 'false';
182
- preview.textContent = 'Rendering diagram…';
183
+ preview.textContent = editorLabels(ctx).diagramRendering;
184
+ preview.setAttribute('role', 'status');
185
+ preview.setAttribute('aria-live', 'polite');
183
186
  let active = true;
184
187
  preview.cancel =
185
188
  () => {
@@ -196,7 +199,7 @@ export function mermaidPreview(onError) {
196
199
  const message = error instanceof Error
197
200
  ? error.message
198
201
  : 'The diagram could not be rendered.';
199
- preview.textContent = `Diagram unavailable: ${message}`;
202
+ preview.textContent = `${editorLabels(ctx).diagramUnavailable} ${message}`;
200
203
  preview.dataset.state = 'error';
201
204
  onError(new InkKitError('diagram-unavailable', message));
202
205
  });
package/dist/paste.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface PasteControllerOptions {
5
5
  context: () => DocumentContext;
6
6
  adapter?: ImageAdapter;
7
7
  onError?: (error: unknown) => void;
8
+ onPendingChanged?: () => void;
8
9
  editable?: () => boolean;
9
10
  literalText?: () => boolean;
10
11
  }
package/dist/paste.js CHANGED
@@ -70,6 +70,7 @@ export class PasteController {
70
70
  }
71
71
  cancelPending() {
72
72
  this.active = undefined;
73
+ this.options.onPendingChanged?.();
73
74
  }
74
75
  destroy() {
75
76
  this.dead = true;
@@ -101,6 +102,7 @@ export class PasteController {
101
102
  to: view.state.selection.to,
102
103
  };
103
104
  this.active = operation;
105
+ this.options.onPendingChanged?.();
104
106
  try {
105
107
  const images = [...(input.images ?? [])];
106
108
  for (const file of files)
@@ -428,8 +430,10 @@ export class PasteController {
428
430
  .scrollIntoView());
429
431
  }
430
432
  finally {
431
- if (this.active === operation)
433
+ if (this.active === operation) {
432
434
  this.active = undefined;
435
+ this.options.onPendingChanged?.();
436
+ }
433
437
  }
434
438
  }
435
439
  }
@@ -1,3 +1,4 @@
1
+ import { editorLabels } from './labels.js';
1
2
  import { $node, $remark, $prose } from '@milkdown/kit/utils';
2
3
  import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
3
4
  import { linkSchema } from '@milkdown/kit/preset/commonmark';
@@ -247,7 +248,7 @@ export const referenceDefinition = $node('reference_definition', () => ({
247
248
  },
248
249
  },
249
250
  }));
250
- export const footnoteReference = $node('footnote_reference', () => ({
251
+ export const footnoteReference = $node('footnote_reference', (ctx) => ({
251
252
  inline: true,
252
253
  group: 'inline',
253
254
  atom: true,
@@ -268,7 +269,7 @@ export const footnoteReference = $node('footnote_reference', () => ({
268
269
  class: 'inkkit-footnote-reference',
269
270
  tabindex: '0',
270
271
  role: 'button',
271
- 'aria-label': `Footnote ${node.attrs.label}`,
272
+ 'aria-label': `${editorLabels(ctx).footnote} ${node.attrs.label}`,
272
273
  'data-inkkit-footnote-reference': node.attrs.identifier,
273
274
  'data-inkkit-label': node.attrs.label,
274
275
  },
@@ -292,7 +293,7 @@ export const footnoteReference = $node('footnote_reference', () => ({
292
293
  },
293
294
  },
294
295
  }));
295
- export const footnoteDefinition = $node('footnote_definition', () => ({
296
+ export const footnoteDefinition = $node('footnote_definition', (ctx) => ({
296
297
  group: 'block',
297
298
  content: 'block+',
298
299
  defining: true,
@@ -310,7 +311,7 @@ export const footnoteDefinition = $node('footnote_definition', () => ({
310
311
  'div',
311
312
  {
312
313
  class: 'inkkit-footnote-definition',
313
- 'aria-label': `Footnote ${node.attrs.label}`,
314
+ 'aria-label': `${editorLabels(ctx).footnote} ${node.attrs.label}`,
314
315
  'data-inkkit-footnote-definition': node.attrs.identifier,
315
316
  'data-inkkit-label': node.attrs.label,
316
317
  },
package/dist/selection.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
2
2
  import { $prose } from '@milkdown/kit/utils';
3
3
  /** The stylesheet paints the selection under this name. */
4
- const name = 'selection';
4
+ const name = 'inkkit-selection';
5
+ const ranges = new Map();
5
6
  /** The selected text within each block. */
6
7
  function covered(state) {
7
8
  const { from, to, empty, visible } = state.selection;
@@ -27,21 +28,32 @@ function domRange(view, span) {
27
28
  range.setEnd(end.node, end.offset);
28
29
  return range;
29
30
  }
30
- function paint(view, highlight) {
31
- highlight.clear();
32
- for (const span of covered(view.state) ?? [])
33
- highlight.add(domRange(view, span));
31
+ function paint(view) {
32
+ ranges.set(view, (covered(view.state) ?? []).map((span) => domRange(view, span)));
33
+ refresh();
34
+ }
35
+ function refresh() {
36
+ if (ranges.size === 0) {
37
+ CSS.highlights.delete(name);
38
+ return;
39
+ }
40
+ const highlight = new Highlight();
41
+ for (const selection of ranges.values())
42
+ for (const range of selection)
43
+ highlight.add(range);
44
+ CSS.highlights.set(name, highlight);
34
45
  }
35
46
  // Paint only selected text, without WebKit filling the surrounding margins.
36
47
  export const selectionPlugin = $prose(() => new Plugin({
37
48
  key: new PluginKey('selection'),
38
49
  view(view) {
39
- const highlight = new Highlight();
40
- CSS.highlights.set(name, highlight);
41
- paint(view, highlight);
50
+ paint(view);
42
51
  return {
43
- update: (view) => paint(view, highlight),
44
- destroy: () => CSS.highlights.delete(name),
52
+ update: (view) => paint(view),
53
+ destroy: () => {
54
+ ranges.delete(view);
55
+ refresh();
56
+ },
45
57
  };
46
58
  },
47
59
  }));