@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/NOTICE +25 -2
- package/README.md +16 -16
- package/dist/callouts.js +6 -3
- package/dist/decorations.js +7 -6
- package/dist/editor.d.ts +65 -4
- package/dist/editor.js +396 -61
- package/dist/images.d.ts +1 -0
- package/dist/images.js +11 -0
- package/dist/index.d.ts +2 -1
- package/dist/labels.d.ts +28 -0
- package/dist/labels.js +26 -0
- package/dist/mermaid.js +6 -3
- package/dist/paste.d.ts +1 -0
- package/dist/paste.js +5 -1
- package/dist/references.js +5 -4
- package/dist/selection.js +22 -10
- package/dist/style.css +377 -299
- package/dist/tables.d.ts +10 -1
- package/dist/tables.js +87 -11
- package/dist/tasks.js +2 -0
- package/dist/types.d.ts +1 -1
- package/package.json +4 -2
package/dist/tables.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { Ctx } from '@milkdown/kit/ctx';
|
|
2
2
|
import { type Node as ProseNode } from '@milkdown/kit/prose/model';
|
|
3
3
|
import type { EditorView } from '@milkdown/kit/prose/view';
|
|
4
|
-
import type { Transaction } from '@milkdown/kit/prose/state';
|
|
4
|
+
import type { EditorState, Transaction } from '@milkdown/kit/prose/state';
|
|
5
5
|
export type TableCommand = 'insert' | 'addRowBefore' | 'addRowAfter' | 'addColumnBefore' | 'addColumnAfter' | 'deleteRow' | 'deleteColumn' | 'deleteTable' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'moveRowUp' | 'moveRowDown' | 'moveColumnLeft' | 'moveColumnRight' | 'sortRows' | 'exit';
|
|
6
|
+
export declare const tableCommands: readonly TableCommand[];
|
|
7
|
+
export declare function tableContext(state: EditorState): {
|
|
8
|
+
row: number;
|
|
9
|
+
column: number;
|
|
10
|
+
rows: number;
|
|
11
|
+
columns: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
/** Checks the same default operations without dispatching a transaction. */
|
|
14
|
+
export declare function tableAvailability(ctx: Ctx): Record<TableCommand, boolean>;
|
|
6
15
|
export interface TableOptions {
|
|
7
16
|
rows?: number;
|
|
8
17
|
columns?: number;
|
package/dist/tables.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { editorLabels } from './labels.js';
|
|
1
2
|
import { commandsCtx, editorViewCtx } from '@milkdown/kit/core';
|
|
2
3
|
import { tableBlock, tableBlockConfig, } from '@milkdown/kit/component/table-block';
|
|
3
4
|
import { insertTableCommand, exitTable, moveRowCommand, moveColCommand, } from '@milkdown/kit/preset/gfm';
|
|
@@ -7,17 +8,92 @@ import { closeHistory } from '@milkdown/kit/prose/history';
|
|
|
7
8
|
import { keymap } from '@milkdown/kit/prose/keymap';
|
|
8
9
|
import { $prose } from '@milkdown/kit/utils';
|
|
9
10
|
import { clipboardText } from './clipboard.js';
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
export const tableCommands = [
|
|
12
|
+
'insert',
|
|
13
|
+
'addRowBefore',
|
|
14
|
+
'addRowAfter',
|
|
15
|
+
'addColumnBefore',
|
|
16
|
+
'addColumnAfter',
|
|
17
|
+
'deleteRow',
|
|
18
|
+
'deleteColumn',
|
|
19
|
+
'deleteTable',
|
|
20
|
+
'alignLeft',
|
|
21
|
+
'alignCenter',
|
|
22
|
+
'alignRight',
|
|
23
|
+
'moveRowUp',
|
|
24
|
+
'moveRowDown',
|
|
25
|
+
'moveColumnLeft',
|
|
26
|
+
'moveColumnRight',
|
|
27
|
+
'sortRows',
|
|
28
|
+
'exit',
|
|
29
|
+
];
|
|
30
|
+
export function tableContext(state) {
|
|
31
|
+
if (!isInTable(state))
|
|
32
|
+
return undefined;
|
|
33
|
+
const rect = selectedRect(state);
|
|
34
|
+
return {
|
|
35
|
+
row: rect.top,
|
|
36
|
+
column: rect.left,
|
|
37
|
+
rows: rect.map.height,
|
|
38
|
+
columns: rect.map.width,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Checks the same default operations without dispatching a transaction. */
|
|
42
|
+
export function tableAvailability(ctx) {
|
|
43
|
+
const view = ctx.get(editorViewCtx);
|
|
44
|
+
const state = view.state;
|
|
45
|
+
const commands = ctx.get(commandsCtx);
|
|
46
|
+
const available = Object.fromEntries(tableCommands.map((name) => [name, false]));
|
|
47
|
+
available.insert = commands.get(insertTableCommand.key)({ row: 3, col: 2 })(state);
|
|
48
|
+
const actions = {
|
|
49
|
+
addRowBefore,
|
|
50
|
+
addRowAfter,
|
|
51
|
+
addColumnBefore,
|
|
52
|
+
addColumnAfter,
|
|
53
|
+
deleteRow,
|
|
54
|
+
deleteColumn,
|
|
55
|
+
deleteTable,
|
|
56
|
+
};
|
|
57
|
+
for (const [name, action] of Object.entries(actions))
|
|
58
|
+
available[name] = action(state);
|
|
59
|
+
available.exit = commands.get(exitTable.key)()(state);
|
|
60
|
+
if (!isInTable(state))
|
|
61
|
+
return available;
|
|
62
|
+
const rect = selectedRect(state);
|
|
63
|
+
available.alignLeft = available.alignCenter = available.alignRight = true;
|
|
64
|
+
if (!editableTable(rect.table))
|
|
65
|
+
return available;
|
|
66
|
+
available.moveRowUp = rect.top > 1;
|
|
67
|
+
available.moveRowDown = rect.top > 0 && rect.bottom < rect.map.height;
|
|
68
|
+
available.moveColumnLeft = rect.left > 0;
|
|
69
|
+
available.moveColumnRight = rect.right < rect.map.width;
|
|
70
|
+
const body = [];
|
|
71
|
+
rect.table.forEach((row, _offset, index) => {
|
|
72
|
+
if (index)
|
|
73
|
+
body.push({ key: clipboardText(row.child(rect.left).content), index });
|
|
74
|
+
});
|
|
75
|
+
const sorted = [...body].sort((a, b) => compareCells(a.key, b.key, 'text', 'ascending') || a.index - b.index);
|
|
76
|
+
available.sortRows = sorted.some((row, index) => row !== body[index]);
|
|
77
|
+
return available;
|
|
78
|
+
}
|
|
79
|
+
const tableLabels = {
|
|
80
|
+
add_row: 'tableAddRow',
|
|
81
|
+
add_col: 'tableAddColumn',
|
|
82
|
+
delete_row: 'tableDeleteRow',
|
|
83
|
+
delete_col: 'tableDeleteColumn',
|
|
84
|
+
align_col_left: 'tableAlignLeft',
|
|
85
|
+
align_col_center: 'tableAlignCenter',
|
|
86
|
+
align_col_right: 'tableAlignRight',
|
|
87
|
+
col_drag_handle: 'tableMoveColumn',
|
|
88
|
+
row_drag_handle: 'tableMoveRow',
|
|
20
89
|
};
|
|
90
|
+
function tableButton(label) {
|
|
91
|
+
const span = document.createElement('span');
|
|
92
|
+
span.setAttribute('role', 'img');
|
|
93
|
+
span.setAttribute('aria-label', label);
|
|
94
|
+
span.textContent = label;
|
|
95
|
+
return span.outerHTML;
|
|
96
|
+
}
|
|
21
97
|
export const tablePlugins = [
|
|
22
98
|
moveRowCommand,
|
|
23
99
|
moveColCommand,
|
|
@@ -25,7 +101,7 @@ export const tablePlugins = [
|
|
|
25
101
|
(ctx) => () => {
|
|
26
102
|
ctx.update(tableBlockConfig.key, (config) => ({
|
|
27
103
|
...config,
|
|
28
|
-
renderButton: (type) =>
|
|
104
|
+
renderButton: (type) => tableButton(editorLabels(ctx)[tableLabels[type]]),
|
|
29
105
|
}));
|
|
30
106
|
},
|
|
31
107
|
tableBlock,
|
package/dist/tasks.js
CHANGED
|
@@ -8,6 +8,8 @@ export const taskListPlugin = $prose(() => new Plugin({
|
|
|
8
8
|
key: new PluginKey('taskToggle'),
|
|
9
9
|
props: {
|
|
10
10
|
handleClickOn(view, _pos, node, nodePos, event) {
|
|
11
|
+
if (!view.editable)
|
|
12
|
+
return false;
|
|
11
13
|
if (node.type.name !== 'list_item' || node.attrs.checked == null)
|
|
12
14
|
return false;
|
|
13
15
|
const target = event.target;
|
package/dist/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface DocumentSnapshot extends DocumentInput {
|
|
|
14
14
|
revision: number;
|
|
15
15
|
dirty: boolean;
|
|
16
16
|
}
|
|
17
|
-
export type EditorErrorCode = 'not-ready' | 'stale-document' | 'composition' | 'operation-pending' | 'destroyed' | 'preservation' | 'image-unavailable' | 'diagram-unavailable';
|
|
17
|
+
export type EditorErrorCode = 'not-ready' | 'stale-document' | 'composition' | 'read-only' | 'operation-pending' | 'destroyed' | 'preservation' | 'image-unavailable' | 'diagram-unavailable';
|
|
18
18
|
export declare class InkKitError extends Error {
|
|
19
19
|
readonly code: EditorErrorCode;
|
|
20
20
|
constructor(code: EditorErrorCode, message: string);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aicayzer/inkkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A preserving Markdown editor for offline web views and the web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"dev": "vite playground",
|
|
43
43
|
"build:playground": "vite build playground --config vite.config.ts",
|
|
44
44
|
"test:package": "node scripts/test-package.mjs",
|
|
45
|
-
"check": "pnpm typecheck && pnpm test && pnpm build && pnpm test:package"
|
|
45
|
+
"check": "pnpm typecheck && pnpm test && pnpm build && pnpm test:package",
|
|
46
|
+
"test:browser": "playwright test --project=chromium"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@milkdown/kit": "7.22.1",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"prosemirror-search": "^1.1.1"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
72
|
+
"@playwright/test": "^1.64.0",
|
|
71
73
|
"@types/hast": "^3.0.5",
|
|
72
74
|
"@types/mdast": "^4.0.4",
|
|
73
75
|
"@types/node": "^26.6.2",
|