jodit-pro
Version:
PRO Version of Jodit Editor
2 lines (1 loc) • 1.07 kB
JavaScript
var c=Object.defineProperty;var m=(t,e)=>c(t,"name",{value:e,configurable:!0});import{Dom as s}from"jodit/esm/core/dom/index.js";function a(t,{selector:e,index:r,requireExactlyOne:h=!1}={}){const o=e!=null,l=r!=null;if(h&&o===l)throw new Error("Either index or selector must be provided, but not both");if(!o&&!l)throw new Error("Block identifier is required");if(o){if(typeof e!="string")throw new Error("Selector must be a string");const i=t.editor.querySelector(e);if(!i)throw new Error(`No element found matching selector "${e}"`);if(!s.isElement(i))throw new Error(`Selector "${e}" does not point to an element node`);return{element:i,identifier:`with selector "${e}"`}}if(typeof r!="number")throw new Error("Block index must be a number");const n=Array.from(t.editor.children);if(r<0||r>=n.length)throw new Error(`Block index ${r} is out of range. Document has ${n.length} blocks`);const f=n[r];if(!s.isElement(f))throw new Error(`Block at index ${r} is not a valid element`);return{element:f,identifier:`at index ${r}`}}m(a,"resolveBlock");export{a as resolveBlock};