@manuscripts/body-editor 1.6.5 → 1.6.6

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.
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.createEditorView = exports.createEditorState = void 0;
21
22
  require("prosemirror-view/style/prosemirror.css");
22
23
  const transform_1 = require("@manuscripts/transform");
23
24
  const prosemirror_state_1 = require("prosemirror-state");
@@ -25,26 +26,24 @@ const prosemirror_view_1 = require("prosemirror-view");
25
26
  const paste_1 = require("../lib/paste");
26
27
  const editor_plugins_1 = __importDefault(require("./editor-plugins"));
27
28
  const editor_views_1 = __importDefault(require("./editor-views"));
28
- exports.default = {
29
- createState: (props) => {
30
- return prosemirror_state_1.EditorState.create({
31
- doc: props.doc,
32
- schema: transform_1.schema,
33
- plugins: (0, editor_plugins_1.default)(props),
34
- });
29
+ const createEditorState = (props) => prosemirror_state_1.EditorState.create({
30
+ doc: props.doc,
31
+ schema: transform_1.schema,
32
+ plugins: (0, editor_plugins_1.default)(props),
33
+ });
34
+ exports.createEditorState = createEditorState;
35
+ const createEditorView = (props, root, state, dispatch) => new prosemirror_view_1.EditorView(root, {
36
+ state,
37
+ editable: () => props.getCapabilities().editArticle,
38
+ scrollMargin: {
39
+ top: 100,
40
+ bottom: 100,
41
+ left: 0,
42
+ right: 0,
35
43
  },
36
- createView: (props) => (el, state, dispatch) => new prosemirror_view_1.EditorView(el, {
37
- state,
38
- editable: () => props.getCapabilities().editArticle,
39
- scrollMargin: {
40
- top: 100,
41
- bottom: 100,
42
- left: 0,
43
- right: 0,
44
- },
45
- dispatchTransaction: dispatch,
46
- nodeViews: (0, editor_views_1.default)(props, dispatch),
47
- attributes: props.attributes,
48
- transformPasted: paste_1.transformPasted,
49
- }),
50
- };
44
+ dispatchTransaction: dispatch,
45
+ nodeViews: (0, editor_views_1.default)(props, dispatch),
46
+ attributes: props.attributes,
47
+ transformPasted: paste_1.transformPasted,
48
+ });
49
+ exports.createEditorView = createEditorView;
package/dist/cjs/index.js CHANGED
@@ -28,11 +28,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
28
28
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
- var __importDefault = (this && this.__importDefault) || function (mod) {
32
- return (mod && mod.__esModule) ? mod : { "default": mod };
33
- };
34
31
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.ManuscriptsEditor = exports.useEditor = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.toolbar = exports.PopperManager = exports.CollabProvider = exports.getMenus = exports.ManuscriptToolbar = exports.OutlineManuscript = exports.OutlineItemIcon = exports.ManuscriptOutline = exports.DialogNames = exports.DialogController = void 0;
32
+ exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.toolbar = exports.PopperManager = exports.CollabProvider = exports.ManuscriptToolbar = exports.OutlineManuscript = exports.OutlineItemIcon = exports.ManuscriptOutline = exports.DialogNames = exports.DialogController = void 0;
36
33
  __exportStar(require("./citation-sources"), exports);
37
34
  __exportStar(require("./commands"), exports);
38
35
  __exportStar(require("./components/application-menu"), exports);
@@ -47,8 +44,7 @@ var OutlineManuscript_1 = require("./components/outline/OutlineManuscript");
47
44
  Object.defineProperty(exports, "OutlineManuscript", { enumerable: true, get: function () { return OutlineManuscript_1.OutlineManuscript; } });
48
45
  var ManuscriptToolbar_1 = require("./components/toolbar/ManuscriptToolbar");
49
46
  Object.defineProperty(exports, "ManuscriptToolbar", { enumerable: true, get: function () { return ManuscriptToolbar_1.ManuscriptToolbar; } });
50
- var menus_1 = require("./menus");
51
- Object.defineProperty(exports, "getMenus", { enumerable: true, get: function () { return __importDefault(menus_1).default; } });
47
+ __exportStar(require("./menus"), exports);
52
48
  var collabProvider_1 = require("./classes/collabProvider");
53
49
  Object.defineProperty(exports, "CollabProvider", { enumerable: true, get: function () { return collabProvider_1.CollabProvider; } });
54
50
  var popper_1 = require("./lib/popper");
@@ -62,7 +58,4 @@ Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: funct
62
58
  Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
63
59
  __exportStar(require("./plugins/keywords"), exports);
64
60
  __exportStar(require("./lib/utils"), exports);
65
- var useEditor_1 = require("./useEditor");
66
- Object.defineProperty(exports, "useEditor", { enumerable: true, get: function () { return __importDefault(useEditor_1).default; } });
67
- var ManuscriptsEditor_1 = require("./configs//ManuscriptsEditor");
68
- Object.defineProperty(exports, "ManuscriptsEditor", { enumerable: true, get: function () { return __importDefault(ManuscriptsEditor_1).default; } });
61
+ __exportStar(require("./useEditor"), exports);
package/dist/cjs/menus.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getMenus = void 0;
18
19
  const transform_1 = require("@manuscripts/transform");
19
20
  const prosemirror_commands_1 = require("prosemirror-commands");
20
21
  const prosemirror_history_1 = require("prosemirror-history");
@@ -24,7 +25,7 @@ const commands_1 = require("./commands");
24
25
  const dialog_1 = require("./components/dialog");
25
26
  const list_1 = require("./keys/list");
26
27
  const hierarchy_1 = require("./lib/hierarchy");
27
- exports.default = (editor, handleOpenDialog, footnotesEnabled, contentEditable) => {
28
+ const getMenus = (editor, handleOpenDialog, footnotesEnabled, contentEditable) => {
28
29
  const { isCommandValid, state } = editor;
29
30
  const wrap = (command) => () => editor.doCommand(command);
30
31
  let menus = [
@@ -438,3 +439,4 @@ exports.default = (editor, handleOpenDialog, footnotesEnabled, contentEditable)
438
439
  return menuGroup;
439
440
  });
440
441
  };
442
+ exports.getMenus = getMenus;
@@ -24,19 +24,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  });
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.useEditor = void 0;
27
28
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
28
29
  const prosemirror_collab_1 = require("prosemirror-collab");
29
30
  const prosemirror_state_1 = require("prosemirror-state");
30
31
  const react_1 = require("react");
31
32
  const react_router_dom_1 = require("react-router-dom");
33
+ const ManuscriptsEditor_1 = require("./configs/ManuscriptsEditor");
32
34
  const use_do_with_debounce_1 = require("./lib/use-do-with-debounce");
33
- const bibliography_1 = require("./plugins/bibliography");
34
- const useEditor = (initialState, createView, editorProps) => {
35
+ const useEditor = (props) => {
35
36
  const view = (0, react_1.useRef)();
36
- const [state, setState] = (0, react_1.useState)(initialState);
37
- const [viewElement, setViewElement] = (0, react_1.useState)(null);
37
+ const [state, setState] = (0, react_1.useState)(() => (0, ManuscriptsEditor_1.createEditorState)(props));
38
38
  const history = (0, react_router_dom_1.useHistory)();
39
- const { collabProvider } = editorProps;
39
+ const { collabProvider } = props;
40
40
  if (collabProvider) {
41
41
  collabProvider.onNewSteps((newVersion, steps, clientIDs) => __awaiter(void 0, void 0, void 0, function* () {
42
42
  if (state && view.current) {
@@ -70,26 +70,15 @@ const useEditor = (initialState, createView, editorProps) => {
70
70
  debounce(() => {
71
71
  setState(nextState);
72
72
  }, 200, !tr.isGeneric);
73
- return state;
73
+ return nextState;
74
74
  }, []);
75
- const replaceView = (state, createView) => {
76
- if (viewElement && view.current) {
77
- view.current.destroy();
78
- view.current = createView(viewElement, state, dispatch);
79
- setState(view.current.state);
80
- }
81
- };
82
75
  const onRender = (0, react_1.useCallback)((el) => {
83
76
  var _a;
84
77
  if (!el) {
85
78
  return;
86
79
  }
87
- view.current = createView(el, ((_a = view.current) === null || _a === void 0 ? void 0 : _a.state) || state, dispatch);
80
+ view.current = (0, ManuscriptsEditor_1.createEditorView)(props, el, ((_a = view.current) === null || _a === void 0 ? void 0 : _a.state) || state, dispatch);
88
81
  setState(view.current.state);
89
- setViewElement(el);
90
- view.current.dispatch(view.current.state.tr.setMeta(bibliography_1.bibliographyKey, {
91
- initCitations: true,
92
- }));
93
82
  }, []);
94
83
  const isCommandValid = (0, react_1.useCallback)((command) => command(state), [state]);
95
84
  const doCommand = (0, react_1.useCallback)((command) => command(state, dispatch, view.current), [state, dispatch]);
@@ -138,9 +127,8 @@ const useEditor = (initialState, createView, editorProps) => {
138
127
  isCommandValid,
139
128
  doCommand,
140
129
  replaceState,
141
- replaceView,
142
130
  view: view.current,
143
131
  dispatch,
144
132
  };
145
133
  };
146
- exports.default = useEditor;
134
+ exports.useEditor = useEditor;
@@ -20,26 +20,22 @@ import { EditorView } from 'prosemirror-view';
20
20
  import { transformPasted } from '../lib/paste';
21
21
  import plugins from './editor-plugins';
22
22
  import views from './editor-views';
23
- export default {
24
- createState: (props) => {
25
- return EditorState.create({
26
- doc: props.doc,
27
- schema,
28
- plugins: plugins(props),
29
- });
23
+ export const createEditorState = (props) => EditorState.create({
24
+ doc: props.doc,
25
+ schema,
26
+ plugins: plugins(props),
27
+ });
28
+ export const createEditorView = (props, root, state, dispatch) => new EditorView(root, {
29
+ state,
30
+ editable: () => props.getCapabilities().editArticle,
31
+ scrollMargin: {
32
+ top: 100,
33
+ bottom: 100,
34
+ left: 0,
35
+ right: 0,
30
36
  },
31
- createView: (props) => (el, state, dispatch) => new EditorView(el, {
32
- state,
33
- editable: () => props.getCapabilities().editArticle,
34
- scrollMargin: {
35
- top: 100,
36
- bottom: 100,
37
- left: 0,
38
- right: 0,
39
- },
40
- dispatchTransaction: dispatch,
41
- nodeViews: views(props, dispatch),
42
- attributes: props.attributes,
43
- transformPasted,
44
- }),
45
- };
37
+ dispatchTransaction: dispatch,
38
+ nodeViews: views(props, dispatch),
39
+ attributes: props.attributes,
40
+ transformPasted,
41
+ });
package/dist/es/index.js CHANGED
@@ -21,7 +21,7 @@ export { ManuscriptOutline } from './components/outline/ManuscriptOutline';
21
21
  export { OutlineItemIcon } from './components/outline/Outline';
22
22
  export { OutlineManuscript } from './components/outline/OutlineManuscript';
23
23
  export { ManuscriptToolbar, } from './components/toolbar/ManuscriptToolbar';
24
- export { default as getMenus } from './menus';
24
+ export * from './menus';
25
25
  export { CollabProvider } from './classes/collabProvider';
26
26
  export { PopperManager } from './lib/popper';
27
27
  export { toolbar } from './toolbar';
@@ -29,5 +29,4 @@ export * from './plugins/highlight';
29
29
  export { commentScroll, isThereSelector, isHighlightComment, } from './plugins/comment_annotation';
30
30
  export * from './plugins/keywords';
31
31
  export * from './lib/utils';
32
- export { default as useEditor } from './useEditor';
33
- export { default as ManuscriptsEditor } from './configs//ManuscriptsEditor';
32
+ export * from './useEditor';
package/dist/es/menus.js CHANGED
@@ -22,7 +22,7 @@ import { addComment, blockActive, canInsert, ifInTableBody, insertBibliographySe
22
22
  import { DialogNames } from './components/dialog';
23
23
  import { skipTrackingChanges } from './keys/list';
24
24
  import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
25
- export default (editor, handleOpenDialog, footnotesEnabled, contentEditable) => {
25
+ export const getMenus = (editor, handleOpenDialog, footnotesEnabled, contentEditable) => {
26
26
  const { isCommandValid, state } = editor;
27
27
  const wrap = (command) => () => editor.doCommand(command);
28
28
  let menus = [
@@ -27,14 +27,13 @@ import { getVersion, receiveTransaction, sendableSteps, } from 'prosemirror-coll
27
27
  import { NodeSelection, } from 'prosemirror-state';
28
28
  import { useCallback, useEffect, useRef, useState } from 'react';
29
29
  import { useHistory } from 'react-router-dom';
30
+ import { createEditorState, createEditorView, } from './configs/ManuscriptsEditor';
30
31
  import { useDoWithDebounce } from './lib/use-do-with-debounce';
31
- import { bibliographyKey } from './plugins/bibliography';
32
- const useEditor = (initialState, createView, editorProps) => {
32
+ export const useEditor = (props) => {
33
33
  const view = useRef();
34
- const [state, setState] = useState(initialState);
35
- const [viewElement, setViewElement] = useState(null);
34
+ const [state, setState] = useState(() => createEditorState(props));
36
35
  const history = useHistory();
37
- const { collabProvider } = editorProps;
36
+ const { collabProvider } = props;
38
37
  if (collabProvider) {
39
38
  collabProvider.onNewSteps((newVersion, steps, clientIDs) => __awaiter(void 0, void 0, void 0, function* () {
40
39
  if (state && view.current) {
@@ -68,26 +67,15 @@ const useEditor = (initialState, createView, editorProps) => {
68
67
  debounce(() => {
69
68
  setState(nextState);
70
69
  }, 200, !tr.isGeneric);
71
- return state;
70
+ return nextState;
72
71
  }, []);
73
- const replaceView = (state, createView) => {
74
- if (viewElement && view.current) {
75
- view.current.destroy();
76
- view.current = createView(viewElement, state, dispatch);
77
- setState(view.current.state);
78
- }
79
- };
80
72
  const onRender = useCallback((el) => {
81
73
  var _a;
82
74
  if (!el) {
83
75
  return;
84
76
  }
85
- view.current = createView(el, ((_a = view.current) === null || _a === void 0 ? void 0 : _a.state) || state, dispatch);
77
+ view.current = createEditorView(props, el, ((_a = view.current) === null || _a === void 0 ? void 0 : _a.state) || state, dispatch);
86
78
  setState(view.current.state);
87
- setViewElement(el);
88
- view.current.dispatch(view.current.state.tr.setMeta(bibliographyKey, {
89
- initCitations: true,
90
- }));
91
79
  }, []);
92
80
  const isCommandValid = useCallback((command) => command(state), [state]);
93
81
  const doCommand = useCallback((command) => command(state, dispatch, view.current), [state, dispatch]);
@@ -136,9 +124,7 @@ const useEditor = (initialState, createView, editorProps) => {
136
124
  isCommandValid,
137
125
  doCommand,
138
126
  replaceState,
139
- replaceView,
140
127
  view: view.current,
141
128
  dispatch,
142
129
  };
143
130
  };
144
- export default useEditor;
@@ -19,11 +19,12 @@ import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style
19
19
  import { Build, ManuscriptNode } from '@manuscripts/transform';
20
20
  import { History } from 'history';
21
21
  import { EditorState, Plugin } from 'prosemirror-state';
22
+ import { EditorView } from 'prosemirror-view';
22
23
  import React from 'react';
23
24
  import { DefaultTheme } from 'styled-components';
24
25
  import { CollabProvider } from '../classes/collabProvider';
26
+ import { Dispatch } from '../commands';
25
27
  import { PopperManager } from '../lib/popper';
26
- import { CreateView } from '../useEditor';
27
28
  export type CSLProps = {
28
29
  style?: string;
29
30
  locale?: string;
@@ -58,8 +59,5 @@ export interface EditorProps {
58
59
  environment?: string;
59
60
  collabProvider?: CollabProvider;
60
61
  }
61
- declare const _default: {
62
- createState: (props: EditorProps) => EditorState;
63
- createView: (props: EditorProps) => CreateView;
64
- };
65
- export default _default;
62
+ export declare const createEditorState: (props: EditorProps) => EditorState;
63
+ export declare const createEditorView: (props: EditorProps, root: HTMLElement, state: EditorState, dispatch: Dispatch) => EditorView;
@@ -21,7 +21,7 @@ export { ManuscriptOutline } from './components/outline/ManuscriptOutline';
21
21
  export { OutlineItemIcon } from './components/outline/Outline';
22
22
  export { OutlineManuscript } from './components/outline/OutlineManuscript';
23
23
  export { ManuscriptToolbar, ToolbarButtonConfig, } from './components/toolbar/ManuscriptToolbar';
24
- export { default as getMenus } from './menus';
24
+ export * from './menus';
25
25
  export { ChangeReceiver } from './types';
26
26
  export { CollabProvider } from './classes/collabProvider';
27
27
  export { PopperManager } from './lib/popper';
@@ -30,5 +30,4 @@ export * from './plugins/highlight';
30
30
  export { commentScroll, isThereSelector, isHighlightComment, } from './plugins/comment_annotation';
31
31
  export * from './plugins/keywords';
32
32
  export * from './lib/utils';
33
- export { default as useEditor } from './useEditor';
34
- export { default as ManuscriptsEditor } from './configs//ManuscriptsEditor';
33
+ export * from './useEditor';
@@ -15,6 +15,5 @@
15
15
  */
16
16
  import { MenuSpec } from './components/application-menu';
17
17
  import { DialogNames } from './components/dialog';
18
- import useEditor from './useEditor';
19
- declare const _default: (editor: ReturnType<typeof useEditor>, handleOpenDialog: (dialog: DialogNames) => void, footnotesEnabled?: boolean, contentEditable?: boolean) => MenuSpec[];
20
- export default _default;
18
+ import { useEditor } from './useEditor';
19
+ export declare const getMenus: (editor: ReturnType<typeof useEditor>, handleOpenDialog: (dialog: DialogNames) => void, footnotesEnabled?: boolean, contentEditable?: boolean) => MenuSpec[];
@@ -16,15 +16,12 @@
16
16
  import { Command, EditorState, Transaction } from 'prosemirror-state';
17
17
  import { EditorView } from 'prosemirror-view';
18
18
  import { EditorProps } from './configs/ManuscriptsEditor';
19
- export type CreateView = (element: HTMLDivElement, state: EditorState, dispatch: (tr: Transaction) => EditorState) => EditorView;
20
- declare const useEditor: (initialState: EditorState, createView: CreateView, editorProps: EditorProps) => {
19
+ export declare const useEditor: (props: EditorProps) => {
21
20
  state: EditorState;
22
21
  onRender: (el: HTMLDivElement | null) => void;
23
22
  isCommandValid: (command: Command) => boolean;
24
23
  doCommand: (command: Command) => boolean;
25
24
  replaceState: (state: EditorState) => void;
26
- replaceView: (state: EditorState, createView: CreateView) => void;
27
25
  view: EditorView | undefined;
28
26
  dispatch: (tr: Transaction) => EditorState;
29
27
  };
30
- export default useEditor;
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.6.5",
4
+ "version": "1.6.6",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -128,4 +128,4 @@
128
128
  "resolutions": {
129
129
  "@types/react": "^17.0.2"
130
130
  }
131
- }
131
+ }