@modusoperandi/licit 1.4.3 → 1.4.6
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/BlockquoteInsertNewLineCommand.js.flow +70 -70
- package/BlockquoteNodeSpec.js.flow +29 -29
- package/BlockquoteToggleCommand.js.flow +56 -56
- package/BookmarkNodeSpec.js.flow +39 -39
- package/BulletListNodeSpec.js.flow +61 -61
- package/CZIProseMirror.js.flow +90 -90
- package/CodeBlockCommand.js.flow +65 -65
- package/CodeBlockNodeSpec.js.flow +24 -24
- package/CodeMarkSpec.js.flow +14 -14
- package/ContentPlaceholderPlugin.js.flow +183 -183
- package/CursorPlaceholderPlugin.js.flow +113 -113
- package/DocLayoutCommand.js.flow +97 -97
- package/DocNodeSpec.js.flow +62 -62
- package/EMMarkSpec.js.flow +39 -39
- package/EditorCommands.js.flow +124 -124
- package/EditorKeyMap.js.flow +173 -173
- package/EditorMarks.js +4 -2
- package/EditorMarks.js.flow +77 -74
- package/EditorNodes.js.flow +55 -55
- package/EditorPageLayoutPlugin.js.flow +67 -67
- package/EditorPlugins.js.flow +8 -8
- package/EditorSchema.js.flow +12 -12
- package/EditorState.js.flow +7 -7
- package/FontSizeMarkSpec.js.flow +54 -54
- package/FontTypeMarkSpec.js.flow +89 -89
- package/HTMLMutator.js.flow +58 -58
- package/HangingIndentMarkSpec.js +34 -0
- package/HangingIndentMarkSpec.js.flow +30 -0
- package/HardBreakNodeSpec.js.flow +15 -15
- package/HeadingNodeSpec.js.flow +42 -42
- package/HistoryRedoCommand.js.flow +41 -41
- package/HistoryUndoCommand.js.flow +41 -41
- package/HorizontalRuleCommand.js.flow +71 -71
- package/HorizontalRuleNodeSpec.js.flow +39 -39
- package/ImageUploadPlaceholderPlugin.js.flow +187 -187
- package/LICENSE +22 -22
- package/LinkMarkSpec.js +4 -2
- package/LinkMarkSpec.js.flow +38 -37
- package/LinkSetURLCommand.js.flow +129 -129
- package/LinkTooltipPlugin.js +31 -37
- package/LinkTooltipPlugin.js.flow +204 -217
- package/ListItemInsertNewLineCommand.js.flow +76 -76
- package/ListItemMergeCommand.js.flow +197 -197
- package/ListItemNodeSpec.js.flow +52 -52
- package/ListSplitCommand.js.flow +54 -54
- package/ListToggleCommand.js.flow +99 -99
- package/MarkNames.js +2 -1
- package/MarkNames.js.flow +20 -19
- package/MarksClearCommand.js.flow +66 -66
- package/NodeNames.js.flow +23 -23
- package/OrderedListNodeSpec.js.flow +131 -131
- package/OverrideMarkSpec.js.flow +49 -49
- package/ParagraphNodeSpec.js +21 -2
- package/ParagraphNodeSpec.js.flow +233 -215
- package/ParagraphSpacingCommand.js.flow +139 -139
- package/PrintCommand.js.flow +53 -53
- package/SelectionPlaceholderPlugin.js.flow +129 -129
- package/SpacerMarkSpec.js.flow +47 -47
- package/StrikeMarkSpec.js.flow +24 -24
- package/StrongMarkSpec.js.flow +39 -39
- package/StyleView.js.flow +18 -18
- package/TableBackgroundColorCommand.js.flow +79 -79
- package/TableBorderColorCommand.js +5 -3
- package/TableBorderColorCommand.js.flow +108 -106
- package/TableCellColorCommand.js.flow +73 -73
- package/TableCellMenuPlugin.js.flow +129 -129
- package/TableInsertCommand.js.flow +117 -117
- package/TableMergeCellsCommand.js.flow +113 -113
- package/TableNodesSpecs.js.flow +144 -144
- package/TablePlugins.js.flow +14 -14
- package/TableResizePlugin.js.flow +636 -636
- package/TextColorMarkSpec.js.flow +40 -40
- package/TextHighlightMarkSpec.js.flow +47 -47
- package/TextInsertTabSpaceCommand.js +0 -3
- package/TextInsertTabSpaceCommand.js.flow +103 -106
- package/TextNoWrapMarkSpec.js.flow +14 -14
- package/TextNodeSpec.js.flow +7 -7
- package/TextSelectionMarkSpec.js.flow +24 -24
- package/TextSubMarkSpec.js.flow +28 -28
- package/TextSuperMarkSpec.js.flow +28 -28
- package/TextUnderlineMarkSpec.js.flow +24 -24
- package/Types.js.flow +77 -77
- package/WebFontLoader.js.flow +22 -22
- package/blockQuoteInputRule.js.flow +36 -36
- package/bom.xml +8573 -8650
- package/browser.js.flow +7 -7
- package/buildEditorPlugins.js.flow +48 -48
- package/buildInputRules.js.flow +85 -85
- package/client/CollabConnector.js.flow +90 -90
- package/client/EditorConnection.js.flow +324 -324
- package/client/Licit.js +39 -39
- package/client/Licit.js.flow +649 -649
- package/client/Licit.test.js.flow +104 -104
- package/client/Reporter.js.flow +35 -35
- package/client/SimpleConnector.js.flow +61 -61
- package/client/http.js.flow +60 -60
- package/client/licit.css +12 -12
- package/client/throttle.js.flow +27 -27
- package/convertFromDOMElement.js.flow +33 -33
- package/convertFromHTML.js.flow +15 -15
- package/convertFromJSON.js.flow +53 -53
- package/convertToCSSPTValue.js.flow +19 -19
- package/convertToJSON.js.flow +7 -7
- package/createCommand.js.flow +62 -62
- package/createEditorKeyMap.js.flow +87 -87
- package/createEmptyEditorState.js.flow +29 -29
- package/createTableResizingPlugin.js.flow +86 -86
- package/findActionableCell.js.flow +74 -74
- package/findActiveMark.js.flow +32 -32
- package/hyphenize.js.flow +17 -17
- package/index.d.ts +167 -167
- package/index.js.flow +10 -10
- package/insertTable.js.flow +54 -54
- package/isEditorStateEmpty.js.flow +32 -32
- package/isTableNode.js.flow +15 -15
- package/joinDown.js.flow +25 -25
- package/joinListNode.js.flow +55 -55
- package/joinUp.js.flow +37 -37
- package/keymaps.js.flow +175 -175
- package/lookUpElement.js.flow +14 -14
- package/nodeAt.js.flow +12 -12
- package/normalizeHTML.js.flow +80 -80
- package/package.json +152 -152
- package/patchAnchorElements.js.flow +38 -38
- package/patchBreakElements.js.flow +22 -22
- package/patchElementInlineStyles.js.flow +92 -92
- package/patchListElements.js.flow +275 -275
- package/patchMathElements.js.flow +58 -58
- package/patchParagraphElements.js.flow +20 -20
- package/patchStyleElements.js.flow +197 -197
- package/patchTableElements.js.flow +88 -88
- package/rebaseDocWithSteps.js.flow +42 -42
- package/sanitizeURL.js.flow +13 -13
- package/splitListItem.js.flow +191 -191
- package/styles.css +46 -46
- package/toClosestFontPtSize.js.flow +22 -22
- package/toSafeHTMLDocument.js.flow +9 -9
- package/toggleBlockquote.js.flow +101 -101
- package/toggleCodeBlock.js.flow +102 -102
- package/ui/AlertInfo.js.flow +63 -63
- package/ui/BookmarkNodeView.js.flow +64 -64
- package/ui/CommandButton.js.flow +68 -68
- package/ui/CommandMenu.js.flow +74 -74
- package/ui/CommandMenuButton.js.flow +128 -128
- package/ui/CustomEditorView.js.flow +29 -29
- package/ui/CustomMenu.js.flow +14 -14
- package/ui/CustomMenuItem.js.flow +35 -35
- package/ui/CustomNodeView.js.flow +207 -207
- package/ui/CustomRadioButton.js.flow +63 -63
- package/ui/DocLayoutEditor.js.flow +130 -130
- package/ui/Editor.js.flow +281 -281
- package/ui/EditorFrameset.js.flow +79 -79
- package/ui/EditorToolbar.js.flow +197 -197
- package/ui/EditorToolbarConfig.js.flow +162 -162
- package/ui/FontSizeCommandMenuButton.js.flow +66 -66
- package/ui/FontTypeCommandMenuButton.js.flow +60 -60
- package/ui/Frag.js.flow +11 -11
- package/ui/Icon.js.flow +82 -82
- package/ui/ImageInlineEditor.js.flow +66 -66
- package/ui/KeyCodes.js.flow +12 -12
- package/ui/LinkTooltip.js.flow +51 -51
- package/ui/LinkURLEditor.js.flow +227 -227
- package/ui/ListItemNodeView.js.flow +101 -101
- package/ui/ListTypeButton.js.flow +121 -121
- package/ui/ListTypeCommandButton.js.flow +85 -85
- package/ui/ListTypeMenu.js.flow +78 -78
- package/ui/LoadingIndicator.js.flow +19 -19
- package/ui/PasteMenu.js.flow +52 -52
- package/ui/ResizeObserver.js.flow +105 -105
- package/ui/RichTextEditor.js.flow +133 -133
- package/ui/SelectionObserver.js.flow +134 -134
- package/ui/TableCellMenu.js.flow +49 -49
- package/ui/TableGridSizeEditor.js.flow +185 -185
- package/ui/TableNodeView.js.flow +36 -36
- package/ui/bindScrollHandler.js.flow +46 -46
- package/ui/canUseCSSFont.js.flow +42 -42
- package/ui/czi-body-layout-editor.css +16 -16
- package/ui/czi-bookmark-view.css +10 -10
- package/ui/czi-cursor-placeholder.css +36 -36
- package/ui/czi-custom-menu-button.css +18 -18
- package/ui/czi-custom-menu-item.css +30 -30
- package/ui/czi-custom-menu.css +8 -8
- package/ui/czi-custom-radio-button.css +80 -80
- package/ui/czi-custom-scrollbar.css +21 -21
- package/ui/czi-editor-frameset.css +81 -81
- package/ui/czi-editor-toolbar.css +122 -122
- package/ui/czi-editor.css +239 -216
- package/ui/czi-form.css +201 -201
- package/ui/czi-frag.css +3 -3
- package/ui/czi-heading.css +40 -40
- package/ui/czi-icon.css +72 -72
- package/ui/czi-image-resize-box.css +165 -165
- package/ui/czi-image-upload-editor.css +57 -57
- package/ui/czi-image-upload-placeholder.css +50 -50
- package/ui/czi-image-url-editor.css +38 -38
- package/ui/czi-image-view.css +121 -121
- package/ui/czi-indent.css +137 -137
- package/ui/czi-inline-editor.css +20 -20
- package/ui/czi-link-tooltip.css +112 -112
- package/ui/czi-list.css +406 -406
- package/ui/czi-loading-indicator.css +66 -66
- package/ui/czi-math-view.css +62 -62
- package/ui/czi-selection-placeholder.css +24 -24
- package/ui/czi-table-cell-menu.css +16 -16
- package/ui/czi-table-grid-size-editor.css +37 -37
- package/ui/czi-table.css +89 -89
- package/ui/czi-vars.css +47 -45
- package/ui/findActiveFontSize.js.flow +55 -55
- package/ui/findActiveFontType.js.flow +35 -35
- package/ui/fonts.css +460 -460
- package/ui/handleEditorDrop.js.flow +28 -28
- package/ui/handleEditorKeyDown.js.flow +39 -39
- package/ui/handleEditorPaste.js.flow +33 -33
- package/ui/htmlElementToRect.js.flow +18 -18
- package/ui/icon-font.css +9 -9
- package/ui/injectStyleSheet.js.flow +40 -40
- package/ui/isElementFullyVisible.js.flow +14 -14
- package/ui/isOffline.js.flow +8 -8
- package/ui/isReactClass.js.flow +12 -12
- package/ui/listType.css +21 -21
- package/ui/resolveImage.js.flow +121 -121
- package/ui/toCSSColor.js.flow +51 -51
- package/ui/toCSSLineSpacing.js.flow +53 -53
- package/ui/toHexColor.js.flow +26 -26
- package/ui/uuid.js.flow +9 -9
- package/uuid.js.flow +9 -9
package/client/Licit.js.flow
CHANGED
|
@@ -1,649 +1,649 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { EditorState, TextSelection, Plugin } from 'prosemirror-state';
|
|
3
|
-
import { Node, Schema } from 'prosemirror-model';
|
|
4
|
-
import { Transform } from 'prosemirror-transform';
|
|
5
|
-
import { EditorView } from 'prosemirror-view';
|
|
6
|
-
import * as React from 'react';
|
|
7
|
-
import { stringify } from 'flatted';
|
|
8
|
-
|
|
9
|
-
import convertFromJSON from '../convertFromJSON.js';
|
|
10
|
-
import RichTextEditor from '../ui/RichTextEditor.js';
|
|
11
|
-
import uuid from '../uuid.js';
|
|
12
|
-
import SimpleConnector from './SimpleConnector.js';
|
|
13
|
-
import CollabConnector from './CollabConnector.js';
|
|
14
|
-
import { EMPTY_DOC_JSON } from '../createEmptyEditorState.js';
|
|
15
|
-
import type { EditorRuntime } from '../Types.js';
|
|
16
|
-
import {
|
|
17
|
-
createPopUp,
|
|
18
|
-
atViewportCenter,
|
|
19
|
-
} from '@modusoperandi/licit-ui-commands';
|
|
20
|
-
import AlertInfo from '../ui/AlertInfo.js';
|
|
21
|
-
import { SetDocAttrStep } from '@modusoperandi/licit-doc-attrs-step';
|
|
22
|
-
import DefaultEditorPlugins from '../buildEditorPlugins.js';
|
|
23
|
-
import EditorMarks from '../EditorMarks.js';
|
|
24
|
-
import EditorNodes from '../EditorNodes.js';
|
|
25
|
-
import convertFromHTML from '../convertFromHTML.js';
|
|
26
|
-
import DocLayoutCommand from '../DocLayoutCommand.js';
|
|
27
|
-
|
|
28
|
-
export const DataType = Object.freeze({
|
|
29
|
-
JSON: Symbol('json'),
|
|
30
|
-
HTML: Symbol('html'),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* LICIT properties:
|
|
35
|
-
* docID {string} [] Collaborative Doument ID
|
|
36
|
-
* collabServiceURL {string} [/collaboration-service] Collaboration Service URL
|
|
37
|
-
* debug {boolean} [false] To enable/disable ProseMirror Debug Tools, available only in development.
|
|
38
|
-
* width {string} [100%] Width of the editor.
|
|
39
|
-
* height {string} [100%] Height of the editor.
|
|
40
|
-
* readOnly {boolean} [false] To enable/disable editing mode.
|
|
41
|
-
* onChange {@callback} [null] Fires after each significant change.
|
|
42
|
-
* @param data {JSON} Modified document data.
|
|
43
|
-
* onReady {@callback} [null] Fires when the editor is fully ready.
|
|
44
|
-
* @param ref {LICIT} Rerefence of the editor.
|
|
45
|
-
* data {JSON|HTML} [null] Document data to be loaded into the editor.
|
|
46
|
-
* dataType {JSON|HTML} [JSON] Document data to be loaded into the editor.
|
|
47
|
-
* disabled {boolean} [false] Disable the editor.
|
|
48
|
-
* embedded {boolean} [false] Disable/Enable inline behaviour.
|
|
49
|
-
* plugins [plugins] External Plugins into the editor.
|
|
50
|
-
*/
|
|
51
|
-
class Licit extends React.Component<any, any> {
|
|
52
|
-
_runtime: EditorRuntime;
|
|
53
|
-
_connector: SimpleConnector;
|
|
54
|
-
_clientID: string;
|
|
55
|
-
_editorView: EditorView; // This will be handy in updating document's content.
|
|
56
|
-
_skipSCU: boolean; // Flag to decide whether to skip shouldComponentUpdate
|
|
57
|
-
_defaultEditorSchema: Schema;
|
|
58
|
-
_defaultEditorPlugins: Array<Plugin>;
|
|
59
|
-
_pasteJSONPlugin: Plugin;
|
|
60
|
-
|
|
61
|
-
_popUp = null;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Provides access to prosemirror view.
|
|
65
|
-
*/
|
|
66
|
-
get editorView(): EditorView {
|
|
67
|
-
return this._editorView;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
constructor(props: any, context: any) {
|
|
71
|
-
super(props, context);
|
|
72
|
-
this.initialize(props);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
initialize(props: any) {
|
|
76
|
-
this._clientID = uuid();
|
|
77
|
-
this._editorView = null;
|
|
78
|
-
this._skipSCU = true;
|
|
79
|
-
|
|
80
|
-
const noop = function () {};
|
|
81
|
-
|
|
82
|
-
// [FS] IRAD-981 2020-06-10
|
|
83
|
-
// Component's configurations.
|
|
84
|
-
// [FS] IRAD-1552 2021-08-26
|
|
85
|
-
// Collaboration server / client should allow string values for document identifiers.
|
|
86
|
-
const docID = props.docID || ''; // Empty means collaborative.
|
|
87
|
-
const collaborative = docID !== '';
|
|
88
|
-
// [FS] IRAD-1553 2021-08-26
|
|
89
|
-
// Configurable Collaboration Service URL.
|
|
90
|
-
const collabServiceURL = props.collabServiceURL || '/collaboration-service';
|
|
91
|
-
const debug = props.debug || false;
|
|
92
|
-
// Default width and height to undefined
|
|
93
|
-
const width = props.width || undefined;
|
|
94
|
-
const height = props.height || undefined;
|
|
95
|
-
const onChangeCB =
|
|
96
|
-
typeof props.onChange === 'function' ? props.onChange : noop;
|
|
97
|
-
const onReadyCB =
|
|
98
|
-
typeof props.onReady === 'function' ? props.onReady : noop;
|
|
99
|
-
const readOnly = props.readOnly || false;
|
|
100
|
-
let data = props.data || null;
|
|
101
|
-
const dataType = props.dataType || DataType.JSON;
|
|
102
|
-
const disabled = props.disabled || false;
|
|
103
|
-
const embedded = props.embedded || false; // [FS] IRAD-996 2020-06-30
|
|
104
|
-
// [FS] 2020-07-03
|
|
105
|
-
// Handle Image Upload from Angular App
|
|
106
|
-
const runtime = props.runtime || null;
|
|
107
|
-
const plugins = props.plugins || null;
|
|
108
|
-
// This flag decides whether DataType.HTML check is needed when
|
|
109
|
-
// changing document. If it forcefully done, it is not needed, otherwise needed.
|
|
110
|
-
this.skipDataTypeCheck = false;
|
|
111
|
-
|
|
112
|
-
this._defaultEditorSchema = new Schema({
|
|
113
|
-
nodes: EditorNodes,
|
|
114
|
-
marks: EditorMarks,
|
|
115
|
-
});
|
|
116
|
-
this._defaultEditorPlugins = new DefaultEditorPlugins(
|
|
117
|
-
this._defaultEditorSchema
|
|
118
|
-
).get();
|
|
119
|
-
this._pasteJSONPlugin = null;
|
|
120
|
-
|
|
121
|
-
const editorState = this.initEditorState(plugins, dataType, data);
|
|
122
|
-
data = editorState.doc;
|
|
123
|
-
|
|
124
|
-
const setState = this.setState.bind(this);
|
|
125
|
-
this._connector = collaborative
|
|
126
|
-
? new CollabConnector(
|
|
127
|
-
editorState,
|
|
128
|
-
setState,
|
|
129
|
-
{
|
|
130
|
-
docID,
|
|
131
|
-
collabServiceURL,
|
|
132
|
-
},
|
|
133
|
-
this._defaultEditorSchema,
|
|
134
|
-
this._defaultEditorPlugins,
|
|
135
|
-
// [FS] IRAD-1578 2021-09-27
|
|
136
|
-
this.onReady.bind(this)
|
|
137
|
-
)
|
|
138
|
-
: new SimpleConnector(editorState, setState);
|
|
139
|
-
|
|
140
|
-
this._connector._dataDefined = !!props.data;
|
|
141
|
-
|
|
142
|
-
// FS IRAD-989 2020-18-06
|
|
143
|
-
// updating properties should automatically render the changes
|
|
144
|
-
|
|
145
|
-
this.state = {
|
|
146
|
-
docID,
|
|
147
|
-
collabServiceURL,
|
|
148
|
-
data,
|
|
149
|
-
editorState,
|
|
150
|
-
width,
|
|
151
|
-
height,
|
|
152
|
-
readOnly,
|
|
153
|
-
onChangeCB,
|
|
154
|
-
onReadyCB,
|
|
155
|
-
debug,
|
|
156
|
-
disabled,
|
|
157
|
-
embedded,
|
|
158
|
-
runtime,
|
|
159
|
-
dataType,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// FS IRAD-1040 2020-26-08
|
|
163
|
-
// Get the modified schema from editorstate and send it to collab server
|
|
164
|
-
if (this._connector.updateSchema) {
|
|
165
|
-
// Use known editorState to update schema.
|
|
166
|
-
this._connector.updateSchema(editorState.schema, data);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
initEditorState(plugins: Array<Plugin>, dataType: DataType, data: any) {
|
|
171
|
-
let editorState = null;
|
|
172
|
-
const effectivePlugins = this.getEffectivePlugins(
|
|
173
|
-
this._defaultEditorSchema,
|
|
174
|
-
this._defaultEditorPlugins,
|
|
175
|
-
plugins
|
|
176
|
-
);
|
|
177
|
-
this._pasteJSONPlugin = effectivePlugins.pasteJSONPlugin;
|
|
178
|
-
if (DataType.JSON === dataType) {
|
|
179
|
-
editorState = convertFromJSON(
|
|
180
|
-
data,
|
|
181
|
-
null,
|
|
182
|
-
effectivePlugins.schema,
|
|
183
|
-
effectivePlugins.plugins
|
|
184
|
-
);
|
|
185
|
-
// [FS] IRAD-1067 2020-09-19
|
|
186
|
-
// The editorState will return null if the doc Json is mal-formed
|
|
187
|
-
if (null === editorState) {
|
|
188
|
-
editorState = convertFromJSON(
|
|
189
|
-
EMPTY_DOC_JSON,
|
|
190
|
-
null,
|
|
191
|
-
effectivePlugins.schema,
|
|
192
|
-
effectivePlugins.plugins
|
|
193
|
-
);
|
|
194
|
-
this.showAlert();
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
editorState = convertFromHTML(
|
|
198
|
-
data,
|
|
199
|
-
effectivePlugins.schema,
|
|
200
|
-
effectivePlugins.plugins
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return editorState;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
getEffectivePlugins(
|
|
208
|
-
schema: Schema,
|
|
209
|
-
defaultPlugins: Array<Plugin>,
|
|
210
|
-
plugins: Array<Plugin>
|
|
211
|
-
): { plugins: Array<Plugin>, schema: Schema, pasteJSONPlugin: Plugin } {
|
|
212
|
-
const effectivePlugins = defaultPlugins;
|
|
213
|
-
let pasteJSONPlugin = null;
|
|
214
|
-
|
|
215
|
-
if (plugins) {
|
|
216
|
-
for (const p of plugins) {
|
|
217
|
-
if (!effectivePlugins.includes(p)) {
|
|
218
|
-
effectivePlugins.push(p);
|
|
219
|
-
if (p.getEffectiveSchema) {
|
|
220
|
-
schema = p.getEffectiveSchema(schema);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (p.initKeyCommands) {
|
|
224
|
-
effectivePlugins.push(p.initKeyCommands());
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (p.insert) {
|
|
228
|
-
pasteJSONPlugin = p;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return { plugins: effectivePlugins, schema, pasteJSONPlugin };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// [FS] IRAD-1578 2021-09-27
|
|
237
|
-
onReady(state: EditorState) {
|
|
238
|
-
const collabEditing = this.state.docID !== '';
|
|
239
|
-
|
|
240
|
-
if (collabEditing) {
|
|
241
|
-
this._editorView && this._editorView.focus();
|
|
242
|
-
if (this.state.onReadyCB) {
|
|
243
|
-
this.state.onReadyCB(this);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// [FS] IRAD-1067 2020-09-19
|
|
249
|
-
// Alert funtion to show document is corrupted
|
|
250
|
-
showAlert() {
|
|
251
|
-
const anchor = null;
|
|
252
|
-
this._popUp = createPopUp(AlertInfo, null, {
|
|
253
|
-
anchor,
|
|
254
|
-
position: atViewportCenter,
|
|
255
|
-
onClose: (val) => {
|
|
256
|
-
if (this._popUp) {
|
|
257
|
-
this._popUp = null;
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
resetCounters(transaction: Transform) {
|
|
264
|
-
for (let index = 1; index <= 10; index++) {
|
|
265
|
-
const counterVar = 'set-cust-style-counter-' + index;
|
|
266
|
-
const setCounterVal = window[counterVar];
|
|
267
|
-
if (setCounterVal) {
|
|
268
|
-
delete window[counterVar];
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
this.setCounterFlags(transaction, true);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
setCounterFlags(transaction: Transform, reset: boolean) {
|
|
275
|
-
let modified = false;
|
|
276
|
-
let counterFlags = null;
|
|
277
|
-
const existingCFlags = transaction.doc.attrs.counterFlags;
|
|
278
|
-
if (reset && !existingCFlags) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
for (let index = 1; index <= 10; index++) {
|
|
283
|
-
const counterVar = 'set-cust-style-counter-' + index;
|
|
284
|
-
|
|
285
|
-
const setCounterVal = window[counterVar];
|
|
286
|
-
if (setCounterVal) {
|
|
287
|
-
if (!counterFlags) {
|
|
288
|
-
counterFlags = {};
|
|
289
|
-
}
|
|
290
|
-
counterFlags[counterVar] = true;
|
|
291
|
-
|
|
292
|
-
if (!existingCFlags) {
|
|
293
|
-
modified = true;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
if (!modified) {
|
|
297
|
-
if (existingCFlags) {
|
|
298
|
-
if (setCounterVal) {
|
|
299
|
-
modified = undefined == existingCFlags[counterVar];
|
|
300
|
-
} else {
|
|
301
|
-
modified = undefined != existingCFlags[counterVar];
|
|
302
|
-
}
|
|
303
|
-
} else {
|
|
304
|
-
modified = setCounterVal;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (modified) {
|
|
310
|
-
const tr = this._editorView.state.tr.step(
|
|
311
|
-
new SetDocAttrStep('counterFlags', counterFlags)
|
|
312
|
-
);
|
|
313
|
-
this._editorView.dispatch(tr);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
getDeletedArtifactIds() {
|
|
318
|
-
if (this._connector.getDeletedArtifactIds) {
|
|
319
|
-
this._connector.getDeletedArtifactIds(this.state.editorState.schema);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
isNodeHasAttribute(node: Node, attrName: string) {
|
|
324
|
-
return node.attrs?.[attrName];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
getDocument(content: any, editorState: EditorState, dataType: DataType) {
|
|
328
|
-
let document = null;
|
|
329
|
-
const { schema } = editorState;
|
|
330
|
-
|
|
331
|
-
if (DataType.JSON === dataType || this.skipDataTypeCheck) {
|
|
332
|
-
document = schema.nodeFromJSON(content || EMPTY_DOC_JSON);
|
|
333
|
-
} else {
|
|
334
|
-
const tempEState = convertFromHTML(
|
|
335
|
-
content || '',
|
|
336
|
-
schema,
|
|
337
|
-
editorState.plugins
|
|
338
|
-
);
|
|
339
|
-
document = tempEState.doc;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return document;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
insertJSON = (json: { [key: string]: any }): void => {
|
|
346
|
-
if (this._pasteJSONPlugin?.insert) {
|
|
347
|
-
this._pasteJSONPlugin.insert(json, this._editorView);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
setContent = (content: any = {}, dataType: DataType): void => {
|
|
352
|
-
this.skipDataTypeCheck = false;
|
|
353
|
-
// [FS] IRAD-1571 2021-09-27
|
|
354
|
-
// dispatch a transaction that MUST start from the views current state;
|
|
355
|
-
const editorState = this._editorView.state;
|
|
356
|
-
let { tr } = editorState;
|
|
357
|
-
const document = this.getDocument(content, editorState, dataType);
|
|
358
|
-
this.skipDataTypeCheck = true;
|
|
359
|
-
|
|
360
|
-
// [FS] IRAD-1593 2021-10-12
|
|
361
|
-
// Reset lastKeyCode since the content is set dynamically and so lastKeyCode is invalid now.
|
|
362
|
-
this._editorView.lastKeyCode = null;
|
|
363
|
-
|
|
364
|
-
// [FS] IRAD-1092 2020-12-03
|
|
365
|
-
// set the value for object metadata and objectId
|
|
366
|
-
// Should update all document attributes.
|
|
367
|
-
Object.keys(document.attrs).forEach((attr) => {
|
|
368
|
-
tr = tr.step(new SetDocAttrStep(attr, document.attrs[attr]));
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
this._skipSCU = true;
|
|
372
|
-
this._editorView.dispatch(tr);
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
hasDataChanged(nextData: any, nextDataType: DataType) {
|
|
376
|
-
let dataChanged = false;
|
|
377
|
-
|
|
378
|
-
// [FS] IRAD-1571 2021-09-27
|
|
379
|
-
// dispatch a transaction that MUST start from the views current state;
|
|
380
|
-
// [FS] IRAD-1589 2021-10-04
|
|
381
|
-
// Do a proper circular JSON comparison.
|
|
382
|
-
if (stringify(this.state.data) !== stringify(nextData)) {
|
|
383
|
-
const editorState = this._editorView.state;
|
|
384
|
-
const nextDoc = this.getDocument(nextData, editorState, nextDataType);
|
|
385
|
-
dataChanged = !nextDoc.eq(editorState.doc);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return dataChanged;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
changeContent(data: any, dataType: DataType) {
|
|
392
|
-
if (this.hasDataChanged(data, dataType)) {
|
|
393
|
-
// FS IRAD-1592 2021-11-10
|
|
394
|
-
// Release here quickly, so that update doesn't care about at this point.
|
|
395
|
-
// data changed, so update document content
|
|
396
|
-
setTimeout(this.setContent.bind(this, data, dataType), 1);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
shouldComponentUpdate(nextProps: any, nextState: any) {
|
|
401
|
-
// Only interested if properties are set from outside.
|
|
402
|
-
if (!this._skipSCU) {
|
|
403
|
-
this._skipSCU = false;
|
|
404
|
-
|
|
405
|
-
this.changeContent(nextState.data, nextState.dataType);
|
|
406
|
-
|
|
407
|
-
if (this.state.docID !== nextState.docID) {
|
|
408
|
-
setTimeout(this.setDocID.bind(this, nextState), 1);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
this.skipDataTypeCheck = true;
|
|
413
|
-
|
|
414
|
-
return true;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
setDocID(nextState: any) {
|
|
418
|
-
// Collaborative mode changed
|
|
419
|
-
const collabEditing = nextState.docID !== '';
|
|
420
|
-
const editorState = this._editorView.state;
|
|
421
|
-
const setState = this.setState.bind(this);
|
|
422
|
-
const docID = nextState.docID || '';
|
|
423
|
-
const collabServiceURL =
|
|
424
|
-
nextState.collabServiceURL || '/collaboration-service';
|
|
425
|
-
|
|
426
|
-
if (this._connector) {
|
|
427
|
-
this._connector.cleanUp();
|
|
428
|
-
}
|
|
429
|
-
// create new connector
|
|
430
|
-
this._connector = collabEditing
|
|
431
|
-
? new CollabConnector(
|
|
432
|
-
editorState,
|
|
433
|
-
setState,
|
|
434
|
-
{
|
|
435
|
-
docID,
|
|
436
|
-
collabServiceURL,
|
|
437
|
-
},
|
|
438
|
-
this._defaultEditorSchema,
|
|
439
|
-
this._defaultEditorPlugins,
|
|
440
|
-
// [FS] IRAD-1578 2021-09-27
|
|
441
|
-
this.onReady.bind(this)
|
|
442
|
-
)
|
|
443
|
-
: new SimpleConnector(editorState, setState);
|
|
444
|
-
|
|
445
|
-
// FS IRAD-1592 2021-11-10
|
|
446
|
-
// Notify collab server
|
|
447
|
-
if (this._connector.updateSchema) {
|
|
448
|
-
// Use known editorState to update schema.
|
|
449
|
-
this._connector.updateSchema(editorState.schema);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
render(): React.Element<any> {
|
|
454
|
-
const {
|
|
455
|
-
editorState,
|
|
456
|
-
width,
|
|
457
|
-
height,
|
|
458
|
-
readOnly,
|
|
459
|
-
disabled,
|
|
460
|
-
embedded,
|
|
461
|
-
runtime,
|
|
462
|
-
} = this.state;
|
|
463
|
-
// [FS] IRAD-978 2020-06-05
|
|
464
|
-
// Using 100vw & 100vh (100% viewport) is not ideal for a component which is expected to be a part of a page,
|
|
465
|
-
// so changing it to 100% width & height which will occupy the area relative to its parent.
|
|
466
|
-
return (
|
|
467
|
-
<RichTextEditor
|
|
468
|
-
disabled={disabled}
|
|
469
|
-
editorState={editorState}
|
|
470
|
-
embedded={embedded}
|
|
471
|
-
height={height}
|
|
472
|
-
onChange={this._onChange}
|
|
473
|
-
onReady={this._onReady}
|
|
474
|
-
readOnly={readOnly}
|
|
475
|
-
runtime={runtime}
|
|
476
|
-
width={width}
|
|
477
|
-
/>
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
_onChange = (data: { state: EditorState, transaction: Transform }): void => {
|
|
482
|
-
const { transaction } = data;
|
|
483
|
-
|
|
484
|
-
/*
|
|
485
|
-
** ProseMirror Debug Tool's Snapshot creates a new state and sets that to editor view's state.
|
|
486
|
-
** This results in the connector's state as an orphan and thus transaction mismatch error.
|
|
487
|
-
** To resolve check and update the connector's state to keep in sync.
|
|
488
|
-
*/
|
|
489
|
-
|
|
490
|
-
if (this._editorView) {
|
|
491
|
-
const isSameState =
|
|
492
|
-
this._connector._editorState == this._editorView.state;
|
|
493
|
-
let invokeOnEdit = false;
|
|
494
|
-
|
|
495
|
-
if (!isSameState) {
|
|
496
|
-
this._connector._editorState = this._editorView.state;
|
|
497
|
-
invokeOnEdit = true;
|
|
498
|
-
} else {
|
|
499
|
-
// [FS] IRAD-1264 2021-03-19
|
|
500
|
-
// check if in non-collab mode.
|
|
501
|
-
if (!(this._connector instanceof CollabConnector)) {
|
|
502
|
-
invokeOnEdit = true;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (invokeOnEdit) {
|
|
506
|
-
// [FS] IRAD-1236 2020-03-05
|
|
507
|
-
// Only need to call if there is any difference in collab mode OR always in non-collab mode.
|
|
508
|
-
this._connector.onEdit(transaction, this._editorView);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (transaction.docChanged || (!isSameState && !transaction.getMeta('suppressOnChange'))) {
|
|
512
|
-
const docJson = this._editorView?.state?.doc?.toJSON();
|
|
513
|
-
if (!Object.isFrozen(docJson?.attrs?.objectMetaData)) {
|
|
514
|
-
docJson.attrs.objectMetaData = {
|
|
515
|
-
...docJson.attrs.objectMetaData,
|
|
516
|
-
lastEditedOn: new Date().toISOString().replace('Z', '+00:00')
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
let isEmpty = false;
|
|
521
|
-
if (docJson.content && docJson.content.length === 1) {
|
|
522
|
-
if (
|
|
523
|
-
!docJson.content[0].content ||
|
|
524
|
-
(docJson.content?.[0]?.content?.[0]?.text &&
|
|
525
|
-
'' === docJson.content?.[0]?.content?.[0]?.text.trim())
|
|
526
|
-
) {
|
|
527
|
-
isEmpty = true;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// setCFlags is/was always the opposite of isEmpty.
|
|
532
|
-
if (isEmpty) {
|
|
533
|
-
this.resetCounters(transaction);
|
|
534
|
-
} else {
|
|
535
|
-
this.setCounterFlags(transaction, false);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// Changing 2nd parameter from boolean to object was not in any way
|
|
539
|
-
// backwards compatible. Any conditional logic placed on isEmpty was
|
|
540
|
-
// broken. Reverting that change, then adding view as a 3rd parameter.
|
|
541
|
-
this.state.onChangeCB(docJson, isEmpty, this._editorView);
|
|
542
|
-
|
|
543
|
-
this.closeOpenedPopupModels();
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
// [FS] IRAD-1173 2021-02-25
|
|
548
|
-
// Bug fix: Transaction mismatch error when a dialog is opened and keep typing.
|
|
549
|
-
closeOpenedPopupModels() {
|
|
550
|
-
const element = document.getElementsByClassName('czi-pop-up-element')[0];
|
|
551
|
-
if (element?.parentElement) {
|
|
552
|
-
element.parentElement.removeChild(element);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
_onReady = (editorView: EditorView): void => {
|
|
557
|
-
// [FS][06-APR-2020][IRAD-922]
|
|
558
|
-
// Showing focus in the editor.
|
|
559
|
-
const { state, dispatch } = editorView;
|
|
560
|
-
this._editorView = editorView;
|
|
561
|
-
const tr = state.tr;
|
|
562
|
-
dispatch(tr.scrollIntoView());
|
|
563
|
-
if (!this._editorView.editable) {
|
|
564
|
-
let _tr = this._editorView.state.tr;
|
|
565
|
-
let modified = false;
|
|
566
|
-
this._editorView.state.doc.descendants((node, pos) => {
|
|
567
|
-
if (node.type.name === 'table') {
|
|
568
|
-
// Apply setNodeMarkup with same type and attrs to force a refresh
|
|
569
|
-
_tr = _tr?.setNodeMarkup(pos, undefined, { ...node.attrs, Id: pos });
|
|
570
|
-
modified = true;
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
if (modified) {
|
|
574
|
-
this._editorView.dispatch(_tr);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
// [FS] IRAD-1578 2021-09-27
|
|
578
|
-
// In collab mode, fire onRead only after getting the response from collab server.
|
|
579
|
-
if (this.state.onReadyCB && this.state.docID === '') {
|
|
580
|
-
editorView.focus();
|
|
581
|
-
this.state.onReadyCB(this);
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* LICIT properties:
|
|
587
|
-
* docID {number} [0] Collaborative Doument ID
|
|
588
|
-
* debug {boolean} [false] To enable/disable ProseMirror Debug Tools, available only in development.
|
|
589
|
-
* width {string} [100%] Width of the editor.
|
|
590
|
-
* height {height} [100%] Height of the editor.
|
|
591
|
-
* readOnly {boolean} [false] To enable/disable editing mode.
|
|
592
|
-
* onChange {@callback} [null] Fires after each significant change.
|
|
593
|
-
* @param data {JSON} Modified document data.
|
|
594
|
-
* onReady {@callback} [null] Fires when the editor is fully ready.
|
|
595
|
-
* @param ref {LICIT} Rerefence of the editor.
|
|
596
|
-
* data {JSON} [null] Document data to be loaded into the editor.
|
|
597
|
-
* disabled {boolean} [false] Disable the editor.
|
|
598
|
-
* embedded {boolean} [false] Disable/Enable inline behaviour.
|
|
599
|
-
*/
|
|
600
|
-
setProps = (props: any): void => {
|
|
601
|
-
if (this.state.readOnly) {
|
|
602
|
-
// It should be possible to load content into the editor in readonly as well.
|
|
603
|
-
// It should not be necessary to make the component writable any time during the process
|
|
604
|
-
const propsCopy = {};
|
|
605
|
-
this._skipSCU = true;
|
|
606
|
-
Object.assign(propsCopy, props);
|
|
607
|
-
// make writable without content change
|
|
608
|
-
propsCopy.readOnly = false;
|
|
609
|
-
delete propsCopy.data;
|
|
610
|
-
this.setState(propsCopy);
|
|
611
|
-
}
|
|
612
|
-
this.skipDataTypeCheck = false;
|
|
613
|
-
// Need to go through shouldComponentUpdate lifecycle here, when updated from outside,
|
|
614
|
-
// so that content is modified gracefully using transaction so that undo/redo works too.
|
|
615
|
-
this._skipSCU = false;
|
|
616
|
-
this.setState(props);
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
goToEnd = (): void => {
|
|
620
|
-
// Return focus to the editor with cursor at end of document.
|
|
621
|
-
const view: EditorView = this.editorView;
|
|
622
|
-
const tr = view.state.tr;
|
|
623
|
-
view.dispatch(
|
|
624
|
-
tr.setSelection(TextSelection.atEnd(view.state.doc)).scrollIntoView()
|
|
625
|
-
);
|
|
626
|
-
view.focus();
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
/**
|
|
630
|
-
* Method to open page layout
|
|
631
|
-
*/
|
|
632
|
-
pageLayout = (): void => {
|
|
633
|
-
const DOC_LAYOUT = new DocLayoutCommand();
|
|
634
|
-
DOC_LAYOUT.waitForUserInput(
|
|
635
|
-
this._editorView.state,
|
|
636
|
-
this._editorView.dispatch,
|
|
637
|
-
this._editorView
|
|
638
|
-
).then((inputs) => {
|
|
639
|
-
DOC_LAYOUT.executeWithUserInput(
|
|
640
|
-
this._editorView.state,
|
|
641
|
-
this._editorView.dispatch,
|
|
642
|
-
this._editorView,
|
|
643
|
-
inputs
|
|
644
|
-
);
|
|
645
|
-
});
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
export default Licit;
|
|
1
|
+
// @flow
|
|
2
|
+
import { EditorState, TextSelection, Plugin } from 'prosemirror-state';
|
|
3
|
+
import { Node, Schema } from 'prosemirror-model';
|
|
4
|
+
import { Transform } from 'prosemirror-transform';
|
|
5
|
+
import { EditorView } from 'prosemirror-view';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { stringify } from 'flatted';
|
|
8
|
+
|
|
9
|
+
import convertFromJSON from '../convertFromJSON.js';
|
|
10
|
+
import RichTextEditor from '../ui/RichTextEditor.js';
|
|
11
|
+
import uuid from '../uuid.js';
|
|
12
|
+
import SimpleConnector from './SimpleConnector.js';
|
|
13
|
+
import CollabConnector from './CollabConnector.js';
|
|
14
|
+
import { EMPTY_DOC_JSON } from '../createEmptyEditorState.js';
|
|
15
|
+
import type { EditorRuntime } from '../Types.js';
|
|
16
|
+
import {
|
|
17
|
+
createPopUp,
|
|
18
|
+
atViewportCenter,
|
|
19
|
+
} from '@modusoperandi/licit-ui-commands';
|
|
20
|
+
import AlertInfo from '../ui/AlertInfo.js';
|
|
21
|
+
import { SetDocAttrStep } from '@modusoperandi/licit-doc-attrs-step';
|
|
22
|
+
import DefaultEditorPlugins from '../buildEditorPlugins.js';
|
|
23
|
+
import EditorMarks from '../EditorMarks.js';
|
|
24
|
+
import EditorNodes from '../EditorNodes.js';
|
|
25
|
+
import convertFromHTML from '../convertFromHTML.js';
|
|
26
|
+
import DocLayoutCommand from '../DocLayoutCommand.js';
|
|
27
|
+
|
|
28
|
+
export const DataType = Object.freeze({
|
|
29
|
+
JSON: Symbol('json'),
|
|
30
|
+
HTML: Symbol('html'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* LICIT properties:
|
|
35
|
+
* docID {string} [] Collaborative Doument ID
|
|
36
|
+
* collabServiceURL {string} [/collaboration-service] Collaboration Service URL
|
|
37
|
+
* debug {boolean} [false] To enable/disable ProseMirror Debug Tools, available only in development.
|
|
38
|
+
* width {string} [100%] Width of the editor.
|
|
39
|
+
* height {string} [100%] Height of the editor.
|
|
40
|
+
* readOnly {boolean} [false] To enable/disable editing mode.
|
|
41
|
+
* onChange {@callback} [null] Fires after each significant change.
|
|
42
|
+
* @param data {JSON} Modified document data.
|
|
43
|
+
* onReady {@callback} [null] Fires when the editor is fully ready.
|
|
44
|
+
* @param ref {LICIT} Rerefence of the editor.
|
|
45
|
+
* data {JSON|HTML} [null] Document data to be loaded into the editor.
|
|
46
|
+
* dataType {JSON|HTML} [JSON] Document data to be loaded into the editor.
|
|
47
|
+
* disabled {boolean} [false] Disable the editor.
|
|
48
|
+
* embedded {boolean} [false] Disable/Enable inline behaviour.
|
|
49
|
+
* plugins [plugins] External Plugins into the editor.
|
|
50
|
+
*/
|
|
51
|
+
class Licit extends React.Component<any, any> {
|
|
52
|
+
_runtime: EditorRuntime;
|
|
53
|
+
_connector: SimpleConnector;
|
|
54
|
+
_clientID: string;
|
|
55
|
+
_editorView: EditorView; // This will be handy in updating document's content.
|
|
56
|
+
_skipSCU: boolean; // Flag to decide whether to skip shouldComponentUpdate
|
|
57
|
+
_defaultEditorSchema: Schema;
|
|
58
|
+
_defaultEditorPlugins: Array<Plugin>;
|
|
59
|
+
_pasteJSONPlugin: Plugin;
|
|
60
|
+
|
|
61
|
+
_popUp = null;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Provides access to prosemirror view.
|
|
65
|
+
*/
|
|
66
|
+
get editorView(): EditorView {
|
|
67
|
+
return this._editorView;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
constructor(props: any, context: any) {
|
|
71
|
+
super(props, context);
|
|
72
|
+
this.initialize(props);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
initialize(props: any) {
|
|
76
|
+
this._clientID = uuid();
|
|
77
|
+
this._editorView = null;
|
|
78
|
+
this._skipSCU = true;
|
|
79
|
+
|
|
80
|
+
const noop = function () {};
|
|
81
|
+
|
|
82
|
+
// [FS] IRAD-981 2020-06-10
|
|
83
|
+
// Component's configurations.
|
|
84
|
+
// [FS] IRAD-1552 2021-08-26
|
|
85
|
+
// Collaboration server / client should allow string values for document identifiers.
|
|
86
|
+
const docID = props.docID || ''; // Empty means collaborative.
|
|
87
|
+
const collaborative = docID !== '';
|
|
88
|
+
// [FS] IRAD-1553 2021-08-26
|
|
89
|
+
// Configurable Collaboration Service URL.
|
|
90
|
+
const collabServiceURL = props.collabServiceURL || '/collaboration-service';
|
|
91
|
+
const debug = props.debug || false;
|
|
92
|
+
// Default width and height to undefined
|
|
93
|
+
const width = props.width || undefined;
|
|
94
|
+
const height = props.height || undefined;
|
|
95
|
+
const onChangeCB =
|
|
96
|
+
typeof props.onChange === 'function' ? props.onChange : noop;
|
|
97
|
+
const onReadyCB =
|
|
98
|
+
typeof props.onReady === 'function' ? props.onReady : noop;
|
|
99
|
+
const readOnly = props.readOnly || false;
|
|
100
|
+
let data = props.data || null;
|
|
101
|
+
const dataType = props.dataType || DataType.JSON;
|
|
102
|
+
const disabled = props.disabled || false;
|
|
103
|
+
const embedded = props.embedded || false; // [FS] IRAD-996 2020-06-30
|
|
104
|
+
// [FS] 2020-07-03
|
|
105
|
+
// Handle Image Upload from Angular App
|
|
106
|
+
const runtime = props.runtime || null;
|
|
107
|
+
const plugins = props.plugins || null;
|
|
108
|
+
// This flag decides whether DataType.HTML check is needed when
|
|
109
|
+
// changing document. If it forcefully done, it is not needed, otherwise needed.
|
|
110
|
+
this.skipDataTypeCheck = false;
|
|
111
|
+
|
|
112
|
+
this._defaultEditorSchema = new Schema({
|
|
113
|
+
nodes: EditorNodes,
|
|
114
|
+
marks: EditorMarks,
|
|
115
|
+
});
|
|
116
|
+
this._defaultEditorPlugins = new DefaultEditorPlugins(
|
|
117
|
+
this._defaultEditorSchema
|
|
118
|
+
).get();
|
|
119
|
+
this._pasteJSONPlugin = null;
|
|
120
|
+
|
|
121
|
+
const editorState = this.initEditorState(plugins, dataType, data);
|
|
122
|
+
data = editorState.doc;
|
|
123
|
+
|
|
124
|
+
const setState = this.setState.bind(this);
|
|
125
|
+
this._connector = collaborative
|
|
126
|
+
? new CollabConnector(
|
|
127
|
+
editorState,
|
|
128
|
+
setState,
|
|
129
|
+
{
|
|
130
|
+
docID,
|
|
131
|
+
collabServiceURL,
|
|
132
|
+
},
|
|
133
|
+
this._defaultEditorSchema,
|
|
134
|
+
this._defaultEditorPlugins,
|
|
135
|
+
// [FS] IRAD-1578 2021-09-27
|
|
136
|
+
this.onReady.bind(this)
|
|
137
|
+
)
|
|
138
|
+
: new SimpleConnector(editorState, setState);
|
|
139
|
+
|
|
140
|
+
this._connector._dataDefined = !!props.data;
|
|
141
|
+
|
|
142
|
+
// FS IRAD-989 2020-18-06
|
|
143
|
+
// updating properties should automatically render the changes
|
|
144
|
+
|
|
145
|
+
this.state = {
|
|
146
|
+
docID,
|
|
147
|
+
collabServiceURL,
|
|
148
|
+
data,
|
|
149
|
+
editorState,
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
readOnly,
|
|
153
|
+
onChangeCB,
|
|
154
|
+
onReadyCB,
|
|
155
|
+
debug,
|
|
156
|
+
disabled,
|
|
157
|
+
embedded,
|
|
158
|
+
runtime,
|
|
159
|
+
dataType,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// FS IRAD-1040 2020-26-08
|
|
163
|
+
// Get the modified schema from editorstate and send it to collab server
|
|
164
|
+
if (this._connector.updateSchema) {
|
|
165
|
+
// Use known editorState to update schema.
|
|
166
|
+
this._connector.updateSchema(editorState.schema, data);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
initEditorState(plugins: Array<Plugin>, dataType: DataType, data: any) {
|
|
171
|
+
let editorState = null;
|
|
172
|
+
const effectivePlugins = this.getEffectivePlugins(
|
|
173
|
+
this._defaultEditorSchema,
|
|
174
|
+
this._defaultEditorPlugins,
|
|
175
|
+
plugins
|
|
176
|
+
);
|
|
177
|
+
this._pasteJSONPlugin = effectivePlugins.pasteJSONPlugin;
|
|
178
|
+
if (DataType.JSON === dataType) {
|
|
179
|
+
editorState = convertFromJSON(
|
|
180
|
+
data,
|
|
181
|
+
null,
|
|
182
|
+
effectivePlugins.schema,
|
|
183
|
+
effectivePlugins.plugins
|
|
184
|
+
);
|
|
185
|
+
// [FS] IRAD-1067 2020-09-19
|
|
186
|
+
// The editorState will return null if the doc Json is mal-formed
|
|
187
|
+
if (null === editorState) {
|
|
188
|
+
editorState = convertFromJSON(
|
|
189
|
+
EMPTY_DOC_JSON,
|
|
190
|
+
null,
|
|
191
|
+
effectivePlugins.schema,
|
|
192
|
+
effectivePlugins.plugins
|
|
193
|
+
);
|
|
194
|
+
this.showAlert();
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
editorState = convertFromHTML(
|
|
198
|
+
data,
|
|
199
|
+
effectivePlugins.schema,
|
|
200
|
+
effectivePlugins.plugins
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return editorState;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getEffectivePlugins(
|
|
208
|
+
schema: Schema,
|
|
209
|
+
defaultPlugins: Array<Plugin>,
|
|
210
|
+
plugins: Array<Plugin>
|
|
211
|
+
): { plugins: Array<Plugin>, schema: Schema, pasteJSONPlugin: Plugin } {
|
|
212
|
+
const effectivePlugins = defaultPlugins;
|
|
213
|
+
let pasteJSONPlugin = null;
|
|
214
|
+
|
|
215
|
+
if (plugins) {
|
|
216
|
+
for (const p of plugins) {
|
|
217
|
+
if (!effectivePlugins.includes(p)) {
|
|
218
|
+
effectivePlugins.push(p);
|
|
219
|
+
if (p.getEffectiveSchema) {
|
|
220
|
+
schema = p.getEffectiveSchema(schema);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (p.initKeyCommands) {
|
|
224
|
+
effectivePlugins.push(p.initKeyCommands());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (p.insert) {
|
|
228
|
+
pasteJSONPlugin = p;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { plugins: effectivePlugins, schema, pasteJSONPlugin };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// [FS] IRAD-1578 2021-09-27
|
|
237
|
+
onReady(state: EditorState) {
|
|
238
|
+
const collabEditing = this.state.docID !== '';
|
|
239
|
+
|
|
240
|
+
if (collabEditing) {
|
|
241
|
+
this._editorView && this._editorView.focus();
|
|
242
|
+
if (this.state.onReadyCB) {
|
|
243
|
+
this.state.onReadyCB(this);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// [FS] IRAD-1067 2020-09-19
|
|
249
|
+
// Alert funtion to show document is corrupted
|
|
250
|
+
showAlert() {
|
|
251
|
+
const anchor = null;
|
|
252
|
+
this._popUp = createPopUp(AlertInfo, null, {
|
|
253
|
+
anchor,
|
|
254
|
+
position: atViewportCenter,
|
|
255
|
+
onClose: (val) => {
|
|
256
|
+
if (this._popUp) {
|
|
257
|
+
this._popUp = null;
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
resetCounters(transaction: Transform) {
|
|
264
|
+
for (let index = 1; index <= 10; index++) {
|
|
265
|
+
const counterVar = 'set-cust-style-counter-' + index;
|
|
266
|
+
const setCounterVal = window[counterVar];
|
|
267
|
+
if (setCounterVal) {
|
|
268
|
+
delete window[counterVar];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
this.setCounterFlags(transaction, true);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
setCounterFlags(transaction: Transform, reset: boolean) {
|
|
275
|
+
let modified = false;
|
|
276
|
+
let counterFlags = null;
|
|
277
|
+
const existingCFlags = transaction.doc.attrs.counterFlags;
|
|
278
|
+
if (reset && !existingCFlags) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
for (let index = 1; index <= 10; index++) {
|
|
283
|
+
const counterVar = 'set-cust-style-counter-' + index;
|
|
284
|
+
|
|
285
|
+
const setCounterVal = window[counterVar];
|
|
286
|
+
if (setCounterVal) {
|
|
287
|
+
if (!counterFlags) {
|
|
288
|
+
counterFlags = {};
|
|
289
|
+
}
|
|
290
|
+
counterFlags[counterVar] = true;
|
|
291
|
+
|
|
292
|
+
if (!existingCFlags) {
|
|
293
|
+
modified = true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!modified) {
|
|
297
|
+
if (existingCFlags) {
|
|
298
|
+
if (setCounterVal) {
|
|
299
|
+
modified = undefined == existingCFlags[counterVar];
|
|
300
|
+
} else {
|
|
301
|
+
modified = undefined != existingCFlags[counterVar];
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
modified = setCounterVal;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (modified) {
|
|
310
|
+
const tr = this._editorView.state.tr.step(
|
|
311
|
+
new SetDocAttrStep('counterFlags', counterFlags)
|
|
312
|
+
);
|
|
313
|
+
this._editorView.dispatch(tr);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
getDeletedArtifactIds() {
|
|
318
|
+
if (this._connector.getDeletedArtifactIds) {
|
|
319
|
+
this._connector.getDeletedArtifactIds(this.state.editorState.schema);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
isNodeHasAttribute(node: Node, attrName: string) {
|
|
324
|
+
return node.attrs?.[attrName];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
getDocument(content: any, editorState: EditorState, dataType: DataType) {
|
|
328
|
+
let document = null;
|
|
329
|
+
const { schema } = editorState;
|
|
330
|
+
|
|
331
|
+
if (DataType.JSON === dataType || this.skipDataTypeCheck) {
|
|
332
|
+
document = schema.nodeFromJSON(content || EMPTY_DOC_JSON);
|
|
333
|
+
} else {
|
|
334
|
+
const tempEState = convertFromHTML(
|
|
335
|
+
content || '',
|
|
336
|
+
schema,
|
|
337
|
+
editorState.plugins
|
|
338
|
+
);
|
|
339
|
+
document = tempEState.doc;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return document;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
insertJSON = (json: { [key: string]: any }): void => {
|
|
346
|
+
if (this._pasteJSONPlugin?.insert) {
|
|
347
|
+
this._pasteJSONPlugin.insert(json, this._editorView);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
setContent = (content: any = {}, dataType: DataType): void => {
|
|
352
|
+
this.skipDataTypeCheck = false;
|
|
353
|
+
// [FS] IRAD-1571 2021-09-27
|
|
354
|
+
// dispatch a transaction that MUST start from the views current state;
|
|
355
|
+
const editorState = this._editorView.state;
|
|
356
|
+
let { tr } = editorState;
|
|
357
|
+
const document = this.getDocument(content, editorState, dataType);
|
|
358
|
+
this.skipDataTypeCheck = true;
|
|
359
|
+
|
|
360
|
+
// [FS] IRAD-1593 2021-10-12
|
|
361
|
+
// Reset lastKeyCode since the content is set dynamically and so lastKeyCode is invalid now.
|
|
362
|
+
this._editorView.lastKeyCode = null;
|
|
363
|
+
|
|
364
|
+
// [FS] IRAD-1092 2020-12-03
|
|
365
|
+
// set the value for object metadata and objectId
|
|
366
|
+
// Should update all document attributes.
|
|
367
|
+
Object.keys(document.attrs).forEach((attr) => {
|
|
368
|
+
tr = tr.step(new SetDocAttrStep(attr, document.attrs[attr]));
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
this._skipSCU = true;
|
|
372
|
+
this._editorView.dispatch(tr);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
hasDataChanged(nextData: any, nextDataType: DataType) {
|
|
376
|
+
let dataChanged = false;
|
|
377
|
+
|
|
378
|
+
// [FS] IRAD-1571 2021-09-27
|
|
379
|
+
// dispatch a transaction that MUST start from the views current state;
|
|
380
|
+
// [FS] IRAD-1589 2021-10-04
|
|
381
|
+
// Do a proper circular JSON comparison.
|
|
382
|
+
if (stringify(this.state.data) !== stringify(nextData)) {
|
|
383
|
+
const editorState = this._editorView.state;
|
|
384
|
+
const nextDoc = this.getDocument(nextData, editorState, nextDataType);
|
|
385
|
+
dataChanged = !nextDoc.eq(editorState.doc);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return dataChanged;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
changeContent(data: any, dataType: DataType) {
|
|
392
|
+
if (this.hasDataChanged(data, dataType)) {
|
|
393
|
+
// FS IRAD-1592 2021-11-10
|
|
394
|
+
// Release here quickly, so that update doesn't care about at this point.
|
|
395
|
+
// data changed, so update document content
|
|
396
|
+
setTimeout(this.setContent.bind(this, data, dataType), 1);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
shouldComponentUpdate(nextProps: any, nextState: any) {
|
|
401
|
+
// Only interested if properties are set from outside.
|
|
402
|
+
if (!this._skipSCU) {
|
|
403
|
+
this._skipSCU = false;
|
|
404
|
+
|
|
405
|
+
this.changeContent(nextState.data, nextState.dataType);
|
|
406
|
+
|
|
407
|
+
if (this.state.docID !== nextState.docID) {
|
|
408
|
+
setTimeout(this.setDocID.bind(this, nextState), 1);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
this.skipDataTypeCheck = true;
|
|
413
|
+
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
setDocID(nextState: any) {
|
|
418
|
+
// Collaborative mode changed
|
|
419
|
+
const collabEditing = nextState.docID !== '';
|
|
420
|
+
const editorState = this._editorView.state;
|
|
421
|
+
const setState = this.setState.bind(this);
|
|
422
|
+
const docID = nextState.docID || '';
|
|
423
|
+
const collabServiceURL =
|
|
424
|
+
nextState.collabServiceURL || '/collaboration-service';
|
|
425
|
+
|
|
426
|
+
if (this._connector) {
|
|
427
|
+
this._connector.cleanUp();
|
|
428
|
+
}
|
|
429
|
+
// create new connector
|
|
430
|
+
this._connector = collabEditing
|
|
431
|
+
? new CollabConnector(
|
|
432
|
+
editorState,
|
|
433
|
+
setState,
|
|
434
|
+
{
|
|
435
|
+
docID,
|
|
436
|
+
collabServiceURL,
|
|
437
|
+
},
|
|
438
|
+
this._defaultEditorSchema,
|
|
439
|
+
this._defaultEditorPlugins,
|
|
440
|
+
// [FS] IRAD-1578 2021-09-27
|
|
441
|
+
this.onReady.bind(this)
|
|
442
|
+
)
|
|
443
|
+
: new SimpleConnector(editorState, setState);
|
|
444
|
+
|
|
445
|
+
// FS IRAD-1592 2021-11-10
|
|
446
|
+
// Notify collab server
|
|
447
|
+
if (this._connector.updateSchema) {
|
|
448
|
+
// Use known editorState to update schema.
|
|
449
|
+
this._connector.updateSchema(editorState.schema);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
render(): React.Element<any> {
|
|
454
|
+
const {
|
|
455
|
+
editorState,
|
|
456
|
+
width,
|
|
457
|
+
height,
|
|
458
|
+
readOnly,
|
|
459
|
+
disabled,
|
|
460
|
+
embedded,
|
|
461
|
+
runtime,
|
|
462
|
+
} = this.state;
|
|
463
|
+
// [FS] IRAD-978 2020-06-05
|
|
464
|
+
// Using 100vw & 100vh (100% viewport) is not ideal for a component which is expected to be a part of a page,
|
|
465
|
+
// so changing it to 100% width & height which will occupy the area relative to its parent.
|
|
466
|
+
return (
|
|
467
|
+
<RichTextEditor
|
|
468
|
+
disabled={disabled}
|
|
469
|
+
editorState={editorState}
|
|
470
|
+
embedded={embedded}
|
|
471
|
+
height={height}
|
|
472
|
+
onChange={this._onChange}
|
|
473
|
+
onReady={this._onReady}
|
|
474
|
+
readOnly={readOnly}
|
|
475
|
+
runtime={runtime}
|
|
476
|
+
width={width}
|
|
477
|
+
/>
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
_onChange = (data: { state: EditorState, transaction: Transform }): void => {
|
|
482
|
+
const { transaction } = data;
|
|
483
|
+
|
|
484
|
+
/*
|
|
485
|
+
** ProseMirror Debug Tool's Snapshot creates a new state and sets that to editor view's state.
|
|
486
|
+
** This results in the connector's state as an orphan and thus transaction mismatch error.
|
|
487
|
+
** To resolve check and update the connector's state to keep in sync.
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
if (this._editorView) {
|
|
491
|
+
const isSameState =
|
|
492
|
+
this._connector._editorState == this._editorView.state;
|
|
493
|
+
let invokeOnEdit = false;
|
|
494
|
+
|
|
495
|
+
if (!isSameState) {
|
|
496
|
+
this._connector._editorState = this._editorView.state;
|
|
497
|
+
invokeOnEdit = true;
|
|
498
|
+
} else {
|
|
499
|
+
// [FS] IRAD-1264 2021-03-19
|
|
500
|
+
// check if in non-collab mode.
|
|
501
|
+
if (!(this._connector instanceof CollabConnector)) {
|
|
502
|
+
invokeOnEdit = true;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (invokeOnEdit) {
|
|
506
|
+
// [FS] IRAD-1236 2020-03-05
|
|
507
|
+
// Only need to call if there is any difference in collab mode OR always in non-collab mode.
|
|
508
|
+
this._connector.onEdit(transaction, this._editorView);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (transaction.docChanged || (!isSameState && !transaction.getMeta('suppressOnChange'))) {
|
|
512
|
+
const docJson = this._editorView?.state?.doc?.toJSON();
|
|
513
|
+
if (!Object.isFrozen(docJson?.attrs?.objectMetaData)) {
|
|
514
|
+
docJson.attrs.objectMetaData = {
|
|
515
|
+
...docJson.attrs.objectMetaData,
|
|
516
|
+
lastEditedOn: new Date().toISOString().replace('Z', '+00:00')
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
}
|
|
520
|
+
let isEmpty = false;
|
|
521
|
+
if (docJson.content && docJson.content.length === 1) {
|
|
522
|
+
if (
|
|
523
|
+
!docJson.content[0].content ||
|
|
524
|
+
(docJson.content?.[0]?.content?.[0]?.text &&
|
|
525
|
+
'' === docJson.content?.[0]?.content?.[0]?.text.trim())
|
|
526
|
+
) {
|
|
527
|
+
isEmpty = true;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// setCFlags is/was always the opposite of isEmpty.
|
|
532
|
+
if (isEmpty) {
|
|
533
|
+
this.resetCounters(transaction);
|
|
534
|
+
} else {
|
|
535
|
+
this.setCounterFlags(transaction, false);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Changing 2nd parameter from boolean to object was not in any way
|
|
539
|
+
// backwards compatible. Any conditional logic placed on isEmpty was
|
|
540
|
+
// broken. Reverting that change, then adding view as a 3rd parameter.
|
|
541
|
+
this.state.onChangeCB(docJson, isEmpty, this._editorView);
|
|
542
|
+
|
|
543
|
+
this.closeOpenedPopupModels();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
// [FS] IRAD-1173 2021-02-25
|
|
548
|
+
// Bug fix: Transaction mismatch error when a dialog is opened and keep typing.
|
|
549
|
+
closeOpenedPopupModels() {
|
|
550
|
+
const element = document.getElementsByClassName('czi-pop-up-element')[0];
|
|
551
|
+
if (element?.parentElement) {
|
|
552
|
+
element.parentElement.removeChild(element);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
_onReady = (editorView: EditorView): void => {
|
|
557
|
+
// [FS][06-APR-2020][IRAD-922]
|
|
558
|
+
// Showing focus in the editor.
|
|
559
|
+
const { state, dispatch } = editorView;
|
|
560
|
+
this._editorView = editorView;
|
|
561
|
+
const tr = state.tr;
|
|
562
|
+
dispatch(tr.scrollIntoView());
|
|
563
|
+
if (!this._editorView.editable) {
|
|
564
|
+
let _tr = this._editorView.state.tr;
|
|
565
|
+
let modified = false;
|
|
566
|
+
this._editorView.state.doc.descendants((node, pos) => {
|
|
567
|
+
if (node.type.name === 'table') {
|
|
568
|
+
// Apply setNodeMarkup with same type and attrs to force a refresh
|
|
569
|
+
_tr = _tr?.setNodeMarkup(pos, undefined, { ...node.attrs, Id: pos });
|
|
570
|
+
modified = true;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
if (modified) {
|
|
574
|
+
this._editorView.dispatch(_tr);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
// [FS] IRAD-1578 2021-09-27
|
|
578
|
+
// In collab mode, fire onRead only after getting the response from collab server.
|
|
579
|
+
if (this.state.onReadyCB && this.state.docID === '') {
|
|
580
|
+
editorView.focus();
|
|
581
|
+
this.state.onReadyCB(this);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* LICIT properties:
|
|
587
|
+
* docID {number} [0] Collaborative Doument ID
|
|
588
|
+
* debug {boolean} [false] To enable/disable ProseMirror Debug Tools, available only in development.
|
|
589
|
+
* width {string} [100%] Width of the editor.
|
|
590
|
+
* height {height} [100%] Height of the editor.
|
|
591
|
+
* readOnly {boolean} [false] To enable/disable editing mode.
|
|
592
|
+
* onChange {@callback} [null] Fires after each significant change.
|
|
593
|
+
* @param data {JSON} Modified document data.
|
|
594
|
+
* onReady {@callback} [null] Fires when the editor is fully ready.
|
|
595
|
+
* @param ref {LICIT} Rerefence of the editor.
|
|
596
|
+
* data {JSON} [null] Document data to be loaded into the editor.
|
|
597
|
+
* disabled {boolean} [false] Disable the editor.
|
|
598
|
+
* embedded {boolean} [false] Disable/Enable inline behaviour.
|
|
599
|
+
*/
|
|
600
|
+
setProps = (props: any): void => {
|
|
601
|
+
if (this.state.readOnly) {
|
|
602
|
+
// It should be possible to load content into the editor in readonly as well.
|
|
603
|
+
// It should not be necessary to make the component writable any time during the process
|
|
604
|
+
const propsCopy = {};
|
|
605
|
+
this._skipSCU = true;
|
|
606
|
+
Object.assign(propsCopy, props);
|
|
607
|
+
// make writable without content change
|
|
608
|
+
propsCopy.readOnly = false;
|
|
609
|
+
delete propsCopy.data;
|
|
610
|
+
this.setState(propsCopy);
|
|
611
|
+
}
|
|
612
|
+
this.skipDataTypeCheck = false;
|
|
613
|
+
// Need to go through shouldComponentUpdate lifecycle here, when updated from outside,
|
|
614
|
+
// so that content is modified gracefully using transaction so that undo/redo works too.
|
|
615
|
+
this._skipSCU = false;
|
|
616
|
+
this.setState(props);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
goToEnd = (): void => {
|
|
620
|
+
// Return focus to the editor with cursor at end of document.
|
|
621
|
+
const view: EditorView = this.editorView;
|
|
622
|
+
const tr = view.state.tr;
|
|
623
|
+
view.dispatch(
|
|
624
|
+
tr.setSelection(TextSelection.atEnd(view.state.doc)).scrollIntoView()
|
|
625
|
+
);
|
|
626
|
+
view.focus();
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Method to open page layout
|
|
631
|
+
*/
|
|
632
|
+
pageLayout = (): void => {
|
|
633
|
+
const DOC_LAYOUT = new DocLayoutCommand();
|
|
634
|
+
DOC_LAYOUT.waitForUserInput(
|
|
635
|
+
this._editorView.state,
|
|
636
|
+
this._editorView.dispatch,
|
|
637
|
+
this._editorView
|
|
638
|
+
).then((inputs) => {
|
|
639
|
+
DOC_LAYOUT.executeWithUserInput(
|
|
640
|
+
this._editorView.state,
|
|
641
|
+
this._editorView.dispatch,
|
|
642
|
+
this._editorView,
|
|
643
|
+
inputs
|
|
644
|
+
);
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
export default Licit;
|