@atlaskit/adf-schema 25.1.0 → 25.2.0

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 (249) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/index.js +0 -2
  3. package/dist/cjs/json-schema/index.js +0 -3
  4. package/dist/cjs/schema/bitbucket-schema.js +0 -2
  5. package/dist/cjs/schema/confluence-schema.js +1 -4
  6. package/dist/cjs/schema/create-schema.js +12 -38
  7. package/dist/cjs/schema/default-schema.js +3 -16
  8. package/dist/cjs/schema/groups.js +13 -6
  9. package/dist/cjs/schema/index.js +0 -5
  10. package/dist/cjs/schema/inline-nodes.js +0 -5
  11. package/dist/cjs/schema/jira-schema.js +0 -36
  12. package/dist/cjs/schema/marks/alignment.js +0 -2
  13. package/dist/cjs/schema/marks/annotation.js +2 -14
  14. package/dist/cjs/schema/marks/code.js +0 -5
  15. package/dist/cjs/schema/marks/confluence-inline-comment.js +1 -1
  16. package/dist/cjs/schema/marks/data-consumer.js +2 -7
  17. package/dist/cjs/schema/marks/em.js +0 -2
  18. package/dist/cjs/schema/marks/fragment.js +0 -13
  19. package/dist/cjs/schema/marks/indentation.js +0 -2
  20. package/dist/cjs/schema/marks/index.js +0 -18
  21. package/dist/cjs/schema/marks/link.js +0 -17
  22. package/dist/cjs/schema/marks/strike.js +0 -2
  23. package/dist/cjs/schema/marks/strong.js +2 -3
  24. package/dist/cjs/schema/marks/subsup.js +0 -5
  25. package/dist/cjs/schema/marks/text-color.js +46 -37
  26. package/dist/cjs/schema/marks/type-ahead-query.js +0 -3
  27. package/dist/cjs/schema/marks/underline.js +0 -2
  28. package/dist/cjs/schema/nodes/block-card.js +1 -2
  29. package/dist/cjs/schema/nodes/blockquote.js +1 -1
  30. package/dist/cjs/schema/nodes/bodied-extension.js +0 -3
  31. package/dist/cjs/schema/nodes/caption.js +1 -1
  32. package/dist/cjs/schema/nodes/code-block.js +11 -29
  33. package/dist/cjs/schema/nodes/date.js +1 -1
  34. package/dist/cjs/schema/nodes/decision-item.js +2 -4
  35. package/dist/cjs/schema/nodes/decision-list.js +0 -2
  36. package/dist/cjs/schema/nodes/doc.js +1 -1
  37. package/dist/cjs/schema/nodes/embed-card.js +6 -6
  38. package/dist/cjs/schema/nodes/emoji.js +11 -9
  39. package/dist/cjs/schema/nodes/expand.js +1 -4
  40. package/dist/cjs/schema/nodes/extension.js +0 -3
  41. package/dist/cjs/schema/nodes/hard-break.js +1 -1
  42. package/dist/cjs/schema/nodes/heading.js +2 -2
  43. package/dist/cjs/schema/nodes/index.js +0 -45
  44. package/dist/cjs/schema/nodes/inline-card.js +4 -4
  45. package/dist/cjs/schema/nodes/inline-extension.js +0 -3
  46. package/dist/cjs/schema/nodes/layout-column.js +4 -5
  47. package/dist/cjs/schema/nodes/layout-section.js +1 -1
  48. package/dist/cjs/schema/nodes/media-group.js +1 -1
  49. package/dist/cjs/schema/nodes/media-inline.js +0 -2
  50. package/dist/cjs/schema/nodes/media-single.js +3 -14
  51. package/dist/cjs/schema/nodes/media.js +10 -28
  52. package/dist/cjs/schema/nodes/mention.js +4 -14
  53. package/dist/cjs/schema/nodes/nested-expand.js +1 -1
  54. package/dist/cjs/schema/nodes/ordered-list.js +3 -17
  55. package/dist/cjs/schema/nodes/panel.js +1 -13
  56. package/dist/cjs/schema/nodes/paragraph.js +1 -6
  57. package/dist/cjs/schema/nodes/placeholder.js +1 -1
  58. package/dist/cjs/schema/nodes/rule.js +1 -1
  59. package/dist/cjs/schema/nodes/status.js +4 -6
  60. package/dist/cjs/schema/nodes/tableNodes.js +12 -39
  61. package/dist/cjs/schema/nodes/task-item.js +2 -4
  62. package/dist/cjs/schema/nodes/task-list.js +0 -2
  63. package/dist/cjs/schema/nodes/text.js +1 -1
  64. package/dist/cjs/steps/analytics.js +4 -38
  65. package/dist/cjs/steps/set-attrs.js +0 -26
  66. package/dist/cjs/steps/table/add-column.js +33 -105
  67. package/dist/cjs/steps/table/constants.js +0 -1
  68. package/dist/cjs/steps/table/sort-column.js +0 -19
  69. package/dist/cjs/steps/table/utils/cell-step.js +18 -49
  70. package/dist/cjs/steps/table/utils/cells-at-column.js +2 -21
  71. package/dist/cjs/steps/table/utils/find-column.js +13 -17
  72. package/dist/cjs/steps/table/utils/get-table-rect-from-doc.js +6 -8
  73. package/dist/cjs/steps/table/utils/side-effects/rows.js +23 -78
  74. package/dist/cjs/steps/table/utils/side-effects/side-effects.js +0 -23
  75. package/dist/cjs/steps/table/utils/side-effects/table.js +2 -18
  76. package/dist/cjs/steps/table/utils/table-map.js +0 -6
  77. package/dist/cjs/steps/type-ahead.js +5 -25
  78. package/dist/cjs/steps.js +0 -6
  79. package/dist/cjs/utils/colors.js +13 -36
  80. package/dist/cjs/utils/confluence/emoji.js +6 -13
  81. package/dist/cjs/utils/extensions.js +0 -8
  82. package/dist/cjs/utils/index.js +0 -4
  83. package/dist/cjs/utils/parseDOM.js +0 -2
  84. package/dist/cjs/utils/url.js +3 -20
  85. package/dist/cjs/utils/uuid.js +0 -3
  86. package/dist/cjs/version.json +1 -1
  87. package/dist/es2019/index.js +1 -2
  88. package/dist/es2019/schema/bitbucket-schema.js +1 -1
  89. package/dist/es2019/schema/confluence-schema.js +1 -2
  90. package/dist/es2019/schema/create-schema.js +12 -25
  91. package/dist/es2019/schema/default-schema.js +3 -11
  92. package/dist/es2019/schema/groups.js +13 -6
  93. package/dist/es2019/schema/index.js +1 -2
  94. package/dist/es2019/schema/jira-schema.js +0 -24
  95. package/dist/es2019/schema/marks/alignment.js +1 -3
  96. package/dist/es2019/schema/marks/annotation.js +3 -9
  97. package/dist/es2019/schema/marks/breakout.js +0 -4
  98. package/dist/es2019/schema/marks/code.js +1 -5
  99. package/dist/es2019/schema/marks/confluence-inline-comment.js +1 -2
  100. package/dist/es2019/schema/marks/data-consumer.js +3 -5
  101. package/dist/es2019/schema/marks/em.js +1 -2
  102. package/dist/es2019/schema/marks/fragment.js +0 -8
  103. package/dist/es2019/schema/marks/indentation.js +0 -4
  104. package/dist/es2019/schema/marks/link.js +2 -11
  105. package/dist/es2019/schema/marks/strike.js +1 -2
  106. package/dist/es2019/schema/marks/strong.js +3 -7
  107. package/dist/es2019/schema/marks/subsup.js +0 -6
  108. package/dist/es2019/schema/marks/text-color.js +44 -29
  109. package/dist/es2019/schema/marks/type-ahead-query.js +0 -2
  110. package/dist/es2019/schema/marks/underline.js +1 -2
  111. package/dist/es2019/schema/marks/unsupported-mark.js +0 -1
  112. package/dist/es2019/schema/marks/unsupported-node-attributes.js +0 -1
  113. package/dist/es2019/schema/nodes/block-card.js +1 -3
  114. package/dist/es2019/schema/nodes/blockquote.js +1 -2
  115. package/dist/es2019/schema/nodes/bodied-extension.js +0 -4
  116. package/dist/es2019/schema/nodes/bullet-list.js +0 -2
  117. package/dist/es2019/schema/nodes/caption.js +1 -2
  118. package/dist/es2019/schema/nodes/code-block.js +11 -28
  119. package/dist/es2019/schema/nodes/confluence-jira-issue.js +0 -2
  120. package/dist/es2019/schema/nodes/confluence-unsupported-block.js +0 -4
  121. package/dist/es2019/schema/nodes/confluence-unsupported-inline.js +0 -4
  122. package/dist/es2019/schema/nodes/date.js +1 -2
  123. package/dist/es2019/schema/nodes/decision-item.js +0 -2
  124. package/dist/es2019/schema/nodes/decision-list.js +1 -2
  125. package/dist/es2019/schema/nodes/doc.js +1 -0
  126. package/dist/es2019/schema/nodes/embed-card.js +1 -2
  127. package/dist/es2019/schema/nodes/emoji.js +9 -6
  128. package/dist/es2019/schema/nodes/expand.js +1 -3
  129. package/dist/es2019/schema/nodes/extension.js +0 -4
  130. package/dist/es2019/schema/nodes/hard-break.js +1 -2
  131. package/dist/es2019/schema/nodes/heading.js +2 -3
  132. package/dist/es2019/schema/nodes/image.js +0 -4
  133. package/dist/es2019/schema/nodes/inline-card.js +4 -5
  134. package/dist/es2019/schema/nodes/inline-extension.js +0 -4
  135. package/dist/es2019/schema/nodes/layout-column.js +4 -6
  136. package/dist/es2019/schema/nodes/layout-section.js +1 -4
  137. package/dist/es2019/schema/nodes/list-item.js +0 -2
  138. package/dist/es2019/schema/nodes/media-group.js +1 -2
  139. package/dist/es2019/schema/nodes/media-single.js +3 -6
  140. package/dist/es2019/schema/nodes/media.js +10 -20
  141. package/dist/es2019/schema/nodes/mention.js +0 -11
  142. package/dist/es2019/schema/nodes/nested-expand.js +1 -2
  143. package/dist/es2019/schema/nodes/ordered-list.js +4 -14
  144. package/dist/es2019/schema/nodes/panel.js +3 -10
  145. package/dist/es2019/schema/nodes/paragraph.js +1 -7
  146. package/dist/es2019/schema/nodes/placeholder.js +1 -2
  147. package/dist/es2019/schema/nodes/rule.js +1 -2
  148. package/dist/es2019/schema/nodes/status.js +1 -2
  149. package/dist/es2019/schema/nodes/tableNodes.js +10 -26
  150. package/dist/es2019/schema/nodes/task-item.js +0 -2
  151. package/dist/es2019/schema/nodes/task-list.js +0 -2
  152. package/dist/es2019/schema/nodes/text.js +1 -0
  153. package/dist/es2019/schema/nodes/unknown-block.js +0 -2
  154. package/dist/es2019/schema/nodes/unsupported-block.js +0 -2
  155. package/dist/es2019/schema/nodes/unsupported-inline.js +0 -2
  156. package/dist/es2019/steps/analytics.js +13 -30
  157. package/dist/es2019/steps/set-attrs.js +3 -12
  158. package/dist/es2019/steps/table/add-column.js +33 -76
  159. package/dist/es2019/steps/table/constants.js +0 -1
  160. package/dist/es2019/steps/table/sort-column.js +1 -8
  161. package/dist/es2019/steps/table/utils/cell-step.js +15 -32
  162. package/dist/es2019/steps/table/utils/cells-at-column.js +6 -11
  163. package/dist/es2019/steps/table/utils/find-column.js +12 -15
  164. package/dist/es2019/steps/table/utils/get-table-rect-from-doc.js +7 -6
  165. package/dist/es2019/steps/table/utils/side-effects/rows.js +19 -59
  166. package/dist/es2019/steps/table/utils/side-effects/side-effects.js +0 -21
  167. package/dist/es2019/steps/table/utils/side-effects/table.js +0 -17
  168. package/dist/es2019/steps/type-ahead.js +3 -15
  169. package/dist/es2019/utils/colors.js +8 -18
  170. package/dist/es2019/utils/confluence/emoji.js +5 -8
  171. package/dist/es2019/utils/extensions.js +0 -4
  172. package/dist/es2019/utils/url.js +2 -12
  173. package/dist/es2019/utils/uuid.js +0 -2
  174. package/dist/es2019/version.json +1 -1
  175. package/dist/esm/index.js +1 -2
  176. package/dist/esm/schema/bitbucket-schema.js +1 -1
  177. package/dist/esm/schema/confluence-schema.js +1 -2
  178. package/dist/esm/schema/create-schema.js +12 -31
  179. package/dist/esm/schema/default-schema.js +3 -11
  180. package/dist/esm/schema/groups.js +13 -6
  181. package/dist/esm/schema/index.js +1 -2
  182. package/dist/esm/schema/jira-schema.js +0 -24
  183. package/dist/esm/schema/marks/alignment.js +1 -1
  184. package/dist/esm/schema/marks/annotation.js +3 -11
  185. package/dist/esm/schema/marks/code.js +1 -3
  186. package/dist/esm/schema/marks/confluence-inline-comment.js +1 -0
  187. package/dist/esm/schema/marks/data-consumer.js +3 -3
  188. package/dist/esm/schema/marks/em.js +1 -0
  189. package/dist/esm/schema/marks/fragment.js +0 -9
  190. package/dist/esm/schema/marks/link.js +0 -12
  191. package/dist/esm/schema/marks/strike.js +1 -0
  192. package/dist/esm/schema/marks/strong.js +3 -1
  193. package/dist/esm/schema/marks/subsup.js +0 -4
  194. package/dist/esm/schema/marks/text-color.js +46 -30
  195. package/dist/esm/schema/marks/underline.js +1 -0
  196. package/dist/esm/schema/nodes/block-card.js +1 -1
  197. package/dist/esm/schema/nodes/blockquote.js +1 -0
  198. package/dist/esm/schema/nodes/bodied-extension.js +0 -2
  199. package/dist/esm/schema/nodes/caption.js +1 -0
  200. package/dist/esm/schema/nodes/code-block.js +11 -26
  201. package/dist/esm/schema/nodes/date.js +1 -0
  202. package/dist/esm/schema/nodes/decision-item.js +2 -2
  203. package/dist/esm/schema/nodes/decision-list.js +1 -0
  204. package/dist/esm/schema/nodes/doc.js +1 -0
  205. package/dist/esm/schema/nodes/embed-card.js +6 -5
  206. package/dist/esm/schema/nodes/emoji.js +12 -7
  207. package/dist/esm/schema/nodes/expand.js +1 -1
  208. package/dist/esm/schema/nodes/extension.js +0 -2
  209. package/dist/esm/schema/nodes/hard-break.js +1 -0
  210. package/dist/esm/schema/nodes/heading.js +2 -1
  211. package/dist/esm/schema/nodes/inline-card.js +4 -3
  212. package/dist/esm/schema/nodes/inline-extension.js +0 -2
  213. package/dist/esm/schema/nodes/layout-column.js +4 -4
  214. package/dist/esm/schema/nodes/layout-section.js +1 -0
  215. package/dist/esm/schema/nodes/media-group.js +1 -0
  216. package/dist/esm/schema/nodes/media-single.js +3 -8
  217. package/dist/esm/schema/nodes/media.js +10 -18
  218. package/dist/esm/schema/nodes/mention.js +4 -13
  219. package/dist/esm/schema/nodes/nested-expand.js +1 -0
  220. package/dist/esm/schema/nodes/ordered-list.js +3 -13
  221. package/dist/esm/schema/nodes/panel.js +1 -10
  222. package/dist/esm/schema/nodes/paragraph.js +1 -5
  223. package/dist/esm/schema/nodes/placeholder.js +1 -0
  224. package/dist/esm/schema/nodes/rule.js +1 -0
  225. package/dist/esm/schema/nodes/status.js +5 -4
  226. package/dist/esm/schema/nodes/tableNodes.js +12 -25
  227. package/dist/esm/schema/nodes/task-item.js +2 -2
  228. package/dist/esm/schema/nodes/text.js +1 -0
  229. package/dist/esm/steps/analytics.js +5 -31
  230. package/dist/esm/steps/set-attrs.js +1 -17
  231. package/dist/esm/steps/table/add-column.js +33 -91
  232. package/dist/esm/steps/table/constants.js +0 -1
  233. package/dist/esm/steps/table/sort-column.js +1 -10
  234. package/dist/esm/steps/table/utils/cell-step.js +18 -42
  235. package/dist/esm/steps/table/utils/cells-at-column.js +2 -18
  236. package/dist/esm/steps/table/utils/find-column.js +13 -16
  237. package/dist/esm/steps/table/utils/get-table-rect-from-doc.js +7 -6
  238. package/dist/esm/steps/table/utils/side-effects/rows.js +23 -76
  239. package/dist/esm/steps/table/utils/side-effects/side-effects.js +0 -18
  240. package/dist/esm/steps/table/utils/side-effects/table.js +2 -13
  241. package/dist/esm/steps/type-ahead.js +6 -18
  242. package/dist/esm/utils/colors.js +12 -23
  243. package/dist/esm/utils/confluence/emoji.js +6 -10
  244. package/dist/esm/utils/extensions.js +0 -4
  245. package/dist/esm/utils/url.js +2 -12
  246. package/dist/esm/version.json +1 -1
  247. package/dist/types/schema/default-schema.d.ts +1 -1
  248. package/dist/types/utils/colors.d.ts +1 -1
  249. package/package.json +2 -2
@@ -6,36 +6,30 @@ import { applyCellStep, createCellStep, getMapFromCellStep, invertCellStep } fro
6
6
  import { SideEffectsHandler } from './utils/side-effects/side-effects';
7
7
  import memoizeOne from 'memoize-one';
8
8
  const ADD_COLUMN_STEP = 'ak-add-column';
9
-
10
9
  function printColumnInfo(columnInfo) {
11
10
  let cellsFrom = [];
12
-
13
11
  for (const cellInfo of columnInfo.values()) {
14
12
  cellsFrom.push(cellInfo.from);
15
13
  }
16
-
17
14
  return `[${cellsFrom.join(',')}]`;
18
15
  }
19
-
20
16
  function createColumnInfo(cellsInfo) {
21
17
  return new Map(cellsInfo.map(cellInfo => [cellInfo.from, cellInfo]));
22
18
  }
23
-
24
19
  const getTableRectAndColumnFactory = (doc, pos, columnInfo) => {
25
20
  return memoizeOne(() => {
26
21
  const rect = getTableRectFromDoc(doc, pos);
27
22
  const column = findColumn(columnInfo, rect);
28
-
29
23
  if (column === null) {
30
24
  throw new Error('no column');
31
25
  }
32
-
33
26
  return {
34
27
  rect,
35
28
  column
36
29
  };
37
30
  });
38
31
  };
32
+
39
33
  /**
40
34
  * Index and positions looks like
41
35
  * 0 1 2 3 -> Add Column Index
@@ -44,8 +38,6 @@ const getTableRectAndColumnFactory = (doc, pos, columnInfo) => {
44
38
  * 0 1 2 x -> Remove Column Index
45
39
  *
46
40
  */
47
-
48
-
49
41
  export class AddColumnStep extends Step {
50
42
  constructor(tablePos, addColumnStepInfo, isDelete = false) {
51
43
  super();
@@ -54,6 +46,7 @@ export class AddColumnStep extends Step {
54
46
  this.sideEffectsHandler = new SideEffectsHandler(addColumnStepInfo.sideEffects);
55
47
  this.columnInfo = createColumnInfo(addColumnStepInfo.cells);
56
48
  }
49
+
57
50
  /**
58
51
  * Detect the column based on all the cells step in column info.
59
52
  * Recreate columnInfo based on the current document. We might need to add new cells added by insert row or unmerge cells.
@@ -68,41 +61,34 @@ export class AddColumnStep extends Step {
68
61
  *
69
62
  * @param doc Current document
70
63
  */
71
-
72
-
73
64
  apply(doc) {
74
65
  const {
75
66
  tablePos
76
- } = this; // Create transform base on the doc
77
-
67
+ } = this;
68
+ // Create transform base on the doc
78
69
  const tr = new Transform(doc);
79
-
80
70
  if (this.sideEffectsHandler.table.handleAddTable(tr, this.isDelete)) {
81
71
  return StepResult.ok(tr.doc);
82
72
  }
83
-
84
73
  let tableRect;
85
-
86
74
  try {
87
75
  tableRect = getTableRectFromDoc(doc, tablePos);
88
76
  } catch (e) {
89
77
  return StepResult.fail(e.message);
90
78
  }
91
-
92
79
  const column = findColumn(this.columnInfo, tableRect);
93
-
94
80
  if (column === null) {
95
81
  return StepResult.fail(`No column for this cells "${printColumnInfo(this.columnInfo)}" in table at position "${tablePos}".`);
96
82
  }
97
-
98
83
  if (this.sideEffectsHandler.table.handleRemoveTable(tr, this.tablePos, tableRect, column, this.isDelete)) {
99
84
  return StepResult.ok(tr.doc);
100
85
  }
86
+ this.columnInfo = this.applyCellSteps(tr, tableRect, column, this.isDelete);
101
87
 
102
- this.columnInfo = this.applyCellSteps(tr, tableRect, column, this.isDelete); // Return the document modified.
103
-
88
+ // Return the document modified.
104
89
  return StepResult.ok(tr.doc);
105
90
  }
91
+
106
92
  /**
107
93
  * Update tablePos with the new position. If tablePos doesnt exist any more remove the step
108
94
  * Update all the cellStep inside columnInfo. If cellStep.from position gets deleted removed it from column info
@@ -110,48 +96,39 @@ export class AddColumnStep extends Step {
110
96
  * Create a new step with all the position updated
111
97
  * @param mapping
112
98
  */
113
-
114
-
115
99
  map(mapping) {
116
100
  const tablePosResult = mapping.mapResult(this.tablePos);
117
-
118
101
  if (tablePosResult.deleted) {
119
102
  // If table was deleted remove the step
120
103
  return null;
121
104
  }
122
-
123
105
  const cellSteps = [];
124
-
125
106
  for (const oldCellStep of this.columnInfo.values()) {
126
107
  const fromResult = mapping.mapResult(oldCellStep.from);
127
108
  const toResult = mapping.mapResult(oldCellStep.to);
128
-
129
109
  if (fromResult.deleted && toResult.deleted) {
130
110
  continue;
131
111
  }
132
-
133
- const cellStep = { ...oldCellStep,
112
+ const cellStep = {
113
+ ...oldCellStep,
134
114
  from: fromResult.pos,
135
115
  to: toResult.pos
136
116
  };
137
-
138
117
  if (oldCellStep.mergeWith !== undefined) {
139
118
  cellStep.mergeWith = mapping.map(oldCellStep.mergeWith);
140
119
  }
141
-
142
120
  cellSteps.push(cellStep);
143
121
  }
144
-
145
122
  if (cellSteps.length === 0) {
146
123
  return null;
147
124
  }
148
-
149
125
  const sideEffects = this.sideEffectsHandler.map(mapping);
150
126
  return new AddColumnStep(tablePosResult.pos, {
151
127
  cells: cellSteps,
152
128
  sideEffects
153
129
  }, this.isDelete);
154
130
  }
131
+
155
132
  /**
156
133
  * if isDelete
157
134
  * Get the original cell node at columnInfo.cellStep[].from to columnInfo.cellStep[].to
@@ -163,13 +140,12 @@ export class AddColumnStep extends Step {
163
140
  * return new step inverted
164
141
  * @param originalDoc
165
142
  */
166
-
167
-
168
143
  invert(originalDoc) {
169
- const stepMap = this.getMap(); // Memoize function to be called only on delete scenarios
170
-
171
- const getTableRectAndColumn = getTableRectAndColumnFactory(originalDoc, this.tablePos, this.columnInfo); // This is needed because the real pos of the cell in the generated document is affected by the previous operations.
144
+ const stepMap = this.getMap();
172
145
 
146
+ // Memoize function to be called only on delete scenarios
147
+ const getTableRectAndColumn = getTableRectAndColumnFactory(originalDoc, this.tablePos, this.columnInfo);
148
+ // This is needed because the real pos of the cell in the generated document is affected by the previous operations.
173
149
  const newCellSteps = Array.from(this.columnInfo.values(), oldCellStep => {
174
150
  const newCellStep = invertCellStep(originalDoc, getTableRectAndColumn, oldCellStep, this.isDelete, stepMap);
175
151
  return newCellStep;
@@ -180,6 +156,7 @@ export class AddColumnStep extends Step {
180
156
  sideEffects
181
157
  }, !this.isDelete);
182
158
  }
159
+
183
160
  /**
184
161
  * StepMap is created based on columnInfo.
185
162
  * ColumnInfo is created on constructor and once is applied (the document could have new cells that weren't part of the original set)
@@ -194,44 +171,37 @@ export class AddColumnStep extends Step {
194
171
  * currentSize: Represent the affected range, this will be pos + currentSize
195
172
  * newSize: Represent the new values, pos + newSize
196
173
  */
197
-
198
-
199
174
  getMap() {
200
175
  const tableMap = this.sideEffectsHandler.getTableMap(this.isDelete);
201
-
202
176
  if (tableMap) {
203
177
  return tableMap;
204
178
  }
205
-
206
179
  let ranges = [];
207
-
208
180
  for (const cellStep of this.columnInfo.values()) {
209
181
  ranges.push(...getMapFromCellStep(cellStep, this.isDelete));
210
182
  }
183
+ ranges = this.sideEffectsHandler.rows.addRowRanges(ranges, this.isDelete);
211
184
 
212
- ranges = this.sideEffectsHandler.rows.addRowRanges(ranges, this.isDelete); // If no steps, I create am empty stepMap
213
-
185
+ // If no steps, I create am empty stepMap
214
186
  return new StepMap(ranges);
215
187
  }
188
+
216
189
  /**
217
190
  * Try to merge this step with another one, to be applied directly
218
191
  * after it. Returns the merged step when possible, null if the
219
192
  * steps can't be merged.
220
193
  */
221
-
222
-
223
194
  merge(other) {
224
195
  // We cannot merge add column step at the moment
225
196
  return null;
226
197
  }
198
+
227
199
  /**
228
200
  * Create a JSON-serializeable representation of this step. When
229
201
  * defining this for a custom subclass, make sure the result object
230
202
  * includes the step type's [JSON id](#transform.Step^jsonID) under
231
203
  * the `stepType` property.
232
204
  */
233
-
234
-
235
205
  toJSON() {
236
206
  const addColumnStepJson = {
237
207
  stepType: ADD_COLUMN_STEP,
@@ -241,109 +211,96 @@ export class AddColumnStep extends Step {
241
211
  from: cellStep.from,
242
212
  to: cellStep.to
243
213
  };
244
-
245
214
  if (cellStep.mergeWith !== undefined) {
246
215
  cellStepJson.mergeWith = cellStep.mergeWith;
247
216
  }
248
-
249
217
  if (cellStep.newCell !== undefined) {
250
218
  cellStepJson.newCell = cellStep.newCell.toJSON();
251
219
  }
252
-
253
220
  return cellStepJson;
254
221
  }),
255
222
  isDelete: this.isDelete
256
223
  };
257
224
  const sideEffectsJSON = this.sideEffectsHandler.toJSON();
258
-
259
225
  if (sideEffectsJSON) {
260
226
  addColumnStepJson.sideEffects = sideEffectsJSON;
261
227
  }
262
-
263
228
  return addColumnStepJson;
264
229
  }
230
+
265
231
  /**
266
232
  * Deserialize a step from its JSON representation. Will call
267
233
  * through to the step class' own implementation of this method.
268
234
  */
269
-
270
-
271
235
  static fromJSON(schema, json) {
272
236
  // TODO: Add validation. Return null if it is invalid. Check in review if this is necessary
273
237
  const cells = json.cells.map(cellsJson => {
274
- const cell = { ...cellsJson,
238
+ const cell = {
239
+ ...cellsJson,
275
240
  newCell: cellsJson.newCell ? schema.nodeFromJSON(cellsJson.newCell) : undefined
276
241
  };
277
242
  return cell;
278
243
  });
279
244
  let sideEffects;
280
-
281
245
  if (json.sideEffects) {
282
246
  sideEffects = SideEffectsHandler.fromJSON(schema, json.sideEffects);
283
247
  }
284
-
285
248
  return new AddColumnStep(json.tablePos, {
286
249
  cells,
287
250
  sideEffects
288
251
  }, json.isDelete);
289
252
  }
290
-
291
253
  static create(doc, tablePos, column, isDelete = false) {
292
- const tableRect = getTableRectFromDoc(doc, tablePos); // By default add column will rely on default behaviour (add empty cell).
293
- // There is no need to add content
254
+ const tableRect = getTableRectFromDoc(doc, tablePos);
294
255
 
256
+ // By default add column will rely on default behaviour (add empty cell).
257
+ // There is no need to add content
295
258
  const cells = [];
296
259
  const iter = cellsAtColumn(tableRect, column);
297
260
  let next = iter.next();
298
-
299
261
  while (!next.done) {
300
262
  const cell = next.value;
301
263
  cells.push(createCellStep(cell, column, isDelete));
302
264
  let skipRows = 0;
303
-
304
265
  if (cell.attrs && cell.attrs.rowspan) {
305
266
  skipRows = cell.attrs.rowspan - 1;
306
267
  }
307
-
308
268
  next = iter.next(skipRows);
309
269
  }
310
-
311
270
  return new AddColumnStep(tablePos, {
312
271
  cells
313
272
  }, isDelete);
314
273
  }
315
-
316
274
  applyCellSteps(tr, tableRect, column, isDelete) {
317
275
  const newColumnInfo = new Map();
318
276
  const rowsHandler = this.sideEffectsHandler.rows.start(this.isDelete);
319
277
  const iter = cellsAtColumn(tableRect, column);
320
- let next = iter.next(); // Iterate for all the cells in the current document
321
-
278
+ let next = iter.next();
279
+ // Iterate for all the cells in the current document
322
280
  while (!next.done) {
323
281
  const cell = next.value;
324
282
  const previousCellStep = this.columnInfo.get(cell.from);
325
- const newCellStep = createCellStep(cell, column, isDelete, previousCellStep); // If is the last cell in the row and doesnt have colspan I need to remove the whole row.
283
+ const newCellStep = createCellStep(cell, column, isDelete, previousCellStep);
326
284
 
285
+ // If is the last cell in the row and doesnt have colspan I need to remove the whole row.
327
286
  const removeRowResult = rowsHandler.handle(tr, tableRect, cell.row, column, cell);
328
-
329
287
  if (removeRowResult.handled) {
330
288
  next = iter.next(removeRowResult.skipRows);
331
289
  continue;
332
- } // Apply the step, to the pseudo document, get rows to skip, and the cellstep (might be modified, for example, a merge cell that remove the cell instead)
333
-
290
+ }
334
291
 
292
+ // Apply the step, to the pseudo document, get rows to skip, and the cellstep (might be modified, for example, a merge cell that remove the cell instead)
335
293
  const {
336
294
  skipRows,
337
295
  cellStep
338
- } = applyCellStep(tr, tableRect, cell, newCellStep, isDelete, column); // Store the new cell step. This could be an existing one or a new cell.
296
+ } = applyCellStep(tr, tableRect, cell, newCellStep, isDelete, column);
339
297
 
298
+ // Store the new cell step. This could be an existing one or a new cell.
340
299
  newColumnInfo.set(newCellStep.from, cellStep);
341
300
  next = iter.next(skipRows);
342
301
  }
343
-
344
302
  rowsHandler.end(tr, tableRect, column);
345
303
  return newColumnInfo;
346
304
  }
347
-
348
305
  }
349
306
  Step.jsonID(ADD_COLUMN_STEP, AddColumnStep);
@@ -1,5 +1,4 @@
1
1
  export let SortOrder;
2
-
3
2
  (function (SortOrder) {
4
3
  SortOrder["ASC"] = "asc";
5
4
  SortOrder["DESC"] = "desc";
@@ -8,34 +8,27 @@ export class TableSortStep extends Step {
8
8
  this.next = next;
9
9
  this.pos = pos;
10
10
  }
11
-
12
11
  invert() {
13
12
  return new TableSortStep(this.pos, this.next, this.prev);
14
13
  }
15
-
16
14
  apply(doc) {
17
15
  return StepResult.ok(doc);
18
16
  }
19
-
20
17
  map() {
21
18
  return null;
22
19
  }
23
-
24
20
  getMap() {
25
21
  return new StepMap([0, 0, 0]);
26
22
  }
27
-
28
23
  toJSON() {
29
24
  return {
30
25
  stepType: tableSortingStepType
31
26
  };
32
27
  }
33
-
34
28
  static fromJSON() {
35
29
  return new ReplaceStep(0, 0, Slice.empty);
36
30
  }
37
-
38
31
  }
39
- /** Register this step with Prosemirror */
40
32
 
33
+ /** Register this step with Prosemirror */
41
34
  Step.jsonID(tableSortingStepType, TableSortStep);
@@ -1,13 +1,12 @@
1
1
  import { addColSpan, removeColSpan } from '@atlaskit/editor-tables/utils';
2
2
  const EmptyCellNodeSize = 4;
3
-
4
3
  function calculateRowsToSkip(attrs) {
5
4
  if (attrs && attrs.rowspan) {
6
5
  return attrs.rowspan - 1;
7
6
  }
8
-
9
7
  return 0;
10
8
  }
9
+
11
10
  /**
12
11
  * Given a cell step, this function has to do the specific transformation to executed that step.
13
12
  * It returns the applied cellStep and rows that needs to skip (because it was already handled).
@@ -18,15 +17,12 @@ function calculateRowsToSkip(attrs) {
18
17
  * @param isDelete
19
18
  * @param column
20
19
  */
21
-
22
-
23
20
  export function applyCellStep(tr, tableRect, cell, cellStep, isDelete, column) {
24
21
  // Apply the merge actions,
25
22
  if (cellStep.mergeWith !== undefined) {
26
23
  let cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.mergeWith));
27
24
  const columns = column - tableRect.map.colCount(cellStep.mergeWith - tableRect.tableStart);
28
25
  const cellAttrs = isDelete ? removeColSpan(cellNode.attrs, columns) : addColSpan(cellNode.attrs, columns);
29
-
30
26
  if (cellAttrs.colspan > 0) {
31
27
  // When colspan is 0 should remove the cell
32
28
  tr.setNodeMarkup(tr.mapping.map(cellStep.mergeWith), undefined, cellAttrs);
@@ -35,17 +31,16 @@ export function applyCellStep(tr, tableRect, cell, cellStep, isDelete, column) {
35
31
  skipRows: calculateRowsToSkip(cellAttrs),
36
32
  cellStep
37
33
  };
38
- } // When the new colspan is 0, I need to change the operation to a delete operation
39
- // Update cellStep with the proper data
40
-
34
+ }
41
35
 
36
+ // When the new colspan is 0, I need to change the operation to a delete operation
37
+ // Update cellStep with the proper data
42
38
  cellStep.from = cellStep.mergeWith;
43
39
  cellStep.to = cellStep.from + cellNode.nodeSize;
44
40
  cellStep.mergeWith = undefined;
45
41
  }
46
-
47
- let skipRows = 0; // Modify temporary document
48
-
42
+ let skipRows = 0;
43
+ // Modify temporary document
49
44
  if (isDelete) {
50
45
  let cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.from));
51
46
  skipRows = calculateRowsToSkip(cellNode.attrs);
@@ -58,35 +53,33 @@ export function applyCellStep(tr, tableRect, cell, cellStep, isDelete, column) {
58
53
  tr.insert(tr.mapping.map(cellStep.from), cell.type.createAndFill());
59
54
  }
60
55
  }
61
-
62
56
  return {
63
57
  tr,
64
58
  skipRows,
65
59
  cellStep
66
60
  };
67
61
  }
62
+
68
63
  /**
69
64
  * Given a cell step, this functions return un StepMap representing this action.
70
65
  * [position, oldSize, newSize]
71
66
  * @param cellStep
72
67
  * @param isDelete
73
68
  */
74
-
75
69
  export function getMapFromCellStep(cellStep, isDelete) {
76
70
  if (cellStep.mergeWith !== undefined) {
77
71
  return [cellStep.mergeWith, 1, 1];
78
72
  }
79
-
80
73
  if (isDelete) {
81
74
  return [cellStep.from, cellStep.to - cellStep.from, 0];
82
75
  } else {
83
76
  if (cellStep.newCell) {
84
77
  return [cellStep.from, 0, cellStep.newCell.nodeSize];
85
78
  }
86
-
87
79
  return [cellStep.from, 0, EmptyCellNodeSize];
88
80
  }
89
81
  }
82
+
90
83
  /**
91
84
  * Helper to calculate the offset of the inverted cells.
92
85
  * When you delete consecutive rows in a single step, the position in the generated document
@@ -95,15 +88,14 @@ export function getMapFromCellStep(cellStep, isDelete) {
95
88
  * @param cellStep
96
89
  * @param isDelete
97
90
  */
98
-
99
91
  function getOffset(map, cellStep, isDelete) {
100
92
  if (isDelete) {
101
93
  return map.map(cellStep.from) - cellStep.from;
102
94
  }
103
-
104
95
  const [, oldSize, newSize] = getMapFromCellStep(cellStep, isDelete);
105
96
  return map.map(cellStep.from) - cellStep.from - (newSize - oldSize);
106
97
  }
98
+
107
99
  /**
108
100
  * Given a cell step, this function invert that step.
109
101
  * @param doc
@@ -112,8 +104,6 @@ function getOffset(map, cellStep, isDelete) {
112
104
  * @param isDelete
113
105
  * @param stepMap
114
106
  */
115
-
116
-
117
107
  export function invertCellStep(doc, getTableRectAndColumn, cellStep, isDelete, stepMap) {
118
108
  /**
119
109
  * We need a correct map when a cell is added
@@ -135,40 +125,38 @@ export function invertCellStep(doc, getTableRectAndColumn, cellStep, isDelete, s
135
125
  * For a delete action this not happen, it will always return the right value
136
126
  */
137
127
  const offset = getOffset(stepMap, cellStep, isDelete);
138
- const newCellStepInfo = { ...cellStep,
128
+ const newCellStepInfo = {
129
+ ...cellStep,
139
130
  // Map the position to position of the generated document
140
131
  from: cellStep.from + offset,
141
132
  to: cellStep.to + offset
142
133
  };
143
-
144
134
  if (cellStep.mergeWith !== undefined) {
145
135
  newCellStepInfo.mergeWith = cellStep.mergeWith + offset;
146
136
  }
147
-
148
137
  if (isDelete) {
149
138
  // Add the removed cell as the new cell of the inverted step
150
139
  const removedCell = doc.nodeAt(cellStep.from);
151
- newCellStepInfo.newCell = removedCell.copy(removedCell.content); // When we delete a column we can end in a position that doesnt represent the right column.
140
+ newCellStepInfo.newCell = removedCell.copy(removedCell.content);
141
+
142
+ // When we delete a column we can end in a position that doesnt represent the right column.
152
143
  // This only happens on merged cell that ends in the deleted column.
153
144
  // We need to remap this position to the "next" cell (AKA cellStep.to)
154
-
155
145
  const {
156
146
  column,
157
147
  rect
158
148
  } = getTableRectAndColumn();
159
-
160
149
  if (column < rect.map.width) {
161
150
  const isAtTheEnd = rect.map.colCount(cellStep.from - rect.tableStart) + removedCell.attrs.colspan - 1 === column;
162
-
163
151
  if (cellStep.mergeWith !== undefined && isAtTheEnd) {
164
152
  newCellStepInfo.mergeWith = newCellStepInfo.from;
165
153
  newCellStepInfo.from = newCellStepInfo.to;
166
154
  }
167
155
  }
168
156
  }
169
-
170
157
  return newCellStepInfo;
171
158
  }
159
+
172
160
  /**
173
161
  * Create a cell step based on the current cell and operation (add/delete)
174
162
  * @param cell
@@ -176,29 +164,24 @@ export function invertCellStep(doc, getTableRectAndColumn, cellStep, isDelete, s
176
164
  * @param isDelete
177
165
  * @param previousCellStep
178
166
  */
179
-
180
167
  export function createCellStep(cell, column, isDelete, previousCellStep) {
181
168
  const newCellStepInfo = {
182
169
  from: cell.from,
183
170
  to: cell.to
184
171
  };
185
-
186
172
  if (cell.hasMergedCells) {
187
173
  // Check what column has to merge
188
174
  if (column !== cell.col || isDelete) {
189
175
  newCellStepInfo.mergeWith = cell.from;
190
176
  }
191
177
  }
192
-
193
178
  if (previousCellStep) {
194
179
  if (previousCellStep.mergeWith !== undefined) {
195
180
  newCellStepInfo.mergeWith = previousCellStep.mergeWith;
196
181
  }
197
-
198
182
  if (previousCellStep.newCell) {
199
183
  newCellStepInfo.newCell = previousCellStep.newCell;
200
184
  }
201
185
  }
202
-
203
186
  return newCellStepInfo;
204
187
  }
@@ -1,6 +1,5 @@
1
1
  import { columnIsHeader, tableNodeTypes } from '@atlaskit/editor-tables/utils';
2
2
  import { getCellIndex, hasMergedColumns, isRootRow } from './table-map';
3
-
4
3
  /**
5
4
  * Helper to have a consistent way to iterate for all the cells in a column.
6
5
  * You can skip rows by passing the rows to skipped in the next arguments.
@@ -15,23 +14,21 @@ export function* cellsAtColumn(rect, col) {
15
14
  table
16
15
  } = rect;
17
16
  let refColumn = col > 0 ? -1 : 0;
18
-
19
17
  if (columnIsHeader(map, table, col + refColumn)) {
20
18
  refColumn = col === 0 || col === map.width ? null : 0;
21
19
  }
22
-
23
20
  for (let row = 0; row < map.height; row++) {
24
21
  let index = getCellIndex(rect.map, row, col);
25
- let pos = map.map[index]; // We only consider to has merged cell to the first cell in a rowspan.
22
+ let pos = map.map[index];
26
23
 
27
- const hasMergedCells = hasMergedColumns(rect.map, row, col) && isRootRow(rect.map, row, col); // If this position falls inside a col-spanning cell
24
+ // We only consider to has merged cell to the first cell in a rowspan.
25
+ const hasMergedCells = hasMergedColumns(rect.map, row, col) && isRootRow(rect.map, row, col);
28
26
 
27
+ // If this position falls inside a col-spanning cell
29
28
  let type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
30
-
31
29
  if (!hasMergedCells) {
32
30
  pos = map.positionAt(row, col, table);
33
31
  }
34
-
35
32
  let cell = table.nodeAt(pos);
36
33
  const cellInfo = {
37
34
  from: tableStart + pos,
@@ -41,15 +38,13 @@ export function* cellsAtColumn(rect, col) {
41
38
  type,
42
39
  hasMergedCells
43
40
  };
44
-
45
41
  if (cell) {
46
42
  cellInfo.attrs = cell.attrs;
47
43
  cellInfo.to = tableStart + pos + cell.nodeSize;
48
- } // We let the consumer to pass the rows that we want to skip
49
-
44
+ }
50
45
 
46
+ // We let the consumer to pass the rows that we want to skip
51
47
  const skippedRows = yield cellInfo;
52
-
53
48
  if (skippedRows && skippedRows > 0) {
54
49
  row += skippedRows;
55
50
  }