@progress/kendo-react-editor
Version:
React Editor enables users to create rich text content through a WYSIWYG interface. KendoReact Editor package
71 lines (70 loc) • 2.44 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 u from "react";
import { listStyle as y, toggleList as f } from "@progress/kendo-editor-common";
import { SplitButton as h } from "@progress/kendo-react-buttons";
import { listsTypes as I } from "../config/toolsSettings.mjs";
import { useLocalization as T } from "@progress/kendo-react-intl";
import { messages as k } from "../messages/index.mjs";
const L = (s, a) => {
const { from: t, to: l } = s.selection;
let i = null;
return s.doc.nodesBetween(t, l, (r) => (i = i || (r.type === a ? r : null), !i)), i;
}, C = (s) => {
let a = !1;
const t = s.view, l = I, i = s.listType, r = T();
let d = [...s.items || []], n, c;
if (t) {
const e = t.state, o = e && e.schema.nodes;
n = o && L(e, o[l.orderedList]), c = o && L(e, o[l.bulletList]), a = !!(i === l.orderedList ? n && !c : !n && c);
}
const p = (e) => {
t && (f(t.state, t.dispatch, t, { listType: i, ...l, listAttrs: {} }, "InsertList"), t.focus());
}, g = (e) => {
if (t) {
const o = e.item.style ? { style: "list-style-type: " + e.item.style + ";" } : {}, m = n || c;
if (m && y(m.attrs) !== e.item.style) {
const v = t.state.selection.$head.posAtIndex(0, -2) - 1;
t.dispatch(t.state.tr.setNodeMarkup(v, t.state.schema.nodes[i], o));
} else
f(t.state, t.dispatch, t, { listType: i, ...l, listAttrs: o }, "InsertList");
t.focus();
}
};
if (a && (n || c)) {
const e = y((n || c).attrs);
d = d.map((o, m) => ({
...o,
selected: e ? o.style === e : m === 0
}));
}
return /* @__PURE__ */ u.createElement(
"span",
{
onMouseDown: (e) => {
e.preventDefault();
}
},
/* @__PURE__ */ u.createElement(
h,
{
textField: "text",
items: d,
icon: s.icon,
svgIcon: s.svgIcon,
onButtonClick: p,
onItemClick: g,
buttonClass: a ? "k-selected" : void 0,
title: s.title !== void 0 ? s.title : r.toLanguageString(s.titleKey, k[s.titleKey])
}
)
);
};
export {
C as ListTool
};