@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
@@ -3,7 +3,6 @@
3
3
  import { Schema } from 'prosemirror-model';
4
4
  import { EditorState } from 'prosemirror-state';
5
5
  import { Plugin } from 'prosemirror-state';
6
- import DefaultEditorPlugins from './buildEditorPlugins';
7
6
 
8
7
  import convertFromJSON from './convertFromJSON';
9
8
  import EditorSchema from './EditorSchema';
@@ -12,24 +11,21 @@ export const EMPTY_DOC_JSON = {
12
11
  type: 'doc',
13
12
  content: [
14
13
  {
15
- type: 'paragraph'
16
- },// [FS] IRAD-1710 2022-03-04 - No text content needed
14
+ type: 'paragraph',
15
+ }, // [FS] IRAD-1710 2022-03-04 - No text content needed
17
16
  ],
18
17
  };
19
18
 
20
19
  export default function createEmptyEditorState(
21
20
  schema: ?Schema,
22
21
  defaultSchema: ?Schema,
23
- plugins: ?Array<Plugin>,
24
- defaultPlugins: ?Array<Plugin>
22
+ plugins: Array<Plugin>
25
23
  ): EditorState {
26
- const newSchema = schema || (defaultSchema ? defaultSchema : EditorSchema);
27
24
  // TODO: Check if schema support doc and paragraph nodes.
28
25
  return convertFromJSON(
29
26
  EMPTY_DOC_JSON,
30
27
  schema,
31
28
  defaultSchema ? defaultSchema : EditorSchema,
32
- plugins,
33
- defaultPlugins ? defaultPlugins : new DefaultEditorPlugins(newSchema).get()
29
+ plugins
34
30
  );
35
31
  }
package/dist/index.js CHANGED
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "DELETE", {
9
9
  return _http.DELETE;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "DataType", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Licit.DataType;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "EditorRuntime", {
13
19
  enumerable: true,
14
20
  get: function () {
@@ -70,10 +76,14 @@ var _isEditorStateEmpty = _interopRequireDefault(require("./isEditorStateEmpty")
70
76
 
71
77
  var _uuid = _interopRequireDefault(require("./ui/uuid"));
72
78
 
73
- var _Licit = _interopRequireDefault(require("./client/Licit.js"));
79
+ var _Licit = _interopRequireWildcard(require("./client/Licit.js"));
74
80
 
75
81
  var _Types = require("./Types");
76
82
 
77
83
  var _http = require("./client/http");
78
84
 
85
+ 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); }
86
+
87
+ 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; }
88
+
79
89
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -5,6 +5,6 @@ export { default as isEditorStateEmpty } from './isEditorStateEmpty';
5
5
  export { default as uuid } from './ui/uuid';
6
6
  // [FS] IRAD-978 2020-06-05
7
7
  // Export Licit as a component
8
- export { default as Licit } from './client/Licit.js';
8
+ export { default as Licit, DataType } from './client/Licit.js';
9
9
  export { ImageLike, EditorRuntime } from './Types';
10
10
  export { GET, POST, DELETE, PATCH } from './client/http';
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.ATTRIBUTE_CSS_BEFORE_CONTENT = void 0;
7
7
  exports.default = patchStyleElements;
8
8
 
9
- var _stable = _interopRequireDefault(require("stable"));
10
-
11
9
  var _toCSSColor = _interopRequireDefault(require("./ui/toCSSColor"));
12
10
 
13
11
  var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
@@ -99,7 +97,7 @@ function patchStyleElements(doc) {
99
97
  });
100
98
  }); // Sort selector by
101
99
 
102
- (0, _stable.default)(selectorTextToCSSTexts, sortBySpecificity).reduce(buildElementToCSSTexts.bind(null, doc), new Map()).forEach(applyInlineStyleSheetCSSTexts);
100
+ selectorTextToCSSTexts.sort(sortBySpecificity).reduce(buildElementToCSSTexts.bind(null, doc), new Map()).forEach(applyInlineStyleSheetCSSTexts);
103
101
  }
104
102
 
105
103
  function buildElementToCSSTexts(doc, elementToCSSTexts, bag) {
@@ -1,6 +1,5 @@
1
1
  // @flow
2
2
 
3
- import stable from 'stable';
4
3
  import toCSSColor from './ui/toCSSColor';
5
4
  import { toCSSLineSpacing } from '@modusoperandi/licit-ui-commands';
6
5
 
@@ -94,7 +93,8 @@ export default function patchStyleElements(doc: Document): void {
94
93
  });
95
94
 
96
95
  // Sort selector by
97
- stable(selectorTextToCSSTexts, sortBySpecificity)
96
+ selectorTextToCSSTexts
97
+ .sort(sortBySpecificity)
98
98
  .reduce(buildElementToCSSTexts.bind(null, doc), new Map<any, any>())
99
99
  .forEach(applyInlineStyleSheetCSSTexts);
100
100
  }
@@ -1,4 +1,4 @@
1
- @import '../../node_modules/@modusoperandi/licit-ui-commands/dist/ui/czi-custom-button.css';
1
+ @import '@modusoperandi/licit-ui-commands/dist/ui/czi-custom-button.css';
2
2
  @import './czi-vars.css';
3
3
 
4
4
  .czi-link-tooltip {
@@ -1,2 +1,2 @@
1
- @import '../../node_modules/@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
1
+ @import '@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
2
2
 
@@ -3,7 +3,7 @@
3
3
  import * as React from 'react';
4
4
  import ReactDOM from 'react-dom';
5
5
 
6
- import Licit from '../../src/client/Licit';
6
+ import Licit, { DataType } from '../../src/client/Licit';
7
7
  import CustomLicitRuntime from './CustomLicitRuntime';
8
8
 
9
9
  function main(): void {
@@ -341,6 +341,7 @@ function main(): void {
341
341
  <Licit
342
342
  collabServiceURL={'http://localhost:3002'}
343
343
  data={docJSON}
344
+ dataType={DataType.JSON}
344
345
  debug={true}
345
346
  docID={'0000-0000-0000-0000'}
346
347
  embedded={false}
@@ -1,9 +1,9 @@
1
1
  // @flow
2
2
 
3
- const {readFileSync, writeFile} = require('fs');
3
+ const { readFileSync, writeFile } = require('fs');
4
4
 
5
5
  // [FS] IRAD-1040 2020-09-02
6
- import {Schema} from 'prosemirror-model';
6
+ import { Schema } from 'prosemirror-model';
7
7
 
8
8
  let _editorSchema: Schema = null;
9
9
 
@@ -65,7 +65,7 @@ export class Instance {
65
65
  }
66
66
  this.sendUpdates();
67
67
  scheduleSave();
68
- return {version: this.version};
68
+ return { version: this.version };
69
69
  }
70
70
 
71
71
  sendUpdates() {
@@ -98,7 +98,7 @@ export class Instance {
98
98
 
99
99
  const steps: any[] = this.steps.slice(startIndex);
100
100
  const users = this.userCount;
101
- return {steps: steps, users: users};
101
+ return { steps: steps, users: users };
102
102
  }
103
103
 
104
104
  collectUsers() {
@@ -156,7 +156,8 @@ function scheduleSave() {
156
156
  function doSave() {
157
157
  saveTimeout = null;
158
158
  const out = {};
159
- for (const prop in instances) out[prop] = {doc: instances[prop].doc.toJSON()};
159
+ for (const prop in instances)
160
+ out[prop] = { doc: instances[prop].doc.toJSON() };
160
161
  writeFile(saveFile, JSON.stringify(out), () => {});
161
162
  }
162
163
 
@@ -182,8 +183,10 @@ export function initEditorSchema(effectiveSchema: Schema) {
182
183
  }
183
184
  }
184
185
 
185
- export function getInstance(id: any, ip: any) {
186
- const inst = instances[id] || newInstance(id);
186
+ export function getInstance(id: any, ip: any, doc: any) {
187
+ const inst =
188
+ instances[id] ||
189
+ newInstance(id, !doc ? undefined : _editorSchema.nodeFromJSON(doc));
187
190
  if (ip) inst.registerUser(ip);
188
191
  inst.lastActive = Date.now();
189
192
  return inst;
@@ -208,7 +211,7 @@ function newInstance(id: any, doc: any) {
208
211
  export function instanceInfo() {
209
212
  const found = [];
210
213
  for (const id in instances)
211
- found.push({id: id, users: instances[id].userCount});
214
+ found.push({ id: id, users: instances[id].userCount });
212
215
  return found;
213
216
  }
214
217
  export class CustomError extends Error {
@@ -1,7 +1,7 @@
1
1
  // @flow
2
2
 
3
- import {Step} from 'prosemirror-transform';
4
- import {Schema} from 'prosemirror-model';
3
+ import { Step } from 'prosemirror-transform';
4
+ import { Schema } from 'prosemirror-model';
5
5
  import Router from './route';
6
6
  import EditorSchema from '../../../src/EditorSchema';
7
7
  import {
@@ -41,7 +41,7 @@ function handleCollabRequest(req: any, resp: any) {
41
41
  resp.writeHead(200, headers);
42
42
  resp.end();
43
43
  } else {
44
- resp.writeHead(404, {'Content-Type': TXT_PLAIN});
44
+ resp.writeHead(404, { 'Content-Type': TXT_PLAIN });
45
45
  resp.end('Not found');
46
46
  }
47
47
  }
@@ -153,8 +153,8 @@ handle('GET', [DOCS], () => {
153
153
  });
154
154
 
155
155
  // Output the current state of a document instance.
156
- handle('GET', [DOCS, null], (id, req) => {
157
- const inst = getInstance(id, reqIP(req));
156
+ handle('PUT', [DOCS, null], (data, id, req) => {
157
+ const inst = getInstance(id, reqIP(req), data);
158
158
  return Output.json({
159
159
  doc_json: inst.doc.toJSON(),
160
160
  users: inst.userCount,
@@ -275,7 +275,7 @@ handle(
275
275
  });
276
276
  setEditorSchema(effectiveSchema);
277
277
  }
278
- return Output.json({result: 'success'});
278
+ return Output.json({ result: 'success' });
279
279
  },
280
280
  true
281
281
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modusoperandi/licit",
3
- "version": "0.13.3",
3
+ "version": "0.13.10",
4
4
  "subversion": "1",
5
5
  "description": "Rich text editor built with React and ProseMirror",
6
6
  "main": "dist/index.js",
@@ -9,11 +9,8 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/MO-Movia/licit.git"
11
11
  },
12
- "bundleDependencies": [
13
- "prosemirror-utils"
14
- ],
15
12
  "scripts": {
16
- "test": "jest",
13
+ "test": "jest --coverage",
17
14
  "build:bom": "cyclonedx-bom -o dist/bom.xml",
18
15
  "build:clean": "rm -rf dist/ && rm -f modusoperandi-licit-*.*.*.tgz",
19
16
  "build:css": "cp src/ui/*.css dist/ui && cp src/ui/mathquill-editor/*.css dist/ui/mathquill-editor && cp src/client/*.css dist/client && cp src/*.css dist",
@@ -92,7 +89,6 @@
92
89
  "write-file-webpack-plugin": "4.5.1"
93
90
  },
94
91
  "dependencies": {
95
- "@modusoperandi/licit-comment": "^0.0.2-1",
96
92
  "@modusoperandi/licit-doc-attrs-step": "^0.1.2",
97
93
  "@modusoperandi/licit-ui-commands": "^0.1.5",
98
94
  "@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
@@ -123,14 +119,13 @@
123
119
  "prosemirror-state": "^1.3.4",
124
120
  "prosemirror-tables": "^1.1.1",
125
121
  "prosemirror-transform": "^1.2.9",
126
- "prosemirror-utils": "file:prosemirror-utils-1.0.0-0.tgz",
122
+ "prosemirror-utils": "^1.0.0-0",
127
123
  "prosemirror-view": "^1.17.3",
128
124
  "query-string": "6.13.1",
129
125
  "react": "^17.0.2",
130
126
  "react-dom": "^17.0.2",
131
127
  "resize-observer-polyfill": "1.5.1",
132
128
  "smooth-scroll-into-view-if-needed": "1.1.28",
133
- "stable": "0.1.8",
134
129
  "style-loader": "^1.2.1",
135
130
  "uuid": "8.2.0",
136
131
  "webfontloader": "1.6.28"
@@ -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();
@@ -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);
@@ -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
+ });
@@ -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;
@@ -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
  }
@@ -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
 
@@ -3,7 +3,6 @@
3
3
  import { Schema } from 'prosemirror-model';
4
4
  import { EditorState } from 'prosemirror-state';
5
5
  import { Plugin } from 'prosemirror-state';
6
- import DefaultEditorPlugins from './buildEditorPlugins';
7
6
 
8
7
  import convertFromJSON from './convertFromJSON';
9
8
  import EditorSchema from './EditorSchema';
@@ -12,24 +11,21 @@ export const EMPTY_DOC_JSON = {
12
11
  type: 'doc',
13
12
  content: [
14
13
  {
15
- type: 'paragraph'
16
- },// [FS] IRAD-1710 2022-03-04 - No text content needed
14
+ type: 'paragraph',
15
+ }, // [FS] IRAD-1710 2022-03-04 - No text content needed
17
16
  ],
18
17
  };
19
18
 
20
19
  export default function createEmptyEditorState(
21
20
  schema: ?Schema,
22
21
  defaultSchema: ?Schema,
23
- plugins: ?Array<Plugin>,
24
- defaultPlugins: ?Array<Plugin>
22
+ plugins: Array<Plugin>
25
23
  ): EditorState {
26
- const newSchema = schema || (defaultSchema ? defaultSchema : EditorSchema);
27
24
  // TODO: Check if schema support doc and paragraph nodes.
28
25
  return convertFromJSON(
29
26
  EMPTY_DOC_JSON,
30
27
  schema,
31
28
  defaultSchema ? defaultSchema : EditorSchema,
32
- plugins,
33
- defaultPlugins ? defaultPlugins : new DefaultEditorPlugins(newSchema).get()
29
+ plugins
34
30
  );
35
31
  }