@fiduswriter/editor 0.1.17 → 0.1.19
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/state_plugins/contributor_input/node_view.js +15 -71
- package/dist/state_plugins/contributor_input/node_view.js.map +1 -1
- package/dist/state_plugins/contributor_input/plugin.js +2 -2
- package/dist/state_plugins/contributor_input/plugin.js.map +1 -1
- package/dist/state_plugins/tag_input/node_view.js +8 -71
- package/dist/state_plugins/tag_input/node_view.js.map +1 -1
- package/dist/state_plugins/tag_input/plugin.js +1 -2
- package/dist/state_plugins/tag_input/plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/state_plugins/contributor_input/node_view.js +22 -80
- package/src/state_plugins/contributor_input/plugin.js +3 -2
- package/src/state_plugins/tag_input/node_view.js +14 -79
- package/src/state_plugins/tag_input/plugin.js +2 -2
- package/src/state_plugins/contributor_input/add_button.js +0 -134
- package/src/state_plugins/contributor_input/helpers.js +0 -24
- package/src/state_plugins/tag_input/helpers.js +0 -69
- package/src/state_plugins/tag_input/tag_editor.js +0 -202
- package/src/state_plugins/tag_input/tag_editor_plugins.js +0 -74
|
@@ -1,76 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AddButton, ContributorsPartView as CommonContributorsPartView } from "@fiduswriter/common/state_plugins/contributor_input";
|
|
2
|
+
import { ContributorDialog } from "../../dialogs/index.js";
|
|
2
3
|
import { addDeletedPartWidget } from "../document_template.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.view
|
|
8
|
-
|
|
9
|
-
this.idTypes =
|
|
10
|
-
(view.state &&
|
|
11
|
-
view.state.doc &&
|
|
12
|
-
view.state.doc.attrs &&
|
|
13
|
-
view.state.doc.attrs.id_types) ||
|
|
14
|
-
[];
|
|
15
|
-
this.dom = document.createElement("div");
|
|
16
|
-
this.dom.classList.add("doc-part");
|
|
17
|
-
this.dom.classList.add(`doc-${this.node.type.name}`);
|
|
18
|
-
this.dom.classList.add(`doc-${this.node.attrs.id}`);
|
|
19
|
-
if (node.attrs.hidden) {
|
|
20
|
-
this.dom.dataset.hidden = true;
|
|
21
|
-
}
|
|
22
|
-
this.contentDOM = document.createElement("span");
|
|
23
|
-
this.contentDOM.classList.add("contributors-inner");
|
|
24
|
-
this.contentDOM.contentEditable = node.attrs.locking !== "fixed";
|
|
25
|
-
this.dom.appendChild(this.contentDOM);
|
|
26
|
-
if (node.attrs.locking !== "fixed") {
|
|
27
|
-
this.addButton = new AddButton(this.dom, () => this.getNode(), this.getPos, this.view, this.idTypes);
|
|
28
|
-
this.addButton.init();
|
|
29
|
-
}
|
|
30
|
-
if (node.attrs.deleted) {
|
|
31
|
-
addDeletedPartWidget(this.dom, view, getPos);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
stopEvent(event) {
|
|
35
|
-
// Trap events for addButton
|
|
36
|
-
if (["click", "mousedown"].includes(event.type)) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
else if (!this.addButton || this.node.attrs.locking === "fixed") {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
else if (this.addButton.hasFocus() && event.type === "keydown") {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
update(node, _decorations, _innerDecorations) {
|
|
50
|
-
this.node = node;
|
|
51
|
-
if (node.attrs.hidden) {
|
|
52
|
-
this.dom.dataset.hidden = true;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
delete this.dom.dataset.hidden;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
getNode() {
|
|
60
|
-
return this.node;
|
|
4
|
+
class EditorAddButton extends AddButton {
|
|
5
|
+
handleActivation(event) {
|
|
6
|
+
event.preventDefault();
|
|
7
|
+
const node = this.getNode();
|
|
8
|
+
const dialog = new ContributorDialog(node, this.view, false, this.idTypes);
|
|
9
|
+
dialog.init();
|
|
61
10
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ignoreMutation(_record) {
|
|
70
|
-
if (this.addButton?.hasFocus()) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
11
|
+
}
|
|
12
|
+
export class ContributorsPartView extends CommonContributorsPartView {
|
|
13
|
+
constructor(node, view, getPos) {
|
|
14
|
+
super(node, view, getPos, {
|
|
15
|
+
addDeletedPartWidget,
|
|
16
|
+
AddButton: EditorAddButton
|
|
17
|
+
});
|
|
74
18
|
}
|
|
75
19
|
}
|
|
76
20
|
//# sourceMappingURL=node_view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node_view.js","sourceRoot":"","sources":["../../../src/state_plugins/contributor_input/node_view.js"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"node_view.js","sourceRoot":"","sources":["../../../src/state_plugins/contributor_input/node_view.js"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,oBAAoB,IAAI,0BAA0B,EAAC,MAAM,qDAAqD,CAAA;AAEjI,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAE5D,MAAM,eAAgB,SAAQ,SAAS;IACnC,gBAAgB,CAAC,KAAK;QAClB,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE3B,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAChC,IAAI,EACJ,IAAI,CAAC,IAAI,EACT,KAAK,EACL,IAAI,CAAC,OAAO,CACf,CAAA;QACD,MAAM,CAAC,IAAI,EAAE,CAAA;IACjB,CAAC;CACJ;AAED,MAAM,OAAO,oBAAqB,SAAQ,0BAA0B;IAChE,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM;QAC1B,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;YACtB,oBAAoB;YACpB,SAAS,EAAE,eAAe;SAC7B,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { NodeSelection, Plugin, PluginKey } from "prosemirror-state";
|
|
12
12
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
13
|
+
import { nextSelection } from "@fiduswriter/common/state_plugins/contributor_input";
|
|
13
14
|
import { ContributorDialog } from "../../dialogs/index.js";
|
|
14
|
-
import { createDropUp } from "./dropup.js";
|
|
15
|
-
import { nextSelection } from "./helpers.js";
|
|
16
15
|
import { ContributorsPartView } from "./node_view.js";
|
|
16
|
+
import { createDropUp } from "./dropup.js";
|
|
17
17
|
const key = new PluginKey("contributorInput");
|
|
18
18
|
/**
|
|
19
19
|
* Create the contributor input plugin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/state_plugins/contributor_input/plugin.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/state_plugins/contributor_input/plugin.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAC,aAAa,EAAC,MAAM,qDAAqD,CAAA;A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prosemirror-state";
|
|
1
|
+
import { TagsPartView as CommonTagsPartView, createTagEditor as commonCreateTagEditor } from "@fiduswriter/common/state_plugins/tag_input";
|
|
3
2
|
import { addDeletedPartWidget } from "../document_template.js";
|
|
4
3
|
import { shouldPreventTagInputFocus } from "./plugin.js";
|
|
5
|
-
|
|
6
|
-
export class TagsPartView {
|
|
4
|
+
const createTagEditor = (view, getPos, getNode) => commonCreateTagEditor(view, getPos, getNode);
|
|
5
|
+
export class TagsPartView extends CommonTagsPartView {
|
|
7
6
|
constructor(node, view, getPos) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.dom.classList.add(`doc-${this.node.type.name}`);
|
|
14
|
-
this.dom.classList.add(`doc-${this.node.attrs.id}`);
|
|
15
|
-
if (node.attrs.hidden) {
|
|
16
|
-
this.dom.dataset.hidden = true;
|
|
17
|
-
}
|
|
18
|
-
this.contentDOM = document.createElement("span");
|
|
19
|
-
this.contentDOM.classList.add("tags-inner");
|
|
20
|
-
this.contentDOM.contentEditable = node.attrs.locking !== "fixed";
|
|
21
|
-
this.dom.appendChild(this.contentDOM);
|
|
22
|
-
if (node.attrs.locking !== "fixed") {
|
|
23
|
-
const [tagInputDOM, tagInputView] = createTagEditor(view, getPos, () => this.getNode());
|
|
24
|
-
this.tagInputView = tagInputView;
|
|
25
|
-
this.dom.appendChild(tagInputDOM);
|
|
26
|
-
}
|
|
27
|
-
if (node.attrs.deleted) {
|
|
28
|
-
addDeletedPartWidget(this.dom, view, getPos);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
stopEvent(event) {
|
|
32
|
-
// Trap events for tagInputView
|
|
33
|
-
if (["click", "mousedown"].includes(event.type)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
else if (!this.tagInputView || this.node.attrs.locking === "fixed") {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
else if (event.type === "keydown" && this.tagInputView.hasFocus()) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
update(node, _decorations, _innerDecorations) {
|
|
47
|
-
this.node = node;
|
|
48
|
-
if (node.attrs.hidden) {
|
|
49
|
-
this.dom.dataset.hidden = true;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
delete this.dom.dataset.hidden;
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
getNode() {
|
|
57
|
-
return this.node;
|
|
58
|
-
}
|
|
59
|
-
setSelection(anchor, head, _root) {
|
|
60
|
-
if (anchor === head && this.view.hasFocus()) {
|
|
61
|
-
// Check if we should prevent refocusing (e.g., user just clicked on a tag)
|
|
62
|
-
if (shouldPreventTagInputFocus()) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// We must be in last position.
|
|
66
|
-
// Activate the tag input tag editor.
|
|
67
|
-
this.tagInputView.focus();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
ignoreMutation(_record) {
|
|
71
|
-
if (this.tagInputView?.hasFocus()) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
7
|
+
super(node, view, getPos, {
|
|
8
|
+
addDeletedPartWidget,
|
|
9
|
+
createTagEditor,
|
|
10
|
+
shouldPreventTagInputFocus
|
|
11
|
+
});
|
|
75
12
|
}
|
|
76
13
|
}
|
|
77
14
|
//# sourceMappingURL=node_view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node_view.js","sourceRoot":"","sources":["../../../src/state_plugins/tag_input/node_view.js"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"node_view.js","sourceRoot":"","sources":["../../../src/state_plugins/tag_input/node_view.js"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,IAAI,kBAAkB,EAClC,eAAe,IAAI,qBAAqB,EAC3C,MAAM,6CAA6C,CAAA;AAEpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAC,0BAA0B,EAAC,MAAM,aAAa,CAAA;AAEtD,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAC9C,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD,MAAM,OAAO,YAAa,SAAQ,kBAAkB;IAChD,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM;QAC1B,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;YACtB,oBAAoB;YACpB,eAAe;YACf,0BAA0B;SAC7B,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { GapCursor } from "prosemirror-gapcursor";
|
|
2
2
|
import { NodeSelection, Plugin, PluginKey, TextSelection } from "prosemirror-state";
|
|
3
|
-
import { nextSelection, submitTag } from "
|
|
3
|
+
import { nextSelection, submitTag, tagInputReferences } from "@fiduswriter/common/state_plugins/tag_input";
|
|
4
4
|
import { TagsPartView } from "./node_view.js";
|
|
5
|
-
import { tagInputReferences } from "./tag_editor.js";
|
|
6
5
|
const key = new PluginKey("tagInput");
|
|
7
6
|
// Track mouse click state across transactions using closure variable
|
|
8
7
|
let mouseClickActive = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/state_plugins/tag_input/plugin.js"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EACH,aAAa,EACb,MAAM,EACN,SAAS,EACT,aAAa,EAChB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAC,aAAa,EAAE,SAAS,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/state_plugins/tag_input/plug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A"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Fidus Writer browser editor",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fiduswriter/bibliography-manager": "^0.1.7",
|
|
35
|
-
"@fiduswriter/common": "^0.1.
|
|
35
|
+
"@fiduswriter/common": "^0.1.5",
|
|
36
36
|
"@fiduswriter/document": "^0.2.20",
|
|
37
37
|
"@fiduswriter/image-manager": "^0.1.4",
|
|
38
38
|
"bibliojson": "^4.0.0",
|
|
@@ -1,86 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {addDeletedPartWidget} from "../document_template.js"
|
|
3
|
-
|
|
4
|
-
import {AddButton} from "./add_button.js"
|
|
5
|
-
|
|
6
|
-
export class ContributorsPartView {
|
|
7
|
-
constructor(node, view, getPos) {
|
|
8
|
-
this.node = node
|
|
9
|
-
this.view = view
|
|
10
|
-
this.getPos = getPos
|
|
11
|
-
this.idTypes =
|
|
12
|
-
(view.state &&
|
|
13
|
-
view.state.doc &&
|
|
14
|
-
view.state.doc.attrs &&
|
|
15
|
-
view.state.doc.attrs.id_types) ||
|
|
16
|
-
[]
|
|
17
|
-
this.dom = document.createElement("div")
|
|
18
|
-
this.dom.classList.add("doc-part")
|
|
19
|
-
this.dom.classList.add(`doc-${this.node.type.name}`)
|
|
20
|
-
this.dom.classList.add(`doc-${this.node.attrs.id}`)
|
|
21
|
-
if (node.attrs.hidden) {
|
|
22
|
-
this.dom.dataset.hidden = true
|
|
23
|
-
}
|
|
1
|
+
import {AddButton, ContributorsPartView as CommonContributorsPartView} from "@fiduswriter/common/state_plugins/contributor_input"
|
|
24
2
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.contentDOM.contentEditable = node.attrs.locking !== "fixed"
|
|
28
|
-
this.dom.appendChild(this.contentDOM)
|
|
29
|
-
if (node.attrs.locking !== "fixed") {
|
|
30
|
-
this.addButton = new AddButton(
|
|
31
|
-
this.dom,
|
|
32
|
-
() => this.getNode(),
|
|
33
|
-
this.getPos,
|
|
34
|
-
this.view,
|
|
35
|
-
this.idTypes
|
|
36
|
-
)
|
|
37
|
-
this.addButton.init()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (node.attrs.deleted) {
|
|
41
|
-
addDeletedPartWidget(this.dom, view, getPos)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
stopEvent(event) {
|
|
46
|
-
// Trap events for addButton
|
|
47
|
-
if (["click", "mousedown"].includes(event.type)) {
|
|
48
|
-
return false
|
|
49
|
-
} else if (!this.addButton || this.node.attrs.locking === "fixed") {
|
|
50
|
-
return false
|
|
51
|
-
} else if (this.addButton.hasFocus() && event.type === "keydown") {
|
|
52
|
-
return true
|
|
53
|
-
} else {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
update(node, _decorations, _innerDecorations) {
|
|
59
|
-
this.node = node
|
|
60
|
-
if (node.attrs.hidden) {
|
|
61
|
-
this.dom.dataset.hidden = true
|
|
62
|
-
} else {
|
|
63
|
-
delete this.dom.dataset.hidden
|
|
64
|
-
}
|
|
65
|
-
return true
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getNode() {
|
|
69
|
-
return this.node
|
|
70
|
-
}
|
|
3
|
+
import {ContributorDialog} from "../../dialogs/index.js"
|
|
4
|
+
import {addDeletedPartWidget} from "../document_template.js"
|
|
71
5
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
6
|
+
class EditorAddButton extends AddButton {
|
|
7
|
+
handleActivation(event) {
|
|
8
|
+
event.preventDefault()
|
|
9
|
+
const node = this.getNode()
|
|
10
|
+
|
|
11
|
+
const dialog = new ContributorDialog(
|
|
12
|
+
node,
|
|
13
|
+
this.view,
|
|
14
|
+
false,
|
|
15
|
+
this.idTypes
|
|
16
|
+
)
|
|
17
|
+
dialog.init()
|
|
78
18
|
}
|
|
19
|
+
}
|
|
79
20
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
21
|
+
export class ContributorsPartView extends CommonContributorsPartView {
|
|
22
|
+
constructor(node, view, getPos) {
|
|
23
|
+
super(node, view, getPos, {
|
|
24
|
+
addDeletedPartWidget,
|
|
25
|
+
AddButton: EditorAddButton
|
|
26
|
+
})
|
|
85
27
|
}
|
|
86
28
|
}
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
import {NodeSelection, Plugin, PluginKey} from "prosemirror-state"
|
|
12
12
|
import {Decoration, DecorationSet} from "prosemirror-view"
|
|
13
13
|
|
|
14
|
+
import {nextSelection} from "@fiduswriter/common/state_plugins/contributor_input"
|
|
15
|
+
|
|
14
16
|
import {ContributorDialog} from "../../dialogs/index.js"
|
|
15
|
-
import {createDropUp} from "./dropup.js"
|
|
16
|
-
import {nextSelection} from "./helpers.js"
|
|
17
17
|
import {ContributorsPartView} from "./node_view.js"
|
|
18
|
+
import {createDropUp} from "./dropup.js"
|
|
18
19
|
|
|
19
20
|
const key = new PluginKey("contributorInput")
|
|
20
21
|
|
|
@@ -1,85 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
TagsPartView as CommonTagsPartView,
|
|
3
|
+
createTagEditor as commonCreateTagEditor
|
|
4
|
+
} from "@fiduswriter/common/state_plugins/tag_input"
|
|
4
5
|
|
|
6
|
+
import {addDeletedPartWidget} from "../document_template.js"
|
|
5
7
|
import {shouldPreventTagInputFocus} from "./plugin.js"
|
|
6
|
-
import {createTagEditor} from "./tag_editor.js"
|
|
7
|
-
|
|
8
|
-
export class TagsPartView {
|
|
9
|
-
constructor(node, view, getPos) {
|
|
10
|
-
this.node = node
|
|
11
|
-
this.view = view
|
|
12
|
-
this.getPos = getPos
|
|
13
|
-
this.dom = document.createElement("div")
|
|
14
|
-
this.dom.classList.add("doc-part")
|
|
15
|
-
this.dom.classList.add(`doc-${this.node.type.name}`)
|
|
16
|
-
this.dom.classList.add(`doc-${this.node.attrs.id}`)
|
|
17
|
-
if (node.attrs.hidden) {
|
|
18
|
-
this.dom.dataset.hidden = true
|
|
19
|
-
}
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.contentDOM.contentEditable = node.attrs.locking !== "fixed"
|
|
24
|
-
this.dom.appendChild(this.contentDOM)
|
|
25
|
-
if (node.attrs.locking !== "fixed") {
|
|
26
|
-
const [tagInputDOM, tagInputView] = createTagEditor(
|
|
27
|
-
view,
|
|
28
|
-
getPos,
|
|
29
|
-
() => this.getNode()
|
|
30
|
-
)
|
|
31
|
-
this.tagInputView = tagInputView
|
|
32
|
-
this.dom.appendChild(tagInputDOM)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (node.attrs.deleted) {
|
|
36
|
-
addDeletedPartWidget(this.dom, view, getPos)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
stopEvent(event) {
|
|
41
|
-
// Trap events for tagInputView
|
|
42
|
-
if (["click", "mousedown"].includes(event.type)) {
|
|
43
|
-
return false
|
|
44
|
-
} else if (!this.tagInputView || this.node.attrs.locking === "fixed") {
|
|
45
|
-
return false
|
|
46
|
-
} else if (event.type === "keydown" && this.tagInputView.hasFocus()) {
|
|
47
|
-
return true
|
|
48
|
-
} else {
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
}
|
|
9
|
+
const createTagEditor = (view, getPos, getNode) =>
|
|
10
|
+
commonCreateTagEditor(view, getPos, getNode)
|
|
52
11
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getNode() {
|
|
64
|
-
return this.node
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setSelection(anchor, head, _root) {
|
|
68
|
-
if (anchor === head && this.view.hasFocus()) {
|
|
69
|
-
// Check if we should prevent refocusing (e.g., user just clicked on a tag)
|
|
70
|
-
if (shouldPreventTagInputFocus()) {
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
// We must be in last position.
|
|
74
|
-
// Activate the tag input tag editor.
|
|
75
|
-
this.tagInputView.focus()
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
ignoreMutation(_record) {
|
|
80
|
-
if (this.tagInputView?.hasFocus()) {
|
|
81
|
-
return true
|
|
82
|
-
}
|
|
83
|
-
return false
|
|
12
|
+
export class TagsPartView extends CommonTagsPartView {
|
|
13
|
+
constructor(node, view, getPos) {
|
|
14
|
+
super(node, view, getPos, {
|
|
15
|
+
addDeletedPartWidget,
|
|
16
|
+
createTagEditor,
|
|
17
|
+
shouldPreventTagInputFocus
|
|
18
|
+
})
|
|
84
19
|
}
|
|
85
20
|
}
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
TextSelection
|
|
7
7
|
} from "prosemirror-state"
|
|
8
8
|
|
|
9
|
-
import {nextSelection, submitTag} from "
|
|
9
|
+
import {nextSelection, submitTag, tagInputReferences} from "@fiduswriter/common/state_plugins/tag_input"
|
|
10
|
+
|
|
10
11
|
import {TagsPartView} from "./node_view.js"
|
|
11
|
-
import {tagInputReferences} from "./tag_editor.js"
|
|
12
12
|
|
|
13
13
|
const key = new PluginKey("tagInput")
|
|
14
14
|
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {keyName} from "w3c-keyname"
|
|
2
|
-
|
|
3
|
-
import {NodeSelection} from "prosemirror-state"
|
|
4
|
-
import {ContributorDialog} from "../../dialogs/index.js"
|
|
5
|
-
import {nextSelection} from "./helpers.js"
|
|
6
|
-
|
|
7
|
-
export class AddButton {
|
|
8
|
-
constructor(dom, getNode, getPos, view, idTypes) {
|
|
9
|
-
this.dom = dom
|
|
10
|
-
this.getNode = getNode
|
|
11
|
-
this.getPos = getPos
|
|
12
|
-
this.view = view
|
|
13
|
-
|
|
14
|
-
this.idTypes = idTypes
|
|
15
|
-
|
|
16
|
-
this.button = null
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
init() {
|
|
20
|
-
const node = this.getNode()
|
|
21
|
-
const nodeTitle = node.attrs.item_title
|
|
22
|
-
this.dom.insertAdjacentHTML(
|
|
23
|
-
"beforeend",
|
|
24
|
-
`<button class="fw-button fw-light">${gettext("Add")} ${nodeTitle.toLowerCase()}...</button>`
|
|
25
|
-
)
|
|
26
|
-
this.button = this.dom.lastElementChild
|
|
27
|
-
this.button.addEventListener("click", event =>
|
|
28
|
-
this.handleActivation(event)
|
|
29
|
-
)
|
|
30
|
-
this.button.addEventListener("keydown", event =>
|
|
31
|
-
this.handleKeyDown(event)
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
handleKeyDown(event) {
|
|
36
|
-
const key = keyName(event)
|
|
37
|
-
switch (key) {
|
|
38
|
-
case "Enter":
|
|
39
|
-
case " ":
|
|
40
|
-
this.handleActivation(event)
|
|
41
|
-
break
|
|
42
|
-
case "ArrowRight":
|
|
43
|
-
case "ArrowDown":
|
|
44
|
-
if (this.handleArrowDown()) {
|
|
45
|
-
event.preventDefault()
|
|
46
|
-
}
|
|
47
|
-
break
|
|
48
|
-
case "ArrowLeft":
|
|
49
|
-
if (this.handleArrowLeft()) {
|
|
50
|
-
event.preventDefault()
|
|
51
|
-
}
|
|
52
|
-
break
|
|
53
|
-
case "ArrowUp":
|
|
54
|
-
if (this.handleArrowUp()) {
|
|
55
|
-
event.preventDefault()
|
|
56
|
-
}
|
|
57
|
-
break
|
|
58
|
-
default:
|
|
59
|
-
break
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
handleActivation(event) {
|
|
64
|
-
event.preventDefault()
|
|
65
|
-
const node = this.getNode()
|
|
66
|
-
|
|
67
|
-
const dialog = new ContributorDialog(
|
|
68
|
-
node,
|
|
69
|
-
this.view,
|
|
70
|
-
false,
|
|
71
|
-
this.idTypes
|
|
72
|
-
)
|
|
73
|
-
dialog.init()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
handleArrowLeft() {
|
|
77
|
-
const node = this.getNode()
|
|
78
|
-
if (node.nodeSize > 2) {
|
|
79
|
-
// At least one contributor
|
|
80
|
-
const startPos = this.getPos() + node.nodeSize - 2
|
|
81
|
-
this.view.dispatch(
|
|
82
|
-
this.view.state.tr.setSelection(
|
|
83
|
-
NodeSelection.create(this.view.state.doc, startPos)
|
|
84
|
-
)
|
|
85
|
-
)
|
|
86
|
-
this.view.focus()
|
|
87
|
-
return true
|
|
88
|
-
} else {
|
|
89
|
-
// There is no tag
|
|
90
|
-
return this.handleArrowUp()
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
handleArrowUp() {
|
|
95
|
-
// We jump to the section before this one.
|
|
96
|
-
const startPos = this.getPos()
|
|
97
|
-
|
|
98
|
-
const newSelection = nextSelection(this.view.state, startPos, -1)
|
|
99
|
-
|
|
100
|
-
if (!newSelection) {
|
|
101
|
-
return false
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.view.dispatch(this.view.state.tr.setSelection(newSelection))
|
|
105
|
-
this.view.focus()
|
|
106
|
-
return true
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
handleArrowDown() {
|
|
110
|
-
// Move the cursor beyond the contributors part
|
|
111
|
-
const node = this.getNode()
|
|
112
|
-
const pos = this.getPos() + node.nodeSize + 1
|
|
113
|
-
|
|
114
|
-
const newSelection = nextSelection(this.view.state, pos, 1)
|
|
115
|
-
|
|
116
|
-
if (!newSelection) {
|
|
117
|
-
return false
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.view.dispatch(this.view.state.tr.setSelection(newSelection))
|
|
121
|
-
this.view.focus()
|
|
122
|
-
return true
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
hasFocus() {
|
|
126
|
-
return this.button === window.document.activeElement
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
focus() {
|
|
130
|
-
if (this.button) {
|
|
131
|
-
this.button.focus()
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {GapCursor} from "prosemirror-gapcursor"
|
|
2
|
-
import {TextSelection} from "prosemirror-state"
|
|
3
|
-
|
|
4
|
-
export const nextSelection = (state, pos, dir) => {
|
|
5
|
-
let newSelection
|
|
6
|
-
let newPos = pos
|
|
7
|
-
let $newPos
|
|
8
|
-
|
|
9
|
-
while (!newSelection) {
|
|
10
|
-
newPos += dir
|
|
11
|
-
if (newPos === 0 || newPos === state.doc.nodeSize) {
|
|
12
|
-
// Could not find any valid position
|
|
13
|
-
break
|
|
14
|
-
}
|
|
15
|
-
$newPos = state.doc.resolve(newPos)
|
|
16
|
-
if ($newPos.parent.inlineContent) {
|
|
17
|
-
newSelection = new TextSelection($newPos)
|
|
18
|
-
} else if (GapCursor.valid($newPos)) {
|
|
19
|
-
newSelection = new GapCursor($newPos)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return newSelection
|
|
24
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {GapCursor} from "prosemirror-gapcursor"
|
|
2
|
-
import {TextSelection} from "prosemirror-state"
|
|
3
|
-
|
|
4
|
-
export const nextSelection = (state, pos, dir) => {
|
|
5
|
-
let newSelection
|
|
6
|
-
let newPos = pos
|
|
7
|
-
let $newPos
|
|
8
|
-
|
|
9
|
-
while (!newSelection) {
|
|
10
|
-
newPos += dir
|
|
11
|
-
if (newPos === 0 || newPos === state.doc.nodeSize) {
|
|
12
|
-
// Could not find any valid position
|
|
13
|
-
break
|
|
14
|
-
}
|
|
15
|
-
$newPos = state.doc.resolve(newPos)
|
|
16
|
-
if ($newPos.parent.inlineContent) {
|
|
17
|
-
newSelection = new TextSelection($newPos)
|
|
18
|
-
} else if (GapCursor.valid($newPos)) {
|
|
19
|
-
newSelection = new GapCursor($newPos)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return newSelection
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const submitTag = (tagInputView, view, getPos) => {
|
|
27
|
-
const tagState = tagInputView.state
|
|
28
|
-
const selectionTo = tagState.selection.to
|
|
29
|
-
const tag =
|
|
30
|
-
selectionTo > 1
|
|
31
|
-
? tagState.doc.textBetween(1, selectionTo)
|
|
32
|
-
: tagState.doc.textContent
|
|
33
|
-
if (tag.length) {
|
|
34
|
-
try {
|
|
35
|
-
const eState = view.state,
|
|
36
|
-
startPos = getPos()
|
|
37
|
-
|
|
38
|
-
// Validate that the position is still valid
|
|
39
|
-
if (
|
|
40
|
-
startPos === null ||
|
|
41
|
-
startPos === undefined ||
|
|
42
|
-
startPos < 0 ||
|
|
43
|
-
startPos >= eState.doc.content.size
|
|
44
|
-
) {
|
|
45
|
-
// Position is out of range, node was likely removed or moved
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const nodeAtPos = view.state.doc.nodeAt(startPos)
|
|
50
|
-
if (!nodeAtPos) {
|
|
51
|
-
// Node no longer exists at this position
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const pos = startPos + nodeAtPos.nodeSize - 1,
|
|
56
|
-
node = eState.schema.nodes.tag.create({tag})
|
|
57
|
-
view.dispatch(view.state.tr.insert(pos, node))
|
|
58
|
-
tagInputView.dispatch(
|
|
59
|
-
tagState.tr.delete(
|
|
60
|
-
1,
|
|
61
|
-
selectionTo > 1 ? selectionTo : tagState.doc.nodeSize - 3
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
} catch (_e) {
|
|
65
|
-
// If there's any error during tag submission (e.g., position became invalid),
|
|
66
|
-
// silently fail to avoid disrupting the user's workflow
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import {history, redo, undo} from "prosemirror-history"
|
|
2
|
-
import {keymap} from "prosemirror-keymap"
|
|
3
|
-
import {Schema} from "prosemirror-model"
|
|
4
|
-
import {NodeSelection, TextSelection} from "prosemirror-state"
|
|
5
|
-
import {EditorState} from "prosemirror-state"
|
|
6
|
-
import {EditorView} from "prosemirror-view"
|
|
7
|
-
|
|
8
|
-
import {nextSelection, submitTag} from "./helpers.js"
|
|
9
|
-
import {pastePlugin, placeholderPlugin} from "./tag_editor_plugins.js"
|
|
10
|
-
|
|
11
|
-
// WeakMap to store tag input references for access from the plugin
|
|
12
|
-
export const tagInputReferences = new WeakMap()
|
|
13
|
-
|
|
14
|
-
const doc = {content: "tag"},
|
|
15
|
-
tag = {
|
|
16
|
-
content: "inline*",
|
|
17
|
-
parseDOM: [{tag: "div.tag-input-editor"}],
|
|
18
|
-
toDOM() {
|
|
19
|
-
return [
|
|
20
|
-
"div",
|
|
21
|
-
{
|
|
22
|
-
class: "tag-input-editor"
|
|
23
|
-
},
|
|
24
|
-
0
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
text = {group: "inline"}
|
|
29
|
-
|
|
30
|
-
const schema = new Schema({
|
|
31
|
-
nodes: {doc, tag, text},
|
|
32
|
-
marks: {}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const ArrowLeft = (state, dispatch, getNode, view, getPos) => {
|
|
36
|
-
// If we're at the leftmost position (position 1), stopEvent will handle moving out of the tag
|
|
37
|
-
if (state.selection.to > 1) {
|
|
38
|
-
// Inside the tag input, move caret left normally
|
|
39
|
-
const tr = state.tr.setSelection(
|
|
40
|
-
TextSelection.create(
|
|
41
|
-
state.doc,
|
|
42
|
-
state.selection.from - 1,
|
|
43
|
-
state.selection.to - 1
|
|
44
|
-
)
|
|
45
|
-
)
|
|
46
|
-
dispatch(tr)
|
|
47
|
-
return true
|
|
48
|
-
} else {
|
|
49
|
-
const node = getNode()
|
|
50
|
-
// Exit tag input to the left
|
|
51
|
-
if (node.nodeSize > 2) {
|
|
52
|
-
// At least one tag
|
|
53
|
-
const startPos = getPos() + node.nodeSize - 2
|
|
54
|
-
view.dispatch(
|
|
55
|
-
view.state.tr.setSelection(
|
|
56
|
-
NodeSelection.create(view.state.doc, startPos)
|
|
57
|
-
)
|
|
58
|
-
)
|
|
59
|
-
view.focus()
|
|
60
|
-
return true
|
|
61
|
-
} else {
|
|
62
|
-
// There is no tag
|
|
63
|
-
return ArrowUp(state, dispatch, getNode, view, getPos)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const ArrowUp = (_state, _dispatch, _getNode, view, getPos) => {
|
|
69
|
-
// We jump to the section before this one.
|
|
70
|
-
const startPos = getPos()
|
|
71
|
-
|
|
72
|
-
const newSelection = nextSelection(view.state, startPos, -1)
|
|
73
|
-
|
|
74
|
-
if (!newSelection) {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
view.dispatch(view.state.tr.setSelection(newSelection))
|
|
79
|
-
view.focus()
|
|
80
|
-
return true
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const ArrowRight = (state, dispatch, getNode, view, getPos) => {
|
|
84
|
-
const docSize = state.doc.nodeSize - 3
|
|
85
|
-
// If we're at the rightmost position, stopEvent will handle moving out of the tag
|
|
86
|
-
if (state.selection.from < docSize) {
|
|
87
|
-
// Inside the tag input, move caret right normally
|
|
88
|
-
const tr = state.tr.setSelection(
|
|
89
|
-
TextSelection.create(
|
|
90
|
-
state.doc,
|
|
91
|
-
state.selection.from + 1,
|
|
92
|
-
state.selection.from + 1
|
|
93
|
-
)
|
|
94
|
-
)
|
|
95
|
-
dispatch(tr)
|
|
96
|
-
return true
|
|
97
|
-
} else {
|
|
98
|
-
return ArrowDown(state, dispatch, getNode, view, getPos)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const ArrowDown = (_state, _dispatch, getNode, view, getPos) => {
|
|
103
|
-
// We are at the end of the tag input. Move the cursor beyond
|
|
104
|
-
const node = getNode()
|
|
105
|
-
const startPos = getPos(),
|
|
106
|
-
pos = startPos + node.nodeSize + 1
|
|
107
|
-
|
|
108
|
-
const newSelection = nextSelection(view.state, pos, 1)
|
|
109
|
-
|
|
110
|
-
if (!newSelection) {
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
view.dispatch(view.state.tr.setSelection(newSelection))
|
|
115
|
-
view.focus()
|
|
116
|
-
return true
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const createTagEditor = (view, getPos, getNode) => {
|
|
120
|
-
const dom = document.createElement("div")
|
|
121
|
-
dom.classList.add("tag-input")
|
|
122
|
-
dom.setAttribute("contenteditable", false)
|
|
123
|
-
const node = getNode()
|
|
124
|
-
|
|
125
|
-
const tagInputView = new EditorView(dom, {
|
|
126
|
-
state: EditorState.create({
|
|
127
|
-
schema,
|
|
128
|
-
doc: schema.nodeFromJSON({
|
|
129
|
-
type: "doc",
|
|
130
|
-
content: [
|
|
131
|
-
{
|
|
132
|
-
type: "tag",
|
|
133
|
-
content: []
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
}),
|
|
137
|
-
plugins: [
|
|
138
|
-
history(),
|
|
139
|
-
placeholderPlugin(node.attrs.item_title),
|
|
140
|
-
pastePlugin(view),
|
|
141
|
-
keymap({
|
|
142
|
-
"Mod-z": undo,
|
|
143
|
-
"Mod-shift-z": undo,
|
|
144
|
-
"Mod-y": redo,
|
|
145
|
-
Enter: (_state, _dispatch, tagInputView) =>
|
|
146
|
-
submitTag(tagInputView, view, getPos),
|
|
147
|
-
ArrowLeft: (state, dispatch, _tagInputView) =>
|
|
148
|
-
ArrowLeft(state, dispatch, getNode, view, getPos),
|
|
149
|
-
ArrowRight: (state, dispatch, _tagInputView) =>
|
|
150
|
-
ArrowRight(state, dispatch, getNode, view, getPos),
|
|
151
|
-
ArrowUp: (state, dispatch, _tagInputView) =>
|
|
152
|
-
ArrowUp(state, dispatch, getNode, view, getPos),
|
|
153
|
-
ArrowDown: (state, dispatch, _tagInputView) =>
|
|
154
|
-
ArrowDown(state, dispatch, getNode, view, getPos)
|
|
155
|
-
})
|
|
156
|
-
]
|
|
157
|
-
}),
|
|
158
|
-
handleDOMEvents: {
|
|
159
|
-
blur: (tagInputView, event) => {
|
|
160
|
-
// Handle blur event
|
|
161
|
-
event.preventDefault()
|
|
162
|
-
// Set a timeout so that change of focus can take place first
|
|
163
|
-
window.setTimeout(() => {
|
|
164
|
-
// Check if getPos still returns a valid position
|
|
165
|
-
const pos = getPos()
|
|
166
|
-
if (pos !== undefined && pos !== null) {
|
|
167
|
-
submitTag(tagInputView, view, getPos)
|
|
168
|
-
}
|
|
169
|
-
}, 1)
|
|
170
|
-
},
|
|
171
|
-
focus: (tagInputView, _event) => {
|
|
172
|
-
const startPos = getPos(),
|
|
173
|
-
pos =
|
|
174
|
-
startPos + view.state.doc.nodeAt(startPos).nodeSize - 1,
|
|
175
|
-
$pos = view.state.doc.resolve(pos)
|
|
176
|
-
view.dispatch(
|
|
177
|
-
view.state.tr.setSelection(new TextSelection($pos))
|
|
178
|
-
)
|
|
179
|
-
tagInputView.focus()
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
handleTextInput: (_view, _from, _to, text) => {
|
|
183
|
-
if ([",", ".", ";"].includes(text)) {
|
|
184
|
-
submitTag(tagInputView, view, getPos)
|
|
185
|
-
return true
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
dispatchTransaction: tr => {
|
|
189
|
-
const newState = tagInputView.state.apply(tr)
|
|
190
|
-
tagInputView.updateState(newState)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// Store references in WeakMap for access from the plugin
|
|
195
|
-
tagInputReferences.set(dom, {
|
|
196
|
-
tagInputView,
|
|
197
|
-
mainView: view,
|
|
198
|
-
getPos
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
return [dom, tagInputView]
|
|
202
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {Plugin} from "prosemirror-state"
|
|
2
|
-
import {Decoration, DecorationSet} from "prosemirror-view"
|
|
3
|
-
|
|
4
|
-
export const placeholderPlugin = nodeTitle =>
|
|
5
|
-
new Plugin({
|
|
6
|
-
props: {
|
|
7
|
-
decorations: state => {
|
|
8
|
-
const doc = state.doc
|
|
9
|
-
if (
|
|
10
|
-
doc.childCount === 1 &&
|
|
11
|
-
doc.firstChild.isTextblock &&
|
|
12
|
-
doc.firstChild.content.size === 0
|
|
13
|
-
) {
|
|
14
|
-
const placeHolder = document.createElement("span")
|
|
15
|
-
placeHolder.classList.add("fw-placeholder")
|
|
16
|
-
// There is only one field, so we know the selection is there
|
|
17
|
-
placeHolder.classList.add("fw-selected")
|
|
18
|
-
placeHolder.setAttribute(
|
|
19
|
-
"data-placeholder",
|
|
20
|
-
`${gettext("Add")} ${nodeTitle.toLowerCase()}...`
|
|
21
|
-
)
|
|
22
|
-
return DecorationSet.create(doc, [
|
|
23
|
-
Decoration.widget(1, placeHolder)
|
|
24
|
-
])
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export const pastePlugin = editorView => {
|
|
31
|
-
return new Plugin({
|
|
32
|
-
props: {
|
|
33
|
-
handleDOMEvents: {
|
|
34
|
-
paste(_view, event) {
|
|
35
|
-
const html = event.clipboardData.getData("text/html"),
|
|
36
|
-
text = event.clipboardData.getData("text/plain"),
|
|
37
|
-
slice = text
|
|
38
|
-
.split(/[,;.]/)
|
|
39
|
-
.map(item => item.trim())
|
|
40
|
-
.filter(item => item.length)
|
|
41
|
-
let tags
|
|
42
|
-
if (text && !html) {
|
|
43
|
-
tags = slice
|
|
44
|
-
} else {
|
|
45
|
-
// Make a paste DOM document
|
|
46
|
-
const clipboardDoc =
|
|
47
|
-
document.implementation.createHTMLDocument(
|
|
48
|
-
"paste document"
|
|
49
|
-
)
|
|
50
|
-
const pasteHTML = document.createElement("body")
|
|
51
|
-
clipboardDoc.body.appendChild(pasteHTML)
|
|
52
|
-
pasteHTML.innerHTML = html
|
|
53
|
-
tags = Array.from(
|
|
54
|
-
pasteHTML.querySelectorAll("span.tag")
|
|
55
|
-
).map(tag => tag.textContent)
|
|
56
|
-
}
|
|
57
|
-
if (!tags.length) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
const pos = editorView.state.selection.from
|
|
61
|
-
const tr = editorView.state.tr
|
|
62
|
-
tags.reverse().forEach(tag => {
|
|
63
|
-
const node = editorView.state.schema.nodes.tag.create({
|
|
64
|
-
tag
|
|
65
|
-
})
|
|
66
|
-
tr.insert(pos, node)
|
|
67
|
-
})
|
|
68
|
-
editorView.dispatch(tr)
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
}
|