@manuscripts/body-editor 2.8.1 → 2.8.2
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/components/toolbar/helpers.js +135 -0
- package/dist/cjs/components/toolbar/type-selector/OptionComponent.js +31 -0
- package/dist/cjs/components/toolbar/type-selector/TypeSelector.js +85 -0
- package/dist/cjs/components/toolbar/type-selector/styles.js +24 -0
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/versions.js +1 -1
- package/dist/es/components/toolbar/helpers.js +127 -0
- package/dist/es/components/toolbar/type-selector/OptionComponent.js +24 -0
- package/dist/es/components/toolbar/type-selector/TypeSelector.js +78 -0
- package/dist/es/components/toolbar/type-selector/styles.js +18 -0
- package/dist/es/index.js +1 -1
- package/dist/es/versions.js +1 -1
- package/dist/types/components/toolbar/helpers.d.ts +8 -0
- package/dist/types/components/toolbar/type-selector/OptionComponent.d.ts +4 -0
- package/dist/types/components/toolbar/type-selector/TypeSelector.d.ts +15 -0
- package/dist/types/components/toolbar/type-selector/styles.d.ts +105 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/components/toolbar/LevelSelector.js +0 -467
- package/dist/es/components/toolbar/LevelSelector.js +0 -460
- package/dist/types/components/toolbar/LevelSelector.d.ts +0 -23
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CSSObjectWithLabel } from 'react-select';
|
|
3
|
+
import { Option } from './TypeSelector';
|
|
4
|
+
export declare const StyledSelect: import("styled-components").StyledComponent<(props: Omit<Pick<import("react-select/dist/declarations/src/Select").Props<Option, false, import("react-select").GroupBase<Option>>, "id" | "form" | "name" | "value" | "theme" | "className" | "aria-errormessage" | "aria-invalid" | "aria-label" | "aria-labelledby" | "onFocus" | "onBlur" | "onChange" | "onKeyDown" | "autoFocus" | "required" | "ariaLiveMessages" | "classNamePrefix" | "delimiter" | "formatOptionLabel" | "hideSelectedOptions" | "inputValue" | "inputId" | "instanceId" | "isClearable" | "isOptionSelected" | "menuPortalTarget" | "onInputChange" | "onMenuOpen" | "onMenuClose" | "onMenuScrollToTop" | "onMenuScrollToBottom"> & {
|
|
5
|
+
placeholder?: import("react").ReactNode;
|
|
6
|
+
options?: import("react-select").OptionsOrGroups<Option, import("react-select").GroupBase<Option>> | undefined;
|
|
7
|
+
tabIndex?: number | undefined;
|
|
8
|
+
'aria-live'?: "off" | "assertive" | "polite" | undefined;
|
|
9
|
+
backspaceRemovesValue?: boolean | undefined;
|
|
10
|
+
blurInputOnSelect?: boolean | undefined;
|
|
11
|
+
captureMenuScroll?: boolean | undefined;
|
|
12
|
+
classNames?: import("react-select").ClassNamesConfig<Option, false, import("react-select").GroupBase<Option>> | undefined;
|
|
13
|
+
closeMenuOnSelect?: boolean | undefined;
|
|
14
|
+
closeMenuOnScroll?: boolean | ((event: Event) => boolean) | undefined;
|
|
15
|
+
components?: Partial<import("react-select/dist/declarations/src/components").SelectComponents<Option, false, import("react-select").GroupBase<Option>>> | undefined;
|
|
16
|
+
controlShouldRenderValue?: boolean | undefined;
|
|
17
|
+
escapeClearsValue?: boolean | undefined;
|
|
18
|
+
filterOption?: ((option: import("react-select/dist/declarations/src/filters").FilterOptionOption<Option>, inputValue: string) => boolean) | null | undefined;
|
|
19
|
+
formatGroupLabel?: ((group: import("react-select").GroupBase<Option>) => import("react").ReactNode) | undefined;
|
|
20
|
+
getOptionLabel?: import("react-select").GetOptionLabel<Option> | undefined;
|
|
21
|
+
getOptionValue?: import("react-select").GetOptionValue<Option> | undefined;
|
|
22
|
+
isDisabled?: boolean | undefined;
|
|
23
|
+
isLoading?: boolean | undefined;
|
|
24
|
+
isOptionDisabled?: ((option: Option, selectValue: import("react-select").Options<Option>) => boolean) | undefined;
|
|
25
|
+
isMulti?: false | undefined;
|
|
26
|
+
isRtl?: boolean | undefined;
|
|
27
|
+
isSearchable?: boolean | undefined;
|
|
28
|
+
loadingMessage?: ((obj: {
|
|
29
|
+
inputValue: string;
|
|
30
|
+
}) => import("react").ReactNode) | undefined;
|
|
31
|
+
minMenuHeight?: number | undefined;
|
|
32
|
+
maxMenuHeight?: number | undefined;
|
|
33
|
+
menuIsOpen?: boolean | undefined;
|
|
34
|
+
menuPlacement?: import("react-select").MenuPlacement | undefined;
|
|
35
|
+
menuPosition?: import("react-select").MenuPosition | undefined;
|
|
36
|
+
menuShouldBlockScroll?: boolean | undefined;
|
|
37
|
+
menuShouldScrollIntoView?: boolean | undefined;
|
|
38
|
+
noOptionsMessage?: ((obj: {
|
|
39
|
+
inputValue: string;
|
|
40
|
+
}) => import("react").ReactNode) | undefined;
|
|
41
|
+
openMenuOnFocus?: boolean | undefined;
|
|
42
|
+
openMenuOnClick?: boolean | undefined;
|
|
43
|
+
pageSize?: number | undefined;
|
|
44
|
+
screenReaderStatus?: ((obj: {
|
|
45
|
+
count: number;
|
|
46
|
+
}) => string) | undefined;
|
|
47
|
+
styles?: import("react-select").StylesConfig<Option, false, import("react-select").GroupBase<Option>> | undefined;
|
|
48
|
+
tabSelectsValue?: boolean | undefined;
|
|
49
|
+
unstyled?: boolean | undefined;
|
|
50
|
+
} & {}, "value" | "onChange" | "inputValue" | "menuIsOpen" | "onInputChange" | "onMenuOpen" | "onMenuClose"> & Partial<Pick<import("react-select/dist/declarations/src/Select").Props<Option, false, import("react-select").GroupBase<Option>>, "id" | "form" | "name" | "value" | "theme" | "className" | "aria-errormessage" | "aria-invalid" | "aria-label" | "aria-labelledby" | "onFocus" | "onBlur" | "onChange" | "onKeyDown" | "autoFocus" | "required" | "ariaLiveMessages" | "classNamePrefix" | "delimiter" | "formatOptionLabel" | "hideSelectedOptions" | "inputValue" | "inputId" | "instanceId" | "isClearable" | "isOptionSelected" | "menuPortalTarget" | "onInputChange" | "onMenuOpen" | "onMenuClose" | "onMenuScrollToTop" | "onMenuScrollToBottom"> & {
|
|
51
|
+
placeholder?: import("react").ReactNode;
|
|
52
|
+
options?: import("react-select").OptionsOrGroups<Option, import("react-select").GroupBase<Option>> | undefined;
|
|
53
|
+
tabIndex?: number | undefined;
|
|
54
|
+
'aria-live'?: "off" | "assertive" | "polite" | undefined;
|
|
55
|
+
backspaceRemovesValue?: boolean | undefined;
|
|
56
|
+
blurInputOnSelect?: boolean | undefined;
|
|
57
|
+
captureMenuScroll?: boolean | undefined;
|
|
58
|
+
classNames?: import("react-select").ClassNamesConfig<Option, false, import("react-select").GroupBase<Option>> | undefined;
|
|
59
|
+
closeMenuOnSelect?: boolean | undefined;
|
|
60
|
+
closeMenuOnScroll?: boolean | ((event: Event) => boolean) | undefined;
|
|
61
|
+
components?: Partial<import("react-select/dist/declarations/src/components").SelectComponents<Option, false, import("react-select").GroupBase<Option>>> | undefined;
|
|
62
|
+
controlShouldRenderValue?: boolean | undefined;
|
|
63
|
+
escapeClearsValue?: boolean | undefined;
|
|
64
|
+
filterOption?: ((option: import("react-select/dist/declarations/src/filters").FilterOptionOption<Option>, inputValue: string) => boolean) | null | undefined;
|
|
65
|
+
formatGroupLabel?: ((group: import("react-select").GroupBase<Option>) => import("react").ReactNode) | undefined;
|
|
66
|
+
getOptionLabel?: import("react-select").GetOptionLabel<Option> | undefined;
|
|
67
|
+
getOptionValue?: import("react-select").GetOptionValue<Option> | undefined;
|
|
68
|
+
isDisabled?: boolean | undefined;
|
|
69
|
+
isLoading?: boolean | undefined;
|
|
70
|
+
isOptionDisabled?: ((option: Option, selectValue: import("react-select").Options<Option>) => boolean) | undefined;
|
|
71
|
+
isMulti?: false | undefined;
|
|
72
|
+
isRtl?: boolean | undefined;
|
|
73
|
+
isSearchable?: boolean | undefined;
|
|
74
|
+
loadingMessage?: ((obj: {
|
|
75
|
+
inputValue: string;
|
|
76
|
+
}) => import("react").ReactNode) | undefined;
|
|
77
|
+
minMenuHeight?: number | undefined;
|
|
78
|
+
maxMenuHeight?: number | undefined;
|
|
79
|
+
menuIsOpen?: boolean | undefined;
|
|
80
|
+
menuPlacement?: import("react-select").MenuPlacement | undefined;
|
|
81
|
+
menuPosition?: import("react-select").MenuPosition | undefined;
|
|
82
|
+
menuShouldBlockScroll?: boolean | undefined;
|
|
83
|
+
menuShouldScrollIntoView?: boolean | undefined;
|
|
84
|
+
noOptionsMessage?: ((obj: {
|
|
85
|
+
inputValue: string;
|
|
86
|
+
}) => import("react").ReactNode) | undefined;
|
|
87
|
+
openMenuOnFocus?: boolean | undefined;
|
|
88
|
+
openMenuOnClick?: boolean | undefined;
|
|
89
|
+
pageSize?: number | undefined;
|
|
90
|
+
screenReaderStatus?: ((obj: {
|
|
91
|
+
count: number;
|
|
92
|
+
}) => string) | undefined;
|
|
93
|
+
styles?: import("react-select").StylesConfig<Option, false, import("react-select").GroupBase<Option>> | undefined;
|
|
94
|
+
tabSelectsValue?: boolean | undefined;
|
|
95
|
+
unstyled?: boolean | undefined;
|
|
96
|
+
} & {}> & import("react-select/dist/declarations/src/useStateManager").StateManagerAdditionalProps<Option> & import("react").RefAttributes<import("react-select/dist/declarations/src/Select").default<Option, false, import("react-select").GroupBase<Option>>>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, any, {}, never>;
|
|
97
|
+
export declare const customStyles: {
|
|
98
|
+
control: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
99
|
+
indicatorSeparator: () => CSSObjectWithLabel;
|
|
100
|
+
dropdownIndicator: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
101
|
+
menu: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
102
|
+
singleValue: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
103
|
+
valueContainer: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
104
|
+
container: (styles: CSSObjectWithLabel) => CSSObjectWithLabel;
|
|
105
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
export * from './commands';
|
|
17
17
|
export { ManuscriptOutline } from './components/outline/ManuscriptOutline';
|
|
18
18
|
export { OutlineItemIcon } from './components/outline/Outline';
|
|
19
|
-
export {
|
|
19
|
+
export { TypeSelector } from './components/toolbar/type-selector/TypeSelector';
|
|
20
20
|
export * from './components/toolbar/ListMenuItem';
|
|
21
21
|
export * from './components/toolbar/InsertTableDialog';
|
|
22
22
|
export * from './menus';
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.8.
|
|
1
|
+
export declare const VERSION = "2.8.2";
|
|
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.8.
|
|
4
|
+
"version": "2.8.2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@iarna/word-count": "^1.1.2",
|
|
33
33
|
"@manuscripts/json-schema": "2.2.11",
|
|
34
34
|
"@manuscripts/library": "1.3.11",
|
|
35
|
-
"@manuscripts/style-guide": "2.1.
|
|
35
|
+
"@manuscripts/style-guide": "2.1.1",
|
|
36
36
|
"@manuscripts/track-changes-plugin": "1.10.0",
|
|
37
37
|
"@manuscripts/transform": "3.0.45",
|
|
38
38
|
"@popperjs/core": "^2.11.8",
|
|
@@ -1,467 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* © 2024 Atypon Systems LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.LevelSelector = void 0;
|
|
22
|
-
const transform_1 = require("@manuscripts/transform");
|
|
23
|
-
const prosemirror_model_1 = require("prosemirror-model");
|
|
24
|
-
const prosemirror_state_1 = require("prosemirror-state");
|
|
25
|
-
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
26
|
-
const react_1 = __importDefault(require("react"));
|
|
27
|
-
const react_select_1 = __importDefault(require("react-select"));
|
|
28
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
29
|
-
const hierarchy_1 = require("../../lib/hierarchy");
|
|
30
|
-
const node_type_icons_1 = require("../../node-type-icons");
|
|
31
|
-
const optionName = (nodeType, depth, listType) => {
|
|
32
|
-
switch (nodeType) {
|
|
33
|
-
case nodeType.schema.nodes.section:
|
|
34
|
-
return (depth > 0 ? 'sub'.repeat(depth - 1) : '') + 'section heading';
|
|
35
|
-
case nodeType.schema.nodes.list:
|
|
36
|
-
return listType === 'order' ? 'Ordered list' : 'Bulleted list';
|
|
37
|
-
default:
|
|
38
|
-
return transform_1.nodeNames.get(nodeType) || nodeType.name;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const titleCase = (text) => text.replace(/\b([a-z])/g, (match) => match.toUpperCase());
|
|
42
|
-
const buildOption = (props) => (Object.assign(Object.assign({}, props), { icon: (0, node_type_icons_1.nodeTypeIcon)(props.nodeType, props.listType), label: titleCase(optionName(props.nodeType, props.depth, props.listType)), isDisabled: Boolean(props.isDisabled), isSelected: Boolean(props.isSelected), isFocused: Boolean(props.isFocused) }));
|
|
43
|
-
const buildOptions = (state, dispatch, view) => {
|
|
44
|
-
var _a;
|
|
45
|
-
const { doc, selection: { $from, $to }, schema, tr, } = state;
|
|
46
|
-
const { nodes } = schema;
|
|
47
|
-
if (!$from.sameParent($to)) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const parentElement = (0, hierarchy_1.findClosestParentElement)($from);
|
|
51
|
-
if (!parentElement) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const depth = ((_a = (0, prosemirror_utils_1.findParentNodeOfType)(schema.nodes.box_element)(state.selection)) === null || _a === void 0 ? void 0 : _a.depth) || 1;
|
|
55
|
-
const moveParagraphToNewSubsection = () => {
|
|
56
|
-
const paragraph = $from.node($from.depth);
|
|
57
|
-
const beforeParagraph = $from.before($from.depth);
|
|
58
|
-
const afterParagraph = $from.after($from.depth);
|
|
59
|
-
const $afterParagraph = doc.resolve(afterParagraph);
|
|
60
|
-
const afterParagraphOffset = $afterParagraph.parentOffset;
|
|
61
|
-
const sectionDepth = $from.depth - 1;
|
|
62
|
-
const parentSection = $from.node(sectionDepth);
|
|
63
|
-
const endIndex = $from.indexAfter(sectionDepth);
|
|
64
|
-
const sectionEnd = $from.end(sectionDepth);
|
|
65
|
-
const textContent = paragraph.textContent;
|
|
66
|
-
const sectionTitle = textContent
|
|
67
|
-
? nodes.section_title.create({}, schema.text(textContent))
|
|
68
|
-
: nodes.section_title.create();
|
|
69
|
-
let sectionContent = prosemirror_model_1.Fragment.from(sectionTitle);
|
|
70
|
-
if (endIndex < parentSection.childCount) {
|
|
71
|
-
sectionContent = sectionContent.append(parentSection.content.cut(afterParagraphOffset));
|
|
72
|
-
}
|
|
73
|
-
const newSection = nodes.section.create({
|
|
74
|
-
id: (0, transform_1.generateNodeID)(nodes.section),
|
|
75
|
-
}, sectionContent);
|
|
76
|
-
tr.replaceWith(beforeParagraph, sectionEnd, newSection);
|
|
77
|
-
const anchor = beforeParagraph + 2;
|
|
78
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + sectionTitle.content.size));
|
|
79
|
-
dispatch(tr.scrollIntoView());
|
|
80
|
-
view && view.focus();
|
|
81
|
-
};
|
|
82
|
-
const moveSectionToSubsection = () => {
|
|
83
|
-
const sectionTitle = $from.node();
|
|
84
|
-
const sectionDepth = $from.depth - 1;
|
|
85
|
-
const section = $from.node(sectionDepth);
|
|
86
|
-
const beforeSection = $from.before(sectionDepth);
|
|
87
|
-
const afterSection = $from.after(sectionDepth);
|
|
88
|
-
const parentSectionDepth = $from.depth - 2;
|
|
89
|
-
const parentSection = $from.node(parentSectionDepth);
|
|
90
|
-
const startIndex = $from.index(parentSectionDepth);
|
|
91
|
-
const previousSection = parentSection.child(startIndex - 1);
|
|
92
|
-
const beforePreviousSection = beforeSection - previousSection.nodeSize;
|
|
93
|
-
tr.replaceWith(beforePreviousSection, afterSection, previousSection.content.append(prosemirror_model_1.Fragment.from(section)));
|
|
94
|
-
const anchor = beforeSection + 1;
|
|
95
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + sectionTitle.content.size));
|
|
96
|
-
dispatch(tr.scrollIntoView());
|
|
97
|
-
view && view.focus();
|
|
98
|
-
};
|
|
99
|
-
const promoteSection = (target) => () => {
|
|
100
|
-
const sectionDepth = $from.depth - 1;
|
|
101
|
-
const section = $from.node(sectionDepth);
|
|
102
|
-
const beforeSection = $from.before(sectionDepth);
|
|
103
|
-
const sectionTitle = $from.node($from.depth);
|
|
104
|
-
const $beforeSection = doc.resolve(beforeSection);
|
|
105
|
-
const beforeSectionOffset = $beforeSection.parentOffset;
|
|
106
|
-
const afterSectionOffset = beforeSectionOffset + section.nodeSize;
|
|
107
|
-
const parentSectionDepth = $from.depth - 2;
|
|
108
|
-
const parentSection = $from.node(parentSectionDepth);
|
|
109
|
-
const startIndex = $from.index(parentSectionDepth);
|
|
110
|
-
const endIndex = $from.indexAfter(parentSectionDepth);
|
|
111
|
-
const beforeParentSection = $from.before(parentSectionDepth);
|
|
112
|
-
const afterParentSection = $from.after(parentSectionDepth);
|
|
113
|
-
const items = [];
|
|
114
|
-
let offset = 0;
|
|
115
|
-
if (startIndex > 0) {
|
|
116
|
-
const precedingSection = parentSection.cut(0, beforeSectionOffset);
|
|
117
|
-
items.push(precedingSection);
|
|
118
|
-
offset += precedingSection.nodeSize;
|
|
119
|
-
}
|
|
120
|
-
items.push(section);
|
|
121
|
-
if (endIndex < parentSection.childCount) {
|
|
122
|
-
const fragment = prosemirror_model_1.Fragment.from(nodes.section_title.create()).append(parentSection.content.cut(afterSectionOffset));
|
|
123
|
-
items.push(parentSection.copy(fragment));
|
|
124
|
-
}
|
|
125
|
-
tr.replaceWith(beforeParentSection, afterParentSection, items);
|
|
126
|
-
const anchor = beforeParentSection + offset + 2;
|
|
127
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + sectionTitle.content.size));
|
|
128
|
-
dispatch(tr.scrollIntoView());
|
|
129
|
-
view && view.focus();
|
|
130
|
-
};
|
|
131
|
-
const promoteParagraphToSection = (target) => () => {
|
|
132
|
-
const paragraph = $from.node($from.depth);
|
|
133
|
-
const beforeParagraph = $from.before($from.depth);
|
|
134
|
-
const $beforeParagraph = doc.resolve(beforeParagraph);
|
|
135
|
-
const beforeParagraphOffset = $beforeParagraph.parentOffset;
|
|
136
|
-
const afterParagraphOffset = beforeParagraphOffset + paragraph.nodeSize;
|
|
137
|
-
const sectionDepth = $from.depth - depth;
|
|
138
|
-
const parentSection = $from.node(sectionDepth);
|
|
139
|
-
const startIndex = $from.index(sectionDepth);
|
|
140
|
-
const endIndex = $from.indexAfter(sectionDepth);
|
|
141
|
-
const beforeParentSection = $from.before(sectionDepth);
|
|
142
|
-
const afterParentSection = $from.after(sectionDepth);
|
|
143
|
-
const items = [];
|
|
144
|
-
let offset = 0;
|
|
145
|
-
if (startIndex > 0) {
|
|
146
|
-
const precedingSection = parentSection.cut(0, beforeParagraphOffset);
|
|
147
|
-
items.push(precedingSection);
|
|
148
|
-
offset += precedingSection.nodeSize;
|
|
149
|
-
}
|
|
150
|
-
const textContent = paragraph.textContent;
|
|
151
|
-
const sectionTitle = textContent
|
|
152
|
-
? nodes.section_title.create({}, schema.text(textContent))
|
|
153
|
-
: nodes.section_title.create();
|
|
154
|
-
let sectionContent = prosemirror_model_1.Fragment.from(sectionTitle);
|
|
155
|
-
if (endIndex < parentSection.childCount) {
|
|
156
|
-
sectionContent = sectionContent.append(parentSection.content.cut(afterParagraphOffset));
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
sectionContent = sectionContent.append(prosemirror_model_1.Fragment.from(paragraph.copy()));
|
|
160
|
-
}
|
|
161
|
-
items.push(parentSection.copy(sectionContent));
|
|
162
|
-
tr.replaceWith(beforeParentSection, afterParentSection, items);
|
|
163
|
-
const anchor = beforeParentSection + offset + 2;
|
|
164
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + sectionTitle.content.size));
|
|
165
|
-
dispatch(tr.scrollIntoView());
|
|
166
|
-
view && view.focus();
|
|
167
|
-
};
|
|
168
|
-
const demoteSectionToParagraph = () => {
|
|
169
|
-
const sectionTitle = $from.node($from.depth);
|
|
170
|
-
const afterSectionTitle = $from.after($from.depth);
|
|
171
|
-
const $afterSectionTitle = doc.resolve(afterSectionTitle);
|
|
172
|
-
const afterSectionTitleOffset = $afterSectionTitle.parentOffset;
|
|
173
|
-
const sectionDepth = $from.depth - depth;
|
|
174
|
-
const section = $from.node(sectionDepth);
|
|
175
|
-
const beforeSection = $from.before(sectionDepth);
|
|
176
|
-
const afterSection = $from.after(sectionDepth);
|
|
177
|
-
const $beforeSection = doc.resolve(beforeSection);
|
|
178
|
-
const previousNode = $beforeSection.nodeBefore;
|
|
179
|
-
const paragraph = nodes.paragraph.create({
|
|
180
|
-
id: (0, transform_1.generateNodeID)(nodes.paragraph),
|
|
181
|
-
}, sectionTitle.content);
|
|
182
|
-
let anchor;
|
|
183
|
-
if (previousNode && (0, transform_1.isSectionNodeType)(previousNode.type)) {
|
|
184
|
-
tr.replaceWith(beforeSection - previousNode.nodeSize, afterSection, previousNode.copy(prosemirror_model_1.Fragment.from(previousNode.content)
|
|
185
|
-
.append(prosemirror_model_1.Fragment.from(paragraph))
|
|
186
|
-
.append(section.content.cut(afterSectionTitleOffset))));
|
|
187
|
-
anchor = beforeSection;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
tr.replaceWith(beforeSection, afterSection, prosemirror_model_1.Fragment.from(paragraph).append(section.content.cut(afterSectionTitleOffset)));
|
|
191
|
-
anchor = beforeSection + 1;
|
|
192
|
-
}
|
|
193
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + paragraph.content.size));
|
|
194
|
-
dispatch(tr.scrollIntoView());
|
|
195
|
-
view && view.focus();
|
|
196
|
-
};
|
|
197
|
-
const convertParagraphToList = (nodeType, listType) => () => {
|
|
198
|
-
const paragraph = $from.node($from.depth);
|
|
199
|
-
const beforeParagraph = $from.before($from.depth);
|
|
200
|
-
const afterParagraph = $from.after($from.depth);
|
|
201
|
-
const list = nodeType.create({
|
|
202
|
-
id: (0, transform_1.generateNodeID)(nodeType),
|
|
203
|
-
listStyleType: listType,
|
|
204
|
-
}, nodes.list_item.create({}, schema.nodes.paragraph.create({}, paragraph.content)));
|
|
205
|
-
tr.replaceWith(beforeParagraph, afterParagraph, list);
|
|
206
|
-
const anchor = beforeParagraph + 3;
|
|
207
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + paragraph.content.size));
|
|
208
|
-
dispatch(tr.scrollIntoView());
|
|
209
|
-
view && view.focus();
|
|
210
|
-
};
|
|
211
|
-
const convertListType = (nodeType, list, listType) => () => {
|
|
212
|
-
tr.setNodeMarkup(list.before, nodeType, Object.assign(Object.assign({}, list.node.attrs), { listStyleType: listType }));
|
|
213
|
-
dispatch(tr.scrollIntoView());
|
|
214
|
-
view && view.focus();
|
|
215
|
-
};
|
|
216
|
-
const parentElementType = parentElement.node.type;
|
|
217
|
-
switch (parentElementType) {
|
|
218
|
-
case parentElementType.schema.nodes.section: {
|
|
219
|
-
const sectionDepth = Math.max(1, $from.depth - depth);
|
|
220
|
-
const parentSectionDepth = sectionDepth - 1;
|
|
221
|
-
const minimumDepth = Math.max(1, parentSectionDepth);
|
|
222
|
-
const beforeSection = $from.before(sectionDepth);
|
|
223
|
-
const $beforeSection = doc.resolve(beforeSection);
|
|
224
|
-
const sectionOffset = $beforeSection.parentOffset;
|
|
225
|
-
const typeOptions = [
|
|
226
|
-
buildOption({
|
|
227
|
-
nodeType: nodes.paragraph,
|
|
228
|
-
value: -4,
|
|
229
|
-
depth: 1,
|
|
230
|
-
action: demoteSectionToParagraph,
|
|
231
|
-
isDisabled: sectionDepth <= 1 && sectionOffset <= 1,
|
|
232
|
-
}),
|
|
233
|
-
buildOption({
|
|
234
|
-
nodeType: nodes.list,
|
|
235
|
-
value: -3,
|
|
236
|
-
depth: 1,
|
|
237
|
-
isDisabled: true,
|
|
238
|
-
listType: 'order',
|
|
239
|
-
}),
|
|
240
|
-
buildOption({
|
|
241
|
-
nodeType: nodes.list,
|
|
242
|
-
value: -2,
|
|
243
|
-
depth: 1,
|
|
244
|
-
isDisabled: true,
|
|
245
|
-
listType: 'bullet',
|
|
246
|
-
}),
|
|
247
|
-
];
|
|
248
|
-
const sectionOptions = [];
|
|
249
|
-
for (let depth = 2; depth < sectionDepth; depth++) {
|
|
250
|
-
const node = $from.node(depth);
|
|
251
|
-
if ((0, transform_1.isSectionNodeType)(node.type)) {
|
|
252
|
-
const indentLevel = depth - 1;
|
|
253
|
-
sectionOptions.push(buildOption({
|
|
254
|
-
nodeType: nodes.section,
|
|
255
|
-
value: depth,
|
|
256
|
-
depth: indentLevel,
|
|
257
|
-
action: promoteSection(depth),
|
|
258
|
-
isDisabled: depth < minimumDepth,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
sectionOptions.push(buildOption({
|
|
263
|
-
nodeType: nodes.section,
|
|
264
|
-
value: parentSectionDepth + 1,
|
|
265
|
-
depth: parentSectionDepth,
|
|
266
|
-
isDisabled: true,
|
|
267
|
-
isSelected: true,
|
|
268
|
-
}));
|
|
269
|
-
const parentSection = $from.node(parentSectionDepth);
|
|
270
|
-
const beforeSectionPos = $from.before(parentSectionDepth + 1);
|
|
271
|
-
const $beforeSectionPos = doc.resolve(beforeSectionPos);
|
|
272
|
-
const precedingSections = [];
|
|
273
|
-
parentSection.nodesBetween(0, $beforeSectionPos.parentOffset, (node) => {
|
|
274
|
-
if ((0, transform_1.isSectionNodeType)(node.type)) {
|
|
275
|
-
precedingSections.push(node);
|
|
276
|
-
}
|
|
277
|
-
return false;
|
|
278
|
-
});
|
|
279
|
-
if (precedingSections.length > 0) {
|
|
280
|
-
sectionOptions.push(buildOption({
|
|
281
|
-
nodeType: nodes.section,
|
|
282
|
-
value: parentSectionDepth + 2,
|
|
283
|
-
depth: parentSectionDepth + 2,
|
|
284
|
-
action: moveSectionToSubsection,
|
|
285
|
-
}));
|
|
286
|
-
}
|
|
287
|
-
return [{ options: typeOptions }, { options: sectionOptions }];
|
|
288
|
-
}
|
|
289
|
-
case parentElementType.schema.nodes.paragraph: {
|
|
290
|
-
const sectionDepth = $from.depth - depth;
|
|
291
|
-
const minimumDepth = Math.max(1, sectionDepth);
|
|
292
|
-
let parentSectionDepth = 0;
|
|
293
|
-
const typeOptions = [
|
|
294
|
-
buildOption({
|
|
295
|
-
nodeType: nodes.paragraph,
|
|
296
|
-
value: -4,
|
|
297
|
-
depth: 1,
|
|
298
|
-
isDisabled: true,
|
|
299
|
-
isSelected: true,
|
|
300
|
-
}),
|
|
301
|
-
buildOption({
|
|
302
|
-
nodeType: nodes.list,
|
|
303
|
-
value: -3,
|
|
304
|
-
depth: 1,
|
|
305
|
-
action: convertParagraphToList(nodes.list, 'order'),
|
|
306
|
-
listType: 'order',
|
|
307
|
-
}),
|
|
308
|
-
buildOption({
|
|
309
|
-
nodeType: nodes.list,
|
|
310
|
-
value: -2,
|
|
311
|
-
depth: 1,
|
|
312
|
-
action: convertParagraphToList(nodes.list, 'bullet'),
|
|
313
|
-
listType: 'bullet',
|
|
314
|
-
}),
|
|
315
|
-
];
|
|
316
|
-
const sectionOptions = [];
|
|
317
|
-
for (let depth = 2; depth <= sectionDepth; depth++) {
|
|
318
|
-
const node = $from.node(depth);
|
|
319
|
-
if ((0, transform_1.isSectionNodeType)(node.type)) {
|
|
320
|
-
const indentLevel = depth - 1;
|
|
321
|
-
sectionOptions.push(buildOption({
|
|
322
|
-
nodeType: nodes.section,
|
|
323
|
-
value: depth,
|
|
324
|
-
depth: indentLevel,
|
|
325
|
-
action: promoteParagraphToSection(depth),
|
|
326
|
-
isDisabled: depth < minimumDepth,
|
|
327
|
-
}));
|
|
328
|
-
parentSectionDepth = depth;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
sectionOptions.push(buildOption({
|
|
332
|
-
nodeType: nodes.section,
|
|
333
|
-
value: parentSectionDepth + 1,
|
|
334
|
-
depth: parentSectionDepth + 1,
|
|
335
|
-
action: moveParagraphToNewSubsection,
|
|
336
|
-
}));
|
|
337
|
-
return [{ options: typeOptions }, { options: sectionOptions }];
|
|
338
|
-
}
|
|
339
|
-
case schema.nodes.list: {
|
|
340
|
-
const { style } = (0, transform_1.getListType)(parentElement.node.attrs.listStyleType);
|
|
341
|
-
return [
|
|
342
|
-
{
|
|
343
|
-
options: [
|
|
344
|
-
buildOption({
|
|
345
|
-
nodeType: parentElementType,
|
|
346
|
-
value: -4,
|
|
347
|
-
depth: 1,
|
|
348
|
-
isDisabled: true,
|
|
349
|
-
isSelected: true,
|
|
350
|
-
}),
|
|
351
|
-
],
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
options: [
|
|
355
|
-
buildOption({
|
|
356
|
-
nodeType: nodes.list,
|
|
357
|
-
value: -3,
|
|
358
|
-
depth: 1,
|
|
359
|
-
action: convertListType(nodes.list, parentElement, style),
|
|
360
|
-
listType: style === 'none' || style === 'disc' ? 'bullet' : 'order',
|
|
361
|
-
}),
|
|
362
|
-
],
|
|
363
|
-
},
|
|
364
|
-
];
|
|
365
|
-
}
|
|
366
|
-
default: {
|
|
367
|
-
return [
|
|
368
|
-
buildOption({
|
|
369
|
-
nodeType: parentElementType,
|
|
370
|
-
value: -3,
|
|
371
|
-
depth: 1,
|
|
372
|
-
isDisabled: true,
|
|
373
|
-
isSelected: true,
|
|
374
|
-
}),
|
|
375
|
-
];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
const OptionContainer = styled_components_1.default.div `
|
|
380
|
-
display: flex;
|
|
381
|
-
align-items: center;
|
|
382
|
-
`;
|
|
383
|
-
const OptionIcon = styled_components_1.default.span `
|
|
384
|
-
display: inline-flex;
|
|
385
|
-
width: ${(props) => props.theme.grid.unit * 4}px;
|
|
386
|
-
justify-content: center;
|
|
387
|
-
align-items: center;
|
|
388
|
-
margin-right: ${(props) => props.theme.grid.unit * 2}px;
|
|
389
|
-
flex-shrink: 0;
|
|
390
|
-
`;
|
|
391
|
-
const OptionLabel = styled_components_1.default.span `
|
|
392
|
-
flex: 1;
|
|
393
|
-
`;
|
|
394
|
-
const Group = styled_components_1.default.div `
|
|
395
|
-
&:not(:last-child) {
|
|
396
|
-
border-bottom: 1px solid ${(props) => props.theme.colors.border.secondary};
|
|
397
|
-
}
|
|
398
|
-
`;
|
|
399
|
-
const StyledSelect = (0, styled_components_1.default)((react_select_1.default)) `
|
|
400
|
-
z-index: 3;
|
|
401
|
-
|
|
402
|
-
& > div:hover {
|
|
403
|
-
border-color: ${(props) => props.theme.colors.border.secondary};
|
|
404
|
-
}
|
|
405
|
-
`;
|
|
406
|
-
const findSelectedOption = (options) => {
|
|
407
|
-
for (const group of options) {
|
|
408
|
-
for (const option of group.options) {
|
|
409
|
-
if (option.isSelected) {
|
|
410
|
-
return option;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
const LevelSelector = ({ state, dispatch, view }) => {
|
|
416
|
-
const { schema: { nodes }, } = state;
|
|
417
|
-
const options = buildOptions(state, dispatch, view);
|
|
418
|
-
return (react_1.default.createElement(StyledSelect, { isDisabled: options.length <= 1, isSearchable: false, options: options, value: options.length === 1
|
|
419
|
-
? options[0]
|
|
420
|
-
: findSelectedOption(options), components: {
|
|
421
|
-
Group: (props) => (react_1.default.createElement(Group, Object.assign({}, props.innerProps, { ref: null }), props.children)),
|
|
422
|
-
GroupHeading: () => null,
|
|
423
|
-
Option: (props) => {
|
|
424
|
-
const data = props.data;
|
|
425
|
-
const style = props.getStyles('option', props);
|
|
426
|
-
style.display = 'flex';
|
|
427
|
-
style.fontSize = 16;
|
|
428
|
-
style.cursor = 'pointer';
|
|
429
|
-
style.paddingLeft = 8 + (data.depth - 1) * 16;
|
|
430
|
-
style.minWidth = 200;
|
|
431
|
-
if (data.nodeType === nodes.section) {
|
|
432
|
-
style.fontSize = Math.max(14, 23 - 3 * (data.value - 1));
|
|
433
|
-
style.fontWeight = 600;
|
|
434
|
-
}
|
|
435
|
-
if (props.isFocused) {
|
|
436
|
-
style.backgroundColor = '#f5fbfc';
|
|
437
|
-
}
|
|
438
|
-
if (props.isSelected) {
|
|
439
|
-
style.backgroundColor = '#f2fbfc';
|
|
440
|
-
style.borderBottom = '1px solid #bce7f6';
|
|
441
|
-
style.borderTop = '1px solid #bce7f6';
|
|
442
|
-
}
|
|
443
|
-
style.color = '#353535';
|
|
444
|
-
if (props.isDisabled && !props.isSelected) {
|
|
445
|
-
style.opacity = 0.4;
|
|
446
|
-
}
|
|
447
|
-
return (react_1.default.createElement(OptionContainer, Object.assign({}, props.innerProps, { ref: null, style: style }),
|
|
448
|
-
react_1.default.createElement(OptionIcon, null, (0, node_type_icons_1.nodeTypeIcon)(data.nodeType, data.listType)),
|
|
449
|
-
react_1.default.createElement(OptionLabel, null, data.label)));
|
|
450
|
-
},
|
|
451
|
-
}, onChange: (value) => {
|
|
452
|
-
if (value && value.action) {
|
|
453
|
-
value.action();
|
|
454
|
-
}
|
|
455
|
-
}, styles: {
|
|
456
|
-
control: (styles) => (Object.assign(Object.assign({}, styles), { backgroundColor: '#fff', borderWidth: 1, borderStyle: 'solid', borderColor: '#e2e2e2', boxShadow: 'none', fontSize: '14px', minHeight: 0, padding: 0, width: 200, overflowX: 'hidden', textOverflow: 'ellipsis', cursor: 'pointer', height: 32 })),
|
|
457
|
-
indicatorSeparator: () => ({
|
|
458
|
-
display: 'none',
|
|
459
|
-
}),
|
|
460
|
-
dropdownIndicator: (styles) => (Object.assign(Object.assign({}, styles), { padding: '0 4px' })),
|
|
461
|
-
menu: (styles) => (Object.assign(Object.assign({}, styles), { width: 'auto' })),
|
|
462
|
-
singleValue: (styles) => (Object.assign(Object.assign({}, styles), { padding: 0 })),
|
|
463
|
-
valueContainer: (styles) => (Object.assign(Object.assign({}, styles), { padding: '1px 8px' })),
|
|
464
|
-
container: (styles) => (Object.assign(Object.assign({}, styles), { border: 'none' })),
|
|
465
|
-
} }));
|
|
466
|
-
};
|
|
467
|
-
exports.LevelSelector = LevelSelector;
|