UNPKG

@progress/kendo-react-editor

Version:

React Editor enables users to create rich text content through a WYSIWYG interface. KendoReact Editor package

9 lines (8 loc) 2.29 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),y=require("@progress/kendo-editor-common"),v=require("@progress/kendo-react-buttons"),x=require("../config/toolsSettings.js"),k=require("@progress/kendo-react-intl"),g=require("../messages/index.js");function T(s){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return i.default=s,Object.freeze(i)}const f=T(p),m=(s,i)=>{const{from:t,to:n}=s.selection;let l=null;return s.doc.nodesBetween(t,n,r=>(l=l||(r.type===i?r:null),!l)),l},I=s=>{let i=!1;const t=s.view,n=x.listsTypes,l=s.listType,r=k.useLocalization();let u=[...s.items||[]],c,a;if(t){const e=t.state,o=e&&e.schema.nodes;c=o&&m(e,o[n.orderedList]),a=o&&m(e,o[n.bulletList]),i=!!(l===n.orderedList?c&&!a:!c&&a)}const L=e=>{t&&(y.toggleList(t.state,t.dispatch,t,{listType:l,...n,listAttrs:{}},"InsertList"),t.focus())},S=e=>{if(t){const o=e.item.style?{style:"list-style-type: "+e.item.style+";"}:{},d=c||a;if(d&&y.listStyle(d.attrs)!==e.item.style){const b=t.state.selection.$head.posAtIndex(0,-2)-1;t.dispatch(t.state.tr.setNodeMarkup(b,t.state.schema.nodes[l],o))}else y.toggleList(t.state,t.dispatch,t,{listType:l,...n,listAttrs:o},"InsertList");t.focus()}};if(u=u.map(e=>({...e,text:e.textKey?r.toLanguageString(e.textKey,g.messages[e.textKey]):e.text})),i&&(c||a)){const e=y.listStyle((c||a).attrs);u=u.map((o,d)=>({...o,selected:e?o.style===e:d===0}))}return f.createElement("span",{onMouseDown:e=>{e.preventDefault()}},f.createElement(v.SplitButton,{textField:"text",items:u,icon:s.icon,svgIcon:s.svgIcon,onButtonClick:L,onItemClick:S,buttonClass:i?"k-selected":void 0,title:s.title!==void 0?s.title:r.toLanguageString(s.titleKey,g.messages[s.titleKey])}))};exports.ListTool=I;