@manuscripts/body-editor 1.13.1-LEAN-3720.0 → 1.13.1

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.
@@ -24,6 +24,7 @@ const transform_1 = require("@manuscripts/transform");
24
24
  const prosemirror_state_1 = require("prosemirror-state");
25
25
  const prosemirror_view_1 = require("prosemirror-view");
26
26
  const clipboard_1 = require("../clipboard");
27
+ const helpers_1 = require("../lib/helpers");
27
28
  const paste_1 = require("../lib/paste");
28
29
  const editor_plugins_1 = __importDefault(require("./editor-plugins"));
29
30
  const editor_views_1 = __importDefault(require("./editor-views"));
@@ -48,6 +49,7 @@ const createEditorView = (props, root, state, dispatch) => {
48
49
  attributes: props.attributes,
49
50
  transformPasted: paste_1.transformPasted,
50
51
  clipboardParser: clipboard_1.clipboardParser,
52
+ handleScrollToSelection: helpers_1.handleScrollToBibliographyItem,
51
53
  });
52
54
  const tr = view.state.tr.setMeta('INIT', true);
53
55
  const nextState = view.state.apply(tr);
@@ -47,7 +47,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
47
47
  });
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.renderMath = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
50
+ exports.handleScrollToBibliographyItem = exports.renderMath = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
51
+ const transform_1 = require("@manuscripts/transform");
51
52
  const isNodeOfType = (...type) => (node) => {
52
53
  const [head, ...tail] = type;
53
54
  if (node.type === node.type.schema.nodes[head]) {
@@ -93,3 +94,27 @@ const renderMath = (math, format) => __awaiter(void 0, void 0, void 0, function*
93
94
  }
94
95
  });
95
96
  exports.renderMath = renderMath;
97
+ const handleScrollToBibliographyItem = (view) => {
98
+ const tr = view.state.tr;
99
+ const node = tr.doc.nodeAt(tr.selection.$from.pos);
100
+ if (!node || node.type !== transform_1.schema.nodes.bibliography_item) {
101
+ return false;
102
+ }
103
+ const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
104
+ if (!bibliographyItemElement) {
105
+ return false;
106
+ }
107
+ const bibliographyItemRect = bibliographyItemElement.getBoundingClientRect();
108
+ const editorBodyElement = document.querySelector('.editor-body');
109
+ const parentRect = editorBodyElement.getBoundingClientRect();
110
+ if (bibliographyItemRect.bottom > window.innerHeight ||
111
+ bibliographyItemRect.top < 150) {
112
+ let childTopOffset = bibliographyItemRect.top - parentRect.top;
113
+ childTopOffset =
114
+ childTopOffset - (window.innerHeight - bibliographyItemRect.height) / 2;
115
+ const scrollToTop = editorBodyElement.scrollTop + childTopOffset;
116
+ editorBodyElement.scrollTo({ top: scrollToTop, behavior: 'smooth' });
117
+ }
118
+ return true;
119
+ };
120
+ exports.handleScrollToBibliographyItem = handleScrollToBibliographyItem;
@@ -18,6 +18,7 @@ import { schema } from '@manuscripts/transform';
18
18
  import { EditorState } from 'prosemirror-state';
19
19
  import { EditorView } from 'prosemirror-view';
20
20
  import { clipboardParser } from '../clipboard';
21
+ import { handleScrollToBibliographyItem } from '../lib/helpers';
21
22
  import { transformPasted } from '../lib/paste';
22
23
  import plugins from './editor-plugins';
23
24
  import views from './editor-views';
@@ -41,6 +42,7 @@ export const createEditorView = (props, root, state, dispatch) => {
41
42
  attributes: props.attributes,
42
43
  transformPasted,
43
44
  clipboardParser,
45
+ handleScrollToSelection: handleScrollToBibliographyItem,
44
46
  });
45
47
  const tr = view.state.tr.setMeta('INIT', true);
46
48
  const nextState = view.state.apply(tr);
@@ -22,6 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
+ import { schema } from '@manuscripts/transform';
25
26
  export const isNodeOfType = (...type) => (node) => {
26
27
  const [head, ...tail] = type;
27
28
  if (node.type === node.type.schema.nodes[head]) {
@@ -63,3 +64,26 @@ export const renderMath = (math, format) => __awaiter(void 0, void 0, void 0, fu
63
64
  return convertMathMLToSVG(math);
64
65
  }
65
66
  });
67
+ export const handleScrollToBibliographyItem = (view) => {
68
+ const tr = view.state.tr;
69
+ const node = tr.doc.nodeAt(tr.selection.$from.pos);
70
+ if (!node || node.type !== schema.nodes.bibliography_item) {
71
+ return false;
72
+ }
73
+ const bibliographyItemElement = document.querySelector(`[id="${node.attrs.id}"]`);
74
+ if (!bibliographyItemElement) {
75
+ return false;
76
+ }
77
+ const bibliographyItemRect = bibliographyItemElement.getBoundingClientRect();
78
+ const editorBodyElement = document.querySelector('.editor-body');
79
+ const parentRect = editorBodyElement.getBoundingClientRect();
80
+ if (bibliographyItemRect.bottom > window.innerHeight ||
81
+ bibliographyItemRect.top < 150) {
82
+ let childTopOffset = bibliographyItemRect.top - parentRect.top;
83
+ childTopOffset =
84
+ childTopOffset - (window.innerHeight - bibliographyItemRect.height) / 2;
85
+ const scrollToTop = editorBodyElement.scrollTop + childTopOffset;
86
+ editorBodyElement.scrollTo({ top: scrollToTop, behavior: 'smooth' });
87
+ }
88
+ return true;
89
+ };
@@ -15,7 +15,9 @@
15
15
  */
16
16
  import { ManuscriptNode } from '@manuscripts/transform';
17
17
  import { Node, ResolvedPos } from 'prosemirror-model';
18
+ import { EditorView } from 'prosemirror-view';
18
19
  export declare const isNodeOfType: (...type: string[]) => (node: Node) => boolean;
19
20
  export declare const nearestAncestor: (func: (node: ManuscriptNode) => boolean) => ($pos: ResolvedPos) => number | null;
20
21
  export declare const mergeSimilarItems: <T>(compareFunc: (a: T, b: T) => boolean, mergeFunc: (a: T, b: T) => T) => (items: T[]) => T[];
21
22
  export declare const renderMath: (math: string, format: string) => Promise<string | null>;
23
+ export declare const handleScrollToBibliographyItem: (view: EditorView) => boolean;
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.13.1-LEAN-3720.0",
4
+ "version": "1.13.1",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -30,7 +30,7 @@
30
30
  "@iarna/word-count": "^1.1.2",
31
31
  "@manuscripts/json-schema": "2.2.8",
32
32
  "@manuscripts/library": "1.3.7",
33
- "@manuscripts/style-guide": "1.13.1-LEAN-3720.0",
33
+ "@manuscripts/style-guide": "1.13.0",
34
34
  "@manuscripts/track-changes-plugin": "1.7.13",
35
35
  "@manuscripts/transform": "2.3.9",
36
36
  "astrocite-eutils": "^0.16.4",