@prosekit/core 0.2.3 → 0.2.4
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 +63 -0
- package/dist/prosekit-core.d.ts +5 -0
- package/dist/prosekit-core.js +92 -7
- package/package.json +1 -1
- package/src/index.ts +7 -0
@@ -3,6 +3,7 @@ import { Attrs } from '@prosekit/pm/model';
|
|
3
3
|
import { Attrs as Attrs_2 } from 'prosemirror-model';
|
4
4
|
import { Command } from '@prosekit/pm/state';
|
5
5
|
import type { ConditionalExcept } from 'type-fest';
|
6
|
+
import type { ContentMatch } from '@prosekit/pm/model';
|
6
7
|
import type { DirectEditorProps } from '@prosekit/pm/view';
|
7
8
|
import { EditorState } from '@prosekit/pm/state';
|
8
9
|
import type { EditorStateConfig } from '@prosekit/pm/state';
|
@@ -180,6 +181,13 @@ export declare const default_alias_1: {
|
|
180
181
|
};
|
181
182
|
};
|
182
183
|
|
184
|
+
/**
|
185
|
+
* @internal
|
186
|
+
*/
|
187
|
+
declare function defaultBlockAt(match: ContentMatch): NodeType_2 | null;
|
188
|
+
export { defaultBlockAt }
|
189
|
+
export { defaultBlockAt as defaultBlockAt_alias_1 }
|
190
|
+
|
183
191
|
declare interface DefaultStateOptions {
|
184
192
|
/**
|
185
193
|
* A JSON object representing the starting document to use when creating the
|
@@ -297,6 +305,15 @@ declare function defineDocChangeHandler(handler: DocChangeHandler): Extension<Ex
|
|
297
305
|
export { defineDocChangeHandler }
|
298
306
|
export { defineDocChangeHandler as defineDocChangeHandler_alias_1 }
|
299
307
|
|
308
|
+
/**
|
309
|
+
* Registers a event handler that is called when the editor gains or loses focus.
|
310
|
+
*
|
311
|
+
* @public
|
312
|
+
*/
|
313
|
+
declare function defineFocusChangeHandler(handler: FocusChangeHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
314
|
+
export { defineFocusChangeHandler }
|
315
|
+
export { defineFocusChangeHandler as defineFocusChangeHandler_alias_1 }
|
316
|
+
|
300
317
|
/**
|
301
318
|
* Add undo/redo history to the editor.
|
302
319
|
*/
|
@@ -472,12 +489,33 @@ declare class Editor<E extends Extension = any> {
|
|
472
489
|
* @internal
|
473
490
|
*/
|
474
491
|
static create(instance: any): Editor<any>;
|
492
|
+
/**
|
493
|
+
* Whether the editor is mounted.
|
494
|
+
*/
|
475
495
|
get mounted(): boolean;
|
496
|
+
/**
|
497
|
+
* The editor view.
|
498
|
+
*/
|
476
499
|
get view(): EditorView;
|
500
|
+
/**
|
501
|
+
* The editor schema.
|
502
|
+
*/
|
477
503
|
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
|
478
504
|
get commands(): ExtractCommandAppliers<E>;
|
505
|
+
/**
|
506
|
+
* Whether the editor is focused.
|
507
|
+
*/
|
508
|
+
get focused(): boolean;
|
479
509
|
mount(place: HTMLElement | null | undefined | void): void;
|
480
510
|
unmount(): void;
|
511
|
+
/**
|
512
|
+
* Focus the editor.
|
513
|
+
*/
|
514
|
+
focus(): void;
|
515
|
+
/**
|
516
|
+
* Blur the editor.
|
517
|
+
*/
|
518
|
+
blur(): void;
|
481
519
|
use(extension: Extension): VoidFunction;
|
482
520
|
get nodes(): Record<ExtractNodes<E>, NodeBuilder>;
|
483
521
|
get marks(): Record<ExtractMarks<E>, MarkBuilder>;
|
@@ -667,6 +705,17 @@ declare interface FacetOptions<Input, Output> {
|
|
667
705
|
export { FacetOptions }
|
668
706
|
export { FacetOptions as FacetOptions_alias_1 }
|
669
707
|
|
708
|
+
/**
|
709
|
+
* A function that is called when the editor gains or loses focus.
|
710
|
+
*
|
711
|
+
* @param hasFocus - Whether the editor has focus.
|
712
|
+
*
|
713
|
+
* @public
|
714
|
+
*/
|
715
|
+
declare type FocusChangeHandler = (hasFocus: boolean) => void;
|
716
|
+
export { FocusChangeHandler }
|
717
|
+
export { FocusChangeHandler as FocusChangeHandler_alias_1 }
|
718
|
+
|
670
719
|
export declare function getBrowserDocument(): Document | undefined;
|
671
720
|
|
672
721
|
export declare function getBrowserWindow(): (Window & typeof globalThis) | null | undefined;
|
@@ -997,6 +1046,13 @@ declare interface NodeViewOptions {
|
|
997
1046
|
export { NodeViewOptions }
|
998
1047
|
export { NodeViewOptions as NodeViewOptions_alias_1 }
|
999
1048
|
|
1049
|
+
/**
|
1050
|
+
* @internal
|
1051
|
+
*/
|
1052
|
+
declare const OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1053
|
+
export { OBJECT_REPLACEMENT_CHARACTER }
|
1054
|
+
export { OBJECT_REPLACEMENT_CHARACTER as OBJECT_REPLACEMENT_CHARACTER_alias_1 }
|
1055
|
+
|
1000
1056
|
export declare function objectEqual<T>(a: T, b: T): boolean;
|
1001
1057
|
|
1002
1058
|
declare type Payload = unknown;
|
@@ -1239,6 +1295,13 @@ declare function withPriority<T extends Extension>(extension: T, priority: Prior
|
|
1239
1295
|
export { withPriority }
|
1240
1296
|
export { withPriority as withPriority_alias_1 }
|
1241
1297
|
|
1298
|
+
/**
|
1299
|
+
* @internal
|
1300
|
+
*/
|
1301
|
+
declare function withSkipCodeBlock(command: Command): Command;
|
1302
|
+
export { withSkipCodeBlock }
|
1303
|
+
export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
|
1304
|
+
|
1242
1305
|
export declare function wrap({ nodeType, attrs, }: {
|
1243
1306
|
nodeType: NodeType;
|
1244
1307
|
attrs?: Attrs | null;
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -17,6 +17,8 @@ export { DefaultStateOptions } from './_tsup-dts-rollup';
|
|
17
17
|
export { defineDoc } from './_tsup-dts-rollup';
|
18
18
|
export { defineDocChangeHandler } from './_tsup-dts-rollup';
|
19
19
|
export { DocChangeHandler } from './_tsup-dts-rollup';
|
20
|
+
export { defineFocusChangeHandler } from './_tsup-dts-rollup';
|
21
|
+
export { FocusChangeHandler } from './_tsup-dts-rollup';
|
20
22
|
export { defineMountHandler } from './_tsup-dts-rollup';
|
21
23
|
export { defineUnmountHandler } from './_tsup-dts-rollup';
|
22
24
|
export { defineUpdateHandler } from './_tsup-dts-rollup';
|
@@ -64,6 +66,7 @@ export { StateJSON } from './_tsup-dts-rollup';
|
|
64
66
|
export { Priority } from './_tsup-dts-rollup';
|
65
67
|
export { SimplifyUnion } from './_tsup-dts-rollup';
|
66
68
|
export { clsx } from './_tsup-dts-rollup';
|
69
|
+
export { defaultBlockAt } from './_tsup-dts-rollup';
|
67
70
|
export { _getId } from './_tsup-dts-rollup';
|
68
71
|
export { getMarkType } from './_tsup-dts-rollup';
|
69
72
|
export { getNodeType } from './_tsup-dts-rollup';
|
@@ -80,3 +83,5 @@ export { isMark } from './_tsup-dts-rollup';
|
|
80
83
|
export { isNodeSelection } from './_tsup-dts-rollup';
|
81
84
|
export { isProseMirrorNode } from './_tsup-dts-rollup';
|
82
85
|
export { isTextSelection } from './_tsup-dts-rollup';
|
86
|
+
export { withSkipCodeBlock } from './_tsup-dts-rollup';
|
87
|
+
export { OBJECT_REPLACEMENT_CHARACTER } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -986,18 +986,34 @@ var Editor = class _Editor {
|
|
986
986
|
}
|
987
987
|
return new _Editor(instance);
|
988
988
|
}
|
989
|
+
/**
|
990
|
+
* Whether the editor is mounted.
|
991
|
+
*/
|
989
992
|
get mounted() {
|
990
993
|
return !!this.instance.view;
|
991
994
|
}
|
995
|
+
/**
|
996
|
+
* The editor view.
|
997
|
+
*/
|
992
998
|
get view() {
|
993
999
|
return this.instance.assertView;
|
994
1000
|
}
|
1001
|
+
/**
|
1002
|
+
* The editor schema.
|
1003
|
+
*/
|
995
1004
|
get schema() {
|
996
1005
|
return this.instance.schema;
|
997
1006
|
}
|
998
1007
|
get commands() {
|
999
1008
|
return this.instance.commandAppliers;
|
1000
1009
|
}
|
1010
|
+
/**
|
1011
|
+
* Whether the editor is focused.
|
1012
|
+
*/
|
1013
|
+
get focused() {
|
1014
|
+
var _a, _b;
|
1015
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
1016
|
+
}
|
1001
1017
|
mount(place) {
|
1002
1018
|
if (!place) {
|
1003
1019
|
return this.unmount();
|
@@ -1010,6 +1026,20 @@ var Editor = class _Editor {
|
|
1010
1026
|
this.instance.unmount();
|
1011
1027
|
}
|
1012
1028
|
}
|
1029
|
+
/**
|
1030
|
+
* Focus the editor.
|
1031
|
+
*/
|
1032
|
+
focus() {
|
1033
|
+
var _a;
|
1034
|
+
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
1035
|
+
}
|
1036
|
+
/**
|
1037
|
+
* Blur the editor.
|
1038
|
+
*/
|
1039
|
+
blur() {
|
1040
|
+
var _a;
|
1041
|
+
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
1042
|
+
}
|
1013
1043
|
use(extension) {
|
1014
1044
|
if (!this.mounted) {
|
1015
1045
|
let lazyRemove = null;
|
@@ -1326,6 +1356,28 @@ function defineDocChangeHandler(handler) {
|
|
1326
1356
|
});
|
1327
1357
|
}
|
1328
1358
|
|
1359
|
+
// src/extensions/events/focus.ts
|
1360
|
+
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1361
|
+
function defineFocusChangeHandler(handler) {
|
1362
|
+
const handleFocus = () => handler(true);
|
1363
|
+
const handleBlur = () => handler(false);
|
1364
|
+
const plugin = new ProseMirrorPlugin2({
|
1365
|
+
key: new PluginKey2("prosekit-focus-handler"),
|
1366
|
+
view: (view) => {
|
1367
|
+
const dom = view.dom;
|
1368
|
+
dom.addEventListener("focus", handleFocus);
|
1369
|
+
dom.addEventListener("blur", handleBlur);
|
1370
|
+
return {
|
1371
|
+
destroy: () => {
|
1372
|
+
dom.removeEventListener("focus", handleFocus);
|
1373
|
+
dom.removeEventListener("blur", handleBlur);
|
1374
|
+
}
|
1375
|
+
};
|
1376
|
+
}
|
1377
|
+
});
|
1378
|
+
return definePlugin(plugin);
|
1379
|
+
}
|
1380
|
+
|
1329
1381
|
// src/extensions/history.ts
|
1330
1382
|
import { history, redo, undo } from "@prosekit/pm/history";
|
1331
1383
|
|
@@ -1335,7 +1387,7 @@ var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigat
|
|
1335
1387
|
// src/extensions/keymap.ts
|
1336
1388
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1337
1389
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1338
|
-
import { Plugin as Plugin3, PluginKey as
|
1390
|
+
import { Plugin as Plugin3, PluginKey as PluginKey3 } from "@prosekit/pm/state";
|
1339
1391
|
function defineKeymap(keymap) {
|
1340
1392
|
return keymapFacet.extension([keymap]);
|
1341
1393
|
}
|
@@ -1386,7 +1438,7 @@ function mergeKeymaps(keymaps) {
|
|
1386
1438
|
])
|
1387
1439
|
);
|
1388
1440
|
}
|
1389
|
-
var keymapPluginKey = new
|
1441
|
+
var keymapPluginKey = new PluginKey3("prosekit-keymap");
|
1390
1442
|
|
1391
1443
|
// src/extensions/history.ts
|
1392
1444
|
function defineHistory() {
|
@@ -1525,7 +1577,7 @@ var markSpecFacet = Facet.define({
|
|
1525
1577
|
});
|
1526
1578
|
|
1527
1579
|
// src/extensions/node-view.ts
|
1528
|
-
import { ProseMirrorPlugin as
|
1580
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1529
1581
|
import "@prosekit/pm/view";
|
1530
1582
|
function defineNodeView(options) {
|
1531
1583
|
return nodeViewFacet.extension([options]);
|
@@ -1538,13 +1590,13 @@ var nodeViewFacet = Facet.define({
|
|
1538
1590
|
nodeViews[input.name] = input.constructor;
|
1539
1591
|
}
|
1540
1592
|
}
|
1541
|
-
return () => [new
|
1593
|
+
return () => [new ProseMirrorPlugin3({ props: { nodeViews } })];
|
1542
1594
|
},
|
1543
1595
|
next: pluginFacet
|
1544
1596
|
});
|
1545
1597
|
|
1546
1598
|
// src/extensions/node-view-effect.ts
|
1547
|
-
import { ProseMirrorPlugin as
|
1599
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin4 } from "@prosekit/pm/state";
|
1548
1600
|
import "@prosekit/pm/view";
|
1549
1601
|
function defineNodeViewFactory(options) {
|
1550
1602
|
return nodeViewFactoryFacet.extension([options]);
|
@@ -1572,7 +1624,7 @@ var nodeViewFactoryFacet = Facet.define({
|
|
1572
1624
|
nodeViews[name] = factory(args);
|
1573
1625
|
}
|
1574
1626
|
}
|
1575
|
-
return () => [new
|
1627
|
+
return () => [new ProseMirrorPlugin4({ props: { nodeViews } })];
|
1576
1628
|
},
|
1577
1629
|
next: pluginFacet
|
1578
1630
|
});
|
@@ -1605,27 +1657,59 @@ function defineText() {
|
|
1605
1657
|
import clsxLite from "clsx/lite";
|
1606
1658
|
var clsx = clsxLite;
|
1607
1659
|
|
1660
|
+
// src/utils/default-block-at.ts
|
1661
|
+
function defaultBlockAt(match) {
|
1662
|
+
for (let i = 0; i < match.edgeCount; i++) {
|
1663
|
+
const { type } = match.edge(i);
|
1664
|
+
if (type.isTextblock && !type.hasRequiredAttrs())
|
1665
|
+
return type;
|
1666
|
+
}
|
1667
|
+
return null;
|
1668
|
+
}
|
1669
|
+
|
1608
1670
|
// src/utils/get-id.ts
|
1609
1671
|
var id = 0;
|
1610
1672
|
function getId() {
|
1611
1673
|
id = (id + 1) % Number.MAX_SAFE_INTEGER;
|
1612
1674
|
return `id:${id}`;
|
1613
1675
|
}
|
1676
|
+
|
1677
|
+
// src/utils/unicode.ts
|
1678
|
+
var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1679
|
+
|
1680
|
+
// src/utils/with-skip-code-block.ts
|
1681
|
+
function isCodeBlockType(type) {
|
1682
|
+
return type.spec.code && type.isBlock;
|
1683
|
+
}
|
1684
|
+
function isInCodeBlock(selection) {
|
1685
|
+
return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
|
1686
|
+
}
|
1687
|
+
function withSkipCodeBlock(command) {
|
1688
|
+
return (state, dispatch, view) => {
|
1689
|
+
if (isInCodeBlock(state.selection)) {
|
1690
|
+
return false;
|
1691
|
+
}
|
1692
|
+
return command(state, dispatch, view);
|
1693
|
+
};
|
1694
|
+
}
|
1614
1695
|
export {
|
1615
1696
|
Editor,
|
1616
1697
|
Facet,
|
1698
|
+
OBJECT_REPLACEMENT_CHARACTER,
|
1617
1699
|
Priority,
|
1618
1700
|
ProseKitError,
|
1619
1701
|
getId as _getId,
|
1620
1702
|
addMark,
|
1621
1703
|
clsx,
|
1622
1704
|
createEditor,
|
1705
|
+
defaultBlockAt,
|
1623
1706
|
defineBaseCommands,
|
1624
1707
|
defineBaseKeymap,
|
1625
1708
|
defineCommands,
|
1626
1709
|
defineDefaultState,
|
1627
1710
|
defineDoc,
|
1628
1711
|
defineDocChangeHandler,
|
1712
|
+
defineFocusChangeHandler,
|
1629
1713
|
defineHistory,
|
1630
1714
|
defineInputRule,
|
1631
1715
|
defineKeymap,
|
@@ -1664,5 +1748,6 @@ export {
|
|
1664
1748
|
toggleMark,
|
1665
1749
|
toggleNode,
|
1666
1750
|
union,
|
1667
|
-
withPriority
|
1751
|
+
withPriority,
|
1752
|
+
withSkipCodeBlock
|
1668
1753
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -18,6 +18,10 @@ export {
|
|
18
18
|
defineDocChangeHandler,
|
19
19
|
type DocChangeHandler,
|
20
20
|
} from './extensions/events/doc-change'
|
21
|
+
export {
|
22
|
+
defineFocusChangeHandler,
|
23
|
+
type FocusChangeHandler,
|
24
|
+
} from './extensions/events/focus'
|
21
25
|
export {
|
22
26
|
defineMountHandler,
|
23
27
|
defineUnmountHandler,
|
@@ -75,6 +79,7 @@ export type { NodeJSON, SelectionJSON, StateJSON } from './types/model'
|
|
75
79
|
export { Priority } from './types/priority'
|
76
80
|
export { type SimplifyUnion } from './types/simplify-union'
|
77
81
|
export { clsx } from './utils/clsx'
|
82
|
+
export { defaultBlockAt } from './utils/default-block-at'
|
78
83
|
export { getId as _getId } from './utils/get-id'
|
79
84
|
export { getMarkType } from './utils/get-mark-type'
|
80
85
|
export { getNodeType } from './utils/get-node-type'
|
@@ -95,3 +100,5 @@ export {
|
|
95
100
|
isProseMirrorNode,
|
96
101
|
isTextSelection,
|
97
102
|
} from './utils/type-assertion'
|
103
|
+
export * from './utils/unicode'
|
104
|
+
export { withSkipCodeBlock } from './utils/with-skip-code-block'
|