@manuscripts/body-editor 1.7.30 → 1.7.31-LEAN-3144-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.
@@ -727,22 +727,35 @@ const updateCommentAnnotationState = (state, dispatch) => {
727
727
  }
728
728
  };
729
729
  exports.updateCommentAnnotationState = updateCommentAnnotationState;
730
- const insertTableFootnote = (node, position, view) => {
730
+ const insertTableFootnote = (node, position, view, inlineFootnote) => {
731
731
  var _a;
732
732
  const { state, dispatch } = view;
733
+ const tr = state.tr;
733
734
  const footnote = state.schema.nodes.footnote.createAndFill({
734
735
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
735
736
  kind: 'footnote',
736
737
  });
737
738
  const insertedAt = state.selection.to;
738
- const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
739
- const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
740
- const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
741
- rids: [footnote.attrs.id],
742
- contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
743
- });
744
- const tr = state.tr;
745
- tr.insert(insertedAt, inlineFootnoteNode);
739
+ let footnoteIndex;
740
+ if (inlineFootnote) {
741
+ const contents = inlineFootnote.node.attrs.contents.split(',').map(Number);
742
+ footnoteIndex = Math.max(...contents) + 1;
743
+ tr.setNodeMarkup(inlineFootnote.pos, undefined, {
744
+ rids: [...inlineFootnote.node.attrs.rids, footnote.attrs.id],
745
+ contents: inlineFootnote.node.attrs.contents + ',' + footnoteIndex,
746
+ });
747
+ }
748
+ else {
749
+ const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
750
+ footnoteIndex =
751
+ inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length +
752
+ 1;
753
+ const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
754
+ rids: [footnote.attrs.id],
755
+ contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
756
+ });
757
+ tr.insert(insertedAt, inlineFootnoteNode);
758
+ }
746
759
  let insertionPos = position;
747
760
  const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element).pop();
748
761
  if (footnotesElement &&
@@ -198,9 +198,10 @@ class ContextMenu {
198
198
  else {
199
199
  const tablesFootnoteLabels = (0, footnotes_utils_1.buildTableFootnoteLabels)(this.node);
200
200
  const footnotesWithPos = (0, prosemirror_utils_1.findChildrenByType)(footnotesElementWithPos.node, transform_1.schema.nodes.footnote);
201
- const footnotes = footnotesWithPos.map((nodeWithPos) => ({
202
- node: nodeWithPos.node,
203
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
201
+ const footnotes = footnotesWithPos
202
+ .map(({ node }) => ({
203
+ node: node,
204
+ index: tablesFootnoteLabels.get(node.attrs.id),
204
205
  }));
205
206
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
206
207
  if (targetDom.node instanceof Element && this.props) {
@@ -14,16 +14,43 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
17
20
  Object.defineProperty(exports, "__esModule", { value: true });
18
21
  exports.InlineFootnoteView = void 0;
22
+ const style_guide_1 = require("@manuscripts/style-guide");
23
+ const transform_1 = require("@manuscripts/transform");
24
+ const prosemirror_utils_1 = require("prosemirror-utils");
25
+ const commands_1 = require("../commands");
19
26
  const track_changes_utils_1 = require("../lib/track-changes-utils");
27
+ const footnotes_utils_1 = require("../plugins/footnotes/footnotes-utils");
20
28
  const base_node_view_1 = require("./base_node_view");
21
29
  const creators_1 = require("./creators");
30
+ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
22
31
  class InlineFootnoteView extends base_node_view_1.BaseNodeView {
23
32
  constructor() {
24
33
  super(...arguments);
34
+ this.findParentTableElement = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(this.view.state.doc.resolve(this.getPos()), (node) => node.type === transform_1.schema.nodes.table_element);
25
35
  this.handleClick = () => {
26
- this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
36
+ if ((0, track_changes_utils_1.isDeleted)(this.node)) {
37
+ return;
38
+ }
39
+ const tableElement = this.findParentTableElement();
40
+ if (tableElement) {
41
+ const componentProps = {
42
+ notes: this.getNotes(tableElement),
43
+ onAdd: this.onAdd,
44
+ onInsert: this.onUpdate,
45
+ onCancel: this.destroy,
46
+ inlineFootnote: this.node,
47
+ };
48
+ this.popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.TableFootnotesSelector, componentProps, this.node, this.getPos, this.view, 'table-footnote-editor');
49
+ this.props.popper.show(this.dom, this.popperContainer, 'bottom-end');
50
+ }
51
+ else {
52
+ this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
53
+ }
27
54
  };
28
55
  this.updateContents = () => {
29
56
  this.setDomAttrs(this.node, this.dom);
@@ -42,6 +69,49 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
42
69
  this.createDOM = () => {
43
70
  return document.createElement('span');
44
71
  };
72
+ this.destroy = () => {
73
+ var _a;
74
+ this.props.popper.destroy();
75
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
76
+ };
77
+ this.getNotes = (tableElement) => {
78
+ var _a;
79
+ const footnotesElement = (_a = (0, prosemirror_utils_1.findChildrenByType)(tableElement.node, transform_1.schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
80
+ let footnotes = [];
81
+ if (footnotesElement) {
82
+ const tablesFootnoteLabels = (0, footnotes_utils_1.buildTableFootnoteLabels)(tableElement.node);
83
+ footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElement, transform_1.schema.nodes.footnote)
84
+ .map(({ node }) => ({
85
+ node: node,
86
+ index: tablesFootnoteLabels.get(node.attrs.id),
87
+ }));
88
+ }
89
+ return footnotes;
90
+ };
91
+ this.onAdd = () => {
92
+ const tableElement = this.findParentTableElement();
93
+ if (tableElement) {
94
+ (0, commands_1.insertTableFootnote)(tableElement.node, tableElement.pos, this.view, {
95
+ node: this.node,
96
+ pos: this.getPos(),
97
+ });
98
+ this.destroy();
99
+ }
100
+ };
101
+ this.onUpdate = (notes) => {
102
+ const contents = this.node.attrs.contents.split(',');
103
+ const rids = notes.map((note) => note.node.attrs.id);
104
+ const { tr } = this.view.state;
105
+ this.view.dispatch(rids.length
106
+ ? tr.setNodeMarkup(this.getPos(), undefined, {
107
+ rids,
108
+ contents: notes
109
+ .map(({ index }) => (index ? index : Math.max(...contents) + 1))
110
+ .join(),
111
+ })
112
+ : tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
113
+ this.destroy();
114
+ };
45
115
  }
46
116
  }
47
117
  exports.InlineFootnoteView = InlineFootnoteView;
@@ -690,22 +690,35 @@ export const updateCommentAnnotationState = (state, dispatch) => {
690
690
  dispatch(tr);
691
691
  }
692
692
  };
693
- export const insertTableFootnote = (node, position, view) => {
693
+ export const insertTableFootnote = (node, position, view, inlineFootnote) => {
694
694
  var _a;
695
695
  const { state, dispatch } = view;
696
+ const tr = state.tr;
696
697
  const footnote = state.schema.nodes.footnote.createAndFill({
697
698
  id: generateID(ObjectTypes.Footnote),
698
699
  kind: 'footnote',
699
700
  });
700
701
  const insertedAt = state.selection.to;
701
- const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
702
- const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
703
- const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
704
- rids: [footnote.attrs.id],
705
- contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
706
- });
707
- const tr = state.tr;
708
- tr.insert(insertedAt, inlineFootnoteNode);
702
+ let footnoteIndex;
703
+ if (inlineFootnote) {
704
+ const contents = inlineFootnote.node.attrs.contents.split(',').map(Number);
705
+ footnoteIndex = Math.max(...contents) + 1;
706
+ tr.setNodeMarkup(inlineFootnote.pos, undefined, {
707
+ rids: [...inlineFootnote.node.attrs.rids, footnote.attrs.id],
708
+ contents: inlineFootnote.node.attrs.contents + ',' + footnoteIndex,
709
+ });
710
+ }
711
+ else {
712
+ const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
713
+ footnoteIndex =
714
+ inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length +
715
+ 1;
716
+ const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
717
+ rids: [footnote.attrs.id],
718
+ contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
719
+ });
720
+ tr.insert(insertedAt, inlineFootnoteNode);
721
+ }
709
722
  let insertionPos = position;
710
723
  const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element).pop();
711
724
  if (footnotesElement &&
@@ -191,9 +191,10 @@ export class ContextMenu {
191
191
  else {
192
192
  const tablesFootnoteLabels = buildTableFootnoteLabels(this.node);
193
193
  const footnotesWithPos = findChildrenByType(footnotesElementWithPos.node, schema.nodes.footnote);
194
- const footnotes = footnotesWithPos.map((nodeWithPos) => ({
195
- node: nodeWithPos.node,
196
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
194
+ const footnotes = footnotesWithPos
195
+ .map(({ node }) => ({
196
+ node: node,
197
+ index: tablesFootnoteLabels.get(node.attrs.id),
197
198
  }));
198
199
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
199
200
  if (targetDom.node instanceof Element && this.props) {
@@ -13,14 +13,38 @@
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
+ import { TableFootnotesSelector, } from '@manuscripts/style-guide';
17
+ import { schema, } from '@manuscripts/transform';
18
+ import { findChildrenByType, findParentNodeClosestToPos, } from 'prosemirror-utils';
19
+ import { insertTableFootnote } from '../commands';
20
+ import { getChangeClasses, isDeleted, } from '../lib/track-changes-utils';
21
+ import { buildTableFootnoteLabels } from '../plugins/footnotes/footnotes-utils';
17
22
  import { BaseNodeView } from './base_node_view';
18
23
  import { createNodeView } from './creators';
24
+ import ReactSubView from './ReactSubView';
19
25
  export class InlineFootnoteView extends BaseNodeView {
20
26
  constructor() {
21
27
  super(...arguments);
28
+ this.findParentTableElement = () => findParentNodeClosestToPos(this.view.state.doc.resolve(this.getPos()), (node) => node.type === schema.nodes.table_element);
22
29
  this.handleClick = () => {
23
- this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
30
+ if (isDeleted(this.node)) {
31
+ return;
32
+ }
33
+ const tableElement = this.findParentTableElement();
34
+ if (tableElement) {
35
+ const componentProps = {
36
+ notes: this.getNotes(tableElement),
37
+ onAdd: this.onAdd,
38
+ onInsert: this.onUpdate,
39
+ onCancel: this.destroy,
40
+ inlineFootnote: this.node,
41
+ };
42
+ this.popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), TableFootnotesSelector, componentProps, this.node, this.getPos, this.view, 'table-footnote-editor');
43
+ this.props.popper.show(this.dom, this.popperContainer, 'bottom-end');
44
+ }
45
+ else {
46
+ this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
47
+ }
24
48
  };
25
49
  this.updateContents = () => {
26
50
  this.setDomAttrs(this.node, this.dom);
@@ -39,6 +63,49 @@ export class InlineFootnoteView extends BaseNodeView {
39
63
  this.createDOM = () => {
40
64
  return document.createElement('span');
41
65
  };
66
+ this.destroy = () => {
67
+ var _a;
68
+ this.props.popper.destroy();
69
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
70
+ };
71
+ this.getNotes = (tableElement) => {
72
+ var _a;
73
+ const footnotesElement = (_a = findChildrenByType(tableElement.node, schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
74
+ let footnotes = [];
75
+ if (footnotesElement) {
76
+ const tablesFootnoteLabels = buildTableFootnoteLabels(tableElement.node);
77
+ footnotes = findChildrenByType(footnotesElement, schema.nodes.footnote)
78
+ .map(({ node }) => ({
79
+ node: node,
80
+ index: tablesFootnoteLabels.get(node.attrs.id),
81
+ }));
82
+ }
83
+ return footnotes;
84
+ };
85
+ this.onAdd = () => {
86
+ const tableElement = this.findParentTableElement();
87
+ if (tableElement) {
88
+ insertTableFootnote(tableElement.node, tableElement.pos, this.view, {
89
+ node: this.node,
90
+ pos: this.getPos(),
91
+ });
92
+ this.destroy();
93
+ }
94
+ };
95
+ this.onUpdate = (notes) => {
96
+ const contents = this.node.attrs.contents.split(',');
97
+ const rids = notes.map((note) => note.node.attrs.id);
98
+ const { tr } = this.view.state;
99
+ this.view.dispatch(rids.length
100
+ ? tr.setNodeMarkup(this.getPos(), undefined, {
101
+ rids,
102
+ contents: notes
103
+ .map(({ index }) => (index ? index : Math.max(...contents) + 1))
104
+ .join(),
105
+ })
106
+ : tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
107
+ this.destroy();
108
+ };
42
109
  }
43
110
  }
44
111
  export default createNodeView(InlineFootnoteView);
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { CommentAnnotation } from '@manuscripts/json-schema';
17
17
  import { FileAttachment } from '@manuscripts/style-guide';
18
- import { ManuscriptEditorState, ManuscriptEditorView, ManuscriptMarkType, ManuscriptNode, ManuscriptNodeType, ManuscriptTransaction } from '@manuscripts/transform';
18
+ import { InlineFootnoteNode, ManuscriptEditorState, ManuscriptEditorView, ManuscriptMarkType, ManuscriptNode, ManuscriptNodeType, ManuscriptTransaction } from '@manuscripts/transform';
19
19
  import { ResolvedPos } from 'prosemirror-model';
20
20
  import { Command, NodeSelection, Selection, TextSelection, Transaction } from 'prosemirror-state';
21
21
  import { NodeWithPos } from 'prosemirror-utils';
@@ -57,4 +57,9 @@ export declare const deleteHighlightMarkers: (rid: string) => Command;
57
57
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch): boolean;
58
58
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch, viewNode?: ManuscriptNode, resolvePos?: ResolvedPos): boolean;
59
59
  export declare const updateCommentAnnotationState: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
60
- export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView) => void;
60
+ interface NodeWithPosition {
61
+ node: InlineFootnoteNode;
62
+ pos: number;
63
+ }
64
+ export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView, inlineFootnote?: NodeWithPosition) => void;
65
+ export {};
@@ -13,18 +13,27 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { FootnoteWithIndex } from '@manuscripts/style-guide';
16
17
  import { ManuscriptNodeView } from '@manuscripts/transform';
17
18
  import { History } from 'history';
19
+ import { ContentNodeWithPos } from 'prosemirror-utils';
18
20
  import { BaseNodeProps, BaseNodeView } from './base_node_view';
21
+ import { EditableBlockProps } from './editable_block';
19
22
  export interface InlineFootnoteProps extends BaseNodeProps {
20
23
  history: History;
21
24
  }
22
- export declare class InlineFootnoteView<PropsType extends InlineFootnoteProps> extends BaseNodeView<PropsType> implements ManuscriptNodeView {
25
+ export declare class InlineFootnoteView<PropsType extends InlineFootnoteProps & EditableBlockProps> extends BaseNodeView<PropsType> implements ManuscriptNodeView {
26
+ protected popperContainer: HTMLDivElement;
27
+ findParentTableElement: () => ContentNodeWithPos | undefined;
23
28
  handleClick: () => void;
24
29
  updateContents: () => void;
25
30
  initialise: () => void;
26
31
  ignoreMutation: () => boolean;
27
32
  createDOM: () => HTMLSpanElement;
33
+ destroy: () => void;
34
+ getNotes: (tableElement: ContentNodeWithPos) => FootnoteWithIndex[];
35
+ onAdd: () => void;
36
+ onUpdate: (notes: FootnoteWithIndex[]) => void;
28
37
  }
29
- declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<InlineFootnoteView<any>>;
38
+ declare const _default: (props: BaseNodeProps, dispatch?: import("../commands").Dispatch | undefined) => import("../types").NodeViewCreator<InlineFootnoteView<any>>;
30
39
  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.30",
4
+ "version": "1.7.31-LEAN-3144-0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -31,8 +31,8 @@
31
31
  "@manuscripts/assets": "^0.6.4",
32
32
  "@manuscripts/json-schema": "^2.2.7",
33
33
  "@manuscripts/library": "^1.3.6",
34
- "@manuscripts/style-guide": "1.8.4",
35
- "@manuscripts/track-changes-plugin": "1.7.8",
34
+ "@manuscripts/style-guide": "1.8.4-LEAN-3144-4",
35
+ "@manuscripts/track-changes-plugin": "1.7.9",
36
36
  "@manuscripts/transform": "^2.1.10",
37
37
  "astrocite-eutils": "^0.16.4",
38
38
  "axios": "^1.6.7",
@@ -112,4 +112,4 @@
112
112
  "@types/react": "^17.0.2",
113
113
  "prosemirror-tables": "^1.3.5"
114
114
  }
115
- }
115
+ }
@@ -724,11 +724,13 @@ Next levels are shifted 'up' by 1
724
724
  text-decoration: none;
725
725
  }
726
726
 
727
+ .ProseMirror .deleted.pending::before,
727
728
  .ProseMirror .deleted.pending {
728
729
  background: var(--pending-bg-color);
729
730
  color: var(--deleted-color);
730
731
  text-decoration: line-through;
731
732
  }
733
+ .ProseMirror .deleted.accepted::before,
732
734
  .ProseMirror .deleted.accepted {
733
735
  background: var(--accepted-bg-color);
734
736
  color: var(--deleted-color);
package/styles/Editor.css CHANGED
@@ -941,6 +941,7 @@
941
941
  cursor: pointer;
942
942
  vertical-align: super;
943
943
  font-size: 75%;
944
+ color: #0d79d0;
944
945
  }
945
946
 
946
947
  .ProseMirror .table-footer {