Skip to content

Commit c4c383d

Browse files
committed
fix: table better show grid
1 parent b99f863 commit c4c383d

File tree

13 files changed

+62
-5
lines changed

13 files changed

+62
-5
lines changed

packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
131131
table: false,
132132
"table-better": {
133133
language: "en_US",
134-
menus: ["column", "row", "merge", "table", "cell", "wrap", "copy", "delete"],
134+
menus: ["column", "row", "merge", "table", "cell", "wrap", "copy", "delete", "grid"],
135135
toolbarTable: !readOnly
136136
},
137137
toolbar

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/assets/css/quill-table-better.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $focused-border: 1px solid $focused-border-color;
7373
border: none;
7474
}
7575

76-
.ql-container:not(.ql-disabled) .ql-table-better {
76+
.ql-container:not(.ql-disabled) .ql-table-better.ql-table-grid {
7777
td {
7878
border: 1px dotted rgba(0, 0, 0, 0.1);
7979
}
@@ -663,3 +663,9 @@ ol.table-list-container {
663663
transform: translateX(1px);
664664
}
665665
}
666+
667+
.ql-table-menus-container.ql-table-grid {
668+
.grid-toggle {
669+
color: var(--link-color);
670+
}
671+
}

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/de_DE.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Danach einfügen",
1717
copyTable: "Tabelle kopieren",
1818
delTable: "Tabelle löschen",
19+
showGrid: "Raster anzeigen",
1920
border: "Rahmen",
2021
color: "Farbe",
2122
width: "Breite",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/en_US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Insert after",
1717
copyTable: "Copy table",
1818
delTable: "Delete table",
19+
showGrid: "Show grid",
1920
border: "Border",
2021
color: "Color",
2122
width: "Width",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/fr_FR.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Insérer après",
1717
copyTable: "Copier le tableau",
1818
delTable: "Supprimer le tableau",
19+
showGrid: "Afficher la grille",
1920
border: "Bordure",
2021
color: "Couleur",
2122
width: "Largeur",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/pl_PL.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Wstaw po",
1717
copyTable: "Kopiuj tabelę",
1818
delTable: "Usuń tabelę",
19+
showGrid: "Pokaż siatkę",
1920
border: "Obramowanie",
2021
color: "Kolor",
2122
width: "Szerokość",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/ru_RU.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Вставить абзац после",
1717
copyTable: "Копировать таблицу",
1818
delTable: "Удалить таблицу",
19+
showGrid: "Показать сетку",
1920
border: "Обводка",
2021
color: "Цвет",
2122
width: "Ширина",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/tr_TR.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "Sonrasına ekle",
1717
copyTable: "Tabloyu kopyala",
1818
delTable: "Tabloyu sil",
19+
showGrid: "Izgarayı göster",
1920
border: "Kenarlık",
2021
color: "Renk",
2122
width: "Genişlik",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/language/zh_CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
insAft: "在表格后面插入",
1717
copyTable: "复制表格",
1818
delTable: "删除表格",
19+
showGrid: "显示网格",
1920
border: "边框",
2021
color: "颜色",
2122
width: "宽度",

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/quill-table-better.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class Table extends Module {
196196
this.quill.updateContents(delta, Quill.sources.USER);
197197
this.quill.setSelection(range.index + _offset, Quill.sources.SILENT);
198198
this.showTools();
199+
this.tableMenus.showGrid(true);
199200
}
200201

201202
// Inserting tables within tables is currently not supported

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/ui/operate-line.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class OperateLine {
3535
this.dragTable = null;
3636
this.direction = null; // 1.level 2.vertical
3737
this.tableBetter = tableBetter;
38-
this.quill.root.addEventListener("mousemove", this.handleMouseMove.bind(this));
38+
if (!this.quill.options.readOnly) {
39+
this.quill.root.addEventListener("mousemove", this.handleMouseMove.bind(this));
40+
}
3941
}
4042

4143
createDragBlock() {

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/ui/table-menus.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,20 @@ function getMenusConfig(useLanguage: UseLanguageHandler, menus?: string[]): Menu
158158
icon: "icons icon-Cell",
159159
handler(list: HTMLUListElement, tooltip: HTMLDivElement) {
160160
const { selectedTds } = this.tableBetter.cellSelection;
161+
const isGridShown = this.isGridShown();
162+
if (isGridShown) {
163+
this.showGrid(false);
164+
}
161165
const attribute =
162166
selectedTds.length > 1
163167
? this.getSelectedTdsAttrs(selectedTds)
164168
: this.getSelectedTdAttrs(selectedTds[0]);
165169
this.toggleAttribute(list, tooltip);
166170
this.tablePropertiesForm = new TablePropertiesForm(this, { attribute, type: "cell" });
167171
this.hideMenus();
172+
if (isGridShown) {
173+
this.showGrid(true);
174+
}
168175
}
169176
},
170177
wrap: {
@@ -203,6 +210,13 @@ function getMenusConfig(useLanguage: UseLanguageHandler, menus?: string[]): Menu
203210
handler() {
204211
this.copyTable();
205212
}
213+
},
214+
grid: {
215+
content: useLanguage("showGrid"),
216+
icon: "icons icon-Table grid-toggle",
217+
handler() {
218+
this.showGrid();
219+
}
206220
}
207221
};
208222
if (menus?.length) {
@@ -259,6 +273,24 @@ class TableMenus {
259273
}
260274
}
261275

276+
isGridShown() {
277+
return this.table?.classList.contains("ql-table-grid");
278+
}
279+
280+
showGrid(isShow?: boolean) {
281+
const tableGridHelperClass = "ql-table-grid";
282+
if (isShow === undefined) {
283+
this.table?.classList.toggle(tableGridHelperClass);
284+
this.root.classList.toggle(tableGridHelperClass);
285+
} else if (isShow) {
286+
this.table?.classList.add(tableGridHelperClass);
287+
this.root.classList.add(tableGridHelperClass);
288+
} else {
289+
this.table?.classList.remove(tableGridHelperClass);
290+
this.root.classList.remove(tableGridHelperClass);
291+
}
292+
}
293+
262294
createList(children: Children) {
263295
if (!children) return null;
264296
const container = this.quill.root.ownerDocument.createElement("ul");
@@ -499,21 +531,25 @@ class TableMenus {
499531
getSelectedTdAttrs(td: HTMLElement) {
500532
const cellBlot = Quill.find(td) as TableCell;
501533
const align = getAlign(cellBlot);
534+
502535
const attr: Props = align
503536
? { ...getElementStyle(td, CELL_PROPERTIES), "text-align": align }
504537
: getElementStyle(td, CELL_PROPERTIES);
538+
console.log("getSelectedTd Attrs", align, cellBlot, attr);
505539
return attr;
506540
}
507541

508542
getSelectedTdsAttrs(selectedTds: HTMLElement[]) {
509543
const map = new Map();
510544
let attribute = null;
545+
console.log("selectedTds", selectedTds);
511546
for (const td of selectedTds) {
512547
const attr = this.getSelectedTdAttrs(td);
513548
if (!attribute) {
514549
attribute = attr;
515550
continue;
516551
}
552+
console.log("attr", attr, Object.keys(attribute));
517553
for (const key of Object.keys(attribute)) {
518554
if (map.has(key)) continue;
519555
if (attr[key] !== attribute[key]) {
@@ -695,6 +731,11 @@ class TableMenus {
695731
}
696732

697733
showMenus() {
734+
if (this.table?.classList.contains("ql-table-grid")) {
735+
this.root.classList.add("ql-table-grid");
736+
} else {
737+
this.root.classList.remove("ql-table-grid");
738+
}
698739
this.root.classList.remove("ql-hidden");
699740
}
700741

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/ui/table-properties-form.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class TablePropertiesForm {
369369
const change = this.attrs;
370370
const old = this.options.attribute;
371371
return Object.keys(change).reduce((attrs: Props, key) => {
372-
if (change[key] !== old[key]) {
372+
if (change[key] !== old[key] || key.startsWith("border")) {
373373
attrs[key] = isDimensions(key) ? addDimensionsUnit(change[key]) : change[key];
374374
}
375375
return attrs;
@@ -417,7 +417,7 @@ class TablePropertiesForm {
417417
saveCellAction() {
418418
const { selectedTds } = this.tableMenus.tableBetter.cellSelection;
419419
const { quill, table } = this.tableMenus;
420-
const colgroup = (Quill.find(table as Node) as TableContainer).colgroup();
420+
const colgroup = (Quill.find(table as Node) as TableContainer)?.colgroup();
421421
const attrs = this.getDiffProperties();
422422
const width = parseFloat(attrs["width"]);
423423
const align = attrs["text-align"];

0 commit comments

Comments
 (0)