A platform for community discussion. Free, open, simple.
UX: scrollable container for rich editor table (#36919)
Renato Atilio348ff900114a
diff --git a/frontend/discourse/app/static/prosemirror/extensions/table.js b/frontend/discourse/app/static/prosemirror/extensions/table.jsindex ec574b25bb4..280136ab1cd 100644--- a/frontend/discourse/app/static/prosemirror/extensions/table.js+++ b/frontend/discourse/app/static/prosemirror/extensions/table.js@@ -1,17 +1,25 @@-// It makes sense to use prosemirror-tables for some of the table functionality,-// but it has some differences from our structure (e.g. no thead/tbody).-//-// The main missing part of this extension for now is a UI companion--// Example:+// Markdown Table Example://// | Left-aligned | Center-aligned | Right-aligned |// | :--- | :---: | ---: |// | git status | git status | git status |// | git diff | git diff | git diff |-/** @type {RichEditorExtension} */+class TableNodeView {+ constructor() {+ const div = document.createElement("div");+ div.classList.add("md-table");+ const table = document.createElement("table");+ div.appendChild(table);++ this.dom = div;+ this.contentDOM = table;+ }+}++/** @type {import("discourse/lib/composer/rich-editor-extensions").RichEditorExtension} */const extension = {+ nodeViews: { table: TableNodeView },nodeSpec: {table: {content: "table_head? table_body",diff --git a/frontend/discourse/tests/integration/components/prosemirror-editor/table-test.js b/frontend/discourse/tests/integration/components/prosemirror-editor/table-test.jsindex 40dbf8faa95..c34adfea66c 100644--- a/frontend/discourse/tests/integration/components/prosemirror-editor/table-test.js+++ b/frontend/discourse/tests/integration/components/prosemirror-editor/table-test.js@@ -10,17 +10,17 @@ module(Object.entries({"basic table": ["| Header 1 | Header 2 |\n| --- | --- |\n| Cell 1 | Cell 2 |",- `<table class="md-table"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table>`,+ `<div class="md-table"><table><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table></div>`,`| Header 1 | Header 2 |\n|----|----|\n| Cell 1 | Cell 2 |\n\n`,],"table with alignment": [`| Left | Center | Right |\n| :--- | :---: | ---: |\n| A | B | C |`,- `<table class="md-table"><thead><tr><th style="text-align: left;">Left</th><th style="text-align: center;">Center</th><th style="text-align: right;">Right</th></tr></thead><tbody><tr><td style="text-align: left;">A</td><td style="text-align: center;">B</td><td style="text-align: right;">C</td></tr></tbody></table>`,+ `<div class="md-table"><table><thead><tr><th style="text-align: left;">Left</th><th style="text-align: center;">Center</th><th style="text-align: right;">Right</th></tr></thead><tbody><tr><td style="text-align: left;">A</td><td style="text-align: center;">B</td><td style="text-align: right;">C</td></tr></tbody></table></div>`,`| Left | Center | Right |\n|:---|:---:|---:|\n| A | B | C |\n\n`,],"table within quotes": [`> \n> | Header 1 | Header 2 |\n> | --- | --- |\n> | Cell 1 | Cell 2 |\n`,- `<blockquote><table class="md-table"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table></blockquote>`,+ `<blockquote><div class="md-table"><table><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table></div></blockquote>`,`> \n> | Header 1 | Header 2 |\n> |----|----|\n> | Cell 1 | Cell 2 |\n\n`,],}).forEach(([name, [markdown, html, expectedMarkdown]]) => {