@modusoperandi/licit 0.13.10 → 0.13.18

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.
@@ -51,7 +51,7 @@ export const DataType = Object.freeze({
51
51
  */
52
52
  class Licit extends React.Component<any, any> {
53
53
  _runtime: EditorRuntime;
54
- _connector: any;
54
+ _connector: SimpleConnector;
55
55
  _clientID: string;
56
56
  _editorView: EditorView; // This will be handy in updating document's content.
57
57
  _skipSCU: boolean; // Flag to decide whether to skip shouldComponentUpdate
@@ -107,6 +107,9 @@ class Licit extends React.Component<any, any> {
107
107
  // Handle Image Upload from Angular App
108
108
  const runtime = props.runtime || null;
109
109
  const plugins = props.plugins || null;
110
+ // This flag decides whether DataType.HTML check is needed when
111
+ // changing document. If it forcefully done, it is not needed, otherwise needed.
112
+ this.skipDataTypeCheck = false;
110
113
 
111
114
  this._defaultEditorSchema = new Schema({
112
115
  nodes: EditorNodes,
@@ -135,6 +138,8 @@ class Licit extends React.Component<any, any> {
135
138
  )
136
139
  : new SimpleConnector(editorState, setState);
137
140
 
141
+ this._connector._dataDefined = !!props.data;
142
+
138
143
  // FS IRAD-989 2020-18-06
139
144
  // updating properties should automatically render the changes
140
145
 
@@ -152,6 +157,7 @@ class Licit extends React.Component<any, any> {
152
157
  disabled,
153
158
  embedded,
154
159
  runtime,
160
+ dataType,
155
161
  };
156
162
 
157
163
  // FS IRAD-1040 2020-26-08
@@ -313,13 +319,33 @@ class Licit extends React.Component<any, any> {
313
319
  return node.attrs && node.attrs[attrName];
314
320
  }
315
321
 
316
- setContent = (content: any = {}): void => {
322
+ getDocument(content: any, editorState: EditorState, dataType: DataType) {
323
+ let document = null;
324
+ const { schema } = editorState;
325
+
326
+ if (DataType.JSON === dataType || this.skipDataTypeCheck) {
327
+ document = schema.nodeFromJSON(content ? content : EMPTY_DOC_JSON);
328
+ } else {
329
+ const tempEState = convertFromHTML(
330
+ content ? content : '',
331
+ schema,
332
+ editorState.plugins
333
+ );
334
+ document = tempEState.doc;
335
+ }
336
+
337
+ return document;
338
+ }
339
+
340
+ setContent = (content: any = {}, dataType: DataType): void => {
341
+ this.skipDataTypeCheck = false;
317
342
  // [FS] IRAD-1571 2021-09-27
318
343
  // dispatch a transaction that MUST start from the view’s current state;
319
344
  const editorState = this._editorView.state;
320
- const { doc, schema } = editorState;
345
+ const { doc } = editorState;
321
346
  let { tr } = editorState;
322
- const document = schema.nodeFromJSON(content ? content : EMPTY_DOC_JSON);
347
+ const document = this.getDocument(content, editorState, dataType);
348
+ this.skipDataTypeCheck = true;
323
349
 
324
350
  // [FS] IRAD-1593 2021-10-12
325
351
  // Reset lastKeyCode since the content is set dynamically and so lastKeyCode is invalid now.
@@ -339,7 +365,7 @@ class Licit extends React.Component<any, any> {
339
365
  this._editorView.dispatch(tr);
340
366
  };
341
367
 
342
- hasDataChanged(nextData: any) {
368
+ hasDataChanged(nextData: any, nextDataType: DataType) {
343
369
  let dataChanged = false;
344
370
 
345
371
  // [FS] IRAD-1571 2021-09-27
@@ -348,21 +374,19 @@ class Licit extends React.Component<any, any> {
348
374
  // Do a proper circular JSON comparison.
349
375
  if (stringify(this.state.data) !== stringify(nextData)) {
350
376
  const editorState = this._editorView.state;
351
- const nextDoc = editorState.schema.nodeFromJSON(
352
- nextData ? nextData : EMPTY_DOC_JSON
353
- );
377
+ const nextDoc = this.getDocument(nextData, editorState, nextDataType);
354
378
  dataChanged = !nextDoc.eq(editorState.doc);
355
379
  }
356
380
 
357
381
  return dataChanged;
358
382
  }
359
383
 
360
- changeContent(data: any) {
361
- if (this.hasDataChanged(data)) {
384
+ changeContent(data: any, dataType: DataType) {
385
+ if (this.hasDataChanged(data, dataType)) {
362
386
  // FS IRAD-1592 2021-11-10
363
387
  // Release here quickly, so that update doesn't care about at this point.
364
388
  // data changed, so update document content
365
- setTimeout(this.setContent.bind(this, data), 1);
389
+ setTimeout(this.setContent.bind(this, data, dataType), 1);
366
390
  }
367
391
  }
368
392
 
@@ -371,13 +395,15 @@ class Licit extends React.Component<any, any> {
371
395
  if (!this._skipSCU) {
372
396
  this._skipSCU = false;
373
397
 
374
- this.changeContent(nextState.data);
398
+ this.changeContent(nextState.data, nextState.dataType);
375
399
 
376
400
  if (this.state.docID !== nextState.docID) {
377
401
  setTimeout(this.setDocID.bind(this, nextState), 1);
378
402
  }
379
403
  }
380
404
 
405
+ this.skipDataTypeCheck = true;
406
+
381
407
  return true;
382
408
  }
383
409
 
@@ -628,6 +654,7 @@ class Licit extends React.Component<any, any> {
628
654
  delete propsCopy.data;
629
655
  this.setState(propsCopy);
630
656
  }
657
+ this.skipDataTypeCheck = false;
631
658
  // Need to go through shouldComponentUpdate lifecycle here, when updated from outside,
632
659
  // so that content is modified gracefully using transaction so that undo/redo works too.
633
660
  this._skipSCU = false;
@@ -14,6 +14,10 @@ export type SetStateCall = (
14
14
  class SimpleConnector {
15
15
  _setState: SetStateCall;
16
16
  _editorState: EditorState;
17
+ // This flag is used to deteremine if data passed in or not
18
+ // If not passed in, use the data from collab server when in collab mode.
19
+ // else use empty content.
20
+ _dataDefined: boolean;
17
21
 
18
22
  constructor(editorState: EditorState, setState: SetStateCall) {
19
23
  this._editorState = editorState;
@@ -49,6 +53,8 @@ class SimpleConnector {
49
53
  // Send the modified schema to server
50
54
  updateSchema = (schema: Schema, data: any) => {};
51
55
 
56
+ updateContent = (data: any) => {};
57
+
52
58
  cleanUp = () => {};
53
59
  }
54
60
 
@@ -12,6 +12,18 @@ export default function convertFromHTML(
12
12
  plugins: Array<Plugin>
13
13
  ): EditorState {
14
14
  const root = document.createElement('html');
15
- root.innerHTML = html;
15
+ root.innerHTML = unEscape(html ? html : ' ');
16
16
  return convertFromDOMElement(root, schema, plugins);
17
17
  }
18
+
19
+ function unEscape(htmlStr) {
20
+ if (htmlStr) {
21
+ htmlStr = htmlStr
22
+ .replace(/&lt;/g, '<')
23
+ .replace(/&gt;/g, '>')
24
+ .replace(/&quot;/g, '"')
25
+ .replace(/&#39;/g, "'")
26
+ .replace(/&amp;/g, '&');
27
+ }
28
+ return htmlStr;
29
+ }
@@ -1,4 +1,4 @@
1
- @import '@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 '@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
1
+ @import '~@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
2
2
 
@@ -8,7 +8,7 @@ const env = require('./env');
8
8
  const path = require('path');
9
9
 
10
10
  const config = {
11
- mode: 'production',//development
11
+ mode: env.NODE_ENV,
12
12
  entry: {// [FS] IRAD-901 2020-07-15 New collab server reusing base PM collab server
13
13
  run_licit_collab_server: path.join(__dirname, '../licit', 'server/collab', 'start.js'),
14
14
  },
package/webpack.config.js CHANGED
@@ -20,7 +20,7 @@ var isDev = env.NODE_ENV === 'development' || 0;
20
20
  // isDev = false;
21
21
 
22
22
  var options = {
23
- mode: 'production',
23
+ mode: env.NODE_ENV,
24
24
  entry: {
25
25
  licit: path.join(__dirname, 'licit', 'client', 'index.js'),
26
26
  },