@modusoperandi/licit 0.1.9 → 0.13.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/.github/workflows/build.yml +1 -7
- package/.github/workflows/lint.yml +1 -1
- package/README.md +1 -1
- package/babel.config.json +54 -0
- package/dist/BlockquoteNodeSpec.js +2 -2
- package/dist/CZIProseMirror.js +4 -4
- package/dist/CodeBlockCommand.js +2 -2
- package/dist/CodeBlockCommand.js.flow +1 -1
- package/dist/CursorPlaceholderPlugin.js +2 -2
- package/dist/DocLayoutCommand.js +2 -4
- package/dist/DocLayoutCommand.js.flow +1 -1
- package/dist/DocNodeSpec.js +1 -1
- package/dist/EditorCommands.js +23 -35
- package/dist/EditorCommands.js.flow +7 -7
- package/dist/EditorKeyMap.js +3 -3
- package/dist/FontTypeMarkSpec.js +1 -1
- package/dist/HeadingNodeSpec.js +2 -2
- package/dist/ImageSourceCommand.js +2 -4
- package/dist/ImageSourceCommand.js.flow +1 -1
- package/dist/ImageUploadPlaceholderPlugin.js +1 -1
- package/dist/LinkSetURLCommand.js +4 -8
- package/dist/LinkSetURLCommand.js.flow +3 -3
- package/dist/LinkTooltipPlugin.js +9 -15
- package/dist/LinkTooltipPlugin.js.flow +5 -5
- package/dist/ListToggleCommand.js +5 -11
- package/dist/ListToggleCommand.js.flow +3 -3
- package/dist/MarkNames.js +1 -1
- package/dist/MarksClearCommand.js +3 -3
- package/dist/MarksClearCommand.js.flow +1 -1
- package/dist/MathEditCommand.js +2 -2
- package/dist/MathEditCommand.js.flow +1 -1
- package/dist/ParagraphNodeSpec.js +3 -4
- package/dist/ParagraphNodeSpec.js.flow +2 -6
- package/dist/ParagraphSpacingCommand.js +3 -3
- package/dist/SelectionPlaceholderPlugin.js +2 -2
- package/dist/SpacerMarkSpec.js +1 -1
- package/dist/TableBackgroundColorCommand.js +3 -7
- package/dist/TableBackgroundColorCommand.js.flow +3 -3
- package/dist/TableBorderColorCommand.js +3 -7
- package/dist/TableBorderColorCommand.js.flow +3 -3
- package/dist/TableCellColorCommand.js +3 -7
- package/dist/TableCellColorCommand.js.flow +3 -3
- package/dist/TableCellMenuPlugin.js +4 -6
- package/dist/TableCellMenuPlugin.js.flow +3 -3
- package/dist/TableInsertCommand.js +3 -5
- package/dist/TableInsertCommand.js.flow +2 -2
- package/dist/TableResizePlugin.js +2 -2
- package/dist/TextInsertTabSpaceCommand.js +2 -4
- package/dist/TextInsertTabSpaceCommand.js.flow +1 -1
- package/dist/Types.js +1 -1
- package/dist/bom.xml +4970 -4167
- package/dist/client/CollabConnector.js +17 -2
- package/dist/client/CollabConnector.js.flow +17 -2
- package/dist/client/EditorConnection.js +15 -4
- package/dist/client/EditorConnection.js.flow +14 -3
- package/dist/client/Licit.js +73 -58
- package/dist/client/Licit.js.flow +101 -85
- package/dist/client/Licit.test.js +18 -17
- package/dist/client/Licit.test.js.flow +13 -11
- package/dist/client/SimpleConnector.js +4 -2
- package/dist/client/SimpleConnector.js.flow +3 -1
- package/dist/client/http.js +3 -3
- package/dist/convertToCSSPTValue.js +1 -1
- package/dist/createEmptyEditorState.js +1 -1
- package/dist/index.js +16 -16
- package/dist/joinListNode.js +2 -2
- package/dist/joinListNode.js.flow +1 -1
- package/dist/keymaps.js +2 -2
- package/dist/patchStyleElements.js +3 -3
- package/dist/patchStyleElements.js.flow +1 -1
- package/dist/splitListItem.js +2 -2
- package/dist/styles.css +2 -2
- package/dist/styles0.css +3 -3
- package/dist/toggleBlockquote.js +6 -14
- package/dist/toggleBlockquote.js.flow +4 -4
- package/dist/toggleCodeBlock.js +4 -10
- package/dist/toggleCodeBlock.js.flow +3 -3
- package/dist/ui/AlertInfo.js +2 -2
- package/dist/ui/CommandButton.js +2 -4
- package/dist/ui/CommandButton.js.flow +1 -1
- package/dist/ui/CommandMenuButton.js +5 -7
- package/dist/ui/CommandMenuButton.js.flow +2 -2
- package/dist/ui/CustomMenuItem.js +3 -5
- package/dist/ui/CustomMenuItem.js.flow +1 -1
- package/dist/ui/CustomNodeView.js +3 -3
- package/dist/ui/CustomRadioButton.js +8 -6
- package/dist/ui/CustomRadioButton.js.flow +3 -3
- package/dist/ui/DocLayoutEditor.js +5 -7
- package/dist/ui/DocLayoutEditor.js.flow +2 -2
- package/dist/ui/Editor.js +1 -2
- package/dist/ui/Editor.js.flow +1 -2
- package/dist/ui/EditorFrameset.js +1 -1
- package/dist/ui/EditorToolbar.js +4 -4
- package/dist/ui/EditorToolbar.js.flow +1 -1
- package/dist/ui/EditorToolbarConfig.js +1 -1
- package/dist/ui/FontSizeCommandMenuButton.js +3 -3
- package/dist/ui/FontSizeCommandMenuButton.js.flow +1 -1
- package/dist/ui/FontTypeCommandMenuButton.js +3 -3
- package/dist/ui/FontTypeCommandMenuButton.js.flow +1 -1
- package/dist/ui/ImageAlignEditor.js +5 -5
- package/dist/ui/ImageAlignEditor.js.flow +1 -1
- package/dist/ui/ImageInlineEditor.js +5 -5
- package/dist/ui/ImageInlineEditor.js.flow +1 -1
- package/dist/ui/ImageNodeView.js +5 -7
- package/dist/ui/ImageNodeView.js.flow +2 -2
- package/dist/ui/ImageResizeBox.js +4 -4
- package/dist/ui/ImageResizeBox.js.flow +1 -1
- package/dist/ui/ImageURLEditor.js +6 -8
- package/dist/ui/ImageURLEditor.js.flow +2 -2
- package/dist/ui/ImageUploadEditor.js +3 -5
- package/dist/ui/ImageUploadEditor.js.flow +2 -2
- package/dist/ui/LinkTooltip.js +4 -4
- package/dist/ui/LinkTooltip.js.flow +1 -1
- package/dist/ui/LinkURLEditor.js +4 -6
- package/dist/ui/LinkURLEditor.js.flow +2 -2
- package/dist/ui/ListTypeButton.js +5 -7
- package/dist/ui/ListTypeButton.js.flow +2 -2
- package/dist/ui/MathEditor.js +4 -6
- package/dist/ui/MathEditor.js.flow +2 -2
- package/dist/ui/MathInlineEditor.js +7 -9
- package/dist/ui/MathInlineEditor.js.flow +2 -2
- package/dist/ui/MathNodeView.js +5 -7
- package/dist/ui/MathNodeView.js.flow +2 -2
- package/dist/ui/ResizeObserver.js +1 -1
- package/dist/ui/TableGridSizeEditor.js +7 -9
- package/dist/ui/TableGridSizeEditor.js.flow +2 -2
- package/dist/ui/czi-link-tooltip.css +1 -1
- package/dist/ui/czi-vars.css +1 -45
- package/dist/ui/findActiveFontType.js +1 -1
- package/dist/ui/htmlElementToRect.js +1 -1
- package/dist/ui/isElementFullyVisible.js +2 -2
- package/dist/ui/isElementFullyVisible.js.flow +1 -1
- package/dist/ui/mathquill-editor/MathQuillEditorSymbols.js +1 -1
- package/dist/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +2 -2
- package/dist/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js.flow +1 -1
- package/dist/ui/resolveImage.js +3 -3
- package/dist/ui/toCSSColor.js +1 -1
- package/dist/ui/toCSSLineSpacing.js +1 -36
- package/dist/ui/toCSSLineSpacing.js.flow +0 -27
- package/flow-typed/@modusoperandilicit-ui-commands.js +5 -0
- package/jest.config.js +207 -0
- package/lint.sh +0 -0
- package/node_modules/prosemirror-utils/LICENSE +13 -0
- package/{dist/ui/PopUpTypes.js.flow → node_modules/prosemirror-utils/README.md} +0 -0
- package/node_modules/prosemirror-utils/dist/helpers.js +119 -0
- package/node_modules/prosemirror-utils/dist/index.js +17 -0
- package/node_modules/prosemirror-utils/dist/index.js.map +1 -0
- package/node_modules/prosemirror-utils/dist/node.js +106 -0
- package/node_modules/prosemirror-utils/dist/selection.js +168 -0
- package/node_modules/prosemirror-utils/dist/transforms.js +257 -0
- package/node_modules/prosemirror-utils/package.json +81 -0
- package/node_modules/prosemirror-utils/typings.d.ts +79 -0
- package/package.json +14 -8
- package/scripts/build_bin.py +0 -0
- package/scripts/ci_check_dist.sh +0 -0
- package/src/CodeBlockCommand.js +1 -1
- package/src/DocLayoutCommand.js +1 -1
- package/src/EditorCommands.js +7 -7
- package/src/ImageSourceCommand.js +1 -1
- package/src/LinkSetURLCommand.js +3 -3
- package/src/LinkTooltipPlugin.js +5 -5
- package/src/ListToggleCommand.js +3 -3
- package/src/MarksClearCommand.js +1 -1
- package/src/MathEditCommand.js +1 -1
- package/src/ParagraphNodeSpec.js +2 -6
- package/src/TableBackgroundColorCommand.js +3 -3
- package/src/TableBorderColorCommand.js +3 -3
- package/src/TableCellColorCommand.js +3 -3
- package/src/TableCellMenuPlugin.js +3 -3
- package/src/TableInsertCommand.js +2 -2
- package/src/TextInsertTabSpaceCommand.js +1 -1
- package/src/client/CollabConnector.js +17 -2
- package/src/client/EditorConnection.js +14 -3
- package/src/client/Licit.js +101 -85
- package/src/client/Licit.test.js +13 -11
- package/src/client/SimpleConnector.js +3 -1
- package/src/joinListNode.js +1 -1
- package/src/patchStyleElements.js +1 -1
- package/src/styles.css +2 -2
- package/src/styles0.css +3 -3
- package/src/toggleBlockquote.js +4 -4
- package/src/toggleCodeBlock.js +3 -3
- package/src/ui/CommandButton.js +1 -1
- package/src/ui/CommandMenuButton.js +2 -2
- package/src/ui/CustomMenuItem.js +1 -1
- package/src/ui/CustomRadioButton.js +3 -3
- package/src/ui/DocLayoutEditor.js +2 -2
- package/src/ui/Editor.js +1 -2
- package/src/ui/EditorToolbar.js +1 -1
- package/src/ui/FontSizeCommandMenuButton.js +1 -1
- package/src/ui/FontTypeCommandMenuButton.js +1 -1
- package/src/ui/ImageAlignEditor.js +1 -1
- package/src/ui/ImageInlineEditor.js +1 -1
- package/src/ui/ImageNodeView.js +2 -2
- package/src/ui/ImageResizeBox.js +1 -1
- package/src/ui/ImageURLEditor.js +2 -2
- package/src/ui/ImageUploadEditor.js +2 -2
- package/src/ui/LinkTooltip.js +1 -1
- package/src/ui/LinkURLEditor.js +2 -2
- package/src/ui/ListTypeButton.js +2 -2
- package/src/ui/MathEditor.js +2 -2
- package/src/ui/MathInlineEditor.js +2 -2
- package/src/ui/MathNodeView.js +2 -2
- package/src/ui/TableGridSizeEditor.js +2 -2
- package/src/ui/czi-link-tooltip.css +1 -1
- package/src/ui/czi-vars.css +1 -45
- package/src/ui/isElementFullyVisible.js +1 -1
- package/src/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +1 -1
- package/src/ui/toCSSLineSpacing.js +0 -27
- package/build_customstyle_server.py +0 -7
- package/dist/FontSizeCommand.js +0 -80
- package/dist/FontSizeCommand.js.flow +0 -57
- package/dist/FontTypeCommand.js +0 -137
- package/dist/FontTypeCommand.js.flow +0 -100
- package/dist/HeadingCommand.js +0 -65
- package/dist/HeadingCommand.js.flow +0 -51
- package/dist/IndentCommand.js +0 -57
- package/dist/IndentCommand.js.flow +0 -41
- package/dist/MarkToggleCommand.js +0 -90
- package/dist/MarkToggleCommand.js.flow +0 -66
- package/dist/TextAlignCommand.js +0 -151
- package/dist/TextAlignCommand.js.flow +0 -122
- package/dist/TextColorCommand.js +0 -114
- package/dist/TextColorCommand.js.flow +0 -87
- package/dist/TextHighlightCommand.js +0 -118
- package/dist/TextHighlightCommand.js.flow +0 -91
- package/dist/TextLineSpacingCommand.js +0 -177
- package/dist/TextLineSpacingCommand.js.flow +0 -157
- package/dist/applyMark.js +0 -84
- package/dist/applyMark.js.flow +0 -61
- package/dist/clearMarks.js +0 -160
- package/dist/clearMarks.js.flow +0 -128
- package/dist/compareNumber.js +0 -18
- package/dist/compareNumber.js.flow +0 -11
- package/dist/consolidateListNodes.js +0 -291
- package/dist/consolidateListNodes.js.flow +0 -281
- package/dist/coverage/lcov-report/block-navigation.js +0 -77
- package/dist/coverage/lcov-report/block-navigation.js.flow +0 -79
- package/dist/coverage/lcov-report/prettify.js +0 -994
- package/dist/coverage/lcov-report/prettify.js.flow +0 -2
- package/dist/coverage/lcov-report/sorter.js +0 -187
- package/dist/coverage/lcov-report/sorter.js.flow +0 -170
- package/dist/findNodesWithSameMark.js +0 -89
- package/dist/findNodesWithSameMark.js.flow +0 -89
- package/dist/isBulletListNode.js +0 -14
- package/dist/isBulletListNode.js.flow +0 -9
- package/dist/isInsideListItem.js +0 -19
- package/dist/isInsideListItem.js.flow +0 -13
- package/dist/isListNode.js +0 -22
- package/dist/isListNode.js.flow +0 -13
- package/dist/isNodeSelectionForNodeType.js +0 -19
- package/dist/isNodeSelectionForNodeType.js.flow +0 -15
- package/dist/isOrderedListNode.js +0 -14
- package/dist/isOrderedListNode.js.flow +0 -9
- package/dist/isTextStyleMarkCommandEnabled.js +0 -59
- package/dist/isTextStyleMarkCommandEnabled.js.flow +0 -49
- package/dist/noop.js +0 -11
- package/dist/noop.js.flow +0 -5
- package/dist/toggleHeading.js +0 -135
- package/dist/toggleHeading.js.flow +0 -113
- package/dist/toggleList.js +0 -431
- package/dist/toggleList.js.flow +0 -450
- package/dist/transformAndPreserveTextSelection.js +0 -173
- package/dist/transformAndPreserveTextSelection.js.flow +0 -151
- package/dist/ui/ColorEditor.js +0 -118
- package/dist/ui/ColorEditor.js.flow +0 -101
- package/dist/ui/CustomButton.js +0 -62
- package/dist/ui/CustomButton.js.flow +0 -33
- package/dist/ui/PointerSurface.js +0 -173
- package/dist/ui/PointerSurface.js.flow +0 -141
- package/dist/ui/PopUp.js +0 -129
- package/dist/ui/PopUp.js.flow +0 -77
- package/dist/ui/PopUpManager.js +0 -266
- package/dist/ui/PopUpManager.js.flow +0 -213
- package/dist/ui/PopUpPosition.js +0 -156
- package/dist/ui/PopUpPosition.js.flow +0 -104
- package/dist/ui/PopUpTypes.js +0 -1
- package/dist/ui/TooltipSurface.js +0 -99
- package/dist/ui/TooltipSurface.js.flow +0 -76
- package/dist/ui/clamp.js +0 -18
- package/dist/ui/clamp.js.flow +0 -11
- package/dist/ui/createPopUp.js +0 -199
- package/dist/ui/createPopUp.js.flow +0 -205
- package/dist/ui/czi-animations.css +0 -15
- package/dist/ui/czi-color-editor.css +0 -56
- package/dist/ui/czi-custom-button.css +0 -93
- package/dist/ui/czi-pop-up.css +0 -32
- package/dist/ui/czi-tooltip-surface.css +0 -45
- package/dist/ui/preventEventDefault.js +0 -10
- package/dist/ui/preventEventDefault.js.flow +0 -5
- package/dist/ui/rects.js +0 -58
- package/dist/ui/rects.js.flow +0 -47
- package/dist/updateIndentLevel.js +0 -232
- package/dist/updateIndentLevel.js.flow +0 -211
- package/flow-typed/@molicit-citation.js +0 -5
- package/licit/server/customstyles/start.js +0 -184
- package/run_customstyle_server.py +0 -20
- package/src/FontSizeCommand.js +0 -57
- package/src/FontTypeCommand.js +0 -100
- package/src/HeadingCommand.js +0 -51
- package/src/IndentCommand.js +0 -41
- package/src/MarkToggleCommand.js +0 -66
- package/src/TextAlignCommand.js +0 -122
- package/src/TextColorCommand.js +0 -87
- package/src/TextHighlightCommand.js +0 -91
- package/src/TextLineSpacingCommand.js +0 -157
- package/src/applyMark.js +0 -61
- package/src/clearMarks.js +0 -128
- package/src/compareNumber.js +0 -11
- package/src/consolidateListNodes.js +0 -281
- package/src/findNodesWithSameMark.js +0 -89
- package/src/isBulletListNode.js +0 -9
- package/src/isInsideListItem.js +0 -13
- package/src/isListNode.js +0 -13
- package/src/isNodeSelectionForNodeType.js +0 -15
- package/src/isOrderedListNode.js +0 -9
- package/src/isTextStyleMarkCommandEnabled.js +0 -49
- package/src/noop.js +0 -5
- package/src/toggleHeading.js +0 -113
- package/src/toggleList.js +0 -450
- package/src/transformAndPreserveTextSelection.js +0 -151
- package/src/ui/ColorEditor.js +0 -101
- package/src/ui/CustomButton.js +0 -33
- package/src/ui/PointerSurface.js +0 -141
- package/src/ui/PopUp.js +0 -77
- package/src/ui/PopUpManager.js +0 -213
- package/src/ui/PopUpPosition.js +0 -104
- package/src/ui/PopUpTypes.js +0 -0
- package/src/ui/TooltipSurface.js +0 -76
- package/src/ui/clamp.js +0 -11
- package/src/ui/createPopUp.js +0 -205
- package/src/ui/czi-animations.css +0 -15
- package/src/ui/czi-color-editor.css +0 -56
- package/src/ui/czi-custom-button.css +0 -93
- package/src/ui/czi-pop-up.css +0 -32
- package/src/ui/czi-tooltip-surface.css +0 -45
- package/src/ui/preventEventDefault.js +0 -5
- package/src/ui/rects.js +0 -47
- package/src/updateIndentLevel.js +0 -211
- package/utils/build_customstyle_server.js +0 -72
package/src/toggleList.js
DELETED
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import consolidateListNodes from './consolidateListNodes';
|
|
4
|
-
import compareNumber from './compareNumber';
|
|
5
|
-
import nullthrows from 'nullthrows';
|
|
6
|
-
import { Fragment, Node, NodeType, Schema } from 'prosemirror-model';
|
|
7
|
-
import { TextSelection } from 'prosemirror-state';
|
|
8
|
-
import { Transform } from 'prosemirror-transform';
|
|
9
|
-
import { findParentNodeOfType } from 'prosemirror-utils';
|
|
10
|
-
|
|
11
|
-
import { HEADING, LIST_ITEM, PARAGRAPH } from './NodeNames';
|
|
12
|
-
import isListNode from './isListNode';
|
|
13
|
-
import transformAndPreserveTextSelection from './transformAndPreserveTextSelection';
|
|
14
|
-
|
|
15
|
-
import type { SelectionMemo } from './transformAndPreserveTextSelection';
|
|
16
|
-
|
|
17
|
-
export default function toggleList(
|
|
18
|
-
tr: Transform,
|
|
19
|
-
schema: Schema,
|
|
20
|
-
listNodeType: NodeType,
|
|
21
|
-
listStyleType: string
|
|
22
|
-
): Transform {
|
|
23
|
-
const { selection, doc } = tr;
|
|
24
|
-
if (!selection || !doc) {
|
|
25
|
-
return tr;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// [FS][04-AUG-2020][IRAD-955]
|
|
29
|
-
// Fix Unable to apply list using Ctrl+A selection
|
|
30
|
-
let { from } = selection;
|
|
31
|
-
let { to } = selection;
|
|
32
|
-
let newselection = selection;
|
|
33
|
-
|
|
34
|
-
if (0 === from && 0 != to) {
|
|
35
|
-
// In here when Ctrl+A is pressed.
|
|
36
|
-
let startPos = -1;
|
|
37
|
-
let endPos = -1;
|
|
38
|
-
|
|
39
|
-
tr.doc.descendants((node, pos) => {
|
|
40
|
-
if (-1 === startPos) {
|
|
41
|
-
startPos = pos;
|
|
42
|
-
} else {
|
|
43
|
-
endPos = pos + 1;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// validate endPos. Both start & end pos can't be -ve.
|
|
48
|
-
endPos = -1 == endPos ? to : endPos;
|
|
49
|
-
|
|
50
|
-
// Actual starting position similar when manually selecting
|
|
51
|
-
startPos = 0 < to - endPos ? to - endPos : 0;
|
|
52
|
-
|
|
53
|
-
from = startPos;
|
|
54
|
-
to = 0 < endPos ? endPos : 0;
|
|
55
|
-
|
|
56
|
-
newselection = TextSelection.create(doc, from, to);
|
|
57
|
-
tr = tr.setSelection(newselection);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const fromSelection = TextSelection.create(doc, from, from);
|
|
61
|
-
const paragraph = schema.nodes[PARAGRAPH];
|
|
62
|
-
const heading = schema.nodes[HEADING];
|
|
63
|
-
const result = findParentNodeOfType(listNodeType)(fromSelection);
|
|
64
|
-
const p = findParentNodeOfType(paragraph)(fromSelection);
|
|
65
|
-
const h = findParentNodeOfType(heading)(fromSelection);
|
|
66
|
-
|
|
67
|
-
if (result) {
|
|
68
|
-
tr = unwrapNodesFromList(tr, schema, result.pos);
|
|
69
|
-
} else if (paragraph && p) {
|
|
70
|
-
tr = wrapNodesWithList(
|
|
71
|
-
tr,
|
|
72
|
-
schema,
|
|
73
|
-
listNodeType,
|
|
74
|
-
listStyleType,
|
|
75
|
-
newselection
|
|
76
|
-
);
|
|
77
|
-
} else if (heading && h) {
|
|
78
|
-
tr = wrapNodesWithList(
|
|
79
|
-
tr,
|
|
80
|
-
schema,
|
|
81
|
-
listNodeType,
|
|
82
|
-
listStyleType,
|
|
83
|
-
newselection
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
return tr;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function unwrapNodesFromList(
|
|
90
|
-
tr: Transform,
|
|
91
|
-
schema: Schema,
|
|
92
|
-
listNodePos: number,
|
|
93
|
-
unwrapParagraphNode?: ?(Node) => Node
|
|
94
|
-
): Transform {
|
|
95
|
-
return transformAndPreserveTextSelection(tr, schema, (memo) => {
|
|
96
|
-
return consolidateListNodes(
|
|
97
|
-
unwrapNodesFromListInternal(memo, listNodePos, unwrapParagraphNode)
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function wrapNodesWithList(
|
|
103
|
-
tr: Transform,
|
|
104
|
-
schema: Schema,
|
|
105
|
-
listNodeType: NodeType,
|
|
106
|
-
listStyleType: string,
|
|
107
|
-
newselection = null
|
|
108
|
-
): Transform {
|
|
109
|
-
return transformAndPreserveTextSelection(tr, schema, (memo) => {
|
|
110
|
-
// [FS][04-AUG-2020][IRAD-955]
|
|
111
|
-
// Fix Unable to apply list using Ctrl+A selection
|
|
112
|
-
return consolidateListNodes(
|
|
113
|
-
wrapNodesWithListInternal(memo, listNodeType, listStyleType, newselection)
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function wrapNodesWithListInternal(
|
|
119
|
-
memo: SelectionMemo,
|
|
120
|
-
listNodeType: NodeType,
|
|
121
|
-
listStyleType: string,
|
|
122
|
-
newselection = null
|
|
123
|
-
): Transform {
|
|
124
|
-
const { schema } = memo;
|
|
125
|
-
let { tr } = memo;
|
|
126
|
-
const { doc, selection } = tr;
|
|
127
|
-
let { from, to } = selection;
|
|
128
|
-
if (!tr || !selection) {
|
|
129
|
-
return tr;
|
|
130
|
-
}
|
|
131
|
-
if (newselection) {
|
|
132
|
-
from = newselection.from;
|
|
133
|
-
to = newselection.to;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const paragraph = schema.nodes[PARAGRAPH];
|
|
137
|
-
const heading = schema.nodes[HEADING];
|
|
138
|
-
|
|
139
|
-
let items = null;
|
|
140
|
-
let lists = [];
|
|
141
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
142
|
-
const nodeType = node.type;
|
|
143
|
-
const nodeName = nodeType.name;
|
|
144
|
-
if (isListNode(node)) {
|
|
145
|
-
if (node.type !== listNodeType) {
|
|
146
|
-
const listNodeAttrs = {
|
|
147
|
-
...node.attrs,
|
|
148
|
-
listNodeType: null,
|
|
149
|
-
};
|
|
150
|
-
tr = tr.setNodeMarkup(pos, listNodeType, listNodeAttrs, node.marks);
|
|
151
|
-
}
|
|
152
|
-
items && lists.push(items);
|
|
153
|
-
items = null;
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (/table/.test(nodeName)) {
|
|
158
|
-
items && lists.push(items);
|
|
159
|
-
items = null;
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (nodeType === heading || nodeType === paragraph) {
|
|
164
|
-
items = items || [];
|
|
165
|
-
items.push({ node, pos });
|
|
166
|
-
} else {
|
|
167
|
-
items && items.length && lists.push(items);
|
|
168
|
-
items = null;
|
|
169
|
-
}
|
|
170
|
-
return true;
|
|
171
|
-
});
|
|
172
|
-
items && items.length && lists.push(items);
|
|
173
|
-
|
|
174
|
-
lists = lists.filter((items) => items.length > 0);
|
|
175
|
-
if (!lists.length) {
|
|
176
|
-
return tr;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
lists.sort((a, b) => {
|
|
180
|
-
const pa = nullthrows(a[0]).pos;
|
|
181
|
-
const pb = nullthrows(b[0]).pos;
|
|
182
|
-
return pa >= pb ? 1 : -1;
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
lists.reverse();
|
|
186
|
-
|
|
187
|
-
lists.forEach((items) => {
|
|
188
|
-
tr = wrapItemsWithListInternal(
|
|
189
|
-
tr,
|
|
190
|
-
schema,
|
|
191
|
-
listNodeType,
|
|
192
|
-
items,
|
|
193
|
-
listStyleType
|
|
194
|
-
);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return tr;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function wrapItemsWithListInternal(
|
|
201
|
-
tr: Transform,
|
|
202
|
-
schema: Schema,
|
|
203
|
-
listNodeType: NodeType,
|
|
204
|
-
items: Array<{ node: Node, pos: number }>,
|
|
205
|
-
listStyleType: string
|
|
206
|
-
): Transform {
|
|
207
|
-
const initialTr = tr;
|
|
208
|
-
const paragraph = schema.nodes[PARAGRAPH];
|
|
209
|
-
const listItem = schema.nodes[LIST_ITEM];
|
|
210
|
-
|
|
211
|
-
if (!paragraph || !listItem) {
|
|
212
|
-
return tr;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const paragraphNodes = [];
|
|
216
|
-
items.forEach((item) => {
|
|
217
|
-
const { node, pos } = item;
|
|
218
|
-
// Temporarily annotate each node with an unique ID.
|
|
219
|
-
const uniqueID = {};
|
|
220
|
-
const nodeAttrs = { ...node.attrs, id: uniqueID };
|
|
221
|
-
// Replace the original node with the node annotated by the uniqueID.
|
|
222
|
-
tr = tr.setNodeMarkup(pos, paragraph, nodeAttrs, node.marks);
|
|
223
|
-
paragraphNodes.push(tr.doc.nodeAt(pos));
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const firstNode = paragraphNodes[0];
|
|
227
|
-
const lastNode = paragraphNodes[paragraphNodes.length - 1];
|
|
228
|
-
if (!firstNode || !lastNode) {
|
|
229
|
-
return initialTr;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const firstNodeID = firstNode.attrs.id;
|
|
233
|
-
const lastNodeID = lastNode.attrs.id;
|
|
234
|
-
if (!firstNodeID || !lastNodeID) {
|
|
235
|
-
return initialTr;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let fromPos = null;
|
|
239
|
-
let toPos = null;
|
|
240
|
-
tr.doc.descendants((node, pos) => {
|
|
241
|
-
const nodeID = node.attrs.id;
|
|
242
|
-
if (nodeID === firstNodeID) {
|
|
243
|
-
fromPos = pos;
|
|
244
|
-
}
|
|
245
|
-
if (nodeID === lastNodeID) {
|
|
246
|
-
toPos = pos + node.nodeSize;
|
|
247
|
-
}
|
|
248
|
-
return fromPos === null || toPos === null;
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
if (fromPos === null || toPos === null) {
|
|
252
|
-
return initialTr;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const listItemNodes = [];
|
|
256
|
-
items.forEach((item) => {
|
|
257
|
-
const { node } = item;
|
|
258
|
-
// Restore the annotated nodes with the copy of the original ones.
|
|
259
|
-
const paragraphNode = paragraph.create(
|
|
260
|
-
node.attrs,
|
|
261
|
-
node.content,
|
|
262
|
-
node.marks
|
|
263
|
-
);
|
|
264
|
-
const listItemNode = listItem.create(
|
|
265
|
-
node.attrs,
|
|
266
|
-
Fragment.from(paragraphNode)
|
|
267
|
-
);
|
|
268
|
-
listItemNodes.push(listItemNode);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const listNodeAttrs = { indent: 0, start: 1, type: listStyleType };
|
|
272
|
-
|
|
273
|
-
const $fromPos = tr.doc.resolve(fromPos);
|
|
274
|
-
const $toPos = tr.doc.resolve(toPos);
|
|
275
|
-
|
|
276
|
-
const hasSameListNodeBefore =
|
|
277
|
-
$fromPos.nodeBefore &&
|
|
278
|
-
$fromPos.nodeBefore.type === listNodeType &&
|
|
279
|
-
$fromPos.nodeBefore.attrs.indent === 0;
|
|
280
|
-
|
|
281
|
-
const hasSameListNodeAfter =
|
|
282
|
-
$toPos.nodeAfter &&
|
|
283
|
-
$toPos.nodeAfter.type === listNodeType &&
|
|
284
|
-
$toPos.nodeAfter.attrs.indent === 0;
|
|
285
|
-
|
|
286
|
-
if (hasSameListNodeBefore) {
|
|
287
|
-
tr = tr.delete(fromPos, toPos);
|
|
288
|
-
tr = tr.insert(fromPos - 1, Fragment.from(listItemNodes));
|
|
289
|
-
if (hasSameListNodeAfter) {
|
|
290
|
-
tr = tr.delete(toPos + 1, toPos + 3);
|
|
291
|
-
}
|
|
292
|
-
} else if (hasSameListNodeAfter) {
|
|
293
|
-
tr = tr.delete(fromPos, toPos);
|
|
294
|
-
tr = tr.insert(fromPos + 1, Fragment.from(listItemNodes));
|
|
295
|
-
} else {
|
|
296
|
-
const listNode = listNodeType.create(
|
|
297
|
-
listNodeAttrs,
|
|
298
|
-
Fragment.from(listItemNodes)
|
|
299
|
-
);
|
|
300
|
-
tr = tr.delete(fromPos, toPos);
|
|
301
|
-
tr = tr.insert(fromPos, Fragment.from(listNode));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return tr;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// [FS] IRAD-966 2020-05-20
|
|
308
|
-
// Fix: Toggling issue for Multi-level list.
|
|
309
|
-
|
|
310
|
-
function unwrapNodesFromSelection(
|
|
311
|
-
tr: Transform,
|
|
312
|
-
listNodePos: number,
|
|
313
|
-
nodes: Node,
|
|
314
|
-
unwrapParagraphNode?: Node,
|
|
315
|
-
from: number,
|
|
316
|
-
to: number
|
|
317
|
-
): Transform {
|
|
318
|
-
const contentBlocksBefore = [];
|
|
319
|
-
const contentBlocksSelected = [];
|
|
320
|
-
const contentBlocksAfter = [];
|
|
321
|
-
const paragraph = nodes[PARAGRAPH];
|
|
322
|
-
const listItem = nodes[LIST_ITEM];
|
|
323
|
-
const listNode = tr.doc.nodeAt(listNodePos);
|
|
324
|
-
|
|
325
|
-
tr.doc.nodesBetween(
|
|
326
|
-
listNodePos,
|
|
327
|
-
listNodePos + listNode.nodeSize,
|
|
328
|
-
(node, pos, parentNode, index) => {
|
|
329
|
-
if (node.type !== paragraph) {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
const block = {
|
|
333
|
-
node,
|
|
334
|
-
pos,
|
|
335
|
-
parentNode,
|
|
336
|
-
index,
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
if (pos + node.nodeSize <= from) {
|
|
340
|
-
contentBlocksBefore.push(block);
|
|
341
|
-
} else if (pos > to) {
|
|
342
|
-
contentBlocksAfter.push(block);
|
|
343
|
-
} else {
|
|
344
|
-
contentBlocksSelected.push(block);
|
|
345
|
-
}
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
if (!contentBlocksSelected.length) {
|
|
351
|
-
return tr;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
tr = tr.delete(listNodePos, listNodePos + listNode.nodeSize);
|
|
355
|
-
|
|
356
|
-
const listNodeType = listNode.type;
|
|
357
|
-
const attrs = { indent: listNode.attrs.indent, start: 1 };
|
|
358
|
-
|
|
359
|
-
if (contentBlocksAfter.length) {
|
|
360
|
-
const nodes = contentBlocksAfter.map((block) => {
|
|
361
|
-
return listItem.create({}, Fragment.from(block.node));
|
|
362
|
-
});
|
|
363
|
-
const frag = Fragment.from(
|
|
364
|
-
listNodeType.create(attrs, Fragment.from(nodes))
|
|
365
|
-
);
|
|
366
|
-
tr = tr.insert(listNodePos, frag);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (contentBlocksSelected.length) {
|
|
370
|
-
const nodes = contentBlocksSelected.map((block) => {
|
|
371
|
-
if (unwrapParagraphNode) {
|
|
372
|
-
return unwrapParagraphNode(block.node);
|
|
373
|
-
} else {
|
|
374
|
-
return block.node;
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
const frag = Fragment.from(nodes);
|
|
378
|
-
tr = tr.insert(listNodePos, frag);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if (contentBlocksBefore.length) {
|
|
382
|
-
const nodes = contentBlocksBefore.map((block) => {
|
|
383
|
-
return listItem.create({}, Fragment.from(block.node));
|
|
384
|
-
});
|
|
385
|
-
const frag = Fragment.from(
|
|
386
|
-
listNodeType.create(attrs, Fragment.from(nodes))
|
|
387
|
-
);
|
|
388
|
-
tr = tr.insert(listNodePos, frag);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return tr;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function unwrapNodesFromListInternal(
|
|
395
|
-
memo: SelectionMemo,
|
|
396
|
-
listNodePos: number,
|
|
397
|
-
unwrapParagraphNode?: ?(Node) => Node
|
|
398
|
-
): Transform {
|
|
399
|
-
const { schema } = memo;
|
|
400
|
-
let { tr } = memo;
|
|
401
|
-
|
|
402
|
-
if (!tr.doc || !tr.selection) {
|
|
403
|
-
return tr;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const { nodes } = schema;
|
|
407
|
-
const paragraph = nodes[PARAGRAPH];
|
|
408
|
-
const listItem = nodes[LIST_ITEM];
|
|
409
|
-
|
|
410
|
-
if (!listItem || !paragraph) {
|
|
411
|
-
return tr;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const listNode = tr.doc.nodeAt(listNodePos);
|
|
415
|
-
if (!isListNode(listNode)) {
|
|
416
|
-
return tr;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const initialSelection = tr.selection;
|
|
420
|
-
const { from, to } = initialSelection;
|
|
421
|
-
|
|
422
|
-
const listNodePoses = [];
|
|
423
|
-
|
|
424
|
-
// keep all list type nodes starting position
|
|
425
|
-
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
426
|
-
if (isListNode(node)) {
|
|
427
|
-
listNodePoses.push(pos);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
if (from === to && from < 1) {
|
|
432
|
-
return tr;
|
|
433
|
-
}
|
|
434
|
-
// Unwraps all selected list
|
|
435
|
-
listNodePoses
|
|
436
|
-
.sort(compareNumber)
|
|
437
|
-
.reverse()
|
|
438
|
-
.forEach((pos) => {
|
|
439
|
-
tr = unwrapNodesFromSelection(
|
|
440
|
-
tr,
|
|
441
|
-
pos,
|
|
442
|
-
nodes,
|
|
443
|
-
unwrapParagraphNode,
|
|
444
|
-
from,
|
|
445
|
-
to
|
|
446
|
-
);
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
return tr;
|
|
450
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Fragment, Schema } from 'prosemirror-model';
|
|
2
|
-
import { TextSelection } from 'prosemirror-state';
|
|
3
|
-
import { Transform } from 'prosemirror-transform';
|
|
4
|
-
|
|
5
|
-
import { MARK_TEXT_SELECTION } from './MarkNames';
|
|
6
|
-
import { PARAGRAPH, TEXT } from './NodeNames';
|
|
7
|
-
import applyMark from './applyMark';
|
|
8
|
-
import uuid from './ui/uuid';
|
|
9
|
-
|
|
10
|
-
export type SelectionMemo = {
|
|
11
|
-
schema: Schema,
|
|
12
|
-
tr: Transform,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// Text used to create temporary selection.
|
|
16
|
-
// This assumes that no user could enter such string manually.
|
|
17
|
-
const PLACEHOLDER_TEXT = `[\u200b\u2800PLACEHOLDER_TEXT_${uuid()}\u2800\u200b]`;
|
|
18
|
-
|
|
19
|
-
// Perform the transform without losing the perceived text selection.
|
|
20
|
-
// The way it works is that this will annotate teh current selection with
|
|
21
|
-
// temporary marks and restores the selection with those marks after performing
|
|
22
|
-
// the transform.
|
|
23
|
-
export default function transformAndPreserveTextSelection(
|
|
24
|
-
tr: Transform,
|
|
25
|
-
schema: Schema,
|
|
26
|
-
fn: (memo: SelectionMemo) => Transform
|
|
27
|
-
): Transform {
|
|
28
|
-
if (tr.getMeta('dryrun')) {
|
|
29
|
-
// There's no need to preserve the selection in dryrun mode.
|
|
30
|
-
return fn({ tr, schema });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const { selection, doc } = tr;
|
|
34
|
-
const markType = schema.marks[MARK_TEXT_SELECTION];
|
|
35
|
-
if (!markType || !selection || !doc) {
|
|
36
|
-
return tr;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!(selection instanceof TextSelection)) {
|
|
40
|
-
return tr;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const { from, to } = selection;
|
|
44
|
-
|
|
45
|
-
// Mark current selection so that we could resume the selection later
|
|
46
|
-
// after changing the whole list.
|
|
47
|
-
let fromOffset = 0;
|
|
48
|
-
let toOffset = 0;
|
|
49
|
-
let placeholderTextNode;
|
|
50
|
-
|
|
51
|
-
if (from === to) {
|
|
52
|
-
if (from === 0) {
|
|
53
|
-
return tr;
|
|
54
|
-
}
|
|
55
|
-
// Selection is collapsed, create a temporary selection that the marks can
|
|
56
|
-
// be applied to.
|
|
57
|
-
const currentNode = tr.doc.nodeAt(from);
|
|
58
|
-
const prevNode = tr.doc.nodeAt(from - 1);
|
|
59
|
-
const nextNode = tr.doc.nodeAt(from + 1);
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
!currentNode &&
|
|
63
|
-
prevNode &&
|
|
64
|
-
prevNode.type.name === PARAGRAPH &&
|
|
65
|
-
!prevNode.firstChild
|
|
66
|
-
) {
|
|
67
|
-
// The selection is at a paragraph node which has no content.
|
|
68
|
-
// Create a temporary text and move selection into that text.
|
|
69
|
-
placeholderTextNode = schema.text(PLACEHOLDER_TEXT);
|
|
70
|
-
tr = tr.insert(from, Fragment.from(placeholderTextNode));
|
|
71
|
-
toOffset = 1;
|
|
72
|
-
} else if (!currentNode && prevNode && prevNode.type.name === TEXT) {
|
|
73
|
-
// The selection is at the end of the text node. Select the last
|
|
74
|
-
// character instead.
|
|
75
|
-
fromOffset = -1;
|
|
76
|
-
} else if (prevNode && currentNode && currentNode.type === prevNode.type) {
|
|
77
|
-
// Ensure that the mark is applied to the same type of node.
|
|
78
|
-
fromOffset = -1;
|
|
79
|
-
} else if (nextNode && currentNode && currentNode.type === nextNode.type) {
|
|
80
|
-
toOffset = 1;
|
|
81
|
-
} else if (nextNode) {
|
|
82
|
-
// Could not find the same type of node, assume the next node is safe to use.
|
|
83
|
-
toOffset = 1;
|
|
84
|
-
} else if (prevNode) {
|
|
85
|
-
// Could not find the same type of node, assume the next node is safe to use.
|
|
86
|
-
fromOffset = -1;
|
|
87
|
-
} else {
|
|
88
|
-
// Selection can't be safely preserved.
|
|
89
|
-
return tr;
|
|
90
|
-
}
|
|
91
|
-
tr = tr.setSelection(
|
|
92
|
-
// [FS] IRAD-1005 2020-07-29
|
|
93
|
-
// Upgrade outdated packages.
|
|
94
|
-
// reset selection using the latest doc.
|
|
95
|
-
// This fixes IRAD-1023
|
|
96
|
-
TextSelection.create(tr.doc, from + fromOffset, to + toOffset)
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// This is an unique ID (by reference).
|
|
101
|
-
const id = {};
|
|
102
|
-
const findMark = (mark) => mark.attrs.id === id;
|
|
103
|
-
|
|
104
|
-
const findMarkRange = () => {
|
|
105
|
-
let markFrom = 0;
|
|
106
|
-
let markTo = 0;
|
|
107
|
-
tr.doc.descendants((node, pos) => {
|
|
108
|
-
if (node.marks && node.marks.find(findMark)) {
|
|
109
|
-
markFrom = markFrom === 0 ? pos : markFrom;
|
|
110
|
-
markTo = pos + node.nodeSize;
|
|
111
|
-
}
|
|
112
|
-
return true;
|
|
113
|
-
});
|
|
114
|
-
return {
|
|
115
|
-
from: markFrom,
|
|
116
|
-
to: markTo,
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// TODO: This has side-effect. It will cause `tr.docChanged` to be `true`.
|
|
121
|
-
// No matter whether `fn({tr, schema})` did change the doc or not.
|
|
122
|
-
tr = applyMark(tr, schema, markType, { id });
|
|
123
|
-
tr = fn({ tr, schema });
|
|
124
|
-
|
|
125
|
-
const markRange = findMarkRange();
|
|
126
|
-
const selectionRange = {
|
|
127
|
-
from: Math.max(0, markRange.from - fromOffset),
|
|
128
|
-
to: Math.max(0, markRange.to - toOffset),
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
selectionRange.to = Math.max(0, selectionRange.from, selectionRange.to);
|
|
132
|
-
|
|
133
|
-
tr = tr.removeMark(markRange.from, markRange.to, markType);
|
|
134
|
-
|
|
135
|
-
if (placeholderTextNode) {
|
|
136
|
-
tr.doc.descendants((node, pos) => {
|
|
137
|
-
if (node.type.name === TEXT && node.text === PLACEHOLDER_TEXT) {
|
|
138
|
-
tr = tr.delete(pos, pos + PLACEHOLDER_TEXT.length);
|
|
139
|
-
placeholderTextNode = null;
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
return true;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
tr = tr.setSelection(
|
|
147
|
-
TextSelection.create(tr.doc, selectionRange.from, selectionRange.to)
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
return tr;
|
|
151
|
-
}
|
package/src/ui/ColorEditor.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import Color from 'color';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
|
|
6
|
-
import CustomButton from './CustomButton';
|
|
7
|
-
import clamp from './clamp';
|
|
8
|
-
|
|
9
|
-
import './czi-color-editor.css';
|
|
10
|
-
|
|
11
|
-
function generateGreyColors(count: number): Array<Color> {
|
|
12
|
-
let cc = 255;
|
|
13
|
-
const interval = cc / count;
|
|
14
|
-
const colors = [];
|
|
15
|
-
while (cc > 0) {
|
|
16
|
-
const color = Color({ r: cc, g: cc, b: cc });
|
|
17
|
-
cc -= interval;
|
|
18
|
-
cc = Math.floor(cc);
|
|
19
|
-
colors.unshift(color);
|
|
20
|
-
}
|
|
21
|
-
return colors;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function generateRainbowColors(
|
|
25
|
-
count: number,
|
|
26
|
-
saturation: number,
|
|
27
|
-
lightness: number
|
|
28
|
-
): Array<Color> {
|
|
29
|
-
const colors = [];
|
|
30
|
-
const interval = 360 / count;
|
|
31
|
-
const ss = clamp(0, saturation, 100);
|
|
32
|
-
const ll = clamp(0, lightness, 100);
|
|
33
|
-
let hue = 0;
|
|
34
|
-
while (hue < 360) {
|
|
35
|
-
const hsl = `hsl(${hue},${ss}%,${ll}%)`;
|
|
36
|
-
const color = Color(hsl);
|
|
37
|
-
colors.unshift(color);
|
|
38
|
-
hue += interval;
|
|
39
|
-
}
|
|
40
|
-
return colors;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class ColorEditor extends React.PureComponent<any, any> {
|
|
44
|
-
props: {
|
|
45
|
-
close: (?string) => void,
|
|
46
|
-
hex?: ?string,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
render(): React.Element<any> {
|
|
50
|
-
const renderColor = this._renderColor;
|
|
51
|
-
const selectedColor = this.props.hex;
|
|
52
|
-
return (
|
|
53
|
-
<div className="czi-color-editor">
|
|
54
|
-
<div className="czi-color-editor-section">
|
|
55
|
-
<CustomButton
|
|
56
|
-
active={!selectedColor}
|
|
57
|
-
className="czi-color-editor-color-transparent"
|
|
58
|
-
label="Transparent"
|
|
59
|
-
onClick={this._onSelectColor}
|
|
60
|
-
value="rgba(0,0,0,0)"
|
|
61
|
-
/>
|
|
62
|
-
</div>
|
|
63
|
-
<div className="czi-color-editor-section">
|
|
64
|
-
{generateGreyColors(10).map(renderColor)}
|
|
65
|
-
</div>
|
|
66
|
-
<div className="czi-color-editor-section">
|
|
67
|
-
{generateRainbowColors(10, 90, 50).map(renderColor)}
|
|
68
|
-
</div>
|
|
69
|
-
<div className="czi-color-editor-section">
|
|
70
|
-
{generateRainbowColors(30, 70, 70).map(renderColor)}
|
|
71
|
-
</div>
|
|
72
|
-
<div className="czi-color-editor-section">
|
|
73
|
-
{generateRainbowColors(30, 90, 30).map(renderColor)}
|
|
74
|
-
</div>
|
|
75
|
-
</div>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
_renderColor = (color: Color, index: number): React.Element<any> => {
|
|
80
|
-
const selectedColor = this.props.hex;
|
|
81
|
-
const hex = color.hex().toLowerCase();
|
|
82
|
-
const style = { backgroundColor: hex };
|
|
83
|
-
const active = selectedColor && selectedColor.toLowerCase() === hex;
|
|
84
|
-
return (
|
|
85
|
-
<CustomButton
|
|
86
|
-
active={active}
|
|
87
|
-
className="czi-color-editor-cell"
|
|
88
|
-
key={`${hex}-${index}`}
|
|
89
|
-
label=""
|
|
90
|
-
onClick={this._onSelectColor}
|
|
91
|
-
style={style}
|
|
92
|
-
value={hex}
|
|
93
|
-
/>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
_onSelectColor = (hex: string): void => {
|
|
98
|
-
this.props.close(hex);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
export default ColorEditor;
|