@manuscripts/body-editor 2.6.2 → 2.6.3-LEAN-4073.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.
@@ -52,7 +52,7 @@ const createEditorView = (props, root, state, dispatch) => {
52
52
  transformPasted: paste_1.transformPasted,
53
53
  handlePaste: paste_1.handlePaste,
54
54
  clipboardParser: clipboard_1.clipboardParser,
55
- handleScrollToSelection: helpers_1.handleScrollToBibliographyItem,
55
+ handleScrollToSelection: helpers_1.handleScrollToSelectedElement,
56
56
  transformCopied: copy_1.transformCopied,
57
57
  handleClickOn: (view, pos, node, nodePos, event) => {
58
58
  if ((event === null || event === void 0 ? void 0 : event.target) &&
package/dist/cjs/index.js CHANGED
@@ -56,6 +56,7 @@ __exportStar(require("./lib/utils"), exports);
56
56
  __exportStar(require("./lib/track-changes-utils"), exports);
57
57
  __exportStar(require("./useEditor"), exports);
58
58
  __exportStar(require("./lib/math"), exports);
59
+ __exportStar(require("./lib/helpers"), exports);
59
60
  var objects_1 = require("./plugins/objects");
60
61
  Object.defineProperty(exports, "objectsPluginKey", { enumerable: true, get: function () { return objects_1.objectsKey; } });
61
62
  var footnotes_1 = require("./plugins/footnotes");
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.findWordBoundaries = exports.handleScrollToBibliographyItem = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
18
+ exports.findWordBoundaries = exports.handleScrollToSelectedElement = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const isNodeOfType = (...type) => (node) => {
21
21
  const [head, ...tail] = type;
@@ -51,30 +51,38 @@ const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
51
51
  }, []);
52
52
  };
53
53
  exports.mergeSimilarItems = mergeSimilarItems;
54
- const handleScrollToBibliographyItem = (view) => {
55
- const tr = view.state.tr;
56
- const node = tr.doc.nodeAt(tr.selection.$from.pos);
57
- if (!node || node.type !== transform_1.schema.nodes.bibliography_item) {
58
- return false;
59
- }
60
- const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
61
- if (!bibliographyItemElement) {
62
- return false;
63
- }
64
- const bibliographyItemRect = bibliographyItemElement.getBoundingClientRect();
54
+ const scrollToElement = (element) => {
55
+ const elementRect = element.getBoundingClientRect();
65
56
  const editorBodyElement = document.querySelector('.editor-body');
66
57
  const parentRect = editorBodyElement.getBoundingClientRect();
67
- if (bibliographyItemRect.bottom > window.innerHeight ||
68
- bibliographyItemRect.top < 150) {
69
- let childTopOffset = bibliographyItemRect.top - parentRect.top;
58
+ if (elementRect.bottom > window.innerHeight || elementRect.top < 150) {
59
+ let childTopOffset = elementRect.top - parentRect.top;
70
60
  childTopOffset =
71
- childTopOffset - (window.innerHeight - bibliographyItemRect.height) / 2;
61
+ childTopOffset - (window.innerHeight - elementRect.height) / 2;
72
62
  const scrollToTop = editorBodyElement.scrollTop + childTopOffset;
73
63
  editorBodyElement.scrollTo({ top: scrollToTop, behavior: 'smooth' });
74
64
  }
75
- return true;
76
65
  };
77
- exports.handleScrollToBibliographyItem = handleScrollToBibliographyItem;
66
+ const handleScrollToSelectedElement = (view, targetHtmlElement) => {
67
+ const tr = view.state.tr;
68
+ const node = tr.doc.nodeAt(tr.selection.$from.pos);
69
+ if (!node) {
70
+ return false;
71
+ }
72
+ if (node.type === transform_1.schema.nodes.bibliography_item) {
73
+ const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
74
+ if (bibliographyItemElement) {
75
+ scrollToElement(bibliographyItemElement);
76
+ return true;
77
+ }
78
+ }
79
+ if (targetHtmlElement) {
80
+ scrollToElement(targetHtmlElement);
81
+ return true;
82
+ }
83
+ return false;
84
+ };
85
+ exports.handleScrollToSelectedElement = handleScrollToSelectedElement;
78
86
  const findWordBoundaries = (state, position) => {
79
87
  let start = position;
80
88
  let end = position;
@@ -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 = '2.6.2';
4
+ exports.VERSION = '2.6.3-LEAN-4073.0';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -19,7 +19,7 @@ import { EditorState } from 'prosemirror-state';
19
19
  import { EditorView } from 'prosemirror-view';
20
20
  import { clipboardParser } from '../clipboard';
21
21
  import { transformCopied } from '../lib/copy';
22
- import { handleScrollToBibliographyItem } from '../lib/helpers';
22
+ import { handleScrollToSelectedElement } from '../lib/helpers';
23
23
  import { handlePaste, transformPasted } from '../lib/paste';
24
24
  import { INIT_META } from '../lib/plugins';
25
25
  import plugins from './editor-plugins';
@@ -45,7 +45,7 @@ export const createEditorView = (props, root, state, dispatch) => {
45
45
  transformPasted,
46
46
  handlePaste,
47
47
  clipboardParser,
48
- handleScrollToSelection: handleScrollToBibliographyItem,
48
+ handleScrollToSelection: handleScrollToSelectedElement,
49
49
  transformCopied,
50
50
  handleClickOn: (view, pos, node, nodePos, event) => {
51
51
  if ((event === null || event === void 0 ? void 0 : event.target) &&
package/dist/es/index.js CHANGED
@@ -33,6 +33,7 @@ export * from './lib/utils';
33
33
  export * from './lib/track-changes-utils';
34
34
  export * from './useEditor';
35
35
  export * from './lib/math';
36
+ export * from './lib/helpers';
36
37
  export { objectsKey as objectsPluginKey } from './plugins/objects';
37
38
  export { footnotesKey as footnotesPluginKey } from './plugins/footnotes';
38
39
  export { bibliographyKey as bibliographyPluginKey } from './plugins/bibliography';
@@ -45,28 +45,36 @@ export const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
45
45
  ];
46
46
  }, []);
47
47
  };
48
- export const handleScrollToBibliographyItem = (view) => {
49
- const tr = view.state.tr;
50
- const node = tr.doc.nodeAt(tr.selection.$from.pos);
51
- if (!node || node.type !== schema.nodes.bibliography_item) {
52
- return false;
53
- }
54
- const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
55
- if (!bibliographyItemElement) {
56
- return false;
57
- }
58
- const bibliographyItemRect = bibliographyItemElement.getBoundingClientRect();
48
+ const scrollToElement = (element) => {
49
+ const elementRect = element.getBoundingClientRect();
59
50
  const editorBodyElement = document.querySelector('.editor-body');
60
51
  const parentRect = editorBodyElement.getBoundingClientRect();
61
- if (bibliographyItemRect.bottom > window.innerHeight ||
62
- bibliographyItemRect.top < 150) {
63
- let childTopOffset = bibliographyItemRect.top - parentRect.top;
52
+ if (elementRect.bottom > window.innerHeight || elementRect.top < 150) {
53
+ let childTopOffset = elementRect.top - parentRect.top;
64
54
  childTopOffset =
65
- childTopOffset - (window.innerHeight - bibliographyItemRect.height) / 2;
55
+ childTopOffset - (window.innerHeight - elementRect.height) / 2;
66
56
  const scrollToTop = editorBodyElement.scrollTop + childTopOffset;
67
57
  editorBodyElement.scrollTo({ top: scrollToTop, behavior: 'smooth' });
68
58
  }
69
- return true;
59
+ };
60
+ export const handleScrollToSelectedElement = (view, targetHtmlElement) => {
61
+ const tr = view.state.tr;
62
+ const node = tr.doc.nodeAt(tr.selection.$from.pos);
63
+ if (!node) {
64
+ return false;
65
+ }
66
+ if (node.type === schema.nodes.bibliography_item) {
67
+ const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
68
+ if (bibliographyItemElement) {
69
+ scrollToElement(bibliographyItemElement);
70
+ return true;
71
+ }
72
+ }
73
+ if (targetHtmlElement) {
74
+ scrollToElement(targetHtmlElement);
75
+ return true;
76
+ }
77
+ return false;
70
78
  };
71
79
  export const findWordBoundaries = (state, position) => {
72
80
  let start = position;
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.6.2';
1
+ export const VERSION = '2.6.3-LEAN-4073.0';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -34,6 +34,7 @@ export * from './lib/utils';
34
34
  export * from './lib/track-changes-utils';
35
35
  export * from './useEditor';
36
36
  export * from './lib/math';
37
+ export * from './lib/helpers';
37
38
  export { objectsKey as objectsPluginKey } from './plugins/objects';
38
39
  export { footnotesKey as footnotesPluginKey } from './plugins/footnotes';
39
40
  export { bibliographyKey as bibliographyPluginKey } from './plugins/bibliography';
@@ -19,7 +19,7 @@ import { EditorView } from 'prosemirror-view';
19
19
  export declare const isNodeOfType: (...type: string[]) => (node: Node) => boolean;
20
20
  export declare const nearestAncestor: (func: (node: ManuscriptNode) => boolean) => ($pos: ResolvedPos) => number | null;
21
21
  export declare const mergeSimilarItems: <T>(compareFunc: (a: T, b: T) => boolean, mergeFunc: (a: T, b: T) => T) => (items: T[]) => T[];
22
- export declare const handleScrollToBibliographyItem: (view: EditorView) => boolean;
22
+ export declare const handleScrollToSelectedElement: (view: EditorView, targetHtmlElement?: HTMLElement) => boolean;
23
23
  export declare const findWordBoundaries: (state: ManuscriptEditorState, position: number) => {
24
24
  from: number;
25
25
  to: number;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.6.2";
1
+ export declare const VERSION = "2.6.3-LEAN-4073.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": "2.6.2",
4
+ "version": "2.6.3-LEAN-4073.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",