@modusoperandi/licit 0.13.3 → 0.13.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.eslintrc.js +59 -55
  2. package/README.md +15 -1
  3. package/dist/bom.xml +5177 -8773
  4. package/dist/client/EditorConnection.js +2 -2
  5. package/dist/client/EditorConnection.js.flow +3 -3
  6. package/dist/client/Licit.js +63 -15
  7. package/dist/client/Licit.js.flow +81 -35
  8. package/dist/client/Licit.test.js +29 -2
  9. package/dist/client/Licit.test.js.flow +33 -2
  10. package/dist/client/http.js +12 -0
  11. package/dist/client/http.js.flow +4 -0
  12. package/dist/convertFromDOMElement.js.flow +2 -2
  13. package/dist/convertFromHTML.js +1 -4
  14. package/dist/convertFromHTML.js.flow +3 -5
  15. package/dist/convertFromJSON.js +12 -28
  16. package/dist/convertFromJSON.js.flow +9 -31
  17. package/dist/createEmptyEditorState.js +3 -6
  18. package/dist/createEmptyEditorState.js.flow +4 -8
  19. package/dist/index.js +11 -1
  20. package/dist/index.js.flow +1 -1
  21. package/dist/patchStyleElements.js +1 -3
  22. package/dist/patchStyleElements.js.flow +2 -2
  23. package/dist/ui/czi-link-tooltip.css +1 -1
  24. package/dist/ui/czi-vars.css +1 -1
  25. package/licit/client/index.js +2 -1
  26. package/licit/server/collab/instance.js +11 -8
  27. package/licit/server/collab/server.js +6 -6
  28. package/package.json +3 -8
  29. package/src/client/EditorConnection.js +3 -3
  30. package/src/client/Licit.js +81 -35
  31. package/src/client/Licit.test.js +33 -2
  32. package/src/client/http.js +4 -0
  33. package/src/convertFromDOMElement.js +2 -2
  34. package/src/convertFromHTML.js +3 -5
  35. package/src/convertFromJSON.js +9 -31
  36. package/src/createEmptyEditorState.js +4 -8
  37. package/src/index.js +1 -1
  38. package/src/patchStyleElements.js +2 -2
  39. package/src/ui/czi-link-tooltip.css +1 -1
  40. package/src/ui/czi-vars.css +1 -1
  41. package/node_modules/prosemirror-utils/LICENSE +0 -13
  42. package/node_modules/prosemirror-utils/README.md +0 -0
  43. package/node_modules/prosemirror-utils/dist/helpers.js +0 -119
  44. package/node_modules/prosemirror-utils/dist/index.js +0 -17
  45. package/node_modules/prosemirror-utils/dist/index.js.map +0 -1
  46. package/node_modules/prosemirror-utils/dist/node.js +0 -106
  47. package/node_modules/prosemirror-utils/dist/selection.js +0 -168
  48. package/node_modules/prosemirror-utils/dist/transforms.js +0 -257
  49. package/node_modules/prosemirror-utils/package.json +0 -81
  50. package/node_modules/prosemirror-utils/typings.d.ts +0 -79
@@ -158,8 +158,8 @@ class EditorConnection {
158
158
  } // Load the document from the server and start up
159
159
 
160
160
 
161
- start() {
162
- this.run((0, _http.GET)(this.url)).then(data => {
161
+ start(input) {
162
+ this.run((0, _http.PUT)(this.url, JSON.stringify(input), 'application/json')).then(data => {
163
163
  data = JSON.parse(data);
164
164
  this.report.success();
165
165
  this.backOff = 0;
@@ -10,7 +10,7 @@ import { Plugin, EditorState } from 'prosemirror-state';
10
10
  import { Step } from 'prosemirror-transform';
11
11
  import { EditorView } from 'prosemirror-view';
12
12
  import uuid from '../uuid';
13
- import { GET, POST } from './http';
13
+ import { GET, POST, PUT } from './http';
14
14
  // [FS] IRAD-1040 2020-09-02
15
15
  import { Schema } from 'prosemirror-model';
16
16
  import { stringify } from 'flatted';
@@ -144,8 +144,8 @@ class EditorConnection {
144
144
  }
145
145
 
146
146
  // Load the document from the server and start up
147
- start(): void {
148
- this.run(GET(this.url)).then(
147
+ start(input: any): void {
148
+ this.run(PUT(this.url, JSON.stringify(input), 'application/json')).then(
149
149
  (data) => {
150
150
  data = JSON.parse(data);
151
151
  this.report.success();
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.DataType = void 0;
7
7
 
8
8
  var _prosemirrorState = require("prosemirror-state");
9
9
 
@@ -45,6 +45,8 @@ var _EditorMarks = _interopRequireDefault(require("../EditorMarks"));
45
45
 
46
46
  var _EditorNodes = _interopRequireDefault(require("../EditorNodes"));
47
47
 
48
+ var _convertFromHTML = _interopRequireDefault(require("../convertFromHTML"));
49
+
48
50
  var _Types = require("../Types");
49
51
 
50
52
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -55,8 +57,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
55
57
 
56
58
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
57
59
 
58
- const ATTR_OBJID = 'objectId';
59
- const ATTR_OBJMETADATA = 'objectMetaData';
60
+ const DataType = Object.freeze({
61
+ JSON: Symbol('json'),
62
+ HTML: Symbol('html')
63
+ });
60
64
  /**
61
65
  * LICIT properties:
62
66
  * docID {string} [] Collaborative Doument ID
@@ -69,12 +73,15 @@ const ATTR_OBJMETADATA = 'objectMetaData';
69
73
  * @param data {JSON} Modified document data.
70
74
  * onReady {@callback} [null] Fires when the editor is fully ready.
71
75
  * @param ref {LICIT} Rerefence of the editor.
72
- * data {JSON} [null] Document data to be loaded into the editor.
76
+ * data {JSON|HTML} [null] Document data to be loaded into the editor.
77
+ * dataType {JSON|HTML} [JSON] Document data to be loaded into the editor.
73
78
  * disabled {boolean} [false] Disable the editor.
74
79
  * embedded {boolean} [false] Disable/Enable inline behaviour.
75
80
  * plugins [plugins] External Plugins into the editor.
76
81
  */
77
82
 
83
+ exports.DataType = DataType;
84
+
78
85
  class Licit extends React.Component {
79
86
  // This will be handy in updating document's content.
80
87
  // Flag to decide whether to skip shouldComponentUpdate
@@ -133,9 +140,11 @@ class Licit extends React.Component {
133
140
 
134
141
  tr = tr.setSelection(selection).replaceSelectionWith(document, false); // [FS] IRAD-1092 2020-12-03
135
142
  // set the value for object metadata and objectId
143
+ // Should update all document attributes.
136
144
 
137
- tr = _this.isNodeHasAttribute(document, ATTR_OBJMETADATA) ? tr.step(new _licitDocAttrsStep.SetDocAttrStep(ATTR_OBJMETADATA, document.attrs.objectMetaData)) : tr;
138
- tr = _this.isNodeHasAttribute(document, ATTR_OBJID) ? tr.step(new _licitDocAttrsStep.SetDocAttrStep(ATTR_OBJID, document.attrs.objectId)) : tr;
145
+ Object.keys(document.attrs).forEach(attr => {
146
+ tr = tr.step(new _licitDocAttrsStep.SetDocAttrStep(attr, document.attrs[attr]));
147
+ });
139
148
  _this._skipSCU = true;
140
149
 
141
150
  _this._editorView.dispatch(tr);
@@ -278,7 +287,8 @@ class Licit extends React.Component {
278
287
  const onChangeCB = typeof props.onChange === 'function' ? props.onChange : noop;
279
288
  const onReadyCB = typeof props.onReady === 'function' ? props.onReady : noop;
280
289
  const readOnly = props.readOnly || false;
281
- const data = props.data || null;
290
+ let data = props.data || null;
291
+ const dataType = props.dataType || DataType.JSON;
282
292
  const disabled = props.disabled || false;
283
293
  const embedded = props.embedded || false; // [FS] IRAD-996 2020-06-30
284
294
  // [FS] 2020-07-03
@@ -291,14 +301,8 @@ class Licit extends React.Component {
291
301
  marks: _EditorMarks.default
292
302
  });
293
303
  this._defaultEditorPlugins = new _buildEditorPlugins.default(this._defaultEditorSchema).get();
294
- let editorState = (0, _convertFromJSON.default)(data, null, this._defaultEditorSchema, plugins, this._defaultEditorPlugins); // [FS] IRAD-1067 2020-09-19
295
- // The editorState will return null if the doc Json is mal-formed
296
-
297
- if (null === editorState) {
298
- editorState = (0, _convertFromJSON.default)(_createEmptyEditorState.EMPTY_DOC_JSON, null, this._defaultEditorSchema, plugins, this._defaultEditorPlugins);
299
- this.showAlert();
300
- }
301
-
304
+ const editorState = this.initEditorState(plugins, dataType, data);
305
+ data = editorState.doc;
302
306
  const setState = this.setState.bind(this);
303
307
  this._connector = collaborative ? new _CollabConnector.default(editorState, setState, {
304
308
  docID,
@@ -328,6 +332,50 @@ class Licit extends React.Component {
328
332
  // Use known editorState to update schema.
329
333
  this._connector.updateSchema(editorState.schema, data);
330
334
  }
335
+ }
336
+
337
+ initEditorState(plugins, dataType, data) {
338
+ let editorState = null;
339
+ const effectivePlugins = this.getEffectivePlugins(this._defaultEditorSchema, this._defaultEditorPlugins, plugins);
340
+
341
+ if (DataType.JSON === dataType) {
342
+ editorState = (0, _convertFromJSON.default)(data, null, effectivePlugins.schema, effectivePlugins.plugins); // [FS] IRAD-1067 2020-09-19
343
+ // The editorState will return null if the doc Json is mal-formed
344
+
345
+ if (null === editorState) {
346
+ editorState = (0, _convertFromJSON.default)(_createEmptyEditorState.EMPTY_DOC_JSON, null, effectivePlugins.schema, effectivePlugins.plugins);
347
+ this.showAlert();
348
+ }
349
+ } else {
350
+ editorState = (0, _convertFromHTML.default)(data, effectivePlugins.schema, effectivePlugins.plugins);
351
+ }
352
+
353
+ return editorState;
354
+ }
355
+
356
+ getEffectivePlugins(schema, defaultPlugins, plugins) {
357
+ const effectivePlugins = defaultPlugins;
358
+
359
+ if (plugins) {
360
+ for (const p of plugins) {
361
+ if (!effectivePlugins.includes(p)) {
362
+ effectivePlugins.push(p);
363
+
364
+ if (p.getEffectiveSchema) {
365
+ schema = p.getEffectiveSchema(schema);
366
+ }
367
+
368
+ if (p.initKeyCommands) {
369
+ effectivePlugins.push(p.initKeyCommands());
370
+ }
371
+ }
372
+ }
373
+ }
374
+
375
+ return {
376
+ plugins: effectivePlugins,
377
+ schema
378
+ };
331
379
  } // [FS] IRAD-1578 2021-09-27
332
380
 
333
381
 
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import { EditorState, TextSelection, Plugin } from 'prosemirror-state';
3
- import { Node } from 'prosemirror-model';
3
+ import { Node, Schema } from 'prosemirror-model';
4
4
  import { Transform } from 'prosemirror-transform';
5
5
  import { EditorView } from 'prosemirror-view';
6
6
  import * as React from 'react';
@@ -14,18 +14,23 @@ import SimpleConnector from './SimpleConnector';
14
14
  import CollabConnector from './CollabConnector';
15
15
  import { EMPTY_DOC_JSON } from '../createEmptyEditorState';
16
16
  import type { EditorRuntime } from '../Types';
17
- import { createPopUp } from '@modusoperandi/licit-ui-commands';
18
- import { atViewportCenter } from '@modusoperandi/licit-ui-commands';
17
+ import {
18
+ createPopUp,
19
+ atViewportCenter,
20
+ } from '@modusoperandi/licit-ui-commands';
19
21
  import AlertInfo from '../ui/AlertInfo';
20
22
  import { SetDocAttrStep } from '@modusoperandi/licit-doc-attrs-step';
21
23
  import './licit.css';
22
24
  import DefaultEditorPlugins from '../buildEditorPlugins';
23
- import { Schema } from 'prosemirror-model';
24
25
  import EditorMarks from '../EditorMarks';
25
26
  import EditorNodes from '../EditorNodes';
27
+ import convertFromHTML from '../convertFromHTML';
28
+
29
+ export const DataType = Object.freeze({
30
+ JSON: Symbol('json'),
31
+ HTML: Symbol('html'),
32
+ });
26
33
 
27
- const ATTR_OBJID = 'objectId';
28
- const ATTR_OBJMETADATA = 'objectMetaData';
29
34
  /**
30
35
  * LICIT properties:
31
36
  * docID {string} [] Collaborative Doument ID
@@ -38,7 +43,8 @@ const ATTR_OBJMETADATA = 'objectMetaData';
38
43
  * @param data {JSON} Modified document data.
39
44
  * onReady {@callback} [null] Fires when the editor is fully ready.
40
45
  * @param ref {LICIT} Rerefence of the editor.
41
- * data {JSON} [null] Document data to be loaded into the editor.
46
+ * data {JSON|HTML} [null] Document data to be loaded into the editor.
47
+ * dataType {JSON|HTML} [JSON] Document data to be loaded into the editor.
42
48
  * disabled {boolean} [false] Disable the editor.
43
49
  * embedded {boolean} [false] Disable/Enable inline behaviour.
44
50
  * plugins [plugins] External Plugins into the editor.
@@ -93,7 +99,8 @@ class Licit extends React.Component<any, any> {
93
99
  const onReadyCB =
94
100
  typeof props.onReady === 'function' ? props.onReady : noop;
95
101
  const readOnly = props.readOnly || false;
96
- const data = props.data || null;
102
+ let data = props.data || null;
103
+ const dataType = props.dataType || DataType.JSON;
97
104
  const disabled = props.disabled || false;
98
105
  const embedded = props.embedded || false; // [FS] IRAD-996 2020-06-30
99
106
  // [FS] 2020-07-03
@@ -109,25 +116,8 @@ class Licit extends React.Component<any, any> {
109
116
  this._defaultEditorSchema
110
117
  ).get();
111
118
 
112
- let editorState = convertFromJSON(
113
- data,
114
- null,
115
- this._defaultEditorSchema,
116
- plugins,
117
- this._defaultEditorPlugins
118
- );
119
- // [FS] IRAD-1067 2020-09-19
120
- // The editorState will return null if the doc Json is mal-formed
121
- if (null === editorState) {
122
- editorState = convertFromJSON(
123
- EMPTY_DOC_JSON,
124
- null,
125
- this._defaultEditorSchema,
126
- plugins,
127
- this._defaultEditorPlugins
128
- );
129
- this.showAlert();
130
- }
119
+ const editorState = this.initEditorState(plugins, dataType, data);
120
+ data = editorState.doc;
131
121
 
132
122
  const setState = this.setState.bind(this);
133
123
  this._connector = collaborative
@@ -172,6 +162,66 @@ class Licit extends React.Component<any, any> {
172
162
  }
173
163
  }
174
164
 
165
+ initEditorState(plugins: Array<Plugin>, dataType: DataType, data: any) {
166
+ let editorState = null;
167
+ const effectivePlugins = this.getEffectivePlugins(
168
+ this._defaultEditorSchema,
169
+ this._defaultEditorPlugins,
170
+ plugins
171
+ );
172
+ if (DataType.JSON === dataType) {
173
+ editorState = convertFromJSON(
174
+ data,
175
+ null,
176
+ effectivePlugins.schema,
177
+ effectivePlugins.plugins
178
+ );
179
+ // [FS] IRAD-1067 2020-09-19
180
+ // The editorState will return null if the doc Json is mal-formed
181
+ if (null === editorState) {
182
+ editorState = convertFromJSON(
183
+ EMPTY_DOC_JSON,
184
+ null,
185
+ effectivePlugins.schema,
186
+ effectivePlugins.plugins
187
+ );
188
+ this.showAlert();
189
+ }
190
+ } else {
191
+ editorState = convertFromHTML(
192
+ data,
193
+ effectivePlugins.schema,
194
+ effectivePlugins.plugins
195
+ );
196
+ }
197
+
198
+ return editorState;
199
+ }
200
+
201
+ getEffectivePlugins(
202
+ schema: Schema,
203
+ defaultPlugins: Array<Plugin>,
204
+ plugins: Array<Plugin>
205
+ ): { plugins: Array<Plugin>, schema: Schema } {
206
+ const effectivePlugins = defaultPlugins;
207
+
208
+ if (plugins) {
209
+ for (const p of plugins) {
210
+ if (!effectivePlugins.includes(p)) {
211
+ effectivePlugins.push(p);
212
+ if (p.getEffectiveSchema) {
213
+ schema = p.getEffectiveSchema(schema);
214
+ }
215
+
216
+ if (p.initKeyCommands) {
217
+ effectivePlugins.push(p.initKeyCommands());
218
+ }
219
+ }
220
+ }
221
+ }
222
+ return { plugins: effectivePlugins, schema };
223
+ }
224
+
175
225
  // [FS] IRAD-1578 2021-09-27
176
226
  onReady(state: EditorState) {
177
227
  const collabEditing = this.state.docID !== '';
@@ -280,14 +330,10 @@ class Licit extends React.Component<any, any> {
280
330
  tr = tr.setSelection(selection).replaceSelectionWith(document, false);
281
331
  // [FS] IRAD-1092 2020-12-03
282
332
  // set the value for object metadata and objectId
283
- tr = this.isNodeHasAttribute(document, ATTR_OBJMETADATA)
284
- ? tr.step(
285
- new SetDocAttrStep(ATTR_OBJMETADATA, document.attrs.objectMetaData)
286
- )
287
- : tr;
288
- tr = this.isNodeHasAttribute(document, ATTR_OBJID)
289
- ? tr.step(new SetDocAttrStep(ATTR_OBJID, document.attrs.objectId))
290
- : tr;
333
+ // Should update all document attributes.
334
+ Object.keys(document.attrs).forEach((attr) => {
335
+ tr = tr.step(new SetDocAttrStep(attr, document.attrs[attr]));
336
+ });
291
337
 
292
338
  this._skipSCU = true;
293
339
  this._editorView.dispatch(tr);
@@ -6,12 +6,16 @@ var _enzyme = require("enzyme");
6
6
 
7
7
  var _enzymeAdapterReact = _interopRequireDefault(require("@wojtekmaj/enzyme-adapter-react-17"));
8
8
 
9
- var _Licit = _interopRequireDefault(require("./Licit"));
9
+ var _Licit = _interopRequireWildcard(require("./Licit"));
10
10
 
11
11
  var _RichTextEditor = _interopRequireDefault(require("../ui/RichTextEditor"));
12
12
 
13
13
  var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
14
14
 
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+
15
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
20
 
17
21
  /**
@@ -45,7 +49,10 @@ describe('<Licit />', () => {
45
49
  },
46
50
  resolve: () => ({
47
51
  min: () => 0,
48
- max: () => 10
52
+ max: () => 10,
53
+ parent: {
54
+ inlineContent: true
55
+ }
49
56
  }),
50
57
  toJSON: () => data
51
58
  },
@@ -75,4 +82,24 @@ describe('<Licit />', () => {
75
82
  expect(licit.editorView).toBe(fakeEditorView);
76
83
  });
77
84
  });
85
+ });
86
+ describe('<Licit with HTML input/>', () => {
87
+ let wrapper;
88
+ let licit;
89
+ const HELLO = 'Hello ';
90
+ const WORLD = 'World';
91
+ const data = '<p stylename="None">' + HELLO + '<strong overridden="false">' + WORLD + '</strong></p>';
92
+ beforeEach(() => {
93
+ wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Licit.default, {
94
+ data: data,
95
+ dataType: _Licit.DataType.HTML
96
+ }));
97
+ licit = wrapper.instance();
98
+ });
99
+ it('should render a <RichTextEditor /> ', () => {
100
+ expect(wrapper.find(_RichTextEditor.default)).toBeTruthy();
101
+ });
102
+ it('should match state text content with the passed in text ', () => {
103
+ expect(licit.state.editorState.doc.textContent).toBe(HELLO + WORLD);
104
+ });
78
105
  });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { configure, shallow } from 'enzyme';
3
3
  import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
4
- import Licit from './Licit';
4
+ import Licit, { DataType } from './Licit';
5
5
  import RichTextEditor from '../ui/RichTextEditor';
6
6
  import { noop } from '@modusoperandi/licit-ui-commands';
7
7
 
@@ -34,7 +34,11 @@ describe('<Licit />', () => {
34
34
  state: {
35
35
  doc: {
36
36
  content: { size: 10 },
37
- resolve: () => ({ min: () => 0, max: () => 10 }),
37
+ resolve: () => ({
38
+ min: () => 0,
39
+ max: () => 10,
40
+ parent: { inlineContent: true },
41
+ }),
38
42
  toJSON: () => data,
39
43
  },
40
44
  tr: {
@@ -65,3 +69,30 @@ describe('<Licit />', () => {
65
69
  });
66
70
  });
67
71
  });
72
+
73
+ describe('<Licit with HTML input/>', () => {
74
+ let wrapper;
75
+ let licit;
76
+
77
+ const HELLO = 'Hello ';
78
+ const WORLD = 'World';
79
+ const data =
80
+ '<p stylename="None">' +
81
+ HELLO +
82
+ '<strong overridden="false">' +
83
+ WORLD +
84
+ '</strong></p>';
85
+
86
+ beforeEach(() => {
87
+ wrapper = shallow(<Licit data={data} dataType={DataType.HTML} />);
88
+ licit = wrapper.instance();
89
+ });
90
+
91
+ it('should render a <RichTextEditor /> ', () => {
92
+ expect(wrapper.find(RichTextEditor)).toBeTruthy();
93
+ });
94
+
95
+ it('should match state text content with the passed in text ', () => {
96
+ expect(licit.state.editorState.doc.textContent).toBe(HELLO + WORLD);
97
+ });
98
+ });
@@ -7,6 +7,7 @@ exports.DELETE = DELETE;
7
7
  exports.GET = GET;
8
8
  exports.PATCH = PATCH;
9
9
  exports.POST = POST;
10
+ exports.PUT = PUT;
10
11
  exports.req = req;
11
12
 
12
13
  /* eslint-disable */
@@ -68,6 +69,17 @@ function POST(url, body, type) {
68
69
  'Content-Type': type
69
70
  }
70
71
  });
72
+ }
73
+
74
+ function PUT(url, body, type) {
75
+ return req({
76
+ url,
77
+ method: 'PUT',
78
+ body,
79
+ headers: {
80
+ 'Content-Type': type
81
+ }
82
+ });
71
83
  } // [FS] IRAD-1128 2021-02-03
72
84
  // http DELETE request overrided
73
85
 
@@ -53,6 +53,10 @@ export function POST(url, body, type) {
53
53
  return req({ url, method: 'POST', body, headers: { 'Content-Type': type } });
54
54
  }
55
55
 
56
+ export function PUT(url, body, type) {
57
+ return req({ url, method: 'PUT', body, headers: { 'Content-Type': type } });
58
+ }
59
+
56
60
  // [FS] IRAD-1128 2021-02-03
57
61
  // http DELETE request overrided
58
62
  export function DELETE(url, type) {
@@ -11,8 +11,8 @@ import EditorSchema from './EditorSchema';
11
11
 
12
12
  export default function convertFromDOMElement(
13
13
  el: HTMLElement,
14
- schema: ?Schema,
15
- plugins: ?Array<Plugin>
14
+ schema: Schema,
15
+ plugins: Array<Plugin>
16
16
  ): EditorState {
17
17
  const effectiveSchema = schema || EditorSchema;
18
18
  const effectivePlugins = plugins || EditorPlugins;
@@ -11,13 +11,10 @@ var _prosemirrorState = require("prosemirror-state");
11
11
 
12
12
  var _convertFromDOMElement = _interopRequireDefault(require("./convertFromDOMElement"));
13
13
 
14
- var _normalizeHTML = _interopRequireDefault(require("./normalizeHTML"));
15
-
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
16
  function convertFromHTML(html, schema, plugins) {
19
17
  const root = document.createElement('html');
20
- const newHTML = (0, _normalizeHTML.default)(html);
21
- root.innerHTML = newHTML;
18
+ root.innerHTML = html;
22
19
  return (0, _convertFromDOMElement.default)(root, schema, plugins);
23
20
  }
@@ -5,15 +5,13 @@ import { EditorState } from 'prosemirror-state';
5
5
  import { Plugin } from 'prosemirror-state';
6
6
 
7
7
  import convertFromDOMElement from './convertFromDOMElement';
8
- import normalizeHTML from './normalizeHTML';
9
8
 
10
9
  export default function convertFromHTML(
11
10
  html: string,
12
- schema: ?Schema,
13
- plugins: ?Array<Plugin>
11
+ schema: Schema,
12
+ plugins: Array<Plugin>
14
13
  ): EditorState {
15
14
  const root = document.createElement('html');
16
- const newHTML = normalizeHTML(html);
17
- root.innerHTML = newHTML;
15
+ root.innerHTML = html;
18
16
  return convertFromDOMElement(root, schema, plugins);
19
17
  }
@@ -13,44 +13,28 @@ var _createEmptyEditorState = _interopRequireDefault(require("./createEmptyEdito
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function convertFromJSON(json, schema, defaultSchema, plugins, defaultPlugins) {
17
- let editorSchema = schema || defaultSchema; // [FS][IRAD-???? 2020-08-17]
18
- // Loads plugins and its corresponding schema in editor
19
-
20
- const effectivePlugins = defaultPlugins;
21
-
22
- if (plugins) {
23
- for (const p of plugins) {
24
- if (!effectivePlugins.includes(p)) {
25
- effectivePlugins.push(p);
26
-
27
- if (p.getEffectiveSchema) {
28
- editorSchema = p.getEffectiveSchema(editorSchema);
29
- }
30
-
31
- if (p.initKeyCommands) {
32
- effectivePlugins.push(p.initKeyCommands());
33
- }
34
- }
35
- }
36
- }
16
+ function convertFromJSON(json, schema, defaultSchema, effectivePlugins) {
17
+ const editorSchema = schema || defaultSchema;
18
+ let error = false;
37
19
 
38
20
  if (typeof json === 'string') {
39
21
  try {
40
22
  json = JSON.parse(json);
41
23
  } catch (ex) {
42
- console.error('convertFromJSON:', ex); // [FS] IRAD-1455 2021-06-16
43
- // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
44
-
45
- return (0, _createEmptyEditorState.default)(schema, defaultSchema, plugins, defaultPlugins);
24
+ console.error('convertFromJSON:', ex);
25
+ error = true;
46
26
  }
47
27
  }
48
28
 
49
29
  if (!json || typeof json !== 'object') {
50
- console.error('convertFromJSON: invalid object', json); // [FS] IRAD-1455 2021-06-16
51
- // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
30
+ console.error('convertFromJSON: invalid object', json);
31
+ error = true;
32
+ }
52
33
 
53
- return (0, _createEmptyEditorState.default)(schema, defaultSchema, plugins, defaultPlugins);
34
+ if (error) {
35
+ // [FS] IRAD-1455 2021-06-16
36
+ // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
37
+ return (0, _createEmptyEditorState.default)(schema, defaultSchema, effectivePlugins);
54
38
  } // [FS] IRAD-1067 2020-09-19
55
39
  // Handle gracefully when error thrown on invalid json
56
40
 
@@ -9,54 +9,32 @@ export default function convertFromJSON(
9
9
  json: Object | string,
10
10
  schema: ?Schema,
11
11
  defaultSchema: Schema,
12
- plugins: ?Array<Plugin>,
13
- defaultPlugins: Array<Plugin>
12
+ effectivePlugins: Array<Plugin>
14
13
  ): EditorState {
15
- let editorSchema = schema || defaultSchema;
14
+ const editorSchema = schema || defaultSchema;
15
+ let error = false;
16
16
 
17
- // [FS][IRAD-???? 2020-08-17]
18
- // Loads plugins and its corresponding schema in editor
19
- const effectivePlugins = defaultPlugins;
20
-
21
- if (plugins) {
22
- for (const p of plugins) {
23
- if (!effectivePlugins.includes(p)) {
24
- effectivePlugins.push(p);
25
- if (p.getEffectiveSchema) {
26
- editorSchema = p.getEffectiveSchema(editorSchema);
27
- }
28
-
29
- if (p.initKeyCommands) {
30
- effectivePlugins.push(p.initKeyCommands());
31
- }
32
- }
33
- }
34
- }
35
17
  if (typeof json === 'string') {
36
18
  try {
37
19
  json = JSON.parse(json);
38
20
  } catch (ex) {
39
21
  console.error('convertFromJSON:', ex);
40
- // [FS] IRAD-1455 2021-06-16
41
- // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
42
- return createEmptyEditorState(
43
- schema,
44
- defaultSchema,
45
- plugins,
46
- defaultPlugins
47
- );
22
+ error = true;
48
23
  }
49
24
  }
50
25
 
51
26
  if (!json || typeof json !== 'object') {
52
27
  console.error('convertFromJSON: invalid object', json);
28
+ error = true;
29
+ }
30
+
31
+ if(error) {
53
32
  // [FS] IRAD-1455 2021-06-16
54
33
  // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
55
34
  return createEmptyEditorState(
56
35
  schema,
57
36
  defaultSchema,
58
- plugins,
59
- defaultPlugins
37
+ effectivePlugins
60
38
  );
61
39
  }
62
40
 
@@ -10,8 +10,6 @@ var _prosemirrorModel = require("prosemirror-model");
10
10
 
11
11
  var _prosemirrorState = require("prosemirror-state");
12
12
 
13
- var _buildEditorPlugins = _interopRequireDefault(require("./buildEditorPlugins"));
14
-
15
13
  var _convertFromJSON = _interopRequireDefault(require("./convertFromJSON"));
16
14
 
17
15
  var _EditorSchema = _interopRequireDefault(require("./EditorSchema"));
@@ -27,8 +25,7 @@ const EMPTY_DOC_JSON = {
27
25
  };
28
26
  exports.EMPTY_DOC_JSON = EMPTY_DOC_JSON;
29
27
 
30
- function createEmptyEditorState(schema, defaultSchema, plugins, defaultPlugins) {
31
- const newSchema = schema || (defaultSchema ? defaultSchema : _EditorSchema.default); // TODO: Check if schema support doc and paragraph nodes.
32
-
33
- return (0, _convertFromJSON.default)(EMPTY_DOC_JSON, schema, defaultSchema ? defaultSchema : _EditorSchema.default, plugins, defaultPlugins ? defaultPlugins : new _buildEditorPlugins.default(newSchema).get());
28
+ function createEmptyEditorState(schema, defaultSchema, plugins) {
29
+ // TODO: Check if schema support doc and paragraph nodes.
30
+ return (0, _convertFromJSON.default)(EMPTY_DOC_JSON, schema, defaultSchema ? defaultSchema : _EditorSchema.default, plugins);
34
31
  }