@manuscripts/body-editor 3.12.34 → 3.12.35

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.
@@ -15,8 +15,9 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.findWordBoundaries = exports.handleScrollToSelectedTarget = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
18
+ exports.findWordBoundaries = exports.handleScrollToSelectedTarget = exports.selectionForOutlineNavigation = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
+ const prosemirror_state_1 = require("prosemirror-state");
20
21
  const isNodeOfType = (...type) => (node) => {
21
22
  const [head, ...tail] = type;
22
23
  if (node.type === node.type.schema.nodes[head]) {
@@ -51,6 +52,32 @@ const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
51
52
  }, []);
52
53
  };
53
54
  exports.mergeSimilarItems = mergeSimilarItems;
55
+ const selectionForOutlineNavigation = (doc, pos) => {
56
+ const node = doc.nodeAt(pos);
57
+ if (!node || (0, transform_1.isExecutableNodeType)(node.type)) {
58
+ return prosemirror_state_1.NodeSelection.create(doc, pos);
59
+ }
60
+ if (node.isTextblock) {
61
+ return prosemirror_state_1.TextSelection.create(doc, pos + 1);
62
+ }
63
+ if (node.type === transform_1.schema.nodes.section) {
64
+ let textPos = null;
65
+ node.forEach((child, offset) => {
66
+ if (textPos !== null) {
67
+ return;
68
+ }
69
+ if (child.type === transform_1.schema.nodes.section_title ||
70
+ child.type === transform_1.schema.nodes.section_title_plain) {
71
+ textPos = pos + 1 + offset + 1;
72
+ }
73
+ });
74
+ if (textPos !== null) {
75
+ return prosemirror_state_1.TextSelection.create(doc, textPos);
76
+ }
77
+ }
78
+ return prosemirror_state_1.NodeSelection.create(doc, pos);
79
+ };
80
+ exports.selectionForOutlineNavigation = selectionForOutlineNavigation;
54
81
  const handleScrollToSelectedTarget = (view) => {
55
82
  const selection = view.state.selection;
56
83
  if (selection.empty) {
@@ -24,6 +24,7 @@ const react_router_dom_1 = require("react-router-dom");
24
24
  const ManuscriptsEditor_1 = require("./configs/ManuscriptsEditor");
25
25
  const popper_1 = require("./lib/popper");
26
26
  const use_do_with_debounce_1 = require("./lib/use-do-with-debounce");
27
+ const helpers_1 = require("./lib/helpers");
27
28
  const search_replace_1 = require("./plugins/search-replace");
28
29
  const useEditor = (externalProps) => {
29
30
  const view = (0, react_1.useRef)(undefined);
@@ -109,12 +110,14 @@ const useEditor = (externalProps) => {
109
110
  if (!id || !currentView || !state) {
110
111
  return;
111
112
  }
112
- state.doc.descendants((node, pos) => {
113
+ const viewState = currentView.state;
114
+ viewState.doc.descendants((node, pos) => {
113
115
  if (node.attrs.id === id) {
114
116
  currentView.focus();
115
- const selection = prosemirror_state_1.NodeSelection.create(state.tr.doc, pos);
116
- currentView.dispatch(state.tr.setSelection(selection));
117
- const dom = currentView.domAtPos(pos + 1);
117
+ const selection = (0, helpers_1.selectionForOutlineNavigation)(viewState.doc, pos);
118
+ currentView.dispatch(viewState.tr.setSelection(selection));
119
+ const scrollPos = selection instanceof prosemirror_state_1.TextSelection ? selection.from : pos + 1;
120
+ const dom = currentView.domAtPos(scrollPos);
118
121
  if (dom.node instanceof Element) {
119
122
  dom.node.scrollIntoView({
120
123
  behavior: 'smooth',
@@ -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 = '3.12.34';
4
+ exports.VERSION = '3.12.35';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -13,7 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { schema, } from '@manuscripts/transform';
16
+ import { isExecutableNodeType, schema, } from '@manuscripts/transform';
17
+ import { NodeSelection, TextSelection } from 'prosemirror-state';
17
18
  export const isNodeOfType = (...type) => (node) => {
18
19
  const [head, ...tail] = type;
19
20
  if (node.type === node.type.schema.nodes[head]) {
@@ -45,6 +46,31 @@ export const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
45
46
  ];
46
47
  }, []);
47
48
  };
49
+ export const selectionForOutlineNavigation = (doc, pos) => {
50
+ const node = doc.nodeAt(pos);
51
+ if (!node || isExecutableNodeType(node.type)) {
52
+ return NodeSelection.create(doc, pos);
53
+ }
54
+ if (node.isTextblock) {
55
+ return TextSelection.create(doc, pos + 1);
56
+ }
57
+ if (node.type === schema.nodes.section) {
58
+ let textPos = null;
59
+ node.forEach((child, offset) => {
60
+ if (textPos !== null) {
61
+ return;
62
+ }
63
+ if (child.type === schema.nodes.section_title ||
64
+ child.type === schema.nodes.section_title_plain) {
65
+ textPos = pos + 1 + offset + 1;
66
+ }
67
+ });
68
+ if (textPos !== null) {
69
+ return TextSelection.create(doc, textPos);
70
+ }
71
+ }
72
+ return NodeSelection.create(doc, pos);
73
+ };
48
74
  export const handleScrollToSelectedTarget = (view) => {
49
75
  const selection = view.state.selection;
50
76
  if (selection.empty) {
@@ -15,12 +15,13 @@
15
15
  */
16
16
  import { trackChangesPluginKey, TrackChangesStatus, } from '@manuscripts/track-changes-plugin';
17
17
  import { getVersion, receiveTransaction, sendableSteps, } from 'prosemirror-collab';
18
- import { NodeSelection, } from 'prosemirror-state';
18
+ import { TextSelection, } from 'prosemirror-state';
19
19
  import { useCallback, useEffect, useRef, useState } from 'react';
20
20
  import { useLocation } from 'react-router-dom';
21
21
  import { createEditorState, createEditorView, } from './configs/ManuscriptsEditor';
22
22
  import { PopperManager } from './lib/popper';
23
23
  import { useDoWithDebounce } from './lib/use-do-with-debounce';
24
+ import { selectionForOutlineNavigation } from './lib/helpers';
24
25
  import { searchReplaceKey } from './plugins/search-replace';
25
26
  export const useEditor = (externalProps) => {
26
27
  const view = useRef(undefined);
@@ -106,12 +107,14 @@ export const useEditor = (externalProps) => {
106
107
  if (!id || !currentView || !state) {
107
108
  return;
108
109
  }
109
- state.doc.descendants((node, pos) => {
110
+ const viewState = currentView.state;
111
+ viewState.doc.descendants((node, pos) => {
110
112
  if (node.attrs.id === id) {
111
113
  currentView.focus();
112
- const selection = NodeSelection.create(state.tr.doc, pos);
113
- currentView.dispatch(state.tr.setSelection(selection));
114
- const dom = currentView.domAtPos(pos + 1);
114
+ const selection = selectionForOutlineNavigation(viewState.doc, pos);
115
+ currentView.dispatch(viewState.tr.setSelection(selection));
116
+ const scrollPos = selection instanceof TextSelection ? selection.from : pos + 1;
117
+ const dom = currentView.domAtPos(scrollPos);
115
118
  if (dom.node instanceof Element) {
116
119
  dom.node.scrollIntoView({
117
120
  behavior: 'smooth',
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.12.34';
1
+ export const VERSION = '3.12.35';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -15,10 +15,12 @@
15
15
  */
16
16
  import { ManuscriptEditorState, ManuscriptNode } from '@manuscripts/transform';
17
17
  import { Node, ResolvedPos } from 'prosemirror-model';
18
+ import { NodeSelection, TextSelection } from 'prosemirror-state';
18
19
  import { EditorView } from 'prosemirror-view';
19
20
  export declare const isNodeOfType: (...type: string[]) => (node: Node) => boolean;
20
21
  export declare const nearestAncestor: (func: (node: ManuscriptNode) => boolean) => ($pos: ResolvedPos) => number | null;
21
22
  export declare const mergeSimilarItems: <T>(compareFunc: (a: T, b: T) => boolean, mergeFunc: (a: T, b: T) => T) => (items: T[]) => T[];
23
+ export declare const selectionForOutlineNavigation: (doc: Node, pos: number) => NodeSelection | TextSelection;
22
24
  export declare const handleScrollToSelectedTarget: (view: EditorView) => boolean;
23
25
  export declare const findWordBoundaries: (state: ManuscriptEditorState, position: number) => {
24
26
  from: number;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.12.34";
1
+ export declare const VERSION = "3.12.35";
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": "3.12.34",
4
+ "version": "3.12.35",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",