@contrail/documents 1.0.109 → 1.0.111

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.
@@ -10,7 +10,7 @@ export declare class DocumentElementFactory {
10
10
  static createFrameElement(options: DocumentElement): DocumentElement;
11
11
  static createComponent(componentType: string, model: any, modelBindings: any, options?: DocumentElement): DocumentElement;
12
12
  static createComponentFromComponentDefinition(componentDefinition: ComponentDefinition, model: any, modelBindings: any, options?: DocumentElement): DocumentElement;
13
- static copyElements(elements: DocumentElement[], commonOptions?: DocumentElement, documentId?: string, positionOffset?: PositionDefinition, lastFrameNumber?: number): {
13
+ static copyElements(elements: DocumentElement[], documentId?: string, commonOptions?: DocumentElement, positionOffset?: PositionDefinition, lastFrameNumber?: number): {
14
14
  oldIdToNewId: Map<string, string>;
15
15
  newElements: DocumentElement[];
16
16
  };
@@ -75,7 +75,7 @@ class DocumentElementFactory {
75
75
  }
76
76
  return element;
77
77
  }
78
- static copyElements(elements, commonOptions = {}, documentId, positionOffset, lastFrameNumber) {
78
+ static copyElements(elements, documentId, commonOptions = {}, positionOffset, lastFrameNumber) {
79
79
  var _a;
80
80
  const oldIdToNewId = new Map();
81
81
  const newElements = [];
@@ -98,16 +98,19 @@ class DocumentElementFactory {
98
98
  delete e.specifiedId;
99
99
  }
100
100
  }
101
- let newId = (0, nanoid_1.nanoid)(16);
101
+ const newInnerElements = [];
102
102
  if (newElement.type === 'table') {
103
103
  const oldChildElements = elements.filter(e => e.tableId === element.id && ['cell', 'column', 'row'].indexOf(e.type) !== -1);
104
- const [newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(newElement, oldChildElements);
105
- if (oldChildElements.length !== newChildElements.length) {
104
+ let newTableElement, newChildElements = [];
105
+ try {
106
+ [newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(newElement, oldChildElements);
107
+ }
108
+ catch (e) { }
109
+ if (oldChildElements.length !== newChildElements.length || oldChildElements.length === 0) {
106
110
  console.log(`Invalid table element to copy`, newElement, oldChildElements, newChildElements);
107
111
  continue;
108
112
  }
109
113
  newElement = newTableElement;
110
- newId = newTableElement.id;
111
114
  newChildElements.forEach(newChildElement => {
112
115
  var _a;
113
116
  let oldChildId;
@@ -123,8 +126,10 @@ class DocumentElementFactory {
123
126
  oldChildId = (_a = elements.find(e => e.type === 'cell' && e.rowId === oldRowId && e.columnId === oldColumnId)) === null || _a === void 0 ? void 0 : _a.id;
124
127
  }
125
128
  if (oldChildId) {
126
- oldIdToNewId[oldChildId] = newChildElement.id;
127
- newElements.push(newChildElement);
129
+ newChildElement.documentId = documentId;
130
+ newChildElement.specifiedId = newChildElement.id;
131
+ oldIdToNewId.set(oldChildId, newChildElement.id);
132
+ newInnerElements.push(newChildElement);
128
133
  }
129
134
  });
130
135
  }
@@ -140,11 +145,12 @@ class DocumentElementFactory {
140
145
  newElement.position.y = newElement.position.y + positionOffset.y;
141
146
  }
142
147
  }
143
- newElement.documentId = documentId;
144
- newElement.specifiedId = newId;
145
- oldIdToNewId[element.id] = newId;
146
148
  newElement = DocumentElementFactory.createElement(element.type, newElement);
149
+ newElement.documentId = documentId;
150
+ newElement.specifiedId = newElement.id;
151
+ oldIdToNewId.set(element.id, newElement.id);
147
152
  newElements.push(newElement);
153
+ newElements.push(...newInnerElements);
148
154
  if (newElement.type === 'group')
149
155
  groupElements.push(newElement);
150
156
  if (DocumentElementFactory.isMask(newElement))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.0.109",
3
+ "version": "1.0.111",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@contrail/actions": "^1.0.14",
42
- "@contrail/document-table": "^1.0.1",
42
+ "@contrail/document-table": "^1.0.2",
43
43
  "@contrail/types": "^3.0.71",
44
44
  "@contrail/util": "^1.0.19",
45
45
  "reflect-metadata": "^0.1.13"