@manuscripts/body-editor 2.0.9 → 2.0.11-JSR

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.
Files changed (36) hide show
  1. package/dist/cjs/configs/editor-plugins.js +3 -1
  2. package/dist/cjs/configs/editor-views.js +2 -0
  3. package/dist/cjs/plugins/objects.js +3 -3
  4. package/dist/cjs/plugins/section_title.js +50 -0
  5. package/dist/cjs/testing/default-editor-data.js +0 -1
  6. package/dist/cjs/versions.js +1 -1
  7. package/dist/cjs/views/bibliography_element.js +1 -1
  8. package/dist/cjs/views/citation_editable.js +8 -4
  9. package/dist/cjs/views/contributors.js +1 -1
  10. package/dist/cjs/views/inline_footnote.js +65 -45
  11. package/dist/cjs/views/section.js +79 -0
  12. package/dist/cjs/views/section_title.js +12 -2
  13. package/dist/es/configs/editor-plugins.js +3 -1
  14. package/dist/es/configs/editor-views.js +2 -0
  15. package/dist/es/plugins/objects.js +3 -3
  16. package/dist/es/plugins/section_title.js +47 -0
  17. package/dist/es/testing/default-editor-data.js +0 -1
  18. package/dist/es/versions.js +1 -1
  19. package/dist/es/views/bibliography_element.js +1 -1
  20. package/dist/es/views/citation_editable.js +8 -4
  21. package/dist/es/views/contributors.js +1 -1
  22. package/dist/es/views/inline_footnote.js +66 -46
  23. package/dist/es/views/section.js +71 -0
  24. package/dist/es/views/section_title.js +12 -2
  25. package/dist/types/components/outline/ManuscriptOutline.d.ts +0 -2
  26. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -2
  27. package/dist/types/configs/editor-views.d.ts +1 -0
  28. package/dist/types/plugins/objects.d.ts +1 -5
  29. package/dist/types/plugins/section_title.d.ts +5 -0
  30. package/dist/types/versions.d.ts +1 -1
  31. package/dist/types/views/inline_footnote.d.ts +3 -1
  32. package/dist/types/views/section.d.ts +28 -0
  33. package/dist/types/views/section_title.d.ts +1 -1
  34. package/package.json +4 -4
  35. package/styles/AdvancedEditor.css +20 -272
  36. package/styles/Editor.css +7 -2
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { FootnotesSelector } from '@manuscripts/style-guide';
16
+ import { ContextMenu, FootnotesSelector, } from '@manuscripts/style-guide';
17
17
  import { schema, } from '@manuscripts/transform';
18
18
  import { NodeSelection, TextSelection } from 'prosemirror-state';
19
19
  import { findChildrenByType, findParentNodeClosestToPos, } from 'prosemirror-utils';
@@ -28,8 +28,23 @@ export class InlineFootnoteView extends BaseNodeView {
28
28
  constructor() {
29
29
  super(...arguments);
30
30
  this.findParentTableElement = () => findParentNodeClosestToPos(this.view.state.doc.resolve(this.getPos()), (node) => node.type === schema.nodes.table_element);
31
+ this.showContextMenu = () => {
32
+ this.props.popper.destroy();
33
+ const componentProps = {
34
+ actions: [
35
+ {
36
+ label: 'Edit',
37
+ action: () => {
38
+ this.props.popper.destroy();
39
+ this.activateGenericFnModal();
40
+ },
41
+ icon: 'Edit',
42
+ },
43
+ ],
44
+ };
45
+ this.props.popper.show(this.dom, ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu'), 'right-start', false);
46
+ };
31
47
  this.handleClick = () => {
32
- var _a;
33
48
  if (isDeleted(this.node)) {
34
49
  return;
35
50
  }
@@ -40,21 +55,59 @@ export class InlineFootnoteView extends BaseNodeView {
40
55
  onAdd: this.onAdd,
41
56
  });
42
57
  }
43
- else if (!this.activateGenericFnModal()) {
44
- if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
45
- let nodePos = undefined;
46
- this.view.state.doc.descendants((node, pos) => {
47
- if (node.attrs.id === this.node.attrs.rids[0]) {
48
- nodePos = pos;
49
- }
50
- });
51
- if (nodePos && this.props.dispatch) {
52
- const sel = TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
53
- this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
58
+ else {
59
+ this.showContextMenu();
60
+ }
61
+ };
62
+ this.scrollToReferenced = () => {
63
+ var _a;
64
+ if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
65
+ let nodePos = undefined;
66
+ this.view.state.doc.descendants((node, pos) => {
67
+ if (node.attrs.id === this.node.attrs.rids[0]) {
68
+ nodePos = pos;
54
69
  }
70
+ });
71
+ if (nodePos && this.props.dispatch) {
72
+ const sel = TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
73
+ this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
55
74
  }
56
75
  }
57
76
  };
77
+ this.activateGenericFnModal = () => {
78
+ if (!this.props.getCapabilities().editArticle) {
79
+ return;
80
+ }
81
+ const fnState = footnotesKey.getState(this.view.state);
82
+ console.log(fnState);
83
+ if (fnState) {
84
+ this.activateModal({
85
+ notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
86
+ node: n[0],
87
+ })),
88
+ onCancel: () => {
89
+ const { tr } = this.view.state;
90
+ if (!this.node.attrs.rids.length) {
91
+ this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
92
+ }
93
+ this.destroy();
94
+ },
95
+ onAdd: () => {
96
+ const footnote = createFootnote(this.view.state, 'footnote');
97
+ const tr = insertFootnote(this.view.state, this.view.state.tr, footnote);
98
+ tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
99
+ footnote.attrs.id,
100
+ ]);
101
+ this.view.dispatch(tr);
102
+ this.view.focus();
103
+ this.destroy();
104
+ },
105
+ addNewLabel: 'Replace with new footnote',
106
+ });
107
+ return true;
108
+ }
109
+ return false;
110
+ };
58
111
  this.updateContents = () => {
59
112
  const attrs = this.node.attrs;
60
113
  this.dom.setAttribute('rids', attrs.rids.join(','));
@@ -148,38 +201,5 @@ export class InlineFootnoteView extends BaseNodeView {
148
201
  this.popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), FootnotesSelector, Object.assign(Object.assign({}, defaultModal), modalProps), this.node, this.getPos, this.view, 'footnote-editor');
149
202
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
150
203
  }
151
- activateGenericFnModal() {
152
- if (!this.props.getCapabilities().editArticle) {
153
- return;
154
- }
155
- const fnState = footnotesKey.getState(this.view.state);
156
- if (fnState && fnState.unusedFootnotes.size > 0) {
157
- this.activateModal({
158
- notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
159
- node: n[0],
160
- })),
161
- onCancel: () => {
162
- const { tr } = this.view.state;
163
- if (!this.node.attrs.rids.length) {
164
- this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
165
- }
166
- this.destroy();
167
- },
168
- onAdd: () => {
169
- const footnote = createFootnote(this.view.state, 'footnote');
170
- const tr = insertFootnote(this.view.state, this.view.state.tr, footnote);
171
- tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
172
- footnote.attrs.id,
173
- ]);
174
- this.view.dispatch(tr);
175
- this.view.focus();
176
- this.destroy();
177
- },
178
- addNewLabel: 'Replace with new footnote',
179
- });
180
- return true;
181
- }
182
- return false;
183
- }
184
204
  }
185
205
  export default createNodeView(InlineFootnoteView);
@@ -0,0 +1,71 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { PAGE_BREAK_AFTER, PAGE_BREAK_BEFORE, PAGE_BREAK_BEFORE_AND_AFTER, } from '@manuscripts/transform';
17
+ import { sectionTitleKey } from '../plugins/section_title';
18
+ import BlockView from './block_view';
19
+ import { createNodeView } from './creators';
20
+ export const handleSectionNumbering = (sections) => {
21
+ sections.forEach((sectionNumber, sectionId) => {
22
+ const section = document.getElementById(sectionId);
23
+ const sectionTitle = section === null || section === void 0 ? void 0 : section.querySelector('h1');
24
+ if (sectionTitle) {
25
+ sectionTitle.dataset.sectionNumber = sectionNumber;
26
+ }
27
+ });
28
+ };
29
+ export class SectionView extends BlockView {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.elementType = 'section';
33
+ this.initialise = () => {
34
+ this.createDOM();
35
+ this.createElement();
36
+ this.updateContents();
37
+ };
38
+ this.createElement = () => {
39
+ this.contentDOM = document.createElement(this.elementType);
40
+ this.dom.appendChild(this.contentDOM);
41
+ };
42
+ this.onUpdateContent = () => {
43
+ const sectionTitleState = sectionTitleKey.getState(this.view.state);
44
+ const { titleSuppressed, generatedLabel, pageBreakStyle, id, category } = this.node.attrs;
45
+ const classNames = [];
46
+ if (titleSuppressed) {
47
+ classNames.push('title-suppressed');
48
+ }
49
+ if (typeof generatedLabel === 'undefined' || generatedLabel) {
50
+ classNames.push('generated-label');
51
+ }
52
+ if (pageBreakStyle === PAGE_BREAK_BEFORE ||
53
+ pageBreakStyle === PAGE_BREAK_BEFORE_AND_AFTER) {
54
+ classNames.push('page-break-before');
55
+ }
56
+ if (pageBreakStyle === PAGE_BREAK_AFTER ||
57
+ pageBreakStyle === PAGE_BREAK_BEFORE_AND_AFTER) {
58
+ classNames.push('page-break-after');
59
+ }
60
+ if (this.contentDOM) {
61
+ this.contentDOM.id = id;
62
+ this.contentDOM.classList.add(...classNames);
63
+ category && this.contentDOM.setAttribute('data-category', category);
64
+ }
65
+ if (sectionTitleState) {
66
+ handleSectionNumbering(sectionTitleState);
67
+ }
68
+ };
69
+ }
70
+ }
71
+ export default createNodeView(SectionView);
@@ -13,23 +13,33 @@
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';
17
+ import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
16
18
  import { sectionLevel } from '../lib/context-menu';
19
+ import { sectionTitleKey } from '../plugins/section_title';
17
20
  import BlockView from './block_view';
18
21
  import { createNodeView } from './creators';
19
22
  export class SectionTitleView extends BlockView {
20
23
  constructor() {
21
24
  super(...arguments);
22
25
  this.elementType = 'h1';
23
- this.updateContents = () => {
26
+ this.onUpdateContent = () => {
24
27
  const $pos = this.view.state.doc.resolve(this.getPos());
28
+ const sectionTitleState = sectionTitleKey.getState(this.view.state);
29
+ const parentSection = findParentNodeOfTypeClosestToPos($pos, schema.nodes.section);
30
+ const sectionNumber = sectionTitleState === null || sectionTitleState === void 0 ? void 0 : sectionTitleState.get(parentSection === null || parentSection === void 0 ? void 0 : parentSection.node.attrs.id);
31
+ const level = $pos.depth > 1 ? $pos.depth - 1 : $pos.depth;
25
32
  if (this.node.childCount) {
26
33
  this.contentDOM.classList.remove('empty-node');
27
34
  }
28
35
  else {
29
36
  this.contentDOM.classList.add('empty-node');
30
- const level = $pos.depth > 1 ? $pos.depth - 1 : $pos.depth;
31
37
  this.contentDOM.setAttribute('data-placeholder', `${sectionLevel(level)} heading`);
32
38
  }
39
+ if (sectionTitleState) {
40
+ this.contentDOM.dataset.sectionNumber = sectionNumber;
41
+ this.contentDOM.dataset.titleLevel = level.toString();
42
+ }
33
43
  };
34
44
  }
35
45
  }
@@ -13,12 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Manuscript } from '@manuscripts/json-schema';
17
16
  import { Capabilities } from '@manuscripts/style-guide';
18
17
  import { ManuscriptEditorView, ManuscriptNode } from '@manuscripts/transform';
19
18
  import React from 'react';
20
19
  export interface ManuscriptOutlineProps {
21
- manuscript: Manuscript;
22
20
  doc: ManuscriptNode | null;
23
21
  can?: Capabilities;
24
22
  view?: ManuscriptEditorView;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import 'prosemirror-view/style/prosemirror.css';
17
- import { Manuscript, UserProfile } from '@manuscripts/json-schema';
17
+ import { UserProfile } from '@manuscripts/json-schema';
18
18
  import { Capabilities } from '@manuscripts/style-guide';
19
19
  import { ManuscriptNode } from '@manuscripts/transform';
20
20
  import { EditorState } from 'prosemirror-state';
@@ -37,7 +37,6 @@ export interface EditorProps {
37
37
  getCurrentUser: () => UserProfile;
38
38
  projectID: string;
39
39
  doc: ManuscriptNode;
40
- getManuscript: () => Manuscript;
41
40
  getFiles: () => FileAttachment[];
42
41
  fileManagement: FileManagement;
43
42
  popper: PopperManager;
@@ -316,6 +316,7 @@ declare const _default: (props: EditorProps, dispatch: Dispatch) => {
316
316
  destroy: () => void;
317
317
  handleDecorations: (decorations: readonly import("prosemirror-view").Decoration[]) => void;
318
318
  } & import("../views/placeholder_element").PlaceholderElementView<any>>;
319
+ section: import("../types").NodeViewCreator<import("../views/section").SectionView<any>>;
319
320
  pullquote_element: import("../types").NodeViewCreator<{
320
321
  gutterButtons: () => HTMLElement[];
321
322
  actionGutterButtons: () => HTMLElement[];
@@ -13,12 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Manuscript } from '@manuscripts/json-schema';
17
16
  import { Target } from '@manuscripts/transform';
18
17
  import { Plugin, PluginKey } from 'prosemirror-state';
19
18
  export declare const objectsKey: PluginKey<Map<string, Target>>;
20
- interface Props {
21
- getManuscript: () => Manuscript;
22
- }
23
- declare const _default: (props: Props) => Plugin<Map<string, Target>>;
19
+ declare const _default: () => Plugin<Map<string, Target>>;
24
20
  export default _default;
@@ -0,0 +1,5 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+ export type PluginState = Map<string, string>;
3
+ export declare const sectionTitleKey: PluginKey<PluginState>;
4
+ declare const _default: () => Plugin<PluginState>;
5
+ export default _default;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.0.9";
1
+ export declare const VERSION = "2.0.11-JSR";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
@@ -27,9 +27,11 @@ export declare class InlineFootnoteView<PropsType extends InlineFootnoteProps &
27
27
  protected popperContainer: HTMLDivElement;
28
28
  isSelected(): boolean;
29
29
  findParentTableElement: () => ContentNodeWithPos | undefined;
30
+ showContextMenu: () => void;
30
31
  handleClick: () => void;
32
+ scrollToReferenced: () => void;
31
33
  activateModal(modalProps: Partial<ModalProps>): void;
32
- activateGenericFnModal(): boolean | undefined;
34
+ activateGenericFnModal: () => boolean | undefined;
33
35
  updateContents: () => void;
34
36
  initialise: () => void;
35
37
  ignoreMutation: () => boolean;
@@ -0,0 +1,28 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { PluginState } from '../plugins/section_title';
17
+ import { BaseNodeProps } from './base_node_view';
18
+ import BlockView from './block_view';
19
+ export declare const handleSectionNumbering: (sections: PluginState) => void;
20
+ export declare class SectionView<PropsType extends BaseNodeProps> extends BlockView<PropsType> {
21
+ elementType: string;
22
+ element: HTMLElement;
23
+ initialise: () => void;
24
+ createElement: () => void;
25
+ onUpdateContent: () => void;
26
+ }
27
+ declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<SectionView<any>>;
28
+ export default _default;
@@ -18,7 +18,7 @@ import BlockView from './block_view';
18
18
  export declare class SectionTitleView<PropsType extends BaseNodeProps> extends BlockView<PropsType> {
19
19
  contentDOM: HTMLElement;
20
20
  elementType: string;
21
- updateContents: () => void;
21
+ onUpdateContent: () => void;
22
22
  }
23
23
  declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<SectionTitleView<any>>;
24
24
  export default _default;
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.0.9",
4
+ "version": "2.0.11-JSR",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -32,9 +32,9 @@
32
32
  "@iarna/word-count": "^1.1.2",
33
33
  "@manuscripts/json-schema": "2.2.10",
34
34
  "@manuscripts/library": "1.3.10",
35
- "@manuscripts/style-guide": "2.0.1",
35
+ "@manuscripts/style-guide": "2.0.2",
36
36
  "@manuscripts/track-changes-plugin": "1.7.17",
37
- "@manuscripts/transform": "2.3.21",
37
+ "@manuscripts/transform": "2.3.21-JSR",
38
38
  "@popperjs/core": "^2.11.8",
39
39
  "astrocite-eutils": "^0.16.4",
40
40
  "codemirror": "^5.58.1",
@@ -116,4 +116,4 @@
116
116
  "engines": {
117
117
  "node": ">=20.16.0"
118
118
  }
119
- }
119
+ }