mirror of
https://github.com/discourse/discourse-table-builder.git
synced 2026-09-18 07:42:13 -04:00
Triggers modal after clicking Edit Table from selection. Data from post is then passed to the modal.
33 lines
896 B
JavaScript
33 lines
896 B
JavaScript
import { action } from "@ember/object";
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
export default {
|
|
setupComponent(args, component) {
|
|
console.log(args, component, this);
|
|
},
|
|
|
|
@action
|
|
showEditTableModal() {
|
|
const selection = window.getSelection();
|
|
const selectedTable = selection.focusNode;
|
|
const { context } = this.args;
|
|
|
|
// TODO: Improve table checking logic AND change so it only shows button when selected content is a table
|
|
if (
|
|
selectedTable.nodeName === "DIV" &&
|
|
selectedTable.classList.contains("md-table")
|
|
) {
|
|
// ? TODO: simply pass quoteState object only?
|
|
const attrs = {
|
|
table: context.quoteState.buffer,
|
|
postId: context.quoteState.postId,
|
|
};
|
|
showModal("table-editor-modal", {
|
|
model: attrs,
|
|
});
|
|
} else {
|
|
console.warn("This is not a table:", selection);
|
|
}
|
|
},
|
|
};
|