A platform for community discussion. Free, open, simple.
FEATURE: support image grid and auto-gridding on rich editor (#35951)
Renato Atilio4dd3becec10c
diff --git a/app/assets/stylesheets/common/rich-editor/rich-editor.scss b/app/assets/stylesheets/common/rich-editor/rich-editor.scssindex 21787f0474e..9cd098f5975 100644--- a/app/assets/stylesheets/common/rich-editor/rich-editor.scss+++ b/app/assets/stylesheets/common/rich-editor/rich-editor.scss@@ -1,3 +1,5 @@+@use "lib/viewport";+.ProseMirror-container {margin: 0;overscroll-behavior: contain;@@ -152,7 +154,13 @@}.html-block {- border: 1px dashed var(--primary-low-mid);+ border: 2px dashed var(--primary-low-mid);+ border-radius: var(--d-border-radius);++ &.ProseMirror-selectednode {+ outline-offset: -2px;+ border-radius: calc(var(--d-border-radius) + 2px);+ }&::after {position: absolute;@@ -160,8 +168,56 @@top: 0;content: "HTML";font-size: var(--font-down-2-rem);- color: var(--primary-low-mid);+ color: var(--primary-medium);z-index: 1;+ background: var(--secondary-very-high);+ padding: 0 var(--space-1);+ border-bottom-left-radius: var(--d-border-radius);+ border-top-right-radius: var(--d-border-radius);+ }+ }++ .composer-image-grid {+ position: relative;+ border: 2px dashed var(--primary-low-mid);+ border-radius: var(--d-border-radius);+ padding: var(--space-half) var(--space-2) var(--space-2) var(--space-2);+ margin-block: var(--space-4);++ &__title {+ display: flex;+ align-items: center;+ justify-content: end;+ font-size: var(--font-down-1-rem);+ color: var(--primary-medium);++ svg {+ font-size: var(--font-up-1-rem);+ padding-inline: var(--space-2);++ &:hover {+ color: var(--primary);+ cursor: pointer;+ }+ }+ }++ img:not(.ProseMirror-separator) {+ @include viewport.until(md) {+ width: 150px !important;+ height: 150px !important;+ }++ @include viewport.from(md) {+ width: 200px !important;+ height: 200px !important;+ }+ object-fit: cover;+ }++ &.ProseMirror-selectednode {+ outline-offset: -2px;+ border-radius: calc(var(--d-border-radius) + 2px);}}@@ -418,7 +474,8 @@ li.ProseMirror-selectednode::after {right: -2px;top: -2px;bottom: -2px;- border: 2px solid #8cf;+ border: 2px solid var(--tertiary-high);+ border-radius: var(--d-border-radius);pointer-events: none;}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 1a44757c7f8..73945779ee8 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3140,6 +3140,10 @@ en:zoom_out: "Decrease image size"zoom_in: "Increase image size"remove: "Remove image"+ add_to_grid: "Add to grid"+ move_outside_grid: "Move outside grid"++ grid_label: "This will be displayed as a grid"image_scale_button: "Scale image to %{percent}%"delete_image_button: Delete Imagediff --git a/frontend/discourse/app/components/composer-editor.gjs b/frontend/discourse/app/components/composer-editor.gjsindex 21301d8a1aa..98af1dcb93b 100644--- a/frontend/discourse/app/components/composer-editor.gjs+++ b/frontend/discourse/app/components/composer-editor.gjs@@ -292,7 +292,7 @@ export default class ComposerEditor extends Component {@bindsetupEditor(textManipulation) {this.textManipulation = textManipulation;- this.uppyComposerUpload.placeholderHandler = textManipulation.placeholder;+ this.uppyComposerUpload.textManipulation = textManipulation;const input = this.element.querySelector(".d-editor-input");diff --git a/frontend/discourse/app/lib/textarea-text-manipulation.js b/frontend/discourse/app/lib/textarea-text-manipulation.jsindex 968a447dc47..3e49f29bd31 100644--- a/frontend/discourse/app/lib/textarea-text-manipulation.js+++ b/frontend/discourse/app/lib/textarea-text-manipulation.js@@ -903,6 +903,91 @@ export default class TextareaTextManipulation {}}+ /**+ * Wraps consecutive upload placeholders in grid tags.+ * @param {string[]} consecutiveImages - Array of consecutive image filenames to wrap+ */+ autoGridImages(consecutiveImages) {+ if (isEmpty(consecutiveImages)) {+ return;+ }++ const reply = this.value;+ const imagesToWrapGrid = new Set(consecutiveImages);++ const uploadingText = i18n("uploading_filename", {+ filename: "%placeholder%",+ });+ const uploadingTextMatch = uploadingText.match(+ /^.*(?=: %placeholder%\s?…)/+ );++ if (!uploadingTextMatch || !uploadingTextMatch[0]) {+ return;+ }++ const uploadingImagePattern = new RegExp(+ "\\[" ++ uploadingTextMatch[0].trim() ++ "\\s?: ([^\\]]+?)\\.\\w+\\s?…\\]\\(\\)",+ "g"+ );++ const matches = reply.match(uploadingImagePattern) || [];+ const foundImages = [];++ const existingGridPattern = /\[grid\]([\s\S]*?)\[\/grid\]/g;+ const gridMatches = reply.match(existingGridPattern);++ matches.forEach((imagePlaceholder) => {+ imagePlaceholder = imagePlaceholder.trim();++ const filenamePattern = new RegExp(+ "\\[" ++ uploadingTextMatch[0].trim() ++ "\\s?: ([^\\]]+?)\\s?\\…\\]\\(\\)"+ );++ const filenameMatch = imagePlaceholder.match(filenamePattern);++ if (filenameMatch && filenameMatch[1]) {+ const filename = filenameMatch[1];++ const isWithinGrid = gridMatches?.some((gridContent) =>+ gridContent.includes(imagePlaceholder)+ );++ if (!isWithinGrid && imagesToWrapGrid.has(filename)) {+ foundImages.push(imagePlaceholder);+ imagesToWrapGrid.delete(filename);++ // Check if we've found all the images+ if (imagesToWrapGrid.size === 0) {+ return;+ }+ }+ }+ });++ // Check if all consecutive images have been found+ if (foundImages.length === consecutiveImages.length) {+ const firstImageMarkdown = foundImages[0];+ const lastImageMarkdown = foundImages[foundImages.length - 1];++ const startIndex = reply.indexOf(firstImageMarkdown);+ const endIndex =+ reply.indexOf(lastImageMarkdown) + lastImageMarkdown.length;++ if (startIndex !== -1 && endIndex !== -1) {+ this.textarea.focus();+ this.selectText(startIndex, endIndex - startIndex);+ this.applySurroundSelection("[grid]", "[/grid]", "grid_surround", {+ useBlockMode: true,+ });+ }+ }+ }+autocomplete(options) {return DAutocompleteModifier.setupAutocomplete(getOwner(this),diff --git a/frontend/discourse/app/lib/uppy/composer-upload.js b/frontend/discourse/app/lib/uppy/composer-upload.jsindex 1eb708c1a1d..c7b4c9301c9 100644--- a/frontend/discourse/app/lib/uppy/composer-upload.js+++ b/frontend/discourse/app/lib/uppy/composer-upload.js@@ -51,8 +51,8 @@ export default class UppyComposerUpload {uploadPreProcessors;uploadHandlers;- /** @type {PlaceholderHandler} */- placeholderHandler;+ /** @type {TextManipulation} */+ textManipulation;#inProgressUploads = [];#bufferedUploadErrors = [];@@ -339,7 +339,7 @@ export default class UppyComposerUpload {);if (!file.meta.skipPlaceholder) {- this.placeholderHandler.insert(file);+ this.textManipulation.placeholder.insert(file);}this.appEvents.trigger(@@ -351,9 +351,11 @@ export default class UppyComposerUpload {const MIN_IMAGES_TO_AUTO_GRID = 3;if (this.siteSettings.experimental_auto_grid_images &&- this.#consecutiveImages?.length >= MIN_IMAGES_TO_AUTO_GRID+ this.#consecutiveImages?.length >= MIN_IMAGES_TO_AUTO_GRID &&+ this.textManipulation) {- this.#autoGridImages();+ this.textManipulation.autoGridImages([...this.#consecutiveImages]);+ this.#consecutiveImages.length = 0;}});});@@ -382,7 +384,7 @@ export default class UppyComposerUpload {this.#removeInProgressUpload(file.id);if (!file.meta.skipPlaceholder) {- this.placeholderHandler.success(file, markdown);+ this.textManipulation.placeholder.success(file, markdown);}this.appEvents.trigger(@@ -409,7 +411,7 @@ export default class UppyComposerUpload {this.uppyWrapper.uppyInstance.on("cancel-all", () => {// Do the manual cancelling work only if the user clicked cancelif (this.#userCancelled) {- this.placeholderHandler.cancelAll();+ this.textManipulation.placeholder.cancelAll();this.#userCancelled = false;this.#reset();@@ -494,13 +496,13 @@ export default class UppyComposerUpload {});this.uppyWrapper.onPreProcessProgress((file) => {- this.placeholderHandler.progress(file);+ this.textManipulation.placeholder.progress(file);});this.uppyWrapper.onPreProcessComplete((file) => {run(() => {- this.placeholderHandler.progressComplete(file);+ this.textManipulation.placeholder.progressComplete(file);});},() => {@@ -543,7 +545,7 @@ export default class UppyComposerUpload {}#resetUpload(file) {- this.placeholderHandler.cancel(file);+ this.textManipulation.placeholder.cancel(file);}@bind@@ -631,93 +633,4 @@ export default class UppyComposerUpload {return regex.test(fileName);});}-- #autoGridImages() {- const reply = this.composerModel.get("reply");- const imagesToWrapGrid = new Set(this.#consecutiveImages);-- const uploadingText = i18n("uploading_filename", {- filename: "%placeholder%",- });- const uploadingTextMatch = uploadingText.match(- /^.*(?=: %placeholder%\s?…)/- );-- if (!uploadingTextMatch || !uploadingTextMatch[0]) {- return;- }-- const uploadingImagePattern = new RegExp(- "\\[" +- uploadingTextMatch[0].trim() +- "\\s?: ([^\\]]+?)\\.\\w+\\s?…\\]\\(\\)",- "g"- );-- const matches = reply.match(uploadingImagePattern) || [];- const foundImages = [];-- const existingGridPattern = /\[grid\]([\s\S]*?)\[\/grid\]/g;- const gridMatches = reply.match(existingGridPattern);-- matches.forEach((imagePlaceholder) => {- imagePlaceholder = imagePlaceholder.trim();-- const filenamePattern = new RegExp(- "\\[" +- uploadingTextMatch[0].trim() +- "\\s?: ([^\\]]+?)\\s?\\…\\]\\(\\)"- );-- const filenameMatch = imagePlaceholder.match(filenamePattern);-- if (filenameMatch && filenameMatch[1]) {- const filename = filenameMatch[1];-- const isWithinGrid = gridMatches?.some((gridContent) =>- gridContent.includes(imagePlaceholder)- );-- if (!isWithinGrid && imagesToWrapGrid.has(filename)) {- foundImages.push(imagePlaceholder);- imagesToWrapGrid.delete(filename);-- // Check if we've found all the images- if (imagesToWrapGrid.size === 0) {- return;- }- }- }- });-- // Check if all consecutive images have been found- if (foundImages.length === this.#consecutiveImages.length) {- const firstImageMarkdown = foundImages[0];- const lastImageMarkdown = foundImages[foundImages.length - 1];-- const startIndex = reply.indexOf(firstImageMarkdown);- const endIndex =- reply.indexOf(lastImageMarkdown) + lastImageMarkdown.length;-- if (startIndex !== -1 && endIndex !== -1) {- const textArea = this.#editorEl.querySelector(this.editorInputClass);- if (textArea) {- textArea.focus();- textArea.selectionStart = startIndex;- textArea.selectionEnd = endIndex;- this.appEvents.trigger(- `${this.composerEventPrefix}:apply-surround`,- "[grid]",- "[/grid]",- "grid_surround",- { useBlockMode: true }- );- }- }- }-- // Clear found images for the next consecutive images:- this.#consecutiveImages.length = 0;- foundImages.length = 0;- }}diff --git a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjsindex f5c198226e3..f3ce257a22e 100644--- a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs+++ b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs@@ -17,33 +17,40 @@ const SCALE_STEP = 25;const MENU_PADDING = 8;+const GRID_ADD_DIRECTION_END = -1;+const GRID_ADD_DIRECTION_START = 1;+class ImageToolbar extends ToolbarBase {constructor(opts = {}) {super(opts);- this.addButton({- id: "image-scale-down",- icon: "magnifying-glass-minus",- title: "composer.image_toolbar.zoom_out",- className: "composer-image-toolbar__zoom-out",- get disabled() {- return !opts.canScaleDown();- },- action: opts.scaleDown,- tabindex: 0,- });+ const isInGrid = opts.isInGrid?.();- this.addButton({- id: "image-scale-up",- icon: "magnifying-glass-plus",- title: "composer.image_toolbar.zoom_in",- className: "composer-image-toolbar__zoom-in",- get disabled() {- return !opts.canScaleUp();- },- action: opts.scaleUp,- tabindex: 0,- });+ if (!isInGrid) {+ this.addButton({+ id: "image-scale-down",+ icon: "magnifying-glass-minus",+ title: "composer.image_toolbar.zoom_out",+ className: "composer-image-toolbar__zoom-out",+ get disabled() {+ return !opts.canScaleDown();+ },+ action: opts.scaleDown,+ tabindex: 0,+ });++ this.addButton({+ id: "image-scale-up",+ icon: "magnifying-glass-plus",+ title: "composer.image_toolbar.zoom_in",+ className: "composer-image-toolbar__zoom-in",+ get disabled() {+ return !opts.canScaleUp();+ },+ action: opts.scaleUp,+ tabindex: 0,+ });+ }this.addButton({id: "image-remove",@@ -53,6 +60,26 @@ class ImageToolbar extends ToolbarBase {action: opts.removeImage,tabindex: 0,});++ if (isInGrid) {+ this.addButton({+ id: "image-move-outside-grid",+ icon: "table-cells-minus",+ title: "composer.image_toolbar.move_outside_grid",+ className: "composer-image-toolbar__move-outside-grid",+ action: opts.moveOutsideGrid,+ tabindex: 0,+ });+ } else {+ this.addButton({+ id: "image-add-to-grid",+ icon: "table-cells-plus",+ title: "composer.image_toolbar.add_to_grid",+ className: "composer-image-toolbar__add-to-grid",+ action: opts.addToGrid,+ tabindex: 0,+ });+ }}}@@ -93,11 +120,18 @@ export default class ImageNodeView extends Component {scaleDown: this.scaleDown.bind(this),scaleUp: this.scaleUp.bind(this),removeImage: this.removeImage.bind(this),- canScaleDown: () =>- !this.args.node.attrs.scale || this.args.node.attrs.scale > MIN_SCALE,- canScaleUp: () =>- this.args.node.attrs.scale && this.args.node.attrs.scale < MAX_SCALE,+ moveOutsideGrid: this.moveOutsideGrid.bind(this),+ addToGrid: this.addToGrid.bind(this),+ canScaleDown: () => {+ const scale = this.args.node.attrs.scale ?? 100;+ return scale > MIN_SCALE;+ },+ canScaleUp: () => {+ const scale = this.args.node.attrs.scale ?? 100;+ return scale < MAX_SCALE;+ },isAltTextMenuOpen: () => this.altMenuInstance?.expanded,+ isInGrid: () => this.isInGrid,});this.menuInstance = await this.menu.newInstance(this.args.dom, {@@ -202,14 +236,14 @@ export default class ImageNodeView extends Component {@actionscaleDown() {- const currentScale = this.args.node.attrs.scale || 100;+ const currentScale = this.args.node.attrs.scale ?? 100;const newScale = Math.max(MIN_SCALE, currentScale - SCALE_STEP);this.scaleImage(newScale);}@actionscaleUp() {- const currentScale = this.args.node.attrs.scale || 100;+ const currentScale = this.args.node.attrs.scale ?? 100;const newScale = Math.min(MAX_SCALE, currentScale + SCALE_STEP);this.scaleImage(newScale);}@@ -276,11 +310,261 @@ export default class ImageNodeView extends Component {return null;}- const scale = (this.args.node.attrs.scale || 100) / 100;+ const scale = (this.args.node.attrs.scale ?? 100) / 100;return htmlSafe(`width: ${width * scale}px`);}+ get isInGrid() {+ const pos = this.args.getPos();+ const $pos = this.args.view.state.doc.resolve(pos);++ for (let depth = $pos.depth; depth >= 0; depth--) {+ if ($pos.node(depth).type.name === "grid") {+ return true;+ }+ }++ return false;+ }++ @action+ addToGrid() {+ const pos = this.args.getPos();+ const view = this.args.view;+ const { state } = view;+ const imageNode = this.args.node;++ const existingGrid = this.#findNearbyGrid(pos);++ if (existingGrid) {+ this.#addToExistingGrid(existingGrid, pos, imageNode, state, view);+ } else {+ const $pos = state.doc.resolve(pos);++ this.#createNewGrid(+ pos,+ imageNode,+ this.#isImageOnlyChildInParagraph($pos),+ state,+ view+ );+ }+ }++ #addToExistingGrid(existingGrid, pos, imageNode, state, view) {+ const { node: gridNode, pos: gridPos, direction } = existingGrid;+ const tr = state.tr;++ const paragraphWithImage = state.schema.nodes.paragraph.create(+ null,+ imageNode+ );+ let insertPos;++ if (direction === GRID_ADD_DIRECTION_END) {+ // Insert at the end of the grid+ insertPos = gridPos + gridNode.nodeSize - 2;+ tr.insert(insertPos, paragraphWithImage);+ const adjustedPos = pos + paragraphWithImage.nodeSize; // Account for the insertion+ tr.delete(adjustedPos, adjustedPos + 1);++ // if empty paragraph is left at adjustedPos, remove it explicitly+ const $adjustedPos = tr.doc.resolve(adjustedPos);+ if (+ $adjustedPos.parent.type.name === "paragraph" &&+ $adjustedPos.parent.content.size === 0+ ) {+ tr.delete(adjustedPos - 1, adjustedPos);+ }++ const newImagePos = insertPos + 1; // Insert position + paragraph boundary+ tr.setSelection(+ NodeSelection.create(tr.doc, newImagePos)+ ).scrollIntoView();+ } else {+ // Insert at the beginning of the grid+ tr.insert(gridPos, paragraphWithImage);+ tr.delete(pos, pos + 1);++ let imagePos = gridPos;++ const $pos = tr.doc.resolve(pos);+ if (+ $pos.parent.type.name === "paragraph" &&+ $pos.parent.content.size === 0+ ) {+ tr.delete(pos - 1, pos);+ imagePos -= 2;+ }++ tr.setSelection(NodeSelection.create(tr.doc, imagePos)).scrollIntoView();+ }++ view.dispatch(tr);+ }++ #createNewGrid(pos, imageNode, isOnlyChildInParagraph, state, view) {+ const tr = state.tr;+ const gridNode = state.schema.nodes.grid.create(+ null,+ state.schema.nodes.paragraph.create(null, imageNode)+ );++ let gridStartPos;+ if (isOnlyChildInParagraph) {+ tr.replaceWith(pos - 1, pos + 1, gridNode);+ gridStartPos = pos - 1;+ } else {+ tr.replaceWith(pos, pos + 1, gridNode);+ gridStartPos = pos;+ }++ // Select the image inside the new grid: grid + paragraph + image+ // Structure: grid(1) > paragraph(1) > image+ const imagePos = gridStartPos + 2; // Skip grid node boundary and paragraph node boundary+ tr.setSelection(NodeSelection.create(tr.doc, imagePos)).scrollIntoView();++ view.dispatch(tr);+ }++ /**+ * Check if the image at the resolved position is the only child in its paragraph.+ * Uses position-based API for reliable detection instead of direct node comparison.+ *+ * @param {import("prosemirror-model").ResolvedPos} $pos - The resolved position of the image+ * @returns {boolean} True if the image is the only child in a paragraph+ */+ #isImageOnlyChildInParagraph($pos) {+ const parent = $pos.parent;++ // Must be in a paragraph+ if (parent.type.name !== "paragraph") {+ return false;+ }++ // Paragraph must have exactly one child+ if (parent.childCount !== 1) {+ return false;+ }++ // The single child must be an image at the current position+ const index = $pos.index();+ const childAtIndex = parent.child(index);++ return childAtIndex.type.name === "image";+ }++ #findNearbyGrid(pos) {+ const { state } = this.args.view;+ const $pos = state.doc.resolve(pos);++ // Find the block containing the image (paragraph)+ let blockDepth = $pos.depth;+ while (blockDepth > 0 && $pos.node(blockDepth).type.name !== "paragraph") {+ blockDepth--;+ }++ if (blockDepth === 0) {+ return null;+ }++ const blockPos = $pos.start(blockDepth);+ const blockNode = $pos.node(blockDepth);+ const blockParent = $pos.node(blockDepth - 1);+ const blockIndex = $pos.index(blockDepth - 1);++ // Check if left sibling is a grid+ if (blockIndex > 0) {+ const leftNode = blockParent.child(blockIndex - 1);+ if (leftNode.type.name === "grid") {+ return {+ node: leftNode,+ pos: blockPos - leftNode.nodeSize,+ direction: GRID_ADD_DIRECTION_END,+ };+ }+ }++ // Check if right sibling is a grid+ if (blockIndex < blockParent.childCount - 1) {+ const rightNode = blockParent.child(blockIndex + 1);+ if (rightNode.type.name === "grid") {+ return {+ node: rightNode,+ pos: blockPos + blockNode.nodeSize,+ direction: GRID_ADD_DIRECTION_START,+ };+ }+ }++ return null;+ }++ @action+ moveOutsideGrid() {+ if (!this.isInGrid) {+ return;+ }++ const pos = this.args.getPos();+ const view = this.args.view;+ const { state } = view;+ const { tr } = state;+ const imageNode = this.args.node;++ const $pos = state.doc.resolve(pos);+ let gridDepth = null;+ let gridPos = null;++ for (let depth = $pos.depth; depth >= 0; depth--) {+ if ($pos.node(depth).type.name === "grid") {+ gridDepth = depth;+ gridPos = $pos.start(depth);+ break;+ }+ }++ if (gridDepth === null) {+ return;+ }++ const gridNode = $pos.node(gridDepth);++ const willGridBeEmpty =+ gridNode.childCount === 1 &&+ gridNode.firstChild.type.name === "paragraph" &&+ gridNode.firstChild.content.size === 1 &&+ gridNode.firstChild.firstChild.type.name === "image";++ const gridEndPos = gridPos + gridNode.nodeSize - 1;+ const paragraphWithImage = state.schema.nodes.paragraph.create(+ null,+ imageNode+ );++ if (willGridBeEmpty) {+ tr.replaceWith(+ gridPos - 1,+ gridPos + gridNode.nodeSize,+ paragraphWithImage+ );+ tr.setSelection(NodeSelection.create(tr.doc, gridPos)).scrollIntoView();+ } else {+ tr.delete(pos - 1, pos + 1);++ const adjustedGridEndPos = tr.mapping.map(gridEndPos);+ tr.insert(adjustedGridEndPos, paragraphWithImage);++ const newImagePos = adjustedGridEndPos + 1; // Insert position + paragraph boundary+ tr.setSelection(+ NodeSelection.create(tr.doc, newImagePos)+ ).scrollIntoView();+ }++ view.dispatch(tr);+ }+@actionupdateImageLoaded() {this.imageLoaded = true;diff --git a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjsindex 8b1c31d5c0e..f3f27dc03e9 100644--- a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs+++ b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs@@ -178,7 +178,7 @@ export default class ProsemirrorEditor extends Component {)),keymap(baseKeymap),- dropCursor({ color: "var(--primary)" }),+ dropCursor({ color: "var(--tertiary-high)", width: 4 }),gapCursor(),history(),...extractPlugins(this.extensions, params, this.handleAsyncPlugin),diff --git a/frontend/discourse/app/static/prosemirror/extensions/grid.js b/frontend/discourse/app/static/prosemirror/extensions/grid.jsnew file mode 100644index 00000000000..3a557660eaa--- /dev/null+++ b/frontend/discourse/app/static/prosemirror/extensions/grid.js@@ -0,0 +1,195 @@+import { bind } from "discourse/lib/decorators";+import { iconHTML } from "discourse/lib/icon-library";+import { i18n } from "discourse-i18n";++class GridNodeView {+ constructor(node, view, getPos) {+ this.node = node;+ this.view = view;+ this.getPos = getPos;++ const div = document.createElement("div");+ div.className = "composer-image-grid";++ const title = document.createElement("div");+ title.className = "composer-image-grid__title";+ title.innerHTML = iconHTML("table-cells");+ title.prepend(document.createTextNode(i18n("composer.grid_label")));++ div.appendChild(title);++ const contentDiv = document.createElement("div");+ div.appendChild(contentDiv);++ this.dom = div;+ this.contentDOM = contentDiv;++ this.svg = div.querySelector("svg");+ this.svg.setAttribute("alt", i18n("composer.toggle_image_grid"));+ this.svg.addEventListener("click", this.iconClickHandler);+ }++ @bind+ iconClickHandler() {+ const pos = this.getPos();+ const currentNode = this.view.state.doc.nodeAt(pos);+ const tr = this.view.state.tr;++ tr.replaceWith(pos, pos + currentNode.nodeSize, currentNode.content);+ this.view.dispatch(tr);+ }++ selectNode() {+ this.dom.classList.add("ProseMirror-selectednode");+ }++ deselectNode() {+ this.dom.classList.remove("ProseMirror-selectednode");+ }++ update(node) {+ return node.type === this.node.type;+ }++ destroy() {+ this.svg.removeEventListener("click", this.iconClickHandler);+ }+}++/** @type {RichEditorExtension} */+const extension = {+ nodeSpec: {+ grid: {+ content: "block+",+ group: "block",+ createGapCursor: true,+ parseDOM: [+ { tag: "div.d-image-grid" },+ { tag: "div.composer-image-grid" },+ ],+ toDOM() {+ return ["div", { class: "composer-image-grid" }, 0];+ },+ },+ },++ nodeViews: {+ grid: GridNodeView,+ },++ parse: {+ bbcode_open(state, token) {+ if (token.attrGet("class") === "d-image-grid") {+ state.openNode(state.schema.nodes.grid);+ return true;+ }+ },+ bbcode_close(state) {+ if (state.top().type.name === "grid") {+ state.closeNode();+ return true;+ }+ },+ },++ serializeNode: {+ grid: (state, node) => {+ state.write("\n[grid]\n\n");+ state.renderContent(node.content);+ state.write("\n[/grid]\n\n");+ },+ },++ inputRules: () => ({+ match: /^\[grid]$/,+ handler: (state, match, start, end) => {+ const grid = state.schema.nodes.grid.createAndFill();+ return state.tr.replaceWith(start - 1, end, grid);+ },+ }),++ plugins({ pmState: { Plugin } }) {+ return new Plugin({+ appendTransaction(transactions, oldState, newState) {+ // Only process if the document actually changed+ if (!transactions.some((tr) => tr.docChanged)) {+ return null;+ }++ const tr = newState.tr;+ let modified = false;++ // Process grids from end to beginning to avoid position shifts+ const gridNodes = [];+ newState.doc.descendants((node, pos) => {+ if (node.type.name === "grid") {+ gridNodes.push({ node, pos });+ }+ });++ gridNodes.reverse().forEach(({ node, pos }) => {+ // If grid is completely empty, remove it+ if (node.childCount === 0) {+ tr.delete(pos, pos + node.nodeSize);+ modified = true;+ return;+ }++ const changes = [];+ let currentPos = pos + 1; // Start inside the grid node++ node.content.forEach((child) => {+ if (child.type.name === "paragraph") {+ if (child.content.size === 0) {+ // Only remove empty paragraph if grid has other content+ if (node.childCount > 1) {+ changes.push({+ type: "remove",+ from: currentPos,+ to: currentPos + child.nodeSize,+ });+ }+ } else {+ // Split paragraphs with multiple images+ const images = [];+ child.content.forEach((grandchild) => {+ if (grandchild.type.name === "image") {+ images.push(grandchild);+ }+ });++ if (images.length > 1) {+ changes.push({+ type: "split",+ from: currentPos,+ to: currentPos + child.nodeSize,+ images,+ });+ }+ }+ }+ currentPos += child.nodeSize;+ });++ changes.reverse().forEach((change) => {+ if (change.type === "remove") {+ tr.delete(change.from, change.to);+ modified = true;+ } else if (change.type === "split") {+ const paragraphs = change.images.map((img) => {+ return newState.schema.nodes.paragraph.create({}, [img]);+ });++ tr.replaceWith(change.from, change.to, paragraphs);+ modified = true;+ }+ });+ });++ return modified ? tr.setMeta("addToHistory", false) : null;+ },+ });+ },+};++export default extension;diff --git a/frontend/discourse/app/static/prosemirror/extensions/override-drag-ghost.js b/frontend/discourse/app/static/prosemirror/extensions/override-drag-ghost.jsnew file mode 100644index 00000000000..d84f274d1c9--- /dev/null+++ b/frontend/discourse/app/static/prosemirror/extensions/override-drag-ghost.js@@ -0,0 +1,79 @@+import { Fragment, Slice } from "prosemirror-model";+import { NodeSelection, Plugin } from "prosemirror-state";++// A 1px transparent image to use as drag image+// This prevents the default drag image from appearing, the image gets in the way and make it harder+// to see where it'll land.+// In the future a better solution will be to use the image but less opaque and smaller.+const EMPTY_DRAG_IMG = new Image();+EMPTY_DRAG_IMG.src =+ "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";++/**+ * Overrides the default drag image with an empty image, giving room for the drop cursor.+ *+ * @type {RichEditorExtension}+ *+ **/++const dropSelectionPlugin = new Plugin({+ appendTransaction(transactions, oldState, newState) {+ // Check if any transaction has the drop UI event+ const hasDropEvent = transactions.some(+ (tr) => tr.getMeta("uiEvent") === "drop"+ );++ if (!hasDropEvent) {+ return null;+ }++ // Check if current selection is a paragraph containing exactly one image+ const { selection } = newState;+ if (+ selection instanceof NodeSelection &&+ selection.node.type.name === "paragraph" &&+ selection.node.childCount === 1 &&+ selection.node.firstChild.type.name === "image"+ ) {+ // Select the image inside the paragraph instead+ const imagePos = selection.from + 1; // paragraph boundary + image position+ return newState.tr.setSelection(+ NodeSelection.create(newState.doc, imagePos)+ );+ }+ return null;+ },+});++const extension = {+ plugins: [+ dropSelectionPlugin,+ {+ props: {+ handleDOMEvents: {+ dragover(view) {+ if (!view.dragging) {+ return false;+ }++ const dragging = view.dragging.slice.content.firstChild;+ if (dragging.type.name === "image") {+ const wrappedNode = view.state.schema.nodes.paragraph.create(+ null,+ dragging+ );+ view.dragging.slice = new Slice(Fragment.from(wrappedNode), 0, 0);+ }+ return false;+ },+ dragstart(view, event) {+ event.dataTransfer.setDragImage(EMPTY_DRAG_IMG, 0, 0);+ return false;+ },+ },+ },+ },+ ],+};++export default extension;diff --git a/frontend/discourse/app/static/prosemirror/extensions/register-default.js b/frontend/discourse/app/static/prosemirror/extensions/register-default.jsindex ffb726914cd..9e63700c01e 100644--- a/frontend/discourse/app/static/prosemirror/extensions/register-default.js+++ b/frontend/discourse/app/static/prosemirror/extensions/register-default.js@@ -5,6 +5,7 @@ import bulletList from "./bullet-list";import code from "./code";import codeBlock from "./code-block";import emoji from "./emoji";+import grid from "./grid";import hardBreak from "./hard-break";import hashtag from "./hashtag";import heading from "./heading";@@ -17,6 +18,7 @@ import markdownPaste from "./markdown-paste";import mention from "./mention";import onebox from "./onebox";import orderedList from "./ordered-list";+import overrideDragGhost from "./override-drag-ghost";import quote from "./quote";import strikethrough from "./strikethrough";import table from "./table";@@ -54,7 +56,9 @@ const defaultExtensions = [orderedList,bulletList,trailingInlineSpace,+ overrideDragGhost,hardBreak,+ grid,];defaultExtensions.forEach(registerRichEditorExtension);diff --git a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.jsindex e207cee22b6..63e43e3ae2a 100644--- a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js+++ b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js@@ -1,6 +1,7 @@// @ts-checkimport { getOwner, setOwner } from "@ember/owner";import { next } from "@ember/runloop";+import { isEmpty } from "@ember/utils";import { TrackedObject } from "@ember-compat/tracked-built-ins";import { lift, setBlockType, toggleMark, wrapIn } from "prosemirror-commands";import { Slice } from "prosemirror-model";@@ -361,6 +362,91 @@ export default class ProsemirrorTextManipulation {this.view.dom.dir = this.view.dom.dir === "rtl" ? "ltr" : "rtl";}+ /**+ * Wraps consecutive upload placeholders in grid tags.+ * @param {string[]} consecutiveImages - Array of consecutive image filenames to wrap+ */+ autoGridImages(consecutiveImages) {+ if (isEmpty(consecutiveImages)) {+ return;+ }++ const imagesToWrapGrid = new Set(consecutiveImages);+ const placeholderNodes = [];++ // Find all placeholder image nodes in the document that match our consecutive images+ this.view.state.doc.descendants((node, pos) => {+ // Skip traversing grids+ if (node.type === this.schema.nodes.grid) {+ return false;+ }++ if (+ node.type === this.schema.nodes.image &&+ node.attrs.placeholder &&+ node.attrs.alt+ ) {+ // Extract filename from the alt text (which contains the upload placeholder text)+ const uploadingText = i18n("uploading_filename", {+ filename: "%placeholder%",+ });+ const uploadingTextMatch = uploadingText.match(+ /^.*(?=: %placeholder%\s?…)/+ );++ if (uploadingTextMatch && uploadingTextMatch[0]) {+ const pattern = new RegExp(+ uploadingTextMatch[0].trim() + "\\s?: ([^…]+)"+ );+ const match = node.attrs.alt.match(pattern);++ if (match && match[1] && imagesToWrapGrid.has(match[1])) {+ placeholderNodes.push({ node, pos, filename: match[1] });+ }+ }+ }+ });++ // Check if we found all consecutive images and they are adjacent+ if (placeholderNodes.length === consecutiveImages.length) {+ // Sort by position to ensure correct order+ placeholderNodes.sort((a, b) => a.pos - b.pos);++ // Check if nodes are consecutive (adjacent)+ let areConsecutive = true;+ for (let i = 1; i < placeholderNodes.length; i++) {+ const prevNode = placeholderNodes[i - 1];+ const currNode = placeholderNodes[i];+ const expectedNextPos = prevNode.pos + prevNode.node.nodeSize;++ // Allow some flexibility for whitespace between nodes+ if (currNode.pos > expectedNextPos + 2) {+ areConsecutive = false;+ break;+ }+ }++ if (areConsecutive) {+ const firstNode = placeholderNodes[0];+ const lastNode = placeholderNodes[placeholderNodes.length - 1];+ const startPos = firstNode.pos;+ const endPos = lastNode.pos + lastNode.node.nodeSize;++ // Replace the placeholder content with the actual placeholder nodes inside a grid+ const tr = this.view.state.tr;+ const content = tr.doc.slice(startPos, endPos).content;++ // Create grid node and put the content inside it+ const gridNode = this.schema.nodes.grid.createAndFill(null, content);++ if (gridNode) {+ tr.replaceWith(startPos, endPos, gridNode);+ this.view.dispatch(tr);+ }+ }+ }+ }+/*** Updates the toolbar state object based on the current editor active states*/diff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rbindex 1704fe6f48a..3b8af822df5 100644--- a/lib/svg_sprite.rb+++ b/lib/svg_sprite.rb@@ -243,6 +243,8 @@ module SvgSpritesuntabletable-cells+ table-cells-minus+ table-cells-plustable-columnstagtagsdiff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex 32288556dd5..7c7c50b4f28 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -2214,4 +2214,92 @@ describe "Composer - ProseMirror editor", type: :system doexpect(rich).to have_css("aside.quote blockquote pre code", text: 'puts "and some code"')endend++ describe "image grid functionality" do+ context "when images are outside a grid" do+ it "shows 'Add to Grid' button for images outside grids" do+ open_composer+ composer.type_content("")++ expect(composer.image_grid).to have_add_to_grid_toolbar+ end++ it "creates single-image grid" do+ open_composer+ composer.type_content("")++ expect(composer.image_grid).to have_images(1)+ composer.image_grid.add_image_to_grid+ expect(composer.image_grid).to have_grid_images(1)+ end+ end++ context "when images are within a grid" do+ it "shows 'Move outside grid' button for images inside grids" do+ open_composer+ composer.type_content("[grid]")++ composer.image_grid.select_first_grid_image+ expect(composer.image_grid).to have_move_outside_grid_toolbar+ end++ it "moves image outside grid" do+ open_composer+ composer.type_content("[grid]")++ composer.image_grid.select_first_grid_image+ composer.image_grid.move_image_outside_grid++ expect(composer.image_grid).to have_grid_images(1)+ expect(composer.image_grid).to have_images(2) # One in grid, one standalone+ end++ it "moves last image outside grid" do+ open_composer+ composer.type_content("[grid]")++ composer.image_grid.move_image_outside_grid++ expect(composer.image_grid).to have_images(1)+ expect(composer.image_grid).to have_no_grid_images+ end+ end+ end++ describe "auto-grid functionality with experimental_auto_grid_images" do+ before { SiteSetting.experimental_auto_grid_images = true }++ it "automatically wraps 3+ uploaded images in a grid" do+ open_composer++ file_path_1 = file_from_fixtures("logo.png", "images").path+ file_path_2 = file_from_fixtures("logo.jpg", "images").path+ file_path_3 = file_from_fixtures("downsized.png", "images").path++ attach_file("file-uploader", [file_path_1, file_path_2, file_path_3], make_visible: true)++ expect(composer).to have_no_in_progress_uploads++ # Should automatically create a grid with 3 images+ expect(composer.image_grid).to have_grid_images(3)+ end++ it "does not create nested grids when uploading images inside an existing grid" do+ open_composer++ composer.type_content("[grid]")++ expect(composer.image_grid).to have_grid_images(2)++ file_path_1 = file_from_fixtures("logo.png", "images").path+ file_path_2 = file_from_fixtures("logo.jpg", "images").path+ file_path_3 = file_from_fixtures("downsized.png", "images").path++ attach_file("file-uploader", [file_path_1, file_path_2, file_path_3], make_visible: true)++ expect(composer).to have_no_in_progress_uploads++ expect(composer.image_grid).to have_single_grid_with_images(5)+ end+ endenddiff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rbindex 449c5c7e526..26906622898 100644--- a/spec/system/page_objects/components/composer.rb+++ b/spec/system/page_objects/components/composer.rb@@ -394,6 +394,10 @@ module PageObjectsfind("#{@composer_id} .composer-toggle-switch")end+ def image_grid+ Components::ComposerImageGrid.new(rich_editor)+ end+privatedef emoji_preview_selector(emoji)diff --git a/spec/system/page_objects/components/composer_image_grid.rb b/spec/system/page_objects/components/composer_image_grid.rbnew file mode 100644index 00000000000..0427560407a--- /dev/null+++ b/spec/system/page_objects/components/composer_image_grid.rb@@ -0,0 +1,56 @@+# frozen_string_literal: true++module PageObjects+ module Components+ class ComposerImageGrid < PageObjects::Components::Base+ def initialize(rich_editor)+ @rich_editor = rich_editor+ end++ def add_image_to_grid+ page.find(".composer-image-toolbar__add-to-grid").click+ self+ end++ def move_image_outside_grid+ page.find(".composer-image-toolbar__move-outside-grid").click+ self+ end++ def select_first_grid_image+ @rich_editor.all(".composer-image-grid .composer-image-node img").first.click+ self+ end++ def has_add_to_grid_toolbar?+ page.has_css?("[data-identifier='composer-image-toolbar']") &&+ page.has_css?(".composer-image-toolbar__add-to-grid") &&+ page.has_no_css?(".composer-image-toolbar__move-outside-grid")+ end++ def has_move_outside_grid_toolbar?+ page.has_css?("[data-identifier='composer-image-toolbar']") &&+ page.has_css?(".composer-image-toolbar__move-outside-grid") &&+ page.has_no_css?(".composer-image-toolbar__add-to-grid")+ end++ def has_images?(count)+ @rich_editor.has_css?(".composer-image-node img", count: count)+ end++ def has_grid_images?(count)+ @rich_editor.has_css?(".composer-image-grid .composer-image-node img", count: count)+ end++ def has_no_grid_images?+ @rich_editor.has_no_css?(".composer-image-grid .composer-image-node img")+ end++ def has_single_grid_with_images?(count)+ @rich_editor.has_css?(".composer-image-grid", count: 1) &&+ @rich_editor.has_css?(".composer-image-grid .composer-image-node img", count: count) &&+ @rich_editor.has_no_css?(".composer-image-grid .composer-image-grid")+ end+ end+ end+enddiff --git a/vendor/assets/svg-icons/discourse-additional.svg b/vendor/assets/svg-icons/discourse-additional.svgindex 1e6e38b9b25..440146b645e 100644--- a/vendor/assets/svg-icons/discourse-additional.svg+++ b/vendor/assets/svg-icons/discourse-additional.svg@@ -111,4 +111,19 @@ Additional SVG icons<symbol viewBox="0 0 700 500" id="discourse-h3"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 473.255 156.521 C 473.255 143.016 482.923 132.105 494.892 132.105 L 657.172 132.105 C 666.097 132.105 674.076 138.286 677.322 147.67 C 680.568 157.055 678.336 167.737 671.777 174.529 L 582.996 266.398 L 597.669 266.398 C 648.45 266.398 689.628 312.865 689.628 370.167 C 689.628 427.47 648.45 473.937 597.669 473.937 L 544.522 473.937 C 515.853 473.937 489.617 455.624 476.839 426.706 L 475.554 423.807 C 470.212 411.752 474.54 397.102 485.222 391.074 C 495.906 385.046 508.889 389.928 514.23 401.985 L 515.515 404.885 C 520.993 417.321 532.284 425.104 544.522 425.104 L 597.669 425.104 C 624.581 425.104 646.353 400.536 646.353 370.167 C 646.353 339.8 624.581 315.23 597.669 315.23 L 527.348 315.23 C 518.423 315.23 510.444 309.05 507.198 299.666 C 503.952 290.281 506.184 279.599 512.743 272.807 L 601.524 180.937 L 494.892 180.937 C 482.923 180.937 473.255 170.026 473.255 156.521 Z" /></symbol><symbol id="discourse-h4" viewBox="0 0 700 500"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 575.204 170.97 C 579.64 158.991 575.619 144.692 566.157 139.076 C 556.694 133.461 545.399 138.551 540.963 150.531 L 465.204 354.242 C 462.425 361.654 462.898 370.34 466.328 377.302 C 469.758 384.264 475.85 388.382 482.355 388.382 L 614.829 388.382 L 614.829 448.275 C 614.829 461.527 623.286 472.233 633.754 472.233 C 644.222 472.233 652.678 461.527 652.678 448.275 L 652.678 388.382 L 671.603 388.382 C 682.071 388.382 690.528 377.676 690.528 364.424 C 690.528 351.172 682.071 340.468 671.603 340.468 L 652.678 340.468 L 652.678 232.659 C 652.678 219.407 644.222 208.704 633.754 208.704 C 623.286 208.704 614.829 219.407 614.829 232.659 L 614.829 340.468 L 512.161 340.468 L 575.204 170.97 Z" /></symbol><symbol id="discourse-h5" viewBox="0 0 700 500"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 486.457 155.75 C 488.44 144.281 497.788 135.903 508.766 135.903 L 644.744 135.903 C 657.279 135.903 667.407 146.695 667.407 160.051 C 667.407 173.406 657.279 184.196 644.744 184.196 L 527.675 184.196 L 513.228 268.704 L 593.752 268.704 C 646.939 268.704 690.07 314.655 690.07 371.321 C 690.07 427.986 646.939 473.938 593.752 473.938 L 534.616 473.938 C 506.712 473.938 481.216 457.112 468.751 430.552 L 465.848 424.365 C 460.253 412.443 464.785 397.956 475.975 391.995 C 487.165 386.034 500.763 390.863 506.358 402.785 L 509.262 408.972 C 514.077 419.234 523.851 425.648 534.616 425.648 L 593.752 425.648 C 621.939 425.648 644.744 401.351 644.744 371.321 C 644.744 341.29 621.939 316.994 593.752 316.994 L 486.103 316.994 C 479.375 316.994 473.001 313.826 468.681 308.317 C 464.36 302.809 462.59 295.566 463.794 288.548 L 486.457 155.75 Z" /></symbol>+ <symbol id="table-cells-plus" viewBox="0 0 512 512">+ <use href="#table-cells"/>+ <g transform="translate(220, 220) scale(0.7)">+ <circle cx="256" cy="256" r="256" fill="var(--secondary)" />+ <use href="#plus" transform="translate(256 256) scale(0.9) translate(-256 -256)" />+ </g>+ </symbol>++ <symbol id="table-cells-minus" viewBox="0 0 512 512">+ <use href="#table-cells"/>+ <g transform="translate(220, 220) scale(0.7)">+ <circle cx="256" cy="256" r="256" fill="var(--secondary)" />+ <use href="#minus" transform="translate(256 256) scale(0.9) translate(-256 -256)" />+ </g>+ </symbol></svg>