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