@fiduswriter/editor 0.1.32 → 0.1.34
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 +1 -1
- package/dist/state_plugins/citation_render.d.ts.map +1 -1
- package/dist/state_plugins/citation_render.js +23 -11
- package/dist/state_plugins/citation_render.js.map +1 -1
- package/package.json +1 -1
- package/src/state_plugins/citation_render.ts +28 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citation_render.d.ts","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAY,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"citation_render.d.ts","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAY,MAAM,mBAAmB,CAAA;AAMnD,UAAU,mBAAmB;IACzB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAA;CACzB;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAU;IAAC,MAAM,EAAE,OAAO,CAAA;CAAC,gCA+D1D,CAAA"}
|
|
@@ -14,7 +14,11 @@ export const citationRenderPlugin = (_options) => new Plugin({
|
|
|
14
14
|
// of previous values
|
|
15
15
|
return meta;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const oldPluginState = key.getState(oldState);
|
|
18
|
+
if (!oldPluginState) {
|
|
19
|
+
return { action: false };
|
|
20
|
+
}
|
|
21
|
+
let { action } = oldPluginState;
|
|
18
22
|
if (action || tr.getMeta("settings")) {
|
|
19
23
|
return { action }; // We already need to reset the bibliography or another setting is used. Don't bother checking for more reasons to do so.
|
|
20
24
|
}
|
|
@@ -22,19 +26,27 @@ export const citationRenderPlugin = (_options) => new Plugin({
|
|
|
22
26
|
if (step instanceof ReplaceStep ||
|
|
23
27
|
step instanceof ReplaceAroundStep) {
|
|
24
28
|
if (step.from !== step.to) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
;
|
|
30
|
+
tr.docs[index].nodesBetween(step.from, step.to, node => {
|
|
31
|
+
if (node.type.name === "citation") {
|
|
32
|
+
// A citation was replaced. We need to reset
|
|
33
|
+
action = "reset";
|
|
34
|
+
}
|
|
35
|
+
else if (!action &&
|
|
36
|
+
node.type.name === "footnote") {
|
|
37
|
+
action = "numbers";
|
|
38
|
+
}
|
|
32
39
|
});
|
|
33
40
|
}
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
if (step.slice?.content) {
|
|
42
|
+
step.slice.content.descendants(node => {
|
|
36
43
|
if (node.type.name === "citation") {
|
|
37
|
-
|
|
44
|
+
// A citation was added. We need to reset
|
|
45
|
+
action = "reset";
|
|
46
|
+
}
|
|
47
|
+
else if (!action &&
|
|
48
|
+
node.type.name === "footnote") {
|
|
49
|
+
action = "numbers";
|
|
38
50
|
}
|
|
39
51
|
});
|
|
40
52
|
}
|
|
@@ -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,EAAC,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"citation_render.js","sourceRoot":"","sources":["../../src/state_plugins/citation_render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,uBAAuB,CAAA;AAGpE,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,gBAAgB,CAAC,CAAA;AAM3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,QAA2B,EAAE,EA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C,IAAI,CAAC,IAAI,KAAK,UAAU,EAC/B,CAAC;gCACC,MAAM,GAAG,SAAS,CAAA;4BACtB,CAAC;wBACL,CAAC,CACJ,CAAA;oBACL,CAAC;oBACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;wBACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;4BAClC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gCAChC,yCAAyC;gCACzC,MAAM,GAAG,OAAO,CAAA;4BACpB,CAAC;iCAAM,IACH,CAAC,MAAM;gCACP,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,EAC/B,CAAC;gCACC,MAAM,GAAG,SAAS,CAAA;4BACtB,CAAC;wBACL,CAAC,CAAC,CAAA;oBACN,CAAC;gBACL,CAAC;YACL,CAAC,CAAC,CAAA;YACF,OAAO,EAAC,MAAM,EAAC,CAAA;QACnB,CAAC;KACJ;CACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {Plugin, PluginKey} from "prosemirror-state"
|
|
2
2
|
import {ReplaceAroundStep, ReplaceStep} from "prosemirror-transform"
|
|
3
|
+
import type {Node} from "prosemirror-model"
|
|
3
4
|
|
|
4
5
|
const key = new PluginKey("citationRender")
|
|
5
6
|
|
|
6
7
|
interface CitationRenderState {
|
|
7
|
-
action:
|
|
8
|
+
action: string | false
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
@@ -21,7 +22,11 @@ export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
|
21
22
|
// of previous values
|
|
22
23
|
return meta as CitationRenderState
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
const oldPluginState = key.getState(oldState) as CitationRenderState | undefined
|
|
26
|
+
if (!oldPluginState) {
|
|
27
|
+
return {action: false}
|
|
28
|
+
}
|
|
29
|
+
let {action} = oldPluginState
|
|
25
30
|
|
|
26
31
|
if (action || tr.getMeta("settings")) {
|
|
27
32
|
return {action} // We already need to reset the bibliography or another setting is used. Don't bother checking for more reasons to do so.
|
|
@@ -32,29 +37,35 @@ export const citationRenderPlugin = (_options: {editor: unknown}) =>
|
|
|
32
37
|
step instanceof ReplaceAroundStep
|
|
33
38
|
) {
|
|
34
39
|
if (step.from !== step.to) {
|
|
35
|
-
|
|
36
|
-
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
37
|
-
tr.doc.nodesBetween(
|
|
38
|
-
newStart,
|
|
39
|
-
newEnd,
|
|
40
|
-
node => {
|
|
41
|
-
if (node.type.name === "citation") {
|
|
42
|
-
action = true
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
})
|
|
47
|
-
} else {
|
|
48
|
-
tr.doc.nodesBetween(
|
|
40
|
+
;(tr.docs[index] as Node).nodesBetween(
|
|
49
41
|
step.from,
|
|
50
42
|
step.to,
|
|
51
43
|
node => {
|
|
52
44
|
if (node.type.name === "citation") {
|
|
53
|
-
|
|
45
|
+
// A citation was replaced. We need to reset
|
|
46
|
+
action = "reset"
|
|
47
|
+
} else if (
|
|
48
|
+
!action &&
|
|
49
|
+
node.type.name === "footnote"
|
|
50
|
+
) {
|
|
51
|
+
action = "numbers"
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
)
|
|
57
55
|
}
|
|
56
|
+
if (step.slice?.content) {
|
|
57
|
+
step.slice.content.descendants(node => {
|
|
58
|
+
if (node.type.name === "citation") {
|
|
59
|
+
// A citation was added. We need to reset
|
|
60
|
+
action = "reset"
|
|
61
|
+
} else if (
|
|
62
|
+
!action &&
|
|
63
|
+
node.type.name === "footnote"
|
|
64
|
+
) {
|
|
65
|
+
action = "numbers"
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
})
|
|
60
71
|
return {action}
|