@manuscripts/body-editor 1.9.18 → 1.9.19-LEAN-3535.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.
@@ -22,9 +22,9 @@ exports.PopperManager = void 0;
22
22
  const popper_js_1 = __importDefault(require("popper.js"));
23
23
  class PopperManager {
24
24
  show(target, contents, placement = 'bottom', showArrow = true, modifiers = {}) {
25
- if (this.activePopper) {
26
- return this.destroy();
27
- }
25
+ this.destroy();
26
+ this.clickEventHandler = this.clickEventHandler.bind(this);
27
+ document.body.addEventListener('click', this.clickEventHandler);
28
28
  window.requestAnimationFrame(() => {
29
29
  const container = document.createElement('div');
30
30
  container.className = 'popper';
@@ -57,8 +57,15 @@ class PopperManager {
57
57
  });
58
58
  });
59
59
  }
60
+ clickEventHandler(event) {
61
+ const editorElement = document.querySelector('.manuscript-editor');
62
+ if (!(editorElement === null || editorElement === void 0 ? void 0 : editorElement.contains(event.target))) {
63
+ this.destroy();
64
+ }
65
+ }
60
66
  destroy() {
61
67
  if (this.activePopper) {
68
+ document.body.removeEventListener('click', this.clickEventHandler);
62
69
  this.removeContainerClass(this.activePopper.reference);
63
70
  this.activePopper.destroy();
64
71
  delete this.activePopper;
@@ -69,6 +69,7 @@ class SuggestionView {
69
69
  if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
70
70
  return;
71
71
  }
72
+ console.log(dom);
72
73
  dom.addEventListener('click', this.listener);
73
74
  });
74
75
  }
@@ -45,9 +45,7 @@ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
45
45
  class BibliographyElementBlockView extends block_view_1.default {
46
46
  constructor() {
47
47
  super(...arguments);
48
- this.clickedElementId = null;
49
48
  this.showPopper = (id) => {
50
- this.props.popper.destroy();
51
49
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
52
50
  if (!bib) {
53
51
  return;
@@ -71,8 +69,6 @@ class BibliographyElementBlockView extends block_view_1.default {
71
69
  this.props.setComment((0, transform_1.buildComment)(citationId));
72
70
  };
73
71
  this.showContextMenu = (elementId) => {
74
- this.props.popper.destroy();
75
- this.clickedElementId = null;
76
72
  const can = this.props.getCapabilities();
77
73
  const element = document.getElementById(elementId);
78
74
  const componentProps = {
@@ -95,7 +91,6 @@ class BibliographyElementBlockView extends block_view_1.default {
95
91
  };
96
92
  this.onClickHandler = (elementId, dataTracked) => {
97
93
  var _a;
98
- this.clickedElementId = elementId;
99
94
  const isSelectedSuggestion = !!((_a = selected_suggestion_ui_1.selectedSuggestionKey
100
95
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
101
96
  const { tr, doc } = this.view.state;
@@ -107,11 +102,9 @@ class BibliographyElementBlockView extends block_view_1.default {
107
102
  if (isSelectedSuggestion) {
108
103
  tr.setMeta(selected_suggestion_ui_1.CLEAR_SUGGESTION_ID, true);
109
104
  }
110
- else {
111
- this.showContextMenu(elementId);
112
- }
113
105
  }
114
106
  this.view.dispatch(tr);
107
+ this.showContextMenu(elementId);
115
108
  };
116
109
  this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
117
110
  this.props.popper.destroy();
@@ -164,7 +157,9 @@ class BibliographyElementBlockView extends block_view_1.default {
164
157
  element.classList.add('selected-suggestion');
165
158
  }
166
159
  if (can.seeReferencesButtons) {
167
- element.addEventListener('click', () => this.onClickHandler(element.id, dataTracked));
160
+ element.addEventListener('click', () => {
161
+ this.onClickHandler(element.id, dataTracked);
162
+ });
168
163
  }
169
164
  wrapper.append(element);
170
165
  }
@@ -175,9 +170,6 @@ class BibliographyElementBlockView extends block_view_1.default {
175
170
  else {
176
171
  this.container.appendChild(wrapper);
177
172
  }
178
- if (this.clickedElementId) {
179
- this.showContextMenu(this.clickedElementId);
180
- }
181
173
  });
182
174
  this.createElement = () => {
183
175
  this.container = document.createElement('div');
@@ -27,6 +27,7 @@ class CitationView extends base_node_view_1.BaseNodeView {
27
27
  constructor() {
28
28
  super(...arguments);
29
29
  this.ignoreMutation = () => true;
30
+ this.wasUpdated = false;
30
31
  this.initialise = () => {
31
32
  if (!this.node.type.spec.toDOM) {
32
33
  throw Error(`Node view ${this.node.type} doesn't have toDOM method`);
@@ -59,6 +60,13 @@ class CitationView extends base_node_view_1.BaseNodeView {
59
60
  this.dom.appendChild(element);
60
61
  (0, comment_annotation_1.addCommentToLeafNode)(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
61
62
  this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
63
+ if (!this.wasUpdated) {
64
+ this.dom.addEventListener('click', () => this.onClickHandler());
65
+ }
66
+ this.wasUpdated = true;
67
+ this.props.popper.update();
68
+ };
69
+ this.onClickHandler = () => {
62
70
  };
63
71
  }
64
72
  }
@@ -47,17 +47,18 @@ class CitationEditableView extends citation_1.CitationView {
47
47
  element.classList.contains('comment-icon') ||
48
48
  ((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('comment-icon')));
49
49
  };
50
- this.selectNode = () => {
50
+ this.onClickHandler = () => {
51
51
  var _a;
52
52
  const can = this.props.getCapabilities();
53
53
  const dataTracked = this.node.attrs.dataTracked;
54
54
  const isSelectedSuggestion = !!((_a = selected_suggestion_ui_1.selectedSuggestionKey
55
55
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
56
- this.dom.classList.add('ProseMirror-selectednode');
56
+ const { tr, doc } = this.view.state;
57
+ tr.setSelection(prosemirror_state_1.NodeSelection.create(doc, this.getPos()));
57
58
  if (dataTracked && !isSelectedSuggestion) {
58
- this.view.dispatch(this.view.state.tr.setMeta(selected_suggestion_ui_1.SET_SUGGESTION_ID, dataTracked[0].id));
59
+ tr.setMeta(selected_suggestion_ui_1.SET_SUGGESTION_ID, dataTracked[0].id);
59
60
  }
60
- else if (can.seeReferencesButtons && !(0, track_changes_utils_1.isDeleted)(this.node)) {
61
+ if (can.seeReferencesButtons && !(0, track_changes_utils_1.isDeleted)(this.node)) {
61
62
  const attrs = (0, track_changes_utils_1.getActualAttrs)(this.node);
62
63
  if (!attrs.rids.length) {
63
64
  this.showPopper();
@@ -66,10 +67,7 @@ class CitationEditableView extends citation_1.CitationView {
66
67
  this.showContextMenu();
67
68
  }
68
69
  }
69
- };
70
- this.deselectNode = () => {
71
- this.dom.classList.remove('ProseMirror-selectednode');
72
- this.props.popper.destroy();
70
+ this.view.dispatch(tr);
73
71
  };
74
72
  this.destroy = () => {
75
73
  var _a;
@@ -77,7 +75,6 @@ class CitationEditableView extends citation_1.CitationView {
77
75
  this.props.popper.destroy();
78
76
  };
79
77
  this.showContextMenu = () => {
80
- this.props.popper.destroy();
81
78
  const componentProps = {
82
79
  actions: [
83
80
  { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
@@ -85,7 +82,9 @@ class CitationEditableView extends citation_1.CitationView {
85
82
  ],
86
83
  };
87
84
  this.contextMenu = (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
88
- this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
85
+ setTimeout(() => {
86
+ this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
87
+ }, 0);
89
88
  };
90
89
  this.showPopper = () => {
91
90
  this.props.popper.destroy();
@@ -179,7 +179,6 @@ class ContributorsView extends block_view_1.default {
179
179
  };
180
180
  this.onClickHandler = (elementId, dataTracked) => {
181
181
  var _a;
182
- this.props.popper.destroy();
183
182
  const isSelectedSuggestion = !!((_a = selected_suggestion_ui_1.selectedSuggestionKey
184
183
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
185
184
  const { tr, doc } = this.view.state;
@@ -192,11 +191,11 @@ class ContributorsView extends block_view_1.default {
192
191
  tr.setMeta(selected_suggestion_ui_1.CLEAR_SUGGESTION_ID, true);
193
192
  }
194
193
  }
194
+ this.view.dispatch(tr);
195
195
  if (!((dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.operation) === track_changes_plugin_1.CHANGE_OPERATION.delete &&
196
196
  (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.status) !== track_changes_plugin_1.CHANGE_STATUS.rejected)) {
197
197
  this.showContextMenu(elementId);
198
198
  }
199
- this.view.dispatch(tr);
200
199
  };
201
200
  this.showContextMenu = (elementId) => {
202
201
  this.props.popper.destroy();
@@ -16,9 +16,9 @@
16
16
  import Popper from 'popper.js';
17
17
  export class PopperManager {
18
18
  show(target, contents, placement = 'bottom', showArrow = true, modifiers = {}) {
19
- if (this.activePopper) {
20
- return this.destroy();
21
- }
19
+ this.destroy();
20
+ this.clickEventHandler = this.clickEventHandler.bind(this);
21
+ document.body.addEventListener('click', this.clickEventHandler);
22
22
  window.requestAnimationFrame(() => {
23
23
  const container = document.createElement('div');
24
24
  container.className = 'popper';
@@ -51,8 +51,15 @@ export class PopperManager {
51
51
  });
52
52
  });
53
53
  }
54
+ clickEventHandler(event) {
55
+ const editorElement = document.querySelector('.manuscript-editor');
56
+ if (!(editorElement === null || editorElement === void 0 ? void 0 : editorElement.contains(event.target))) {
57
+ this.destroy();
58
+ }
59
+ }
54
60
  destroy() {
55
61
  if (this.activePopper) {
62
+ document.body.removeEventListener('click', this.clickEventHandler);
56
63
  this.removeContainerClass(this.activePopper.reference);
57
64
  this.activePopper.destroy();
58
65
  delete this.activePopper;
@@ -66,6 +66,7 @@ class SuggestionView {
66
66
  if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
67
67
  return;
68
68
  }
69
+ console.log(dom);
69
70
  dom.addEventListener('click', this.listener);
70
71
  });
71
72
  }
@@ -39,9 +39,7 @@ import ReactSubView from './ReactSubView';
39
39
  export class BibliographyElementBlockView extends BlockView {
40
40
  constructor() {
41
41
  super(...arguments);
42
- this.clickedElementId = null;
43
42
  this.showPopper = (id) => {
44
- this.props.popper.destroy();
45
43
  const bib = getBibliographyPluginState(this.view.state);
46
44
  if (!bib) {
47
45
  return;
@@ -65,8 +63,6 @@ export class BibliographyElementBlockView extends BlockView {
65
63
  this.props.setComment(buildComment(citationId));
66
64
  };
67
65
  this.showContextMenu = (elementId) => {
68
- this.props.popper.destroy();
69
- this.clickedElementId = null;
70
66
  const can = this.props.getCapabilities();
71
67
  const element = document.getElementById(elementId);
72
68
  const componentProps = {
@@ -89,7 +85,6 @@ export class BibliographyElementBlockView extends BlockView {
89
85
  };
90
86
  this.onClickHandler = (elementId, dataTracked) => {
91
87
  var _a;
92
- this.clickedElementId = elementId;
93
88
  const isSelectedSuggestion = !!((_a = selectedSuggestionKey
94
89
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
95
90
  const { tr, doc } = this.view.state;
@@ -101,11 +96,9 @@ export class BibliographyElementBlockView extends BlockView {
101
96
  if (isSelectedSuggestion) {
102
97
  tr.setMeta(CLEAR_SUGGESTION_ID, true);
103
98
  }
104
- else {
105
- this.showContextMenu(elementId);
106
- }
107
99
  }
108
100
  this.view.dispatch(tr);
101
+ this.showContextMenu(elementId);
109
102
  };
110
103
  this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
111
104
  this.props.popper.destroy();
@@ -158,7 +151,9 @@ export class BibliographyElementBlockView extends BlockView {
158
151
  element.classList.add('selected-suggestion');
159
152
  }
160
153
  if (can.seeReferencesButtons) {
161
- element.addEventListener('click', () => this.onClickHandler(element.id, dataTracked));
154
+ element.addEventListener('click', () => {
155
+ this.onClickHandler(element.id, dataTracked);
156
+ });
162
157
  }
163
158
  wrapper.append(element);
164
159
  }
@@ -169,9 +164,6 @@ export class BibliographyElementBlockView extends BlockView {
169
164
  else {
170
165
  this.container.appendChild(wrapper);
171
166
  }
172
- if (this.clickedElementId) {
173
- this.showContextMenu(this.clickedElementId);
174
- }
175
167
  });
176
168
  this.createElement = () => {
177
169
  this.container = document.createElement('div');
@@ -24,6 +24,7 @@ export class CitationView extends BaseNodeView {
24
24
  constructor() {
25
25
  super(...arguments);
26
26
  this.ignoreMutation = () => true;
27
+ this.wasUpdated = false;
27
28
  this.initialise = () => {
28
29
  if (!this.node.type.spec.toDOM) {
29
30
  throw Error(`Node view ${this.node.type} doesn't have toDOM method`);
@@ -56,6 +57,13 @@ export class CitationView extends BaseNodeView {
56
57
  this.dom.appendChild(element);
57
58
  addCommentToLeafNode(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
58
59
  this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
60
+ if (!this.wasUpdated) {
61
+ this.dom.addEventListener('click', () => this.onClickHandler());
62
+ }
63
+ this.wasUpdated = true;
64
+ this.props.popper.update();
65
+ };
66
+ this.onClickHandler = () => {
59
67
  };
60
68
  }
61
69
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { ContextMenu } from '@manuscripts/style-guide';
17
17
  import { buildComment, schema, } from '@manuscripts/transform';
18
- import { TextSelection } from 'prosemirror-state';
18
+ import { NodeSelection, TextSelection } from 'prosemirror-state';
19
19
  import { findChildrenByType } from 'prosemirror-utils';
20
20
  import { CitationEditor, } from '../components/references/CitationEditor';
21
21
  import { CitationViewer, } from '../components/references/CitationViewer';
@@ -41,17 +41,18 @@ export class CitationEditableView extends CitationView {
41
41
  element.classList.contains('comment-icon') ||
42
42
  ((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('comment-icon')));
43
43
  };
44
- this.selectNode = () => {
44
+ this.onClickHandler = () => {
45
45
  var _a;
46
46
  const can = this.props.getCapabilities();
47
47
  const dataTracked = this.node.attrs.dataTracked;
48
48
  const isSelectedSuggestion = !!((_a = selectedSuggestionKey
49
49
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
50
- this.dom.classList.add('ProseMirror-selectednode');
50
+ const { tr, doc } = this.view.state;
51
+ tr.setSelection(NodeSelection.create(doc, this.getPos()));
51
52
  if (dataTracked && !isSelectedSuggestion) {
52
- this.view.dispatch(this.view.state.tr.setMeta(SET_SUGGESTION_ID, dataTracked[0].id));
53
+ tr.setMeta(SET_SUGGESTION_ID, dataTracked[0].id);
53
54
  }
54
- else if (can.seeReferencesButtons && !isDeleted(this.node)) {
55
+ if (can.seeReferencesButtons && !isDeleted(this.node)) {
55
56
  const attrs = getActualAttrs(this.node);
56
57
  if (!attrs.rids.length) {
57
58
  this.showPopper();
@@ -60,10 +61,7 @@ export class CitationEditableView extends CitationView {
60
61
  this.showContextMenu();
61
62
  }
62
63
  }
63
- };
64
- this.deselectNode = () => {
65
- this.dom.classList.remove('ProseMirror-selectednode');
66
- this.props.popper.destroy();
64
+ this.view.dispatch(tr);
67
65
  };
68
66
  this.destroy = () => {
69
67
  var _a;
@@ -71,7 +69,6 @@ export class CitationEditableView extends CitationView {
71
69
  this.props.popper.destroy();
72
70
  };
73
71
  this.showContextMenu = () => {
74
- this.props.popper.destroy();
75
72
  const componentProps = {
76
73
  actions: [
77
74
  { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
@@ -79,7 +76,9 @@ export class CitationEditableView extends CitationView {
79
76
  ],
80
77
  };
81
78
  this.contextMenu = ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
82
- this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
79
+ setTimeout(() => {
80
+ this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
81
+ }, 0);
83
82
  };
84
83
  this.showPopper = () => {
85
84
  this.props.popper.destroy();
@@ -173,7 +173,6 @@ export class ContributorsView extends BlockView {
173
173
  };
174
174
  this.onClickHandler = (elementId, dataTracked) => {
175
175
  var _a;
176
- this.props.popper.destroy();
177
176
  const isSelectedSuggestion = !!((_a = selectedSuggestionKey
178
177
  .getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
179
178
  const { tr, doc } = this.view.state;
@@ -186,11 +185,11 @@ export class ContributorsView extends BlockView {
186
185
  tr.setMeta(CLEAR_SUGGESTION_ID, true);
187
186
  }
188
187
  }
188
+ this.view.dispatch(tr);
189
189
  if (!((dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.operation) === CHANGE_OPERATION.delete &&
190
190
  (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.status) !== CHANGE_STATUS.rejected)) {
191
191
  this.showContextMenu(elementId);
192
192
  }
193
- this.view.dispatch(tr);
194
193
  };
195
194
  this.showContextMenu = (elementId) => {
196
195
  this.props.popper.destroy();
@@ -17,6 +17,7 @@ import Popper from 'popper.js';
17
17
  export declare class PopperManager {
18
18
  protected activePopper?: Popper;
19
19
  show(target: Element, contents: HTMLElement, placement?: Popper.Placement, showArrow?: boolean, modifiers?: Popper.Modifiers): void;
20
+ clickEventHandler(event: Event): void;
20
21
  destroy(): void;
21
22
  update(): void;
22
23
  private focusInput;
@@ -24,7 +24,6 @@ export declare class BibliographyElementBlockView<PropsType extends Bibliography
24
24
  private container;
25
25
  private editor;
26
26
  private contextMenu;
27
- private clickedElementId;
28
27
  showPopper: (id: string) => void;
29
28
  stopEvent: () => boolean;
30
29
  ignoreMutation: () => boolean;
@@ -17,8 +17,10 @@ import { ManuscriptNodeView } from '@manuscripts/transform';
17
17
  import { BaseNodeProps, BaseNodeView } from './base_node_view';
18
18
  export declare class CitationView<PropsType extends BaseNodeProps> extends BaseNodeView<PropsType> implements ManuscriptNodeView {
19
19
  ignoreMutation: () => boolean;
20
+ wasUpdated: boolean;
20
21
  initialise: () => this;
21
22
  updateContents: () => void;
23
+ onClickHandler: () => void;
22
24
  }
23
25
  declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<CitationView<any>>;
24
26
  export default _default;
@@ -19,8 +19,7 @@ export declare class CitationEditableView extends CitationView<EditableBlockProp
19
19
  private editor;
20
20
  private contextMenu;
21
21
  stopEvent: (event: Event) => boolean;
22
- selectNode: () => void;
23
- deselectNode: () => void;
22
+ onClickHandler: () => void;
24
23
  destroy: () => void;
25
24
  showContextMenu: () => void;
26
25
  showPopper: () => void;
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.9.18",
4
+ "version": "1.9.19-LEAN-3535.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",