dn-react-text-editor 0.1.1 → 0.2.0
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 +14 -214
- package/dist/attach_file.d.mts +20 -18
- package/dist/attach_file.d.ts +20 -18
- package/dist/attach_file.js +18 -9
- package/dist/attach_file.mjs +18 -9
- 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 +1082 -0
- package/dist/create_text_editor.mjs +1053 -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 +790 -380
- package/dist/index.mjs +789 -377
- 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 -720
- package/dist/text_editor.mjs +0 -687
|
@@ -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 React, { DetailedHTMLProps, InputHTMLAttributes, Ref } 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): ({ ref, className, autoFocus, placeholder, defaultValue, onChange, updateDelay, ...props }?: TextEditorProps) => React.JSX.Element;
|
|
27
|
+
|
|
28
|
+
export { type TextEditorController, type TextEditorProps, createTextEditor };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { DetailedHTMLProps, InputHTMLAttributes, Ref } 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): ({ ref, className, autoFocus, placeholder, defaultValue, onChange, updateDelay, ...props }?: TextEditorProps) => React.JSX.Element;
|
|
27
|
+
|
|
28
|
+
export { type TextEditorController, type TextEditorProps, createTextEditor };
|