@prosekit/core 0.2.4 → 0.2.5
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 +16 -1
- package/dist/prosekit-core.d.ts +1 -0
- package/dist/prosekit-core.js +21 -14
- package/package.json +2 -2
- package/src/index.ts +1 -0
@@ -165,7 +165,7 @@ declare type ConverterTuple = Tuple5<FacetConverter | undefined>;
|
|
165
165
|
/**
|
166
166
|
* @public
|
167
167
|
*/
|
168
|
-
declare function createEditor<E extends Extension>(
|
168
|
+
declare function createEditor<E extends Extension>(options: EditorOptions<E>): Editor<E>;
|
169
169
|
export { createEditor }
|
170
170
|
export { createEditor as createEditor_alias_1 }
|
171
171
|
|
@@ -517,6 +517,7 @@ declare class Editor<E extends Extension = any> {
|
|
517
517
|
*/
|
518
518
|
blur(): void;
|
519
519
|
use(extension: Extension): VoidFunction;
|
520
|
+
get state(): EditorState;
|
520
521
|
get nodes(): Record<ExtractNodes<E>, NodeBuilder>;
|
521
522
|
get marks(): Record<ExtractMarks<E>, MarkBuilder>;
|
522
523
|
}
|
@@ -781,6 +782,15 @@ export { isAllSelection as isAllSelection_alias_1 }
|
|
781
782
|
|
782
783
|
export declare function isElement(value: unknown): value is Element;
|
783
784
|
|
785
|
+
/**
|
786
|
+
* Check if the selection is in a code block.
|
787
|
+
*
|
788
|
+
* @internal
|
789
|
+
*/
|
790
|
+
declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
|
791
|
+
export { isInCodeBlock }
|
792
|
+
export { isInCodeBlock as isInCodeBlock_alias_1 }
|
793
|
+
|
784
794
|
export declare const isMac: boolean;
|
785
795
|
|
786
796
|
/**
|
@@ -1237,6 +1247,11 @@ export { toggleNode as toggleNode_alias_1 }
|
|
1237
1247
|
|
1238
1248
|
declare type Tuple5<T> = [T, T, T, T, T];
|
1239
1249
|
|
1250
|
+
/**
|
1251
|
+
* Merge multiple extensions into one.
|
1252
|
+
*
|
1253
|
+
* @public
|
1254
|
+
*/
|
1240
1255
|
declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
1241
1256
|
export { union }
|
1242
1257
|
export { union as union_alias_1 }
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -70,6 +70,7 @@ export { defaultBlockAt } from './_tsup-dts-rollup';
|
|
70
70
|
export { _getId } from './_tsup-dts-rollup';
|
71
71
|
export { getMarkType } from './_tsup-dts-rollup';
|
72
72
|
export { getNodeType } from './_tsup-dts-rollup';
|
73
|
+
export { isInCodeBlock } from './_tsup-dts-rollup';
|
73
74
|
export { jsonFromElement } from './_tsup-dts-rollup';
|
74
75
|
export { jsonFromHTML } from './_tsup-dts-rollup';
|
75
76
|
export { jsonFromNode } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -825,12 +825,9 @@ function union(extension) {
|
|
825
825
|
}
|
826
826
|
|
827
827
|
// src/editor/editor.ts
|
828
|
-
function createEditor({
|
829
|
-
|
830
|
-
|
831
|
-
defaultHTML,
|
832
|
-
defaultSelection
|
833
|
-
}) {
|
828
|
+
function createEditor(options) {
|
829
|
+
const { defaultDoc, defaultHTML, defaultSelection } = options;
|
830
|
+
let extension = options.extension;
|
834
831
|
if (defaultDoc || defaultHTML) {
|
835
832
|
extension = union([
|
836
833
|
extension,
|
@@ -858,6 +855,7 @@ var EditorInstance = class {
|
|
858
855
|
const schema = new Schema6(schemaInput);
|
859
856
|
const stateConfig = stateInput ? stateInput({ schema }) : { schema };
|
860
857
|
const state = EditorState2.create(stateConfig);
|
858
|
+
this.cachedState = state;
|
861
859
|
if (commandInput) {
|
862
860
|
for (const [name, commandCreator] of Object.entries(commandInput)) {
|
863
861
|
this.defineCommand(name, commandCreator);
|
@@ -865,10 +863,7 @@ var EditorInstance = class {
|
|
865
863
|
}
|
866
864
|
this.directEditorProps = { state, ...viewInput };
|
867
865
|
this.schema = this.directEditorProps.state.schema;
|
868
|
-
const getState = () =>
|
869
|
-
var _a;
|
870
|
-
return (_a = this.view) == null ? void 0 : _a.state;
|
871
|
-
};
|
866
|
+
const getState = () => this.getState();
|
872
867
|
this.nodeBuilders = Object.fromEntries(
|
873
868
|
Object.values(this.schema.nodes).map((type) => [
|
874
869
|
type.name,
|
@@ -882,6 +877,12 @@ var EditorInstance = class {
|
|
882
877
|
])
|
883
878
|
);
|
884
879
|
}
|
880
|
+
getState() {
|
881
|
+
if (this.view) {
|
882
|
+
this.cachedState = this.view.state;
|
883
|
+
}
|
884
|
+
return this.cachedState;
|
885
|
+
}
|
885
886
|
updateExtension(extension, mode) {
|
886
887
|
var _a;
|
887
888
|
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, mode);
|
@@ -1054,6 +1055,9 @@ var Editor = class _Editor {
|
|
1054
1055
|
this.instance.updateExtension(extension, "add");
|
1055
1056
|
return () => this.instance.updateExtension(extension, "remove");
|
1056
1057
|
}
|
1058
|
+
get state() {
|
1059
|
+
return this.instance.getState();
|
1060
|
+
}
|
1057
1061
|
get nodes() {
|
1058
1062
|
return this.instance.nodeBuilders;
|
1059
1063
|
}
|
@@ -1674,16 +1678,18 @@ function getId() {
|
|
1674
1678
|
return `id:${id}`;
|
1675
1679
|
}
|
1676
1680
|
|
1677
|
-
// src/utils/
|
1678
|
-
var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1679
|
-
|
1680
|
-
// src/utils/with-skip-code-block.ts
|
1681
|
+
// src/utils/is-in-code-block.ts
|
1681
1682
|
function isCodeBlockType(type) {
|
1682
1683
|
return type.spec.code && type.isBlock;
|
1683
1684
|
}
|
1684
1685
|
function isInCodeBlock(selection) {
|
1685
1686
|
return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
|
1686
1687
|
}
|
1688
|
+
|
1689
|
+
// src/utils/unicode.ts
|
1690
|
+
var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1691
|
+
|
1692
|
+
// src/utils/with-skip-code-block.ts
|
1687
1693
|
function withSkipCodeBlock(command) {
|
1688
1694
|
return (state, dispatch, view) => {
|
1689
1695
|
if (isInCodeBlock(state.selection)) {
|
@@ -1729,6 +1735,7 @@ export {
|
|
1729
1735
|
getNodeType,
|
1730
1736
|
insertNode,
|
1731
1737
|
isAllSelection,
|
1738
|
+
isInCodeBlock,
|
1732
1739
|
isMark,
|
1733
1740
|
isNodeSelection,
|
1734
1741
|
isProseMirrorNode,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.2.
|
4
|
+
"version": "0.2.5",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -44,7 +44,7 @@
|
|
44
44
|
"@prosekit/dev": "*",
|
45
45
|
"tsup": "^8.0.1",
|
46
46
|
"typescript": "^5.3.3",
|
47
|
-
"vitest": "^1.
|
47
|
+
"vitest": "^1.2.0"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"build:tsup": "tsup",
|
package/src/index.ts
CHANGED
@@ -83,6 +83,7 @@ export { defaultBlockAt } from './utils/default-block-at'
|
|
83
83
|
export { getId as _getId } from './utils/get-id'
|
84
84
|
export { getMarkType } from './utils/get-mark-type'
|
85
85
|
export { getNodeType } from './utils/get-node-type'
|
86
|
+
export { isInCodeBlock } from './utils/is-in-code-block'
|
86
87
|
export {
|
87
88
|
jsonFromElement,
|
88
89
|
jsonFromHTML,
|