@manuscripts/body-editor 3.5.19 → 3.6.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.
@@ -67,9 +67,19 @@ const addToStart = (state, dispatch) => {
67
67
  exports.addToStart = addToStart;
68
68
  const markActive = (type) => (state) => {
69
69
  const { from, $from, to, empty } = state.selection;
70
+ let hasMark = false;
71
+ state.doc.nodesBetween(from, to, (node) => {
72
+ if (node.isText) {
73
+ node.marks.forEach((m) => {
74
+ if (m.type === type && !(0, track_changes_utils_1.isDeleted)(m)) {
75
+ hasMark = true;
76
+ }
77
+ });
78
+ }
79
+ });
70
80
  return empty
71
81
  ? Boolean(type.isInSet(state.storedMarks || $from.marks()))
72
- : state.doc.rangeHasMark(from, to, type);
82
+ : state.doc.rangeHasMark(from, to, type) && hasMark;
73
83
  };
74
84
  exports.markActive = markActive;
75
85
  const isNodeSelection = (selection) => selection instanceof prosemirror_state_1.NodeSelection;
@@ -6,6 +6,7 @@ const transform_1 = require("@manuscripts/transform");
6
6
  const prosemirror_state_1 = require("prosemirror-state");
7
7
  const prosemirror_view_1 = require("prosemirror-view");
8
8
  const commands_1 = require("../commands");
9
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
9
10
  const selection_1 = require("../selection");
10
11
  exports.selectedSuggestionKey = new prosemirror_state_1.PluginKey('selected-suggestion');
11
12
  const EMPTY = {
@@ -29,10 +30,12 @@ exports.default = () => {
29
30
  const buildPluginState = (state) => {
30
31
  const selection = state.selection;
31
32
  const changes = (0, selection_1.getSelectionChangeGroup)(state);
32
- if (changes) {
33
+ if (changes.length) {
33
34
  return buildGroupOfChangesDecoration(state.doc, changes);
34
35
  }
35
- const $pos = (0, commands_1.isTextSelection)(selection) ? selection.$cursor : selection.$to;
36
+ const $pos = (0, commands_1.isTextSelection)(selection) && selection.$cursor
37
+ ? selection.$cursor
38
+ : selection.$to;
36
39
  if (!$pos) {
37
40
  return EMPTY;
38
41
  }
@@ -64,7 +67,7 @@ const getEffectiveSelection = ($pos) => {
64
67
  return current;
65
68
  }
66
69
  const parent = $pos.parent;
67
- const child = parent.childBefore($pos.parentOffset);
70
+ const child = parent.childBefore(Math.max($pos.parentOffset - 1, 0));
68
71
  const node = child.node;
69
72
  if (node) {
70
73
  const from = $pos.start() + child.offset;
@@ -96,7 +99,14 @@ const buildNodeDecoration = (doc, selection) => {
96
99
  };
97
100
  const buildTextDecoration = (doc, selection) => {
98
101
  const node = selection.node;
99
- const suggestion = getTrackedMark(node)?.attrs.dataTracked;
102
+ let suggestion = getTrackedMark(node)?.attrs.dataTracked;
103
+ if (!suggestion) {
104
+ for (const mark of node.marks) {
105
+ if ((0, track_changes_utils_1.isTracked)(mark)) {
106
+ suggestion = mark.attrs.dataTracked[0];
107
+ }
108
+ }
109
+ }
100
110
  if (!suggestion) {
101
111
  return EMPTY;
102
112
  }
@@ -52,10 +52,12 @@ const getSelectionChangeGroup = (state) => {
52
52
  selection instanceof InlineNodesSelection) &&
53
53
  selection.$from;
54
54
  if ($pos) {
55
- return track_changes_plugin_1.trackChangesPluginKey
55
+ return (track_changes_plugin_1.trackChangesPluginKey
56
56
  .getState(state)
57
- ?.changeSet.groupChanges.find((c) => isPositionAtRange(c, $pos.pos));
57
+ ?.changeSet.groupChanges.find((c) => isPositionAtRange(c, $pos.pos)) ||
58
+ []);
58
59
  }
60
+ return [];
59
61
  };
60
62
  exports.getSelectionChangeGroup = getSelectionChangeGroup;
61
63
  const isPositionAtRange = (changes, pos) => (changes.length > 1 ||
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '3.5.19';
4
+ exports.VERSION = '3.6.0';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -62,9 +62,19 @@ export const addToStart = (state, dispatch) => {
62
62
  };
63
63
  export const markActive = (type) => (state) => {
64
64
  const { from, $from, to, empty } = state.selection;
65
+ let hasMark = false;
66
+ state.doc.nodesBetween(from, to, (node) => {
67
+ if (node.isText) {
68
+ node.marks.forEach((m) => {
69
+ if (m.type === type && !isDeleted(m)) {
70
+ hasMark = true;
71
+ }
72
+ });
73
+ }
74
+ });
65
75
  return empty
66
76
  ? Boolean(type.isInSet(state.storedMarks || $from.marks()))
67
- : state.doc.rangeHasMark(from, to, type);
77
+ : state.doc.rangeHasMark(from, to, type) && hasMark;
68
78
  };
69
79
  export const isNodeSelection = (selection) => selection instanceof NodeSelection;
70
80
  export const blockActive = (type) => (state) => {
@@ -3,6 +3,7 @@ import { schema, } from '@manuscripts/transform';
3
3
  import { Plugin, PluginKey } from 'prosemirror-state';
4
4
  import { Decoration, DecorationSet } from 'prosemirror-view';
5
5
  import { isTextSelection } from '../commands';
6
+ import { isTracked } from '../lib/track-changes-utils';
6
7
  import { getSelectionChangeGroup } from '../selection';
7
8
  export const selectedSuggestionKey = new PluginKey('selected-suggestion');
8
9
  const EMPTY = {
@@ -26,10 +27,12 @@ export default () => {
26
27
  const buildPluginState = (state) => {
27
28
  const selection = state.selection;
28
29
  const changes = getSelectionChangeGroup(state);
29
- if (changes) {
30
+ if (changes.length) {
30
31
  return buildGroupOfChangesDecoration(state.doc, changes);
31
32
  }
32
- const $pos = isTextSelection(selection) ? selection.$cursor : selection.$to;
33
+ const $pos = isTextSelection(selection) && selection.$cursor
34
+ ? selection.$cursor
35
+ : selection.$to;
33
36
  if (!$pos) {
34
37
  return EMPTY;
35
38
  }
@@ -61,7 +64,7 @@ const getEffectiveSelection = ($pos) => {
61
64
  return current;
62
65
  }
63
66
  const parent = $pos.parent;
64
- const child = parent.childBefore($pos.parentOffset);
67
+ const child = parent.childBefore(Math.max($pos.parentOffset - 1, 0));
65
68
  const node = child.node;
66
69
  if (node) {
67
70
  const from = $pos.start() + child.offset;
@@ -93,7 +96,14 @@ const buildNodeDecoration = (doc, selection) => {
93
96
  };
94
97
  const buildTextDecoration = (doc, selection) => {
95
98
  const node = selection.node;
96
- const suggestion = getTrackedMark(node)?.attrs.dataTracked;
99
+ let suggestion = getTrackedMark(node)?.attrs.dataTracked;
100
+ if (!suggestion) {
101
+ for (const mark of node.marks) {
102
+ if (isTracked(mark)) {
103
+ suggestion = mark.attrs.dataTracked[0];
104
+ }
105
+ }
106
+ }
97
107
  if (!suggestion) {
98
108
  return EMPTY;
99
109
  }
@@ -47,10 +47,12 @@ export const getSelectionChangeGroup = (state) => {
47
47
  selection instanceof InlineNodesSelection) &&
48
48
  selection.$from;
49
49
  if ($pos) {
50
- return trackChangesPluginKey
50
+ return (trackChangesPluginKey
51
51
  .getState(state)
52
- ?.changeSet.groupChanges.find((c) => isPositionAtRange(c, $pos.pos));
52
+ ?.changeSet.groupChanges.find((c) => isPositionAtRange(c, $pos.pos)) ||
53
+ []);
53
54
  }
55
+ return [];
54
56
  };
55
57
  const isPositionAtRange = (changes, pos) => (changes.length > 1 ||
56
58
  changes[0].dataTracked.operation === CHANGE_OPERATION.structure) &&
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.5.19';
1
+ export const VERSION = '3.6.0';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -14,14 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { TrackedAttrs } from '@manuscripts/track-changes-plugin';
17
- import { Attrs, Fragment, Node as ProsemirrorNode } from 'prosemirror-model';
18
- export declare function isDeleted(node: ProsemirrorNode): boolean;
17
+ import { Attrs, Fragment, Mark, Node as ProsemirrorNode } from 'prosemirror-model';
18
+ export declare function isDeleted(node: ProsemirrorNode | Mark): boolean;
19
19
  export declare function isShadowDelete(node: ProsemirrorNode): boolean;
20
20
  export declare function isPendingInsert(node: ProsemirrorNode): boolean;
21
21
  export declare function isPending(node: ProsemirrorNode): boolean;
22
22
  export declare function isPendingSetAttrs(node: ProsemirrorNode): boolean;
23
23
  export declare function getChangeClasses(dataTracked?: TrackedAttrs[]): string[];
24
- export declare function isTracked(node: ProsemirrorNode): boolean;
24
+ export declare function isTracked(node: ProsemirrorNode | Mark): boolean;
25
25
  export declare const getAttrsTrackingButton: (changeID: string) => HTMLButtonElement;
26
26
  export declare function isHidden(node: ProsemirrorNode): boolean;
27
27
  export declare function isDeletedText(node: ProsemirrorNode): boolean;
@@ -22,5 +22,5 @@ export declare class NodesSelection extends NodeSelection {
22
22
  constructor($from: ResolvedPos, $to: ResolvedPos);
23
23
  toJSON(): NodesSelectionJSON;
24
24
  }
25
- export declare const getSelectionChangeGroup: (state: ManuscriptEditorState) => TrackedChange[] | undefined;
25
+ export declare const getSelectionChangeGroup: (state: ManuscriptEditorState) => TrackedChange[];
26
26
  export {};
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.5.19";
1
+ export declare const VERSION = "3.6.0";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "3.5.19",
4
+ "version": "3.6.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -40,8 +40,8 @@
40
40
  "@iarna/word-count": "1.1.2",
41
41
  "@manuscripts/json-schema": "2.2.12",
42
42
  "@manuscripts/style-guide": "3.3.2",
43
- "@manuscripts/track-changes-plugin": "2.0.13",
44
- "@manuscripts/transform": "4.2.20",
43
+ "@manuscripts/track-changes-plugin": "2.1.0",
44
+ "@manuscripts/transform": "4.3.0",
45
45
  "@popperjs/core": "2.11.8",
46
46
  "citeproc": "2.4.63",
47
47
  "codemirror": "5.65.19",
@@ -975,7 +975,8 @@ figure .selected-suggestion {
975
975
  background-color: transparent !important;
976
976
  }
977
977
 
978
- .selected-suggestion[data-track-status='pending'] .block:not(.box-element):not(.trans-abstract),
978
+ .selected-suggestion[data-track-status='pending']
979
+ .block:not(.box-element):not(.trans-abstract),
979
980
  .block:has(figure.selected-suggestion),
980
981
  figure.block:has(.equation.selected-suggestion) {
981
982
  box-shadow: inset 6px 0 0 black, inset 9px 0 0 lightgray;
@@ -1042,7 +1043,7 @@ figure.block:has(.equation.selected-suggestion) {
1042
1043
  }
1043
1044
 
1044
1045
  .selected-suggestion[data-track-status='pending'][data-track-op='delete']
1045
- .block:not(.box-element):not(.trans-abstract) {
1046
+ .block:not(.box-element):not(.trans-abstract) {
1046
1047
  box-shadow: inset 6px 0 0 var(--deleted-color),
1047
1048
  inset 9px 0 0 var(--deleted-pending-bg-color) !important;
1048
1049
  animation: fadeOutBackground 3s forwards;
@@ -1050,7 +1051,10 @@ figure.block:has(.equation.selected-suggestion) {
1050
1051
  }
1051
1052
 
1052
1053
  /* Updated Block */
1053
- .tracking-visible .ProseMirror [data-track-op='set_attrs'] .block:not(.trans-abstract),
1054
+ .tracking-visible
1055
+ .ProseMirror
1056
+ [data-track-op='set_attrs']
1057
+ .block:not(.trans-abstract),
1054
1058
  .tracking-visible .block:has(figure[data-track-op='set_attrs']),
1055
1059
  .tracking-visible figure.block:has(.equation.set_attrs),
1056
1060
  .tracking-visible
@@ -1067,7 +1071,9 @@ figure.block:has(.equation.selected-suggestion) {
1067
1071
  box-shadow: inset 3px 0 0 var(--updated-border-color);
1068
1072
  }
1069
1073
 
1070
- .tracking-visible .selected-suggestion[data-track-op='set_attrs'] .block:not(.trans-abstract),
1074
+ .tracking-visible
1075
+ .selected-suggestion[data-track-op='set_attrs']
1076
+ .block:not(.trans-abstract),
1071
1077
  .tracking-visible
1072
1078
  .block:has(figure.selected-suggestion[data-track-op='set_attrs']),
1073
1079
  .tracking-visible .selected-suggestion[data-track-op='node_split'] .block,
@@ -1147,6 +1153,26 @@ figure.block:has(.equation.selected-suggestion) {
1147
1153
  border-color: var(--updated-border-color);
1148
1154
  }
1149
1155
 
1156
+ b[data-track-status='pending'][data-track-op='insert'],
1157
+ i[data-track-status='pending'][data-track-op='insert'],
1158
+ sup[data-track-status='pending'][data-track-op='insert'],
1159
+ sub[data-track-status='pending'][data-track-op='insert'],
1160
+ u[data-track-status='pending'][data-track-op='insert'],
1161
+ s[data-track-status='pending'][data-track-op='insert'] {
1162
+ background: var(--inserted-pending-bg-color);
1163
+ color: var(--inserted-pending-color);
1164
+ }
1165
+
1166
+ b[data-track-status='pending'][data-track-op='delete'],
1167
+ i[data-track-status='pending'][data-track-op='delete'],
1168
+ sup[data-track-status='pending'][data-track-op='delete'],
1169
+ sub[data-track-status='pending'][data-track-op='delete'],
1170
+ u[data-track-status='pending'][data-track-op='delete'],
1171
+ s[data-track-status='pending'][data-track-op='delete'] {
1172
+ background: var(--deleted-pending-bg-color);
1173
+ color: var(--deleted-color);
1174
+ }
1175
+
1150
1176
  /* Needed for the snapshot comparison */
1151
1177
  .tracking-visible
1152
1178
  .block-list
@@ -1582,7 +1608,7 @@ th:hover > .table-context-menu-button,
1582
1608
  border: 1px solid #f2f2f2;
1583
1609
  box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.12);
1584
1610
  background-color: #ffffff;
1585
-
1611
+
1586
1612
  position: absolute;
1587
1613
  top: -8px;
1588
1614
  right: -8px;
@@ -1668,7 +1694,8 @@ th:hover > .table-context-menu-button,
1668
1694
  margin-bottom: 30px;
1669
1695
  }
1670
1696
 
1671
- .hero-image-container, .attachments-container {
1697
+ .hero-image-container,
1698
+ .attachments-container {
1672
1699
  border: 1px solid #c9c9c9;
1673
1700
  border-radius: 4px;
1674
1701
  background: #ffffff;
@@ -1812,7 +1839,7 @@ th:hover > .table-context-menu-button,
1812
1839
  }
1813
1840
  .ProseMirror .abstracts .add-translation-text {
1814
1841
  font-size: 14px;
1815
- color:#353535
1842
+ color: #353535;
1816
1843
  }
1817
1844
  .ProseMirror .abstracts .add-translation-container .add-button {
1818
1845
  margin: 0;
@@ -1838,7 +1865,7 @@ th:hover > .table-context-menu-button,
1838
1865
  display: flex;
1839
1866
  align-items: center;
1840
1867
  font-size: 14px;
1841
- color: #6E6E6E;
1868
+ color: #6e6e6e;
1842
1869
  cursor: pointer;
1843
1870
  }
1844
1871
  .abstracts-language-dropdown {
@@ -1846,7 +1873,7 @@ th:hover > .table-context-menu-button,
1846
1873
  top: -86px !important;
1847
1874
  }
1848
1875
 
1849
- .ProseMirror .block-trans_abstract p.empty-node[data-placeholder] {
1876
+ .ProseMirror .block-trans_abstract p.empty-node[data-placeholder] {
1850
1877
  font-style: italic;
1851
1878
  color: #c9c9c9;
1852
1879
  margin: 0;
@@ -1930,7 +1957,7 @@ th:hover > .table-context-menu-button,
1930
1957
  cursor: pointer;
1931
1958
  }
1932
1959
 
1933
- .attachments-container .attachment-header {
1960
+ .attachments-container .attachment-header {
1934
1961
  display: flex;
1935
1962
  align-items: center;
1936
1963
  margin-bottom: 12px;
@@ -1978,11 +2005,11 @@ th:hover > .table-context-menu-button,
1978
2005
  margin-bottom: 12px;
1979
2006
  }
1980
2007
 
1981
-
1982
- .block-attachments:has(.attachment-item:empty), .block-attachments.empty-node {
2008
+ .block-attachments:has(.attachment-item:empty),
2009
+ .block-attachments.empty-node {
1983
2010
  display: none !important;
1984
2011
  }
1985
2012
 
1986
2013
  .ProseMirror a.link:empty::before {
1987
- content: "\00a0";
2014
+ content: '\00a0';
1988
2015
  }