@fiduswriter/editor 0.1.35 → 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.
- package/dist/state_plugins/citation_render.d.ts +9 -3
- package/dist/state_plugins/citation_render.d.ts.map +1 -1
- package/dist/state_plugins/citation_render.js +28 -3
- package/dist/state_plugins/citation_render.js.map +1 -1
- package/dist/state_plugins/jump_hidden_nodes.d.ts.map +1 -1
- package/dist/state_plugins/jump_hidden_nodes.js +21 -34
- package/dist/state_plugins/jump_hidden_nodes.js.map +1 -1
- package/package.json +1 -1
- package/src/state_plugins/citation_render.ts +33 -4
- package/src/state_plugins/jump_hidden_nodes.ts +25 -36
|
@@ -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;QAC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sBAAsB,EAAE,CAAA;oBACrD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAA;oBACtD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;gBACrB,CAAC;qBAAM,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACnD,OAAO,CAAC,MAAM,CAAC,GAAG,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jump_hidden_nodes.d.ts","sourceRoot":"","sources":["../../src/state_plugins/jump_hidden_nodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAA2B,MAAM,mBAAmB,CAAA;AAmBlE,eAAO,MAAM,qBAAqB,GAAI,UAAU;IAAC,MAAM,EAAE,OAAO,CAAA;CAAC,
|
|
1
|
+
{"version":3,"file":"jump_hidden_nodes.d.ts","sourceRoot":"","sources":["../../src/state_plugins/jump_hidden_nodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAA2B,MAAM,mBAAmB,CAAA;AAmBlE,eAAO,MAAM,qBAAqB,GAAI,UAAU;IAAC,MAAM,EAAE,OAAO,CAAA;CAAC,gBAmC3D,CAAA"}
|
|
@@ -16,45 +16,32 @@ const key = new PluginKey("jump-hidden-nodes");
|
|
|
16
16
|
export const jumpHiddenNodesPlugin = (_options) => new Plugin({
|
|
17
17
|
key,
|
|
18
18
|
appendTransaction: (trs, oldState, state) => {
|
|
19
|
-
if (state.selection.
|
|
19
|
+
if (!state.selection.empty) {
|
|
20
20
|
// Only applies to collapsed selection
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
movedLeft = true;
|
|
23
|
+
const selectionSet = trs.find(tr => tr.selectionSet);
|
|
24
|
+
if (selectionSet && posHidden(state.selection.$from)) {
|
|
25
|
+
const dir = state.selection.from > oldState.selection.from ? 1 : -1;
|
|
26
|
+
let newPos = state.selection.from, hidden = true, validTextSelection = false, validGapCursor = false;
|
|
27
|
+
let $pos = state.selection.$from;
|
|
28
|
+
while (hidden || (!validGapCursor && !validTextSelection)) {
|
|
29
|
+
newPos += dir;
|
|
30
|
+
if (newPos === 0 || newPos === state.doc.nodeSize) {
|
|
31
|
+
// Could not find any valid position
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
$pos = state.doc.resolve(newPos);
|
|
35
|
+
validTextSelection = $pos.parent.inlineContent;
|
|
36
|
+
validGapCursor = GapCursor.valid($pos);
|
|
37
|
+
hidden = posHidden($pos);
|
|
39
38
|
}
|
|
39
|
+
const selection = validTextSelection
|
|
40
|
+
? new TextSelection($pos)
|
|
41
|
+
: new GapCursor($pos);
|
|
42
|
+
return state.tr.setSelection(selection);
|
|
40
43
|
}
|
|
41
|
-
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let tr = state.tr;
|
|
45
|
-
if ($pos.node().isTextblock &&
|
|
46
|
-
$pos.pos >= startPos &&
|
|
47
|
-
$pos.pos <= startPos) {
|
|
48
|
-
// Try to set text selection
|
|
49
|
-
tr = tr.setSelection(TextSelection.near($pos));
|
|
50
|
-
}
|
|
51
|
-
else if ($pos.pos !== startPos) {
|
|
52
|
-
tr = tr.setSelection(new GapCursor($pos));
|
|
53
|
-
}
|
|
54
|
-
if (trs[trs.length - 1].doc.eq(tr.doc)) {
|
|
55
|
-
return tr;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
44
|
+
return undefined;
|
|
58
45
|
}
|
|
59
46
|
});
|
|
60
47
|
//# sourceMappingURL=jump_hidden_nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jump_hidden_nodes.js","sourceRoot":"","sources":["../../src/state_plugins/jump_hidden_nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAGlE,MAAM,SAAS,GAAG,CAAC,IAAiB,EAAE,EAAE;IACpC,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACzB,IACI,IAAI,CAAC,KAAK,CAAC,MAAM;YACjB,CAAC,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACzD,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,EAC/C,CAAC;YACC,MAAM,GAAG,IAAI,CAAA;QACjB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAA2B,EAAE,EAAE,CACjE,IAAI,MAAM,CAAC;IACP,GAAG;IACH,iBAAiB,EAAE,CAAC,GAA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AAO,SAAS,CAAA;IACpB,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
|
})
|
|
@@ -22,46 +22,35 @@ export const jumpHiddenNodesPlugin = (_options: {editor: unknown}) =>
|
|
|
22
22
|
new Plugin({
|
|
23
23
|
key,
|
|
24
24
|
appendTransaction: (trs, oldState, state) => {
|
|
25
|
-
if (state.selection.
|
|
25
|
+
if (!state.selection.empty) {
|
|
26
26
|
// Only applies to collapsed selection
|
|
27
27
|
return
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$pos = state.doc.resolve(
|
|
45
|
-
|
|
29
|
+
const selectionSet = trs.find(tr => tr.selectionSet)
|
|
30
|
+
if (selectionSet && posHidden(state.selection.$from)) {
|
|
31
|
+
const dir =
|
|
32
|
+
state.selection.from > oldState.selection.from ? 1 : -1
|
|
33
|
+
let newPos = state.selection.from,
|
|
34
|
+
hidden = true,
|
|
35
|
+
validTextSelection = false,
|
|
36
|
+
validGapCursor = false
|
|
37
|
+
let $pos: ResolvedPos = state.selection.$from
|
|
38
|
+
while (hidden || (!validGapCursor && !validTextSelection)) {
|
|
39
|
+
newPos += dir
|
|
40
|
+
if (newPos === 0 || newPos === state.doc.nodeSize) {
|
|
41
|
+
// Could not find any valid position
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
$pos = state.doc.resolve(newPos)
|
|
45
|
+
validTextSelection = $pos.parent.inlineContent
|
|
46
|
+
validGapCursor = (GapCursor as any).valid($pos)
|
|
47
|
+
hidden = posHidden($pos)
|
|
46
48
|
}
|
|
49
|
+
const selection = validTextSelection
|
|
50
|
+
? new TextSelection($pos)
|
|
51
|
+
: new GapCursor($pos)
|
|
52
|
+
return state.tr.setSelection(selection)
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
let tr = state.tr
|
|
52
|
-
if (
|
|
53
|
-
$pos.node().isTextblock &&
|
|
54
|
-
$pos.pos >= startPos &&
|
|
55
|
-
$pos.pos <= startPos
|
|
56
|
-
) {
|
|
57
|
-
// Try to set text selection
|
|
58
|
-
tr = tr.setSelection(TextSelection.near($pos))
|
|
59
|
-
} else if ($pos.pos !== startPos) {
|
|
60
|
-
tr = tr.setSelection(new GapCursor($pos))
|
|
61
|
-
}
|
|
62
|
-
if (trs[trs.length - 1].doc.eq(tr.doc)) {
|
|
63
|
-
return tr
|
|
64
|
-
}
|
|
65
|
-
return
|
|
54
|
+
return undefined
|
|
66
55
|
}
|
|
67
56
|
})
|