@manuscripts/body-editor 1.7.20 → 1.7.21

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.
@@ -26,6 +26,7 @@ const prosemirror_transform_1 = require("prosemirror-transform");
26
26
  const prosemirror_utils_1 = require("prosemirror-utils");
27
27
  const list_1 = require("./keys/list");
28
28
  const helpers_1 = require("./lib/helpers");
29
+ const track_changes_utils_1 = require("./lib/track-changes-utils");
29
30
  const utils_1 = require("./lib/utils");
30
31
  const comment_annotation_1 = require("./plugins/comment_annotation");
31
32
  const highlight_1 = require("./plugins/highlight");
@@ -737,10 +738,12 @@ const insertTableFootnote = (node, position, state, dispatch) => {
737
738
  const tr = state.tr;
738
739
  tr.insert(insertedAt, inlineFootnoteNode);
739
740
  let insertionPos;
740
- const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element);
741
- if (footnotesElement.length) {
742
- const pos = footnotesElement[0].pos;
743
- insertionPos = position + pos + footnotesElement[0].node.nodeSize + 1;
741
+ const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element).pop();
742
+ if (footnotesElement &&
743
+ !(0, track_changes_utils_1.isDeleted)(footnotesElement.node) &&
744
+ !(0, track_changes_utils_1.isRejectedInsert)(footnotesElement.node)) {
745
+ const pos = footnotesElement.pos;
746
+ insertionPos = position + pos + footnotesElement.node.nodeSize + 1;
744
747
  tr.insert(insertionPos, footnote);
745
748
  }
746
749
  else {
@@ -25,6 +25,7 @@ const prosemirror_utils_1 = require("prosemirror-utils");
25
25
  const commands_1 = require("../commands");
26
26
  const ReactSubView_1 = __importDefault(require("../views/ReactSubView"));
27
27
  const popper_1 = require("./popper");
28
+ const track_changes_utils_1 = require("./track-changes-utils");
28
29
  const popper = new popper_1.PopperManager();
29
30
  const listTypes = [transform_1.schema.nodes.ordered_list, transform_1.schema.nodes.bullet_list];
30
31
  const readonlyTypes = [transform_1.schema.nodes.keywords, transform_1.schema.nodes.bibliography_element];
@@ -186,14 +187,16 @@ class ContextMenu {
186
187
  if (isInTable) {
187
188
  menu.appendChild(this.createMenuSection((section) => {
188
189
  section.appendChild(this.createMenuItem('Add Reference Note', () => {
189
- var _a;
190
- const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element);
191
- if (!footnotesElement.length) {
190
+ var _a, _b;
191
+ const footnotesElement = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
192
+ if (!footnotesElement ||
193
+ (0, track_changes_utils_1.isDeleted)(footnotesElement) ||
194
+ (0, track_changes_utils_1.isRejectedInsert)(footnotesElement)) {
192
195
  const { state, dispatch } = this.view;
193
196
  (0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
194
197
  }
195
198
  else {
196
- const footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElement[0].node, transform_1.schema.nodes.footnote).map((nodeWithPos) => {
199
+ const footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElement, transform_1.schema.nodes.footnote).map((nodeWithPos) => {
197
200
  return nodeWithPos.node;
198
201
  });
199
202
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
@@ -225,7 +228,7 @@ class ContextMenu {
225
228
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
226
229
  },
227
230
  }, this.node, this.getPos, this.view, 'table-footnote-editor');
228
- (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
231
+ (_b = this.props) === null || _b === void 0 ? void 0 : _b.popper.show(targetDom.node, popperContainer, 'bottom-end');
229
232
  }
230
233
  }
231
234
  }));
@@ -132,10 +132,10 @@ exports.default = () => {
132
132
  }
133
133
  }
134
134
  if (node.type === transform_1.schema.nodes.footnotes_element) {
135
- decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
136
- class: 'footnote-element',
137
- }));
138
135
  if ((parent === null || parent === void 0 ? void 0 : parent.type) === transform_1.schema.nodes.table_element_footer) {
136
+ decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
137
+ class: 'table-footnotes-element',
138
+ }));
139
139
  tableInlineFootnoteIds = (0, footnotes_utils_1.findTableInlineFootnoteIds)(state.doc.resolve(pos));
140
140
  }
141
141
  else {
@@ -18,7 +18,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.FootnoteView = void 0;
21
+ exports.setTCClasses = exports.FootnoteView = void 0;
22
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
22
23
  const block_view_1 = __importDefault(require("./block_view"));
23
24
  const creators_1 = require("./creators");
24
25
  class FootnoteView extends block_view_1.default {
@@ -28,4 +29,13 @@ class FootnoteView extends block_view_1.default {
28
29
  }
29
30
  }
30
31
  exports.FootnoteView = FootnoteView;
31
- exports.default = (0, creators_1.createNodeOrElementView)(FootnoteView, 'div');
32
+ const setTCClasses = (node, dom) => {
33
+ const dataTracked = node.attrs.dataTracked;
34
+ if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
35
+ const lastChange = dataTracked[dataTracked.length - 1];
36
+ const changeClasses = (0, track_changes_utils_1.getChangeClasses)([lastChange]);
37
+ dom.classList.add(...changeClasses);
38
+ }
39
+ };
40
+ exports.setTCClasses = setTCClasses;
41
+ exports.default = (0, creators_1.createNodeOrElementView)(FootnoteView, 'div', exports.setTCClasses);
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const creators_1 = require("./creators");
19
19
  const editable_block_1 = require("./editable_block");
20
20
  const footnote_1 = require("./footnote");
21
- exports.default = (0, creators_1.createNodeOrElementView)((0, editable_block_1.EditableBlock)(footnote_1.FootnoteView), 'div');
21
+ exports.default = (0, creators_1.createNodeOrElementView)((0, editable_block_1.EditableBlock)(footnote_1.FootnoteView), 'div', footnote_1.setTCClasses);
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.FootnotesElementView = void 0;
22
22
  const block_view_1 = __importDefault(require("./block_view"));
23
23
  const creators_1 = require("./creators");
24
+ const footnote_1 = require("./footnote");
24
25
  class FootnotesElementView extends block_view_1.default {
25
26
  constructor() {
26
27
  super(...arguments);
@@ -37,4 +38,4 @@ class FootnotesElementView extends block_view_1.default {
37
38
  }
38
39
  }
39
40
  exports.FootnotesElementView = FootnotesElementView;
40
- exports.default = (0, creators_1.createNodeOrElementView)(FootnotesElementView, 'div');
41
+ exports.default = (0, creators_1.createNodeOrElementView)(FootnotesElementView, 'div', footnote_1.setTCClasses);
@@ -17,5 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const creators_1 = require("./creators");
19
19
  const editable_block_1 = require("./editable_block");
20
+ const footnote_1 = require("./footnote");
20
21
  const footnotes_element_1 = require("./footnotes_element");
21
- exports.default = (0, creators_1.createNodeOrElementView)((0, editable_block_1.EditableBlock)(footnotes_element_1.FootnotesElementView), 'div');
22
+ exports.default = (0, creators_1.createNodeOrElementView)((0, editable_block_1.EditableBlock)(footnotes_element_1.FootnotesElementView), 'div', footnote_1.setTCClasses);
@@ -16,6 +16,7 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.InlineFootnoteView = void 0;
19
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
19
20
  const base_node_view_1 = require("./base_node_view");
20
21
  const creators_1 = require("./creators");
21
22
  class InlineFootnoteView extends base_node_view_1.BaseNodeView {
@@ -26,6 +27,10 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
26
27
  };
27
28
  this.updateContents = () => {
28
29
  this.setDomAttrs(this.node, this.dom);
30
+ this.dom.className = [
31
+ 'footnote',
32
+ ...(0, track_changes_utils_1.getChangeClasses)(this.node.attrs.dataTracked),
33
+ ].join(' ');
29
34
  };
30
35
  this.initialise = () => {
31
36
  this.dom = this.createDOM();
@@ -23,6 +23,7 @@ import { findWrapping } from 'prosemirror-transform';
23
23
  import { findChildrenByType, findParentNodeOfType, } from 'prosemirror-utils';
24
24
  import { skipCommandTracking } from './keys/list';
25
25
  import { isNodeOfType, nearestAncestor } from './lib/helpers';
26
+ import { isDeleted, isRejectedInsert } from './lib/track-changes-utils';
26
27
  import { findParentNodeWithId, getChildOfType } from './lib/utils';
27
28
  import { commentAnnotation } from './plugins/comment_annotation';
28
29
  import { highlightKey, SET_COMMENT } from './plugins/highlight';
@@ -700,10 +701,12 @@ export const insertTableFootnote = (node, position, state, dispatch) => {
700
701
  const tr = state.tr;
701
702
  tr.insert(insertedAt, inlineFootnoteNode);
702
703
  let insertionPos;
703
- const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element);
704
- if (footnotesElement.length) {
705
- const pos = footnotesElement[0].pos;
706
- insertionPos = position + pos + footnotesElement[0].node.nodeSize + 1;
704
+ const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element).pop();
705
+ if (footnotesElement &&
706
+ !isDeleted(footnotesElement.node) &&
707
+ !isRejectedInsert(footnotesElement.node)) {
708
+ const pos = footnotesElement.pos;
709
+ insertionPos = position + pos + footnotesElement.node.nodeSize + 1;
707
710
  tr.insert(insertionPos, footnote);
708
711
  }
709
712
  else {
@@ -19,6 +19,7 @@ import { findChildrenByType, hasParentNodeOfType } from 'prosemirror-utils';
19
19
  import { addComment, createBlock, insertGeneralFootnote, insertTableFootnote, } from '../commands';
20
20
  import ReactSubView from '../views/ReactSubView';
21
21
  import { PopperManager } from './popper';
22
+ import { isDeleted, isRejectedInsert } from './track-changes-utils';
22
23
  const popper = new PopperManager();
23
24
  const listTypes = [schema.nodes.ordered_list, schema.nodes.bullet_list];
24
25
  const readonlyTypes = [schema.nodes.keywords, schema.nodes.bibliography_element];
@@ -179,14 +180,16 @@ export class ContextMenu {
179
180
  if (isInTable) {
180
181
  menu.appendChild(this.createMenuSection((section) => {
181
182
  section.appendChild(this.createMenuItem('Add Reference Note', () => {
182
- var _a;
183
- const footnotesElement = findChildrenByType(this.node, schema.nodes.footnotes_element);
184
- if (!footnotesElement.length) {
183
+ var _a, _b;
184
+ const footnotesElement = (_a = findChildrenByType(this.node, schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
185
+ if (!footnotesElement ||
186
+ isDeleted(footnotesElement) ||
187
+ isRejectedInsert(footnotesElement)) {
185
188
  const { state, dispatch } = this.view;
186
189
  insertTableFootnote(this.node, this.getPos(), state, dispatch);
187
190
  }
188
191
  else {
189
- const footnotes = findChildrenByType(footnotesElement[0].node, schema.nodes.footnote).map((nodeWithPos) => {
192
+ const footnotes = findChildrenByType(footnotesElement, schema.nodes.footnote).map((nodeWithPos) => {
190
193
  return nodeWithPos.node;
191
194
  });
192
195
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
@@ -218,7 +221,7 @@ export class ContextMenu {
218
221
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
219
222
  },
220
223
  }, this.node, this.getPos, this.view, 'table-footnote-editor');
221
- (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
224
+ (_b = this.props) === null || _b === void 0 ? void 0 : _b.popper.show(targetDom.node, popperContainer, 'bottom-end');
222
225
  }
223
226
  }
224
227
  }));
@@ -127,10 +127,10 @@ export default () => {
127
127
  }
128
128
  }
129
129
  if (node.type === schema.nodes.footnotes_element) {
130
- decorations.push(Decoration.node(pos, pos + node.nodeSize, {
131
- class: 'footnote-element',
132
- }));
133
130
  if ((parent === null || parent === void 0 ? void 0 : parent.type) === schema.nodes.table_element_footer) {
131
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, {
132
+ class: 'table-footnotes-element',
133
+ }));
134
134
  tableInlineFootnoteIds = findTableInlineFootnoteIds(state.doc.resolve(pos));
135
135
  }
136
136
  else {
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { getChangeClasses } from '../lib/track-changes-utils';
16
17
  import BlockView from './block_view';
17
18
  import { createNodeOrElementView } from './creators';
18
19
  export class FootnoteView extends BlockView {
@@ -21,4 +22,12 @@ export class FootnoteView extends BlockView {
21
22
  this.elementType = 'div';
22
23
  }
23
24
  }
24
- export default createNodeOrElementView(FootnoteView, 'div');
25
+ export const setTCClasses = (node, dom) => {
26
+ const dataTracked = node.attrs.dataTracked;
27
+ if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
28
+ const lastChange = dataTracked[dataTracked.length - 1];
29
+ const changeClasses = getChangeClasses([lastChange]);
30
+ dom.classList.add(...changeClasses);
31
+ }
32
+ };
33
+ export default createNodeOrElementView(FootnoteView, 'div', setTCClasses);
@@ -15,5 +15,5 @@
15
15
  */
16
16
  import { createNodeOrElementView } from './creators';
17
17
  import { EditableBlock } from './editable_block';
18
- import { FootnoteView } from './footnote';
19
- export default createNodeOrElementView(EditableBlock(FootnoteView), 'div');
18
+ import { FootnoteView, setTCClasses } from './footnote';
19
+ export default createNodeOrElementView(EditableBlock(FootnoteView), 'div', setTCClasses);
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import BlockView from './block_view';
17
17
  import { createNodeOrElementView } from './creators';
18
+ import { setTCClasses } from './footnote';
18
19
  export class FootnotesElementView extends BlockView {
19
20
  constructor() {
20
21
  super(...arguments);
@@ -30,4 +31,4 @@ export class FootnotesElementView extends BlockView {
30
31
  this.checkEditability();
31
32
  }
32
33
  }
33
- export default createNodeOrElementView(FootnotesElementView, 'div');
34
+ export default createNodeOrElementView(FootnotesElementView, 'div', setTCClasses);
@@ -15,5 +15,6 @@
15
15
  */
16
16
  import { createNodeOrElementView } from './creators';
17
17
  import { EditableBlock } from './editable_block';
18
+ import { setTCClasses } from './footnote';
18
19
  import { FootnotesElementView } from './footnotes_element';
19
- export default createNodeOrElementView(EditableBlock(FootnotesElementView), 'div');
20
+ export default createNodeOrElementView(EditableBlock(FootnotesElementView), 'div', setTCClasses);
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { getChangeClasses } from '../lib/track-changes-utils';
16
17
  import { BaseNodeView } from './base_node_view';
17
18
  import { createNodeView } from './creators';
18
19
  export class InlineFootnoteView extends BaseNodeView {
@@ -23,6 +24,10 @@ export class InlineFootnoteView extends BaseNodeView {
23
24
  };
24
25
  this.updateContents = () => {
25
26
  this.setDomAttrs(this.node, this.dom);
27
+ this.dom.className = [
28
+ 'footnote',
29
+ ...getChangeClasses(this.node.attrs.dataTracked),
30
+ ].join(' ');
26
31
  };
27
32
  this.initialise = () => {
28
33
  this.dom = this.createDOM();
@@ -13,10 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ManuscriptNode } from '@manuscripts/transform';
16
17
  import { BaseNodeProps } from './base_node_view';
17
18
  import BlockView from './block_view';
18
19
  export declare class FootnoteView<PropsType extends BaseNodeProps> extends BlockView<PropsType> {
19
20
  elementType: string;
20
21
  }
22
+ export declare const setTCClasses: (node: ManuscriptNode, dom: HTMLElement) => void;
21
23
  declare const _default: (props: BaseNodeProps) => import("../types").NodeViewCreator<FootnoteView<any>>;
22
24
  export default _default;
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": "1.7.20",
4
+ "version": "1.7.21",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -111,4 +111,4 @@
111
111
  "resolutions": {
112
112
  "@types/react": "^17.0.2"
113
113
  }
114
- }
114
+ }
package/styles/Editor.css CHANGED
@@ -944,18 +944,18 @@
944
944
  padding-top: 8px;
945
945
  }
946
946
 
947
- .ProseMirror .table-footer .footnote-element:not(:first-child)::before {
947
+ .ProseMirror .table-footnotes-element:not(:first-child)::before {
948
948
  content: '';
949
949
  border-bottom: 1px dashed #C9C9C9;
950
950
  display: block;
951
951
  margin-bottom: 8px;
952
952
  }
953
953
 
954
- .ProseMirror .table-footer .footnote-element {
954
+ .ProseMirror .table-footnotes-element {
955
955
  counter-reset: table_footnote;
956
956
  }
957
957
 
958
- .ProseMirror .table-footer .footnote-element > div:not(:has(.unctied-table-footnote)) p::before {
958
+ .ProseMirror .table-footnotes-element > div:not(:has(.unctied-table-footnote)) p::before {
959
959
  counter-increment: table_footnote;
960
960
  content: counter(table_footnote);
961
961
  display: inline-block;
@@ -978,7 +978,7 @@
978
978
  .table-footer > div > p {
979
979
  padding-bottom: 10px;
980
980
  }
981
- .ProseMirror .table-footer .footnote-element .footnote-selected {
981
+ .ProseMirror .table-footnotes-element .footnote-selected {
982
982
  border: 1px solid #bce7f6;
983
983
  }
984
984
  .table-footer > div:has(> p.footnote-selected) > p {
@@ -998,7 +998,7 @@
998
998
  cursor: pointer;
999
999
  }
1000
1000
 
1001
- .ProseMirror .footnote-element > div:has(.unctied-table-footnote) {
1001
+ .ProseMirror .table-footnotes-element > div:has(.unctied-table-footnote) {
1002
1002
  position: relative;
1003
1003
  }
1004
1004