@prosekit/extensions 0.7.11 → 0.7.13
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/_tsup-dts-rollup.d.ts +236 -5
- package/dist/loro/style.css +30 -0
- package/dist/prosekit-extensions-loro.d.ts +11 -0
- package/dist/prosekit-extensions-loro.js +79 -0
- package/dist/prosekit-extensions-table.d.ts +15 -3
- package/dist/prosekit-extensions-table.js +170 -26
- package/dist/table/style.css +6 -1
- package/package.json +23 -2
@@ -8,7 +8,10 @@ import { bundledLanguagesInfo } from 'shiki';
|
|
8
8
|
import { BundledTheme } from 'shiki';
|
9
9
|
import { BundledThemeInfo } from 'shiki';
|
10
10
|
import { bundledThemesInfo } from 'shiki';
|
11
|
+
import { CellSelection } from 'prosemirror-tables';
|
11
12
|
import { Command } from '@prosekit/pm/state';
|
13
|
+
import { CursorAwareness } from 'loro-prosemirror';
|
14
|
+
import type { DecorationAttrs } from '@prosekit/pm/view';
|
12
15
|
import { DedentListOptions } from 'prosemirror-flat-list';
|
13
16
|
import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
|
14
17
|
import { DocExtension } from '@prosekit/core';
|
@@ -17,6 +20,7 @@ import { Extension } from '@prosekit/core';
|
|
17
20
|
import { ExtensionTyping } from '@prosekit/core';
|
18
21
|
import { ExtractMarkActions } from '@prosekit/core';
|
19
22
|
import { ExtractNodeActions } from '@prosekit/core';
|
23
|
+
import { FindParentNodeResult } from '@prosekit/core';
|
20
24
|
import { GapCursor } from 'prosemirror-gapcursor';
|
21
25
|
import { getSingletonHighlighter } from 'shiki/bundle/full';
|
22
26
|
import type { Highlighter } from 'shiki';
|
@@ -26,6 +30,9 @@ import { InputRule } from '@prosekit/pm/inputrules';
|
|
26
30
|
import type { IsEqual } from 'type-fest';
|
27
31
|
import { ListAttributes } from 'prosemirror-flat-list';
|
28
32
|
import { ListDOMSerializer } from 'prosemirror-flat-list';
|
33
|
+
import type { LoroDocType } from 'loro-prosemirror';
|
34
|
+
import { LoroSyncPluginProps } from 'loro-prosemirror';
|
35
|
+
import { LoroUndoPluginProps } from 'loro-prosemirror';
|
29
36
|
import { MarkType } from '@prosekit/pm/model';
|
30
37
|
import { Node as Node_2 } from 'prosemirror-model';
|
31
38
|
import { NodeAction } from '@prosekit/core';
|
@@ -34,10 +41,13 @@ import { NodeJSON } from '@prosekit/core';
|
|
34
41
|
import type { NodeType } from '@prosekit/pm/model';
|
35
42
|
import { Options } from 'tsup';
|
36
43
|
import { Parser } from 'prosemirror-highlight';
|
44
|
+
import type { PeerID } from 'loro-crdt';
|
37
45
|
import { PlainExtension } from '@prosekit/core';
|
38
46
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
39
47
|
import { PluginKey } from '@prosekit/pm/state';
|
40
48
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
49
|
+
import type { ResolvedPos } from '@prosekit/pm/model';
|
50
|
+
import type { Selection as Selection_2 } from '@prosekit/pm/state';
|
41
51
|
import { SimplifyDeeper } from '@prosekit/core';
|
42
52
|
import type { SpecialLanguage } from 'shiki';
|
43
53
|
import { StepJSON } from '@prosekit/core';
|
@@ -663,6 +673,31 @@ declare function defineListSpec(): ListSpecExtension;
|
|
663
673
|
export { defineListSpec }
|
664
674
|
export { defineListSpec as defineListSpec_alias_1 }
|
665
675
|
|
676
|
+
/**
|
677
|
+
* @public
|
678
|
+
*/
|
679
|
+
export declare function defineLoro(options: LoroOptions): LoroExtension;
|
680
|
+
|
681
|
+
declare function defineLoroCommands(): LoroCommandsExtension;
|
682
|
+
export { defineLoroCommands }
|
683
|
+
export { defineLoroCommands as defineLoroCommands_alias_1 }
|
684
|
+
|
685
|
+
declare function defineLoroCursorPlugin(options: LoroCursorOptions): PlainExtension;
|
686
|
+
export { defineLoroCursorPlugin }
|
687
|
+
export { defineLoroCursorPlugin as defineLoroCursorPlugin_alias_1 }
|
688
|
+
|
689
|
+
declare function defineLoroKeymap(): PlainExtension;
|
690
|
+
export { defineLoroKeymap }
|
691
|
+
export { defineLoroKeymap as defineLoroKeymap_alias_1 }
|
692
|
+
|
693
|
+
declare function defineLoroSyncPlugin(options: LoroSyncPluginProps): PlainExtension;
|
694
|
+
export { defineLoroSyncPlugin }
|
695
|
+
export { defineLoroSyncPlugin as defineLoroSyncPlugin_alias_1 }
|
696
|
+
|
697
|
+
declare function defineLoroUndoPlugin(options: LoroUndoPluginProps): PlainExtension;
|
698
|
+
export { defineLoroUndoPlugin }
|
699
|
+
export { defineLoroUndoPlugin as defineLoroUndoPlugin_alias_1 }
|
700
|
+
|
666
701
|
/**
|
667
702
|
* Defines an input rule for automatically adding inline marks when a given
|
668
703
|
* pattern is typed.
|
@@ -779,7 +814,9 @@ export declare function defineStrikeSpec(): StrikeSpecExtension;
|
|
779
814
|
/**
|
780
815
|
* @public
|
781
816
|
*/
|
782
|
-
|
817
|
+
declare function defineTable(): TableExtension;
|
818
|
+
export { defineTable }
|
819
|
+
export { defineTable as defineTable_alias_1 }
|
783
820
|
|
784
821
|
/**
|
785
822
|
* @internal
|
@@ -1054,7 +1091,27 @@ export declare type EnterRuleOptions = {
|
|
1054
1091
|
*
|
1055
1092
|
* @public
|
1056
1093
|
*/
|
1057
|
-
|
1094
|
+
declare const exitTable: Command;
|
1095
|
+
export { exitTable }
|
1096
|
+
export { exitTable as exitTable_alias_1 }
|
1097
|
+
|
1098
|
+
/**
|
1099
|
+
* Try to find a resolved pos of a cell by using the given pos as a hit point.
|
1100
|
+
*
|
1101
|
+
* @internal
|
1102
|
+
*/
|
1103
|
+
export declare function findCellPos(doc: ProseMirrorNode, pos: number): ResolvedPos | undefined;
|
1104
|
+
|
1105
|
+
/**
|
1106
|
+
* Try to find the anchor and head cell in the same table by using the given
|
1107
|
+
* anchor and head as hit points, or fallback to the selection's anchor and
|
1108
|
+
* head.
|
1109
|
+
*
|
1110
|
+
* @internal
|
1111
|
+
*/
|
1112
|
+
export declare function findCellRange(selection: Selection_2, anchorHit?: number, headHit?: number): [ResolvedPos, ResolvedPos] | undefined;
|
1113
|
+
|
1114
|
+
export declare function findTable($pos: ResolvedPos): FindParentNodeResult | undefined;
|
1058
1115
|
|
1059
1116
|
export { GapCursor }
|
1060
1117
|
|
@@ -1164,22 +1221,39 @@ export declare type ImageSpecExtension = Extension<{
|
|
1164
1221
|
|
1165
1222
|
export { IndentListOptions }
|
1166
1223
|
|
1224
|
+
export declare function inputText(input: string): Promise<void>;
|
1225
|
+
|
1167
1226
|
/**
|
1168
1227
|
* Insert a table node with the given number of rows and columns, and optionally
|
1169
1228
|
* a header row.
|
1170
1229
|
*
|
1230
|
+
* @param options
|
1231
|
+
*
|
1171
1232
|
* @public
|
1172
1233
|
*/
|
1173
|
-
|
1234
|
+
declare function insertTable(options: InsertTableOptions): Command;
|
1235
|
+
export { insertTable }
|
1236
|
+
export { insertTable as insertTable_alias_1 }
|
1174
1237
|
|
1175
1238
|
/**
|
1176
1239
|
* @public
|
1177
1240
|
*/
|
1178
|
-
|
1241
|
+
declare interface InsertTableOptions {
|
1179
1242
|
row: number;
|
1180
1243
|
col: number;
|
1181
1244
|
header: boolean;
|
1182
1245
|
}
|
1246
|
+
export { InsertTableOptions }
|
1247
|
+
export { InsertTableOptions as InsertTableOptions_alias_1 }
|
1248
|
+
|
1249
|
+
/**
|
1250
|
+
* Checks if the given object is a `CellSelection` instance.
|
1251
|
+
*
|
1252
|
+
* @public
|
1253
|
+
*/
|
1254
|
+
declare function isCellSelection(value: unknown): value is CellSelection;
|
1255
|
+
export { isCellSelection }
|
1256
|
+
export { isCellSelection as isCellSelection_alias_1 }
|
1183
1257
|
|
1184
1258
|
/**
|
1185
1259
|
* @internal
|
@@ -1309,6 +1383,57 @@ declare type ListSpecExtension = Extension<{
|
|
1309
1383
|
export { ListSpecExtension }
|
1310
1384
|
export { ListSpecExtension as ListSpecExtension_alias_1 }
|
1311
1385
|
|
1386
|
+
/**
|
1387
|
+
* @internal
|
1388
|
+
*/
|
1389
|
+
export declare type LoroCommandsExtension = Extension<{
|
1390
|
+
Commands: {
|
1391
|
+
undo: [];
|
1392
|
+
redo: [];
|
1393
|
+
};
|
1394
|
+
}>;
|
1395
|
+
|
1396
|
+
declare interface LoroCursorOptions {
|
1397
|
+
awareness: CursorAwareness;
|
1398
|
+
getSelection?: (state: EditorState) => Selection_2;
|
1399
|
+
createCursor?: (user: PeerID) => Element;
|
1400
|
+
createSelection?: (user: PeerID) => DecorationAttrs;
|
1401
|
+
}
|
1402
|
+
export { LoroCursorOptions }
|
1403
|
+
export { LoroCursorOptions as LoroCursorOptions_alias_1 }
|
1404
|
+
|
1405
|
+
/**
|
1406
|
+
* @internal
|
1407
|
+
*/
|
1408
|
+
export declare type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>;
|
1409
|
+
|
1410
|
+
export declare interface LoroOptions {
|
1411
|
+
/**
|
1412
|
+
* The Loro instance handles the state of shared data.
|
1413
|
+
*/
|
1414
|
+
doc: LoroDocType;
|
1415
|
+
/**
|
1416
|
+
* The Awareness instance.
|
1417
|
+
*/
|
1418
|
+
awareness: CursorAwareness;
|
1419
|
+
/**
|
1420
|
+
* Extra options for `LoroSyncPlugin`.
|
1421
|
+
*/
|
1422
|
+
sync?: Omit<LoroSyncPluginProps, 'doc'>;
|
1423
|
+
/**
|
1424
|
+
* Extra options for the `LoroUndoPlugin`.
|
1425
|
+
*/
|
1426
|
+
undo?: Omit<LoroUndoPluginProps, 'doc'>;
|
1427
|
+
/**
|
1428
|
+
* Extra options for `LoroCursorPlugin`.
|
1429
|
+
*/
|
1430
|
+
cursor?: Omit<LoroCursorOptions, 'awareness'>;
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
export { LoroSyncPluginProps }
|
1434
|
+
|
1435
|
+
export { LoroUndoPluginProps }
|
1436
|
+
|
1312
1437
|
/**
|
1313
1438
|
* Options for {@link defineMarkInputRule}.
|
1314
1439
|
*
|
@@ -1468,6 +1593,96 @@ export declare interface SearchQueryOptions {
|
|
1468
1593
|
wholeWord?: boolean;
|
1469
1594
|
}
|
1470
1595
|
|
1596
|
+
/**
|
1597
|
+
* @public
|
1598
|
+
*/
|
1599
|
+
declare function selectTable(options?: SelectTableOptions): Command;
|
1600
|
+
export { selectTable }
|
1601
|
+
export { selectTable as selectTable_alias_1 }
|
1602
|
+
|
1603
|
+
/**
|
1604
|
+
* @public
|
1605
|
+
*/
|
1606
|
+
declare function selectTableCell(options?: SelectTableCellOptions): Command;
|
1607
|
+
export { selectTableCell }
|
1608
|
+
export { selectTableCell as selectTableCell_alias_1 }
|
1609
|
+
|
1610
|
+
/**
|
1611
|
+
* @public
|
1612
|
+
*/
|
1613
|
+
declare interface SelectTableCellOptions {
|
1614
|
+
/**
|
1615
|
+
* A hit position of the table cell to select from. By default, the selection
|
1616
|
+
* anchor will be used.
|
1617
|
+
*/
|
1618
|
+
pos?: number;
|
1619
|
+
}
|
1620
|
+
export { SelectTableCellOptions }
|
1621
|
+
export { SelectTableCellOptions as SelectTableCellOptions_alias_1 }
|
1622
|
+
|
1623
|
+
/**
|
1624
|
+
* @public
|
1625
|
+
*/
|
1626
|
+
declare function selectTableColumn(options?: SelectTableColumnOptions): Command;
|
1627
|
+
export { selectTableColumn }
|
1628
|
+
export { selectTableColumn as selectTableColumn_alias_1 }
|
1629
|
+
|
1630
|
+
/**
|
1631
|
+
* @public
|
1632
|
+
*/
|
1633
|
+
declare interface SelectTableColumnOptions {
|
1634
|
+
/**
|
1635
|
+
* A hit position of the table cell to select from. By default, the selection
|
1636
|
+
* anchor will be used.
|
1637
|
+
*/
|
1638
|
+
anchor?: number;
|
1639
|
+
/**
|
1640
|
+
* A hit position of the table cell to select to. By default, the selection
|
1641
|
+
* head will be used.
|
1642
|
+
*/
|
1643
|
+
head?: number;
|
1644
|
+
}
|
1645
|
+
export { SelectTableColumnOptions }
|
1646
|
+
export { SelectTableColumnOptions as SelectTableColumnOptions_alias_1 }
|
1647
|
+
|
1648
|
+
/**
|
1649
|
+
* @public
|
1650
|
+
*/
|
1651
|
+
declare interface SelectTableOptions {
|
1652
|
+
/**
|
1653
|
+
* A hit position of the table to select from. By default, the selection
|
1654
|
+
* anchor will be used.
|
1655
|
+
*/
|
1656
|
+
pos?: number;
|
1657
|
+
}
|
1658
|
+
export { SelectTableOptions }
|
1659
|
+
export { SelectTableOptions as SelectTableOptions_alias_1 }
|
1660
|
+
|
1661
|
+
/**
|
1662
|
+
* @public
|
1663
|
+
*/
|
1664
|
+
declare function selectTableRow(options?: SelectTableRowOptions): Command;
|
1665
|
+
export { selectTableRow }
|
1666
|
+
export { selectTableRow as selectTableRow_alias_1 }
|
1667
|
+
|
1668
|
+
/**
|
1669
|
+
* @public
|
1670
|
+
*/
|
1671
|
+
declare interface SelectTableRowOptions {
|
1672
|
+
/**
|
1673
|
+
* A hit position of the table cell to select from. By default, the selection
|
1674
|
+
* anchor will be used.
|
1675
|
+
*/
|
1676
|
+
anchor?: number;
|
1677
|
+
/**
|
1678
|
+
* A hit position of the table cell to select to. By default, the selection
|
1679
|
+
* head will be used.
|
1680
|
+
*/
|
1681
|
+
head?: number;
|
1682
|
+
}
|
1683
|
+
export { SelectTableRowOptions }
|
1684
|
+
export { SelectTableRowOptions as SelectTableRowOptions_alias_1 }
|
1685
|
+
|
1471
1686
|
/**
|
1472
1687
|
* @internal
|
1473
1688
|
*/
|
@@ -1619,6 +1834,20 @@ declare type TableCommandsExtension = Extension<{
|
|
1619
1834
|
Commands: {
|
1620
1835
|
insertTable: [InsertTableOptions];
|
1621
1836
|
exitTable: [];
|
1837
|
+
selectTable: [options?: SelectTableOptions];
|
1838
|
+
selectTableCell: [options?: SelectTableCellOptions];
|
1839
|
+
selectTableColumn: [options?: SelectTableColumnOptions];
|
1840
|
+
selectTableRow: [options?: SelectTableRowOptions];
|
1841
|
+
addTableColumnBefore: [];
|
1842
|
+
addTableColumnAfter: [];
|
1843
|
+
addTableRowAbove: [];
|
1844
|
+
addTableRowBelow: [];
|
1845
|
+
deleteTable: [];
|
1846
|
+
deleteTableColumn: [];
|
1847
|
+
deleteTableRow: [];
|
1848
|
+
deleteCellSelection: [];
|
1849
|
+
mergeTableCells: [];
|
1850
|
+
splitTableCell: [];
|
1622
1851
|
};
|
1623
1852
|
}>;
|
1624
1853
|
export { TableCommandsExtension }
|
@@ -1627,13 +1856,15 @@ export { TableCommandsExtension as TableCommandsExtension_alias_1 }
|
|
1627
1856
|
/**
|
1628
1857
|
* @internal
|
1629
1858
|
*/
|
1630
|
-
|
1859
|
+
declare type TableExtension = Union<[
|
1631
1860
|
TableSpecExtension,
|
1632
1861
|
TableRowSpecExtension,
|
1633
1862
|
TableCellSpecExtension,
|
1634
1863
|
TableHeaderCellSpecExtension,
|
1635
1864
|
TableCommandsExtension
|
1636
1865
|
]>;
|
1866
|
+
export { TableExtension }
|
1867
|
+
export { TableExtension as TableExtension_alias_1 }
|
1637
1868
|
|
1638
1869
|
/**
|
1639
1870
|
* @internal
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/* src/loro/style.css */
|
2
|
+
.ProseMirror-loro-cursor:first-child {
|
3
|
+
margin-top: 16px;
|
4
|
+
}
|
5
|
+
.ProseMirror-loro-cursor {
|
6
|
+
position: relative;
|
7
|
+
margin-left: -1px;
|
8
|
+
margin-right: -1px;
|
9
|
+
border-left: 1px solid black;
|
10
|
+
border-right: 1px solid black;
|
11
|
+
border-color: orange;
|
12
|
+
word-break: normal;
|
13
|
+
pointer-events: none;
|
14
|
+
}
|
15
|
+
.ProseMirror-loro-cursor > div {
|
16
|
+
position: absolute;
|
17
|
+
top: -1.05em;
|
18
|
+
left: -1px;
|
19
|
+
font-size: 13px;
|
20
|
+
background-color: rgb(250, 129, 0);
|
21
|
+
font-family: serif;
|
22
|
+
font-style: normal;
|
23
|
+
font-weight: normal;
|
24
|
+
line-height: normal;
|
25
|
+
user-select: none;
|
26
|
+
color: white;
|
27
|
+
padding-left: 2px;
|
28
|
+
padding-right: 2px;
|
29
|
+
white-space: nowrap;
|
30
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export { defineLoro } from './_tsup-dts-rollup';
|
2
|
+
export { LoroOptions } from './_tsup-dts-rollup';
|
3
|
+
export { LoroExtension } from './_tsup-dts-rollup';
|
4
|
+
export { defineLoroCommands_alias_1 as defineLoroCommands } from './_tsup-dts-rollup';
|
5
|
+
export { defineLoroCursorPlugin_alias_1 as defineLoroCursorPlugin } from './_tsup-dts-rollup';
|
6
|
+
export { defineLoroKeymap } from './_tsup-dts-rollup';
|
7
|
+
export { defineLoroSyncPlugin } from './_tsup-dts-rollup';
|
8
|
+
export { defineLoroUndoPlugin } from './_tsup-dts-rollup';
|
9
|
+
export { LoroCursorOptions_alias_1 as LoroCursorOptions } from './_tsup-dts-rollup';
|
10
|
+
export { LoroSyncPluginProps } from './_tsup-dts-rollup';
|
11
|
+
export { LoroUndoPluginProps } from './_tsup-dts-rollup';
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// src/loro/index.ts
|
2
|
+
import {
|
3
|
+
Priority,
|
4
|
+
union,
|
5
|
+
withPriority
|
6
|
+
} from "@prosekit/core";
|
7
|
+
|
8
|
+
// src/loro/commands.ts
|
9
|
+
import { defineCommands } from "@prosekit/core";
|
10
|
+
import { redo, undo } from "loro-prosemirror";
|
11
|
+
var commands = {
|
12
|
+
undo: () => undo,
|
13
|
+
redo: () => redo
|
14
|
+
};
|
15
|
+
function defineLoroCommands() {
|
16
|
+
return defineCommands(commands);
|
17
|
+
}
|
18
|
+
|
19
|
+
// src/loro/cursor-plugin.ts
|
20
|
+
import { definePlugin } from "@prosekit/core";
|
21
|
+
import { LoroCursorPlugin } from "loro-prosemirror";
|
22
|
+
function defineLoroCursorPlugin(options) {
|
23
|
+
const { awareness, ...rest } = options;
|
24
|
+
return definePlugin(LoroCursorPlugin(awareness, rest));
|
25
|
+
}
|
26
|
+
|
27
|
+
// src/loro/keymap.ts
|
28
|
+
import {
|
29
|
+
defineKeymap,
|
30
|
+
isApple
|
31
|
+
} from "@prosekit/core";
|
32
|
+
import { redo as redo2, undo as undo2 } from "loro-prosemirror";
|
33
|
+
var keymap = {
|
34
|
+
"Mod-z": undo2,
|
35
|
+
"Shift-Mod-z": redo2
|
36
|
+
};
|
37
|
+
if (!isApple) {
|
38
|
+
keymap["Mod-y"] = redo2;
|
39
|
+
}
|
40
|
+
function defineLoroKeymap() {
|
41
|
+
return defineKeymap(keymap);
|
42
|
+
}
|
43
|
+
|
44
|
+
// src/loro/sync-plugin.ts
|
45
|
+
import { definePlugin as definePlugin2 } from "@prosekit/core";
|
46
|
+
import { LoroSyncPlugin } from "loro-prosemirror";
|
47
|
+
function defineLoroSyncPlugin(options) {
|
48
|
+
return definePlugin2(LoroSyncPlugin(options));
|
49
|
+
}
|
50
|
+
|
51
|
+
// src/loro/undo-plugin.ts
|
52
|
+
import { definePlugin as definePlugin3 } from "@prosekit/core";
|
53
|
+
import { LoroUndoPlugin } from "loro-prosemirror";
|
54
|
+
function defineLoroUndoPlugin(options) {
|
55
|
+
return definePlugin3(LoroUndoPlugin(options));
|
56
|
+
}
|
57
|
+
|
58
|
+
// src/loro/index.ts
|
59
|
+
function defineLoro(options) {
|
60
|
+
const { doc, awareness, sync, undo: undo3, cursor } = options;
|
61
|
+
return withPriority(
|
62
|
+
union([
|
63
|
+
defineLoroKeymap(),
|
64
|
+
defineLoroCommands(),
|
65
|
+
defineLoroCursorPlugin({ ...cursor, awareness }),
|
66
|
+
defineLoroUndoPlugin({ ...undo3, doc }),
|
67
|
+
defineLoroSyncPlugin({ ...sync, doc })
|
68
|
+
]),
|
69
|
+
Priority.high
|
70
|
+
);
|
71
|
+
}
|
72
|
+
export {
|
73
|
+
defineLoro,
|
74
|
+
defineLoroCommands,
|
75
|
+
defineLoroCursorPlugin,
|
76
|
+
defineLoroKeymap,
|
77
|
+
defineLoroSyncPlugin,
|
78
|
+
defineLoroUndoPlugin
|
79
|
+
};
|
@@ -1,13 +1,25 @@
|
|
1
1
|
export { defineTable } from './_tsup-dts-rollup';
|
2
2
|
export { TableExtension } from './_tsup-dts-rollup';
|
3
|
-
export { defineTableCellSpec } from './_tsup-dts-rollup';
|
4
3
|
export { defineTableCommands } from './_tsup-dts-rollup';
|
5
|
-
export {
|
4
|
+
export { exitTable } from './_tsup-dts-rollup';
|
5
|
+
export { insertTable } from './_tsup-dts-rollup';
|
6
|
+
export { selectTable } from './_tsup-dts-rollup';
|
7
|
+
export { selectTableCell } from './_tsup-dts-rollup';
|
8
|
+
export { selectTableColumn } from './_tsup-dts-rollup';
|
9
|
+
export { selectTableRow } from './_tsup-dts-rollup';
|
10
|
+
export { InsertTableOptions } from './_tsup-dts-rollup';
|
11
|
+
export { SelectTableCellOptions } from './_tsup-dts-rollup';
|
12
|
+
export { SelectTableColumnOptions } from './_tsup-dts-rollup';
|
13
|
+
export { SelectTableOptions } from './_tsup-dts-rollup';
|
14
|
+
export { SelectTableRowOptions } from './_tsup-dts-rollup';
|
15
|
+
export { TableCommandsExtension } from './_tsup-dts-rollup';
|
6
16
|
export { defineTablePlugins } from './_tsup-dts-rollup';
|
17
|
+
export { defineTableCellSpec } from './_tsup-dts-rollup';
|
18
|
+
export { defineTableHeaderCellSpec } from './_tsup-dts-rollup';
|
7
19
|
export { defineTableRowSpec } from './_tsup-dts-rollup';
|
8
20
|
export { defineTableSpec } from './_tsup-dts-rollup';
|
9
21
|
export { TableCellSpecExtension } from './_tsup-dts-rollup';
|
10
|
-
export { TableCommandsExtension } from './_tsup-dts-rollup';
|
11
22
|
export { TableHeaderCellSpecExtension } from './_tsup-dts-rollup';
|
12
23
|
export { TableRowSpecExtension } from './_tsup-dts-rollup';
|
13
24
|
export { TableSpecExtension } from './_tsup-dts-rollup';
|
25
|
+
export { isCellSelection } from './_tsup-dts-rollup';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// src/table/
|
1
|
+
// src/table/table.ts
|
2
2
|
import { union } from "@prosekit/core";
|
3
3
|
|
4
4
|
// src/table/table-commands.ts
|
@@ -9,31 +9,83 @@ import {
|
|
9
9
|
insertNode
|
10
10
|
} from "@prosekit/core";
|
11
11
|
import { TextSelection } from "@prosekit/pm/state";
|
12
|
+
import {
|
13
|
+
addColumnAfter,
|
14
|
+
addColumnBefore,
|
15
|
+
addRowAfter,
|
16
|
+
addRowBefore,
|
17
|
+
CellSelection as CellSelection2,
|
18
|
+
deleteCellSelection,
|
19
|
+
deleteColumn,
|
20
|
+
deleteRow,
|
21
|
+
deleteTable,
|
22
|
+
mergeCells,
|
23
|
+
splitCell,
|
24
|
+
TableMap
|
25
|
+
} from "prosemirror-tables";
|
26
|
+
|
27
|
+
// src/table/table-utils.ts
|
28
|
+
import { findParentNode } from "@prosekit/core";
|
29
|
+
import {
|
30
|
+
cellAround,
|
31
|
+
cellNear,
|
32
|
+
CellSelection,
|
33
|
+
inSameTable
|
34
|
+
} from "prosemirror-tables";
|
35
|
+
function isCellSelection(value) {
|
36
|
+
return value instanceof CellSelection;
|
37
|
+
}
|
38
|
+
function findTable($pos) {
|
39
|
+
return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
|
40
|
+
}
|
41
|
+
function findCellRange(selection, anchorHit, headHit) {
|
42
|
+
var _a, _b;
|
43
|
+
if (anchorHit == null && headHit == null && isCellSelection(selection)) {
|
44
|
+
return [selection.$anchorCell, selection.$headCell];
|
45
|
+
}
|
46
|
+
const anchor = (_a = anchorHit != null ? anchorHit : headHit) != null ? _a : selection.anchor;
|
47
|
+
const head = (_b = headHit != null ? headHit : anchorHit) != null ? _b : selection.head;
|
48
|
+
const doc = selection.$head.doc;
|
49
|
+
const $anchorCell = findCellPos(doc, anchor);
|
50
|
+
const $headCell = findCellPos(doc, head);
|
51
|
+
if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) {
|
52
|
+
return [$anchorCell, $headCell];
|
53
|
+
}
|
54
|
+
}
|
55
|
+
function findCellPos(doc, pos) {
|
56
|
+
const $pos = doc.resolve(pos);
|
57
|
+
return cellAround($pos) || cellNear($pos);
|
58
|
+
}
|
59
|
+
|
60
|
+
// src/table/table-commands.ts
|
12
61
|
function createEmptyTable(schema, row, col, header) {
|
13
|
-
const
|
14
|
-
const
|
15
|
-
const
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
);
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
);
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
return table.createAndFill(null, rows);
|
62
|
+
const tableType = getNodeType(schema, "table");
|
63
|
+
const tableRowType = getNodeType(schema, "tableRow");
|
64
|
+
const tableCellType = getNodeType(schema, "tableCell");
|
65
|
+
const tableHeaderCellType = getNodeType(schema, "tableHeaderCell");
|
66
|
+
if (header) {
|
67
|
+
const headerCell = tableHeaderCellType.createAndFill();
|
68
|
+
const headerCells = repeat(headerCell, col);
|
69
|
+
const headerRow = tableRowType.createAndFill(null, headerCells);
|
70
|
+
const bodyCell = tableCellType.createAndFill();
|
71
|
+
const bodyCells = repeat(bodyCell, col);
|
72
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
73
|
+
const bodyRows = repeat(bodyRow, row - 1);
|
74
|
+
return tableType.createAndFill(null, [headerRow, ...bodyRows]);
|
75
|
+
} else {
|
76
|
+
const bodyCell = tableCellType.createAndFill();
|
77
|
+
const bodyCells = repeat(bodyCell, col);
|
78
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
79
|
+
const bodyRows = repeat(bodyRow, row);
|
80
|
+
return tableType.createAndFill(null, bodyRows);
|
81
|
+
}
|
34
82
|
}
|
35
|
-
function
|
83
|
+
function repeat(node, length) {
|
84
|
+
return Array(length).fill(node);
|
85
|
+
}
|
86
|
+
function insertTable(options) {
|
36
87
|
return (state, dispatch, view) => {
|
88
|
+
const { row, col, header } = options;
|
37
89
|
const table = createEmptyTable(state.schema, row, col, header);
|
38
90
|
return insertNode({ node: table })(state, dispatch, view);
|
39
91
|
};
|
@@ -70,10 +122,95 @@ var exitTable = (state, dispatch) => {
|
|
70
122
|
}
|
71
123
|
return true;
|
72
124
|
};
|
125
|
+
function selectTableColumn(options) {
|
126
|
+
return (state, dispatch) => {
|
127
|
+
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
|
128
|
+
if (!range) {
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
if (dispatch) {
|
132
|
+
const [$anchorCell, $headCell] = range;
|
133
|
+
const selection = CellSelection2.colSelection($anchorCell, $headCell);
|
134
|
+
dispatch(state.tr.setSelection(selection));
|
135
|
+
}
|
136
|
+
return true;
|
137
|
+
};
|
138
|
+
}
|
139
|
+
function selectTableRow(options) {
|
140
|
+
return (state, dispatch) => {
|
141
|
+
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
|
142
|
+
if (!range) {
|
143
|
+
return false;
|
144
|
+
}
|
145
|
+
if (dispatch) {
|
146
|
+
const [$anchorCell, $headCell] = range;
|
147
|
+
const selection = CellSelection2.rowSelection($anchorCell, $headCell);
|
148
|
+
dispatch(state.tr.setSelection(selection));
|
149
|
+
}
|
150
|
+
return true;
|
151
|
+
};
|
152
|
+
}
|
153
|
+
function selectTableCell(options) {
|
154
|
+
return (state, dispatch) => {
|
155
|
+
var _a;
|
156
|
+
const $cellPos = findCellPos(
|
157
|
+
state.doc,
|
158
|
+
(_a = options == null ? void 0 : options.pos) != null ? _a : state.selection.anchor
|
159
|
+
);
|
160
|
+
if (!$cellPos) {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
if (dispatch) {
|
164
|
+
const selection = new CellSelection2($cellPos);
|
165
|
+
dispatch(state.tr.setSelection(selection));
|
166
|
+
}
|
167
|
+
return true;
|
168
|
+
};
|
169
|
+
}
|
170
|
+
function selectTable(options) {
|
171
|
+
return (state, dispatch) => {
|
172
|
+
const $pos = (options == null ? void 0 : options.pos) ? state.doc.resolve(options.pos) : state.selection.$anchor;
|
173
|
+
const table = findTable($pos);
|
174
|
+
if (!table) {
|
175
|
+
return false;
|
176
|
+
}
|
177
|
+
const map = TableMap.get(table.node);
|
178
|
+
if (map.map.length === 0) {
|
179
|
+
return false;
|
180
|
+
}
|
181
|
+
if (dispatch) {
|
182
|
+
let tr = state.tr;
|
183
|
+
const firstCellPosInTable = map.map[0];
|
184
|
+
const lastCellPosInTable = map.map[map.map.length - 1];
|
185
|
+
const firstCellPos = table.pos + firstCellPosInTable + 1;
|
186
|
+
const lastCellPos = table.pos + lastCellPosInTable + 1;
|
187
|
+
const $firstCellPos = tr.doc.resolve(firstCellPos);
|
188
|
+
const $lastCellPos = tr.doc.resolve(lastCellPos);
|
189
|
+
const selection = new CellSelection2($firstCellPos, $lastCellPos);
|
190
|
+
tr = tr.setSelection(selection);
|
191
|
+
dispatch == null ? void 0 : dispatch(tr);
|
192
|
+
}
|
193
|
+
return true;
|
194
|
+
};
|
195
|
+
}
|
73
196
|
function defineTableCommands() {
|
74
197
|
return defineCommands({
|
75
198
|
insertTable,
|
76
|
-
exitTable: () => exitTable
|
199
|
+
exitTable: () => exitTable,
|
200
|
+
selectTable,
|
201
|
+
selectTableCell,
|
202
|
+
selectTableColumn,
|
203
|
+
selectTableRow,
|
204
|
+
addTableColumnBefore: () => addColumnBefore,
|
205
|
+
addTableColumnAfter: () => addColumnAfter,
|
206
|
+
addTableRowAbove: () => addRowBefore,
|
207
|
+
addTableRowBelow: () => addRowAfter,
|
208
|
+
deleteTable: () => deleteTable,
|
209
|
+
deleteTableColumn: () => deleteColumn,
|
210
|
+
deleteTableRow: () => deleteRow,
|
211
|
+
deleteCellSelection: () => deleteCellSelection,
|
212
|
+
mergeTableCells: () => mergeCells,
|
213
|
+
splitTableCell: () => splitCell
|
77
214
|
});
|
78
215
|
}
|
79
216
|
|
@@ -170,7 +307,7 @@ function defineTableHeaderCellSpec() {
|
|
170
307
|
});
|
171
308
|
}
|
172
309
|
|
173
|
-
// src/table/
|
310
|
+
// src/table/table.ts
|
174
311
|
function defineTable() {
|
175
312
|
return union(
|
176
313
|
defineTableSpec(),
|
@@ -188,5 +325,12 @@ export {
|
|
188
325
|
defineTableHeaderCellSpec,
|
189
326
|
defineTablePlugins,
|
190
327
|
defineTableRowSpec,
|
191
|
-
defineTableSpec
|
328
|
+
defineTableSpec,
|
329
|
+
exitTable,
|
330
|
+
insertTable,
|
331
|
+
isCellSelection,
|
332
|
+
selectTable,
|
333
|
+
selectTableCell,
|
334
|
+
selectTableColumn,
|
335
|
+
selectTableRow
|
192
336
|
};
|
package/dist/table/style.css
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.7.
|
4
|
+
"version": "0.7.13",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -114,6 +114,14 @@
|
|
114
114
|
"./list/style.css": {
|
115
115
|
"default": "./dist/list/style.css"
|
116
116
|
},
|
117
|
+
"./loro": {
|
118
|
+
"types": "./dist/prosekit-extensions-loro.d.ts",
|
119
|
+
"import": "./dist/prosekit-extensions-loro.js",
|
120
|
+
"default": "./dist/prosekit-extensions-loro.js"
|
121
|
+
},
|
122
|
+
"./loro/style.css": {
|
123
|
+
"default": "./dist/loro/style.css"
|
124
|
+
},
|
117
125
|
"./mark-rule": {
|
118
126
|
"types": "./dist/prosekit-extensions-mark-rule.d.ts",
|
119
127
|
"import": "./dist/prosekit-extensions-mark-rule.js",
|
@@ -200,16 +208,24 @@
|
|
200
208
|
"prosemirror-gapcursor": "^1.3.2",
|
201
209
|
"prosemirror-highlight": "^0.8.0",
|
202
210
|
"prosemirror-search": "^1.0.0",
|
203
|
-
"prosemirror-tables": "^1.
|
211
|
+
"prosemirror-tables": "^1.5.0",
|
204
212
|
"shiki": "^1.14.1",
|
205
213
|
"@prosekit/core": "^0.7.9",
|
206
214
|
"@prosekit/pm": "^0.1.8"
|
207
215
|
},
|
208
216
|
"peerDependencies": {
|
217
|
+
"loro-crdt": ">= 0.16.7",
|
218
|
+
"loro-prosemirror": ">= 0.0.7",
|
209
219
|
"y-prosemirror": ">= 1.2.9",
|
210
220
|
"yjs": ">= 13.6.18"
|
211
221
|
},
|
212
222
|
"peerDependenciesMeta": {
|
223
|
+
"loro-crdt": {
|
224
|
+
"optional": true
|
225
|
+
},
|
226
|
+
"loro-prosemirror": {
|
227
|
+
"optional": true
|
228
|
+
},
|
213
229
|
"y-prosemirror": {
|
214
230
|
"optional": true
|
215
231
|
},
|
@@ -219,6 +235,8 @@
|
|
219
235
|
},
|
220
236
|
"devDependencies": {
|
221
237
|
"@vitest/browser": "^2.0.5",
|
238
|
+
"loro-crdt": "^0.16.7",
|
239
|
+
"loro-prosemirror": "^0.0.7",
|
222
240
|
"tsup": "^8.2.4",
|
223
241
|
"type-fest": "^4.25.0",
|
224
242
|
"typescript": "^5.5.4",
|
@@ -283,6 +301,9 @@
|
|
283
301
|
"list": [
|
284
302
|
"./dist/prosekit-extensions-list.d.ts"
|
285
303
|
],
|
304
|
+
"loro": [
|
305
|
+
"./dist/prosekit-extensions-loro.d.ts"
|
306
|
+
],
|
286
307
|
"mark-rule": [
|
287
308
|
"./dist/prosekit-extensions-mark-rule.d.ts"
|
288
309
|
],
|