reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
2 lines (1 loc) • 942 B
JavaScript
;function d(e){try{return JSON.stringify(e)}catch{return JSON.stringify({})}}function g(e,n=!1){return r=>{const o=e.startsWith("data-")?e:`data-${e}`;let t=decodeURIComponent(r.getAttribute(o));if(t==null||typeof t=="string"&&t==="null")try{const c=r.outerHTML.match(/([\S\s])+?="([\S\s])+?"/g);c&&c.length>0&&(t=(c.map(a=>a.trim()).reduce((a,u)=>{const i=u.indexOf("="),f=[u.slice(0,i),u.slice(i+1).slice(1,-1)];return a[f[0]]=f[1],a},{})[e.toLowerCase()]||"").replaceAll(""",'"'))}catch(l){console.error("Error getDatasetAttribute ",l.message,r)}if(n)try{return JSON.parse(t)}catch{return{}}if(t.includes("%")||t.includes("auto"))return t;const s=Number.parseInt(t);return s!==s?t:s}}function p(e){const{attrs:n}=e;return Object.keys(n).reduce((r,o)=>{const t=n[o];if(t==null)return r;let s="";return typeof t=="object"?s=d(t):s=t,r[o]=s,r},Object.create(null))}exports.getDatasetAttribute=g;exports.nodeAttrsToDataset=p;