yurich 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,9 +5,11 @@
5
5
 
6
6
  A headless rich text editor for React built on native `contentEditable` + Selection API.
7
7
 
8
+ [Overview](https://leeyujoo.com/yurich/overview/) | [Quick start](https://leeyujoo.com/yurich/#quick-start) | [Live demo](https://leeyujoo.com/yurich/#live-demo) | [API reference](https://leeyujoo.com/yurich/api/)
9
+
8
10
  ## Why yurich?
9
11
 
10
- - **Zero dependencies** — Only React as a peer dependency. No ProseMirror, no Slate, no heavy document model.
12
+ - **Zero runtime dependencies** — React and React DOM are peer dependencies.
11
13
  - **Native contentEditable** — Uses the browser's built-in editing with the Selection API directly. Does **not** use `document.execCommand`.
12
14
  - **HTML-native model** — The DOM *is* the document. No separate document model to sync.
13
15
  - **Schema from extensions** — The extensions you enable define which tags exist. Everything else is removed on paste, on load, and in the output.
@@ -50,6 +52,7 @@ function ToolbarButton({ command, label, children }: {
50
52
  const active = useIsActive(editor, command);
51
53
  return (
52
54
  <button
55
+ type="button"
53
56
  aria-pressed={active}
54
57
  aria-label={label}
55
58
  onMouseDown={e => e.preventDefault()}
@@ -138,7 +141,7 @@ Creates an editor instance that lives as long as the component.
138
141
  | `sanitize` | `boolean` | `true` | Sanitize the output of `getHTML()` and `onChange`. Read once. |
139
142
  | `historyLimit` | `number` | `100` | Max undo steps. Read once. |
140
143
 
141
- `onChange` and `onChangeJSON` are called at most once per animation frame, and only when the content actually changed.
144
+ `onChange` and `onChangeJSON` are called at most once per animation frame. Loading HTML with `setHTML(html, { history: false })` can call them even when the HTML is unchanged.
142
145
 
143
146
  ### `EditorInstance`
144
147
 
@@ -313,14 +316,14 @@ const Mention: Extension = {
313
316
  | `keyboardShortcuts` | `Record<string, string>` | Key combo → command name |
314
317
  | `isActive` | `(editor, command?, value?) => boolean` | Whether the extension is active at the selection |
315
318
 
316
- Tags are lowercase. An attribute is kept only when the mark declares a rule for it: the rule receives the current value (or `null`) and the element, and returns the value to write or `null` to leave the attribute out.
319
+ Tags are lowercase. An attribute is kept only when the mark declares a rule for it. The rule receives the current value (or `null`) and the element and returns the value to write or `null` to leave the attribute out. For `setMark`, the rule receives an inert element with the proposed attributes and the marked text. The same attribute policy applies to custom extensions and the built-in marks.
317
320
 
318
321
  **Editor methods for commands**
319
322
 
320
323
  | Method | Description |
321
324
  |---|---|
322
325
  | `toggleMark(tag)` | Add the mark to the selection, or remove it when all of the selection has it |
323
- | `setMark(tag, attrs?, text?)` | Add the mark with attributes. With only a caret, `text` is inserted and marked. |
326
+ | `setMark(tag, attrs?, text?)` | Add or update the mark after validating its attributes. With only a caret, `text` is inserted and marked. |
324
327
  | `removeMark(tag)` | Remove the mark from the selection. With only a caret, remove the whole mark around it. |
325
328
  | `isMarkActive(tag)` | Whether all of the selected text has the mark |
326
329
  | `setBlock(tag)` / `toggleBlock(tag)` | Change the selected blocks to `tag` / toggle between `tag` and paragraph |
@@ -355,9 +358,9 @@ HTML enters the document in four places — `initialValue`, `setHTML`, paste, an
355
358
  The sanitizer rebuilds the content from the schema instead of removing what looks dangerous:
356
359
 
357
360
  - Only the tags of the enabled extensions come out, plus `<p>` and `<br>`.
358
- - Only declared attributes come out: `href`, `target` and `rel` on links, and `text-align` on blocks with `TextAlign`. No `on*` handlers, `class`, `id` or other styles.
359
- - Link addresses must start with `http://`, `https://` or `mailto:`. `target` may only be `_blank`, and then `rel="noopener noreferrer"` is set.
360
- - `<script>`, `<style>`, `<iframe>`, `<svg>`, `<math>`, `<noscript>`, `<title>`, `<audio>`, `<video>` and similar tags are removed together with their content, even when an extension declares them.
361
+ - The built-in extensions allow `href`, `target` and `rel` on links and `text-align` on blocks with `TextAlign`. `target` may only be `_blank`, which sets `rel="noopener noreferrer"`.
362
+ - URL attributes on marks require an absolute `http://` or `https://` URL. `href` also accepts `mailto:`. Event handlers, inline HTML attributes such as `srcdoc`, custom-element upgrades using `is`, and multi-URL attributes such as `srcset` are discarded.
363
+ - Tags such as `<script>`, `<style>`, `<iframe>`, `<svg>`, `<math>`, `<audio>` and `<video>` are removed with their content. The schema rejects these as output tags even when they are reached through an alias. Custom element names cannot be output tags.
361
364
  - Other unknown tags are removed but their text is kept. An unknown tag that starts a line in HTML (`<td>`, `<section>`, …) becomes a paragraph.
362
365
  - Plain text is pasted as text nodes and never parsed as HTML.
363
366
 
@@ -374,14 +377,23 @@ The sanitizer rebuilds the content from the schema instead of removing what look
374
377
 
375
378
  ## Development
376
379
 
380
+ Use Node.js 24 LTS and [pnpm 12.25.1](https://pnpm.io/installation) for local development, as in CI.
381
+
377
382
  ```bash
378
- yarn dev # demo
379
- yarn lint
380
- yarn typecheck
381
- yarn test # Playwright: Chromium, WebKit, Firefox, and iPhone / Pixel emulation
383
+ pnpm install
384
+ pnpm dev # documentation and live demo
385
+ pnpm build:demo # static documentation site
386
+ pnpm lint
387
+ pnpm typecheck
388
+ pnpm test # Playwright: Chromium, WebKit, Firefox, and iPhone / Pixel emulation
382
389
  ```
383
390
 
384
- The first test run needs the browsers: `yarn playwright install`.
391
+ The first test run needs the browsers: `pnpm exec playwright install`.
392
+
393
+ Documentation sources are in `demo/docs/<locale>/`. The build uses the examples marked in the English Markdown across all languages. Keep the section IDs after translated headings so existing links continue to work.
394
+ The feature guides use localized introductions, usage steps, and notes from `feature-guides.md` alongside shared React examples in `demo/feature-guides.ts`.
395
+
396
+ The docs build emits `sitemap.xml`, localized `llms.txt` indexes, and Markdown versions of every document. These files use the package homepage for canonical URLs and the package manifest for the documented version.
385
397
 
386
398
  ## License
387
399
 
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react"),pe=require("react/jsx-runtime"),qe={tag:"p",type:"paragraph",aliases:["div"]},P=e=>{const t=new Map,n=new Map,s=new Map,o=(r,l)=>{for(const i of[l.tag,...l.aliases??[]])r.set(i,l)};o(n,qe);for(const r of e){r.marks?.forEach(l=>o(t,l)),r.blocks?.forEach(l=>o(n,l));for(const[l,i]of Object.entries(r.blockStyles??{}))s.set(l,new Set(i))}return{marks:t,blocks:n,blockStyles:s,blockSelector:Array.from(n.keys()).join(",")}},j=(e,t)=>e instanceof HTMLElement&&t.blocks.has(e.localName),Ue=300,Fe=e=>{let t=[],n=[],s={blocks:[],before:null,after:null},o=null,r=null;const l=()=>{r!==null&&(clearTimeout(r),r=null),o&&(t.push(s),t.length>e&&t.shift(),s=o,o=null,n=[])};return{reset(i){t=[],n=[],o=null,s={blocks:i,before:null,after:null}},record(i,u){if(!u){l(),o=i,l();return}o=o?{...i,before:o.before}:i,r!==null&&clearTimeout(r),r=setTimeout(l,Ue)},undo(){l();const i=t.pop();if(!i)return null;const u=s;return n.push(u),s=i,{blocks:i.blocks,selection:u.before}},redo(){l();const i=n.pop();return i?(t.push(s),s=i,{blocks:i.blocks,selection:i.after}):null},canUndo:()=>t.length>0||o!==null,canRedo:()=>n.length>0&&o===null,cancelTimer(){r!==null&&(clearTimeout(r),r=null)}}},I=(e,t)=>{const n=e.ownerDocument.createElement(t);for(const s of Array.from(e.attributes))n.setAttribute(s.name,s.value);return n.append(...e.childNodes),e.replaceWith(n),n},w=e=>{e.replaceWith(...e.childNodes)},M=e=>e instanceof HTMLElement&&(e.localName==="ul"||e.localName==="ol"),ze=(e,t)=>e.attributes.length===t.attributes.length&&Array.from(e.attributes).every(n=>t.getAttribute(n.name)===n.value),Y=e=>{const t=window.getSelection(),n=t?.anchorNode??null,s=t?.focusNode??null,o=t?.anchorOffset??0,r=t?.focusOffset??0;e(),!(!t||!n||!s)&&(n.nodeType!==Node.TEXT_NODE||s.nodeType!==Node.TEXT_NODE||!n.isConnected||!s.isConnected||t.anchorNode===n&&t.anchorOffset===o&&t.focusNode===s&&t.focusOffset===r||t.setBaseAndExtent(n,Math.min(o,n.length),s,Math.min(r,s.length)))},ge=(e,t)=>{const n=Array.from(e.childNodes),s=n.some(i=>j(i,t)),o=[];let r=[];const l=()=>{if(r.length===0)return;if(r.some(u=>u.nodeType===Node.ELEMENT_NODE||u.textContent?.trim())||!s){const u=(e.ownerDocument??document).createElement("p");e.insertBefore(u,r[0]),u.append(...r),o.push(u)}else r.forEach(u=>e.removeChild(u));r=[]};for(const i of n)j(i,t)?l():i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE?r.push(i):e.removeChild(i);return l(),o},ye=e=>{let t=e.nextSibling;for(;t instanceof Element&&t.localName===e.localName;)e.append(...t.childNodes),t.remove(),t=e.nextSibling},Ke=e=>{for(const t of Array.from(e.childNodes)){if(t instanceof Element&&t.localName==="li")continue;if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim()){t.remove();continue}const n=e.ownerDocument.createElement("li");t.replaceWith(n),n.append(t)}if(e.children.length===0){e.remove();return}ye(e)},We=(e,t,n)=>{let s=t;for(const o of[t,...t.querySelectorAll("*")]){if(!e.contains(o))continue;const r=o.localName;if(r==="br")continue;const l=n.marks.get(r)??n.blocks.get(r);if(!l){w(o);continue}const i=l.tag===r?o:I(o,l.tag);if(o===s&&(s=i),n.marks.has(r)){const u=i.parentElement?.closest(l.tag);i.childNodes.length===0?i.remove():u&&u!==e&&e.contains(u)&&w(i)}}s.normalize();for(const o of Array.from(s.querySelectorAll("*"))){if(!n.marks.has(o.localName)||!e.contains(o))continue;let r=o.nextSibling;for(;r instanceof Element&&r.localName===o.localName&&ze(o,r);)o.append(...r.childNodes),r.remove(),r=o.nextSibling}s.normalize();for(const o of[s,...s.querySelectorAll("ul, ol")])M(o)&&e.contains(o)&&Ke(o)},ie=(e,t,n)=>{Y(()=>{const s=new Set(ge(e,t));for(const o of n)o instanceof Element&&o.parentNode===e&&s.add(o);for(const o of s)o.parentNode===e&&We(e,o,t);for(const o of Array.from(e.children))M(o)&&o.parentNode===e&&ye(o)})},Xe=new Set(["script","style","title","iframe","noscript","noembed","noframes","plaintext","xmp","svg","math","audio","video"]),ae=["address","article","aside","blockquote","dd","details","div","dl","dt","fieldset","figcaption","figure","footer","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","ol","p","pre","section","summary","table","tbody","td","tfoot","th","thead","tr","ul"].join(","),Ne=e=>{const t=document.createRange();return t.selectNodeContents(e),Array.from(t.cloneContents().childNodes)},ke=(e,t)=>{const n=[];for(const s of(e??"").split(";")){const o=s.indexOf(":");if(o===-1)continue;const r=s.slice(0,o).trim().toLowerCase(),l=s.slice(o+1).trim().toLowerCase();t.blockStyles.get(r)?.has(l)&&n.push(`${r}: ${l}`)}return n.join("; ")};let J=null;const _=(e,t,n)=>{for(const s of e){const o=$e(s,n);o&&t.appendChild(o)}},$e=(e,t)=>{const n=J,s=m=>{const g=n.createDocumentFragment();return _(m,g,t),g};if(e instanceof HTMLFormElement)return s(Ne(e));if(e.nodeType===Node.TEXT_NODE)return n.createTextNode(e.textContent??"");if(!(e instanceof Element))return null;const o=e.localName;if(Xe.has(o))return null;if(o==="br")return n.createElement("br");const r=t.marks.get(o);if(r){const m=n.createElement(r.tag);for(const[g,S]of Object.entries(r.attrs??{})){const h=S(e.getAttribute(g),e);h!==null&&m.setAttribute(g,h)}return _(e.childNodes,m,t),m}const l=e.matches(ae),i=e.querySelector(ae)!==null,u=t.blocks.get(o);if((u?.tag==="p"||!u&&l)&&i)return s(e.childNodes);if(u||l){const m=n.createElement(u?.tag??"p"),g=ke(e.getAttribute("style"),t);return g&&m.setAttribute("style",g),_(e.childNodes,m,t),u||m.childNodes.length>0?m:null}return s(e.childNodes)},Q=(e,t)=>{J??=document.implementation.createHTMLDocument("");const n=J.createElement("div");return _(e,n,t),n.innerHTML},H=(e,t)=>{if(!e)return"";const n=new DOMParser().parseFromString(e,"text/html");return Q(n.body.childNodes,t)},Je=e=>e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()),be=(e,t,n,s=!1)=>{const o=h=>{const y={type:"text",text:h};return t.length>0&&(y.marks=[...t]),[y]},r=(h,y)=>Array.from(h).flatMap(p=>be(p,y,n));if(e instanceof HTMLFormElement)return r(Ne(e),t);if(e.nodeType===Node.TEXT_NODE){const h=e.textContent??"";return(s?h.trim():h)?o(h):[]}if(!(e instanceof Element))return[];const l=e.localName;if(l==="br")return s?[]:o(`
2
- `);const i=n.marks.get(l);if(i){const h={type:i.type},y={};for(const[p,v]of Object.entries(i.attrs??{})){const A=v(e.getAttribute(p),e);A!==null&&(y[p]=A)}return Object.keys(y).length>0&&(h.attrs=y),r(e.childNodes,[...t,h])}const u=n.blocks.get(l);if(!u)return r(e.childNodes,t);const m={type:u.type},g={...u.attrs};for(const h of ke(e.getAttribute("style"),n).split("; ")){const[y,p]=h.split(": ");p&&(g[Je(y)]=p)}Object.keys(g).length>0&&(m.attrs=g);const S=r(e.childNodes,t);return S.length>0&&(m.content=S),[m]},Ee=(e,t)=>be(e,[],t,!0),Ve=(e,t)=>Q(e.childNodes,P(t)),Ge=(e,t)=>{const n=P(t);return{type:"doc",content:Array.from(e.childNodes).flatMap(s=>Ee(s,n))}},k=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const n=t.getRangeAt(0);return e.contains(n.commonAncestorContainer)?n:null},Se=e=>{const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e))},ve=(e,t)=>{const n=document.createRange();n.setStart(e,0),n.setEnd(t,t.length),Se(n)},Z=e=>{let t=e;for(;t.lastChild;)t=t.lastChild;const n=document.createRange();t.nodeType===Node.TEXT_NODE?n.setStart(t,t.length):t===e?n.setStart(e,0):n.setStartAfter(t),n.collapse(!0),Se(n)},Ye=e=>{let t=e;for(;t.lastChild;)t=t.lastChild;const n=window.getSelection();t.nodeType===Node.TEXT_NODE?n?.collapse(t,t.length):t===e?n?.collapse(e,0):n?.collapse(t.parentNode,Array.prototype.indexOf.call(t.parentNode.childNodes,t))},ue=(e,t,n)=>{if(t===e)return n<e.childNodes.length?[n,0]:[Math.max(n-1,0),1/0];let s=t;for(;s.parentNode!==e;)s=s.parentNode;const o=document.createRange();return o.setStart(s,0),o.setEnd(t,n),[Array.prototype.indexOf.call(e.childNodes,s),o.toString().length]},de=(e,[t,n])=>{const s=e.childNodes[Math.min(t,e.childNodes.length-1)];if(!s)return[e,0];const o=document.createTreeWalker(s,NodeFilter.SHOW_TEXT);let r=n,l=null;for(let i=o.nextNode();i;i=o.nextNode()){if(r<=i.length)return[i,r];r-=i.length,l=i}return l?[l,l.length]:[s,0]},W=e=>{const t=window.getSelection();return!t?.anchorNode||!t.focusNode||!e.contains(t.anchorNode)||!e.contains(t.focusNode)?null:{anchor:ue(e,t.anchorNode,t.anchorOffset),focus:ue(e,t.focusNode,t.focusOffset)}},Qe=(e,t)=>{const n=window.getSelection();if(!(!n||!e.isConnected)){if(!t){Z(e);return}n.setBaseAndExtent(...de(e,t.anchor),...de(e,t.focus))}},x=(e,t,n)=>{for(let s=e;s&&s!==n;s=s.parentNode)if(s instanceof HTMLElement&&(s.localName===t.tag||t.aliases?.includes(s.localName)))return s;return null},ee=(e,t)=>{const n=t.commonAncestorContainer,s=n.nodeType===Node.TEXT_NODE?n.parentNode:n,o=document.createTreeWalker(s,NodeFilter.SHOW_TEXT),r=[];for(let l=o.nextNode();l;l=o.nextNode()){if(!t.intersectsNode(l)||l.parentNode===e||M(l.parentNode))continue;const i=l===t.startContainer?t.startOffset:0,u=l===t.endContainer?t.endOffset:l.length;i<u&&r.push({node:l,start:i,end:u})}return r},Ae=e=>e.map(({node:t,start:n,end:s})=>(s<t.length&&t.splitText(s),n>0?t.splitText(n):t)),fe=(e,t)=>{for(const[n,s]of Object.entries(t??{}))e.setAttribute(n,s)},Te=(e,t,n)=>{if(t.collapsed)return x(t.startContainer,n,e)!==null;const s=ee(e,t);return s.length>0&&s.every(o=>x(o.node,n,e))},xe=(e,t,n,s,o)=>{if(t.collapsed){if(!o)return;t.insertNode(document.createTextNode(o))}const r=Ae(ee(e,t));if(r.length!==0){for(const l of r){const i=x(l,n,e);if(i){fe(i,s);continue}const u=document.createElement(n.tag);fe(u,s),l.replaceWith(u),u.append(l)}ve(r[0],r[r.length-1])}},Ze=(e,t)=>{const n=document.createRange();n.setStart(e,0),n.setEndBefore(t);const s=document.createRange();s.setStartAfter(t),s.setEnd(e,e.childNodes.length);for(const[o,r]of[[n,"before"],[s,"after"]]){const l=o.extractContents();if(!l.textContent&&!l.querySelector("br"))continue;const i=e.cloneNode(!1);i.append(l),e[r](i)}w(e)},Ce=(e,t,n)=>{if(t.collapsed){const o=x(t.startContainer,n,e);o&&Y(()=>w(o));return}const s=Ae(ee(e,t));if(s.length!==0){for(const o of s)for(let r=x(o,n,e);r;r=x(o,n,e))Ze(r,o);ve(s[0],s[s.length-1])}},et=(e,t,n)=>{t.collapsed||(Te(e,t,n)?Ce(e,t,n):xe(e,t,n))},Le=(e,t)=>j(e,t)&&!M(e),he=(e,t,n)=>{for(let s=e;s&&s!==t;s=s.parentNode)if(Le(s,n))return s;return null},tt=(e,t)=>{const n=document.createRange();return n.selectNodeContents(t),e.compareBoundaryPoints(Range.START_TO_START,n)>0&&n.setStart(e.startContainer,e.startOffset),e.compareBoundaryPoints(Range.END_TO_END,n)<0&&n.setEnd(e.endContainer,e.endOffset),n.toString()!==""},C=(e,t,n)=>{const s=(i,u)=>i.childNodes[u]??i.lastChild??i,o=he(s(t.startContainer,t.startOffset),e,n),r=he(s(t.endContainer,t.endOffset),e,n);if(!o)return[];if(!r||o===r)return[o];const l=Array.from(e.querySelectorAll(n.blockSelector)).filter(i=>Le(i,n)&&!i.querySelector(n.blockSelector)&&t.intersectsNode(i));return l.length>1&&!tt(t,l[l.length-1])&&l.pop(),l},te=e=>{if(!k(e))return null;if(e.childNodes.length===0){const t=document.createElement("p");t.append(document.createElement("br")),e.append(t),window.getSelection()?.collapse(t,0)}return k(e)},we=(e,t)=>{let n=null;Y(()=>{n=t()});const s=k(e);n&&(!s||s.startContainer===e)&&Ye(n)},V=(e,t)=>{const n=e.parentElement;if(!M(n))return I(e,t);const s=n.cloneNode(!1);for(;e.nextSibling;)s.append(e.nextSibling);return n.after(e),s.childNodes.length>0&&e.after(s),n.childNodes.length===0&&n.remove(),I(e,t)},nt=(e,t,n)=>{const s=t.blocks.get(n);if(!s||s.tag!==n||n==="li"||n==="ul"||n==="ol")return;const o=te(e);if(!o)return;const r=C(e,o,t);we(e,()=>{let l=null;for(const i of r)i.localName===n?l=i:l=i.localName==="li"?V(i,n):I(i,n);return l})},ot=(e,t,n)=>{const s=k(e);if(!s)return!1;const o=C(e,s,t);return o.length>0&&o.every(r=>r.localName===n)},st=(e,t,n,s)=>{if(!t.blockStyles.get(n)?.has(s))return;const o=te(e);if(o)for(const r of C(e,o,t))r.style.setProperty(n,s)},rt=(e,t,n)=>{const s=k(e);if(!s)return null;const[o]=C(e,s,t);return o?.style.getPropertyValue(n)||null},G=(e,t)=>e.localName==="li"&&e.parentElement?.localName===t,ct=(e,t,n)=>{const s=k(e);if(!s)return!1;const o=C(e,s,t);return o.length>0&&o.every(r=>G(r,n))},lt=(e,t)=>{const n=document.createElement(t),s=document.createElement("li"),o=e.getAttribute("style");return o&&s.setAttribute("style",o),s.append(...e.childNodes),n.append(s),e.replaceWith(n),s},it=(e,t,n)=>{if(!t.blocks.has(n))return;const s=te(e);if(!s)return;const o=C(e,s,t),r=o.every(l=>G(l,n));we(e,()=>{let l=null;for(const i of o)r?l=V(i,"p"):G(i,n)?l=i:l=lt(i.localName==="li"?V(i,"p"):i,n);return l})},ne=(e,t)=>{e.deleteContents();const n=t.lastChild;if(e.insertNode(t),!n)return;const s=n.nextSibling;s?.nodeName==="BR"&&!s.nextSibling&&s.remove(),Z(n)},at=(e,t,n,s)=>{t.deleteContents();let o=t.startContainer;for(;o&&o!==e&&o.parentNode!==e;)o=o.parentNode;if(!o||o===e||!j(o,s)){ne(t,n);return}ge(n,s);const r=n.lastChild;if(!r)return;const l=document.createRange();l.selectNodeContents(o),l.setStart(t.startContainer,t.startOffset);const i=o.cloneNode(!1);i.append(l.extractContents()),o.after(n,i);for(const u of[o,i])u.textContent?.trim()||u.remove();Z(r)},ut=(e,t,n,s)=>{const o=document.createElement("template");o.innerHTML=n;const r=o.content,l=r.childNodes.length===1?r.firstChild:null;l instanceof HTMLElement&&l.localName==="p"&&!l.querySelector(s.blockSelector)&&w(l),r.querySelector(s.blockSelector)?at(e,t,r,s):ne(t,r)},dt=(e,t,n)=>{const s=document.createDocumentFragment(),o=t.startContainer,r=(o instanceof Element?o:o.parentElement)?.closest("pre");r&&e.contains(r)?s.append(n):n.split(/\r\n?|\n/).forEach((l,i)=>{i>0&&s.append(document.createElement("br")),l&&s.append(l)}),ne(t,s)},ft=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.userAgent),ht=new Set(["Control","Shift","Alt","Meta"]),mt=e=>{const t=[];return(ft?e.metaKey:e.ctrlKey)&&t.push("Mod"),e.shiftKey&&t.push("Shift"),e.altKey&&t.push("Alt"),ht.has(e.key)||t.push(e.key.length===1?e.key.toUpperCase():e.key),t.join("+")},pt=(e,t)=>{for(const n of e){const s=n.keyboardShortcuts?.[t];if(s)return s}return null},gt=(e,t)=>e.length===t.length&&e.every((n,s)=>n===t[s]),yt=e=>{let t=e,n=P(t.extensions);const s=Fe(t.historyLimit??100);let o=null,r=null,l=!1,i=0,u=0,m=null;const g=new Set;let S=new WeakMap;const h=new Set;let y=!1,p=[],v=null;const A=()=>{u++,g.forEach(c=>c())},U=()=>{m===null&&(m=requestAnimationFrame(()=>{m=null,t.onChange?.(N.getHTML()),t.onChangeJSON?.(N.getJSON())}))},F=c=>{let a=S.get(c);return a||(a={},S.set(c,a)),a},O=c=>{if(o)for(const a of c){if(y=!0,a.target===o){a.addedNodes.forEach(f=>h.add(f));continue}let d=a.target;for(;d&&d.parentNode!==o;)d=d.parentNode;d&&(h.add(d),S.delete(d))}},z=c=>Array.from(c.children,a=>F(a).raw??=a.outerHTML),b=(c=!1)=>{if(!o||!r||(O(r.takeRecords()),!y||l))return;ie(o,n,h),O(r.takeRecords()),h.clear(),y=!1;const a=z(o);gt(a,p)||(s.record({blocks:a,before:v,after:W(o)},c),p=a,U()),v=W(o)??v,A()},se=c=>{if(!c||!o||!r)return;const{blocks:a}=c;let d=0;for(;d<p.length&&d<a.length&&p[d]===a[d];)d++;let f=p.length,T=a.length;for(;f>d&&T>d&&p[f-1]===a[T-1];)f--,T--;const R=Array.from(o.children),le=document.createElement("template");le.innerHTML=H(a.slice(d,T).join(""),n),R.slice(d,f).forEach(Ie=>Ie.remove()),o.insertBefore(le.content,R[f]??null),O(r.takeRecords()),h.clear(),y=!1,p=z(o),Qe(o,c.selection),v=c.selection,A(),U()},re=(()=>{let c=!1;return()=>{const a=!!o&&k(o)!==null;o&&a&&(v=W(o)),(a||c)&&A(),c=a}})(),De=c=>{if(c.isComposing)return;const a=c.metaKey||c.ctrlKey,d=c.key.toLowerCase();if(a&&(d==="z"||d==="y")){c.preventDefault(),d==="z"&&!c.shiftKey?N.history.undo():N.history.redo();return}const f=pt(t.extensions,mt(c));f&&(c.preventDefault(),N.execute(f))},_e=c=>{c.preventDefault();const a=c.clipboardData?.getData("text/html"),d=c.clipboardData?.getData("text/plain");N.change(()=>{const f=o&&k(o);!o||!f||(a?ut(o,f,H(a,n),n):d&&dt(o,f,d))})},ce=(c,a)=>{c.innerHTML=H(a,n),ie(c,n,Array.from(c.childNodes)),p=z(c),s.reset(p),v=null},Pe=()=>{const c=document.createElement("div");return c.contentEditable="true",c.setAttribute("role","textbox"),c.setAttribute("aria-multiline","true"),c.tabIndex=0,ce(c,t.initialValue??""),c.addEventListener("keydown",De),c.addEventListener("paste",_e),c.addEventListener("drop",a=>a.preventDefault()),c.addEventListener("compositionstart",()=>{l=!0}),c.addEventListener("compositionend",()=>{l=!1,b(!0)}),r=new MutationObserver(a=>{O(a),b(!0)}),r.observe(c,{childList:!0,subtree:!0,characterData:!0,attributes:!0}),c},B=c=>{const a=n.marks.get(c);return a&&a.tag===c?a:null},K=c=>{N.change(()=>{const a=o&&k(o);o&&a&&c(o,a)})},je=(c,a)=>{const d=o&&k(o);return o&&d?a(o,d):c},N={get el(){return o},get extensions(){return t.extensions},get revision(){return u},history:{undo:()=>{b(),se(s.undo())},redo:()=>{b(),se(s.redo())},canUndo:()=>s.canUndo(),canRedo:()=>s.canRedo()},mount(c){o??=Pe(),c.append(o),document.addEventListener("selectionchange",re)},unmount(){o?.remove(),document.removeEventListener("selectionchange",re)},destroy(){s.cancelTimer(),m!==null&&(cancelAnimationFrame(m),m=null)},setOptions(c){const a=c.extensions!==void 0&&(c.extensions.length!==t.extensions.length||c.extensions.some((d,f)=>d!==t.extensions[f]));t={...t,...c},a&&(n=P(t.extensions),S=new WeakMap)},subscribe(c){return g.add(c),()=>{g.delete(c)}},execute(c,a){for(const d of t.extensions){const f=d.commands?.[c];if(f){N.change(()=>f(N,a));return}}throw new Error(`Command not found: ${c}`)},isActive(c,a){return!o||!k(o)?!1:(t.extensions.find(f=>f.commands?.[c]&&f.isActive)??t.extensions.find(f=>f.name===c&&f.isActive))?.isActive?.(N,c,a)??!1},getHTML(){return o?(b(),t.sanitize===!1?o.innerHTML:Array.from(o.children,c=>F(c).html??=Q([c],n)).join("")):""},getJSON(){return o?(b(),{type:"doc",content:Array.from(o.children).flatMap(c=>F(c).json??=Ee(c,n))}):{type:"doc",content:[]}},setHTML(c,{history:a=!0}={}){if(!o||!r){t={...t,initialValue:c};return}if(b(),a){o.innerHTML=H(c,n),b();return}ce(o,c),r.takeRecords(),h.clear(),y=!1,A(),U()},change(c){if(!(!o||l)){if(i>0){c();return}b(),i++;try{c()}finally{i--}b()}},toggleMark(c){const a=B(c);a&&K((d,f)=>et(d,f,a))},setMark(c,a,d){const f=B(c);f&&K((T,R)=>xe(T,R,f,a,d))},removeMark(c){const a=B(c);a&&K((d,f)=>Ce(d,f,a))},isMarkActive(c){const a=B(c);return a?je(!1,(d,f)=>Te(d,f,a)):!1},setBlock(c){N.change(()=>o&&nt(o,n,c))},toggleBlock(c){N.setBlock(N.isBlockActive(c)?"p":c)},isBlockActive(c){return o?ot(o,n,c):!1},toggleList(c){N.change(()=>o&&it(o,n,c))},isListActive(c){return o?ct(o,n,c):!1},setBlockStyle(c,a){N.change(()=>o&&st(o,n,c,a))},getBlockStyle(c){return o?rt(o,n,c):null}};return N},Nt=e=>{const[t]=E.useState(()=>yt(e)),{extensions:n,onChange:s,onChangeJSON:o}=e;return E.useEffect(()=>{t.setOptions({extensions:n,onChange:s,onChangeJSON:o})}),E.useEffect(()=>()=>t.destroy(),[t]),t},Me=E.createContext(null),Oe=()=>{const e=E.useContext(Me);if(!e)throw new Error("useEditorContext must be used within an EditorProvider");return e},kt=({editor:e,children:t})=>pe.jsx(Me.Provider,{value:e,children:t}),X=(e,t,n)=>{n===void 0?e.removeAttribute(t):e.setAttribute(t,n)},Be=({className:e,ariaLabel:t,ariaDescribedBy:n})=>{const s=Oe(),o=E.useRef(null);return E.useEffect(()=>{if(o.current)return s.mount(o.current),()=>s.unmount()},[s]),E.useEffect(()=>{const r=s.el;r&&(X(r,"class",e),X(r,"aria-label",t),X(r,"aria-describedby",n))},[s,e,t,n]),pe.jsx("div",{ref:o,style:{display:"contents"}})};Be.displayName="EditorContent";const q=(e,t)=>{const n=E.useRef(null),s=()=>{const o=n.current;if(o&&o.revision===e.revision&&o.selector===t)return o.value;const r=t(e);return n.current={revision:e.revision,selector:t,value:r},r};return E.useSyncExternalStore(e.subscribe,s,s)},bt=(e,t,n)=>q(e,s=>s.isActive(t,n)),Et=e=>q(e,t=>t.history.canUndo()),St=e=>q(e,t=>t.history.canRedo()),Re=e=>`toggle${e[0].toUpperCase()}${e.slice(1)}`,L=e=>{const{name:t,tag:n,aliases:s,shortcut:o}=e,r=Re(t);return{name:t,marks:[{tag:n,type:t,aliases:s}],commands:{[r]:l=>l.toggleMark(n)},keyboardShortcuts:o?{[o]:r}:void 0,isActive:l=>l.isMarkActive(n)}},oe=e=>{const{name:t,tag:n,shortcut:s}=e,o=Re(t);return{name:t,blocks:[{tag:n,type:t}],commands:{[o]:r=>r.toggleBlock(n)},keyboardShortcuts:s?{[s]:o}:void 0,isActive:r=>r.isBlockActive(n)}},vt=L({name:"bold",tag:"strong",aliases:["b"],shortcut:"Mod+B"}),At=L({name:"italic",tag:"em",aliases:["i"],shortcut:"Mod+I"}),Tt=L({name:"underline",tag:"u",shortcut:"Mod+U"}),xt=L({name:"strikethrough",tag:"s",aliases:["del"],shortcut:"Mod+Shift+S"}),Ct=L({name:"code",tag:"code"}),Lt=oe({name:"blockquote",tag:"blockquote"}),wt=oe({name:"codeBlock",tag:"pre"}),D=[1,2,3,4,5,6],Mt={name:"heading",blocks:D.map(e=>({tag:`h${e}`,type:"heading",attrs:{level:e}})),commands:{setHeading:(e,t)=>{D.includes(t)&&e.setBlock(`h${t}`)},removeHeading:e=>e.setBlock("p")},isActive:(e,t,n)=>{if(t==="setHeading")return D.includes(n)&&e.isBlockActive(`h${n}`);const s=D.some(o=>e.isBlockActive(`h${o}`));return t==="removeHeading"?!s:s}},He=(e,t)=>{const n=`toggle${e[0].toUpperCase()}${e.slice(1)}`;return{name:e,blocks:[{tag:t,type:e},{tag:"li",type:"listItem"}],commands:{[n]:s=>s.toggleList(t)},isActive:s=>s.isListActive(t)}},Ot=He("orderedList","ol"),Bt=He("unorderedList","ul"),$={alignLeft:"left",alignCenter:"center",alignRight:"right",alignJustify:"justify"},Rt={name:"textAlign",blockStyles:{"text-align":Object.values($)},commands:Object.fromEntries(Object.entries($).map(([e,t])=>[e,n=>n.setBlockStyle("text-align",t)])),isActive:(e,t)=>t!==void 0&&(e.getBlockStyle("text-align")??"left")===$[t]},me=e=>/^(https?:\/\/|mailto:)/i.test(e),Ht={name:"link",marks:[{tag:"a",type:"link",attrs:{href:e=>e&&me(e)?e:null,target:e=>e==="_blank"?e:null,rel:(e,t)=>t.getAttribute("target")==="_blank"?"noopener noreferrer":null}}],commands:{setLink:(e,t)=>{const n=t?.href;n&&me(n)&&e.setMark("a",{href:n},n)},removeLink:e=>e.removeMark("a")},isActive:e=>e.isMarkActive("a")};exports.Blockquote=Lt;exports.Bold=vt;exports.Code=Ct;exports.CodeBlock=wt;exports.EditorContent=Be;exports.EditorProvider=kt;exports.Heading=Mt;exports.Italic=At;exports.Link=Ht;exports.OrderedList=Ot;exports.Strikethrough=xt;exports.TextAlign=Rt;exports.Underline=Tt;exports.UnorderedList=Bt;exports.block=oe;exports.mark=L;exports.toHTML=Ve;exports.toJSON=Ge;exports.useCanRedo=St;exports.useCanUndo=Et;exports.useEditor=Nt;exports.useEditorContext=Oe;exports.useEditorState=q;exports.useIsActive=bt;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");var n=new Set([`applet`,`audio`,`base`,`embed`,`fencedframe`,`frame`,`frameset`,`iframe`,`link`,`math`,`meta`,`noembed`,`noframes`,`noscript`,`object`,`plaintext`,`portal`,`script`,`style`,`svg`,`template`,`textarea`,`title`,`video`,`xmp`]),r=new Set([`action`,`background`,`cite`,`classid`,`codebase`,`data`,`dynsrc`,`formaction`,`href`,`icon`,`itemid`,`longdesc`,`lowsrc`,`manifest`,`poster`,`profile`,`src`,`usemap`,`xlink:href`]),i=new Set([`archive`,`attributionsrc`,`imagesrcset`,`is`,`ping`,`srcdoc`,`srcset`]),a=e=>n.has(e),o=e=>/^[a-z][a-z0-9-]*$/.test(e),s=e=>o(e)&&!a(e)&&e!==`form`&&!e.includes(`-`),c=(e,t)=>{if(!/^(https?:\/\/|mailto:)/i.test(t))return!1;try{let{protocol:n}=new URL(t);return n===`http:`||n===`https:`||e===`href`&&n===`mailto:`}catch{return!1}},l=e=>/^[a-z][a-z0-9_.:-]*$/.test(e)&&!e.startsWith(`on`)&&!i.has(e),u=(e,t)=>{let n=[];for(let[i,a]of Object.entries(t.attrs??{})){let t=i.toLowerCase();if(!l(t))continue;let o=a(e.getAttribute(t),e);o!==null&&(!r.has(t)||c(t,o))&&n.push([t,o])}return n},d={tag:`p`,type:`paragraph`,aliases:[`div`]},f=e=>{let t=new Map,n=new Map,r=new Map,i=(e,t)=>{if(!s(t.tag))return;let n=t.aliases?.filter(e=>o(e)&&!a(e)&&e!==`form`),r={...t,aliases:n};for(let t of[r.tag,...n??[]])e.set(t,r)};i(n,d);for(let a of e){a.marks?.forEach(e=>i(t,e)),a.blocks?.forEach(e=>i(n,e));for(let[e,t]of Object.entries(a.blockStyles??{}))r.set(e,new Set(t))}return{marks:t,blocks:n,blockStyles:r,blockSelector:Array.from(n.keys()).join(`,`)}},p=(e,t)=>e instanceof HTMLElement&&t.blocks.has(e.localName),m=300,h=e=>{let t=[],n=[],r={blocks:[],before:null,after:null},i=null,a=null,o=()=>{a!==null&&(clearTimeout(a),a=null),i&&(t.push(r),t.length>e&&t.shift(),r=i,i=null,n=[])};return{reset(e){t=[],n=[],i=null,r={blocks:e,before:null,after:null}},record(e,t){t?(i=i?{...e,before:i.before}:e,a!==null&&clearTimeout(a),a=setTimeout(o,m)):(o(),i=e,o())},undo(){o();let e=t.pop();if(!e)return null;let i=r;return n.push(i),r=e,{blocks:e.blocks,selection:i.before}},redo(){o();let e=n.pop();return e?(t.push(r),r=e,{blocks:e.blocks,selection:e.after}):null},canUndo:()=>t.length>0||i!==null,canRedo:()=>n.length>0&&i===null,cancelTimer(){a!==null&&(clearTimeout(a),a=null)}}},g=e=>{let t=window.getSelection();if(!t||t.rangeCount===0)return null;let n=t.getRangeAt(0);return e.contains(n.commonAncestorContainer)?n:null},_=e=>{let t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e))},v=(e,t)=>{let n=document.createRange();n.setStart(e,0),n.setEnd(t,t.length),_(n)},y=e=>{let t=e;for(;t.lastChild;)t=t.lastChild;let n=document.createRange();t.nodeType===Node.TEXT_NODE?n.setStart(t,t.length):t===e?n.setStart(e,0):n.setStartAfter(t),n.collapse(!0),_(n)},b=e=>{let t=e;for(;t.lastChild;)t=t.lastChild;let n=window.getSelection();t.nodeType===Node.TEXT_NODE?n?.collapse(t,t.length):t===e?n?.collapse(e,0):n?.collapse(t.parentNode,Array.prototype.indexOf.call(t.parentNode.childNodes,t))},x=(e,t,n)=>{let r=[];for(let n=t;n!==e;n=n.parentNode)r.push(Array.prototype.indexOf.call(n.parentNode.childNodes,n));return[r.reverse(),n]},S=(e,[t,n])=>{let r=e;for(let e of t){let t=r.childNodes.item(e);if(!t)return[r,r.childNodes.length];r=t}let i=r.nodeType===Node.TEXT_NODE?r.length:r.childNodes.length;return[r,Math.min(n,i)]},C=(e,t)=>{let n=e.firstChild,r=t.firstChild;for(;n&&r;){if(n.nodeName!==r.nodeName||n.nodeValue!==r.nodeValue||!C(n,r))return!1;n=n.nextSibling,r=r.nextSibling}return n===r},w=(e,t,n)=>{let[r,i]=S(e,n),a=document.createRange();a.setStart(e,0),a.setEnd(r,i);let o=a.cloneContents(),s=(o.textContent?.length??0)+o.querySelectorAll(`br`).length,c=r.nodeType===Node.TEXT_NODE?i===0:i<r.childNodes.length,l=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,{acceptNode:e=>e.nodeType===Node.TEXT_NODE||e.nodeName===`BR`?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}),u=[t,0];for(let e=l.nextNode();e;e=l.nextNode())if(e.nodeType===Node.TEXT_NODE){let t=e.length;if(s<t||s===t&&!c)return[e,s];s-=t,u=[e,t]}else{let t=e.parentNode,n=Array.prototype.indexOf.call(t.childNodes,e);if(s===0)return[t,n];if(s--,u=[t,n+1],s===0&&!c)return u}return u},T=e=>{let t=window.getSelection();if(!t?.anchorNode||!t.focusNode||!e.contains(t.anchorNode)||!e.contains(t.focusNode))return null;let n=x(e,t.anchorNode,t.anchorOffset);return{anchor:n,focus:t.isCollapsed?n:x(e,t.focusNode,t.focusOffset)}},ee=(e,t,n)=>{let r=window.getSelection();if(r&&e.isConnected){if(!t)y(e);else{if(n!==void 0){let i=e.ownerDocument.createElement(`template`);if(i.innerHTML=n,!C(i.content,e)){let n=w(i.content,e,t.anchor),a=t.focus===t.anchor?n:w(i.content,e,t.focus);r.setBaseAndExtent(...n,...a);return}}r.setBaseAndExtent(...S(e,t.anchor),...S(e,t.focus))}}},E=(e,t,n=Array.from(e.attributes,({name:e,value:t})=>[e,t]))=>{let r=e.ownerDocument.createElement(t);for(let[e,t]of n)r.setAttribute(e,t);return r.append(...e.childNodes),e.replaceWith(r),r},D=e=>{e.replaceWith(...e.childNodes)},te=(e,t)=>{let n=t;for(;n&&n!==e&&n.parentNode!==e;)n=n.parentNode;return n===e?null:n},O=e=>e instanceof HTMLElement&&(e.localName===`ul`||e.localName===`ol`),ne=(e,t)=>e.attributes.length===t.attributes.length&&Array.from(e.attributes).every(e=>t.getAttribute(e.name)===e.value),re=e=>{let t=window.getSelection(),n=t?.anchorNode??null,r=t?.focusNode??null,i=t?.anchorOffset??0,a=t?.focusOffset??0;e(),t&&n&&r&&n.nodeType===Node.TEXT_NODE&&r.nodeType===Node.TEXT_NODE&&n.isConnected&&r.isConnected&&(t.anchorNode!==n||t.anchorOffset!==i||t.focusNode!==r||t.focusOffset!==a)&&t.setBaseAndExtent(n,Math.min(i,n.length),r,Math.min(a,r.length))},k=(e,t,n)=>{for(let r=e;r&&r!==n;r=r.parentNode)if(r instanceof HTMLElement&&(r.localName===t.tag||t.aliases?.includes(r.localName)))return r;return null},A=(e,t)=>{let n=t.commonAncestorContainer,r=n.nodeType===Node.TEXT_NODE?n.parentNode:n,i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),a=[];for(let n=i.nextNode();n;n=i.nextNode()){if(!t.intersectsNode(n)||n.parentNode===e||O(n.parentNode))continue;let r=n===t.startContainer?t.startOffset:0,i=n===t.endContainer?t.endOffset:n.length;r<i&&a.push({node:n,start:r,end:i})}return a},j=e=>e.map(({node:e,start:t,end:n})=>(n<e.length&&e.splitText(n),t>0?e.splitText(t):e)),ie=(e,t,n,r)=>{let i=e.ownerDocument.createElement(`template`).content.ownerDocument.createElement(t.tag);i.textContent=r;for(let{name:t,value:n}of Array.from(e.attributes))l(t)&&i.setAttribute(t,n);for(let[e,t]of Object.entries(n))l(e.toLowerCase())&&i.setAttribute(e,t);let a=new Map(u(i,t));for(let t of e.getAttributeNames())a.has(t)||e.removeAttribute(t);for(let[t,n]of a)e.getAttribute(t)!==n&&e.setAttribute(t,n)},ae=(e,t,n)=>{if(t.collapsed)return k(t.startContainer,n,e)!==null;let r=A(e,t);return r.length>0&&r.every(t=>k(t.node,n,e))},oe=(e,t,n,r,i)=>{if(t.collapsed){if(!i)return;t.insertNode(document.createTextNode(i))}let a=j(A(e,t));if(a.length!==0){for(let t of a){let i=k(t,n,e);if(i){r&&ie(i,n,r,i.textContent??``);continue}let a=document.createElement(n.tag);r&&ie(a,n,r,t.data),t.replaceWith(a),a.append(t)}v(a[0],a[a.length-1])}},se=(e,t)=>{let n=document.createRange();n.setStart(e,0),n.setEndBefore(t);let r=document.createRange();r.setStartAfter(t),r.setEnd(e,e.childNodes.length);for(let[t,i]of[[n,`before`],[r,`after`]]){let n=t.extractContents();if(!n.textContent&&!n.querySelector(`br`))continue;let r=e.cloneNode(!1);r.append(n),e[i](r)}D(e)},ce=(e,t,n)=>{if(t.collapsed){let r=k(t.startContainer,n,e);r&&re(()=>D(r));return}let r=j(A(e,t));if(r.length!==0){for(let t of r)for(let r=k(t,n,e);r;r=k(t,n,e))se(r,t);v(r[0],r[r.length-1])}},le=(e,t,n)=>{t.collapsed||(ae(e,t,n)?ce(e,t,n):oe(e,t,n))},M=e=>e.nodeType===Node.TEXT_NODE&&/^[\t\n\f\r ]*$/.test(e.textContent??``),ue=e=>Array.from(e.childNodes).some(e=>!M(e)),de=(e,t)=>{let n=[],r=null;for(let i of e.childNodes)p(i,t)?(n.push({nodes:[i],block:i}),r=null):(r||n.push(r={nodes:[],block:null}),r.nodes.push(i));return n},fe=(e,t,n)=>{for(let r of n.blockStyles.keys()){let n=e.style.getPropertyValue(r);n&&!t.style.getPropertyValue(r)&&t.style.setProperty(r,n)}},N=e=>{e.firstChild||e.append(e.ownerDocument.createElement(`br`))},P=(e,t)=>{let n=e.ownerDocument.createElement(`p`);return n.append(...t),N(n),n},pe=e=>{let t=P(e,Array.from(e.childNodes));for(let{name:n,value:r}of e.attributes)t.setAttribute(n,r);return t},me=(e,t,n,r,i)=>{let a=t.findIndex(n);if(a<0)return null;let o=e.ownerDocument.createDocumentFragment(),s=null,c=null,l=()=>{s&&ue(s)&&o.append(s),s=null};for(let u of t.slice(a))if(n(u)){l();let e=i(u);o.append(...e),c=e.at(-1)??c}else s??=e.cloneNode(!1),s.append(...r(u));return l(),e.after(o),ue(e)||e.remove(),c},he=(e,t)=>{let n=t;for(;n.parentNode&&n.parentNode!==e;)n=n.parentNode;return n.parentNode===e?n:null},ge=(e,t,n)=>{let r=de(e,n);if(!r.some(e=>e.block)){let t=pe(e);return e.replaceWith(t),t}return me(e,r,e=>e.nodes.some(e=>t.has(e)),e=>e.nodes,t=>{let r=t.block??P(e,t.nodes);return fe(e,r,n),N(r),[r]})},_e=(e,t)=>{let n=de(e,t);if(!n.some(e=>e.block))return[pe(e)];let r=[];for(let i of n){if(!i.block&&i.nodes.every(M))continue;let n=i.block??P(e,i.nodes);fe(e,n,t),N(n),r.push(n)}return r},ve=(e,t,n)=>{let r=e.ownerDocument.createDocumentFragment(),i=null,a=null;for(let t of Array.from(e.childNodes))t instanceof HTMLElement&&n.has(t)?(N(t),r.append(t),i=t,a=null):i&&(a||(a=e.cloneNode(!1),i.append(a)),a.append(t));if(!i)return null;for(;e.nextSibling;)i.append(e.nextSibling);return t.after(r),e.firstChild||e.remove(),i},ye=(e,t,n)=>{let r=new Map,i=new Set(e),a=null;for(let e of i){let n=e.parentElement;if(!O(n)){let n=_e(e,t);e.replaceWith(...n),a=n[0];continue}let o=n.closest(`li`);for(;o&&!i.has(o);)o=o.parentElement?.closest(`li`)??null;if(o)continue;let s=r.get(n);s||r.set(n,s=new Set),s.add(e)}let o=null;for(let[e,i]of r){let r=e.parentElement;a=r?.localName===`li`?ve(e,r,i)??a:me(e,Array.from(e.children),e=>i.has(e),e=>[e],e=>{let r=e.contains(n??null),i=_e(e,t);return e.remove(),r&&(o=i.find(e=>e.contains(n??null))??i[0]),i})??a}return o??a},be=(e,t)=>{let n=e.parentElement;if(O(n)){let t=n.cloneNode(!1);for(;e.nextSibling;)t.append(e.nextSibling);n.after(e),t.firstChild&&e.after(t),n.firstChild||n.remove()}return E(e,t)},xe=(e,t)=>p(e,t)&&!O(e),F=(e,t,n)=>{for(let r=e;r&&r!==t;r=r.parentNode)if(xe(r,n))return r;return null},Se=(e,t)=>{let n=document.createRange();return n.selectNodeContents(t),e.compareBoundaryPoints(Range.START_TO_START,n)>0&&n.setStart(e.startContainer,e.startOffset),e.compareBoundaryPoints(Range.END_TO_END,n)<0&&n.setEnd(e.endContainer,e.endOffset),n.toString()!==``},I=(e,t)=>e.childNodes[t]??e.lastChild??e,L=(e,t,n)=>{let r=F(I(t.startContainer,t.startOffset),e,n),i=F(I(t.endContainer,t.endOffset),e,n);if(!r)return[];if(!i||r===i)return[r];let a=Array.from(e.querySelectorAll(n.blockSelector)).filter(e=>xe(e,n)&&!e.querySelector(n.blockSelector)&&t.intersectsNode(e));return a.length>1&&!Se(t,a[a.length-1])&&a.pop(),a},R=e=>{if(!g(e))return null;if(e.childNodes.length===0){let t=document.createElement(`p`);t.append(document.createElement(`br`)),e.append(t),window.getSelection()?.collapse(t,0)}return g(e)},Ce=(e,t,n)=>{let r=window.getSelection(),i=g(e);if(!r||!i)return;let a=(n,r,i=r>0&&r===n.childNodes.length)=>{let a=n.childNodes[r-Number(i)];return()=>{if(a&&e.contains(a)){let e=a.parentNode;return e!==n&&p(a,t)?[a,i?a.childNodes.length:0]:e!==n&&a.nodeName===`BR`&&e.childNodes.length===1?[e,0]:[e,Array.prototype.indexOf.call(e.childNodes,a)+Number(i)]}if(n===e||!e.contains(n))return null;let o=n.nodeType===Node.TEXT_NODE?n.length:n.childNodes.length;return[n,Math.min(r,o)]}},{startContainer:o,startOffset:s,endContainer:c,endOffset:l,collapsed:u}=i,d=!u&&r.anchorNode===c&&r.anchorOffset===l,f=a(o,s),m=u?f:a(c,l,!0),h=n();if(!h)return;let _=d?m():f(),v=u?_:d?f():m();_&&v?(r.anchorNode!==_[0]||r.anchorOffset!==_[1]||r.focusNode!==v[0]||r.focusOffset!==v[1])&&r.setBaseAndExtent(..._,...v):u&&s===0?r.collapse(h,0):(u||!e.contains(r.anchorNode)||r.anchorNode===e)&&b(h)},z=(e,t,n)=>{let r=(e instanceof Element?e:e.parentElement)?.closest(n)??null;return r!==t&&t.contains(r)?r:null},we=(e,t,n)=>{if(!t.collapsed||t.startContainer===e)return null;let{startContainer:r,startOffset:i}=t;if(i&&r.nodeType===Node.TEXT_NODE)return null;let a=r.childNodes[i],o=z(r,e,`li, blockquote`);if(!o||!p(o,n))return null;let s=a??r,c=o.localName===`blockquote`,l=he(o,s),u=c&&l&&p(l,n)?l:o;if(!a&&i!==0){let t=F(s,e,n);if(i!==1||r.firstChild?.nodeName!==`BR`||!t||t.textContent||t.querySelectorAll(`br`).length!==1)return null}for(let e=s;e!==u;e=e.parentNode){let t=e.previousSibling,r=e.parentNode===o;for(;r&&t&&M(t)&&(p(e,n)||c&&/[\n\r]/.test(t.textContent??``));)t=t.previousSibling;if(t){if(c&&r&&p(t,n))break;return null}}return c?()=>ge(o,new Set([l??o]),n):()=>ye([o],n,s)},Te=(e,t,n,r)=>{let i=new Map;for(let r of e){let e=z(r,t,`blockquote`);if(!e)continue;let a=i.get(e);a||i.set(e,a=new Set);let o=he(e,r===e&&n.collapsed?I(n.startContainer,n.startOffset):r);o&&a.add(o)}if(!n.collapsed)for(let[e,t]of i)for(let i of e.childNodes)p(i,r)||M(i)||!n.intersectsNode(i)||n.endContainer===i&&n.endOffset===0||t.add(i);let a=null;for(let[e,t]of i)a=ge(e,t,r)??a;return a},B=(e,t,n)=>e.localName===t||t===`blockquote`&&z(e,n,t)!==null,Ee=(e,t,n,r=!1)=>{let i=t.blocks.get(n);if(!i||i.tag!==n||n===`li`||n===`ul`||n===`ol`)return;let a=R(e);if(!a)return;let o=L(e,a,t),s=r&&o.every(t=>B(t,n,e)),c=s?`p`:n;Ce(e,t,()=>{if(s&&n===`blockquote`)return Te(o,e,a,t);let r=null;for(let t of o)r=B(t,c,e)?t:t.localName===`li`?be(t,c):E(t,c);return r})},De=(e,t,n)=>{let r=g(e);if(!r)return!1;let i=L(e,r,t);return i.length>0&&i.every(t=>B(t,n,e))},Oe=(e,t,n,r)=>{if(!t.blockStyles.get(n)?.has(r))return;let i=R(e);if(i)for(let a of L(e,i,t))a.style.setProperty(n,r)},ke=(e,t,n)=>{let r=g(e);if(!r)return null;let[i]=L(e,r,t);return i?.style.getPropertyValue(n)||null},V=(e,t)=>e.localName===`li`&&e.parentElement?.localName===t,Ae=(e,t,n)=>Array.from(new Set(L(e,t,n).map(t=>z(t,e,`li`)??t))),je=(e,t,n)=>{let r=g(e);if(!r)return!1;let i=Ae(e,r,t);return i.length>0&&i.every(e=>V(e,n))},Me=(e,t)=>{let n=document.createElement(t),r=document.createElement(`li`),i=e.getAttribute(`style`);return i&&r.setAttribute(`style`,i),r.append(...e.childNodes),n.append(r),e.replaceWith(n),r},Ne=(e,t,n)=>{if(!t.blocks.has(n))return;let r=R(e);if(!r)return;let i=Ae(e,r,t),a=i.every(e=>V(e,n));Ce(e,t,()=>{if(a)return ye(i,t,r.collapsed?r.startContainer:void 0);let e=null;for(let t of i)e=V(t,n)?t:Me(t.localName===`li`?be(t,`p`):t,n);return e})},Pe=`address.article.aside.blockquote.dd.details.div.dl.dt.fieldset.figcaption.figure.footer.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.summary.table.tbody.td.tfoot.th.thead.tr.ul`.split(`.`).join(`,`),Fe=e=>{let t=document.createRange();return t.selectNodeContents(e),Array.from(t.cloneContents().childNodes)},H=(e,t)=>{let n=[];for(let r of(e??``).split(`;`)){let e=r.indexOf(`:`);if(e===-1)continue;let i=r.slice(0,e).trim().toLowerCase(),a=r.slice(e+1).trim().toLowerCase();t.blockStyles.get(i)?.has(a)&&n.push(`${i}: ${a}`)}return n.join(`; `)},U=null,W=(e,t,n)=>{for(let r of e){let e=Ie(r,n);e&&t.appendChild(e)}},Ie=(e,t)=>{let n=U,r=e=>{let r=n.createDocumentFragment();return W(e,r,t),r};if(e instanceof HTMLFormElement)return r(Fe(e));if(e.nodeType===Node.TEXT_NODE)return n.createTextNode(e.textContent??``);if(!(e instanceof Element))return null;let i=e.localName;if(a(i))return null;if(i===`br`)return n.createElement(`br`);let o=t.marks.get(i);if(o){let r=n.createElement(o.tag);for(let[t,n]of u(e,o))r.setAttribute(t,n);return W(e.childNodes,r,t),r}let s=e.matches(Pe),c=e.querySelector(Pe)!==null,l=t.blocks.get(i);if((l?.tag===`p`||!l&&s)&&c)return r(e.childNodes);if(l||s){let r=n.createElement(l?.tag??`p`),i=H(e.getAttribute(`style`),t);return i&&r.setAttribute(`style`,i),W(e.childNodes,r,t),l||r.childNodes.length>0?r:null}return r(e.childNodes)},G=(e,t)=>{U??=document.implementation.createHTMLDocument(``);let n=U.createElement(`div`);return W(e,n,t),n.innerHTML},K=(e,t)=>e?G(new DOMParser().parseFromString(e,`text/html`).body.childNodes,t):``,Le=(e,t)=>{let n=Array.from(e.childNodes),r=n.some(e=>p(e,t)),i=[],a=[],o=()=>{if(a.length!==0){if(a.some(e=>e.nodeType===Node.ELEMENT_NODE||e.textContent?.trim())||!r){let t=(e.ownerDocument??document).createElement(`p`);e.insertBefore(t,a[0]),t.append(...a),i.push(t)}else a.forEach(t=>e.removeChild(t));a=[]}};for(let r of n)p(r,t)?o():r.nodeType===Node.ELEMENT_NODE||r.nodeType===Node.TEXT_NODE?a.push(r):e.removeChild(r);return o(),i},Re=e=>{let t=e.nextSibling;for(;t instanceof Element&&t.localName===e.localName;)e.append(...t.childNodes),t.remove(),t=e.nextSibling},ze=e=>{for(let t of Array.from(e.childNodes)){if(t instanceof Element&&t.localName===`li`)continue;if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim()){t.remove();continue}let n=e.ownerDocument.createElement(`li`);t.replaceWith(n),n.append(t)}e.children.length===0?e.remove():Re(e)},Be=(e,t,n)=>{let r=t;for(let i of[t,...t.querySelectorAll(`*`)]){if(!e.contains(i))continue;let t=i.localName;if(t===`br`)continue;let a=n.marks.get(t),o=a??n.blocks.get(t);if(!o){D(i);continue}let s=i;if(o.tag!==t){let e=!a&&H(i.getAttribute(`style`),n),t=a?u(i,a):[];e&&t.push([`style`,e]),s=E(i,o.tag,t)}if(i===r&&(r=s),a){let t=s.parentElement?.closest(o.tag);s.childNodes.length===0?s.remove():t&&t!==e&&e.contains(t)&&D(s)}}r.normalize();for(let t of Array.from(r.querySelectorAll(`*`))){if(!n.marks.has(t.localName)||!e.contains(t))continue;let r=t.nextSibling;for(;r instanceof Element&&r.localName===t.localName&&ne(t,r);)t.append(...r.childNodes),r.remove(),r=t.nextSibling}r.normalize();for(let t of[r,...r.querySelectorAll(`ul, ol`)])O(t)&&e.contains(t)&&ze(t)},Ve=(e,t,n)=>{re(()=>{let r=new Set(Le(e,t));for(let t of n)t instanceof Element&&t.parentNode===e&&r.add(t);for(let n of r)n.parentNode===e&&Be(e,n,t);for(let t of Array.from(e.children))O(t)&&t.parentNode===e&&Re(t)})},He=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),Ue=(e,t,n,r=!1)=>{let i=e=>{let n={type:`text`,text:e};return t.length>0&&(n.marks=[...t]),[n]},o=(e,t)=>Array.from(e).flatMap(e=>Ue(e,t,n));if(e instanceof HTMLFormElement)return o(Fe(e),t);if(e.nodeType===Node.TEXT_NODE){let t=e.textContent??``;return(r?t.trim():t)?i(t):[]}if(!(e instanceof Element))return[];let s=e.localName;if(a(s))return[];if(s===`br`)return r?[]:i(`
2
+ `);let c=n.marks.get(s);if(c){let n={type:c.type},r=Object.fromEntries(u(e,c));return Object.keys(r).length>0&&(n.attrs=r),o(e.childNodes,[...t,n])}let l=n.blocks.get(s);if(!l)return o(e.childNodes,t);let d={type:l.type},f={...l.attrs};for(let t of H(e.getAttribute(`style`),n).split(`; `)){let[e,n]=t.split(`: `);n&&(f[He(e)]=n)}Object.keys(f).length>0&&(d.attrs=f);let p=o(e.childNodes,t);return p.length>0&&(d.content=p),[d]},We=(e,t)=>Ue(e,[],t,!0),Ge=(e,t)=>G(e.childNodes,f(t)),Ke=(e,t)=>{let n=f(t);return{type:`doc`,content:Array.from(e.childNodes).flatMap(e=>We(e,n))}},qe=(e,t)=>{let n=new WeakMap,r=new Set,i=!1,a=e=>{let t=n.get(e);return t||(t={},n.set(e,t)),t},o=t=>{for(let a of t){if(i=!0,a.target===e){a.addedNodes.forEach(e=>r.add(e));continue}let t=te(e,a.target);t&&(r.add(t),n.delete(t))}},s=new MutationObserver(e=>{o(e),t()}),c=()=>{r.clear(),i=!1},l=(t,n)=>{e.innerHTML=K(t,n)};return{root:e,observe(){s.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0})},normalizeChanges(t,n){return o(s.takeRecords()),!i||n?!1:(Ve(e,t,r),o(s.takeRecords()),c(),!0)},discardChanges(){s.takeRecords(),c()},invalidateCache(){n=new WeakMap},rawBlocks(){return Array.from(e.children,e=>a(e).raw??=e.outerHTML)},getHTML(t,n){return n?Array.from(e.children,e=>a(e).html??=G([e],t)).join(``):e.innerHTML},getJSON(t){return{type:`doc`,content:Array.from(e.children).flatMap(e=>a(e).json??=We(e,t))}},replaceHTML:l,loadHTML(t,n){l(t,n),Ve(e,n,Array.from(e.childNodes))},replaceBlocks(t,n,r){let i=0;for(;i<t.length&&i<n.length&&t[i]===n[i];)i++;let a=t.length,l=n.length;for(;a>i&&l>i&&t[a-1]===n[l-1];)a--,l--;let u=Array.from(e.children),d=e.ownerDocument.createElement(`template`);d.innerHTML=K(n.slice(i,l).join(``),r),u.slice(i,a).forEach(e=>e.remove()),e.insertBefore(d.content,u[a]??null),o(s.takeRecords()),c()}}},q=(e,t)=>{e.deleteContents();let n=t.lastChild;if(e.insertNode(t),!n)return;let r=n.nextSibling;r?.nodeName===`BR`&&!r.nextSibling&&r.remove(),y(n)},Je=(e,t,n,r)=>{t.deleteContents();let i=te(e,t.startContainer);if(!i||!p(i,r)){q(t,n);return}Le(n,r);let a=n.lastChild;if(!a)return;let o=document.createRange();o.selectNodeContents(i),o.setStart(t.startContainer,t.startOffset);let s=i.cloneNode(!1);s.append(o.extractContents()),i.after(n,s);for(let e of[i,s])e.textContent?.trim()||e.remove();y(a)},Ye=(e,t,n,r)=>{let i=document.createElement(`template`);i.innerHTML=n;let a=i.content,o=a.childNodes.length===1?a.firstChild:null;o instanceof HTMLElement&&o.localName===`p`&&!o.querySelector(r.blockSelector)&&D(o),a.querySelector(r.blockSelector)?Je(e,t,a,r):q(t,a)},Xe=(e,t,n)=>{let r=document.createDocumentFragment(),i=t.startContainer,a=(i instanceof Element?i:i.parentElement)?.closest(`pre`);a&&e.contains(a)?r.append(n):n.split(/\r\n?|\n/).forEach((e,t)=>{t>0&&r.append(document.createElement(`br`)),e&&r.append(e)}),q(t,r)},Ze=typeof navigator<`u`&&/Mac|iPhone|iPad|iPod/.test(navigator.userAgent),Qe=new Set([`Control`,`Shift`,`Alt`,`Meta`]),$e=e=>{let t=[];return(Ze?e.metaKey:e.ctrlKey)&&t.push(`Mod`),e.shiftKey&&t.push(`Shift`),e.altKey&&t.push(`Alt`),Qe.has(e.key)||t.push(e.key.length===1?e.key.toUpperCase():e.key),t.join(`+`)},et=(e,t)=>{for(let n of e){let e=n.keyboardShortcuts?.[t];if(e)return e}return null},tt=(e,t,n)=>{e.addEventListener(`keydown`,e=>{if(e.isComposing)return;let n=e.metaKey||e.ctrlKey,r=e.key.toLowerCase();if(n&&(r===`z`||r===`y`)){e.preventDefault(),r===`z`&&!e.shiftKey?t.history.undo():t.history.redo();return}let i=et(t.extensions,$e(e));i&&(e.preventDefault(),t.execute(i))}),e.addEventListener(`beforeinput`,r=>{if(r.inputType!==`deleteContentBackward`||!r.cancelable||r.defaultPrevented||n.composing||r.isComposing)return;n.flushTyping();let i=g(e);if(!i)return;let a=we(e,i,n.schema);if(!a)return;let o=i.startContainer;r.preventDefault(),t.change(()=>{let e=a();e&&window.getSelection()?.collapse(e.contains(o)?o:e,0)})}),e.addEventListener(`paste`,r=>{r.preventDefault();let i=r.clipboardData?.getData(`text/html`),a=r.clipboardData?.getData(`text/plain`);t.change(()=>{let t=g(e);if(t){if(i){let r=n.schema;Ye(e,t,K(i,r),r)}else a&&Xe(e,t,a)}})}),e.addEventListener(`drop`,e=>e.preventDefault()),e.addEventListener(`compositionstart`,()=>n.setComposing(!0)),e.addEventListener(`compositionend`,()=>{n.setComposing(!1),n.flushTyping()})},nt=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),rt=e=>{let t=e,n=f(t.extensions),r=h(t.historyLimit??100),i=null,a=!1,o=0,s=0,c=null,l=new Set,u=[],d=null,p=()=>{s++,l.forEach(e=>e())},m=()=>{c===null&&(c=requestAnimationFrame(()=>{c=null,t.onChange?.(D.getHTML()),t.onChangeJSON?.(D.getJSON())}))},_=(e=!1)=>{if(!i?.normalizeChanges(n,a))return;let{root:t}=i,o=i.rawBlocks(),s=T(t);nt(o,u)||(r.record({blocks:o,before:d,after:s},e),u=o,m()),d=s??d,p()},v=e=>{if(!e||!i)return;let{root:t}=i,{blocks:r}=e;i.replaceBlocks(u,r,n),u=i.rawBlocks(),ee(t,e.selection,nt(u,r)?void 0:r.join(``)),d=T(t),p(),m()},y=(()=>{let e=!1;return()=>{let t=i?.root,n=!!t&&g(t)!==null;t&&n&&(d=T(t)),(n||e)&&p(),e=n}})(),b=(e,t)=>{e.loadHTML(t,n),u=e.rawBlocks(),r.reset(u),d=null},x=()=>{let e=document.createElement(`div`);e.contentEditable=`true`,e.setAttribute(`role`,`textbox`),e.setAttribute(`aria-multiline`,`true`),e.tabIndex=0;let r=qe(e,()=>_(!0));return b(r,t.initialValue??``),tt(e,D,{get schema(){return n},get composing(){return a},setComposing(e){a=e},flushTyping:()=>_(!0)}),r.observe(),r},S=e=>{let t=n.marks.get(e);return t&&t.tag===e?t:null},C=e=>{D.change(()=>{let t=i?.root,n=t&&g(t);t&&n&&e(t,n)})},w=(e,t)=>{let n=i?.root,r=n&&g(n);return n&&r?t(n,r):e},E=e=>{D.change(()=>{i&&e(i.root)})},D={get el(){return i?.root??null},get extensions(){return t.extensions},get revision(){return s},history:{undo:()=>{_(),v(r.undo())},redo:()=>{_(),v(r.redo())},canUndo:()=>r.canUndo(),canRedo:()=>r.canRedo()},mount(e){i??=x(),e.append(i.root),document.addEventListener(`selectionchange`,y)},unmount(){i?.root.remove(),document.removeEventListener(`selectionchange`,y)},destroy(){r.cancelTimer(),c!==null&&(cancelAnimationFrame(c),c=null)},setOptions(e){let r=e.extensions!==void 0&&(e.extensions.length!==t.extensions.length||e.extensions.some((e,n)=>e!==t.extensions[n]));t={...t,...e},r&&(n=f(t.extensions),i?.invalidateCache())},subscribe(e){return l.add(e),()=>{l.delete(e)}},execute(e,n){for(let r of t.extensions){let t=r.commands?.[e];if(t){D.change(()=>t(D,n));return}}throw Error(`Command not found: ${e}`)},isActive(e,n){return!i||!g(i.root)?!1:(t.extensions.find(t=>t.commands?.[e]&&t.isActive)??t.extensions.find(t=>t.name===e&&t.isActive))?.isActive?.(D,e,n)??!1},getHTML(){return i?(_(),i.getHTML(n,t.sanitize!==!1)):``},getJSON(){return i?(_(),i.getJSON(n)):{type:`doc`,content:[]}},setHTML(e,{history:r=!0}={}){i?(_(),r?(i.replaceHTML(e,n),_()):(b(i,e),i.discardChanges(),p(),m())):t={...t,initialValue:e}},change(e){if(i&&!a){if(o>0)e();else{_(),d=T(i.root)??d,o++;try{e()}finally{o--}_()}}},toggleMark(e){let t=S(e);t&&C((e,n)=>le(e,n,t))},setMark(e,t,n){let r=S(e);r&&C((e,i)=>oe(e,i,r,t,n))},removeMark(e){let t=S(e);t&&C((e,n)=>ce(e,n,t))},isMarkActive(e){let t=S(e);return t?w(!1,(e,n)=>ae(e,n,t)):!1},setBlock(e){E(t=>Ee(t,n,e))},toggleBlock(e){E(t=>Ee(t,n,e,!0))},isBlockActive(e){return i?De(i.root,n,e):!1},toggleList(e){E(t=>Ne(t,n,e))},isListActive(e){return i?je(i.root,n,e):!1},setBlockStyle(e,t){E(r=>Oe(r,n,e,t))},getBlockStyle(e){return i?ke(i.root,n,e):null}};return D},it=t=>{let[n]=(0,e.useState)(()=>rt(t)),{extensions:r,onChange:i,onChangeJSON:a}=t;return(0,e.useEffect)(()=>{n.setOptions({extensions:r,onChange:i,onChangeJSON:a})}),(0,e.useEffect)(()=>()=>n.destroy(),[n]),n},at=(0,e.createContext)(null),ot=()=>{let t=(0,e.useContext)(at);if(!t)throw Error(`useEditorContext must be used within an EditorProvider`);return t},st=({editor:e,children:n})=>(0,t.jsx)(at.Provider,{value:e,children:n}),J=(e,t,n)=>{n===void 0?e.removeAttribute(t):e.setAttribute(t,n)},ct=({className:n,ariaLabel:r,ariaDescribedBy:i})=>{let a=ot(),o=(0,e.useRef)(null);return(0,e.useEffect)(()=>{if(o.current)return a.mount(o.current),()=>a.unmount()},[a]),(0,e.useEffect)(()=>{let e=a.el;e&&(J(e,`class`,n),J(e,`aria-label`,r),J(e,`aria-describedby`,i))},[a,n,r,i]),(0,t.jsx)(`div`,{ref:o,style:{display:`contents`}})};ct.displayName=`EditorContent`;var Y=(t,n)=>{let r=(0,e.useRef)(null),i=()=>{let e=r.current;if(e&&e.revision===t.revision&&e.selector===n)return e.value;let i=n(t);return r.current={revision:t.revision,selector:n,value:i},i};return(0,e.useSyncExternalStore)(t.subscribe,i,i)},lt=(e,t,n)=>Y(e,e=>e.isActive(t,n)),ut=e=>Y(e,e=>e.history.canUndo()),dt=e=>Y(e,e=>e.history.canRedo()),ft=e=>`toggle${e[0].toUpperCase()}${e.slice(1)}`,X=e=>{let{name:t,tag:n,aliases:r,shortcut:i}=e,a=ft(t);return{name:t,marks:[{tag:n,type:t,aliases:r}],commands:{[a]:e=>e.toggleMark(n)},keyboardShortcuts:i?{[i]:a}:void 0,isActive:e=>e.isMarkActive(n)}},Z=e=>{let{name:t,tag:n,shortcut:r}=e,i=ft(t);return{name:t,blocks:[{tag:n,type:t}],commands:{[i]:e=>e.toggleBlock(n)},keyboardShortcuts:r?{[r]:i}:void 0,isActive:e=>e.isBlockActive(n)}},pt=X({name:`bold`,tag:`strong`,aliases:[`b`],shortcut:`Mod+B`}),mt=X({name:`italic`,tag:`em`,aliases:[`i`],shortcut:`Mod+I`}),ht=X({name:`underline`,tag:`u`,shortcut:`Mod+U`}),gt=X({name:`strikethrough`,tag:`s`,aliases:[`del`],shortcut:`Mod+Shift+S`}),_t=X({name:`code`,tag:`code`}),vt=Z({name:`blockquote`,tag:`blockquote`}),yt=Z({name:`codeBlock`,tag:`pre`}),Q=[1,2,3,4,5,6],bt={name:`heading`,blocks:Q.map(e=>({tag:`h${e}`,type:`heading`,attrs:{level:e}})),commands:{setHeading:(e,t)=>{Q.includes(t)&&e.setBlock(`h${t}`)},removeHeading:e=>e.setBlock(`p`)},isActive:(e,t,n)=>{if(t===`setHeading`)return Q.includes(n)&&e.isBlockActive(`h${n}`);let r=Q.some(t=>e.isBlockActive(`h${t}`));return t===`removeHeading`?!r:r}},xt=(e,t)=>{let n=`toggle${e[0].toUpperCase()}${e.slice(1)}`;return{name:e,blocks:[{tag:t,type:e},{tag:`li`,type:`listItem`}],commands:{[n]:e=>e.toggleList(t)},isActive:e=>e.isListActive(t)}},St=xt(`orderedList`,`ol`),Ct=xt(`unorderedList`,`ul`),$={alignLeft:`left`,alignCenter:`center`,alignRight:`right`,alignJustify:`justify`},wt={name:`textAlign`,blockStyles:{"text-align":Object.values($)},commands:Object.fromEntries(Object.entries($).map(([e,t])=>[e,e=>e.setBlockStyle(`text-align`,t)])),isActive:(e,t)=>t!==void 0&&(e.getBlockStyle(`text-align`)??`left`)===$[t]},Tt={name:`link`,marks:[{tag:`a`,type:`link`,attrs:{href:e=>e&&c(`href`,e)?e:null,target:e=>e===`_blank`?e:null,rel:(e,t)=>t.getAttribute(`target`)===`_blank`?`noopener noreferrer`:null}}],commands:{setLink:(e,t)=>{let n=t?.href;n&&c(`href`,n)&&e.setMark(`a`,{href:n},n)},removeLink:e=>e.removeMark(`a`)},isActive:e=>e.isMarkActive(`a`)};exports.Blockquote=vt,exports.Bold=pt,exports.Code=_t,exports.CodeBlock=yt,exports.EditorContent=ct,exports.EditorProvider=st,exports.Heading=bt,exports.Italic=mt,exports.Link=Tt,exports.OrderedList=St,exports.Strikethrough=gt,exports.TextAlign=wt,exports.Underline=ht,exports.UnorderedList=Ct,exports.block=Z,exports.mark=X,exports.toHTML=Ge,exports.toJSON=Ke,exports.useCanRedo=dt,exports.useCanUndo=ut,exports.useEditor=it,exports.useEditorContext=ot,exports.useEditorState=Y,exports.useIsActive=lt;
package/dist/index.d.cts CHANGED
@@ -76,7 +76,7 @@ export declare type EditorInstance = {
76
76
  /** Runs a DOM edit, then normalizes the document, records history and reports the change */
77
77
  change: (edit: () => void) => void;
78
78
  toggleMark: (tag: string) => void;
79
- /** With only a caret, `text` is inserted and becomes the marked content */
79
+ /** Validates attributes against the mark spec. With only a caret, inserts and marks `text`. */
80
80
  setMark: (tag: string, attrs?: Record<string, string>, text?: string) => void;
81
81
  removeMark: (tag: string) => void;
82
82
  isMarkActive: (tag: string) => boolean;
@@ -142,7 +142,7 @@ export declare type MarkSpec = {
142
142
  type: string;
143
143
  /** Other tags read as this mark and rewritten to `tag` */
144
144
  aliases?: string[];
145
- /** Attributes to keep. A rule returns the value to write, or null to leave the attribute out. */
145
+ /** Attribute rules for editing and serialization. Return a value to keep it or null to drop it. */
146
146
  attrs?: Record<string, AttributeRule>;
147
147
  };
148
148
 
package/dist/index.d.ts CHANGED
@@ -76,7 +76,7 @@ export declare type EditorInstance = {
76
76
  /** Runs a DOM edit, then normalizes the document, records history and reports the change */
77
77
  change: (edit: () => void) => void;
78
78
  toggleMark: (tag: string) => void;
79
- /** With only a caret, `text` is inserted and becomes the marked content */
79
+ /** Validates attributes against the mark spec. With only a caret, inserts and marks `text`. */
80
80
  setMark: (tag: string, attrs?: Record<string, string>, text?: string) => void;
81
81
  removeMark: (tag: string) => void;
82
82
  isMarkActive: (tag: string) => boolean;
@@ -142,7 +142,7 @@ export declare type MarkSpec = {
142
142
  type: string;
143
143
  /** Other tags read as this mark and rewritten to `tag` */
144
144
  aliases?: string[];
145
- /** Attributes to keep. A rule returns the value to write, or null to leave the attribute out. */
145
+ /** Attribute rules for editing and serialization. Return a value to keep it or null to drop it. */
146
146
  attrs?: Record<string, AttributeRule>;
147
147
  };
148
148