dn-react-text-editor 0.1.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/LICENSE +7 -0
- package/README.md +222 -0
- package/dist/attach_file.d.mts +28 -0
- package/dist/attach_file.d.ts +28 -0
- package/dist/attach_file.js +169 -0
- package/dist/attach_file.mjs +144 -0
- package/dist/cn.d.mts +3 -0
- package/dist/cn.d.ts +3 -0
- package/dist/cn.js +32 -0
- package/dist/cn.mjs +7 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +735 -0
- package/dist/index.mjs +698 -0
- package/dist/plugins/drag_and_drop.d.mts +12 -0
- package/dist/plugins/drag_and_drop.d.ts +12 -0
- package/dist/plugins/drag_and_drop.js +57 -0
- package/dist/plugins/drag_and_drop.mjs +32 -0
- package/dist/plugins/keymap.d.mts +6 -0
- package/dist/plugins/keymap.d.ts +6 -0
- package/dist/plugins/keymap.js +59 -0
- package/dist/plugins/keymap.mjs +34 -0
- package/dist/plugins/placehoder.d.mts +5 -0
- package/dist/plugins/placehoder.d.ts +5 -0
- package/dist/plugins/placehoder.js +114 -0
- package/dist/plugins/placehoder.mjs +89 -0
- package/dist/plugins/trailing_paragraph.d.mts +5 -0
- package/dist/plugins/trailing_paragraph.d.ts +5 -0
- package/dist/plugins/trailing_paragraph.js +46 -0
- package/dist/plugins/trailing_paragraph.mjs +21 -0
- package/dist/plugins/upload_placeholder.d.mts +7 -0
- package/dist/plugins/upload_placeholder.d.ts +7 -0
- package/dist/plugins/upload_placeholder.js +94 -0
- package/dist/plugins/upload_placeholder.mjs +68 -0
- package/dist/prosemirror/index.d.mts +7 -0
- package/dist/prosemirror/index.d.ts +7 -0
- package/dist/prosemirror/index.js +36 -0
- package/dist/prosemirror/index.mjs +8 -0
- package/dist/schema.d.mts +7 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.js +286 -0
- package/dist/schema.mjs +261 -0
- package/dist/text_editor.d.mts +36 -0
- package/dist/text_editor.d.ts +36 -0
- package/dist/text_editor.js +729 -0
- package/dist/text_editor.mjs +696 -0
- package/package.json +56 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/drag_and_drop.tsx
|
|
21
|
+
var drag_and_drop_exports = {};
|
|
22
|
+
__export(drag_and_drop_exports, {
|
|
23
|
+
dragAndDropPlugin: () => dragAndDropPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(drag_and_drop_exports);
|
|
26
|
+
var import_prosemirror_state = require("prosemirror-state");
|
|
27
|
+
function dragAndDropPlugin({ attachFile }) {
|
|
28
|
+
return new import_prosemirror_state.Plugin({
|
|
29
|
+
props: {
|
|
30
|
+
handleDOMEvents: {
|
|
31
|
+
drop(view, event) {
|
|
32
|
+
const files = event.dataTransfer?.files;
|
|
33
|
+
if (!files || files.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
const pos = view.state.selection.$from.pos || view.posAtCoords({
|
|
38
|
+
left: event.clientX,
|
|
39
|
+
top: event.clientY
|
|
40
|
+
})?.pos || null;
|
|
41
|
+
if (pos === null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const medias = Array.from(files).filter(
|
|
45
|
+
(file) => file.type.startsWith("image/") || file.type.startsWith("video/")
|
|
46
|
+
);
|
|
47
|
+
attachFile(view, medias);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
dragAndDropPlugin
|
|
57
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/plugins/drag_and_drop.tsx
|
|
2
|
+
import { Plugin } from "prosemirror-state";
|
|
3
|
+
function dragAndDropPlugin({ attachFile }) {
|
|
4
|
+
return new Plugin({
|
|
5
|
+
props: {
|
|
6
|
+
handleDOMEvents: {
|
|
7
|
+
drop(view, event) {
|
|
8
|
+
const files = event.dataTransfer?.files;
|
|
9
|
+
if (!files || files.length === 0) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
const pos = view.state.selection.$from.pos || view.posAtCoords({
|
|
14
|
+
left: event.clientX,
|
|
15
|
+
top: event.clientY
|
|
16
|
+
})?.pos || null;
|
|
17
|
+
if (pos === null) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const medias = Array.from(files).filter(
|
|
21
|
+
(file) => file.type.startsWith("image/") || file.type.startsWith("video/")
|
|
22
|
+
);
|
|
23
|
+
attachFile(view, medias);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
dragAndDropPlugin
|
|
32
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/keymap.tsx
|
|
21
|
+
var keymap_exports = {};
|
|
22
|
+
__export(keymap_exports, {
|
|
23
|
+
buildKeymap: () => buildKeymap
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(keymap_exports);
|
|
26
|
+
var import_prosemirror_history = require("prosemirror-history");
|
|
27
|
+
var import_prosemirror_commands = require("prosemirror-commands");
|
|
28
|
+
var import_prosemirror_schema_list = require("prosemirror-schema-list");
|
|
29
|
+
function buildKeymap(schema) {
|
|
30
|
+
const keys = {};
|
|
31
|
+
function bind(key, cmd) {
|
|
32
|
+
keys[key] = cmd;
|
|
33
|
+
}
|
|
34
|
+
bind("Mod-z", import_prosemirror_history.undo);
|
|
35
|
+
bind("Shift-Mod-z", import_prosemirror_history.redo);
|
|
36
|
+
bind("Mod-y", import_prosemirror_history.redo);
|
|
37
|
+
const li = schema.nodes.list_item;
|
|
38
|
+
bind(
|
|
39
|
+
"Enter",
|
|
40
|
+
(0, import_prosemirror_commands.chainCommands)((0, import_prosemirror_schema_list.splitListItem)(li), (state, dispatch) => {
|
|
41
|
+
const { $head } = state.selection;
|
|
42
|
+
if ($head.parent.type === state.schema.nodes.paragraph) {
|
|
43
|
+
(0, import_prosemirror_commands.splitBlockAs)((n) => {
|
|
44
|
+
return {
|
|
45
|
+
type: n.type,
|
|
46
|
+
attrs: n.attrs
|
|
47
|
+
};
|
|
48
|
+
})(state, dispatch);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
return keys;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
buildKeymap
|
|
59
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/plugins/keymap.tsx
|
|
2
|
+
import { undo, redo } from "prosemirror-history";
|
|
3
|
+
import { chainCommands, splitBlockAs } from "prosemirror-commands";
|
|
4
|
+
import { splitListItem } from "prosemirror-schema-list";
|
|
5
|
+
function buildKeymap(schema) {
|
|
6
|
+
const keys = {};
|
|
7
|
+
function bind(key, cmd) {
|
|
8
|
+
keys[key] = cmd;
|
|
9
|
+
}
|
|
10
|
+
bind("Mod-z", undo);
|
|
11
|
+
bind("Shift-Mod-z", redo);
|
|
12
|
+
bind("Mod-y", redo);
|
|
13
|
+
const li = schema.nodes.list_item;
|
|
14
|
+
bind(
|
|
15
|
+
"Enter",
|
|
16
|
+
chainCommands(splitListItem(li), (state, dispatch) => {
|
|
17
|
+
const { $head } = state.selection;
|
|
18
|
+
if ($head.parent.type === state.schema.nodes.paragraph) {
|
|
19
|
+
splitBlockAs((n) => {
|
|
20
|
+
return {
|
|
21
|
+
type: n.type,
|
|
22
|
+
attrs: n.attrs
|
|
23
|
+
};
|
|
24
|
+
})(state, dispatch);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
return keys;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
buildKeymap
|
|
34
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/placehoder.tsx
|
|
21
|
+
var placehoder_exports = {};
|
|
22
|
+
__export(placehoder_exports, {
|
|
23
|
+
placeholderPlugin: () => placeholderPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(placehoder_exports);
|
|
26
|
+
var import_prosemirror_model = require("prosemirror-model");
|
|
27
|
+
var import_prosemirror_state2 = require("prosemirror-state");
|
|
28
|
+
var import_prosemirror_view2 = require("prosemirror-view");
|
|
29
|
+
|
|
30
|
+
// src/plugins/upload_placeholder.tsx
|
|
31
|
+
var import_prosemirror_state = require("prosemirror-state");
|
|
32
|
+
var import_prosemirror_view = require("prosemirror-view");
|
|
33
|
+
var uploadPlaceholderPlugin = new import_prosemirror_state.Plugin({
|
|
34
|
+
state: {
|
|
35
|
+
init() {
|
|
36
|
+
return import_prosemirror_view.DecorationSet.empty;
|
|
37
|
+
},
|
|
38
|
+
apply(tr, set) {
|
|
39
|
+
set = set.map(tr.mapping, tr.doc);
|
|
40
|
+
const action = tr.getMeta(this);
|
|
41
|
+
if (action && action.add) {
|
|
42
|
+
const { type, width, height } = action.add;
|
|
43
|
+
const widget = document.createElement("div");
|
|
44
|
+
widget.className = "upload-placeholder";
|
|
45
|
+
widget.style.width = `100%`;
|
|
46
|
+
if (type.startsWith("image/") || type.startsWith("video/")) {
|
|
47
|
+
widget.style.aspectRatio = `${width} / ${height}`;
|
|
48
|
+
widget.style.maxWidth = `${width}px`;
|
|
49
|
+
} else {
|
|
50
|
+
widget.style.height = "80px";
|
|
51
|
+
}
|
|
52
|
+
const progress = document.createElement("div");
|
|
53
|
+
progress.className = "upload-progress";
|
|
54
|
+
widget.appendChild(progress);
|
|
55
|
+
const deco = import_prosemirror_view.Decoration.widget(action.add.pos, widget, {
|
|
56
|
+
id: action.add.id
|
|
57
|
+
});
|
|
58
|
+
set = set.add(tr.doc, [deco]);
|
|
59
|
+
} else if (action && action.progress) {
|
|
60
|
+
const found = set.find(
|
|
61
|
+
void 0,
|
|
62
|
+
void 0,
|
|
63
|
+
(spec) => spec.id === action.progress.id
|
|
64
|
+
);
|
|
65
|
+
if (found.length) {
|
|
66
|
+
const widget = found[0].type.toDOM;
|
|
67
|
+
const progress = widget.querySelector(".upload-progress");
|
|
68
|
+
if (progress) {
|
|
69
|
+
progress.innerHTML = `${Math.round(action.progress.progress)}%`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (action && action.remove) {
|
|
73
|
+
set = set.remove(
|
|
74
|
+
set.find(void 0, void 0, (spec) => spec.id === action.remove.id)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return set;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
props: {
|
|
81
|
+
decorations(state) {
|
|
82
|
+
return this.getState(state);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// src/plugins/placehoder.tsx
|
|
88
|
+
var getFirstChildDescendants = (view) => {
|
|
89
|
+
const nodes = [];
|
|
90
|
+
view.state.doc?.descendants((n) => {
|
|
91
|
+
nodes.push(n);
|
|
92
|
+
});
|
|
93
|
+
return nodes;
|
|
94
|
+
};
|
|
95
|
+
function placeholderPlugin(text) {
|
|
96
|
+
const update = (view) => {
|
|
97
|
+
const decos = uploadPlaceholderPlugin.getState(view.state);
|
|
98
|
+
if (decos && decos.find().length > 0 || view.state.doc.content.content.some((e) => e.type.name !== "paragraph") || view.state.doc.childCount > 1 || getFirstChildDescendants(view).length > 1 || view.state.doc.textContent) {
|
|
99
|
+
view.dom.removeAttribute("data-placeholder");
|
|
100
|
+
} else {
|
|
101
|
+
view.dom.setAttribute("data-placeholder", text);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return new import_prosemirror_state2.Plugin({
|
|
105
|
+
view(view) {
|
|
106
|
+
update(view);
|
|
107
|
+
return { update };
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
placeholderPlugin
|
|
114
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/plugins/placehoder.tsx
|
|
2
|
+
import "prosemirror-model";
|
|
3
|
+
import { Plugin as Plugin2 } from "prosemirror-state";
|
|
4
|
+
import "prosemirror-view";
|
|
5
|
+
|
|
6
|
+
// src/plugins/upload_placeholder.tsx
|
|
7
|
+
import { Plugin } from "prosemirror-state";
|
|
8
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
9
|
+
var uploadPlaceholderPlugin = new Plugin({
|
|
10
|
+
state: {
|
|
11
|
+
init() {
|
|
12
|
+
return DecorationSet.empty;
|
|
13
|
+
},
|
|
14
|
+
apply(tr, set) {
|
|
15
|
+
set = set.map(tr.mapping, tr.doc);
|
|
16
|
+
const action = tr.getMeta(this);
|
|
17
|
+
if (action && action.add) {
|
|
18
|
+
const { type, width, height } = action.add;
|
|
19
|
+
const widget = document.createElement("div");
|
|
20
|
+
widget.className = "upload-placeholder";
|
|
21
|
+
widget.style.width = `100%`;
|
|
22
|
+
if (type.startsWith("image/") || type.startsWith("video/")) {
|
|
23
|
+
widget.style.aspectRatio = `${width} / ${height}`;
|
|
24
|
+
widget.style.maxWidth = `${width}px`;
|
|
25
|
+
} else {
|
|
26
|
+
widget.style.height = "80px";
|
|
27
|
+
}
|
|
28
|
+
const progress = document.createElement("div");
|
|
29
|
+
progress.className = "upload-progress";
|
|
30
|
+
widget.appendChild(progress);
|
|
31
|
+
const deco = Decoration.widget(action.add.pos, widget, {
|
|
32
|
+
id: action.add.id
|
|
33
|
+
});
|
|
34
|
+
set = set.add(tr.doc, [deco]);
|
|
35
|
+
} else if (action && action.progress) {
|
|
36
|
+
const found = set.find(
|
|
37
|
+
void 0,
|
|
38
|
+
void 0,
|
|
39
|
+
(spec) => spec.id === action.progress.id
|
|
40
|
+
);
|
|
41
|
+
if (found.length) {
|
|
42
|
+
const widget = found[0].type.toDOM;
|
|
43
|
+
const progress = widget.querySelector(".upload-progress");
|
|
44
|
+
if (progress) {
|
|
45
|
+
progress.innerHTML = `${Math.round(action.progress.progress)}%`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else if (action && action.remove) {
|
|
49
|
+
set = set.remove(
|
|
50
|
+
set.find(void 0, void 0, (spec) => spec.id === action.remove.id)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return set;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
props: {
|
|
57
|
+
decorations(state) {
|
|
58
|
+
return this.getState(state);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// src/plugins/placehoder.tsx
|
|
64
|
+
var getFirstChildDescendants = (view) => {
|
|
65
|
+
const nodes = [];
|
|
66
|
+
view.state.doc?.descendants((n) => {
|
|
67
|
+
nodes.push(n);
|
|
68
|
+
});
|
|
69
|
+
return nodes;
|
|
70
|
+
};
|
|
71
|
+
function placeholderPlugin(text) {
|
|
72
|
+
const update = (view) => {
|
|
73
|
+
const decos = uploadPlaceholderPlugin.getState(view.state);
|
|
74
|
+
if (decos && decos.find().length > 0 || view.state.doc.content.content.some((e) => e.type.name !== "paragraph") || view.state.doc.childCount > 1 || getFirstChildDescendants(view).length > 1 || view.state.doc.textContent) {
|
|
75
|
+
view.dom.removeAttribute("data-placeholder");
|
|
76
|
+
} else {
|
|
77
|
+
view.dom.setAttribute("data-placeholder", text);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return new Plugin2({
|
|
81
|
+
view(view) {
|
|
82
|
+
update(view);
|
|
83
|
+
return { update };
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
placeholderPlugin
|
|
89
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/trailing_paragraph.tsx
|
|
21
|
+
var trailing_paragraph_exports = {};
|
|
22
|
+
__export(trailing_paragraph_exports, {
|
|
23
|
+
trailingParagraph: () => trailingParagraph
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(trailing_paragraph_exports);
|
|
26
|
+
var import_prosemirror_state = require("prosemirror-state");
|
|
27
|
+
function trailingParagraph() {
|
|
28
|
+
return new import_prosemirror_state.Plugin({
|
|
29
|
+
appendTransaction(transactions, oldState, newState) {
|
|
30
|
+
const doc = newState.doc;
|
|
31
|
+
const lastNode = doc.lastChild;
|
|
32
|
+
if (lastNode && lastNode.type.name !== "paragraph") {
|
|
33
|
+
const paragraphType = newState.schema.nodes.paragraph;
|
|
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
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
trailingParagraph
|
|
46
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/plugins/trailing_paragraph.tsx
|
|
2
|
+
import { Plugin } from "prosemirror-state";
|
|
3
|
+
function trailingParagraph() {
|
|
4
|
+
return new Plugin({
|
|
5
|
+
appendTransaction(transactions, oldState, newState) {
|
|
6
|
+
const doc = newState.doc;
|
|
7
|
+
const lastNode = doc.lastChild;
|
|
8
|
+
if (lastNode && lastNode.type.name !== "paragraph") {
|
|
9
|
+
const paragraphType = newState.schema.nodes.paragraph;
|
|
10
|
+
const tr = newState.tr;
|
|
11
|
+
const endPos = doc.content.size;
|
|
12
|
+
tr.insert(endPos, paragraphType.create());
|
|
13
|
+
return tr;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
trailingParagraph
|
|
21
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Plugin, EditorState } from 'prosemirror-state';
|
|
2
|
+
import { DecorationSet } from 'prosemirror-view';
|
|
3
|
+
|
|
4
|
+
declare const uploadPlaceholderPlugin: Plugin<DecorationSet>;
|
|
5
|
+
declare const findPlaceholder: (state: EditorState, id: unknown) => number | null;
|
|
6
|
+
|
|
7
|
+
export { findPlaceholder, uploadPlaceholderPlugin };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Plugin, EditorState } from 'prosemirror-state';
|
|
2
|
+
import { DecorationSet } from 'prosemirror-view';
|
|
3
|
+
|
|
4
|
+
declare const uploadPlaceholderPlugin: Plugin<DecorationSet>;
|
|
5
|
+
declare const findPlaceholder: (state: EditorState, id: unknown) => number | null;
|
|
6
|
+
|
|
7
|
+
export { findPlaceholder, uploadPlaceholderPlugin };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/upload_placeholder.tsx
|
|
21
|
+
var upload_placeholder_exports = {};
|
|
22
|
+
__export(upload_placeholder_exports, {
|
|
23
|
+
findPlaceholder: () => findPlaceholder,
|
|
24
|
+
uploadPlaceholderPlugin: () => uploadPlaceholderPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(upload_placeholder_exports);
|
|
27
|
+
var import_prosemirror_state = require("prosemirror-state");
|
|
28
|
+
var import_prosemirror_view = require("prosemirror-view");
|
|
29
|
+
var uploadPlaceholderPlugin = new import_prosemirror_state.Plugin({
|
|
30
|
+
state: {
|
|
31
|
+
init() {
|
|
32
|
+
return import_prosemirror_view.DecorationSet.empty;
|
|
33
|
+
},
|
|
34
|
+
apply(tr, set) {
|
|
35
|
+
set = set.map(tr.mapping, tr.doc);
|
|
36
|
+
const action = tr.getMeta(this);
|
|
37
|
+
if (action && action.add) {
|
|
38
|
+
const { type, width, height } = action.add;
|
|
39
|
+
const widget = document.createElement("div");
|
|
40
|
+
widget.className = "upload-placeholder";
|
|
41
|
+
widget.style.width = `100%`;
|
|
42
|
+
if (type.startsWith("image/") || type.startsWith("video/")) {
|
|
43
|
+
widget.style.aspectRatio = `${width} / ${height}`;
|
|
44
|
+
widget.style.maxWidth = `${width}px`;
|
|
45
|
+
} else {
|
|
46
|
+
widget.style.height = "80px";
|
|
47
|
+
}
|
|
48
|
+
const progress = document.createElement("div");
|
|
49
|
+
progress.className = "upload-progress";
|
|
50
|
+
widget.appendChild(progress);
|
|
51
|
+
const deco = import_prosemirror_view.Decoration.widget(action.add.pos, widget, {
|
|
52
|
+
id: action.add.id
|
|
53
|
+
});
|
|
54
|
+
set = set.add(tr.doc, [deco]);
|
|
55
|
+
} else if (action && action.progress) {
|
|
56
|
+
const found = set.find(
|
|
57
|
+
void 0,
|
|
58
|
+
void 0,
|
|
59
|
+
(spec) => spec.id === action.progress.id
|
|
60
|
+
);
|
|
61
|
+
if (found.length) {
|
|
62
|
+
const widget = found[0].type.toDOM;
|
|
63
|
+
const progress = widget.querySelector(".upload-progress");
|
|
64
|
+
if (progress) {
|
|
65
|
+
progress.innerHTML = `${Math.round(action.progress.progress)}%`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else if (action && action.remove) {
|
|
69
|
+
set = set.remove(
|
|
70
|
+
set.find(void 0, void 0, (spec) => spec.id === action.remove.id)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return set;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
props: {
|
|
77
|
+
decorations(state) {
|
|
78
|
+
return this.getState(state);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
var findPlaceholder = (state, id) => {
|
|
83
|
+
const decos = uploadPlaceholderPlugin.getState(state);
|
|
84
|
+
if (!decos) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const found = decos.find(void 0, void 0, (spec) => spec.id === id);
|
|
88
|
+
return found.length ? found[0].from : null;
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
findPlaceholder,
|
|
93
|
+
uploadPlaceholderPlugin
|
|
94
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/plugins/upload_placeholder.tsx
|
|
2
|
+
import { Plugin } from "prosemirror-state";
|
|
3
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
4
|
+
var uploadPlaceholderPlugin = new Plugin({
|
|
5
|
+
state: {
|
|
6
|
+
init() {
|
|
7
|
+
return DecorationSet.empty;
|
|
8
|
+
},
|
|
9
|
+
apply(tr, set) {
|
|
10
|
+
set = set.map(tr.mapping, tr.doc);
|
|
11
|
+
const action = tr.getMeta(this);
|
|
12
|
+
if (action && action.add) {
|
|
13
|
+
const { type, width, height } = action.add;
|
|
14
|
+
const widget = document.createElement("div");
|
|
15
|
+
widget.className = "upload-placeholder";
|
|
16
|
+
widget.style.width = `100%`;
|
|
17
|
+
if (type.startsWith("image/") || type.startsWith("video/")) {
|
|
18
|
+
widget.style.aspectRatio = `${width} / ${height}`;
|
|
19
|
+
widget.style.maxWidth = `${width}px`;
|
|
20
|
+
} else {
|
|
21
|
+
widget.style.height = "80px";
|
|
22
|
+
}
|
|
23
|
+
const progress = document.createElement("div");
|
|
24
|
+
progress.className = "upload-progress";
|
|
25
|
+
widget.appendChild(progress);
|
|
26
|
+
const deco = Decoration.widget(action.add.pos, widget, {
|
|
27
|
+
id: action.add.id
|
|
28
|
+
});
|
|
29
|
+
set = set.add(tr.doc, [deco]);
|
|
30
|
+
} else if (action && action.progress) {
|
|
31
|
+
const found = set.find(
|
|
32
|
+
void 0,
|
|
33
|
+
void 0,
|
|
34
|
+
(spec) => spec.id === action.progress.id
|
|
35
|
+
);
|
|
36
|
+
if (found.length) {
|
|
37
|
+
const widget = found[0].type.toDOM;
|
|
38
|
+
const progress = widget.querySelector(".upload-progress");
|
|
39
|
+
if (progress) {
|
|
40
|
+
progress.innerHTML = `${Math.round(action.progress.progress)}%`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else if (action && action.remove) {
|
|
44
|
+
set = set.remove(
|
|
45
|
+
set.find(void 0, void 0, (spec) => spec.id === action.remove.id)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return set;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
props: {
|
|
52
|
+
decorations(state) {
|
|
53
|
+
return this.getState(state);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
var findPlaceholder = (state, id) => {
|
|
58
|
+
const decos = uploadPlaceholderPlugin.getState(state);
|
|
59
|
+
if (!decos) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const found = decos.find(void 0, void 0, (spec) => spec.id === id);
|
|
63
|
+
return found.length ? found[0].from : null;
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
findPlaceholder,
|
|
67
|
+
uploadPlaceholderPlugin
|
|
68
|
+
};
|