@manuscripts/body-editor 1.7.23 → 1.7.24-LEAN-3338-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.
@@ -311,17 +311,18 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
311
311
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
312
312
  kind,
313
313
  });
314
- const insertedAt = state.selection.to;
315
314
  const node = state.schema.nodes.inline_footnote.create({
316
315
  rids: [footnote.attrs.id],
317
316
  });
318
- const tr = state.tr;
317
+ const insertedAt = state.selection.to;
318
+ const { tr } = state;
319
319
  tr.insert(insertedAt, node);
320
320
  const footnotesSection = (0, prosemirror_utils_1.findChildrenByType)(tr.doc, transform_1.schema.nodes.footnotes_section)[0];
321
321
  let selectionPos;
322
322
  if (!footnotesSection) {
323
+ const sectionTitle = 'Footnotes';
323
324
  const section = state.schema.nodes.footnotes_section.create({}, [
324
- state.schema.nodes.section_title.create({}, state.schema.text('Notes')),
325
+ state.schema.nodes.section_title.create({}, state.schema.text(sectionTitle)),
325
326
  state.schema.nodes.footnotes_element.create({}, footnote),
326
327
  ]);
327
328
  const backmatter = (0, prosemirror_utils_1.findChildrenByType)(tr.doc, transform_1.schema.nodes.backmatter)[0];
@@ -330,10 +331,25 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
330
331
  }
331
332
  else {
332
333
  const footnoteElement = (0, prosemirror_utils_1.findChildrenByType)(footnotesSection.node, transform_1.schema.nodes.footnotes_element);
333
- const pos = footnotesSection.pos +
334
- footnoteElement[0].pos +
335
- footnoteElement[0].node.nodeSize -
336
- 1;
334
+ let index = 0;
335
+ state.doc.slice(0, insertedAt).content.descendants((node) => {
336
+ if (node.type === transform_1.schema.nodes.inline_footnote) {
337
+ index++;
338
+ return false;
339
+ }
340
+ });
341
+ let correctPosition = 0;
342
+ if (index != 0) {
343
+ footnoteElement[0].node.descendants((node, pos, parent, nodeIndex) => {
344
+ if (node.type === transform_1.schema.nodes.footnote) {
345
+ if (index > nodeIndex) {
346
+ correctPosition = pos + node.nodeSize;
347
+ return false;
348
+ }
349
+ }
350
+ });
351
+ }
352
+ const pos = footnotesSection.pos + footnoteElement[0].pos + correctPosition + 2;
337
353
  tr.insert(pos, footnote);
338
354
  selectionPos = pos + 2;
339
355
  }
@@ -20,6 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  require("prosemirror-gapcursor/style/gapcursor.css");
22
22
  require("prosemirror-tables/style/tables.css");
23
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
23
24
  const prosemirror_collab_1 = require("prosemirror-collab");
24
25
  const prosemirror_dropcursor_1 = require("prosemirror-dropcursor");
25
26
  const prosemirror_history_1 = require("prosemirror-history");
@@ -41,13 +42,18 @@ const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fi
41
42
  const toc_1 = __importDefault(require("../plugins/toc"));
42
43
  const rules_1 = __importDefault(require("../rules"));
43
44
  exports.default = (props) => {
44
- const plugins = props.plugins || [];
45
45
  const allPlugins = [
46
46
  rules_1.default,
47
47
  ...keys_1.default,
48
48
  (0, prosemirror_dropcursor_1.dropCursor)(),
49
49
  (0, prosemirror_history_1.history)(),
50
- ...plugins,
50
+ (0, track_changes_plugin_1.trackChangesPlugin)({
51
+ userID: props.userID,
52
+ debug: props.debug,
53
+ initialStatus: props.getCapabilities().editWithoutTracking
54
+ ? track_changes_plugin_1.TrackChangesStatus.disabled
55
+ : track_changes_plugin_1.TrackChangesStatus.enabled,
56
+ }),
51
57
  (0, tables_cursor_fix_1.default)(),
52
58
  (0, elements_1.default)(),
53
59
  (0, persist_1.default)(),
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.findTableInlineFootnoteIds = void 0;
18
+ exports.createFootnoteLabel = exports.findTableInlineFootnoteIds = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const prosemirror_utils_1 = require("prosemirror-utils");
21
21
  const findTableInlineFootnoteIds = ($pos) => {
@@ -28,3 +28,15 @@ const findTableInlineFootnoteIds = ($pos) => {
28
28
  : []);
29
29
  };
30
30
  exports.findTableInlineFootnoteIds = findTableInlineFootnoteIds;
31
+ const createFootnoteLabel = (id) => {
32
+ const _id = parseInt(id, 10) + 1;
33
+ const START = 96;
34
+ const RANGE = 26;
35
+ const id1 = _id % RANGE || RANGE;
36
+ const id2 = Math.ceil(_id / RANGE);
37
+ const label = id2 === 1
38
+ ? String.fromCharCode(START + id1)
39
+ : `${String.fromCharCode(START + id2 - 1)}${String.fromCharCode(START + id1)}`;
40
+ return label;
41
+ };
42
+ exports.createFootnoteLabel = createFootnoteLabel;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.uncitedFootnoteWidget = exports.buildPluginState = exports.footnotesKey = void 0;
18
+ exports.getFootnotesPluginState = exports.uncitedFootnoteWidget = exports.buildPluginState = exports.footnotesKey = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const lodash_1 = require("lodash");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
@@ -36,7 +36,7 @@ const buildPluginState = (doc) => {
36
36
  parentNode.type !== transform_1.schema.nodes.table_cell) {
37
37
  nodes.push([node, pos]);
38
38
  node.attrs.rids.forEach((rid) => {
39
- labels.set(rid, String(++index));
39
+ labels.set(rid, (0, footnotes_utils_1.createFootnoteLabel)(String(index++)));
40
40
  });
41
41
  }
42
42
  });
@@ -45,8 +45,9 @@ const buildPluginState = (doc) => {
45
45
  exports.buildPluginState = buildPluginState;
46
46
  const scrollToInlineFootnote = (rid, view) => {
47
47
  view.state.doc.descendants((node, pos) => {
48
+ var _a;
48
49
  const footnote = node;
49
- if (footnote.attrs.rids.includes(rid)) {
50
+ if ((_a = footnote.attrs.rids) === null || _a === void 0 ? void 0 : _a.includes(rid)) {
50
51
  const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, pos);
51
52
  view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
52
53
  }
@@ -148,3 +149,7 @@ exports.default = () => {
148
149
  },
149
150
  });
150
151
  };
152
+ const getFootnotesPluginState = (state) => {
153
+ return exports.footnotesKey.getState(state);
154
+ };
155
+ exports.getFootnotesPluginState = getFootnotesPluginState;
@@ -81,10 +81,8 @@ exports.defaultEditorProps = {
81
81
  locale: '',
82
82
  },
83
83
  getCitationProvider: () => undefined,
84
- plugins: [],
85
84
  retrySync: () => Promise.resolve(),
86
85
  setComment: () => undefined,
87
86
  setSelectedComment: () => undefined,
88
87
  setEditorSelectedSuggestion: () => undefined,
89
- environment: undefined,
90
88
  };
@@ -60,8 +60,7 @@ const useEditor = (props) => {
60
60
  view.current.updateState(nextState);
61
61
  const trackState = track_changes_plugin_1.trackChangesPluginKey.getState(view.current.state);
62
62
  if (collabProvider &&
63
- trackState &&
64
- trackState.status !== track_changes_plugin_1.TrackChangesStatus.viewSnapshots) {
63
+ (!trackState || trackState.status !== track_changes_plugin_1.TrackChangesStatus.viewSnapshots)) {
65
64
  const sendable = (0, prosemirror_collab_1.sendableSteps)(nextState);
66
65
  if (sendable) {
67
66
  collabProvider.sendSteps(sendable.version, sendable.steps, sendable.clientID, !tr.isGeneric);
@@ -23,7 +23,7 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
23
23
  constructor() {
24
24
  super(...arguments);
25
25
  this.handleClick = () => {
26
- this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
26
+ this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rids[0] }));
27
27
  };
28
28
  this.updateContents = () => {
29
29
  this.setDomAttrs(this.node, this.dom);
@@ -292,17 +292,18 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
292
292
  id: generateID(ObjectTypes.Footnote),
293
293
  kind,
294
294
  });
295
- const insertedAt = state.selection.to;
296
295
  const node = state.schema.nodes.inline_footnote.create({
297
296
  rids: [footnote.attrs.id],
298
297
  });
299
- const tr = state.tr;
298
+ const insertedAt = state.selection.to;
299
+ const { tr } = state;
300
300
  tr.insert(insertedAt, node);
301
301
  const footnotesSection = findChildrenByType(tr.doc, schema.nodes.footnotes_section)[0];
302
302
  let selectionPos;
303
303
  if (!footnotesSection) {
304
+ const sectionTitle = 'Footnotes';
304
305
  const section = state.schema.nodes.footnotes_section.create({}, [
305
- state.schema.nodes.section_title.create({}, state.schema.text('Notes')),
306
+ state.schema.nodes.section_title.create({}, state.schema.text(sectionTitle)),
306
307
  state.schema.nodes.footnotes_element.create({}, footnote),
307
308
  ]);
308
309
  const backmatter = findChildrenByType(tr.doc, schema.nodes.backmatter)[0];
@@ -311,10 +312,25 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
311
312
  }
312
313
  else {
313
314
  const footnoteElement = findChildrenByType(footnotesSection.node, schema.nodes.footnotes_element);
314
- const pos = footnotesSection.pos +
315
- footnoteElement[0].pos +
316
- footnoteElement[0].node.nodeSize -
317
- 1;
315
+ let index = 0;
316
+ state.doc.slice(0, insertedAt).content.descendants((node) => {
317
+ if (node.type === schema.nodes.inline_footnote) {
318
+ index++;
319
+ return false;
320
+ }
321
+ });
322
+ let correctPosition = 0;
323
+ if (index != 0) {
324
+ footnoteElement[0].node.descendants((node, pos, parent, nodeIndex) => {
325
+ if (node.type === schema.nodes.footnote) {
326
+ if (index > nodeIndex) {
327
+ correctPosition = pos + node.nodeSize;
328
+ return false;
329
+ }
330
+ }
331
+ });
332
+ }
333
+ const pos = footnotesSection.pos + footnoteElement[0].pos + correctPosition + 2;
318
334
  tr.insert(pos, footnote);
319
335
  selectionPos = pos + 2;
320
336
  }
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import 'prosemirror-gapcursor/style/gapcursor.css';
17
17
  import 'prosemirror-tables/style/tables.css';
18
+ import { trackChangesPlugin, TrackChangesStatus, } from '@manuscripts/track-changes-plugin';
18
19
  import { collab } from 'prosemirror-collab';
19
20
  import { dropCursor } from 'prosemirror-dropcursor';
20
21
  import { history } from 'prosemirror-history';
@@ -36,13 +37,18 @@ import table_editing_fix from '../plugins/tables-cursor-fix';
36
37
  import toc from '../plugins/toc';
37
38
  import rules from '../rules';
38
39
  export default (props) => {
39
- const plugins = props.plugins || [];
40
40
  const allPlugins = [
41
41
  rules,
42
42
  ...keys,
43
43
  dropCursor(),
44
44
  history(),
45
- ...plugins,
45
+ trackChangesPlugin({
46
+ userID: props.userID,
47
+ debug: props.debug,
48
+ initialStatus: props.getCapabilities().editWithoutTracking
49
+ ? TrackChangesStatus.disabled
50
+ : TrackChangesStatus.enabled,
51
+ }),
46
52
  table_editing_fix(),
47
53
  elements(),
48
54
  persist(),
@@ -24,3 +24,14 @@ export const findTableInlineFootnoteIds = ($pos) => {
24
24
  .flat()
25
25
  : []);
26
26
  };
27
+ export const createFootnoteLabel = (id) => {
28
+ const _id = parseInt(id, 10) + 1;
29
+ const START = 96;
30
+ const RANGE = 26;
31
+ const id1 = _id % RANGE || RANGE;
32
+ const id2 = Math.ceil(_id / RANGE);
33
+ const label = id2 === 1
34
+ ? String.fromCharCode(START + id1)
35
+ : `${String.fromCharCode(START + id2 - 1)}${String.fromCharCode(START + id1)}`;
36
+ return label;
37
+ };
@@ -15,13 +15,13 @@
15
15
  */
16
16
  import { isFootnoteNode, isInlineFootnoteNode, schema, } from '@manuscripts/transform';
17
17
  import { isEqual } from 'lodash';
18
- import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
18
+ import { NodeSelection, Plugin, PluginKey, } from 'prosemirror-state';
19
19
  import { hasParentNodeOfType } from 'prosemirror-utils';
20
20
  import { Decoration, DecorationSet } from 'prosemirror-view';
21
21
  import { alertIcon } from '../../assets';
22
22
  import { findParentNodeWithIdValue } from '../../lib/utils';
23
23
  import { placeholderWidget } from '../placeholder';
24
- import { findTableInlineFootnoteIds } from './footnotes-utils';
24
+ import { createFootnoteLabel, findTableInlineFootnoteIds, } from './footnotes-utils';
25
25
  export const footnotesKey = new PluginKey('footnotes');
26
26
  export const buildPluginState = (doc) => {
27
27
  const nodes = [];
@@ -33,7 +33,7 @@ export const buildPluginState = (doc) => {
33
33
  parentNode.type !== schema.nodes.table_cell) {
34
34
  nodes.push([node, pos]);
35
35
  node.attrs.rids.forEach((rid) => {
36
- labels.set(rid, String(++index));
36
+ labels.set(rid, createFootnoteLabel(String(index++)));
37
37
  });
38
38
  }
39
39
  });
@@ -41,8 +41,9 @@ export const buildPluginState = (doc) => {
41
41
  };
42
42
  const scrollToInlineFootnote = (rid, view) => {
43
43
  view.state.doc.descendants((node, pos) => {
44
+ var _a;
44
45
  const footnote = node;
45
- if (footnote.attrs.rids.includes(rid)) {
46
+ if ((_a = footnote.attrs.rids) === null || _a === void 0 ? void 0 : _a.includes(rid)) {
46
47
  const selection = NodeSelection.create(view.state.doc, pos);
47
48
  view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
48
49
  }
@@ -143,3 +144,6 @@ export default () => {
143
144
  },
144
145
  });
145
146
  };
147
+ export const getFootnotesPluginState = (state) => {
148
+ return footnotesKey.getState(state);
149
+ };
@@ -75,10 +75,8 @@ export const defaultEditorProps = {
75
75
  locale: '',
76
76
  },
77
77
  getCitationProvider: () => undefined,
78
- plugins: [],
79
78
  retrySync: () => Promise.resolve(),
80
79
  setComment: () => undefined,
81
80
  setSelectedComment: () => undefined,
82
81
  setEditorSelectedSuggestion: () => undefined,
83
- environment: undefined,
84
82
  };
@@ -57,8 +57,7 @@ export const useEditor = (props) => {
57
57
  view.current.updateState(nextState);
58
58
  const trackState = trackChangesPluginKey.getState(view.current.state);
59
59
  if (collabProvider &&
60
- trackState &&
61
- trackState.status !== TrackChangesStatus.viewSnapshots) {
60
+ (!trackState || trackState.status !== TrackChangesStatus.viewSnapshots)) {
62
61
  const sendable = sendableSteps(nextState);
63
62
  if (sendable) {
64
63
  collabProvider.sendSteps(sendable.version, sendable.steps, sendable.clientID, !tr.isGeneric);
@@ -20,7 +20,7 @@ export class InlineFootnoteView extends BaseNodeView {
20
20
  constructor() {
21
21
  super(...arguments);
22
22
  this.handleClick = () => {
23
- this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
23
+ this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rids[0] }));
24
24
  };
25
25
  this.updateContents = () => {
26
26
  this.setDomAttrs(this.node, this.dom);
@@ -18,7 +18,7 @@ import { CommentAnnotation, Manuscript, UserProfile } from '@manuscripts/json-sc
18
18
  import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style-guide';
19
19
  import { ManuscriptNode } from '@manuscripts/transform';
20
20
  import { History } from 'history';
21
- import { EditorState, Plugin } from 'prosemirror-state';
21
+ import { EditorState } from 'prosemirror-state';
22
22
  import { EditorView } from 'prosemirror-view';
23
23
  import { DefaultTheme } from 'styled-components';
24
24
  import { CollabProvider } from '../classes/collabProvider';
@@ -34,7 +34,6 @@ export interface EditorProps {
34
34
  };
35
35
  locale: string;
36
36
  theme: DefaultTheme;
37
- plugins?: Plugin[];
38
37
  getCurrentUser: () => UserProfile;
39
38
  projectID: string;
40
39
  doc: ManuscriptNode;
@@ -44,12 +43,13 @@ export interface EditorProps {
44
43
  popper: PopperManager;
45
44
  history: History;
46
45
  getCapabilities: () => Capabilities;
46
+ userID: string;
47
+ debug: boolean;
47
48
  cslProps: CSLProps;
48
49
  setComment: (comment?: CommentAnnotation) => void;
49
50
  setSelectedComment: (id?: string) => void;
50
51
  setEditorSelectedSuggestion: (id?: string) => void;
51
52
  retrySync: (componentIDs: string[]) => Promise<void>;
52
- environment?: string;
53
53
  collabProvider?: CollabProvider;
54
54
  }
55
55
  export declare const createEditorState: (props: EditorProps) => EditorState;
@@ -32,6 +32,8 @@ interface PluginProps {
32
32
  cslProps: CSLProps;
33
33
  popper: PopperManager;
34
34
  collabProvider?: CollabProvider;
35
+ userID: string;
36
+ debug: boolean;
35
37
  }
36
38
  declare const _default: (props: PluginProps) => any[];
37
39
  export default _default;
@@ -15,3 +15,4 @@
15
15
  */
16
16
  import { ResolvedPos } from 'prosemirror-model';
17
17
  export declare const findTableInlineFootnoteIds: ($pos: ResolvedPos) => Set<string>;
18
+ export declare const createFootnoteLabel: (id: string) => string;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { InlineFootnoteNode, ManuscriptNode } from '@manuscripts/transform';
17
- import { Plugin, PluginKey } from 'prosemirror-state';
17
+ import { EditorState, Plugin, PluginKey } from 'prosemirror-state';
18
18
  interface PluginState {
19
19
  nodes: [InlineFootnoteNode, number][];
20
20
  labels: Map<string, string>;
@@ -24,3 +24,4 @@ export declare const buildPluginState: (doc: ManuscriptNode) => PluginState;
24
24
  export declare const uncitedFootnoteWidget: () => () => HTMLSpanElement;
25
25
  declare const _default: () => Plugin<PluginState>;
26
26
  export default _default;
27
+ export declare const getFootnotesPluginState: (state: EditorState) => PluginState;
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.7.23",
4
+ "version": "1.7.24-LEAN-3338-0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -31,9 +31,9 @@
31
31
  "@manuscripts/assets": "^0.6.4",
32
32
  "@manuscripts/json-schema": "^2.2.6",
33
33
  "@manuscripts/library": "^1.3.5",
34
- "@manuscripts/style-guide": "^1.8.0",
35
- "@manuscripts/track-changes-plugin": "^1.7.7",
36
- "@manuscripts/transform": "^2.1.6",
34
+ "@manuscripts/style-guide": "1.8.1",
35
+ "@manuscripts/track-changes-plugin": "1.7.8",
36
+ "@manuscripts/transform": "^2.1.8",
37
37
  "astrocite-eutils": "^0.16.4",
38
38
  "axios": "^1.6.7",
39
39
  "mathjax-full": "^3.2.2",
@@ -109,6 +109,7 @@
109
109
  "uuid": "^9.0.0"
110
110
  },
111
111
  "resolutions": {
112
- "@types/react": "^17.0.2"
112
+ "@types/react": "^17.0.2",
113
+ "prosemirror-tables": "^1.3.5"
113
114
  }
114
- }
115
+ }
package/styles/Editor.css CHANGED
@@ -162,7 +162,7 @@
162
162
  .ProseMirror sub {
163
163
  line-height: 0;
164
164
  }
165
-
165
+ .ProseMirror .footnote,
166
166
  .ProseMirror .citation,
167
167
  .ProseMirror .cross-reference {
168
168
  font-weight: bold;
@@ -991,10 +991,18 @@
991
991
  .table-footer > div:has(> p.footnote-selected) > p:last-child {
992
992
  border-bottom: 1px solid #bce7f6;
993
993
  }
994
+
995
+ .ProseMirror .footnotes-element .block > div p {
996
+ display: flex;
997
+ }
998
+ .ProseMirror .footnotes-element .block > div p > ins {
999
+ flex: 1 0 auto;
1000
+ }
1001
+
994
1002
  .ProseMirror .footnote-label {
1003
+ flex: 0 0 auto;
995
1004
  vertical-align: super;
996
1005
  font-size: 75%;
997
- margin-right: 8px;
998
1006
  cursor: pointer;
999
1007
  }
1000
1008