@progress/kendo-react-editor
Version:
React Editor enables users to create rich text content through a WYSIWYG interface. KendoReact Editor package
84 lines (83 loc) • 3.22 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as c from "react";
import { Button as f } from "@progress/kendo-react-buttons";
import { parentNode as P, onDownPreventDefault as I } from "../utils.mjs";
import { registerForLocalization as v, provideLocalizationService as N } from "@progress/kendo-react-intl";
import { messages as d } from "../../messages/index.mjs";
import { InsertTablePopupNS as w } from "./popup.mjs";
import { createTable as S, insertNode as M, canInsert as k } from "@progress/kendo-editor-common";
import { classNames as y } from "@progress/kendo-react-common";
var h;
((T) => {
T.createInsertTableTool = (p) => {
const u = class extends c.Component {
constructor() {
super(...arguments), this.state = {
openedPopup: !1
}, this.button = null, this.togglePopup = () => {
this.setState({
openedPopup: !this.state.openedPopup
});
}, this.closePopup = () => {
this.state.openedPopup && this.togglePopup();
}, this.onTableInsert = (t, a) => {
const { view: e } = this.props;
if (!e)
return;
const { table: o, table_row: r, table_cell: n } = e.state.schema.nodes, s = S({ table: o, table_row: r, table_cell: n }, t, a);
s && M(s, !0)(e.state, e.dispatch), e.focus(), this.closePopup();
};
}
render() {
const { view: t, render: a, ...e } = this.props, o = t && t.state, r = N(this), { createTable: n, createTableHint: s } = p.messages, m = r.toLanguageString(
n,
d[n]
), g = r.toLanguageString(
s,
d[s]
), l = !!(!o || !k(o, o.schema.nodes.table) || P(o.selection.$from, (i) => i.type.name === "table_caption_external")), b = [
/* @__PURE__ */ c.createElement(
f,
{
onClick: l ? void 0 : this.togglePopup,
"aria-disabled": l ? !0 : void 0,
ref: (i) => {
this.button = i && i.element;
},
key: "InsertTable",
...I,
title: m,
...p.props,
...e,
className: y(e.className, p.props.className, { "k-disabled": l })
}
),
t && !l && /* @__PURE__ */ c.createElement(
w.InsertTablePopup,
{
key: "insertTablePopup",
createTableMessage: m,
createTableHintMessage: g,
dir: e.dir,
anchor: this.button,
show: this.state.openedPopup,
onClose: this.closePopup,
onTableInsert: this.onTableInsert
}
) || null
];
return a ? a.call(void 0, b, { view: t }) : b;
}
};
return v(u), u;
};
})(h || (h = {}));
export {
h as InsertTableToolNS
};