@fiduswriter/editor 0.1.36 → 0.1.37
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.
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Plugin } from "prosemirror-state";
|
|
2
|
+
import type { ModCitations } from "../citations/index.js";
|
|
2
3
|
interface CitationRenderState {
|
|
3
4
|
action: string | false;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
editor:
|
|
7
|
-
|
|
6
|
+
interface CitationRenderOptions {
|
|
7
|
+
editor: {
|
|
8
|
+
mod: {
|
|
9
|
+
citations: ModCitations;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const citationRenderPlugin: (options: CitationRenderOptions) => Plugin<CitationRenderState>;
|
|
8
14
|
export {};
|
|
9
15
|
//# sourceMappingURL=citation_render.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citation_render.d.ts","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"citation_render.d.ts","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAA8B,MAAM,mBAAmB,CAAA;AAIrE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAA;AAIvD,UAAU,mBAAmB;IACzB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAA;CACzB;AAED,UAAU,qBAAqB;IAC3B,MAAM,EAAE;QAAC,GAAG,EAAE;YAAC,SAAS,EAAE,YAAY,CAAA;SAAC,CAAA;KAAC,CAAA;CAC3C;AAED,eAAO,MAAM,oBAAoB,GAAI,SAAS,qBAAqB,gCAsF7D,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
2
|
import { ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
|
|
3
3
|
const key = new PluginKey("citationRender");
|
|
4
|
-
export const citationRenderPlugin = (
|
|
4
|
+
export const citationRenderPlugin = (options) => new Plugin({
|
|
5
5
|
key,
|
|
6
6
|
state: {
|
|
7
7
|
init() {
|
|
@@ -27,7 +27,7 @@ export const citationRenderPlugin = (_options) => new Plugin({
|
|
|
27
27
|
step instanceof ReplaceAroundStep) {
|
|
28
28
|
if (step.from !== step.to) {
|
|
29
29
|
;
|
|
30
|
-
tr.docs[index].nodesBetween(step.from, step.to, node => {
|
|
30
|
+
tr.docs[index].nodesBetween(step.from, step.to, (node) => {
|
|
31
31
|
if (node.type.name === "citation") {
|
|
32
32
|
// A citation was replaced. We need to reset
|
|
33
33
|
action = "reset";
|
|
@@ -39,7 +39,7 @@ export const citationRenderPlugin = (_options) => new Plugin({
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
if (step.slice?.content) {
|
|
42
|
-
step.slice.content.descendants(node => {
|
|
42
|
+
step.slice.content.descendants((node) => {
|
|
43
43
|
if (node.type.name === "citation") {
|
|
44
44
|
// A citation was added. We need to reset
|
|
45
45
|
action = "reset";
|
|
@@ -54,6 +54,31 @@ export const citationRenderPlugin = (_options) => new Plugin({
|
|
|
54
54
|
});
|
|
55
55
|
return { action };
|
|
56
56
|
}
|
|
57
|
+
},
|
|
58
|
+
view(_view) {
|
|
59
|
+
options.editor.mod.citations.resetCitations();
|
|
60
|
+
return {
|
|
61
|
+
update: (view, _prevState) => {
|
|
62
|
+
const stateAction = key.getState(view.state);
|
|
63
|
+
const action = stateAction?.action;
|
|
64
|
+
if (action === "reset") {
|
|
65
|
+
options.editor.mod.citations.resetCitations();
|
|
66
|
+
const tr = view.state.tr.setMeta(key, { action: false });
|
|
67
|
+
view.dispatch(tr);
|
|
68
|
+
}
|
|
69
|
+
else if (action === "numbers") {
|
|
70
|
+
options.editor.mod.citations.footnoteNumberOverride();
|
|
71
|
+
const tr = view.state.tr.setMeta(key, { action: false });
|
|
72
|
+
view.dispatch(tr);
|
|
73
|
+
}
|
|
74
|
+
else if (view.dom.querySelector(".citation:empty")) {
|
|
75
|
+
options.editor.mod.citations.resetCitations();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
destroy: () => {
|
|
79
|
+
options.editor.mod.citations.resetCitations();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
57
82
|
}
|
|
58
83
|
});
|
|
59
84
|
//# sourceMappingURL=citation_render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citation_render.js","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"citation_render.js","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAmB,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,uBAAuB,CAAA;AAKpE,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,gBAAgB,CAAC,CAAA;AAU3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAA8B,EAAE,EAAE,CACnE,IAAI,MAAM,CAAsB;IAC5B,GAAG;IACH,KAAK,EAAE;QACH,IAAI;YACA,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,CAAA;QAC1B,CAAC;QACD,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM;YAC7B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC5B,IAAI,IAAI,EAAE,CAAC;gBACP,4DAA4D;gBAC5D,qBAAqB;gBACrB,OAAO,IAA2B,CAAA;YACtC,CAAC;YACD,MAAM,cAAc,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAoC,CAAA;YAChF,IAAI,CAAC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,CAAC,SAAS,CAAC,cAAc,EAAE,CAAA;gBACjD,CAAC;YACL,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACV,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,CAAA;YACjD,CAAC;SACJ,CAAA;IACL,CAAC;CACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {Plugin, PluginKey} from "prosemirror-state"
|
|
1
|
+
import {Plugin, PluginKey, type EditorState} from "prosemirror-state"
|
|
2
2
|
import {ReplaceAroundStep, ReplaceStep} from "prosemirror-transform"
|
|
3
|
+
import type {EditorView} from "prosemirror-view"
|
|
3
4
|
import type {Node} from "prosemirror-model"
|
|
5
|
+
import type {ModCitations} from "../citations/index.js"
|
|
4
6
|
|
|
5
7
|
const key = new PluginKey("citationRender")
|
|
6
8
|
|
|
@@ -8,7 +10,11 @@ interface CitationRenderState {
|
|
|
8
10
|
action: string | false
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
interface CitationRenderOptions {
|
|
14
|
+
editor: {mod: {citations: ModCitations}}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const citationRenderPlugin = (options: CitationRenderOptions) =>
|
|
12
18
|
new Plugin<CitationRenderState>({
|
|
13
19
|
key,
|
|
14
20
|
state: {
|
|
@@ -40,7 +46,7 @@ export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
|
40
46
|
;(tr.docs[index] as Node).nodesBetween(
|
|
41
47
|
step.from,
|
|
42
48
|
step.to,
|
|
43
|
-
node => {
|
|
49
|
+
(node: Node) => {
|
|
44
50
|
if (node.type.name === "citation") {
|
|
45
51
|
// A citation was replaced. We need to reset
|
|
46
52
|
action = "reset"
|
|
@@ -54,7 +60,7 @@ export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
|
54
60
|
)
|
|
55
61
|
}
|
|
56
62
|
if (step.slice?.content) {
|
|
57
|
-
step.slice.content.descendants(node => {
|
|
63
|
+
step.slice.content.descendants((node: Node) => {
|
|
58
64
|
if (node.type.name === "citation") {
|
|
59
65
|
// A citation was added. We need to reset
|
|
60
66
|
action = "reset"
|
|
@@ -70,5 +76,28 @@ export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
|
70
76
|
})
|
|
71
77
|
return {action}
|
|
72
78
|
}
|
|
79
|
+
},
|
|
80
|
+
view(_view: EditorView): {update: (view: EditorView, prevState: EditorState) => void; destroy: () => void} {
|
|
81
|
+
options.editor.mod.citations.resetCitations()
|
|
82
|
+
return {
|
|
83
|
+
update: (view: EditorView, _prevState: EditorState) => {
|
|
84
|
+
const stateAction = key.getState(view.state) as CitationRenderState | undefined
|
|
85
|
+
const action = stateAction?.action
|
|
86
|
+
if (action === "reset") {
|
|
87
|
+
options.editor.mod.citations.resetCitations()
|
|
88
|
+
const tr = view.state.tr.setMeta(key, {action: false})
|
|
89
|
+
view.dispatch(tr)
|
|
90
|
+
} else if (action === "numbers") {
|
|
91
|
+
options.editor.mod.citations.footnoteNumberOverride()
|
|
92
|
+
const tr = view.state.tr.setMeta(key, {action: false})
|
|
93
|
+
view.dispatch(tr)
|
|
94
|
+
} else if (view.dom.querySelector(".citation:empty")) {
|
|
95
|
+
options.editor.mod.citations.resetCitations()
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
destroy: () => {
|
|
99
|
+
options.editor.mod.citations.resetCitations()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
73
102
|
}
|
|
74
103
|
})
|