dn-react-text-editor 0.1.2 → 0.2.1
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/README.md +19 -0
- package/dist/attach_file.d.mts +20 -22
- package/dist/attach_file.d.ts +20 -22
- package/dist/attach_file.js +5 -5
- package/dist/attach_file.mjs +5 -4
- package/dist/base64_file_uploader.d.mts +6 -0
- package/dist/base64_file_uploader.d.ts +6 -0
- package/dist/{plugins/trailing_paragraph.js → base64_file_uploader.js} +19 -22
- package/dist/base64_file_uploader.mjs +18 -0
- package/dist/commands.d.mts +23 -0
- package/dist/commands.d.ts +23 -0
- package/dist/commands.js +110 -0
- package/dist/commands.mjs +75 -0
- package/dist/create_text_editor.d.mts +28 -0
- package/dist/create_text_editor.d.ts +28 -0
- package/dist/create_text_editor.js +1093 -0
- package/dist/create_text_editor.mjs +1064 -0
- package/dist/html.d.mts +8 -0
- package/dist/html.d.ts +8 -0
- package/dist/html.js +136 -0
- package/dist/html.mjs +98 -0
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +782 -365
- package/dist/index.mjs +777 -360
- package/dist/input.d.mts +21 -0
- package/dist/input.d.ts +21 -0
- package/dist/input.js +70 -0
- package/dist/input.mjs +37 -0
- package/dist/plugins/drag_and_drop.d.mts +1 -1
- package/dist/plugins/drag_and_drop.d.ts +1 -1
- package/dist/plugins/drag_and_drop.js +3 -0
- package/dist/plugins/drag_and_drop.mjs +3 -0
- package/dist/plugins/highlighter.d.mts +6 -0
- package/dist/plugins/highlighter.d.ts +6 -0
- package/dist/plugins/highlighter.js +105 -0
- package/dist/plugins/highlighter.mjs +69 -0
- package/dist/plugins/keymap.js +17 -0
- package/dist/plugins/keymap.mjs +17 -0
- package/dist/schema.d.mts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +255 -14
- package/dist/schema.mjs +245 -14
- package/dist/text_editor_controller.d.mts +46 -0
- package/dist/text_editor_controller.d.ts +46 -0
- package/dist/text_editor_controller.js +503 -0
- package/dist/text_editor_controller.mjs +470 -0
- package/package.json +3 -1
- package/dist/plugins/trailing_paragraph.d.mts +0 -5
- package/dist/plugins/trailing_paragraph.d.ts +0 -5
- package/dist/plugins/trailing_paragraph.mjs +0 -21
- package/dist/text_editor.d.mts +0 -37
- package/dist/text_editor.d.ts +0 -37
- package/dist/text_editor.js +0 -722
- package/dist/text_editor.mjs +0 -692
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
# React Text Editor
|
|
2
2
|
|
|
3
3
|
A rich text editor component for React built on ProseMirror.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { TextEditor } from "dn-react-text-editor";
|
|
9
|
+
|
|
10
|
+
const TextEditor = useTextEditor();
|
|
11
|
+
|
|
12
|
+
function App() {
|
|
13
|
+
return (
|
|
14
|
+
<TextEditor
|
|
15
|
+
placeholder="Write something..."
|
|
16
|
+
onChange={(e) => {
|
|
17
|
+
console.log(e.target.value);
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
package/dist/attach_file.d.mts
CHANGED
|
@@ -3,30 +3,28 @@ import { createSchema } from './schema.mjs';
|
|
|
3
3
|
import 'orderedmap';
|
|
4
4
|
import 'prosemirror-model';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type GenerateMetadata = (file: File) => Promise<{
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
poster?: string;
|
|
10
|
+
}> | {
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
poster?: string;
|
|
14
|
+
};
|
|
15
|
+
type UploadFile = (file: File) => Promise<{
|
|
16
|
+
src: string;
|
|
17
|
+
alt?: string;
|
|
18
|
+
}> | {
|
|
19
|
+
src: string;
|
|
20
|
+
alt?: string;
|
|
21
|
+
};
|
|
7
22
|
type AttachFileOptions = {
|
|
8
23
|
schema: ReturnType<typeof createSchema>;
|
|
9
|
-
generateMetadata?:
|
|
10
|
-
|
|
11
|
-
height?: number;
|
|
12
|
-
poster?: string;
|
|
13
|
-
}> | {
|
|
14
|
-
width?: number;
|
|
15
|
-
height?: number;
|
|
16
|
-
poster?: string;
|
|
17
|
-
};
|
|
18
|
-
uploadFile?: (file: File) => Promise<{
|
|
19
|
-
src: string;
|
|
20
|
-
alt?: string;
|
|
21
|
-
}> | {
|
|
22
|
-
src: string;
|
|
23
|
-
alt?: string;
|
|
24
|
-
};
|
|
24
|
+
generateMetadata?: GenerateMetadata;
|
|
25
|
+
uploadFile?: UploadFile;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
-
src: string;
|
|
28
|
-
alt: string;
|
|
29
|
-
}>;
|
|
27
|
+
type AttachFile = (view: EditorView, files: File[]) => Promise<void>;
|
|
30
28
|
declare function createAttachFile({ schema, generateMetadata, uploadFile, }: AttachFileOptions): AttachFile;
|
|
31
29
|
|
|
32
|
-
export { type AttachFile,
|
|
30
|
+
export { type AttachFile, type AttachFileOptions, type GenerateMetadata, type UploadFile, createAttachFile };
|
package/dist/attach_file.d.ts
CHANGED
|
@@ -3,30 +3,28 @@ import { createSchema } from './schema.js';
|
|
|
3
3
|
import 'orderedmap';
|
|
4
4
|
import 'prosemirror-model';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type GenerateMetadata = (file: File) => Promise<{
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
poster?: string;
|
|
10
|
+
}> | {
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
poster?: string;
|
|
14
|
+
};
|
|
15
|
+
type UploadFile = (file: File) => Promise<{
|
|
16
|
+
src: string;
|
|
17
|
+
alt?: string;
|
|
18
|
+
}> | {
|
|
19
|
+
src: string;
|
|
20
|
+
alt?: string;
|
|
21
|
+
};
|
|
7
22
|
type AttachFileOptions = {
|
|
8
23
|
schema: ReturnType<typeof createSchema>;
|
|
9
|
-
generateMetadata?:
|
|
10
|
-
|
|
11
|
-
height?: number;
|
|
12
|
-
poster?: string;
|
|
13
|
-
}> | {
|
|
14
|
-
width?: number;
|
|
15
|
-
height?: number;
|
|
16
|
-
poster?: string;
|
|
17
|
-
};
|
|
18
|
-
uploadFile?: (file: File) => Promise<{
|
|
19
|
-
src: string;
|
|
20
|
-
alt?: string;
|
|
21
|
-
}> | {
|
|
22
|
-
src: string;
|
|
23
|
-
alt?: string;
|
|
24
|
-
};
|
|
24
|
+
generateMetadata?: GenerateMetadata;
|
|
25
|
+
uploadFile?: UploadFile;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
-
src: string;
|
|
28
|
-
alt: string;
|
|
29
|
-
}>;
|
|
27
|
+
type AttachFile = (view: EditorView, files: File[]) => Promise<void>;
|
|
30
28
|
declare function createAttachFile({ schema, generateMetadata, uploadFile, }: AttachFileOptions): AttachFile;
|
|
31
29
|
|
|
32
|
-
export { type AttachFile,
|
|
30
|
+
export { type AttachFile, type AttachFileOptions, type GenerateMetadata, type UploadFile, createAttachFile };
|
package/dist/attach_file.js
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/attach_file.tsx
|
|
21
21
|
var attach_file_exports = {};
|
|
22
22
|
__export(attach_file_exports, {
|
|
23
|
-
base64ImageUploader: () => base64ImageUploader,
|
|
24
23
|
createAttachFile: () => createAttachFile
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(attach_file_exports);
|
|
@@ -91,8 +90,8 @@ var findPlaceholder = (state, id) => {
|
|
|
91
90
|
return found.length ? found[0].from : null;
|
|
92
91
|
};
|
|
93
92
|
|
|
94
|
-
// src/
|
|
95
|
-
var
|
|
93
|
+
// src/base64_file_uploader.ts
|
|
94
|
+
var base64FileUploader = async (file) => {
|
|
96
95
|
const base64 = await new Promise((resolve, reject) => {
|
|
97
96
|
const reader = new FileReader();
|
|
98
97
|
reader.onload = () => {
|
|
@@ -106,10 +105,12 @@ var base64ImageUploader = async (file) => {
|
|
|
106
105
|
alt: file.name
|
|
107
106
|
};
|
|
108
107
|
};
|
|
108
|
+
|
|
109
|
+
// src/attach_file.tsx
|
|
109
110
|
function createAttachFile({
|
|
110
111
|
schema,
|
|
111
112
|
generateMetadata,
|
|
112
|
-
uploadFile =
|
|
113
|
+
uploadFile = base64FileUploader
|
|
113
114
|
}) {
|
|
114
115
|
const attachEachFile = async (view, file, pos) => {
|
|
115
116
|
const metadata = generateMetadata ? await generateMetadata(file) : {};
|
|
@@ -173,6 +174,5 @@ function createAttachFile({
|
|
|
173
174
|
}
|
|
174
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
175
176
|
0 && (module.exports = {
|
|
176
|
-
base64ImageUploader,
|
|
177
177
|
createAttachFile
|
|
178
178
|
});
|
package/dist/attach_file.mjs
CHANGED
|
@@ -66,8 +66,8 @@ var findPlaceholder = (state, id) => {
|
|
|
66
66
|
return found.length ? found[0].from : null;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
// src/
|
|
70
|
-
var
|
|
69
|
+
// src/base64_file_uploader.ts
|
|
70
|
+
var base64FileUploader = async (file) => {
|
|
71
71
|
const base64 = await new Promise((resolve, reject) => {
|
|
72
72
|
const reader = new FileReader();
|
|
73
73
|
reader.onload = () => {
|
|
@@ -81,10 +81,12 @@ var base64ImageUploader = async (file) => {
|
|
|
81
81
|
alt: file.name
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
|
+
|
|
85
|
+
// src/attach_file.tsx
|
|
84
86
|
function createAttachFile({
|
|
85
87
|
schema,
|
|
86
88
|
generateMetadata,
|
|
87
|
-
uploadFile =
|
|
89
|
+
uploadFile = base64FileUploader
|
|
88
90
|
}) {
|
|
89
91
|
const attachEachFile = async (view, file, pos) => {
|
|
90
92
|
const metadata = generateMetadata ? await generateMetadata(file) : {};
|
|
@@ -147,6 +149,5 @@ function createAttachFile({
|
|
|
147
149
|
};
|
|
148
150
|
}
|
|
149
151
|
export {
|
|
150
|
-
base64ImageUploader,
|
|
151
152
|
createAttachFile
|
|
152
153
|
};
|
|
@@ -17,30 +17,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/base64_file_uploader.ts
|
|
21
|
+
var base64_file_uploader_exports = {};
|
|
22
|
+
__export(base64_file_uploader_exports, {
|
|
23
|
+
base64FileUploader: () => base64FileUploader
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const tr = newState.tr;
|
|
35
|
-
const endPos = doc.content.size;
|
|
36
|
-
tr.insert(endPos, paragraphType.create());
|
|
37
|
-
return tr;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
25
|
+
module.exports = __toCommonJS(base64_file_uploader_exports);
|
|
26
|
+
var base64FileUploader = async (file) => {
|
|
27
|
+
const base64 = await new Promise((resolve, reject) => {
|
|
28
|
+
const reader = new FileReader();
|
|
29
|
+
reader.onload = () => {
|
|
30
|
+
resolve(reader.result);
|
|
31
|
+
};
|
|
32
|
+
reader.onerror = reject;
|
|
33
|
+
reader.readAsDataURL(file);
|
|
41
34
|
});
|
|
42
|
-
|
|
35
|
+
return {
|
|
36
|
+
src: base64,
|
|
37
|
+
alt: file.name
|
|
38
|
+
};
|
|
39
|
+
};
|
|
43
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
41
|
0 && (module.exports = {
|
|
45
|
-
|
|
42
|
+
base64FileUploader
|
|
46
43
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/base64_file_uploader.ts
|
|
2
|
+
var base64FileUploader = async (file) => {
|
|
3
|
+
const base64 = await new Promise((resolve, reject) => {
|
|
4
|
+
const reader = new FileReader();
|
|
5
|
+
reader.onload = () => {
|
|
6
|
+
resolve(reader.result);
|
|
7
|
+
};
|
|
8
|
+
reader.onerror = reject;
|
|
9
|
+
reader.readAsDataURL(file);
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
src: base64,
|
|
13
|
+
alt: file.name
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
base64FileUploader
|
|
18
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema, NodeType, Attrs } from 'prosemirror-model';
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
import { AttachFile } from './attach_file.mjs';
|
|
4
|
+
import './schema.mjs';
|
|
5
|
+
import 'orderedmap';
|
|
6
|
+
|
|
7
|
+
declare const createCommands: (schema: Schema, view: EditorView, options?: {
|
|
8
|
+
attachFile?: AttachFile;
|
|
9
|
+
}) => {
|
|
10
|
+
isBlockTypeActive: (node: NodeType, attrs?: Attrs | null, excludes?: NodeType[]) => false | undefined;
|
|
11
|
+
setBlockType: (node: string, attrs?: Attrs | null) => void;
|
|
12
|
+
toggleBlockType: (node: string, attrs?: Attrs | null) => void;
|
|
13
|
+
toggleMark: (mark: string, attrs?: Attrs | null, options?: {
|
|
14
|
+
removeWhenPresent?: boolean;
|
|
15
|
+
enterInlineAtoms?: boolean;
|
|
16
|
+
includeWhitespace?: boolean;
|
|
17
|
+
}) => void;
|
|
18
|
+
wrapInList: (listType: string, attrs?: Attrs | null) => void;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
attachFile: (files: File[]) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { createCommands };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema, NodeType, Attrs } from 'prosemirror-model';
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
import { AttachFile } from './attach_file.js';
|
|
4
|
+
import './schema.js';
|
|
5
|
+
import 'orderedmap';
|
|
6
|
+
|
|
7
|
+
declare const createCommands: (schema: Schema, view: EditorView, options?: {
|
|
8
|
+
attachFile?: AttachFile;
|
|
9
|
+
}) => {
|
|
10
|
+
isBlockTypeActive: (node: NodeType, attrs?: Attrs | null, excludes?: NodeType[]) => false | undefined;
|
|
11
|
+
setBlockType: (node: string, attrs?: Attrs | null) => void;
|
|
12
|
+
toggleBlockType: (node: string, attrs?: Attrs | null) => void;
|
|
13
|
+
toggleMark: (mark: string, attrs?: Attrs | null, options?: {
|
|
14
|
+
removeWhenPresent?: boolean;
|
|
15
|
+
enterInlineAtoms?: boolean;
|
|
16
|
+
includeWhitespace?: boolean;
|
|
17
|
+
}) => void;
|
|
18
|
+
wrapInList: (listType: string, attrs?: Attrs | null) => void;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
attachFile: (files: File[]) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { createCommands };
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/commands.tsx
|
|
31
|
+
var commands_exports = {};
|
|
32
|
+
__export(commands_exports, {
|
|
33
|
+
createCommands: () => createCommands
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(commands_exports);
|
|
36
|
+
var commands = __toESM(require("prosemirror-commands"));
|
|
37
|
+
var schemaList = __toESM(require("prosemirror-schema-list"));
|
|
38
|
+
var createCommands = (schema, view, options = {}) => {
|
|
39
|
+
{
|
|
40
|
+
const isBlockTypeActive = (node, attrs, excludes = []) => {
|
|
41
|
+
const state = view.state;
|
|
42
|
+
const ranges = state.selection.ranges;
|
|
43
|
+
let active = false;
|
|
44
|
+
for (const range of ranges) {
|
|
45
|
+
const { $from, $to } = range;
|
|
46
|
+
state.doc.nodesBetween($from.pos, $to.pos, (n) => {
|
|
47
|
+
if (active) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (n.type !== node || excludes.includes(n.type)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!attrs || Object.keys(attrs).every((key) => n.attrs[key] === attrs[key])) {
|
|
54
|
+
active = true;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return active;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const setBlockType2 = (node, attrs) => {
|
|
61
|
+
view.focus();
|
|
62
|
+
const nodeType = schema.nodes[node];
|
|
63
|
+
const command = commands.setBlockType(nodeType, attrs);
|
|
64
|
+
command(view.state, view.dispatch);
|
|
65
|
+
};
|
|
66
|
+
const toggleBlockType = (node, attrs) => {
|
|
67
|
+
view.focus();
|
|
68
|
+
const nodeType = schema.nodes[node];
|
|
69
|
+
const command = commands.setBlockType(nodeType, attrs);
|
|
70
|
+
if (isBlockTypeActive(nodeType, attrs)) {
|
|
71
|
+
command(view.state, view.dispatch);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const toggleMark2 = (mark, attrs, options2) => {
|
|
75
|
+
view.focus();
|
|
76
|
+
const markType = schema.marks[mark];
|
|
77
|
+
const command = commands.toggleMark(markType, attrs, options2);
|
|
78
|
+
command(view.state, view.dispatch);
|
|
79
|
+
};
|
|
80
|
+
const wrapInList2 = (listType, attrs) => {
|
|
81
|
+
view.focus();
|
|
82
|
+
const nodeType = schema.nodes[listType];
|
|
83
|
+
const command = schemaList.wrapInList(nodeType, attrs);
|
|
84
|
+
command(view.state, view.dispatch);
|
|
85
|
+
};
|
|
86
|
+
const clear = () => {
|
|
87
|
+
const tr = view.state.tr.replaceWith(
|
|
88
|
+
0,
|
|
89
|
+
view.state.doc.content.size,
|
|
90
|
+
schema.nodes.doc.createAndFill()
|
|
91
|
+
);
|
|
92
|
+
view.dispatch(tr);
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
isBlockTypeActive,
|
|
96
|
+
setBlockType: setBlockType2,
|
|
97
|
+
toggleBlockType,
|
|
98
|
+
toggleMark: toggleMark2,
|
|
99
|
+
wrapInList: wrapInList2,
|
|
100
|
+
clear,
|
|
101
|
+
attachFile: (files) => {
|
|
102
|
+
options.attachFile?.(view, files);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
createCommands
|
|
110
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/commands.tsx
|
|
2
|
+
import * as commands from "prosemirror-commands";
|
|
3
|
+
import * as schemaList from "prosemirror-schema-list";
|
|
4
|
+
var createCommands = (schema, view, options = {}) => {
|
|
5
|
+
{
|
|
6
|
+
const isBlockTypeActive = (node, attrs, excludes = []) => {
|
|
7
|
+
const state = view.state;
|
|
8
|
+
const ranges = state.selection.ranges;
|
|
9
|
+
let active = false;
|
|
10
|
+
for (const range of ranges) {
|
|
11
|
+
const { $from, $to } = range;
|
|
12
|
+
state.doc.nodesBetween($from.pos, $to.pos, (n) => {
|
|
13
|
+
if (active) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (n.type !== node || excludes.includes(n.type)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!attrs || Object.keys(attrs).every((key) => n.attrs[key] === attrs[key])) {
|
|
20
|
+
active = true;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return active;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const setBlockType2 = (node, attrs) => {
|
|
27
|
+
view.focus();
|
|
28
|
+
const nodeType = schema.nodes[node];
|
|
29
|
+
const command = commands.setBlockType(nodeType, attrs);
|
|
30
|
+
command(view.state, view.dispatch);
|
|
31
|
+
};
|
|
32
|
+
const toggleBlockType = (node, attrs) => {
|
|
33
|
+
view.focus();
|
|
34
|
+
const nodeType = schema.nodes[node];
|
|
35
|
+
const command = commands.setBlockType(nodeType, attrs);
|
|
36
|
+
if (isBlockTypeActive(nodeType, attrs)) {
|
|
37
|
+
command(view.state, view.dispatch);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const toggleMark2 = (mark, attrs, options2) => {
|
|
41
|
+
view.focus();
|
|
42
|
+
const markType = schema.marks[mark];
|
|
43
|
+
const command = commands.toggleMark(markType, attrs, options2);
|
|
44
|
+
command(view.state, view.dispatch);
|
|
45
|
+
};
|
|
46
|
+
const wrapInList2 = (listType, attrs) => {
|
|
47
|
+
view.focus();
|
|
48
|
+
const nodeType = schema.nodes[listType];
|
|
49
|
+
const command = schemaList.wrapInList(nodeType, attrs);
|
|
50
|
+
command(view.state, view.dispatch);
|
|
51
|
+
};
|
|
52
|
+
const clear = () => {
|
|
53
|
+
const tr = view.state.tr.replaceWith(
|
|
54
|
+
0,
|
|
55
|
+
view.state.doc.content.size,
|
|
56
|
+
schema.nodes.doc.createAndFill()
|
|
57
|
+
);
|
|
58
|
+
view.dispatch(tr);
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
isBlockTypeActive,
|
|
62
|
+
setBlockType: setBlockType2,
|
|
63
|
+
toggleBlockType,
|
|
64
|
+
toggleMark: toggleMark2,
|
|
65
|
+
wrapInList: wrapInList2,
|
|
66
|
+
clear,
|
|
67
|
+
attachFile: (files) => {
|
|
68
|
+
options.attachFile?.(view, files);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
createCommands
|
|
75
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DetailedHTMLProps, InputHTMLAttributes, Ref, FC } from 'react';
|
|
2
|
+
import { Transaction } from 'prosemirror-state';
|
|
3
|
+
import { EditorView } from 'prosemirror-view';
|
|
4
|
+
import { createSchema } from './schema.mjs';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
|
+
import { createCommands } from './commands.mjs';
|
|
7
|
+
import { TextEditorControllerProps, CreateTextEditorOptions } from './text_editor_controller.mjs';
|
|
8
|
+
import 'orderedmap';
|
|
9
|
+
import 'prosemirror-model';
|
|
10
|
+
import './attach_file.mjs';
|
|
11
|
+
|
|
12
|
+
type TextEditorController = {
|
|
13
|
+
schema: ReturnType<typeof createSchema>;
|
|
14
|
+
view: EditorView;
|
|
15
|
+
subject: Subject<Transaction>;
|
|
16
|
+
set value(value: string);
|
|
17
|
+
get value(): string;
|
|
18
|
+
} & {
|
|
19
|
+
commands: ReturnType<typeof createCommands>;
|
|
20
|
+
};
|
|
21
|
+
type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
22
|
+
type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
|
|
23
|
+
ref?: Ref<TextEditorController>;
|
|
24
|
+
name?: string;
|
|
25
|
+
} & TextEditorControllerProps;
|
|
26
|
+
declare function createTextEditor(options?: CreateTextEditorOptions): FC<TextEditorProps>;
|
|
27
|
+
|
|
28
|
+
export { type TextEditorController, type TextEditorProps, createTextEditor };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DetailedHTMLProps, InputHTMLAttributes, Ref, FC } from 'react';
|
|
2
|
+
import { Transaction } from 'prosemirror-state';
|
|
3
|
+
import { EditorView } from 'prosemirror-view';
|
|
4
|
+
import { createSchema } from './schema.js';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
|
+
import { createCommands } from './commands.js';
|
|
7
|
+
import { TextEditorControllerProps, CreateTextEditorOptions } from './text_editor_controller.js';
|
|
8
|
+
import 'orderedmap';
|
|
9
|
+
import 'prosemirror-model';
|
|
10
|
+
import './attach_file.js';
|
|
11
|
+
|
|
12
|
+
type TextEditorController = {
|
|
13
|
+
schema: ReturnType<typeof createSchema>;
|
|
14
|
+
view: EditorView;
|
|
15
|
+
subject: Subject<Transaction>;
|
|
16
|
+
set value(value: string);
|
|
17
|
+
get value(): string;
|
|
18
|
+
} & {
|
|
19
|
+
commands: ReturnType<typeof createCommands>;
|
|
20
|
+
};
|
|
21
|
+
type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
22
|
+
type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
|
|
23
|
+
ref?: Ref<TextEditorController>;
|
|
24
|
+
name?: string;
|
|
25
|
+
} & TextEditorControllerProps;
|
|
26
|
+
declare function createTextEditor(options?: CreateTextEditorOptions): FC<TextEditorProps>;
|
|
27
|
+
|
|
28
|
+
export { type TextEditorController, type TextEditorProps, createTextEditor };
|