@manuscripts/body-editor 3.16.3 → 3.17.1
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.
- package/dist/cjs/lib/context-menu.js +28 -11
- package/dist/cjs/lib/popper.js +18 -3
- package/dist/cjs/lib/position-menu.js +175 -100
- package/dist/cjs/lib/view.js +10 -1
- package/dist/cjs/plugins/detect-inconsistency/index.js +6 -4
- package/dist/cjs/plugins/persist.js +3 -0
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/box_element.js +23 -1
- package/dist/cjs/views/caption_title.js +1 -1
- package/dist/cjs/views/footnote.js +43 -18
- package/dist/cjs/views/general_table_footnote.js +31 -21
- package/dist/cjs/views/image_element.js +7 -62
- package/dist/cjs/views/pullquote_element.js +23 -1
- package/dist/cjs/views/table_element.js +23 -1
- package/dist/es/lib/context-menu.js +29 -12
- package/dist/es/lib/popper.js +18 -3
- package/dist/es/lib/position-menu.js +173 -91
- package/dist/es/lib/view.js +8 -0
- package/dist/es/plugins/detect-inconsistency/index.js +6 -4
- package/dist/es/plugins/persist.js +3 -0
- package/dist/es/versions.js +1 -1
- package/dist/es/views/box_element.js +23 -1
- package/dist/es/views/caption_title.js +1 -1
- package/dist/es/views/footnote.js +43 -18
- package/dist/es/views/general_table_footnote.js +31 -21
- package/dist/es/views/image_element.js +7 -62
- package/dist/es/views/pullquote_element.js +23 -1
- package/dist/es/views/table_element.js +23 -1
- package/dist/types/lib/popper.d.ts +4 -2
- package/dist/types/lib/position-menu.d.ts +36 -11
- package/dist/types/lib/view.d.ts +3 -1
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/box_element.d.ts +6 -0
- package/dist/types/views/footnote.d.ts +5 -2
- package/dist/types/views/general_table_footnote.d.ts +2 -2
- package/dist/types/views/image_element.d.ts +2 -9
- package/dist/types/views/pullquote_element.d.ts +6 -0
- package/dist/types/views/table_element.d.ts +6 -0
- package/package.json +2 -2
- package/src/lib/context-menu.ts +42 -21
- package/src/lib/popper.ts +23 -4
- package/src/lib/position-menu.ts +243 -137
- package/src/lib/view.ts +17 -0
- package/src/plugins/detect-inconsistency/index.ts +6 -4
- package/src/plugins/persist.ts +3 -0
- package/src/versions.ts +1 -1
- package/src/views/box_element.ts +34 -1
- package/src/views/caption_title.ts +1 -1
- package/src/views/footnote.ts +69 -33
- package/src/views/general_table_footnote.ts +43 -20
- package/src/views/image_element.ts +12 -89
- package/src/views/pullquote_element.ts +33 -1
- package/src/views/table_element.ts +34 -1
- package/styles/AdvancedEditor.css +5 -8
- package/styles/Editor.css +9 -5
|
@@ -35,8 +35,15 @@ const readonlyTypes = [
|
|
|
35
35
|
transform_1.schema.nodes.bibliography_section,
|
|
36
36
|
transform_1.schema.nodes.footnotes_section,
|
|
37
37
|
];
|
|
38
|
-
const
|
|
39
|
-
|
|
38
|
+
const getBoxElementOfSectionTitle = ($pos, node) => {
|
|
39
|
+
if ((0, transform_1.isSectionTitleNode)(node)) {
|
|
40
|
+
const parent = $pos.node($pos.depth - 1);
|
|
41
|
+
if (parent.type === transform_1.schema.nodes.box_element) {
|
|
42
|
+
return parent;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
40
47
|
const sectionLevel = (depth) => {
|
|
41
48
|
switch (depth) {
|
|
42
49
|
case 1:
|
|
@@ -157,18 +164,28 @@ class ContextMenu {
|
|
|
157
164
|
const menu = document.createElement('div');
|
|
158
165
|
menu.className = 'menu';
|
|
159
166
|
const $pos = this.resolvePos();
|
|
160
|
-
const
|
|
161
|
-
const type =
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
const boxParent = getBoxElementOfSectionTitle($pos, this.node);
|
|
168
|
+
const type = boxParent ? transform_1.schema.nodes.box_element : this.node.type;
|
|
169
|
+
const positionableTypes = [
|
|
170
|
+
transform_1.schema.nodes.figure_element,
|
|
171
|
+
transform_1.schema.nodes.image_element,
|
|
172
|
+
transform_1.schema.nodes.box_element,
|
|
173
|
+
transform_1.schema.nodes.pullquote_element,
|
|
174
|
+
transform_1.schema.nodes.table_element,
|
|
175
|
+
];
|
|
176
|
+
let nodeBase = this.node;
|
|
177
|
+
if (positionableTypes.includes(type)) {
|
|
164
178
|
const figure = (0, utils_1.getMatchingChild)(this.node, (node) => node.type === transform_1.schema.nodes.figure);
|
|
165
179
|
if (figure) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
menu.appendChild(submenu);
|
|
180
|
+
nodeBase = figure;
|
|
181
|
+
}
|
|
182
|
+
if (boxParent) {
|
|
183
|
+
nodeBase = boxParent;
|
|
171
184
|
}
|
|
185
|
+
const submenuOptions = position_menu_1.HorizontalPositionMenu.createPositionOptions(transform_1.schema.nodes[nodeBase.type.name], nodeBase, nodeBase.attrs.type, this.view, () => popper.destroy());
|
|
186
|
+
const submenuLabel = 'Position';
|
|
187
|
+
const submenu = this.createSubmenu(submenuLabel, submenuOptions);
|
|
188
|
+
menu.appendChild(submenu);
|
|
172
189
|
}
|
|
173
190
|
if (type === transform_1.schema.nodes.list) {
|
|
174
191
|
menu.appendChild(this.createMenuSection((section) => {
|
package/dist/cjs/lib/popper.js
CHANGED
|
@@ -22,9 +22,10 @@ class PopperManager {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
this.isActive = () => !!this.activePopper;
|
|
24
24
|
}
|
|
25
|
-
show(target, contents, placement = 'bottom', showArrow = true, modifiers = [], autoFocus = true) {
|
|
25
|
+
show(target, contents, placement = 'bottom', showArrow = true, modifiers = [], autoFocus = true, autoCloseOnOutsideClick = true, onDestroy = undefined) {
|
|
26
26
|
this.destroy();
|
|
27
27
|
this.triggerElement = target;
|
|
28
|
+
this.destructionListener = onDestroy;
|
|
28
29
|
window.requestAnimationFrame(() => {
|
|
29
30
|
const container = document.createElement('div');
|
|
30
31
|
container.className = 'popper';
|
|
@@ -84,9 +85,10 @@ class PopperManager {
|
|
|
84
85
|
this.destroy();
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
|
-
if (contents.classList.contains('context-menu') ||
|
|
88
|
+
if ((contents.classList.contains('context-menu') ||
|
|
88
89
|
contents.classList.contains('language') ||
|
|
89
|
-
contents.classList.contains('section-category'))
|
|
90
|
+
contents.classList.contains('section-category')) &&
|
|
91
|
+
autoCloseOnOutsideClick) {
|
|
90
92
|
window.addEventListener('click', this.handleDocumentClick);
|
|
91
93
|
}
|
|
92
94
|
});
|
|
@@ -94,6 +96,8 @@ class PopperManager {
|
|
|
94
96
|
destroy() {
|
|
95
97
|
if (this.activePopper) {
|
|
96
98
|
this.removeContainerClass(this.activePopper.state.elements.reference);
|
|
99
|
+
this.destructionListener?.(this.activePopper);
|
|
100
|
+
this.destructionListener = undefined;
|
|
97
101
|
this.activePopper.destroy();
|
|
98
102
|
this.activePopper.state.elements.popper.remove();
|
|
99
103
|
if (this.handleDocumentClick) {
|
|
@@ -111,6 +115,17 @@ class PopperManager {
|
|
|
111
115
|
this.activePopper.update();
|
|
112
116
|
}
|
|
113
117
|
}
|
|
118
|
+
replaceContent(newContent) {
|
|
119
|
+
if (this.container && this.activePopper) {
|
|
120
|
+
const arrow = this.container.querySelector('.popper-arrow');
|
|
121
|
+
this.container.innerHTML = '';
|
|
122
|
+
if (arrow) {
|
|
123
|
+
this.container.appendChild(arrow);
|
|
124
|
+
}
|
|
125
|
+
this.container.appendChild(newContent);
|
|
126
|
+
this.activePopper.update();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
114
129
|
focusInput(container, autoFocus = true) {
|
|
115
130
|
const input = container.querySelector('input');
|
|
116
131
|
if (input) {
|
|
@@ -14,112 +14,187 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
18
|
+
exports.HorizontalPositionMenu = exports.HorizontalPositions = void 0;
|
|
22
19
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
23
20
|
const icons_1 = require("../icons");
|
|
24
|
-
const
|
|
25
|
-
const ReactSubView_1 = __importDefault(require("../views/ReactSubView"));
|
|
21
|
+
const ReactSubView_1 = require("../views/ReactSubView");
|
|
26
22
|
const navigation_utils_1 = require("./navigation-utils");
|
|
27
23
|
const view_1 = require("./view");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
element.setAttribute('data-alignment', 'right');
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
element.removeAttribute('data-alignment');
|
|
92
|
-
break;
|
|
24
|
+
var HorizontalPositions;
|
|
25
|
+
(function (HorizontalPositions) {
|
|
26
|
+
HorizontalPositions["left"] = "half-left";
|
|
27
|
+
HorizontalPositions["right"] = "half-right";
|
|
28
|
+
HorizontalPositions["default"] = "";
|
|
29
|
+
})(HorizontalPositions || (exports.HorizontalPositions = HorizontalPositions = {}));
|
|
30
|
+
class HorizontalPositionMenu {
|
|
31
|
+
constructor(parent, onChange, location, getPositionSource) {
|
|
32
|
+
this.menuOpen = false;
|
|
33
|
+
this.posMenuSelector = 'position-menu';
|
|
34
|
+
this.buttonClass = 'position-menu-button';
|
|
35
|
+
const preSource = getPositionSource?.() || parent.node;
|
|
36
|
+
if (typeof preSource.attrs.type === 'undefined') {
|
|
37
|
+
console.error("This node doesn't support horizontal alignment");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.getPositionSource = getPositionSource;
|
|
41
|
+
this.location = location || parent.dom;
|
|
42
|
+
this.onChange = onChange.bind(parent);
|
|
43
|
+
this.parent = parent;
|
|
44
|
+
}
|
|
45
|
+
static createPositionOptions(nodeType, node, currentPosition, view, onComplete) {
|
|
46
|
+
const createAction = (position) => () => {
|
|
47
|
+
onComplete?.();
|
|
48
|
+
(0, view_1.updateNodeAttrs)(view, nodeType, {
|
|
49
|
+
...node.attrs,
|
|
50
|
+
type: position,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
title: 'Left',
|
|
56
|
+
action: createAction(HorizontalPositions.left),
|
|
57
|
+
IconComponent: icons_1.imageLeftIcon,
|
|
58
|
+
iconName: 'ImageLeft',
|
|
59
|
+
selected: currentPosition === HorizontalPositions.left,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: 'Default',
|
|
63
|
+
action: createAction(HorizontalPositions.default),
|
|
64
|
+
IconComponent: icons_1.imageDefaultIcon,
|
|
65
|
+
iconName: 'ImageDefault',
|
|
66
|
+
selected: !currentPosition || currentPosition === HorizontalPositions.default,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
title: 'Right',
|
|
70
|
+
action: createAction(HorizontalPositions.right),
|
|
71
|
+
IconComponent: icons_1.imageRightIcon,
|
|
72
|
+
iconName: 'ImageRight',
|
|
73
|
+
selected: currentPosition === HorizontalPositions.right,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
createPopperMenuPositionOptions(nodeType, node, currentPosition, view, onComplete) {
|
|
78
|
+
return HorizontalPositionMenu.createPositionOptions(nodeType, node, currentPosition, view, onComplete).map((option) => ({
|
|
79
|
+
label: option.title,
|
|
80
|
+
action: option.action,
|
|
81
|
+
icon: option.iconName,
|
|
82
|
+
selected: option.selected,
|
|
83
|
+
}));
|
|
93
84
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
85
|
+
createPositionMenuWrapper(currentPosition, props) {
|
|
86
|
+
const can = props.getCapabilities();
|
|
87
|
+
const positionMenuWrapper = document.createElement('div');
|
|
88
|
+
positionMenuWrapper.classList.add(this.posMenuSelector);
|
|
89
|
+
const positionMenuButton = document.createElement('div');
|
|
90
|
+
positionMenuButton.classList.add(this.buttonClass);
|
|
91
|
+
let icon;
|
|
92
|
+
switch (currentPosition) {
|
|
93
|
+
case HorizontalPositions.left:
|
|
94
|
+
icon = icons_1.imageLeftIcon;
|
|
95
|
+
break;
|
|
96
|
+
case HorizontalPositions.right:
|
|
97
|
+
icon = icons_1.imageRightIcon;
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
icon = icons_1.imageDefaultIcon;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (icon) {
|
|
104
|
+
positionMenuButton.innerHTML = icon;
|
|
105
|
+
}
|
|
106
|
+
const onClick = () => {
|
|
107
|
+
this.showPositionMenu();
|
|
108
|
+
};
|
|
109
|
+
if (can.editArticle) {
|
|
110
|
+
positionMenuButton.tabIndex = -1;
|
|
111
|
+
positionMenuButton.addEventListener('click', onClick);
|
|
112
|
+
positionMenuButton.addEventListener('keydown', (0, navigation_utils_1.handleEnterKey)(onClick));
|
|
113
|
+
}
|
|
114
|
+
if (this.positionMenuWrapper) {
|
|
115
|
+
const button = this.positionMenuWrapper.querySelector('.' + this.buttonClass);
|
|
116
|
+
if (button) {
|
|
117
|
+
this.positionMenuWrapper.removeChild(button);
|
|
118
|
+
this.positionMenuWrapper.appendChild(positionMenuButton);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
positionMenuWrapper.appendChild(positionMenuButton);
|
|
123
|
+
this.positionMenuWrapper = positionMenuWrapper;
|
|
124
|
+
this.location.prepend(this.positionMenuWrapper);
|
|
125
|
+
}
|
|
113
126
|
}
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
getHorizontalPositionOptions(current, onPick, destroy) {
|
|
128
|
+
const componentProps = {
|
|
129
|
+
actions: [
|
|
130
|
+
{
|
|
131
|
+
label: 'Left',
|
|
132
|
+
action: () => {
|
|
133
|
+
destroy();
|
|
134
|
+
this.menuOpen = false;
|
|
135
|
+
onPick(HorizontalPositions.left);
|
|
136
|
+
},
|
|
137
|
+
icon: 'ImageLeft',
|
|
138
|
+
selected: current === HorizontalPositions.left,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
label: 'Default',
|
|
142
|
+
action: () => {
|
|
143
|
+
destroy();
|
|
144
|
+
this.menuOpen = false;
|
|
145
|
+
onPick(HorizontalPositions.default);
|
|
146
|
+
},
|
|
147
|
+
icon: 'ImageDefault',
|
|
148
|
+
selected: !current,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: 'Right',
|
|
152
|
+
action: () => {
|
|
153
|
+
destroy();
|
|
154
|
+
this.menuOpen = false;
|
|
155
|
+
onPick(HorizontalPositions.right);
|
|
156
|
+
},
|
|
157
|
+
icon: 'ImageRight',
|
|
158
|
+
selected: current === HorizontalPositions.right,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
return componentProps;
|
|
163
|
+
}
|
|
164
|
+
showPositionMenu(force = false) {
|
|
165
|
+
const p = this.parent;
|
|
166
|
+
if (this.menuOpen && !force) {
|
|
167
|
+
p.props.popper.destroy();
|
|
168
|
+
this.menuOpen = false;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const posSource = this.getPositionSource
|
|
172
|
+
? this.getPositionSource()
|
|
173
|
+
: this.parent.node;
|
|
174
|
+
const componentProps = this.getHorizontalPositionOptions(posSource?.attrs.type || HorizontalPositions.default, this.onChange, p.props.popper.destroy.bind(p.props.popper));
|
|
175
|
+
(0, ReactSubView_1.createSubViewAsync)(p.props, style_guide_1.ContextMenu, componentProps, p.node, p.getPos, p.view, ['context-menu', this.posMenuSelector]).then((content) => {
|
|
176
|
+
if (this.menuOpen && p.props.popper.isActive()) {
|
|
177
|
+
p.props.popper.replaceContent(content);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
p.props.popper.show(this.positionMenuWrapper, content, 'left', false, [], true, true, () => {
|
|
181
|
+
this.menuOpen = false;
|
|
182
|
+
});
|
|
183
|
+
this.menuOpen = true;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
116
186
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
187
|
+
create() {
|
|
188
|
+
if (!this.parent) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const p = this.parent;
|
|
192
|
+
if (p.props.getCapabilities()?.editArticle) {
|
|
193
|
+
const posSource = this.getPositionSource
|
|
194
|
+
? this.getPositionSource()
|
|
195
|
+
: this.parent.node;
|
|
196
|
+
this.createPositionMenuWrapper(posSource?.attrs.type || HorizontalPositions.default, p.props);
|
|
197
|
+
}
|
|
121
198
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
exports.createPositionMenuWrapper = createPositionMenuWrapper;
|
|
199
|
+
}
|
|
200
|
+
exports.HorizontalPositionMenu = HorizontalPositionMenu;
|
package/dist/cjs/lib/view.js
CHANGED
|
@@ -48,7 +48,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.saveBibliographyItem = exports.insertBibliographyItems = exports.deleteNode = exports.updateNodeAttrs = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
|
|
51
|
+
exports.isSelectionInsideNode = exports.saveBibliographyItem = exports.insertBibliographyItems = exports.deleteNode = exports.updateNodeAttrs = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
|
|
52
52
|
const transform_1 = require("@manuscripts/transform");
|
|
53
53
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
54
54
|
const utils = __importStar(require("prosemirror-utils"));
|
|
@@ -144,3 +144,12 @@ const saveBibliographyItem = (view, attrs) => {
|
|
|
144
144
|
(0, exports.insertBibliographyItems)(view, attrs);
|
|
145
145
|
};
|
|
146
146
|
exports.saveBibliographyItem = saveBibliographyItem;
|
|
147
|
+
const isSelectionInsideNode = (view, node, pos) => {
|
|
148
|
+
const { from, to, empty } = view.state.selection;
|
|
149
|
+
const end = pos + node.nodeSize;
|
|
150
|
+
if (empty) {
|
|
151
|
+
return from > pos && from < end;
|
|
152
|
+
}
|
|
153
|
+
return from >= pos && to <= end;
|
|
154
|
+
};
|
|
155
|
+
exports.isSelectionInsideNode = isSelectionInsideNode;
|
|
@@ -25,10 +25,12 @@ exports.default = (props) => {
|
|
|
25
25
|
key: exports.detectInconsistencyKey,
|
|
26
26
|
state: {
|
|
27
27
|
init: (_, state) => (0, detect_inconsistency_utils_1.buildPluginState)(state, props, false),
|
|
28
|
-
apply: (tr, value, newState) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
apply: (tr, value, _, newState) => {
|
|
29
|
+
const metaValue = tr.getMeta(exports.detectInconsistencyKey);
|
|
30
|
+
const showDecorations = metaValue !== undefined ? metaValue : value.showDecorations;
|
|
31
|
+
if (!tr.docChanged && metaValue === undefined) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
32
34
|
return (0, detect_inconsistency_utils_1.buildPluginState)(newState, props, showDecorations);
|
|
33
35
|
},
|
|
34
36
|
},
|
package/dist/cjs/versions.js
CHANGED
|
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.BoxElementView = void 0;
|
|
22
22
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
23
23
|
const creators_1 = require("./creators");
|
|
24
|
+
const position_menu_1 = require("../lib/position-menu");
|
|
24
25
|
class BoxElementView extends block_view_1.default {
|
|
25
26
|
constructor() {
|
|
26
27
|
super(...arguments);
|
|
@@ -29,9 +30,30 @@ class BoxElementView extends block_view_1.default {
|
|
|
29
30
|
this.contentDOM = document.createElement(this.elementType);
|
|
30
31
|
this.contentDOM.className = 'block box-element';
|
|
31
32
|
this.contentDOM.setAttribute('id', this.node.attrs.id);
|
|
32
|
-
this.
|
|
33
|
+
this.container = document.createElement('div');
|
|
34
|
+
this.container.classList.add('container');
|
|
35
|
+
this.container.appendChild(this.contentDOM);
|
|
36
|
+
this.dom.appendChild(this.container);
|
|
33
37
|
};
|
|
34
38
|
}
|
|
39
|
+
updateContents() {
|
|
40
|
+
super.updateContents();
|
|
41
|
+
this.addTools();
|
|
42
|
+
}
|
|
43
|
+
addTools() {
|
|
44
|
+
this.addPositionMenu();
|
|
45
|
+
}
|
|
46
|
+
addPositionMenu() {
|
|
47
|
+
if (!this.positionMenu) {
|
|
48
|
+
this.positionMenu = new position_menu_1.HorizontalPositionMenu(this, this.updateHorizontalPosition, this.container);
|
|
49
|
+
}
|
|
50
|
+
this.positionMenu.create();
|
|
51
|
+
}
|
|
52
|
+
updateHorizontalPosition(horizontalPosition) {
|
|
53
|
+
const tr = this.view.state.tr;
|
|
54
|
+
tr.setNodeAttribute(this.getPos(), 'type', horizontalPosition);
|
|
55
|
+
this.view.dispatch(tr);
|
|
56
|
+
}
|
|
35
57
|
}
|
|
36
58
|
exports.BoxElementView = BoxElementView;
|
|
37
59
|
exports.default = (0, creators_1.createNodeView)(BoxElementView);
|
|
@@ -27,7 +27,7 @@ class CaptionTitleView extends base_node_view_1.BaseNodeView {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
createDOM() {
|
|
30
|
-
this.dom = document.createElement('
|
|
30
|
+
this.dom = document.createElement('div');
|
|
31
31
|
this.dom.className = 'caption-title placeholder';
|
|
32
32
|
this.contentDOM = this.dom;
|
|
33
33
|
}
|
|
@@ -23,6 +23,7 @@ const style_guide_1 = require("@manuscripts/style-guide");
|
|
|
23
23
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
24
24
|
const transform_1 = require("@manuscripts/transform");
|
|
25
25
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
26
|
+
const xor_1 = __importDefault(require("lodash/xor"));
|
|
26
27
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
27
28
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
28
29
|
const DeleteFootnoteDialog_1 = require("../components/views/DeleteFootnoteDialog");
|
|
@@ -32,25 +33,31 @@ const base_node_view_1 = require("./base_node_view");
|
|
|
32
33
|
const creators_1 = require("./creators");
|
|
33
34
|
const ReactSubView_1 = __importDefault(require("./ReactSubView"));
|
|
34
35
|
const navigation_utils_1 = require("../lib/navigation-utils");
|
|
36
|
+
const view_1 = require("../lib/view");
|
|
35
37
|
class FootnoteView extends base_node_view_1.BaseNodeView {
|
|
36
38
|
constructor() {
|
|
37
39
|
super(...arguments);
|
|
40
|
+
this.isMenuShown = false;
|
|
41
|
+
this.previousActionsLabels = [];
|
|
38
42
|
this.initialise = () => {
|
|
39
43
|
this.dom = document.createElement('div');
|
|
40
44
|
this.dom.classList.add('footnote');
|
|
41
45
|
this.dom.tabIndex = 0;
|
|
42
46
|
this.contentDOM = document.createElement('div');
|
|
43
47
|
this.contentDOM.classList.add('footnote-text');
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const element = event.target;
|
|
50
|
-
const item = element.closest('.footnote');
|
|
51
|
-
if (item) {
|
|
52
|
-
this.showContextMenu(item, fromKeyboard);
|
|
48
|
+
if (!this.view.editable) {
|
|
49
|
+
const actions = this.getContextMenuActions();
|
|
50
|
+
if (actions.length > 0) {
|
|
51
|
+
this.dom.addEventListener('mousedown', () => this.showContextMenu(actions, true));
|
|
52
|
+
}
|
|
53
53
|
}
|
|
54
|
+
this.dom.addEventListener('keydown', (0, navigation_utils_1.handleEnterKey)(() => {
|
|
55
|
+
const actions = this.getContextMenuActions();
|
|
56
|
+
if (actions.length > 0) {
|
|
57
|
+
this.showContextMenu(actions, true);
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
this.updateContents();
|
|
54
61
|
};
|
|
55
62
|
this.handleMarkerClick = (e) => {
|
|
56
63
|
e?.preventDefault();
|
|
@@ -134,35 +141,53 @@ class FootnoteView extends base_node_view_1.BaseNodeView {
|
|
|
134
141
|
this.dom.innerHTML = '';
|
|
135
142
|
this.dom.appendChild(marker);
|
|
136
143
|
this.contentDOM && this.dom.appendChild(this.contentDOM);
|
|
144
|
+
const selectionInsideNode = (0, view_1.isSelectionInsideNode)(this.view, this.node, this.getPos());
|
|
145
|
+
const actions = this.getContextMenuActions();
|
|
146
|
+
const hasActions = actions.length > 0;
|
|
147
|
+
const currentLabels = actions.map(({ label }) => label);
|
|
148
|
+
const changedLabels = (0, xor_1.default)(currentLabels, this.previousActionsLabels);
|
|
149
|
+
if (selectionInsideNode &&
|
|
150
|
+
hasActions &&
|
|
151
|
+
(!this.isMenuShown || changedLabels.length > 0)) {
|
|
152
|
+
this.showContextMenu(actions, false);
|
|
153
|
+
this.previousActionsLabels = actions.map(({ label }) => label);
|
|
154
|
+
}
|
|
155
|
+
else if ((!hasActions || !selectionInsideNode) && this.isMenuShown) {
|
|
156
|
+
this.props.popper.destroy();
|
|
157
|
+
this.isMenuShown = false;
|
|
158
|
+
this.previousActionsLabels = [];
|
|
159
|
+
}
|
|
137
160
|
}
|
|
138
161
|
getFootnoteState() {
|
|
139
162
|
const id = this.node.attrs.id;
|
|
140
163
|
const fn = (0, footnotes_1.getFootnotesElementState)(this.view.state, id);
|
|
141
164
|
return { id, fn };
|
|
142
165
|
}
|
|
143
|
-
showContextMenu(
|
|
166
|
+
showContextMenu(actions, autoFocus) {
|
|
167
|
+
this.isMenuShown = true;
|
|
144
168
|
this.props.popper.destroy();
|
|
169
|
+
this.contextMenu = (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, { actions }, this.node, this.getPos, this.view, ['context-menu', 'footnote-context-menu']);
|
|
170
|
+
this.props.popper.show(this.dom, this.contextMenu, 'right-start', true, [], autoFocus, false);
|
|
171
|
+
}
|
|
172
|
+
getContextMenuActions() {
|
|
145
173
|
const can = this.props.getCapabilities();
|
|
146
174
|
const { id, fn } = this.getFootnoteState();
|
|
147
|
-
const
|
|
148
|
-
actions: [],
|
|
149
|
-
};
|
|
175
|
+
const actions = [];
|
|
150
176
|
if (!fn?.unusedFootnoteIDs.has(id)) {
|
|
151
|
-
|
|
152
|
-
label: 'Go to footnote
|
|
177
|
+
actions.push({
|
|
178
|
+
label: 'Go to footnote Reference',
|
|
153
179
|
action: () => this.handleMarkerClick(),
|
|
154
180
|
icon: 'Scroll',
|
|
155
181
|
});
|
|
156
182
|
}
|
|
157
183
|
if (can.editArticle && !(0, track_changes_plugin_1.isDeleted)(this.node)) {
|
|
158
|
-
|
|
184
|
+
actions.push({
|
|
159
185
|
label: 'Delete',
|
|
160
186
|
action: () => this.handleDeleteClick(),
|
|
161
187
|
icon: 'Delete',
|
|
162
188
|
});
|
|
163
189
|
}
|
|
164
|
-
|
|
165
|
-
this.props.popper.show(element, this.contextMenu, 'right-start', true, [], autoFocus);
|
|
190
|
+
return actions;
|
|
166
191
|
}
|
|
167
192
|
}
|
|
168
193
|
exports.FootnoteView = FootnoteView;
|