@manuscripts/body-editor 2.5.10-LEAN-4065.0 → 2.6.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.
@@ -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 copy_1 = require("../lib/copy");
27
28
  const helpers_1 = require("../lib/helpers");
28
29
  const paste_1 = require("../lib/paste");
29
30
  const plugins_1 = require("../lib/plugins");
@@ -52,6 +53,7 @@ const createEditorView = (props, root, state, dispatch) => {
52
53
  handlePaste: paste_1.handlePaste,
53
54
  clipboardParser: clipboard_1.clipboardParser,
54
55
  handleScrollToSelection: helpers_1.handleScrollToBibliographyItem,
56
+ transformCopied: copy_1.transformCopied,
55
57
  handleClickOn: (view, pos, node, nodePos, event) => {
56
58
  if ((event === null || event === void 0 ? void 0 : event.target) &&
57
59
  event.target.classList.contains('table-context-menu-button')) {
package/dist/cjs/index.js CHANGED
@@ -29,7 +29,7 @@ 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
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.affiliationLabel = exports.authorLabel = exports.metadata = exports.bibliographyPluginKey = exports.footnotesPluginKey = exports.objectsPluginKey = exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
32
+ exports.metadata = exports.bibliographyPluginKey = exports.footnotesPluginKey = exports.objectsPluginKey = exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
33
33
  __exportStar(require("./commands"), exports);
34
34
  var ManuscriptOutline_1 = require("./components/outline/ManuscriptOutline");
35
35
  Object.defineProperty(exports, "ManuscriptOutline", { enumerable: true, get: function () { return ManuscriptOutline_1.ManuscriptOutline; } });
@@ -64,6 +64,3 @@ var bibliography_1 = require("./plugins/bibliography");
64
64
  Object.defineProperty(exports, "bibliographyPluginKey", { enumerable: true, get: function () { return bibliography_1.bibliographyKey; } });
65
65
  var references_1 = require("./lib/references");
66
66
  Object.defineProperty(exports, "metadata", { enumerable: true, get: function () { return references_1.metadata; } });
67
- var authors_1 = require("./lib/authors");
68
- Object.defineProperty(exports, "authorLabel", { enumerable: true, get: function () { return authors_1.authorLabel; } });
69
- Object.defineProperty(exports, "affiliationLabel", { enumerable: true, get: function () { return authors_1.affiliationLabel; } });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformCopied = void 0;
4
+ const transform_1 = require("@manuscripts/transform");
5
+ const prosemirror_model_1 = require("prosemirror-model");
6
+ const prosemirror_utils_1 = require("prosemirror-utils");
7
+ const table_1 = require("./table");
8
+ const transformCopied = (slice, view) => {
9
+ var _a, _b, _c;
10
+ const { state } = view;
11
+ const cutDepth = Math.min(slice.openStart, slice.openEnd);
12
+ const tableSlice = handleTableSelection(slice, view, cutDepth);
13
+ if (tableSlice) {
14
+ return tableSlice;
15
+ }
16
+ if (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
17
+ ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock)) {
18
+ let newSliceContent = [];
19
+ (_c = slice.content.firstChild) === null || _c === void 0 ? void 0 : _c.descendants((node) => {
20
+ var _a, _b;
21
+ if (node.childCount > 1 ||
22
+ (((_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.table_element &&
23
+ ((_b = node.content.lastChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.table_element)) {
24
+ newSliceContent = (0, table_1.updateSliceWithFullTableContent)(state, node.content);
25
+ return false;
26
+ }
27
+ return true;
28
+ });
29
+ if (newSliceContent.length > 1) {
30
+ return new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(newSliceContent), 0, 0);
31
+ }
32
+ else {
33
+ const updateSelection = handleTableSelection(new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(newSliceContent), slice.openStart, slice.openEnd), view, 0);
34
+ if (updateSelection) {
35
+ return updateSelection;
36
+ }
37
+ }
38
+ }
39
+ return slice;
40
+ };
41
+ exports.transformCopied = transformCopied;
42
+ const handleTableSelection = (slice, view, cutDepth) => {
43
+ var _a, _b;
44
+ if ((!view.props.handleKeyDown || !view.state.selection.empty) &&
45
+ (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.table ||
46
+ ((_b = slice.content.firstChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.table_element)) {
47
+ const tableElement = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.table_element)(view.state.selection);
48
+ if (tableElement) {
49
+ return (0, table_1.handleTableSlice)(view, cutDepth, tableElement);
50
+ }
51
+ }
52
+ return null;
53
+ };
@@ -20,6 +20,7 @@ const transform_1 = require("@manuscripts/transform");
20
20
  const prosemirror_model_1 = require("prosemirror-model");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_utils_1 = require("prosemirror-utils");
23
+ const table_1 = require("./table");
23
24
  const removeFirstParagraphIfEmpty = (slice) => {
24
25
  const firstChild = slice.content.firstChild;
25
26
  if (firstChild &&
@@ -64,6 +65,16 @@ const handlePaste = (view, event, slice) => {
64
65
  dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, insertPos)).scrollIntoView());
65
66
  return true;
66
67
  }
68
+ if (slice.content.firstChild &&
69
+ (slice.content.firstChild.type == transform_1.schema.nodes.table_row ||
70
+ slice.content.firstChild.type == transform_1.schema.nodes.table_cell)) {
71
+ const newTable = (0, table_1.createTableFromSlice)(slice, view.state.schema);
72
+ if (newTable) {
73
+ const tr = view.state.tr.insert(view.state.selection.$anchor.pos, newTable);
74
+ view.dispatch(tr);
75
+ return true;
76
+ }
77
+ }
67
78
  if (selection instanceof prosemirror_state_1.TextSelection &&
68
79
  selection.$anchor.parentOffset === 0 &&
69
80
  selection.$head.parentOffset === 0 &&
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateSliceWithFullTableContent = exports.findTableElement = exports.handleTableSlice = exports.createTableFromSlice = void 0;
4
+ const transform_1 = require("@manuscripts/transform");
5
+ const prosemirror_model_1 = require("prosemirror-model");
6
+ const prosemirror_state_1 = require("prosemirror-state");
7
+ const createTableFromSlice = (slice, schema) => {
8
+ const rows = [];
9
+ slice.content.forEach((node) => {
10
+ if (node.type === schema.nodes.table_row) {
11
+ rows.push(node);
12
+ }
13
+ else if (node.type === schema.nodes.table_cell) {
14
+ rows.push(schema.nodes.table_row.create(null, prosemirror_model_1.Fragment.from(node)));
15
+ }
16
+ });
17
+ if (rows.length > 0) {
18
+ return schema.nodes.table.create(null, rows);
19
+ }
20
+ return null;
21
+ };
22
+ exports.createTableFromSlice = createTableFromSlice;
23
+ const handleTableSlice = (view, cutDepth, tableElement) => {
24
+ const { node, pos } = tableElement;
25
+ view.dispatch(view.state.tr.setSelection(prosemirror_state_1.TextSelection.create(view.state.doc, pos, pos + node.nodeSize)));
26
+ return new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(node), cutDepth, cutDepth);
27
+ };
28
+ exports.handleTableSlice = handleTableSlice;
29
+ const findTableElement = (state) => {
30
+ const { from, to } = state.selection;
31
+ let tableNode = null;
32
+ state.doc.nodesBetween(from, to, (node) => {
33
+ if (node.type === transform_1.schema.nodes.table_element) {
34
+ tableNode = node;
35
+ return false;
36
+ }
37
+ return true;
38
+ });
39
+ return { tableNode };
40
+ };
41
+ exports.findTableElement = findTableElement;
42
+ const updateSliceWithFullTableContent = (state, slice) => {
43
+ const newSliceContent = [];
44
+ slice.forEach((node) => {
45
+ if (node.type === transform_1.schema.nodes.table_element) {
46
+ const { tableNode } = (0, exports.findTableElement)(state);
47
+ tableNode && newSliceContent.push(tableNode);
48
+ }
49
+ else {
50
+ newSliceContent.push(node);
51
+ }
52
+ });
53
+ return newSliceContent;
54
+ };
55
+ exports.updateSliceWithFullTableContent = updateSliceWithFullTableContent;
@@ -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.5.10-LEAN-4065.0';
4
+ exports.VERSION = '2.6.0';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -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 { transformCopied } from '../lib/copy';
21
22
  import { handleScrollToBibliographyItem } from '../lib/helpers';
22
23
  import { handlePaste, transformPasted } from '../lib/paste';
23
24
  import { INIT_META } from '../lib/plugins';
@@ -45,6 +46,7 @@ export const createEditorView = (props, root, state, dispatch) => {
45
46
  handlePaste,
46
47
  clipboardParser,
47
48
  handleScrollToSelection: handleScrollToBibliographyItem,
49
+ transformCopied,
48
50
  handleClickOn: (view, pos, node, nodePos, event) => {
49
51
  if ((event === null || event === void 0 ? void 0 : event.target) &&
50
52
  event.target.classList.contains('table-context-menu-button')) {
package/dist/es/index.js CHANGED
@@ -37,4 +37,3 @@ export { objectsKey as objectsPluginKey } from './plugins/objects';
37
37
  export { footnotesKey as footnotesPluginKey } from './plugins/footnotes';
38
38
  export { bibliographyKey as bibliographyPluginKey } from './plugins/bibliography';
39
39
  export { metadata } from './lib/references';
40
- export { authorLabel, affiliationLabel, } from './lib/authors';
@@ -0,0 +1,49 @@
1
+ import { schema } from '@manuscripts/transform';
2
+ import { Fragment, Slice } from 'prosemirror-model';
3
+ import { findParentNodeOfType } from 'prosemirror-utils';
4
+ import { handleTableSlice, updateSliceWithFullTableContent } from './table';
5
+ export const transformCopied = (slice, view) => {
6
+ var _a, _b, _c;
7
+ const { state } = view;
8
+ const cutDepth = Math.min(slice.openStart, slice.openEnd);
9
+ const tableSlice = handleTableSelection(slice, view, cutDepth);
10
+ if (tableSlice) {
11
+ return tableSlice;
12
+ }
13
+ if (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
14
+ ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock)) {
15
+ let newSliceContent = [];
16
+ (_c = slice.content.firstChild) === null || _c === void 0 ? void 0 : _c.descendants((node) => {
17
+ var _a, _b;
18
+ if (node.childCount > 1 ||
19
+ (((_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.table_element &&
20
+ ((_b = node.content.lastChild) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.table_element)) {
21
+ newSliceContent = updateSliceWithFullTableContent(state, node.content);
22
+ return false;
23
+ }
24
+ return true;
25
+ });
26
+ if (newSliceContent.length > 1) {
27
+ return new Slice(Fragment.from(newSliceContent), 0, 0);
28
+ }
29
+ else {
30
+ const updateSelection = handleTableSelection(new Slice(Fragment.from(newSliceContent), slice.openStart, slice.openEnd), view, 0);
31
+ if (updateSelection) {
32
+ return updateSelection;
33
+ }
34
+ }
35
+ }
36
+ return slice;
37
+ };
38
+ const handleTableSelection = (slice, view, cutDepth) => {
39
+ var _a, _b;
40
+ if ((!view.props.handleKeyDown || !view.state.selection.empty) &&
41
+ (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.table ||
42
+ ((_b = slice.content.firstChild) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.table_element)) {
43
+ const tableElement = findParentNodeOfType(schema.nodes.table_element)(view.state.selection);
44
+ if (tableElement) {
45
+ return handleTableSlice(view, cutDepth, tableElement);
46
+ }
47
+ }
48
+ return null;
49
+ };
@@ -17,6 +17,7 @@ import { schema, } from '@manuscripts/transform';
17
17
  import { Fragment } from 'prosemirror-model';
18
18
  import { TextSelection } from 'prosemirror-state';
19
19
  import { findParentNode } from 'prosemirror-utils';
20
+ import { createTableFromSlice } from './table';
20
21
  const removeFirstParagraphIfEmpty = (slice) => {
21
22
  const firstChild = slice.content.firstChild;
22
23
  if (firstChild &&
@@ -60,6 +61,16 @@ export const handlePaste = (view, event, slice) => {
60
61
  dispatch(tr.setSelection(TextSelection.create(tr.doc, insertPos)).scrollIntoView());
61
62
  return true;
62
63
  }
64
+ if (slice.content.firstChild &&
65
+ (slice.content.firstChild.type == schema.nodes.table_row ||
66
+ slice.content.firstChild.type == schema.nodes.table_cell)) {
67
+ const newTable = createTableFromSlice(slice, view.state.schema);
68
+ if (newTable) {
69
+ const tr = view.state.tr.insert(view.state.selection.$anchor.pos, newTable);
70
+ view.dispatch(tr);
71
+ return true;
72
+ }
73
+ }
63
74
  if (selection instanceof TextSelection &&
64
75
  selection.$anchor.parentOffset === 0 &&
65
76
  selection.$head.parentOffset === 0 &&
@@ -0,0 +1,48 @@
1
+ import { schema, } from '@manuscripts/transform';
2
+ import { Fragment, Slice } from 'prosemirror-model';
3
+ import { TextSelection } from 'prosemirror-state';
4
+ export const createTableFromSlice = (slice, schema) => {
5
+ const rows = [];
6
+ slice.content.forEach((node) => {
7
+ if (node.type === schema.nodes.table_row) {
8
+ rows.push(node);
9
+ }
10
+ else if (node.type === schema.nodes.table_cell) {
11
+ rows.push(schema.nodes.table_row.create(null, Fragment.from(node)));
12
+ }
13
+ });
14
+ if (rows.length > 0) {
15
+ return schema.nodes.table.create(null, rows);
16
+ }
17
+ return null;
18
+ };
19
+ export const handleTableSlice = (view, cutDepth, tableElement) => {
20
+ const { node, pos } = tableElement;
21
+ view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos, pos + node.nodeSize)));
22
+ return new Slice(Fragment.from(node), cutDepth, cutDepth);
23
+ };
24
+ export const findTableElement = (state) => {
25
+ const { from, to } = state.selection;
26
+ let tableNode = null;
27
+ state.doc.nodesBetween(from, to, (node) => {
28
+ if (node.type === schema.nodes.table_element) {
29
+ tableNode = node;
30
+ return false;
31
+ }
32
+ return true;
33
+ });
34
+ return { tableNode };
35
+ };
36
+ export const updateSliceWithFullTableContent = (state, slice) => {
37
+ const newSliceContent = [];
38
+ slice.forEach((node) => {
39
+ if (node.type === schema.nodes.table_element) {
40
+ const { tableNode } = findTableElement(state);
41
+ tableNode && newSliceContent.push(tableNode);
42
+ }
43
+ else {
44
+ newSliceContent.push(node);
45
+ }
46
+ });
47
+ return newSliceContent;
48
+ };
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.5.10-LEAN-4065.0';
1
+ export const VERSION = '2.6.0';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -38,4 +38,3 @@ export { objectsKey as objectsPluginKey } from './plugins/objects';
38
38
  export { footnotesKey as footnotesPluginKey } from './plugins/footnotes';
39
39
  export { bibliographyKey as bibliographyPluginKey } from './plugins/bibliography';
40
40
  export { metadata, BibliographyItemAttrs } from './lib/references';
41
- export { authorLabel, affiliationLabel, AffiliationAttrs, ContributorAttrs, } from './lib/authors';
@@ -0,0 +1,3 @@
1
+ import { Slice } from 'prosemirror-model';
2
+ import { EditorView } from 'prosemirror-view';
3
+ export declare const transformCopied: (slice: Slice, view: EditorView) => Slice;
@@ -0,0 +1,9 @@
1
+ import { ManuscriptEditorState, ManuscriptEditorView } from '@manuscripts/transform';
2
+ import { Fragment, Node, Schema, Slice } from 'prosemirror-model';
3
+ import { ContentNodeWithPos } from 'prosemirror-utils';
4
+ export declare const createTableFromSlice: (slice: Slice, schema: Schema) => Node | null;
5
+ export declare const handleTableSlice: (view: ManuscriptEditorView, cutDepth: number, tableElement: ContentNodeWithPos) => Slice;
6
+ export declare const findTableElement: (state: ManuscriptEditorState) => {
7
+ tableNode: null;
8
+ };
9
+ export declare const updateSliceWithFullTableContent: (state: ManuscriptEditorState, slice: Fragment) => Node[];
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.5.10-LEAN-4065.0";
1
+ export declare const VERSION = "2.6.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.5.10-LEAN-4065.0",
4
+ "version": "2.6.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",