@opentiny/fluent-editor 3.25.3 → 4.0.0-alpha.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 (208) hide show
  1. package/es/attributors/font-style.es.js +1 -1
  2. package/es/attributors/font-style.es.js.map +1 -1
  3. package/es/attributors/line-height.es.js +1 -1
  4. package/es/attributors/line-height.es.js.map +1 -1
  5. package/es/config/editor.utils.es.js +0 -9
  6. package/es/config/editor.utils.es.js.map +1 -1
  7. package/es/config/i18n/en-us.es.js +33 -4
  8. package/es/config/i18n/en-us.es.js.map +1 -1
  9. package/es/config/i18n/zh-cn.es.js +33 -4
  10. package/es/config/i18n/zh-cn.es.js.map +1 -1
  11. package/es/config/index.es.js +1 -2
  12. package/es/core/fluent-editor.es.js +3 -0
  13. package/es/core/fluent-editor.es.js.map +1 -1
  14. package/es/fluent-editor.es.js +12 -9
  15. package/es/fluent-editor.es.js.map +1 -1
  16. package/es/index.es.js +5 -2
  17. package/es/index.es.js.map +1 -1
  18. package/es/modules/custom-clipboard.es.js +1 -57
  19. package/es/modules/custom-clipboard.es.js.map +1 -1
  20. package/es/modules/custom-image/image-bar.es.js +2 -1
  21. package/es/modules/custom-image/image-bar.es.js.map +1 -1
  22. package/es/modules/i18n.es.js +4 -3
  23. package/es/modules/i18n.es.js.map +1 -1
  24. package/es/modules/link/index.es.js +0 -17
  25. package/es/modules/link/index.es.js.map +1 -1
  26. package/es/modules/mathlive/tooltip.es.js +8 -3
  27. package/es/modules/mathlive/tooltip.es.js.map +1 -1
  28. package/es/modules/shortcut-key/index.es.js +213 -0
  29. package/es/modules/shortcut-key/index.es.js.map +1 -0
  30. package/es/modules/table-up/index.es.js +61 -0
  31. package/es/modules/table-up/index.es.js.map +1 -0
  32. package/es/modules/toolbar/better-picker.es.js +21 -269
  33. package/es/modules/toolbar/better-picker.es.js.map +1 -1
  34. package/es/modules/toolbar/index.es.js +0 -1
  35. package/es/modules/toolbar/index.es.js.map +1 -1
  36. package/es/modules/toolbar/toolbar-tip.es.js +38 -8
  37. package/es/modules/toolbar/toolbar-tip.es.js.map +1 -1
  38. package/es/themes/snow.es.js +185 -46
  39. package/es/themes/snow.es.js.map +1 -1
  40. package/es/ui/icons.config.es.js +6 -5
  41. package/es/ui/icons.config.es.js.map +1 -1
  42. package/es/ui/icons.es.js +3 -12
  43. package/es/ui/icons.es.js.map +1 -1
  44. package/lib/attributors/font-style.cjs.js +1 -1
  45. package/lib/attributors/font-style.cjs.js.map +1 -1
  46. package/lib/attributors/line-height.cjs.js +1 -1
  47. package/lib/attributors/line-height.cjs.js.map +1 -1
  48. package/lib/config/editor.utils.cjs.js +0 -9
  49. package/lib/config/editor.utils.cjs.js.map +1 -1
  50. package/lib/config/i18n/en-us.cjs.js +33 -4
  51. package/lib/config/i18n/en-us.cjs.js.map +1 -1
  52. package/lib/config/i18n/zh-cn.cjs.js +33 -4
  53. package/lib/config/i18n/zh-cn.cjs.js.map +1 -1
  54. package/lib/config/index.cjs.js +0 -1
  55. package/lib/config/index.cjs.js.map +1 -1
  56. package/lib/core/fluent-editor.cjs.js +3 -0
  57. package/lib/core/fluent-editor.cjs.js.map +1 -1
  58. package/lib/fluent-editor.cjs.js +12 -9
  59. package/lib/fluent-editor.cjs.js.map +1 -1
  60. package/lib/index.cjs.js +7 -1
  61. package/lib/index.cjs.js.map +1 -1
  62. package/lib/modules/custom-clipboard.cjs.js +0 -56
  63. package/lib/modules/custom-clipboard.cjs.js.map +1 -1
  64. package/lib/modules/custom-image/image-bar.cjs.js +2 -1
  65. package/lib/modules/custom-image/image-bar.cjs.js.map +1 -1
  66. package/lib/modules/i18n.cjs.js +4 -3
  67. package/lib/modules/i18n.cjs.js.map +1 -1
  68. package/lib/modules/link/index.cjs.js +0 -17
  69. package/lib/modules/link/index.cjs.js.map +1 -1
  70. package/lib/modules/mathlive/tooltip.cjs.js +8 -3
  71. package/lib/modules/mathlive/tooltip.cjs.js.map +1 -1
  72. package/lib/modules/shortcut-key/index.cjs.js +213 -0
  73. package/lib/modules/shortcut-key/index.cjs.js.map +1 -0
  74. package/lib/modules/table-up/index.cjs.js +61 -0
  75. package/lib/modules/table-up/index.cjs.js.map +1 -0
  76. package/lib/modules/toolbar/better-picker.cjs.js +21 -270
  77. package/lib/modules/toolbar/better-picker.cjs.js.map +1 -1
  78. package/lib/modules/toolbar/index.cjs.js +0 -1
  79. package/lib/modules/toolbar/index.cjs.js.map +1 -1
  80. package/lib/modules/toolbar/toolbar-tip.cjs.js +38 -8
  81. package/lib/modules/toolbar/toolbar-tip.cjs.js.map +1 -1
  82. package/lib/themes/snow.cjs.js +187 -48
  83. package/lib/themes/snow.cjs.js.map +1 -1
  84. package/lib/ui/icons.cjs.js +2 -11
  85. package/lib/ui/icons.cjs.js.map +1 -1
  86. package/lib/ui/icons.config.cjs.js +6 -5
  87. package/lib/ui/icons.config.cjs.js.map +1 -1
  88. package/package.json +5 -3
  89. package/style.css +315 -2135
  90. package/types/attributors/font-style.d.ts +1 -1
  91. package/types/config/editor.config.d.ts +62 -6
  92. package/types/config/editor.utils.d.ts +0 -1
  93. package/types/config/i18n/en-us.d.ts +31 -3
  94. package/types/config/i18n/zh-cn.d.ts +31 -3
  95. package/types/config/types/toolbar-item.interface.d.ts +11 -11
  96. package/types/core/fluent-editor.d.ts +1 -0
  97. package/types/index.d.ts +2 -0
  98. package/types/modules/i18n.d.ts +1 -1
  99. package/types/modules/shortcut-key/index.d.ts +97 -0
  100. package/types/modules/table-up/index.d.ts +66 -0
  101. package/types/modules/toolbar/better-picker.d.ts +15 -0
  102. package/types/themes/snow.d.ts +10 -2
  103. package/types/ui/icons.config.d.ts +2 -2
  104. package/es/modules/global-link/constants.es.js +0 -9
  105. package/es/modules/global-link/constants.es.js.map +0 -1
  106. package/es/modules/global-link/formats/customer-widget-link.es.js +0 -28
  107. package/es/modules/global-link/formats/customer-widget-link.es.js.map +0 -1
  108. package/es/modules/global-link/formats/doc-link.es.js +0 -42
  109. package/es/modules/global-link/formats/doc-link.es.js.map +0 -1
  110. package/es/modules/global-link/formats/wiki-link.es.js +0 -34
  111. package/es/modules/global-link/formats/wiki-link.es.js.map +0 -1
  112. package/es/modules/global-link/formats/work-item-link.es.js +0 -36
  113. package/es/modules/global-link/formats/work-item-link.es.js.map +0 -1
  114. package/es/modules/global-link/global-link-panel.es.js +0 -2
  115. package/es/modules/global-link/global-link-panel.es.js.map +0 -1
  116. package/es/modules/global-link/index.es.js +0 -139
  117. package/es/modules/global-link/index.es.js.map +0 -1
  118. package/es/modules/global-link/utils/createTable.es.js +0 -50
  119. package/es/modules/global-link/utils/createTable.es.js.map +0 -1
  120. package/es/modules/quick-menu.es.js +0 -82
  121. package/es/modules/quick-menu.es.js.map +0 -1
  122. package/es/modules/table/better-table.es.js +0 -485
  123. package/es/modules/table/better-table.es.js.map +0 -1
  124. package/es/modules/table/formats/header.es.js +0 -94
  125. package/es/modules/table/formats/header.es.js.map +0 -1
  126. package/es/modules/table/formats/list.es.js +0 -163
  127. package/es/modules/table/formats/list.es.js.map +0 -1
  128. package/es/modules/table/formats/table.es.js +0 -969
  129. package/es/modules/table/formats/table.es.js.map +0 -1
  130. package/es/modules/table/modules/table-column-tool.es.js +0 -400
  131. package/es/modules/table/modules/table-column-tool.es.js.map +0 -1
  132. package/es/modules/table/modules/table-operation-menu.es.js +0 -475
  133. package/es/modules/table/modules/table-operation-menu.es.js.map +0 -1
  134. package/es/modules/table/modules/table-scroll-bar.es.js +0 -190
  135. package/es/modules/table/modules/table-scroll-bar.es.js.map +0 -1
  136. package/es/modules/table/modules/table-selection.es.js +0 -305
  137. package/es/modules/table/modules/table-selection.es.js.map +0 -1
  138. package/es/modules/table/modules/table-selector.es.js +0 -158
  139. package/es/modules/table/modules/table-selector.es.js.map +0 -1
  140. package/es/modules/table/table-config.es.js +0 -74
  141. package/es/modules/table/table-config.es.js.map +0 -1
  142. package/es/modules/table/utils/index.es.js +0 -54
  143. package/es/modules/table/utils/index.es.js.map +0 -1
  144. package/es/modules/table/utils/node-matchers.es.js +0 -292
  145. package/es/modules/table/utils/node-matchers.es.js.map +0 -1
  146. package/lib/modules/global-link/constants.cjs.js +0 -9
  147. package/lib/modules/global-link/constants.cjs.js.map +0 -1
  148. package/lib/modules/global-link/formats/customer-widget-link.cjs.js +0 -28
  149. package/lib/modules/global-link/formats/customer-widget-link.cjs.js.map +0 -1
  150. package/lib/modules/global-link/formats/doc-link.cjs.js +0 -42
  151. package/lib/modules/global-link/formats/doc-link.cjs.js.map +0 -1
  152. package/lib/modules/global-link/formats/wiki-link.cjs.js +0 -34
  153. package/lib/modules/global-link/formats/wiki-link.cjs.js.map +0 -1
  154. package/lib/modules/global-link/formats/work-item-link.cjs.js +0 -36
  155. package/lib/modules/global-link/formats/work-item-link.cjs.js.map +0 -1
  156. package/lib/modules/global-link/global-link-panel.cjs.js +0 -2
  157. package/lib/modules/global-link/global-link-panel.cjs.js.map +0 -1
  158. package/lib/modules/global-link/index.cjs.js +0 -139
  159. package/lib/modules/global-link/index.cjs.js.map +0 -1
  160. package/lib/modules/global-link/utils/createTable.cjs.js +0 -50
  161. package/lib/modules/global-link/utils/createTable.cjs.js.map +0 -1
  162. package/lib/modules/quick-menu.cjs.js +0 -82
  163. package/lib/modules/quick-menu.cjs.js.map +0 -1
  164. package/lib/modules/table/better-table.cjs.js +0 -485
  165. package/lib/modules/table/better-table.cjs.js.map +0 -1
  166. package/lib/modules/table/formats/header.cjs.js +0 -94
  167. package/lib/modules/table/formats/header.cjs.js.map +0 -1
  168. package/lib/modules/table/formats/list.cjs.js +0 -163
  169. package/lib/modules/table/formats/list.cjs.js.map +0 -1
  170. package/lib/modules/table/formats/table.cjs.js +0 -969
  171. package/lib/modules/table/formats/table.cjs.js.map +0 -1
  172. package/lib/modules/table/modules/table-column-tool.cjs.js +0 -400
  173. package/lib/modules/table/modules/table-column-tool.cjs.js.map +0 -1
  174. package/lib/modules/table/modules/table-operation-menu.cjs.js +0 -475
  175. package/lib/modules/table/modules/table-operation-menu.cjs.js.map +0 -1
  176. package/lib/modules/table/modules/table-scroll-bar.cjs.js +0 -190
  177. package/lib/modules/table/modules/table-scroll-bar.cjs.js.map +0 -1
  178. package/lib/modules/table/modules/table-selection.cjs.js +0 -305
  179. package/lib/modules/table/modules/table-selection.cjs.js.map +0 -1
  180. package/lib/modules/table/modules/table-selector.cjs.js +0 -158
  181. package/lib/modules/table/modules/table-selector.cjs.js.map +0 -1
  182. package/lib/modules/table/table-config.cjs.js +0 -74
  183. package/lib/modules/table/table-config.cjs.js.map +0 -1
  184. package/lib/modules/table/utils/index.cjs.js +0 -54
  185. package/lib/modules/table/utils/index.cjs.js.map +0 -1
  186. package/lib/modules/table/utils/node-matchers.cjs.js +0 -292
  187. package/lib/modules/table/utils/node-matchers.cjs.js.map +0 -1
  188. package/types/modules/global-link/constants.d.ts +0 -3
  189. package/types/modules/global-link/formats/customer-widget-link.d.ts +0 -14
  190. package/types/modules/global-link/formats/doc-link.d.ts +0 -17
  191. package/types/modules/global-link/formats/wiki-link.d.ts +0 -16
  192. package/types/modules/global-link/formats/work-item-link.d.ts +0 -16
  193. package/types/modules/global-link/global-link-panel.d.ts +0 -19
  194. package/types/modules/global-link/index.d.ts +0 -18
  195. package/types/modules/global-link/utils/createTable.d.ts +0 -1
  196. package/types/modules/quick-menu.d.ts +0 -22
  197. package/types/modules/table/better-table.d.ts +0 -35
  198. package/types/modules/table/formats/header.d.ts +0 -23
  199. package/types/modules/table/formats/list.d.ts +0 -34
  200. package/types/modules/table/formats/table.d.ts +0 -147
  201. package/types/modules/table/modules/table-column-tool.d.ts +0 -23
  202. package/types/modules/table/modules/table-operation-menu.d.ts +0 -38
  203. package/types/modules/table/modules/table-scroll-bar.d.ts +0 -33
  204. package/types/modules/table/modules/table-selection.d.ts +0 -37
  205. package/types/modules/table/modules/table-selector.d.ts +0 -22
  206. package/types/modules/table/table-config.d.ts +0 -38
  207. package/types/modules/table/utils/index.d.ts +0 -17
  208. package/types/modules/table/utils/node-matchers.d.ts +0 -9
@@ -1,969 +0,0 @@
1
- import Quill from "quill";
2
- import { isNullOrUndefined } from "../../../config/editor.utils.es.js";
3
- import { compare } from "../../../utils/method.es.js";
4
- import { CELL_IDENTITY_KEYS, CELL_ATTRIBUTES, CELL_DEFAULT, COL_ATTRIBUTES, COL_DEFAULT, ERROR_LIMIT, CELL_MIN_HEIGHT } from "../table-config.es.js";
5
- import { getRelativeRect } from "../utils/index.es.js";
6
- import Header from "./header.es.js";
7
- import ListItem, { ListContainer } from "./list.es.js";
8
- const Break = Quill.imports["blots/break"];
9
- const Block = Quill.imports["blots/block"];
10
- const Container = Quill.imports["blots/container"];
11
- class TableCellLine extends Block {
12
- static create(value) {
13
- const node = super.create(value);
14
- if (value.tdBgColor) {
15
- node.setAttribute(`data-parent-bg`, value.tdBgColor);
16
- delete value.tdBgColor;
17
- }
18
- CELL_IDENTITY_KEYS.forEach((key) => {
19
- const identityMaker = key === "row" ? rowId : cellId;
20
- node.setAttribute(`data-${key}`, value[key] || identityMaker());
21
- });
22
- CELL_ATTRIBUTES.forEach((attrName) => {
23
- const keyValue = value[attrName] || CELL_DEFAULT[attrName];
24
- keyValue && node.setAttribute(`data-${attrName}`, keyValue);
25
- });
26
- if (value.height) {
27
- node.setAttribute("height", value.height);
28
- }
29
- return node;
30
- }
31
- static formats(domNode) {
32
- const formats = {};
33
- if (formats.list) {
34
- formats.list = domNode.classList.item(0);
35
- }
36
- return reduceFormats(domNode, formats);
37
- }
38
- toggleAttribute(name, value) {
39
- if (value) {
40
- this.domNode.setAttribute(name, value);
41
- } else {
42
- this.domNode.removeAttribute(name);
43
- }
44
- }
45
- formatChildren(name, value) {
46
- this.children.forEach((child) => {
47
- child.format && child.format(name, value);
48
- if (!child.domNode.style) {
49
- return;
50
- }
51
- if (child.domNode.tagName === "SPAN" && value) {
52
- child.domNode.style.backgroundColor = value;
53
- } else {
54
- child.domNode.style.backgroundColor = "initial";
55
- }
56
- });
57
- }
58
- format(name, value) {
59
- if ([...CELL_ATTRIBUTES, ...CELL_IDENTITY_KEYS, "parent-bg"].includes(name)) {
60
- if (value) {
61
- this.domNode.setAttribute(`data-${name}`, value);
62
- } else {
63
- this.domNode.removeAttribute(`data-${name}`);
64
- }
65
- } else if (name === "header") {
66
- if (!value) {
67
- return;
68
- }
69
- const { row, cell, rowspan, colspan } = TableCellLine.formats(this.domNode);
70
- super.format(name, {
71
- value,
72
- row,
73
- cell,
74
- rowspan,
75
- colspan
76
- });
77
- } else {
78
- super.format(name, value);
79
- }
80
- switch (true) {
81
- case name === "cell-bg": {
82
- this.toggleAttribute("data-cell-bg", value);
83
- }
84
- }
85
- }
86
- optimize(context) {
87
- super.optimize(context);
88
- const { row, cell, rowspan, colspan, cellBg } = this.domNode.dataset;
89
- const formats = TableCellLine.formats(this.domNode);
90
- const parentFormats = this.parent.formats();
91
- if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) {
92
- this.wrap(this.statics.requiredContainer.blotName, { row, cell, rowspan, colspan, cellBg });
93
- } else if (!compare(formats, parentFormats)) {
94
- this.parent.format("row", formats.row);
95
- this.parent.format("cell", formats.cell);
96
- this.parent.format("rowspan", formats.rowspan);
97
- this.parent.format("colspan", formats.colspan);
98
- formats["cell-bg"] && this.parent.setCellBg(formats["cell-bg"]);
99
- }
100
- const parentHeight = this.domNode.getAttribute("height");
101
- if (parentHeight) {
102
- this.parent.domNode.style.height = parentHeight;
103
- }
104
- }
105
- tableCell() {
106
- return this.parent;
107
- }
108
- }
109
- TableCellLine.blotName = "table-cell-line";
110
- TableCellLine.className = "qlbt-cell-line";
111
- TableCellLine.tagName = "DIV";
112
- class TableCell extends Container {
113
- static create(value = { row: rowId() }) {
114
- const node = super.create(value);
115
- CELL_IDENTITY_KEYS.forEach((key) => {
116
- node.setAttribute(`data-${key}`, value[key]);
117
- });
118
- CELL_ATTRIBUTES.forEach((attrName) => {
119
- if (value[attrName]) {
120
- node.setAttribute(attrName, value[attrName]);
121
- }
122
- });
123
- return node;
124
- }
125
- static formats(domNode) {
126
- const formats = {
127
- height: void 0,
128
- row: void 0
129
- };
130
- formats.height = domNode.getAttribute("height") || void 0;
131
- if (domNode.hasAttribute("data-row")) {
132
- formats.row = domNode.getAttribute("data-row");
133
- }
134
- if (domNode.hasAttribute("data-cell-bg")) {
135
- formats["cell-bg"] = domNode.getAttribute("data-cell-bg") || void 0;
136
- }
137
- return CELL_ATTRIBUTES.reduce((formats2, attribute) => {
138
- if (domNode.hasAttribute(attribute)) {
139
- formats2[attribute] = domNode.getAttribute(attribute);
140
- }
141
- return formats2;
142
- }, formats);
143
- }
144
- checkMerge() {
145
- if (super.checkMerge() && !isNullOrUndefined(this.next.children.head)) {
146
- const getCellId = (node) => {
147
- return node.formats && node.formats()[node.statics.blotName] || {
148
- cell: node.domNode.getAttribute("data-cell")
149
- };
150
- };
151
- const thisHead = getCellId(this.children.head);
152
- const thisTail = getCellId(this.children.tail);
153
- const nextHead = getCellId(this.next.children.head);
154
- const nextTail = getCellId(this.next.children.tail);
155
- return thisHead.cell === thisTail.cell && thisHead.cell === nextHead.cell && thisHead.cell === nextTail.cell;
156
- }
157
- return false;
158
- }
159
- cellOffset() {
160
- if (this.parent) {
161
- return this.parent.children.indexOf(this);
162
- }
163
- return -1;
164
- }
165
- formats() {
166
- const formats = {};
167
- if (this.domNode.hasAttribute("data-row")) {
168
- formats.row = this.domNode.getAttribute("data-row");
169
- }
170
- if (this.domNode.hasAttribute("data-cell")) {
171
- formats.cell = this.domNode.getAttribute("data-cell");
172
- }
173
- return CELL_ATTRIBUTES.reduce((tableFormats, attribute) => {
174
- if (this.domNode.hasAttribute(attribute)) {
175
- tableFormats[attribute] = this.domNode.getAttribute(attribute);
176
- }
177
- return tableFormats;
178
- }, formats);
179
- }
180
- toggleAttribute(name, value) {
181
- if (value) {
182
- this.domNode.setAttribute(name, value);
183
- } else {
184
- this.domNode.removeAttribute(name);
185
- }
186
- }
187
- formatChildren(name, value) {
188
- this.children.forEach((child) => {
189
- child.format(name, value);
190
- });
191
- }
192
- /**
193
- * this method is for TableCellLine to change cell background color
194
- * if use `format('cell-bg', value)` will loop trigger
195
- * TableCellLine.optimize -> TableCell.format -> TableCellLine.optimize ...
196
- */
197
- setCellBg(value) {
198
- if (value) {
199
- this.domNode.style.backgroundColor = value;
200
- } else {
201
- this.domNode.style.backgroundColor = "initial";
202
- }
203
- }
204
- format(name, value) {
205
- const quill = Quill.find(this.scroll.domNode.parentNode);
206
- switch (true) {
207
- case CELL_ATTRIBUTES.includes(name):
208
- this.toggleAttribute(name, value);
209
- break;
210
- case ["row", "cell"].includes(name):
211
- this.toggleAttribute(`data-${name}`, value);
212
- break;
213
- case name === "background": {
214
- const hasBgColor = this.domNode.querySelectorAll("div.qlbt-cell-line[data-parent-bg]");
215
- hasBgColor.forEach((child) => child.removeAttribute("data-parent-bg"));
216
- this.domNode.style.background = "";
217
- this.domNode.style.backgroundColor = value;
218
- this.children.head.format("parent-bg", value);
219
- break;
220
- }
221
- case name === "size": {
222
- const start = quill.getIndex(this.children.head);
223
- const total = quill.getIndex(this.children.tail) + this.children.tail.length();
224
- const length = total - start > 0 ? total - start : 0;
225
- quill.setSelection(start, length, Quill.sources.USER);
226
- quill.format(name, value, Quill.sources.USER);
227
- quill.setSelection(start);
228
- break;
229
- }
230
- case name === "cell-bg": {
231
- this.toggleAttribute("data-cell-bg", value);
232
- this.toggleAttribute("data-parent-bg", value);
233
- this.formatChildren(name, value);
234
- this.setCellBg(value);
235
- break;
236
- }
237
- }
238
- }
239
- optimize(context) {
240
- const hasBg = Array.from(this.domNode.childNodes).find((item) => item.getAttribute("data-parent-bg"));
241
- const bgColor = hasBg && hasBg.getAttribute("data-parent-bg");
242
- if (bgColor && bgColor !== this.domNode.style.backgroundColor) {
243
- this.domNode.style.backgroundColor = bgColor;
244
- }
245
- const rId = this.domNode.getAttribute("data-row");
246
- if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) {
247
- this.wrap(this.statics.requiredContainer.blotName, {
248
- row: rId
249
- });
250
- } else if (rId !== this.parent.formats().row) {
251
- this.parent.format("row", rId);
252
- }
253
- this.children.forEach((child) => {
254
- if (isNullOrUndefined(child.next)) {
255
- return;
256
- }
257
- const childFormats = this.getFormat(child.domNode);
258
- const nextFormats = this.getFormat(child.next.domNode);
259
- if (childFormats.cell !== nextFormats.cell) {
260
- const next = this.splitAfter(child);
261
- if (next) {
262
- next.optimize();
263
- }
264
- if (this.prev) {
265
- this.prev.optimize();
266
- }
267
- }
268
- });
269
- super.optimize(context);
270
- }
271
- // 兼容读取TableCell中的子blot,包括table-cell-line、line、head
272
- getFormat(domNode) {
273
- const formats = {};
274
- const firstChild = domNode.childNodes[0];
275
- if (firstChild && domNode.tagName === "OL") {
276
- formats.list = firstChild.classList.item(0);
277
- }
278
- return reduceFormats(domNode, formats);
279
- }
280
- row() {
281
- return this.parent;
282
- }
283
- rowOffset() {
284
- if (this.row()) {
285
- return -1;
286
- }
287
- return this.row().rowOffset();
288
- }
289
- table() {
290
- return this.row() && this.row().table();
291
- }
292
- }
293
- TableCell.blotName = "table";
294
- TableCell.tagName = "TD";
295
- class TableRow extends Container {
296
- static create(value) {
297
- const node = super.create(value);
298
- if (value.row) {
299
- node.setAttribute("data-row", value.row);
300
- }
301
- return node;
302
- }
303
- checkMerge() {
304
- if (super.checkMerge() && !isNullOrUndefined(this.next.children.head)) {
305
- const thisHead = this.children.head.formats();
306
- const thisTail = this.children.tail.formats();
307
- const nextHead = this.next.children.head.formats();
308
- const nextTail = this.next.children.tail.formats();
309
- return thisHead.row === thisTail.row && thisHead.row === nextHead.row && thisHead.row === nextTail.row;
310
- }
311
- return false;
312
- }
313
- formats() {
314
- return ["row"].reduce((formats, attrName) => {
315
- if (this.domNode.hasAttribute(`data-${attrName}`)) {
316
- formats[attrName] = this.domNode.getAttribute(`data-${attrName}`);
317
- }
318
- return formats;
319
- }, {});
320
- }
321
- format(key, value) {
322
- this.domNode.setAttribute(`data-${key}`, value);
323
- }
324
- optimize(context) {
325
- if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) {
326
- this.wrap(this.statics.requiredContainer.blotName);
327
- }
328
- this.children.forEach((child) => {
329
- if (isNullOrUndefined(child.next)) {
330
- return;
331
- }
332
- const childFormats = child.formats();
333
- const nextFormats = child.next.formats();
334
- if (childFormats.row !== nextFormats.row) {
335
- const next = this.splitAfter(child);
336
- if (next) {
337
- next.optimize();
338
- }
339
- if (this.prev) {
340
- this.prev.optimize();
341
- }
342
- }
343
- });
344
- super.optimize(context);
345
- }
346
- rowOffset() {
347
- if (!this.parent) {
348
- return -1;
349
- }
350
- return this.parent.children.indexOf(this);
351
- }
352
- table() {
353
- return this.parent && this.parent.parent;
354
- }
355
- }
356
- TableRow.blotName = "table-row";
357
- TableRow.tagName = "TR";
358
- class TableBody extends Container {
359
- }
360
- TableBody.blotName = "table-body";
361
- TableBody.tagName = "TBODY";
362
- class TableCol extends Block {
363
- static create(value) {
364
- const node = super.create(value);
365
- COL_ATTRIBUTES.forEach((attrName) => {
366
- node.setAttribute(`${attrName}`, value[attrName] || COL_DEFAULT[attrName]);
367
- });
368
- return node;
369
- }
370
- static formats(domNode) {
371
- return COL_ATTRIBUTES.reduce((formats, attribute) => {
372
- if (domNode.hasAttribute(`${attribute}`)) {
373
- formats[attribute] = domNode.getAttribute(`${attribute}`) || void 0;
374
- }
375
- return formats;
376
- }, {});
377
- }
378
- format(name, value) {
379
- if (COL_ATTRIBUTES.includes(name)) {
380
- this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]);
381
- } else {
382
- super.format(name, value);
383
- }
384
- }
385
- html() {
386
- return this.domNode.outerHTML;
387
- }
388
- }
389
- TableCol.blotName = "table-col";
390
- TableCol.tagName = "col";
391
- class TableColGroup extends Container {
392
- optimize(context) {
393
- super.optimize(context);
394
- if (this.parent && this.statics.requiredContainer && this.parent instanceof this.statics.requiredContainer) {
395
- this.parent.updateTableWidth();
396
- }
397
- if (this.parent.parent.domNode.className === "quill-better-table-wrapper" && this.parent.parent.domNode.tagName === "DIV" && this.parent.domNode.children.length >= 2 && this.parent.domNode.children[0].tagName === "COLGROUP" && this.parent.domNode.children[1].tagName === "TBODY") {
398
- let trId = "";
399
- let colSpan = 0;
400
- let colgroupNumber = 0;
401
- for (let i = 0; i < this.parent.domNode.children.length; i++) {
402
- if (this.parent.domNode.children[i].tagName === "TBODY") {
403
- if (trId === "") {
404
- trId = this.parent.domNode.children[i].children[0].getAttribute("data-row");
405
- }
406
- colSpan = this.findTdColspanInTbody(this.parent.domNode.children[i], trId);
407
- } else if (this.parent.domNode.children[i].tagName === "COLGROUP") {
408
- colgroupNumber = this.parent.domNode.children[i].children.length;
409
- }
410
- }
411
- let elementSibling = this.parent.domNode.nextElementSibling;
412
- while (elementSibling && elementSibling.tagName === "TABLE") {
413
- for (let i = 0; i < elementSibling.children.length; i++) {
414
- if (elementSibling.children[i].tagName === "TBODY") {
415
- colSpan += this.findTdColspanInTbody(elementSibling.children[i], trId);
416
- }
417
- }
418
- elementSibling = elementSibling.nextElementSibling;
419
- }
420
- if (colgroupNumber < colSpan) {
421
- const length = colSpan - colgroupNumber;
422
- for (let i = 0; i < length; i++) {
423
- const newCol = document.createElement("col");
424
- newCol.width = this.parent.domNode.children[0].children[this.parent.domNode.children[0].children.length - 1].width;
425
- const newBr = document.createElement("br");
426
- newCol.appendChild(newBr);
427
- this.parent.domNode.children[0].appendChild(newCol);
428
- this.parent.domNode.style.width += newCol.width;
429
- }
430
- }
431
- }
432
- }
433
- // this.parent.domNode.children[1].children[0].children[0].colSpan
434
- findTdColspanInTbody(tbody, trId) {
435
- let colSpan = 0;
436
- for (let i = 0; i < tbody.children.length; i++) {
437
- if (tbody.children[i].getAttribute("data-row") !== trId) {
438
- return colSpan;
439
- }
440
- for (let j = 0; j < tbody.children[i].children.length; j++) {
441
- if (tbody.children[i].children[j].colSpan) {
442
- colSpan += tbody.children[i].children[j].colSpan;
443
- }
444
- }
445
- }
446
- return colSpan;
447
- }
448
- }
449
- TableColGroup.blotName = "table-col-group";
450
- TableColGroup.tagName = "colgroup";
451
- class TableContainer extends Container {
452
- static create() {
453
- const node = super.create();
454
- return node;
455
- }
456
- constructor(scroll, domNode) {
457
- super(scroll, domNode);
458
- domNode.setAttribute("contenteditable", false);
459
- this.updateTableWidth();
460
- }
461
- updateTableWidth() {
462
- let colGroup = this.colGroup();
463
- if (!colGroup) {
464
- if (this.parent && this.parent.children.head && this.domNode.hasAttribute("style")) {
465
- colGroup = this.parent.children.head.children.head;
466
- this.domNode = this.parent.children.head.domNode;
467
- } else if (this.domNode.tagName === "TABLE") {
468
- return;
469
- } else {
470
- return;
471
- }
472
- }
473
- const tableWidth = colGroup.children.reduce((sumWidth, col) => {
474
- const tableCol = col.formats()[TableCol.blotName];
475
- let tableColWidth = COL_DEFAULT.width;
476
- if (tableCol && tableCol.width) {
477
- tableColWidth = Number.parseInt(tableCol.width, 10);
478
- }
479
- sumWidth = sumWidth + tableColWidth;
480
- return sumWidth;
481
- }, 0);
482
- this.domNode.removeAttribute("style");
483
- this.domNode.style.width = `${tableWidth}px`;
484
- if (colGroup.next) {
485
- setTimeout(() => {
486
- let tdIndex = 0;
487
- let maxTds;
488
- const colNum = colGroup.children.length;
489
- const tableRows = this.descendants(TableRow);
490
- for (let i = 0; i < tableRows.length; i++) {
491
- const tds = tableRows[i].domNode.querySelectorAll("td");
492
- if (tds.length === colNum) {
493
- maxTds = tds;
494
- break;
495
- }
496
- }
497
- colGroup.children.forEach((col) => {
498
- if (maxTds && col.domNode.width === "auto") {
499
- const width = getComputedStyle(maxTds[tdIndex]).width;
500
- const num = Number.parseInt(width, 10);
501
- col.domNode.width = num < COL_DEFAULT.width && COL_DEFAULT.width || num;
502
- }
503
- tdIndex++;
504
- });
505
- });
506
- }
507
- }
508
- cells(column) {
509
- return this.rows().map((row) => row.children.at(column));
510
- }
511
- colGroup() {
512
- return this.children.head;
513
- }
514
- deleteColumns(compareRect, delIndexes = [], editorWrapper) {
515
- const [body] = this.descendants(TableBody);
516
- if (isNullOrUndefined(body) || isNullOrUndefined(body.children.head)) {
517
- return;
518
- }
519
- const tableCells = this.descendants(TableCell);
520
- const removedCells = [];
521
- const modifiedCells = [];
522
- tableCells.forEach((cell) => {
523
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
524
- if (cellRect.x + ERROR_LIMIT > compareRect.x && cellRect.x1 - ERROR_LIMIT < compareRect.x1) {
525
- removedCells.push(cell);
526
- } else if (cellRect.x < compareRect.x + ERROR_LIMIT && cellRect.x1 > compareRect.x1 - ERROR_LIMIT) {
527
- modifiedCells.push(cell);
528
- }
529
- });
530
- if (removedCells.length === tableCells.length) {
531
- this.tableDestroy();
532
- return true;
533
- }
534
- delIndexes.forEach(() => {
535
- const col = this.colGroup().children.at(delIndexes[0]);
536
- if (!col || this.colGroup().children.at(delIndexes[0]).domNode !== this.colGroup().domNode.children[delIndexes[0]]) {
537
- this.colGroup().domNode.removeChild(this.colGroup().domNode.children[delIndexes[0]]);
538
- } else {
539
- col.remove();
540
- }
541
- });
542
- removedCells.forEach((cell) => {
543
- cell.remove();
544
- });
545
- modifiedCells.forEach((cell) => {
546
- const cellColspan = Number.parseInt(cell.formats().colspan, 10);
547
- cell.format("colspan", cellColspan - delIndexes.length);
548
- });
549
- this.updateTableWidth();
550
- }
551
- deleteRow(compareRect, editorWrapper) {
552
- const [body] = this.descendants(TableBody);
553
- if (isNullOrUndefined(body) || isNullOrUndefined(body.children.head)) {
554
- return;
555
- }
556
- const tableCells = this.descendants(TableCell);
557
- const tableRows = this.descendants(TableRow);
558
- const removedCells = [];
559
- const modifiedCells = [];
560
- const fallCells = [];
561
- tableCells.forEach((cell) => {
562
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
563
- if (cellRect.y > compareRect.y - ERROR_LIMIT && cellRect.y1 < compareRect.y1 + ERROR_LIMIT) {
564
- removedCells.push(cell);
565
- } else if (cellRect.y < compareRect.y + ERROR_LIMIT && cellRect.y1 > compareRect.y1 - ERROR_LIMIT) {
566
- modifiedCells.push(cell);
567
- if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) {
568
- fallCells.push(cell);
569
- }
570
- }
571
- });
572
- if (removedCells.length === tableCells.length) {
573
- this.tableDestroy();
574
- return;
575
- }
576
- const removedRowsLength = this.rows().reduce((sum, row) => {
577
- const rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper);
578
- if (rowRect.y > compareRect.y - ERROR_LIMIT && rowRect.y1 < compareRect.y1 + ERROR_LIMIT) {
579
- sum += 1;
580
- }
581
- return sum;
582
- }, 0);
583
- fallCells.forEach((cell) => {
584
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
585
- const nextRow = cell.parent.next;
586
- const cellsInNextRow = nextRow.children;
587
- const refCell = cellsInNextRow.reduce((ref, compareCell) => {
588
- const compareCellRect = getRelativeRect(compareCell.domNode.getBoundingClientRect(), editorWrapper);
589
- if (cellRect.x1 - compareCellRect.x < ERROR_LIMIT) {
590
- ref = compareCell;
591
- }
592
- return ref;
593
- }, null);
594
- nextRow.insertBefore(cell, refCell);
595
- const curRowId = nextRow.formats().row;
596
- cell.format("row", curRowId);
597
- cell.children.forEach((cellLine) => {
598
- cellLine.format("row", curRowId);
599
- });
600
- });
601
- modifiedCells.forEach((cell) => {
602
- const cellRowspan = Number.parseInt(cell.formats().rowspan, 10);
603
- const curRowspan = cellRowspan - removedRowsLength;
604
- cell.domNode.removeAttribute("style");
605
- cell.format("rowspan", curRowspan);
606
- cell.children.forEach((cellLine) => {
607
- cellLine.format("rowspan", curRowspan);
608
- });
609
- });
610
- removedCells.forEach((cell) => {
611
- cell.remove();
612
- });
613
- tableRows.forEach((row) => {
614
- if (row.children.length === 0) {
615
- row.remove();
616
- }
617
- });
618
- }
619
- tableDestroy() {
620
- const quill = Quill.find(this.scroll.domNode.parentNode);
621
- const tableModule = quill.getModule("better-table");
622
- this.remove();
623
- tableModule.hideTableTools();
624
- quill.update(Quill.sources.USER);
625
- }
626
- insertCell(tableRow, ref, bg = "") {
627
- const id = cellId();
628
- const rId = tableRow.formats().row;
629
- const tableCell = this.scroll.create(
630
- TableCell.blotName,
631
- { ...CELL_DEFAULT, row: rId }
632
- );
633
- tableCell.domNode.style.backgroundColor = bg;
634
- const cellLine = this.scroll.create(TableCellLine.blotName, {
635
- row: rId,
636
- cell: id
637
- });
638
- tableCell.appendChild(cellLine);
639
- if (ref) {
640
- tableRow.insertBefore(tableCell, ref);
641
- } else {
642
- tableRow.appendChild(tableCell);
643
- }
644
- }
645
- insertColumn(compareRect, colIndex, isRight = true, editorWrapper) {
646
- const [body] = this.descendants(TableBody);
647
- const [tableColGroup] = this.descendants(TableColGroup);
648
- const tableCols = this.descendants(TableCol);
649
- const addAsideCells = [];
650
- const modifiedCells = [];
651
- const affectedCells = [];
652
- if (isNullOrUndefined(body) || isNullOrUndefined(body.children.head)) {
653
- return;
654
- }
655
- const tableCells = this.descendants(TableCell);
656
- tableCells.forEach((cell) => {
657
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
658
- if (isRight) {
659
- if (Math.abs(cellRect.x1 - compareRect.x1) < ERROR_LIMIT) {
660
- addAsideCells.push(cell);
661
- } else if (compareRect.x1 - cellRect.x > ERROR_LIMIT && compareRect.x1 - cellRect.x1 < -ERROR_LIMIT) {
662
- modifiedCells.push(cell);
663
- }
664
- } else {
665
- if (Math.abs(cellRect.x - compareRect.x) < ERROR_LIMIT) {
666
- addAsideCells.push(cell);
667
- } else if (compareRect.x - cellRect.x > ERROR_LIMIT && compareRect.x - cellRect.x1 < -ERROR_LIMIT) {
668
- modifiedCells.push(cell);
669
- }
670
- }
671
- });
672
- addAsideCells.forEach((cell) => {
673
- const ref = isRight ? cell.next : cell;
674
- const id = cellId();
675
- const tableRow = cell.parent;
676
- const rId = tableRow.formats().row;
677
- const cellFormats = cell.formats();
678
- const tableCell = this.scroll.create(
679
- TableCell.blotName,
680
- { ...CELL_DEFAULT, row: rId, rowspan: cellFormats.rowspan }
681
- );
682
- const cellLine = this.scroll.create(TableCellLine.blotName, {
683
- row: rId,
684
- cell: id,
685
- rowspan: cellFormats.rowspan
686
- });
687
- tableCell.appendChild(cellLine);
688
- if (ref) {
689
- tableRow.insertBefore(tableCell, ref);
690
- } else {
691
- tableRow.appendChild(tableCell);
692
- }
693
- affectedCells.push(tableCell);
694
- });
695
- const tableCol = this.scroll.create(TableCol.blotName, true);
696
- let colRef;
697
- if (isRight) {
698
- colRef = tableCols[colIndex] && tableCols[colIndex].next;
699
- } else {
700
- colRef = tableCols[colIndex];
701
- }
702
- if (colRef) {
703
- tableColGroup.insertBefore(tableCol, colRef);
704
- } else {
705
- tableColGroup.appendChild(tableCol);
706
- }
707
- modifiedCells.forEach((cell) => {
708
- const cellColspan = cell.formats().colspan;
709
- cell.format("colspan", Number.parseInt(cellColspan, 10) + 1);
710
- affectedCells.push(cell);
711
- });
712
- affectedCells.sort((cellA, cellB) => {
713
- const y1 = cellA.domNode.getBoundingClientRect().y;
714
- const y2 = cellB.domNode.getBoundingClientRect().y;
715
- return y1 - y2;
716
- });
717
- this.updateTableWidth();
718
- return affectedCells;
719
- }
720
- insertRow(compareRect, isDown, editorWrapper) {
721
- const [body] = this.descendants(TableBody);
722
- if (isNullOrUndefined(body) || isNullOrUndefined(body.children.head)) {
723
- return;
724
- }
725
- const tableCells = this.descendants(TableCell);
726
- const rId = rowId();
727
- const newRow = this.scroll.create(TableRow.blotName, {
728
- row: rId
729
- });
730
- const addBelowCells = [];
731
- const modifiedCells = [];
732
- const affectedCells = [];
733
- tableCells.forEach((cell) => {
734
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
735
- if (isDown) {
736
- if (Math.abs(cellRect.y1 - compareRect.y1) < ERROR_LIMIT) {
737
- addBelowCells.push(cell);
738
- } else if (compareRect.y1 - cellRect.y > ERROR_LIMIT && compareRect.y1 - cellRect.y1 < -ERROR_LIMIT) {
739
- modifiedCells.push(cell);
740
- }
741
- } else {
742
- if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) {
743
- addBelowCells.push(cell);
744
- } else if (compareRect.y - cellRect.y > ERROR_LIMIT && compareRect.y - cellRect.y1 < -ERROR_LIMIT) {
745
- modifiedCells.push(cell);
746
- }
747
- }
748
- });
749
- const sortFunc = (cellA, cellB) => {
750
- const x1 = cellA.domNode.getBoundingClientRect().x;
751
- const x2 = cellB.domNode.getBoundingClientRect().x;
752
- return x1 - x2;
753
- };
754
- addBelowCells.sort(sortFunc);
755
- addBelowCells.forEach((cell) => {
756
- const cId = cellId();
757
- const cellFormats = cell.formats();
758
- const tableCell = this.scroll.create(
759
- TableCell.blotName,
760
- { ...CELL_DEFAULT, row: rId, cell: cId, colspan: cellFormats.colspan }
761
- );
762
- const cellLine = this.scroll.create(TableCellLine.blotName, {
763
- row: rId,
764
- cell: cId,
765
- colspan: cellFormats.colspan
766
- });
767
- const empty = this.scroll.create(Break.blotName);
768
- cellLine.appendChild(empty);
769
- tableCell.appendChild(cellLine);
770
- newRow.appendChild(tableCell);
771
- affectedCells.push(tableCell);
772
- });
773
- modifiedCells.forEach((cell) => {
774
- const cellRowspan = Number.parseInt(cell.formats().rowspan, 10);
775
- cell.format("rowspan", cellRowspan + 1);
776
- affectedCells.push(cell);
777
- });
778
- const refRow = this.rows().find((row) => {
779
- const rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper);
780
- if (isDown) {
781
- return Math.abs(rowRect.y - compareRect.y - compareRect.height) < ERROR_LIMIT;
782
- } else {
783
- return Math.abs(rowRect.y - compareRect.y) < ERROR_LIMIT;
784
- }
785
- });
786
- body.insertBefore(newRow, refRow);
787
- affectedCells.sort(sortFunc);
788
- return affectedCells;
789
- }
790
- mergeCells(_compareRect, mergingCells, rowspan, colspan, _editorWrapper) {
791
- const mergedCell = mergingCells.reduce((result, tableCell, index) => {
792
- if (index !== 0) {
793
- if (result) {
794
- tableCell.moveChildren(result);
795
- }
796
- tableCell.remove();
797
- } else {
798
- tableCell.format("colspan", colspan);
799
- tableCell.format("rowspan", rowspan);
800
- result = tableCell;
801
- if (rowspan > 1) {
802
- const minHeight = CELL_MIN_HEIGHT * rowspan + rowspan - 1;
803
- const cellHeight = Number.parseInt(tableCell.domNode.style.height, 10) || 0;
804
- if (cellHeight < minHeight) {
805
- tableCell.domNode.style.height = `${minHeight}px`;
806
- }
807
- }
808
- }
809
- return result;
810
- }, null);
811
- const rId = mergedCell.domNode.getAttribute("data-row");
812
- const cId = mergedCell.children.head.domNode.getAttribute("data-cell");
813
- mergedCell.children.forEach((cellLine) => {
814
- cellLine.domNode.setAttribute("data-parent-bg", mergedCell.domNode.style.backgroundColor);
815
- if (cellLine.children.head.domNode.style) {
816
- cellLine.children.head.domNode.style.backgroundColor = mergedCell.domNode.style.backgroundColor;
817
- }
818
- if (!cellLine.prev || cellLine.domNode.textContent.trim()) {
819
- cellLine.format("cell", cId);
820
- cellLine.format("row", rId);
821
- cellLine.format("colspan", colspan);
822
- cellLine.format("rowspan", rowspan);
823
- } else {
824
- cellLine.remove();
825
- }
826
- });
827
- return mergedCell;
828
- }
829
- unmergeCells(unmergingCells, editorWrapper) {
830
- let cellFormats = {};
831
- let cellRowspan = 1;
832
- let cellColspan = 1;
833
- unmergingCells.forEach((tableCell) => {
834
- const tableCellBgColor = tableCell.domNode.style.backgroundColor;
835
- cellFormats = tableCell.formats();
836
- cellRowspan = cellFormats.rowspan;
837
- cellColspan = cellFormats.colspan;
838
- if (cellColspan > 1) {
839
- const ref = tableCell.next;
840
- const row = tableCell.row();
841
- tableCell.format("colspan", 1);
842
- if (tableCell.domNode.children && tableCell.domNode.children[0].tagName === "DIV" && tableCell.domNode.children[0].getAttribute("data-colspan")) {
843
- tableCell.domNode.children[0].setAttribute("data-colspan", 1);
844
- }
845
- for (let colspanIndex = cellColspan; colspanIndex > 1; colspanIndex--) {
846
- this.insertCell(row, ref, tableCellBgColor);
847
- }
848
- }
849
- if (cellRowspan > 1) {
850
- let rowspanIndex = cellRowspan;
851
- let nextRow = tableCell.row().next;
852
- while (rowspanIndex > 1) {
853
- const refInNextRow = nextRow.children.reduce((result, cell) => {
854
- const compareRect = getRelativeRect(tableCell.domNode.getBoundingClientRect(), editorWrapper);
855
- const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper);
856
- if (Math.abs(compareRect.x1 - cellRect.x) < ERROR_LIMIT) {
857
- result = cell;
858
- }
859
- return result;
860
- }, null);
861
- for (let colspanIndex = cellColspan; colspanIndex > 0; colspanIndex--) {
862
- this.insertCell(nextRow, refInNextRow, tableCellBgColor);
863
- }
864
- rowspanIndex -= 1;
865
- nextRow = nextRow.next;
866
- }
867
- tableCell.domNode.removeAttribute("style");
868
- if (tableCell.domNode.children && tableCell.domNode.children[0].tagName === "DIV" && tableCell.domNode.children[0].getAttribute("data-rowspan")) {
869
- tableCell.domNode.children[0].setAttribute("data-rowspan", 1);
870
- }
871
- tableCell.format("rowspan", 1);
872
- }
873
- });
874
- }
875
- emptyCells(selectedTds) {
876
- selectedTds.forEach((selectedTd) => {
877
- const cellFormats = selectedTd.formats();
878
- const cellLine = this.scroll.create(TableCellLine.blotName, {
879
- row: cellFormats.row || rowId(),
880
- cell: cellFormats.cell || cellId(),
881
- rowspan: cellFormats.rowspan,
882
- colspan: cellFormats.colspan
883
- });
884
- const empty = this.scroll.create(Break.blotName);
885
- cellLine.appendChild(empty);
886
- selectedTd.domNode.innerHTML = "";
887
- selectedTd.appendChild(cellLine);
888
- });
889
- }
890
- rows() {
891
- const body = this.children.tail;
892
- if (isNullOrUndefined(body)) {
893
- return [];
894
- }
895
- return body.children.map((row) => row);
896
- }
897
- }
898
- TableContainer.blotName = "ql-table-container";
899
- TableContainer.className = "quill-better-table";
900
- TableContainer.tagName = "TABLE";
901
- class TableViewWrapper extends Container {
902
- constructor(scroll, domNode) {
903
- super(scroll, domNode);
904
- const quill = Quill.find(scroll.domNode.parentNode);
905
- if (quill.options.readOnly) {
906
- domNode.style.overflow = "auto";
907
- }
908
- domNode.addEventListener(
909
- "scroll",
910
- (e) => {
911
- const tableModule = quill.getModule("better-table");
912
- if (tableModule.columnTool) {
913
- tableModule.columnTool.domNode.scrollLeft = e.target.scrollLeft;
914
- }
915
- if (tableModule.tableSelection && tableModule.tableSelection.selectedTds.length > 0) {
916
- tableModule.tableSelection.repositionHelpLines();
917
- }
918
- },
919
- false
920
- );
921
- }
922
- }
923
- TableViewWrapper.blotName = "table-view";
924
- TableViewWrapper.className = "quill-better-table-wrapper";
925
- TableViewWrapper.tagName = "DIV";
926
- TableViewWrapper.allowedChildren = [TableContainer];
927
- TableContainer.requiredContainer = TableViewWrapper;
928
- TableContainer.allowedChildren = [TableBody, TableColGroup];
929
- TableBody.requiredContainer = TableContainer;
930
- TableBody.allowedChildren = [TableRow];
931
- TableRow.requiredContainer = TableBody;
932
- TableRow.allowedChildren = [TableCell];
933
- TableCell.requiredContainer = TableRow;
934
- TableCell.allowedChildren = [TableCellLine, Header, ListItem, ListContainer];
935
- TableCellLine.requiredContainer = TableCell;
936
- TableColGroup.allowedChildren = [TableCol];
937
- TableColGroup.requiredContainer = TableContainer;
938
- TableCol.requiredContainer = TableColGroup;
939
- function rowId() {
940
- const id = Math.random().toString(36).slice(2, 6);
941
- return `row-${id}`;
942
- }
943
- function cellId() {
944
- const id = Math.random().toString(36).slice(2, 6);
945
- return `cell-${id}`;
946
- }
947
- function reduceFormats(domNode, formats) {
948
- return [...CELL_ATTRIBUTES, ...CELL_IDENTITY_KEYS].reduce((tableFormats, attribute) => {
949
- if (domNode.hasAttribute(`data-${attribute}`)) {
950
- tableFormats[attribute] = domNode.getAttribute(`data-${attribute}`) || void 0;
951
- }
952
- return tableFormats;
953
- }, formats);
954
- }
955
- export {
956
- CELL_ATTRIBUTES,
957
- CELL_IDENTITY_KEYS,
958
- TableBody,
959
- TableCell,
960
- TableCellLine,
961
- TableCol,
962
- TableColGroup,
963
- TableContainer,
964
- TableRow,
965
- TableViewWrapper,
966
- cellId,
967
- rowId
968
- };
969
- //# sourceMappingURL=table.es.js.map