noteloom 0.3.3 → 0.5.0

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.
Files changed (104) hide show
  1. package/README.md +173 -808
  2. package/bin/noteloom.mjs +139 -0
  3. package/dist/canvas.cjs +2 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.ts +2 -0
  6. package/dist/canvas.js +5 -0
  7. package/dist/canvas.js.map +1 -0
  8. package/dist/collab.cjs +2 -0
  9. package/dist/collab.cjs.map +1 -0
  10. package/dist/collab.d.ts +19 -0
  11. package/dist/collab.js +379 -0
  12. package/dist/collab.js.map +1 -0
  13. package/dist/comments.cjs +2 -0
  14. package/dist/comments.cjs.map +1 -0
  15. package/dist/comments.d.ts +17 -0
  16. package/dist/comments.js +19 -0
  17. package/dist/comments.js.map +1 -0
  18. package/dist/index.cjs +2 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +374 -34
  21. package/dist/index.js +3983 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/persistence.cjs +2 -0
  24. package/dist/persistence.cjs.map +1 -0
  25. package/dist/persistence.d.ts +11 -0
  26. package/dist/persistence.js +12 -0
  27. package/dist/persistence.js.map +1 -0
  28. package/dist/shared/CommentAvatar-TKqsM8vG.js +53 -0
  29. package/dist/shared/CommentAvatar-TKqsM8vG.js.map +1 -0
  30. package/dist/shared/CommentAvatar-V457IgoQ.cjs +2 -0
  31. package/dist/shared/CommentAvatar-V457IgoQ.cjs.map +1 -0
  32. package/dist/shared/CommentThreadCard-CwKd6fp3.js +213 -0
  33. package/dist/shared/CommentThreadCard-CwKd6fp3.js.map +1 -0
  34. package/dist/shared/CommentThreadCard-YziIa8My.cjs +2 -0
  35. package/dist/shared/CommentThreadCard-YziIa8My.cjs.map +1 -0
  36. package/dist/shared/CommentsPanel-DezejDdE.cjs +2 -0
  37. package/dist/shared/CommentsPanel-DezejDdE.cjs.map +1 -0
  38. package/dist/shared/CommentsPanel-dx7IaoqS.js +76 -0
  39. package/dist/shared/CommentsPanel-dx7IaoqS.js.map +1 -0
  40. package/dist/shared/VersionHistory-DhYb8C2e.js +1120 -0
  41. package/dist/shared/VersionHistory-DhYb8C2e.js.map +1 -0
  42. package/dist/shared/VersionHistory-DuSxis_7.cjs +12 -0
  43. package/dist/shared/VersionHistory-DuSxis_7.cjs.map +1 -0
  44. package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs +2 -0
  45. package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs.map +1 -0
  46. package/dist/shared/VoiceListeningIndicator-bv285FSY.js +338 -0
  47. package/dist/shared/VoiceListeningIndicator-bv285FSY.js.map +1 -0
  48. package/dist/shared/fieldRegistry-BoYyW3GH.cjs +2 -0
  49. package/dist/shared/fieldRegistry-BoYyW3GH.cjs.map +1 -0
  50. package/dist/shared/fieldRegistry-PjJWXFoB.js +223 -0
  51. package/dist/shared/fieldRegistry-PjJWXFoB.js.map +1 -0
  52. package/dist/shared/icons-BCseh2pt.cjs +3531 -0
  53. package/dist/shared/icons-BCseh2pt.cjs.map +1 -0
  54. package/dist/shared/icons-D5Ctow8R.js +4279 -0
  55. package/dist/shared/icons-D5Ctow8R.js.map +1 -0
  56. package/dist/shared/index-CbIBsFmI.cjs +2 -0
  57. package/dist/shared/index-CbIBsFmI.cjs.map +1 -0
  58. package/dist/shared/index-D_8hJpI7.js +2145 -0
  59. package/dist/shared/index-D_8hJpI7.js.map +1 -0
  60. package/dist/shared/indexedDbPersistence-BKlGPFTP.js +112 -0
  61. package/dist/shared/indexedDbPersistence-BKlGPFTP.js.map +1 -0
  62. package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs +2 -0
  63. package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs.map +1 -0
  64. package/dist/shared/leafBlockFactory-CaLWUcfa.cjs +2 -0
  65. package/dist/shared/leafBlockFactory-CaLWUcfa.cjs.map +1 -0
  66. package/dist/shared/leafBlockFactory-DSa1XCox.js +335 -0
  67. package/dist/shared/leafBlockFactory-DSa1XCox.js.map +1 -0
  68. package/dist/shared/serialize-BqKU9EZy.js +86 -0
  69. package/dist/shared/serialize-BqKU9EZy.js.map +1 -0
  70. package/dist/shared/serialize-CqwX55uK.cjs +3 -0
  71. package/dist/shared/serialize-CqwX55uK.cjs.map +1 -0
  72. package/dist/shared/starter-kit-DyX1U84W.cjs +27 -0
  73. package/dist/shared/starter-kit-DyX1U84W.cjs.map +1 -0
  74. package/dist/shared/starter-kit-mfeNxqFn.js +4980 -0
  75. package/dist/shared/starter-kit-mfeNxqFn.js.map +1 -0
  76. package/dist/shared/usePopoverEdgeClamp-CPRWQtZV.cjs +2 -0
  77. package/dist/shared/usePopoverEdgeClamp-CPRWQtZV.cjs.map +1 -0
  78. package/dist/shared/usePopoverEdgeClamp-D_hB5t60.js +109 -0
  79. package/dist/shared/usePopoverEdgeClamp-D_hB5t60.js.map +1 -0
  80. package/dist/shared/useServiceWorkerUpdate-BduabXv6.js +94 -0
  81. package/dist/shared/useServiceWorkerUpdate-BduabXv6.js.map +1 -0
  82. package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs +2 -0
  83. package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs.map +1 -0
  84. package/dist/starter-kit.cjs +2 -0
  85. package/dist/starter-kit.cjs.map +1 -0
  86. package/dist/starter-kit.d.ts +9 -0
  87. package/dist/starter-kit.js +10 -0
  88. package/dist/starter-kit.js.map +1 -0
  89. package/dist/style.css +3529 -3283
  90. package/dist/versions.cjs +2 -0
  91. package/dist/versions.cjs.map +1 -0
  92. package/dist/versions.d.ts +11 -0
  93. package/dist/versions.js +13 -0
  94. package/dist/versions.js.map +1 -0
  95. package/dist/voice.cjs +2 -0
  96. package/dist/voice.cjs.map +1 -0
  97. package/dist/voice.d.ts +7 -0
  98. package/dist/voice.js +8 -0
  99. package/dist/voice.js.map +1 -0
  100. package/package.json +159 -92
  101. package/dist/noteloom.cjs +0 -3292
  102. package/dist/noteloom.cjs.map +0 -1
  103. package/dist/noteloom.es.js +0 -15047
  104. package/dist/noteloom.es.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leafBlockFactory-DSa1XCox.js","sources":["../../src/react/focusRun.js","../../src/blocks/shared/navigationCommands.js","../../src/react/domRunSync.js","../../src/react/selectionResolve.js","../../src/blocks/shared/blockCommands.js","../../src/blocks/shared/leafBlockFactory.js"],"sourcesContent":["function setCaretAtOffsetNow(runId, offset) {\n const el = document.querySelector(`[data-run-id=\"${runId}\"]`);\n if (!el) return;\n el.focus();\n const textNode = el.firstChild;\n const range = document.createRange();\n if (textNode && textNode.nodeType === 3) {\n const clamped = Math.max(0, Math.min(offset, textNode.length));\n range.setStart(textNode, clamped);\n range.setEnd(textNode, clamped);\n } else {\n range.selectNodeContents(el);\n range.collapse(offset <= 0);\n }\n const selection = window.getSelection();\n selection?.removeAllRanges();\n selection?.addRange(range);\n}\n\nfunction focusRunAt(runId, atStart) {\n requestAnimationFrame(() => {\n const el = document.querySelector(`[data-run-id=\"${runId}\"]`);\n if (!el) return;\n el.focus();\n const range = document.createRange();\n range.selectNodeContents(el);\n range.collapse(atStart);\n const selection = window.getSelection();\n selection?.removeAllRanges();\n selection?.addRange(range);\n });\n}\n\n/** Best-effort: move DOM focus + caret to the end of the given run's editable element. */\nexport function focusRunEnd(runId) {\n focusRunAt(runId, false);\n}\n\n/** Best-effort: move DOM focus + caret to the start of the given run's editable element. */\nexport function focusRunStart(runId) {\n focusRunAt(runId, true);\n}\n\n/**\n * Best-effort: move DOM focus + caret to a specific character offset within\n * the given (text) run — deferred to the next animation frame, since most\n * callers use this right after a structural change (a new block/run that\n * may not exist in the DOM yet on this exact tick).\n */\nexport function focusRunAtOffset(runId, offset) {\n requestAnimationFrame(() => setCaretAtOffsetNow(runId, offset));\n}\n\n/**\n * Synchronous (no requestAnimationFrame) variant of focusRunAtOffset —\n * for the one call site (voice dictation's live interim-text hot path,\n * see useVoiceTyping.js) where the target run's DOM node is already\n * known to exist and has *already* been synchronously rewritten by the\n * time this is called. Deferring here would leave a window where a\n * rapid-fire next event reads the selection before it's been fixed,\n * which is exactly the caret-corruption bug this exists to avoid — every\n * other call site should keep using the rAF-deferred focusRunAtOffset\n * above.\n */\nexport function setCaretSync(runId, offset) {\n setCaretAtOffsetNow(runId, offset);\n}\n","import { focusRunEnd } from '../../react/focusRun.js';\n\nfunction adjacentSiblingId(store, blockId, direction) {\n const block = store.getBlock(blockId);\n const parent = block && store.getBlock(block.parentId);\n if (!parent) return null;\n const index = parent.contentIds.indexOf(blockId);\n const adjacentIndex = direction === 'up' ? index - 1 : index + 1;\n if (adjacentIndex < 0 || adjacentIndex >= parent.contentIds.length) return null;\n return parent.contentIds[adjacentIndex];\n}\n\n/**\n * Resolves which run id should receive focus when moving from `blockId` in\n * `direction` ('up' | 'down') — pure logic, no DOM, so it's directly\n * testable. When the adjacent sibling is a container with actual content\n * (a table with rows, a layout with columns holding blocks), this *enters*\n * it — landing in its first cell/child when moving down, or its last when\n * moving up — via resolveBlockFirstRun/resolveBlockLastRun. Only a sibling\n * with truly nothing focusable at all (a divider, or an empty table with\n * zero rows) gets skipped over entirely, continuing the search to the next\n * sibling after it.\n */\nexport function resolveAdjacentFocusTarget(store, blockId, direction) {\n let currentId = blockId;\n while (true) {\n const adjacentId = adjacentSiblingId(store, currentId, direction);\n if (!adjacentId) return null;\n const runId =\n direction === 'up'\n ? resolveBlockLastRun(store, adjacentId)\n : resolveBlockFirstRun(store, adjacentId);\n if (runId) return runId;\n currentId = adjacentId; // truly empty (no rows/children at all): keep walking past it\n }\n}\n\n/** Moves focus to the nearest focusable sibling block's text in `direction` (see resolveAdjacentFocusTarget). */\nexport function focusAdjacentBlock(store, blockId, direction) {\n const targetRunId = resolveAdjacentFocusTarget(store, blockId, direction);\n if (targetRunId) focusRunEnd(targetRunId);\n}\n\n/**\n * Resolves the first directly-focusable run inside `blockId`, descending\n * into containers as needed — a leaf's own contentIds/titleRunIds are\n * already run ids, but a table's contentIds are row *block* ids (recurse\n * into the first row, then its first cell, then that cell's runs), and\n * likewise for a layout's columns. Used to focus into a block right after\n * it's created (Enter, a slash command), so the caret always lands\n * somewhere typeable instead of staying on the block that triggered it.\n */\nexport function resolveBlockFirstRun(store, blockId) {\n const block = store.getBlock(blockId);\n if (!block) return null;\n const runIds = block.props?.titleRunIds ?? block.contentIds;\n if (!runIds || runIds.length === 0) return null;\n const firstId = runIds[0];\n if (store.getRun(firstId)) return firstId; // a leaf's ids are runs directly\n return resolveBlockFirstRun(store, firstId); // a container's ids are child blocks: recurse\n}\n\n/** Moves focus to the first typeable position inside `blockId` (see resolveBlockFirstRun). */\nexport function focusBlockStart(store, blockId) {\n const runId = resolveBlockFirstRun(store, blockId);\n if (runId) focusRunEnd(runId);\n}\n\n/** Symmetric to resolveBlockFirstRun: the last directly-focusable run inside `blockId`, descending into containers' last child. */\nexport function resolveBlockLastRun(store, blockId) {\n const block = store.getBlock(blockId);\n if (!block) return null;\n const runIds = block.props?.titleRunIds ?? block.contentIds;\n if (!runIds || runIds.length === 0) return null;\n const lastId = runIds[runIds.length - 1];\n if (store.getRun(lastId)) return lastId;\n return resolveBlockLastRun(store, lastId);\n}\n\n/** Moves focus to the last typeable position inside `blockId` (see resolveBlockLastRun). */\nexport function focusBlockEnd(store, blockId) {\n const runId = resolveBlockLastRun(store, blockId);\n if (runId) focusRunEnd(runId);\n}\n","import { genId } from '../utils/idGen.js';\n\n/**\n * A completely empty `<span></span>` (no text node at all) is not a valid\n * caret anchor in many browsers' contentEditable implementation: clicking\n * into it places the caret at the *container* level instead, and typing\n * then inserts a brand-new text node as a *sibling* of the empty span\n * rather than inside it. That stray node is never one React created, so it\n * becomes invisible to React's reconciliation from that point on — every\n * subsequent keystroke reads a DOM that's drifted further from what React\n * thinks it rendered, which is what produced runaway duplicated/shrinking\n * text. The fix (the same one Slate/Lexical use) is to never render a\n * truly empty text node: an empty run gets this zero-width-space\n * placeholder instead, giving the browser a real anchor, and it's stripped\n * back out whenever DOM text is read back into a run's logical value.\n */\nexport const EMPTY_RUN_PLACEHOLDER = '​';\n\nconst ZERO_WIDTH_SPACE_RE = /​/g;\n\n/** Strips the placeholder out of a string, however many times it appears. */\nexport function stripEmptyRunPlaceholder(text) {\n return (text ?? '').replace(ZERO_WIDTH_SPACE_RE, '');\n}\n\nfunction readRunText(node) {\n return stripEmptyRunPlaceholder(node.textContent);\n}\n\n/**\n * Reconciles a contentEditable container's *actual current* child nodes\n * back against the run list it was last rendered with. This is what makes\n * one shared contentEditable region per block work: React renders each run\n * as a child (a plain `<span data-run-id>` for text, an atomic\n * `contentEditable={false}` island for a non-text inline type), the browser\n * mutates that DOM natively as the user types/deletes/pastes, and this\n * function reads the result back into run objects on the container's\n * `input` event.\n *\n * Fast path (`onlyValueChanges: true`): every child still has the same\n * data-run-id, in the same order, and only text values differ — the\n * common case for ordinary typing, since the browser's native text edit\n * stays inside the existing span whose data-run-id attribute survives\n * untouched. Callers should apply per-run `updateRun` ops in this case, to\n * preserve History's per-run undo coalescing.\n *\n * Slow path (`onlyValueChanges: false`): node(s) appeared/disappeared/\n * reordered — e.g. paste, IME composition boundaries, or an atomic inline\n * chip being deleted as a whole unit. Callers should apply one\n * `setBlockRuns` op (see operations.js) as a single coarser undo step.\n *\n * Atomic (non-text) runs are matched by id only and never have their value\n * re-derived from DOM text content — they render their own UI, not plain\n * text, so `textContent` isn't a meaningful \"value\" for them.\n */\nexport function reconcileDomToRuns(containerEl, currentRuns) {\n const byId = new Map(currentRuns.map((run) => [run.id, run]));\n const seen = new Set();\n const nextRuns = [];\n let sameIdentityAndOrder = true;\n\n for (const node of containerEl.childNodes) {\n const runId = node.nodeType === 1 ? node.dataset?.runId : undefined;\n\n if (runId && byId.has(runId)) {\n seen.add(runId);\n const existing = byId.get(runId);\n\n if (existing.type !== 'text') {\n nextRuns.push(existing); // atomic: identity-only, never re-derive from DOM\n continue;\n }\n\n const newValue = readRunText(node);\n nextRuns.push(newValue === existing.value ? existing : { ...existing, value: newValue });\n continue;\n }\n\n // No existing run matches this DOM node at all: a structural change\n // (new text node from typing at a boundary, paste, IME, etc.).\n sameIdentityAndOrder = false;\n const text = readRunText(node);\n if (text) nextRuns.push({ id: genId(), type: 'text', value: text, marks: {} });\n }\n\n if (currentRuns.some((run) => !seen.has(run.id))) sameIdentityAndOrder = false; // a run's node vanished\n if (nextRuns.length !== currentRuns.length) sameIdentityAndOrder = false;\n if (sameIdentityAndOrder) {\n for (let i = 0; i < nextRuns.length; i += 1) {\n if (nextRuns[i].id !== currentRuns[i].id) {\n sameIdentityAndOrder = false;\n break;\n }\n }\n }\n\n const changed = !sameIdentityAndOrder || nextRuns.some((run, i) => run !== currentRuns[i]);\n\n return { runs: nextRuns, changed, onlyValueChanges: sameIdentityAndOrder };\n}\n","import { stripEmptyRunPlaceholder } from './domRunSync.js';\n\n/**\n * v1 scope: resolves the native selection only when it's a non-collapsed\n * range entirely within one run's single text node — matches the same\n * single-run limitation as toggleMarkOnRunRange and the clipboard range\n * resolution. Returns null for collapsed selections or ranges spanning\n * multiple runs/blocks.\n */\nexport function resolveRunSelection() {\n const selection = window.getSelection?.();\n if (!selection || selection.rangeCount === 0) return null;\n const range = selection.getRangeAt(0);\n if (range.collapsed || range.startContainer !== range.endContainer) return null;\n\n const container = range.startContainer;\n const el = container.nodeType === 1 ? container : container.parentElement;\n const runEl = el?.closest?.('[data-run-id]');\n if (!runEl) return null;\n const blockEl = runEl.closest('[data-block-id]');\n if (!blockEl) return null;\n\n const rawText = container.textContent ?? '';\n return {\n runId: runEl.getAttribute('data-run-id'),\n blockId: blockEl.getAttribute('data-block-id'),\n startOffset: stripEmptyRunPlaceholder(rawText.slice(0, range.startOffset)).length,\n endOffset: stripEmptyRunPlaceholder(rawText.slice(0, range.endOffset)).length,\n };\n}\n\n/**\n * Native selection gestures that don't drill into a specific run's text\n * node — Ctrl+A \"select all\" within one contentEditable region is the main\n * one — anchor directly on the shared contentEditable container instead,\n * addressing by child-index rather than character offset. Without this,\n * detecting \"the whole current block is already selected\" (the trigger for\n * promoting a second Ctrl+A to a whole-document selection) silently fails\n * for exactly the selection shape native select-all actually produces.\n */\nfunction resolveContainerLevelSelection(node, offset) {\n if (node?.nodeType !== 1 || node.getAttribute?.('contenteditable') !== 'true') return null;\n const children = node.childNodes;\n if (children.length === 0) return null;\n\n const atEnd = offset >= children.length;\n const child = children[atEnd ? children.length - 1 : Math.max(0, offset)];\n const runId = child?.nodeType === 1 ? child.dataset?.runId : undefined;\n if (!runId) return null;\n const blockEl = child.closest('[data-block-id]');\n if (!blockEl) return null;\n\n return {\n runId,\n blockId: blockEl.getAttribute('data-block-id'),\n // Raw DOM length, not the logical (placeholder-stripped) length: a run\n // that started empty and was later typed into keeps a leftover\n // zero-width-space byte in its actual text node forever (see\n // TextRunSpan in EditableBlockContent.jsx — never rewritten, to avoid\n // resetting the caret on every keystroke), even though run.value itself\n // is clean. Using the raw length here would put native select-all's\n // offset one character ahead of run.value.length for exactly those\n // blocks, which is exactly what silently broke \"is the whole block\n // selected\" detection for any block typed into after being created\n // empty (slash-menu-created blocks, Enter-split blocks, etc.).\n offset: atEnd ? stripEmptyRunPlaceholder(child.textContent ?? '').length : 0,\n };\n}\n\nfunction resolveRunAndOffset(node, offset) {\n const containerLevel = resolveContainerLevelSelection(node, offset);\n if (containerLevel) return containerLevel;\n\n let el = node?.nodeType === 1 ? node : node?.parentElement;\n const runEl = el?.closest?.('[data-run-id]');\n if (!runEl) return null;\n const blockEl = runEl.closest('[data-block-id]');\n if (!blockEl) return null;\n\n // `offset` is a raw DOM char index when node is the run's own text node;\n // when the selection anchors on the run element itself (e.g. an empty/\n // atomic island), it's a child-node index instead — convert to a char\n // count. Either way, strip any leftover placeholder byte so the result\n // lines up with run.value.length (see the matching comment in\n // resolveContainerLevelSelection above — same underlying cause).\n let charOffset = stripEmptyRunPlaceholder((node.textContent ?? '').slice(0, offset)).length;\n if (node === runEl) {\n charOffset = 0;\n for (let i = 0; i < offset && i < runEl.childNodes.length; i += 1) {\n charOffset += stripEmptyRunPlaceholder(runEl.childNodes[i].textContent ?? '').length;\n }\n }\n\n return {\n runId: runEl.getAttribute('data-run-id'),\n blockId: blockEl.getAttribute('data-block-id'),\n offset: charOffset,\n };\n}\n\n/**\n * Resolves a *collapsed* caret to the run+char-offset it sits at — used by\n * Enter-to-split so the new block gets exactly the text after the caret,\n * instead of always starting blank. Returns null for a non-collapsed\n * selection or a caret that isn't inside any run at all.\n */\nexport function resolveCollapsedCaret() {\n const selection = window.getSelection?.();\n if (!selection || selection.rangeCount === 0 || !selection.isCollapsed) return null;\n return resolveRunAndOffset(selection.anchorNode, selection.anchorOffset);\n}\n\n/**\n * Resolves a non-collapsed selection that may span *multiple runs within\n * the same block* (e.g. selecting text that crosses a bold boundary) —\n * generalizes resolveRunSelection's single-run limitation. Returns null if\n * the selection spans multiple blocks (use resolveCrossBlockSelection for\n * that) or if either end isn't inside a run at all.\n */\nexport function resolveMultiRunSelection() {\n const selection = window.getSelection?.();\n if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;\n\n const anchor = resolveRunAndOffset(selection.anchorNode, selection.anchorOffset);\n const focus = resolveRunAndOffset(selection.focusNode, selection.focusOffset);\n if (!anchor || !focus) return null;\n if (anchor.blockId !== focus.blockId) return null; // cross-block: use resolveCrossBlockSelection\n\n return {\n blockId: anchor.blockId,\n startRunId: anchor.runId,\n startOffset: anchor.offset,\n endRunId: focus.runId,\n endOffset: focus.offset,\n };\n}\n\n/**\n * Resolves a non-collapsed selection spanning *multiple sibling blocks*\n * under a shared parent (e.g. from the middle of one paragraph through the\n * middle of another a few blocks down) — for toggleMarkOverBlockRange.\n * Needs `store` (unlike the other resolvers here) to walk the parent's\n * contentIds and slice out the sibling range. Returns null when the\n * selection is actually within one block (use resolveMultiRunSelection\n * instead), or when the two blocks aren't siblings under the same parent\n * (nested at different depths — not supported in v1).\n */\nexport function resolveCrossBlockSelection(store) {\n const selection = window.getSelection?.();\n if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;\n\n const anchor = resolveRunAndOffset(selection.anchorNode, selection.anchorOffset);\n const focus = resolveRunAndOffset(selection.focusNode, selection.focusOffset);\n if (!anchor || !focus) return null;\n if (anchor.blockId === focus.blockId) return null; // same block: use resolveMultiRunSelection\n\n const startBlock = store.getBlock(anchor.blockId);\n const parent = startBlock && store.getBlock(startBlock.parentId);\n if (!parent) return null;\n\n const ids = parent.contentIds;\n const i1 = ids.indexOf(anchor.blockId);\n const i2 = ids.indexOf(focus.blockId);\n if (i1 === -1 || i2 === -1) return null; // not siblings under the same parent\n\n const [from, to] = i1 <= i2 ? [i1, i2] : [i2, i1];\n\n return {\n blockIds: ids.slice(from, to + 1),\n startBlockId: anchor.blockId,\n startRunId: anchor.runId,\n startOffset: anchor.offset,\n endBlockId: focus.blockId,\n endRunId: focus.runId,\n endOffset: focus.offset,\n };\n}\n","import { insertBlock, updateRun, setBlockRuns, removeBlock } from '../../store/operations.js';\nimport { focusBlockStart } from './navigationCommands.js';\nimport { resolveCollapsedCaret } from '../../react/selectionResolve.js';\nimport { genId } from '../../utils/idGen.js';\n\n/**\n * Inserts a new block immediately after `currentBlockId`, as a sibling under\n * the same parent. `factory(parentId)` must return `{ block, runs, subtreeBlocks }`\n * — `runs` may be empty for non-leaf types, and `subtreeBlocks` (default [])\n * holds any additional descendant blocks for multi-level inserts (e.g. a\n * table's rows/cells alongside its own root block). Shared by every block\n * type's slash command so \"where do I insert relative to the current block\"\n * is written once.\n */\nexport function insertSiblingAfter(store, currentBlockId, factory) {\n const current = store.getBlock(currentBlockId);\n const parentId = current.parentId;\n const parent = store.getBlock(parentId);\n const index = parent.contentIds.indexOf(currentBlockId) + 1;\n const { block, runs = [], subtreeBlocks = [] } = factory(parentId);\n store.applyOperation(\n insertBlock(block, parentId, index, { blocks: [block, ...subtreeBlocks], runs }),\n );\n return block.id;\n}\n\n/**\n * Same as insertSiblingAfter, but also moves focus into the new block —\n * every editor does this (Enter, or picking a block from the slash menu,\n * always lands the caret in the thing you just created, never leaves it on\n * the block you triggered it from). Descends into containers (table,\n * layout) to find the first actually-typeable position.\n */\nexport function insertSiblingAfterAndFocus(store, currentBlockId, factory) {\n const newBlockId = insertSiblingAfter(store, currentBlockId, factory);\n focusBlockStart(store, newBlockId);\n return newBlockId;\n}\n\n/**\n * Inserts a new block as the *first child* of `parentBlockId` and focuses\n * it. Used when a container block (a list item with nested items beneath\n * it) needs the new block to appear visually right after the parent's own\n * content but before its existing children — since children render\n * *inside* the parent's own DOM subtree, a \"sibling in the grandparent's\n * array\" would only ever land after that whole subtree, not between the\n * parent's title and its first child.\n */\nexport function insertFirstChildAndFocus(store, parentBlockId, factory) {\n const { block, runs = [], subtreeBlocks = [] } = factory(parentBlockId);\n store.applyOperation(\n insertBlock(block, parentBlockId, 0, { blocks: [block, ...subtreeBlocks], runs }),\n );\n focusBlockStart(store, block.id);\n return block.id;\n}\n\nfunction applyOps(store, ops) {\n if (typeof store.performBatch === 'function') {\n store.performBatch(ops);\n } else {\n for (const op of ops) store.applyOperation(op);\n }\n}\n\n/**\n * Pure: splits an ordered list of Run objects at `caretRunId`/`caretOffset`\n * into \"everything before the caret\" and \"everything at/after it\",\n * splitting the caret's own run in two when it's a text run with content on\n * both sides. Identity is preserved wherever possible (a run that doesn't\n * actually get cut keeps its id) so only a genuine mid-run split spends a\n * new id. Neither side is ever left with zero runs — a block needs at least\n * one run to render/anchor a caret in, so an empty side gets a fresh blank\n * text run.\n */\nexport function splitRunsAtCaret(runs, caretRunId, caretOffset) {\n const idx = runs.findIndex((r) => r.id === caretRunId);\n if (idx === -1) return null;\n\n const caretRun = runs[idx];\n const before = runs.slice(0, idx);\n const after = runs.slice(idx + 1);\n\n if (caretRun.type === 'text') {\n const value = caretRun.value ?? '';\n const leftValue = value.slice(0, caretOffset);\n const rightValue = value.slice(caretOffset);\n if (leftValue && rightValue) {\n before.push({ ...caretRun, value: leftValue });\n after.unshift({ ...caretRun, id: genId(), value: rightValue });\n } else if (rightValue) {\n after.unshift(caretRun); // caret at the run's start: whole run moves right, unchanged\n } else {\n before.push(caretRun); // caret at the run's end (or run already empty): stays left, unchanged\n }\n } else if (caretOffset > 0) {\n before.push(caretRun); // atomic run: never split inside it, only before/after\n } else {\n after.unshift(caretRun);\n }\n\n const leftRuns = before.length ? before : [{ id: genId(), type: 'text', value: '', marks: {} }];\n const rightRuns = after.length ? after : [{ id: genId(), type: 'text', value: '', marks: {} }];\n return { leftRuns, rightRuns };\n}\n\n/**\n * Enter-to-split: every real editor splits the block's content at the\n * caret (text before stays, text after moves into the new sibling) rather\n * than always creating a blank sibling and leaving all the text behind.\n * Falls back to the old \"just append an empty sibling\" behavior when there\n * is no resolvable live caret in this exact block (no DOM selection at all,\n * as in most non-interactive tests, or a caret that landed somewhere else).\n *\n * `currentRunIds` must be the block's own run ids (contentIds for a plain\n * leaf, props.titleRunIds for a listItem) — same convention as\n * EditableBlockContent's `runIds` prop. `factory(parentId, initialRuns?)`\n * must accept the optional pre-built run list (see createTextLeafBlock/\n * createListItemBlock).\n */\nexport function insertSiblingSplitAtCaretAndFocus(store, blockId, currentRunIds, factory) {\n const current = store.getBlock(blockId);\n const parent = store.getBlock(current.parentId);\n const index = parent.contentIds.indexOf(blockId) + 1;\n return splitAndInsertAtCaret(store, blockId, currentRunIds, factory, {\n insertParentId: parent.id,\n insertIndex: index,\n fallback: () => insertSiblingAfterAndFocus(store, blockId, factory),\n });\n}\n\n/**\n * Same idea as insertSiblingSplitAtCaretAndFocus, but for the \"this item has\n * nested children\" case (see insertFirstChildAndFocus): the new block's\n * content is the split-off right-hand runs, and it lands as the first child\n * of `blockId` itself (whose own title runs get truncated to the left half)\n * rather than as its sibling.\n */\nexport function insertFirstChildSplitAtCaretAndFocus(store, blockId, currentRunIds, factory) {\n return splitAndInsertAtCaret(store, blockId, currentRunIds, factory, {\n insertParentId: blockId,\n insertIndex: 0,\n fallback: () => insertFirstChildAndFocus(store, blockId, factory),\n });\n}\n\nfunction splitAndInsertAtCaret(\n store,\n blockId,\n currentRunIds,\n factory,\n { insertParentId, insertIndex, fallback },\n) {\n const caret = resolveCollapsedCaret();\n if (!caret || caret.blockId !== blockId) return fallback();\n\n const currentRuns = currentRunIds.map((id) => store.getRun(id)).filter(Boolean);\n const split = splitRunsAtCaret(currentRuns, caret.runId, caret.offset);\n if (!split) return fallback();\n\n const { leftRuns, rightRuns } = split;\n const { block, runs = rightRuns, subtreeBlocks = [] } = factory(insertParentId, rightRuns);\n\n // Enter at the very start of a block's content leaves nothing before the\n // caret, so leftRuns comes back empty — but the block staying behind\n // must never end up with zero runs: an empty contentEditable region isn't\n // a valid caret anchor in most browsers, so the next time someone types\n // into it, every keystroke mints a brand-new run instead of updating one\n // in place (the same \"characters double\" bug this exact guard fixes for\n // removeRun/handleInput in EditableBlockContent).\n const survivingLeftRuns = leftRuns.length\n ? leftRuns\n : [{ id: genId(), type: 'text', value: '', marks: {} }];\n\n applyOps(store, [\n setBlockRuns(blockId, survivingLeftRuns),\n insertBlock(block, insertParentId, insertIndex, { blocks: [block, ...subtreeBlocks], runs }),\n ]);\n focusBlockStart(store, block.id);\n return block.id;\n}\n\nfunction getOwnRunIds(block) {\n return block?.props?.titleRunIds ?? block?.contentIds ?? [];\n}\n\n// A listItem's own text lives in props.titleRunIds while contentIds holds\n// its nested child *blocks* — so for it (and any other block shaped that\n// way), contentIds having entries means it has children, not extra runs.\nfunction hasNestedChildren(block) {\n return Boolean(block?.props?.titleRunIds) && (block.contentIds?.length ?? 0) > 0;\n}\n\n/**\n * Converts an empty block in place to a different type, instead of leaving\n * the old empty block behind with a new sibling after it — e.g. picking\n * \"Heading\" from the slash menu on a still-empty paragraph turns that same\n * paragraph into the heading, rather than inserting a heading after an\n * orphaned blank paragraph. Removes the old block and inserts the new one\n * at the same index as one atomic step, so undo/redo treats it as a single\n * operation.\n */\nfunction replaceBlockInPlace(store, blockId, factory) {\n const current = store.getBlock(blockId);\n const parentId = current.parentId;\n const parent = store.getBlock(parentId);\n const index = parent.contentIds.indexOf(blockId);\n const { block, runs = [], subtreeBlocks = [] } = factory(parentId);\n\n applyOps(store, [\n removeBlock(blockId),\n insertBlock(block, parentId, index, { blocks: [block, ...subtreeBlocks], runs }),\n ]);\n focusBlockStart(store, block.id);\n return block.id;\n}\n\n/**\n * Slash-command entry point for block-level commands: removes the\n * \"/query\" span from the triggering run (merging whatever was before and\n * after it — a block command doesn't need to preserve a split point the\n * way an inline command does, since it's creating an entirely separate\n * sibling block, not splicing into this one).\n *\n * If trimming the query leaves the block completely empty — it was the\n * block's only run and the block has no nested children — the block is\n * converted in place (replaceBlockInPlace) rather than inserted after,\n * which would otherwise leave a pointless empty block sitting above the\n * one the user actually meant to create. Otherwise, behaves as before:\n * trims the query and inserts+focuses the new block after the current one.\n */\nexport function trimSlashQueryAndInsertAfter(\n store,\n { blockId, runId, sliceStart, sliceEnd },\n factory,\n) {\n const run = store.getRun(runId);\n const value = run?.value ?? '';\n const newValue = value.slice(0, sliceStart) + value.slice(sliceEnd);\n\n const block = store.getBlock(blockId);\n const ownRunIds = getOwnRunIds(block);\n const isOnlyRun = ownRunIds.length === 1 && ownRunIds[0] === runId;\n const wouldBeEmpty = isOnlyRun && newValue === '' && !hasNestedChildren(block);\n\n if (wouldBeEmpty) {\n return replaceBlockInPlace(store, blockId, factory);\n }\n\n store.applyOperation(updateRun(runId, { value: newValue }));\n return insertSiblingAfterAndFocus(store, blockId, factory);\n}\n","import { genId } from '../../utils/idGen.js';\n\n/**\n * Builds a factory(parentId, initialRuns?) -> {block, runs} for a text leaf\n * block. Most callers (slash commands) omit `initialRuns` and get a single\n * blank run; Enter-to-split passes the runs that landed after the caret so\n * the new block starts with that text instead of empty.\n */\nexport function createTextLeafBlock(type, props = {}) {\n return function factory(parentId, initialRuns) {\n const blockId = genId();\n const runs = initialRuns?.length\n ? initialRuns\n : [{ id: genId(), type: 'text', value: '', marks: {} }];\n return {\n block: { id: blockId, type, parentId, contentIds: runs.map((r) => r.id), props },\n runs,\n };\n };\n}\n"],"names":["setCaretAtOffsetNow","runId","offset","el","textNode","range","clamped","selection","focusRunAt","atStart","focusRunEnd","focusRunStart","focusRunAtOffset","setCaretSync","adjacentSiblingId","store","blockId","direction","block","parent","index","adjacentIndex","resolveAdjacentFocusTarget","currentId","adjacentId","resolveBlockLastRun","resolveBlockFirstRun","focusAdjacentBlock","targetRunId","runIds","_a","firstId","focusBlockStart","lastId","focusBlockEnd","EMPTY_RUN_PLACEHOLDER","ZERO_WIDTH_SPACE_RE","stripEmptyRunPlaceholder","text","readRunText","node","reconcileDomToRuns","containerEl","currentRuns","byId","run","seen","nextRuns","sameIdentityAndOrder","existing","newValue","genId","i","changed","resolveRunSelection","container","runEl","_b","blockEl","rawText","resolveContainerLevelSelection","children","atEnd","child","resolveRunAndOffset","containerLevel","charOffset","resolveCollapsedCaret","resolveMultiRunSelection","anchor","focus","resolveCrossBlockSelection","startBlock","ids","i1","i2","from","to","insertSiblingAfter","currentBlockId","factory","parentId","runs","subtreeBlocks","insertBlock","insertSiblingAfterAndFocus","newBlockId","insertFirstChildAndFocus","parentBlockId","applyOps","ops","op","splitRunsAtCaret","caretRunId","caretOffset","idx","r","caretRun","before","after","value","leftValue","rightValue","leftRuns","rightRuns","insertSiblingSplitAtCaretAndFocus","currentRunIds","current","splitAndInsertAtCaret","insertFirstChildSplitAtCaretAndFocus","insertParentId","insertIndex","fallback","caret","id","split","survivingLeftRuns","setBlockRuns","getOwnRunIds","hasNestedChildren","replaceBlockInPlace","removeBlock","trimSlashQueryAndInsertAfter","sliceStart","sliceEnd","ownRunIds","updateRun","createTextLeafBlock","type","props","initialRuns"],"mappings":";AAAA,SAASA,EAAoBC,GAAOC,GAAQ;AAC1C,QAAMC,IAAK,SAAS,cAAc,iBAAiBF,CAAK,IAAI;AAC5D,MAAI,CAACE,EAAI;AACT,EAAAA,EAAG,MAAK;AACR,QAAMC,IAAWD,EAAG,YACdE,IAAQ,SAAS,YAAW;AAClC,MAAID,KAAYA,EAAS,aAAa,G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
4
+ return {
5
+ html: f(l, c, o, e),
6
+ text: o.map((n) => {
7
+ const i = l.getBlock(n);
8
+ return c.get(i.type).toPlainText(i, e);
9
+ }).join(`
10
+ `),
11
+ json: JSON.stringify({ version: 1, blocks: o.map((n) => m(l, n)) })
12
+ };
13
+ }
14
+ function f(l, c, o, p) {
15
+ let e = "", n = 0;
16
+ for (; n < o.length; ) {
17
+ const i = l.getBlock(o[n]);
18
+ if (i.type === "listItem") {
19
+ const r = !!i.props.ordered;
20
+ let t = "", s = n;
21
+ for (; s < o.length; ) {
22
+ const a = l.getBlock(o[s]);
23
+ if (a.type !== "listItem" || !!a.props.ordered !== r) break;
24
+ t += c.get("listItem").toHTML(a, p), s += 1;
25
+ }
26
+ const u = r ? "ol" : "ul";
27
+ e += `<${u}>${t}</${u}>`, n = s;
28
+ } else if (i.type === "blockquote") {
29
+ let r = "", t = n;
30
+ for (; t < o.length; ) {
31
+ const s = l.getBlock(o[t]);
32
+ if (s.type !== "blockquote") break;
33
+ r += c.get("blockquote").toHTML(s, p), t += 1;
34
+ }
35
+ e += `<blockquote>${r}</blockquote>`, n = t;
36
+ } else
37
+ e += c.get(i.type).toHTML(i, p), n += 1;
38
+ }
39
+ return e;
40
+ }
41
+ function m(l, c) {
42
+ const o = [], p = [], e = (n) => {
43
+ var t;
44
+ const i = l.getRun(n);
45
+ if (i) {
46
+ p.push(i);
47
+ return;
48
+ }
49
+ const r = l.getBlock(n);
50
+ if (r) {
51
+ o.push(r);
52
+ for (const s of r.contentIds) e(s);
53
+ for (const s of ((t = r.props) == null ? void 0 : t.titleRunIds) ?? []) e(s);
54
+ }
55
+ };
56
+ return e(c), { rootId: c, blocks: o, runs: p };
57
+ }
58
+ function h({ rootId: l, blocks: c, runs: o }) {
59
+ const p = /* @__PURE__ */ new Map();
60
+ for (const t of c) p.set(t.id, d());
61
+ for (const t of o) p.set(t.id, d());
62
+ const e = (t) => p.get(t) ?? t, n = c.map((t) => {
63
+ var s;
64
+ return {
65
+ ...t,
66
+ id: e(t.id),
67
+ parentId: t.parentId ? e(t.parentId) : t.parentId,
68
+ contentIds: t.contentIds.map(e),
69
+ props: {
70
+ ...t.props,
71
+ ...(s = t.props) != null && s.titleRunIds ? { titleRunIds: t.props.titleRunIds.map(e) } : {}
72
+ }
73
+ };
74
+ }), i = o.map((t) => ({ ...t, id: e(t.id) })), r = e(l);
75
+ return {
76
+ block: n.find((t) => t.id === r),
77
+ runs: i,
78
+ subtreeBlocks: n.filter((t) => t.id !== r)
79
+ };
80
+ }
81
+ export {
82
+ m as c,
83
+ h as r,
84
+ k as s
85
+ };
86
+ //# sourceMappingURL=serialize-BqKU9EZy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-BqKU9EZy.js","sources":["../../src/clipboard/serialize.js"],"sourcesContent":["/**\n * Serializes an ordered list of top-level (sibling) block ids into the three\n * clipboard payloads. All per-type formatting is delegated to the registry\n * (toHTML/toPlainText) — this module only owns cross-block concerns: joining\n * blocks together and grouping consecutive `listItem` blocks into one\n * wrapping <ul>/<ol> (a single list item's toHTML only knows about itself,\n * not its siblings).\n */\nimport { genId } from '../utils/idGen.js';\n\nexport function serializeBlockRange(store, registry, blockIds, inlineRegistry) {\n const ctx = { store, registry, inlineRegistry };\n return {\n html: serializeHTML(store, registry, blockIds, ctx),\n text: blockIds\n .map((id) => {\n const block = store.getBlock(id);\n return registry.get(block.type).toPlainText(block, ctx);\n })\n .join('\\n'),\n json: JSON.stringify({ version: 1, blocks: blockIds.map((id) => captureSubtree(store, id)) }),\n };\n}\n\nfunction serializeHTML(store, registry, blockIds, ctx) {\n let html = '';\n let i = 0;\n while (i < blockIds.length) {\n const block = store.getBlock(blockIds[i]);\n if (block.type === 'listItem') {\n const ordered = Boolean(block.props.ordered);\n let itemsHTML = '';\n let j = i;\n while (j < blockIds.length) {\n const candidate = store.getBlock(blockIds[j]);\n if (candidate.type !== 'listItem' || Boolean(candidate.props.ordered) !== ordered) break;\n itemsHTML += registry.get('listItem').toHTML(candidate, ctx);\n j += 1;\n }\n const tag = ordered ? 'ol' : 'ul';\n html += `<${tag}>${itemsHTML}</${tag}>`;\n i = j;\n } else if (block.type === 'blockquote') {\n // Same grouping idea as listItem above: each blockquote block's own\n // toHTML only emits its own line (a <p>), since the model keeps\n // multi-line quotes as separate sibling blocks rather than one\n // container — consecutive quote siblings share one wrapping\n // <blockquote> on the way out, matching how they'd come back in via\n // domWalk's consumeBlockquote.\n let linesHTML = '';\n let j = i;\n while (j < blockIds.length) {\n const candidate = store.getBlock(blockIds[j]);\n if (candidate.type !== 'blockquote') break;\n linesHTML += registry.get('blockquote').toHTML(candidate, ctx);\n j += 1;\n }\n html += `<blockquote>${linesHTML}</blockquote>`;\n i = j;\n } else {\n html += registry.get(block.type).toHTML(block, ctx);\n i += 1;\n }\n }\n return html;\n}\n\n/**\n * Read-only capture of a block subtree (block + descendants + their runs)\n * — used for the app-specific clipboard JSON, and reused as-is by\n * `duplicateBlock` (see blocks/shared/blockActions.js) since \"clone this\n * subtree with fresh ids\" is exactly the same operation either way.\n */\nexport function captureSubtree(store, rootId) {\n const blocks = [];\n const runs = [];\n const walk = (id) => {\n const run = store.getRun(id);\n if (run) {\n runs.push(run);\n return;\n }\n const block = store.getBlock(id);\n if (!block) return;\n blocks.push(block);\n for (const childId of block.contentIds) walk(childId);\n for (const runId of block.props?.titleRunIds ?? []) walk(runId);\n };\n walk(rootId);\n return { rootId, blocks, runs };\n}\n\n/**\n * Regenerates ids for a captured subtree so pasting the same clipboard\n * contents twice never collides with ids already in the document (or with\n * the ids still referenced by the copy source, if it's the same doc).\n */\nexport function remapSubtreeIds({ rootId, blocks, runs }) {\n const idMap = new Map();\n for (const b of blocks) idMap.set(b.id, genId());\n for (const r of runs) idMap.set(r.id, genId());\n const remap = (id) => idMap.get(id) ?? id;\n\n const newBlocks = blocks.map((b) => ({\n ...b,\n id: remap(b.id),\n parentId: b.parentId ? remap(b.parentId) : b.parentId,\n contentIds: b.contentIds.map(remap),\n props: {\n ...b.props,\n ...(b.props?.titleRunIds ? { titleRunIds: b.props.titleRunIds.map(remap) } : {}),\n },\n }));\n const newRuns = runs.map((r) => ({ ...r, id: remap(r.id) }));\n const newRootId = remap(rootId);\n\n return {\n block: newBlocks.find((b) => b.id === newRootId),\n runs: newRuns,\n subtreeBlocks: newBlocks.filter((b) => b.id !== newRootId),\n };\n}\n"],"names":["serializeBlockRange","store","registry","blockIds","inlineRegistry","ctx","serializeHTML","id","block","captureSubtree","html","i","ordered","itemsHTML","j","candidate","tag","linesHTML","rootId","blocks","runs","walk","run","childId","runId","_a","remapSubtreeIds","idMap","b","genId","r","remap","newBlocks","newRuns","newRootId"],"mappings":";AAUO,SAASA,EAAoBC,GAAOC,GAAUC,GAAUC,GAAgB;AAC7E,QAAMC,IAAM,EAAE,OAAAJ,GAAO,UAAAC,GAAU,gBAAAE,EAAc;AAC7C,SAAO;AAAA,IACL,MAAME,EAAcL,GAAOC,GAAUC,GAAUE,CAAG;AAAA,IAClD,MAAMF,EACH,IAAI,CAACI,MAAO;AACX,YAAMC,IAAQP,EAAM,SAASM,CAAE;AAC/B,aAAOL,EAAS,IAAIM,EAAM,IAAI,EAAE,YAAYA,GAAOH,CAAG;AAAA,IACxD,CAAC,EACA,KAAK;AAAA,CAAI;AAAA,IACZ,MAAM,KAAK,UAAU,EAAE,SAAS,GAAG,QAAQF,EAAS,IAAI,CAACI,MAAOE,EAAeR,GAAOM,CAAE,CAAC,EAAC,CAAE;AAAA,EAChG;AACA;AAEA,SAASD,EAAcL,GAAOC,GAAUC,GAAUE,GAAK;AACrD,MAAIK,IAAO,IACPC,IAAI;AACR,SAAOA,IAAIR,EAAS,UAAQ;AAC1B,UAAMK,IAAQP,EAAM,SAASE,EAASQ,CAAC,CAAC;AACxC,QAAIH,EAAM,SAAS,YAAY;AAC7B,YAAMI,IAAU,EAAQJ,EAAM,MAAM;AACpC,UAAIK,IAAY,IACZC,IAAIH;AACR,aAAOG,IAAIX,EAAS,UAAQ;AAC1B,cA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.getBlock(n);return s.get(i.type).toPlainText(i,e)}).join(`
2
+ `),json:JSON.stringify({version:1,blocks:o.map(n=>f(l,n))})}}function k(l,s,o,p){let e="",n=0;for(;n<o.length;){const i=l.getBlock(o[n]);if(i.type==="listItem"){const r=!!i.props.ordered;let t="",c=n;for(;c<o.length;){const u=l.getBlock(o[c]);if(u.type!=="listItem"||!!u.props.ordered!==r)break;t+=s.get("listItem").toHTML(u,p),c+=1}const a=r?"ol":"ul";e+=`<${a}>${t}</${a}>`,n=c}else if(i.type==="blockquote"){let r="",t=n;for(;t<o.length;){const c=l.getBlock(o[t]);if(c.type!=="blockquote")break;r+=s.get("blockquote").toHTML(c,p),t+=1}e+=`<blockquote>${r}</blockquote>`,n=t}else e+=s.get(i.type).toHTML(i,p),n+=1}return e}function f(l,s){const o=[],p=[],e=n=>{var t;const i=l.getRun(n);if(i){p.push(i);return}const r=l.getBlock(n);if(r){o.push(r);for(const c of r.contentIds)e(c);for(const c of((t=r.props)==null?void 0:t.titleRunIds)??[])e(c)}};return e(s),{rootId:s,blocks:o,runs:p}}function m({rootId:l,blocks:s,runs:o}){const p=new Map;for(const t of s)p.set(t.id,d.genId());for(const t of o)p.set(t.id,d.genId());const e=t=>p.get(t)??t,n=s.map(t=>{var c;return{...t,id:e(t.id),parentId:t.parentId?e(t.parentId):t.parentId,contentIds:t.contentIds.map(e),props:{...t.props,...(c=t.props)!=null&&c.titleRunIds?{titleRunIds:t.props.titleRunIds.map(e)}:{}}}}),i=o.map(t=>({...t,id:e(t.id)})),r=e(l);return{block:n.find(t=>t.id===r),runs:i,subtreeBlocks:n.filter(t=>t.id!==r)}}exports.captureSubtree=f;exports.remapSubtreeIds=m;exports.serializeBlockRange=g;
3
+ //# sourceMappingURL=serialize-CqwX55uK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-CqwX55uK.cjs","sources":["../../src/clipboard/serialize.js"],"sourcesContent":["/**\n * Serializes an ordered list of top-level (sibling) block ids into the three\n * clipboard payloads. All per-type formatting is delegated to the registry\n * (toHTML/toPlainText) — this module only owns cross-block concerns: joining\n * blocks together and grouping consecutive `listItem` blocks into one\n * wrapping <ul>/<ol> (a single list item's toHTML only knows about itself,\n * not its siblings).\n */\nimport { genId } from '../utils/idGen.js';\n\nexport function serializeBlockRange(store, registry, blockIds, inlineRegistry) {\n const ctx = { store, registry, inlineRegistry };\n return {\n html: serializeHTML(store, registry, blockIds, ctx),\n text: blockIds\n .map((id) => {\n const block = store.getBlock(id);\n return registry.get(block.type).toPlainText(block, ctx);\n })\n .join('\\n'),\n json: JSON.stringify({ version: 1, blocks: blockIds.map((id) => captureSubtree(store, id)) }),\n };\n}\n\nfunction serializeHTML(store, registry, blockIds, ctx) {\n let html = '';\n let i = 0;\n while (i < blockIds.length) {\n const block = store.getBlock(blockIds[i]);\n if (block.type === 'listItem') {\n const ordered = Boolean(block.props.ordered);\n let itemsHTML = '';\n let j = i;\n while (j < blockIds.length) {\n const candidate = store.getBlock(blockIds[j]);\n if (candidate.type !== 'listItem' || Boolean(candidate.props.ordered) !== ordered) break;\n itemsHTML += registry.get('listItem').toHTML(candidate, ctx);\n j += 1;\n }\n const tag = ordered ? 'ol' : 'ul';\n html += `<${tag}>${itemsHTML}</${tag}>`;\n i = j;\n } else if (block.type === 'blockquote') {\n // Same grouping idea as listItem above: each blockquote block's own\n // toHTML only emits its own line (a <p>), since the model keeps\n // multi-line quotes as separate sibling blocks rather than one\n // container — consecutive quote siblings share one wrapping\n // <blockquote> on the way out, matching how they'd come back in via\n // domWalk's consumeBlockquote.\n let linesHTML = '';\n let j = i;\n while (j < blockIds.length) {\n const candidate = store.getBlock(blockIds[j]);\n if (candidate.type !== 'blockquote') break;\n linesHTML += registry.get('blockquote').toHTML(candidate, ctx);\n j += 1;\n }\n html += `<blockquote>${linesHTML}</blockquote>`;\n i = j;\n } else {\n html += registry.get(block.type).toHTML(block, ctx);\n i += 1;\n }\n }\n return html;\n}\n\n/**\n * Read-only capture of a block subtree (block + descendants + their runs)\n * — used for the app-specific clipboard JSON, and reused as-is by\n * `duplicateBlock` (see blocks/shared/blockActions.js) since \"clone this\n * subtree with fresh ids\" is exactly the same operation either way.\n */\nexport function captureSubtree(store, rootId) {\n const blocks = [];\n const runs = [];\n const walk = (id) => {\n const run = store.getRun(id);\n if (run) {\n runs.push(run);\n return;\n }\n const block = store.getBlock(id);\n if (!block) return;\n blocks.push(block);\n for (const childId of block.contentIds) walk(childId);\n for (const runId of block.props?.titleRunIds ?? []) walk(runId);\n };\n walk(rootId);\n return { rootId, blocks, runs };\n}\n\n/**\n * Regenerates ids for a captured subtree so pasting the same clipboard\n * contents twice never collides with ids already in the document (or with\n * the ids still referenced by the copy source, if it's the same doc).\n */\nexport function remapSubtreeIds({ rootId, blocks, runs }) {\n const idMap = new Map();\n for (const b of blocks) idMap.set(b.id, genId());\n for (const r of runs) idMap.set(r.id, genId());\n const remap = (id) => idMap.get(id) ?? id;\n\n const newBlocks = blocks.map((b) => ({\n ...b,\n id: remap(b.id),\n parentId: b.parentId ? remap(b.parentId) : b.parentId,\n contentIds: b.contentIds.map(remap),\n props: {\n ...b.props,\n ...(b.props?.titleRunIds ? { titleRunIds: b.props.titleRunIds.map(remap) } : {}),\n },\n }));\n const newRuns = runs.map((r) => ({ ...r, id: remap(r.id) }));\n const newRootId = remap(rootId);\n\n return {\n block: newBlocks.find((b) => b.id === newRootId),\n runs: newRuns,\n subtreeBlocks: newBlocks.filter((b) => b.id !== newRootId),\n };\n}\n"],"names":["serializeBlockRange","store","registry","blockIds","inlineRegistry","ctx","serializeHTML","id","block","captureSubtree","html","i","ordered","itemsHTML","j","candidate","tag","linesHTML","rootId","blocks","runs","walk","run","childId","runId","_a","remapSubtreeIds","idMap","b","genId","r","remap","newBlocks","newRuns","newRootId"],"mappings":"qDAUO,SAASA,EAAoBC,EAAOC,EAAUC,EAAUC,EAAgB,CAC7E,MAAMC,EAAM,CAAE,MAAAJ,EAAO,SAAAC,EAAU,eAAAE,CAAc,EAC7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AK,CAAA,CACnF,CACA,EAAI,EACIE,EAAUb,EAAK,IAAKU,IAAO,CAAE,GAAGA,EAAG,GAAIC,EAAMD,EAAE,EAAE,CAAC,EAAG,EACrDI,EAAYH,EAAMb,CAAM,EAE9B,MAAO,CACL,MAAOc,EAAU,KAAMJ,GAAMA,EAAE,KAAOM,CAAS,EAC/C,KAAMD,EACN,cAAeD,EAAU,OAAQJ,GAAMA,EAAE,KAAOM,CAAS,CAC7D,CACA"}
@@ -0,0 +1,27 @@
1
+ "use strict";var Vn=Object.defineProperty;var qn=(e,t,n)=>t in e?Vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var mt=(e,t,n)=>qn(e,typeof t!="symbol"?t+"":t,n);const v=require("./index-CbIBsFmI.cjs"),a=require("react/jsx-runtime"),u=require("react"),be=require("react-dom"),c=require("./icons-BCseh2pt.cjs"),C=require("./leafBlockFactory-CaLWUcfa.cjs"),ae=require("./usePopoverEdgeClamp-CPRWQtZV.cjs"),Wn=require("./CommentThreadCard-YziIa8My.cjs"),ht=require("./serialize-CqwX55uK.cjs");function Nt(e){return e?e.type!=="text"?!1:(e.value??"")==="":!0}function te(e,t){return!t||t.length===0?!0:t.every(n=>Nt(e.getRun(n)))}function Me(e,t){var l,s;if(!t)return!1;const n=t.contentIds.length>0,o=(((s=(l=t.props)==null?void 0:l.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!o}function Et({isOpen:e,initialHref:t,initialTarget:n,hasExistingLink:o,onSave:l,onRemove:s,onClose:r}){const[i,d]=u.useState(""),[f,m]=u.useState("_self");u.useEffect(()=>{e&&(d(t),m(n))},[e]);const p=i.trim(),h=u.useCallback(k=>{k.preventDefault(),p&&l(p,f)},[p,f,l]);return a.jsx(ae.Modal,{isOpen:e,onClose:r,title:o?"Edit link":"Add link",children:a.jsxs("form",{onSubmit:h,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"URL"}),a.jsx("input",{type:"text",value:i,onChange:k=>d(k.target.value),placeholder:"https://example.com",autoFocus:!0})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Open in"}),a.jsxs("select",{value:f,onChange:k=>m(k.target.value),children:[a.jsx("option",{value:"_self",children:"Same tab"}),a.jsx("option",{value:"_blank",children:"New tab"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[o&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:r,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",disabled:!p,children:"Save"})]})]})})}function $e(e,t,n,o){const[l,s]=u.useState(null);return u.useLayoutEffect(()=>{if(n==null||o==null){s(null);return}s({top:n,left:o})},[n,o]),u.useLayoutEffect(()=>{if(!t||!e.current||!l)return;const r=e.current.getBoundingClientRect(),i=ae.clampLeftToViewport(l.left,r.width),d=ae.clampTopToViewport(l.top,r.height);(i!==l.left||d!==l.top)&&s({top:d,left:i})},[t,e,l]),l}function Qn({containerRef:e,store:t}){var g;const[n,o]=u.useState(null),[l,s]=u.useState(!1),r=u.useRef(null),i=u.useRef(null),d=u.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null)},[]),f=u.useCallback(()=>{d(),r.current=setTimeout(()=>{o(y=>l?y:null)},250)},[d,l]);u.useEffect(()=>{const y=e.current;if(!y)return;const w=O=>{var _,T,A;const $=(T=(_=O.target).closest)==null?void 0:T.call(_,"[data-run-id]");if(!$||!y.contains($))return;const S=$.dataset.runId,L=t.getRun(S);(A=L==null?void 0:L.marks)!=null&&A.link&&(d(),o(M=>(M==null?void 0:M.runId)===S?M:{runId:S,rect:$.getBoundingClientRect()}))},j=()=>f();return y.addEventListener("mouseover",w),y.addEventListener("mouseout",j),()=>{y.removeEventListener("mouseover",w),y.removeEventListener("mouseout",j)}},[e,t,d,f]),u.useEffect(()=>()=>d(),[d]);const m=u.useCallback(()=>s(!0),[]),p=u.useCallback(()=>{s(!1),o(null)},[]),h=u.useCallback((y,w)=>{if(!n)return;const j=t.getRun(n.runId);j&&(t.applyOperation(c.updateRun(n.runId,{marks:{...j.marks,link:{href:y,target:w}}})),p())},[n,t,p]),k=u.useCallback(()=>{if(!n)return;const y=t.getRun(n.runId);if(!y)return;const w={...y.marks};delete w.link,t.applyOperation(c.updateRun(n.runId,{marks:w})),p()},[n,t,p]),x=n&&t.getRun(n.runId),b=(g=x==null?void 0:x.marks)==null?void 0:g.link,I=!!(n&&b&&!l),B=$e(i,I,n?n.rect.bottom+6:null,n?n.rect.left:null);return a.jsxs(a.Fragment,{children:[I&&B?be.createPortal(a.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:B.top,left:B.left},onMouseEnter:d,onMouseLeave:f,children:[a.jsx("a",{className:"be-link-hover-card-url",href:b.href,target:b.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:b.href}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Edit link",title:"Edit link",children:a.jsx(c.PencilIcon,{size:13})}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:k,"aria-label":"Remove link",title:"Remove link",children:a.jsx(c.XIcon,{size:13})})]}),document.body):null,a.jsx(Et,{isOpen:l,initialHref:(b==null?void 0:b.href)??"",initialTarget:(b==null?void 0:b.target)??"_self",hasExistingLink:!!b,onSave:h,onRemove:k,onClose:p})]})}function St({title:e,onClose:t}){return a.jsxs("div",{className:"be-comment-popover-header",children:[a.jsx("span",{className:"be-comment-popover-title",children:e}),a.jsx("button",{type:"button",className:"be-comment-popover-close",onClick:t,"aria-label":"Close",children:a.jsx(c.XIcon,{size:14})})]})}const Yn='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function Xn({containerRef:e,store:t,authorId:n}){const[o,l]=u.useState(null),[s,r]=u.useState(!1),i=u.useRef(null),d=u.useRef(null),f=u.useRef(null),[,m]=c.useHoveredComment(),p=u.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),h=u.useCallback(()=>{p(),i.current=setTimeout(()=>{l(g=>s?g:null)},250)},[p,s]);u.useEffect(()=>{const g=e.current;if(!g)return;const y=$=>{var _,T,A;const S=(_=$==null?void 0:$.closest)==null?void 0:_.call($,"[data-run-id]");if(!S||!g.contains(S))return null;const L=(A=(T=t.getRun(S.dataset.runId))==null?void 0:T.marks)==null?void 0:A.commentIds;return L!=null&&L.length?{runEl:S,commentIds:L}:null},w=$=>{const S=y($.target);S&&(p(),l(L=>L&&L.runEl===S.runEl?L:{rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl}))},j=()=>h(),O=$=>{const S=y($.target);if(!S){r(!1),l(null);return}p(),r(!0),l({rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl})};return g.addEventListener("mouseover",w),g.addEventListener("mouseout",j),g.addEventListener("click",O),()=>{g.removeEventListener("mouseover",w),g.removeEventListener("mouseout",j),g.removeEventListener("click",O)}},[e,t,p,h]),u.useEffect(()=>{if(!o)return;const g=w=>{var j,O;(j=d.current)!=null&&j.contains(w.target)||(O=e.current)!=null&&O.contains(w.target)||(r(!1),l(null))},y=w=>{w.key==="Escape"&&(r(!1),l(null))};return document.addEventListener("mousedown",g),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",y)}},[o,e]),u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{var g;m(((g=o==null?void 0:o.commentIds)==null?void 0:g[0])??null)},[o,m]);const k=u.useCallback(()=>{r(!1),l(null)},[]),x=!!o,b=$e(d,x,o?o.rect.bottom+6:null,o?o.rect.left:null),I=u.useRef(!1);if(u.useEffect(()=>{var g,y;s&&d.current&&!I.current?(I.current=!0,f.current=document.activeElement,(d.current.querySelector(Yn)??d.current).focus()):!s&&I.current&&(I.current=!1,(y=(g=f.current)==null?void 0:g.focus)==null||y.call(g),f.current=null)},[s,b]),!x||!b)return null;const B=o.commentIds.map(g=>t.getComment(g)).filter(Boolean);return B.length===0?null:be.createPortal(a.jsxs("div",{ref:d,className:"be-comment-popover",contentEditable:!1,style:{position:"fixed",top:b.top,left:b.left},onMouseEnter:p,onMouseLeave:h,role:"dialog","aria-modal":s||void 0,"aria-label":`Comments (${B.length})`,tabIndex:-1,children:[a.jsx(St,{title:`Comments (${B.length})`,onClose:k}),B.map(g=>a.jsx(Wn.CommentThreadCard,{store:t,thread:g,authorId:n},g.id))]}),document.body)}function gt(e,t){const n=e==null?void 0:e.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;t.length===0||t.every(Nt)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function Jn(e={}){return{fontWeight:e.bold?"bold":void 0,fontStyle:e.italic?"italic":void 0,textDecoration:[(e.underline||e.link)&&"underline",e.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:e.subscript?"sub":e.superscript?"super":void 0,fontSize:e.subscript||e.superscript?"smaller":void 0,color:e.color||(e.link?"var(--noteloom-accent)":void 0),backgroundColor:e.highlight||void 0,cursor:e.link?"pointer":void 0}}function Zn(e,t){const n=e.childNodes.length===1?e.firstChild:null;n&&n.nodeType===3?n.nodeValue!==t&&(n.nodeValue=t):e.textContent=t}function eo({id:e,host:t,onValueSynced:n}){const o=v.useRun(e),[l]=c.useHoveredComment();return u.useLayoutEffect(()=>{var m,p,h,k,x;if(!t||!o)return;const s=o.value??"";(C.stripEmptyRunPlaceholder(t.textContent)!==s||s===""&&t.textContent==="")&&Zn(t,s===""?C.EMPTY_RUN_PLACEHOLDER:s);const d=Jn(o.marks);t.style.fontWeight=d.fontWeight??"",t.style.fontStyle=d.fontStyle??"",t.style.textDecoration=d.textDecoration??"",t.style.verticalAlign=d.verticalAlign??"",t.style.fontSize=d.fontSize??"",t.style.color=d.color??"",t.style.backgroundColor=d.backgroundColor??"",t.style.cursor=d.cursor??"",t.classList.toggle("be-comment-highlight",(((p=(m=o.marks)==null?void 0:m.commentIds)==null?void 0:p.length)??0)>0),t.classList.toggle("be-comment-highlight-active",!!l&&!!((k=(h=o.marks)==null?void 0:h.commentIds)!=null&&k.includes(l)));const f=(x=o.marks)==null?void 0:x.link;t.title=f!=null&&f.href?`${f.href} — Ctrl+Click to open`:"",t.onclick=f!=null&&f.href?b=>{!b.ctrlKey&&!b.metaKey||(b.preventDefault(),window.open(f.href,f.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[t,o,n,l]),null}function bt(e,t,n,o){var p,h,k;const l=(p=window.getSelection)==null?void 0:p.call(window);if(!l||!l.isCollapsed||l.rangeCount===0)return null;const{anchorNode:s,anchorOffset:r}=l;if(!s||!e.contains(s))return null;const i=x=>{const b=t.indexOf(x);if(b===-1)return null;const I=o?t[b-1]:t[b+1];if(!I)return null;const B=n(I);return B&&B.type!=="text"?I:null};if(s===e){const x=o?r-1:r,b=e.childNodes[x],I=(b==null?void 0:b.nodeType)===1?(h=b.dataset)==null?void 0:h.runId:void 0;if(!I||t.indexOf(I)===-1)return null;const B=n(I);return B&&B.type!=="text"?I:null}const d=s.nodeType===1?s:s.parentElement,f=(k=d==null?void 0:d.closest)==null?void 0:k.call(d,"[data-run-id]");return!f||!e.contains(f)||!(o?r===0:r===(s.textContent??"").length)?null:i(f.getAttribute("data-run-id"))}function kt(e,t,n){var d,f;const o=(d=window.getSelection)==null?void 0:d.call(window);if(!o||o.isCollapsed||o.rangeCount===0)return null;const l=o.getRangeAt(0);if(l.startContainer!==l.endContainer||!e.contains(l.startContainer)||l.endOffset!==l.startOffset+1)return null;const s=l.startContainer.childNodes[l.startOffset],r=(s==null?void 0:s.nodeType)===1?(f=s.dataset)==null?void 0:f.runId:void 0;if(!r||t.indexOf(r)===-1)return null;const i=n(r);return i&&i.type!=="text"?r:null}function yt(e,t,n){var i;if(t===e)return{childIndex:n,charOffset:null};const o=t.nodeType===1?t:t.parentElement,l=(i=o==null?void 0:o.closest)==null?void 0:i.call(o,"[data-run-id]");if(!l||!e.contains(l))return null;const s=Array.prototype.indexOf.call(e.childNodes,l),r=t===l?n===0?0:(l.textContent??"").length:n;return{childIndex:s,charOffset:r}}function to(e,t,n,o){const l=yt(e,o.startContainer,o.startOffset),s=yt(e,o.endContainer,o.endOffset);if(!l||!s)return null;const r=Array.from(e.childNodes).filter(m=>{var p;return m.nodeType===1&&((p=m.dataset)==null?void 0:p.runId)&&t.indexOf(m.dataset.runId)!==-1});let i=!1;const d=[];let f=null;return r.forEach((m,p)=>{const h=m.dataset.runId,k=n(h);if(!k)return;const x=p<l.childIndex,b=s.charOffset===null?p>=s.childIndex:p>s.childIndex;if(x||b){d.push(k);return}const I=l.charOffset!==null&&p===l.childIndex,B=s.charOffset!==null&&p===s.childIndex;if(k.type!=="text"){i=!0,f===null&&(f=d.length);return}const g=k.value??"";if(I&&B){const y=g.slice(0,l.charOffset)+g.slice(s.charOffset);y&&d.push({...k,value:y}),f=d.length}else if(I){const y=g.slice(0,l.charOffset);y&&d.push({...k,value:y}),f===null&&(f=d.length)}else if(B){const y=g.slice(s.charOffset);y&&d.push({id:c.genId(),type:"text",value:y,marks:k.marks})}}),i?{nextRuns:d,insertionIndex:f??d.length}:null}function no(e){var s;const t=(s=window.getSelection)==null?void 0:s.call(window);if(!t||!t.isCollapsed)return!1;const n=e.firstChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset===0;let o=n;for(;o&&o.firstChild;)o=o.firstChild;if(t.anchorNode!==o&&t.anchorNode!==n)return!1;const l=o.nodeType===3&&o.textContent===C.EMPTY_RUN_PLACEHOLDER?1:0;return t.anchorOffset<=l}function oo(e){var s;const t=(s=window.getSelection)==null?void 0:s.call(window);if(!t||!t.isCollapsed)return!1;const n=e.lastChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset>=e.childNodes.length;let o=n;for(;o&&o.lastChild;)o=o.lastChild;if(t.anchorNode!==o&&t.anchorNode!==n)return!1;const l=o.nodeType===3?(o.textContent??"").length:0;return t.anchorOffset>=l}function It(e,t,n){const o=e.getBlock(t),l=e.getBlock(o==null?void 0:o.parentId);if(!l)return null;const s=l.contentIds.indexOf(t),r=n==="backward"?s-1:s+1;if(r<0||r>=l.contentIds.length)return null;const i=l.contentIds[r];return Me(e,e.getBlock(i))?i:null}function lo({id:e,blockId:t,host:n,inlineRegistry:o,onValueSynced:l}){const s=v.useRun(e);if(!s)return null;if(s.type==="text")return a.jsx(eo,{id:e,host:n,onValueSynced:l});const r=o==null?void 0:o.get(s.type);if(!r)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${e})`),null;const i=r.component;return a.jsx(i,{id:e,blockId:t})}function so(e,t,n){let o=e.get(n);if(!o){o=document.createElement("span"),o.dataset.runId=n;const l=t.getRun(n);l&&l.type!=="text"&&o.setAttribute("contenteditable","false"),e.set(n,o)}return o}function ue({blockId:e,runIds:t,dir:n="auto",onEnter:o,onBackspaceAtStart:l,onDeleteAtEnd:s,onArrowUp:r,onArrowDown:i,onTab:d,onShiftTab:f,onAutoformat:m}){const p=c.useEditorStore(),h=c.useInlineRegistry(),k=c.useCommentAuthorId(),{getSelectedBlockId:x,setSelectedBlockId:b}=c.useSelectedBlock(),I=u.useRef(null),B=u.useRef(!1),g=u.useRef(new Map);u.useLayoutEffect(()=>{const T=I.current;if(!T)return;const A=new Set(t);for(const[D,E]of g.current)A.has(D)||(E.remove(),g.current.delete(D));let M=null;for(const D of t){const E=g.current.get(D);if(!E)continue;const P=M?M.nextSibling:T.firstChild;P!==E&&T.insertBefore(E,P),M=E}},[t]);const y=u.useCallback(()=>{if(B.current)return;const T=I.current;if(!T)return;const A=t.map(P=>p.getRun(P)).filter(Boolean),{runs:M,changed:D,onlyValueChanges:E}=C.reconcileDomToRuns(T,A);if(D){if(E){if(M.forEach((P,z)=>{P!==A[z]&&p.applyOperation(c.updateRun(P.id,{value:P.value}))}),m!=null&&m(M))return}else p.applyOperation(c.setBlockRuns(e,M.length?M:[{id:c.genId(),type:"text",value:"",marks:{}}]));gt(T,M)}},[p,e,t,m]),w=u.useCallback(()=>{gt(I.current,t.map(T=>p.getRun(T)).filter(Boolean))},[p,t]),j=u.useCallback(()=>{B.current=!0},[]),O=u.useCallback(()=>{B.current=!1,y()},[y]),$=u.useCallback(T=>{const M=t.map(D=>p.getRun(D)).filter(Boolean).filter(D=>D.id!==T);p.applyOperation(c.setBlockRuns(e,M.length?M:[{id:c.genId(),type:"text",value:"",marks:{}}]))},[p,e,t]),S=u.useCallback(T=>{x()===T?(p.applyOperation(c.removeBlock(T)),b(null)):b(T)},[p,x,b]),L=u.useCallback(T=>{var ee,Q,fe,le;if(B.current)return;if(T.target instanceof Node){const W=T.target.nodeType===1?T.target:T.target.parentElement;if((ee=W==null?void 0:W.closest)!=null&&ee.call(W,'[contenteditable="false"]'))return}const A=T.inputType??"",M=A.startsWith("delete"),D=A==="insertText"||A==="insertReplacementText";if(!M&&!D)return;const E=I.current;if(!E)return;const P=(Q=T.getTargetRanges)==null?void 0:Q.call(T),z=(fe=window.getSelection)==null?void 0:fe.call(window),G=(P==null?void 0:P[0])??(z!=null&&z.rangeCount?z.getRangeAt(0):null);if(!G||!E.contains(G.startContainer)||!E.contains(G.endContainer))return;const U=to(E,t,W=>p.getRun(W),G);if(!U)return;T.preventDefault();let{nextRuns:F,insertionIndex:V}=U,ne=null,Z=!1;if(D&&T.data){const W={id:c.genId(),type:"text",value:T.data,marks:{}};F=[...F.slice(0,V),W,...F.slice(V)],ne=W.id,Z=!1}else V>0?(ne=(le=F[V-1])==null?void 0:le.id,Z=!1):F.length>0&&(ne=F[0].id,Z=!0);const X=F.length?F:[{id:c.genId(),type:"text",value:"",marks:{}}];p.applyOperation(c.setBlockRuns(e,X));const se=ne??X[0].id;Z?C.focusRunStart(se):C.focusRunEnd(se)},[p,e,t]);u.useEffect(()=>{const T=I.current;if(T)return T.addEventListener("beforeinput",L),()=>T.removeEventListener("beforeinput",L)},[L]);const _=u.useCallback(T=>{if(!B.current){if(T.key==="Enter"&&o){T.preventDefault(),o(T);return}if(T.key==="Backspace"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){T.preventDefault(),$(M);return}const D=A&&bt(A,t,p.getRun.bind(p),!0);if(D){T.preventDefault(),$(D);return}if(A&&no(A)){if(!te(p,t)){const P=It(p,e,"backward");if(P){T.preventDefault(),S(P);return}}T.preventDefault(),l&&l(T)}return}if(T.key==="Delete"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){T.preventDefault(),$(M);return}const D=A&&bt(A,t,p.getRun.bind(p),!1);if(D){T.preventDefault(),$(D);return}if(A&&oo(A)){const E=It(p,e,"forward");if(E){T.preventDefault(),S(E);return}s&&s(T)}return}if(T.key==="ArrowUp"&&r){T.preventDefault(),r(T);return}if(T.key==="ArrowDown"&&i){T.preventDefault(),i(T);return}T.key==="Tab"&&(T.shiftKey&&f?(T.preventDefault(),f(T)):!T.shiftKey&&d&&(T.preventDefault(),d(T)))}},[o,l,s,r,i,d,f,$,S,t,e,p]);return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:I,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:y,onCompositionStart:j,onCompositionEnd:O,onKeyDown:_,children:t.map(T=>{const A=so(g.current,p,T);return be.createPortal(a.jsx(lo,{id:T,blockId:e,host:A,inlineRegistry:h,onValueSynced:w},T),A)})}),a.jsx(Qn,{containerRef:I,store:p}),a.jsx(Xn,{containerRef:I,store:p,authorId:k})]})}function Ge(e){const t=e.getRootId(),n=e.getBlock(t);if(!n||n.contentIds.length>0)return null;const{block:o,runs:l}=C.createTextLeafBlock("paragraph")(t);return e.applyOperation(c.insertBlock(o,t,0,{blocks:[o],runs:l})),o.id}const ro=new Set(["callout"]),Ct=new Set(["paragraph","heading","blockquote"]);function Mt(e,t){return e===t||Ct.has(e)&&Ct.has(t)}function Oe(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.contentIds.length===0||n.contentIds.length===1&&ao(e,n.contentIds[0]);if(l<=0){if(!s)return null;if(o.contentIds.length>1)return ye(e,[c.removeBlock(t)]),e.getBlock(o.id).contentIds[0];if(ro.has(o.type))return co(e,o);if(n.type==="paragraph")return null;const{block:f,runs:m}=C.createTextLeafBlock("paragraph")(o.id);return ye(e,[c.insertBlock(f,o.id,l,{blocks:[f],runs:m}),c.removeBlock(t)]),f.id}const r=o.contentIds[l-1],i=e.getBlock(r);if(s)return ye(e,[c.removeBlock(t)]),r;if(Me(e,i))return ye(e,[c.removeBlock(r)]),t;if(!i||!Mt(i.type,n.type))return null;const d=[...i.contentIds,...n.contentIds];return ye(e,[c.setBlockContentIds(r,d),c.setBlockContentIds(t,[]),c.removeBlock(t)]),r}function ao(e,t){const n=e.getRun(t);return!n||(n.value??"")===""}function co(e,t){const n=e.getBlock(t.parentId);if(!n)return null;const o=n.contentIds.indexOf(t.id),l=o>0?n.contentIds[o-1]:null,s=o!==-1&&o<n.contentIds.length-1?n.contentIds[o+1]:null;ye(e,[c.removeBlock(t.id)]);const r=Ge(e);return l??s??r}function ye(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Ie(e,t,n,o){if(!t||t===n)return;const l=C.resolveBlockLastRun(e,t);if(l){C.focusRunEnd(l);return}o(t),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${t}"]`))==null||s.focus()})}function ce(e,t){var o,l;if(!t)return"auto";if((o=t.props)!=null&&o.dir)return t.props.dir;const n=e.getBlock(e.getRootId());return((l=n==null?void 0:n.props)==null?void 0:l.dir)??"auto"}function io(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}const uo=[{re:/^(#{1,3})[  ]$/,type:"heading",props:e=>({level:e[1].length})},{re:/^[-*][  ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[  ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][  ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[  ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function po(e,t,n){if(n.length!==1||n[0].type!=="text")return!1;const o=n[0].value??"";for(const l of uo){const s=l.re.exec(o);if(!s)continue;const r=o.slice(s[0].length),{ops:i}=ae.convertBlockType(e,t,l.type,l.props(s),[n[0].id]);return io(e,[c.updateRun(n[0].id,{value:r}),...i]),C.focusRunStart(n[0].id),!0}return!1}const fo=new Set(["callout","toggleHeading"]);function mo({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{const h=t.getBlock(n==null?void 0:n.parentId),k=te(t,(n==null?void 0:n.contentIds)??[]),x=!!h&&h.contentIds[h.contentIds.length-1]===e;if(k&&x&&fo.has(h==null?void 0:h.type)){C.insertSiblingAfterAndFocus(t,h.id,C.createTextLeafBlock("paragraph"));return}C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),s=u.useCallback(()=>{var I,B;const h=t.getBlock(n==null?void 0:n.parentId),k=te(t,(n==null?void 0:n.contentIds)??[]),x=((I=h==null?void 0:h.contentIds)==null?void 0:I.length)===1&&h.contentIds[0]===e;if(k&&x&&(h==null?void 0:h.type)==="toggleHeading"){const g=((B=h.props)==null?void 0:B.titleRunIds)??[],y=g[g.length-1];y&&C.focusRunEnd(y);return}const b=Oe(t,e);Ie(t,b,e,o)},[t,e,n,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=u.useCallback(h=>po(t,e,h),[t,e]),f=c.useBlockClassName("be-paragraph",n);if(!n)return null;const m=te(t,n.contentIds),p=ce(t,n);return a.jsx("div",{className:f,"data-block-id":e,"data-empty":m?"":void 0,"data-placeholder":"Type '/' for commands",dir:p,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:p,onEnter:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i,onAutoformat:d})})}const ho={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function ie(e,t,n={}){const o=[],l=(s,r)=>{var f,m;if(s.nodeType===3){const p=s.textContent;p&&o.push({id:c.genId(),type:"text",value:p,marks:{...r}});return}if(s.nodeType!==1)return;if(t!=null&&t.inlineRegistry)for(const p of t.inlineRegistry.listHtmlMatchers()){const h=p.fromHTML(s,t);if(h){o.push(h);return}}let i=r;const d=ho[s.tagName];d&&(i={...i,[d]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(f=s.style)!=null&&f.color&&(i={...i,color:s.style.color}),(m=s.style)!=null&&m.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const p of s.childNodes)l(p,i)};return l(e,n),o.length?o:[{id:c.genId(),type:"text",value:"",marks:{}}]}function go(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</p>`}function bo(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function ko(e,t){return v.runsToMarkdown(e.contentIds.map(n=>t.store.getRun(n)),t)}function yo(e,t){if(e.tagName!=="P")return null;const n=ie(e,t);return{block:{id:c.genId(),type:"paragraph",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}const $t=v.defineBlock({name:"paragraph",component:mo,contentModel:"runs",defaultProps:{},toHTML:go,toPlainText:bo,toMarkdown:ko,fromHTML:yo,slashCommand:{label:"Text",icon:c.TextIcon,keywords:["paragraph","text","p"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("paragraph"))}});function Io({id:e}){var k;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),s=u.useCallback(()=>{const x=Oe(t,e);Ie(t,x,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=((k=n==null?void 0:n.props)==null?void 0:k.level)??3,f=c.useBlockClassName(`be-heading be-heading-${d}`,n);if(!n)return null;const m=`h${d}`,p=te(t,n.contentIds),h=ce(t,n);return a.jsx(m,{className:f,"data-block-id":e,"data-empty":p?"":void 0,"data-placeholder":`Heading ${d}`,dir:h,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:h,onEnter:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})}const Xe={1:c.Heading1Icon,2:c.Heading2Icon,3:c.Heading3Icon},Co={H1:1,H2:2,H3:3};function xo(e,t){var l;const n=((l=e.props)==null?void 0:l.level)??3,o=e.contentIds.map(s=>t.store.getRun(s));return`<h${n}>${o.map(s=>v.runToHTML(s,t)).join("")}</h${n}>`}function Bo(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function vo(e,t){var l;const n=((l=e.props)==null?void 0:l.level)??3,o=v.runsToMarkdown(e.contentIds.map(s=>t.store.getRun(s)),t);return`${"#".repeat(n)} ${o}`}function To(e,t){const n=Co[e.tagName];if(!n)return null;const o=ie(e,t);return{block:{id:c.genId(),type:"heading",parentId:null,contentIds:o.map(s=>s.id),props:{level:n}},runs:o}}const Ot=v.defineBlock({name:"heading",contentModel:"runs",component:Io,defaultProps:{level:3},toHTML:xo,toPlainText:Bo,toMarkdown:vo,fromHTML:To,slashCommands:[{label:"Heading 1",icon:Xe[1],keywords:["heading","h1","title"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:1}))},{label:"Heading 2",icon:Xe[2],keywords:["heading","h2","subtitle"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:2}))},{label:"Heading 3",icon:Xe[3],keywords:["heading","h3","title"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:3}))}]}),wo=[];function it(e){const t=c.useEditorStore(),n=u.useCallback(l=>t.subscribe(e,l),[t,e]),o=u.useCallback(()=>{const l=t.getBlock(e);return l?l.contentIds:wo},[t,e]);return u.useSyncExternalStore(n,o)}class Dt extends u.Component{constructor(){super(...arguments);mt(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,o){var l,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,o),(s=(l=this.props).onError)==null||s.call(l,n,o),queueMicrotask(()=>this.setState(r=>({hasError:!1,nonce:r.nonce+1})))}render(){return this.state.hasError?null:a.jsx(u.Fragment,{children:this.props.children},this.state.nonce)}}const ut=u.memo(function({id:t}){const n=v.useBlock(t),o=c.useBlockRegistry();if(!n)return null;const l=o.get(n.type);if(!l)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${t})`),null;const s=l.component;return a.jsx(Dt,{children:a.jsx(s,{id:t})})});function Ve(e,t,n,o){const l=u.useRef(!1),s=u.useRef(!1);u.useEffect(()=>{var m,p;if(!t){s.current=!1,l.current&&(l.current=!1,(p=(m=o==null?void 0:o.current)==null?void 0:m.focus)==null||p.call(m));return}l.current=!0;const r=e.current;if(!r)return;const i=()=>Array.from(r.querySelectorAll('[role="menuitem"]')),d=h=>{var b;const k=i();if(k.length===0)return;const x=(h%k.length+k.length)%k.length;(b=k[x])==null||b.focus()};s.current||(s.current=!0,d(0));const f=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const k=i(),x=k.indexOf(document.activeElement);x!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),d(x+1)):h.key==="ArrowUp"?(h.preventDefault(),d(x-1)):h.key==="Home"?(h.preventDefault(),d(0)):h.key==="End"&&(h.preventDefault(),d(k.length-1)))};return r.addEventListener("keydown",f),()=>r.removeEventListener("keydown",f)})}const xt="be-live-region";function Ro(){if(typeof document>"u")return null;let e=document.getElementById(xt);return e||(e=document.createElement("div"),e.id=xt,e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),Object.assign(e.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(e),e)}function de(e){const t=Ro();t&&(t.textContent="",setTimeout(()=>{t.textContent=e},0))}const ke="💡",Pt="gray";function Ao({icon:e=ke,color:t=Pt}={}){return function(o){const l=c.genId(),{block:s,runs:r}=C.createTextLeafBlock("paragraph")(l);return{block:{id:l,type:"callout",parentId:o,contentIds:[s.id],props:{icon:e,color:t}},runs:r,subtreeBlocks:[s]}}}const Ht=[{type:"paragraph",props:{},label:"Text",icon:c.TextIcon},{type:"heading",props:{level:1},label:"Heading 1",icon:c.Heading1Icon},{type:"heading",props:{level:2},label:"Heading 2",icon:c.Heading2Icon},{type:"heading",props:{level:3},label:"Heading 3",icon:c.Heading3Icon},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:c.BulletedListIcon},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:c.NumberedListIcon},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:c.CheckboxIcon},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:c.ChevronRightIcon},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:c.ChevronRightIcon},{type:"blockquote",props:{},label:"Quote",icon:c.QuoteIcon},{type:"callout",props:{icon:ke},label:"Callout",icon:c.CalloutIcon},{type:"code",props:{language:"plaintext"},label:"Code",icon:c.CodeIcon}],jo=new Set(Ht.map(e=>e.type));function _t(e){return jo.has(e)}function Lo(e,t){return e!=null&&e.props&&"titleRunIds"in e.props?e.props.titleRunIds:t&&!t.isLeaf(e==null?void 0:e.type)?[]:(e==null?void 0:e.contentIds)??[]}function Ft(e,t,n,o){const l=e.getBlock(n),s=Lo(l,t),r=[];if(o.type==="code")for(const m of s){const p=e.getRun(m);p!=null&&p.marks&&Object.keys(p.marks).length>0&&r.push(c.updateRun(m,{marks:{}}))}const i={...o.props},{ops:d,newBlockId:f}=ae.convertBlockType(e,n,o.type,i,s,t);return{ops:[...r,...d],newBlockId:f}}function Ut({onSelect:e,onClose:t,containerRef:n,menuClassName:o="be-block-gutter-menu",itemClassName:l="be-block-gutter-menu-item"}){const[s,r]=u.useState(!1),[i,d]=u.useState(null),f=u.useRef(null),m=u.useRef(null),p=u.useCallback(g=>{m.current=g,n&&(n.current=g)},[n]),h=u.useCallback(()=>{r(!1),t==null||t()},[t]);v.useOutsideClickAndEscape([f,m],s,h),Ve(m,s,h,f);const k=$e(m,s,i==null?void 0:i.top,i?i.right+4:null),x=u.useCallback(()=>{var g;d(((g=f.current)==null?void 0:g.getBoundingClientRect())??null),r(!0)},[]),b=u.useCallback(g=>{e(g),h()},[e,h]),I=u.useCallback(g=>{g.key==="ArrowRight"&&!s&&(g.preventDefault(),x())},[s,x]),B=u.useCallback(g=>{g.key==="ArrowLeft"&&(g.preventDefault(),h())},[h]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:f,type:"button",role:"menuitem",className:l,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():x(),onKeyDown:I,children:[a.jsx(c.ChevronRightIcon,{size:15})," Turn into"]}),s&&k&&be.createPortal(a.jsx("div",{ref:p,role:"menu","aria-label":"Turn into",className:o,style:{position:"fixed",top:k.top,left:k.left},onKeyDown:B,children:Ht.map((g,y)=>{const w=g.icon;return a.jsxs("button",{type:"button",role:"menuitem",className:l,onClick:()=>b(g),children:[a.jsx(w,{size:15})," ",g.label]},`${g.type}-${y}`)})}),document.body)]})}function Kt(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=ht.captureSubtree(e,t),{block:r,runs:i,subtreeBlocks:d}=ht.remapSubtreeIds(s);return e.applyOperation(c.insertBlock(r,o.id,l+1,{blocks:[r,...d],runs:i})),C.focusBlockStart(e,r.id),r.id}function zt(e,t){const n=e.getBlock(t),o=n&&e.getBlock(n.parentId);if(!o)return!1;const l=o.contentIds.indexOf(t);return l<=0?!1:(e.applyOperation(c.moveBlock(t,o.id,l-1)),!0)}function Gt(e,t){const n=e.getBlock(t),o=n&&e.getBlock(n.parentId);if(!o)return!1;const l=o.contentIds.indexOf(t);return l===-1||l>=o.contentIds.length-1?!1:(e.applyOperation(c.moveBlock(t,o.id,l+1)),!0)}function dt(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=l>0?o.contentIds[l-1]:null,r=l!==-1&&l<o.contentIds.length-1?o.contentIds[l+1]:null;e.applyOperation(c.removeBlock(t));const i=Ge(e),d=s??r??i;return d&&C.focusBlockStart(e,d),d??null}function No(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Vt({id:e}){var T;const t=c.useEditorStore(),n=c.useBlockRegistry(),o=v.useBlock(e),[l,s]=u.useState(!1),[r,i]=u.useState(null),d=u.useRef(null),f=u.useRef(null),m=u.useRef(null),p=u.useMemo(()=>[d,f,m],[]),[h]=c.useBlockRangeSelection(),k=h.includes(e),x=u.useCallback(()=>s(!1),[]);v.useOutsideClickAndEscape(p,l,x),Ve(f,l,x,d);const b=u.useCallback(()=>{var A;i(((A=d.current)==null?void 0:A.getBoundingClientRect())??null),s(!0)},[]),I=$e(f,l,(r==null?void 0:r.bottom)!=null?r.bottom+4:null,r==null?void 0:r.left),B=u.useCallback(()=>{C.insertSiblingAfterAndFocus(t,e,C.createTextLeafBlock("paragraph"))},[t,e]),g=u.useCallback(()=>{Kt(t,e),de("Block duplicated"),x()},[t,e,x]),y=u.useCallback(()=>{zt(t,e)&&de("Block moved up"),x()},[t,e,x]),w=u.useCallback(()=>{Gt(t,e)&&de("Block moved down"),x()},[t,e,x]),j=u.useCallback(()=>{dt(t,e),de("Block deleted"),x()},[t,e,x]),O=!!((T=o==null?void 0:o.props)!=null&&T.hidden),$=u.useCallback(()=>{t.applyOperation(c.updateBlockProps(e,{hidden:!O})),de(O?"Block shown in preview":"Block hidden in preview"),x()},[t,e,O,x]),S=ce(t,o)==="rtl",L=u.useCallback(()=>{t.applyOperation(c.updateBlockProps(e,{dir:S?"ltr":"rtl"})),de(S?"Block set to left-to-right":"Block set to right-to-left"),x()},[t,e,S,x]),_=u.useCallback(A=>{const{ops:M}=Ft(t,n,e,A);No(t,M),de(`Turned into ${A.label}`),x()},[t,n,e,x]);return o?a.jsxs("div",{className:`be-block-row${O?" be-block-row-hidden":""}${k?" be-block-row-range-selected":""}`,"data-block-row-id":e,dir:ce(t,o),children:[a.jsxs("div",{className:`be-block-gutter${l?" be-block-gutter-active":""}`,contentEditable:!1,children:[a.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:B,"aria-label":"Add block below",children:a.jsx(c.PlusIcon,{size:16})}),a.jsx("button",{ref:d,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":l,onClick:()=>l?x():b(),children:a.jsx(c.GripVerticalIcon,{size:16})})]}),a.jsx("div",{className:"be-block-row-content",children:a.jsx(ut,{id:e})}),l&&I&&be.createPortal(a.jsxs("div",{ref:f,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:I.top,left:I.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:g,children:[a.jsx(c.CopyIcon,{size:15})," Duplicate"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:y,children:[a.jsx(c.ArrowUpIcon,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[a.jsx(c.ArrowDownIcon,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:$,children:[O?a.jsx(c.EyeIcon,{size:15}):a.jsx(c.EyeOffIcon,{size:15}),O?"Show in preview":"Hide in preview"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:L,children:[S?a.jsx(c.AlignLeftIcon,{size:15}):a.jsx(c.AlignRightIcon,{size:15}),S?"Switch to left-to-right":"Switch to right-to-left"]}),_t(o.type)&&a.jsx(Ut,{onSelect:_,onClose:()=>{},containerRef:m}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:j,children:[a.jsx(c.TrashIcon,{size:15})," Delete"]})]}),document.body)]}):null}function pe({parentId:e,isTopLevel:t=!1,filterIds:n}){const o=it(e),l=c.useEditorStore(),[s]=c.usePreviewMode(),r=n??o,i=s?r.filter(d=>{var f,m;return!((m=(f=l.getBlock(d))==null?void 0:f.props)!=null&&m.hidden)}):r;return t&&!s?i.map(d=>a.jsx(Vt,{id:d},d)):i.map(d=>a.jsx(ut,{id:d},d))}const Eo=97,So=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function Mo(e){let t="";for(;e>0;)e-=1,t=String.fromCharCode(Eo+e%26)+t,e=Math.floor(e/26);return t}function $o(e){let t="",n=e;for(const[o,l]of So)for(;n>=o;)t+=l,n-=o;return t}function Oo(e){var t,n;return(e==null?void 0:e.type)==="listItem"&&((t=e.props)==null?void 0:t.checked)===void 0&&((n=e.props)==null?void 0:n.collapsed)===void 0}function Bt(e,t){let n=0,o=t;for(;o;){const l=e.getBlock(o.parentId);if(!l||l.type!=="listItem")break;n+=1,o=l}return n}function Do(e,t,n){const o=n.indexOf(t.id);let l=1;for(let s=o-1;s>=0;s-=1){const r=e.getBlock(n[s]);if(!Oo(r)||!r.props.ordered)break;l+=1}return l}function Po(e,t){const n=(e%3+3)%3;return n===0?`${t}.`:n===1?`${Mo(t)}.`:`${$o(t)}.`}const Ho=["•","◦","▪"];function _o(e){const t=(e%3+3)%3;return Ho[t]}function Ne({ordered:e=!1,checked:t,collapsed:n}={}){return function(l,s){const r=c.genId(),i=s!=null&&s.length?s:[{id:c.genId(),type:"text",value:"",marks:{}}],d={ordered:e,titleRunIds:i.map(h=>h.id)};t!==void 0&&(d.checked=t);let f=[],m=[],p=i;if(n!==void 0){d.collapsed=n;const{block:h,runs:k}=C.createTextLeafBlock("paragraph")(r);f=[h.id],m=[h],p=[...i,...k]}return{block:{id:r,type:"listItem",parentId:l,contentIds:f,props:d},runs:p,subtreeBlocks:m}}}function Fo(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=l>0?o.contentIds[l-1]:null,r=s?e.getBlock(s):null;if(!r||r.type!=="listItem"){C.focusAdjacentBlock(e,t,"down");return}e.applyOperation(c.moveBlock(t,s,r.contentIds.length)),C.focusBlockStart(e,t)}function nt(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId);if(!o||o.type!=="listItem")return;const l=o.parentId,r=e.getBlock(l).contentIds.indexOf(o.id);e.applyOperation(c.moveBlock(t,l,r+1)),C.focusBlockStart(e,t)}function Ae(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function qt(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function Uo(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const o=e.getBlock(n[0]);return!!o&&o.type==="paragraph"&&te(e,o.contentIds)}function Ko(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.props.titleRunIds??[],i=qt(e,s)&&Uo(e,n);if(l>0){const m=o.contentIds[l-1],p=e.getBlock(m);if(i)return Ae(e,[c.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0};if(Me(e,p))return Ae(e,[c.removeBlock(m)]),{focusBlockId:t,needsRefocus:!1};if((p==null?void 0:p.type)==="listItem"&&n.contentIds.length===0){const h=[...p.props.titleRunIds??[],...s];return Ae(e,[c.updateBlockProps(m,{titleRunIds:h}),c.updateBlockProps(t,{titleRunIds:[]}),c.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0}}return null}if(o.type==="listItem")return nt(e,t),{focusBlockId:t,needsRefocus:!0};if(!i)return null;if(o.contentIds.length>1)return Ae(e,[c.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:d,runs:f}=C.createTextLeafBlock("paragraph")(o.id);return Ae(e,[c.insertBlock(d,o.id,l,{blocks:[d],runs:f}),c.removeBlock(t)]),{focusBlockId:d.id,needsRefocus:!0}}function zo(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Go(e,t){const o=e.getBlock(t).parentId,s=e.getBlock(o).contentIds.indexOf(t),{block:r,runs:i}=C.createTextLeafBlock("paragraph")(o);return zo(e,[c.insertBlock(r,o,s,{blocks:[r],runs:i}),c.updateBlockProps(t,{titleRunIds:[]}),c.removeBlock(t)]),C.focusBlockStart(e,r.id),r.id}function Vo(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function qo({id:e}){var $,S;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=it(n==null?void 0:n.parentId),s=u.useCallback(()=>{var P,z,G,U,F;const L=((P=n==null?void 0:n.props)==null?void 0:P.titleRunIds)??[],_=t.getBlock(n==null?void 0:n.parentId),T=qt(t,L);if(T&&(_==null?void 0:_.type)==="listItem"){nt(t,e);return}const A=(((z=n==null?void 0:n.contentIds)==null?void 0:z.length)??0)>0;if(T&&(_==null?void 0:_.type)!=="listItem"&&!A){Go(t,e);return}const M=((G=n==null?void 0:n.props)==null?void 0:G.checked)!==void 0,D=((U=n==null?void 0:n.props)==null?void 0:U.collapsed)!==void 0,E=Ne({ordered:(F=n==null?void 0:n.props)==null?void 0:F.ordered,checked:M?!1:void 0,collapsed:D?!1:void 0});A&&!D?C.insertFirstChildSplitAtCaretAndFocus(t,e,L,E):C.insertSiblingSplitAtCaretAndFocus(t,e,L,E)},[t,e,n]),r=u.useCallback(()=>Fo(t,e),[t,e]),i=u.useCallback(()=>nt(t,e),[t,e]),d=u.useCallback(()=>{const L=Ko(t,e);!L||!L.needsRefocus||Ie(t,L.focusBlockId,e,o)},[t,e,o]),f=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),m=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),p=u.useCallback(()=>{var L;t.applyOperation(c.updateBlockProps(e,{checked:!((L=n==null?void 0:n.props)!=null&&L.checked)}))},[t,e,($=n==null?void 0:n.props)==null?void 0:$.checked]),h=u.useCallback(()=>{var _,T;if(!((((_=n==null?void 0:n.contentIds)==null?void 0:_.length)??0)>0)){const{block:A,runs:M}=C.createTextLeafBlock("paragraph")(e);Vo(t,[c.insertBlock(A,e,0,{blocks:[A],runs:M}),c.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(A.contentIds[0]);return}t.applyOperation(c.updateBlockProps(e,{collapsed:!((T=n==null?void 0:n.props)!=null&&T.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(S=n==null?void 0:n.props)==null?void 0:S.collapsed]),k=c.useBlockClassName("be-list-item",n);if(!n)return null;const{ordered:x,checked:b,collapsed:I,titleRunIds:B=[]}=n.props,g=b!==void 0,y=!g&&I!==void 0,w=n.contentIds.length>0,j=B.map(L=>t.getRun(L)).filter(L=>(L==null?void 0:L.type)==="text").map(L=>L.value).join("").trim(),O=ce(t,n);return a.jsxs("div",{className:k,"data-block-id":e,dir:O,children:[a.jsxs("div",{className:"be-list-item-row",children:[g?a.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!b,onChange:p,"aria-label":j||"To-do item"}):y?a.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!I,"aria-label":w?I?"Expand toggle":"Collapse toggle":"Add content to toggle",children:I?a.jsx(c.ChevronRightIcon,{}):a.jsx(c.ChevronDownIcon,{})}):a.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:x?Po(Bt(t,n),Do(t,n,l)):_o(Bt(t,n))}),a.jsx("div",{className:"be-list-item-title","data-empty":te(t,B)?"":void 0,"data-placeholder":g?"To-do":y?"Toggle":"List item",style:b?{textDecoration:"line-through",opacity:.6}:void 0,children:a.jsx(ue,{blockId:e,runIds:B,dir:O,onEnter:s,onTab:r,onShiftTab:i,onBackspaceAtStart:d,onArrowUp:f,onArrowDown:m})})]}),(!y||!I)&&a.jsx("div",{className:"be-list-item-children",children:a.jsx(pe,{parentId:e})})]})}function Wo(e,t){const{titleRunIds:n=[],ordered:o}=e.props,l=n.map(i=>v.runToHTML(t.store.getRun(i),t)).join(""),s=e.contentIds.map(i=>t.registry.get(t.store.getBlock(i).type).toHTML(t.store.getBlock(i),t)).join(""),r=s?`<${o?"ol":"ul"}>${s}</${o?"ol":"ul"}>`:"";return`<li>${l}${r}</li>`}function Qo(e,t){const{titleRunIds:n=[]}=e.props;return n.map(o=>v.runToPlainText(t.store.getRun(o),t)).join("")}function Yo(e,t){const{titleRunIds:n=[],ordered:o,checked:l}=e.props,s=l!==void 0?l?"- [x] ":"- [ ] ":o?"1. ":"- ",r=v.runsToMarkdown(n.map(d=>t.store.getRun(d)),t),i=e.contentIds.map(d=>{const f=t.store.getBlock(d),m=t.registry.get(f.type);return(m.toMarkdown??m.toPlainText)(f,t).split(`
2
+ `).map(h=>h&&` ${h}`).join(`
3
+ `)}).join(`
4
+ `);return i?`${s}${r}
5
+ ${i}`:`${s}${r}`}function Wt(e,t){const n=[],o=[];for(const p of e.childNodes)p.nodeType===1&&(p.tagName==="UL"||p.tagName==="OL")?o.push(p):n.push(p);const l=e.ownerDocument.createElement("span");for(const p of n)l.appendChild(p.cloneNode(!0));const s=ie(l,t),r=c.genId(),i=[...s],d=[],f=[];for(const p of o){const h=p.tagName==="OL";for(const k of p.children){if(k.tagName!=="LI")continue;const x=Wt(k,t);x.block.parentId=r,x.block.props.ordered=h,d.push(x.block,...x.childBlocks),i.push(...x.runs),f.push(x.block.id)}}return{block:{id:r,type:"listItem",parentId:null,contentIds:f,props:{ordered:!1,titleRunIds:s.map(p=>p.id)}},runs:i,childBlocks:d}}function Xo(e,t){if(e.tagName!=="LI")return null;const{block:n,runs:o,childBlocks:l}=Wt(e,t);return{block:n,runs:o,subtreeBlocks:l}}const Qt=v.defineBlock({name:"listItem",contentModel:"blocks",component:qo,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Wo,toPlainText:Qo,toMarkdown:Yo,fromHTML:Xo,slashCommands:[{label:"Bulleted list",icon:c.BulletedListIcon,keywords:["list","bullet","ul"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1}))},{label:"Numbered list",icon:c.NumberedListIcon,keywords:["list","number","ordered","ol"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!0}))},{label:"To-do list",icon:c.CheckboxIcon,keywords:["todo","checkbox","task","checklist"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1,checked:!1}))},{label:"Toggle list",icon:c.ChevronRightIcon,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1,collapsed:!1}))}]}),Yt=["text","date","checkbox","select"],De="text",qe=160,me=80;function Jo(e){return`Column ${e+1}`}function pt(e){return Array.from({length:e},(t,n)=>({id:c.genId(),label:Jo(n),type:De,width:qe}))}function J(e,t){var o;const n=(o=e.props)==null?void 0:o.columns;return!Array.isArray(n)||n.length!==t?pt(t):n.map(l=>{const s=l.type??De,r=l.width??qe;return s===l.type&&r===l.width?l:{...l,type:s,width:r}})}function Xt(e){switch(e){case"date":return{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:c.genId(),type:"text",value:"",marks:{}}}}function We(e,t){const n=Xt(t==null?void 0:t.type);return{block:{id:c.genId(),type:"tableCell",parentId:e,contentIds:[n.id],props:{}},run:n}}function Jt(e,t,n){if(e.type===t)return e;let o;if(e.type==="text")o=e.value??"";else{const l=n==null?void 0:n.get(e.type);o=l!=null&&l.toPlainText?l.toPlainText(e):""}if(t==="date"){const l=o?new Date(o):null,s=l&&!Number.isNaN(l.getTime())?l.toISOString().slice(0,10):"";return{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:s}}}return t==="checkbox"?{id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:o}}:{id:c.genId(),type:"text",value:o,marks:{}}}function Se(e,t){if(!e)return"";if(e.type==="text")return e.value??"";const n=t==null?void 0:t.get(e.type);return n!=null&&n.toPlainText?n.toPlainText(e):""}function Zo(e,t,n){var o,l,s;return t==="date"?((o=e==null?void 0:e.data)==null?void 0:o.isoDate)??"":t==="checkbox"?(l=e==null?void 0:e.data)!=null&&l.checked?1:0:t==="select"?(((s=e==null?void 0:e.data)==null?void 0:s.selectedLabel)??"").trim():Se(e,n).trim()}function el(e,t,n){if(n==="checkbox")return e-t;const o=Number(e),l=Number(t);return e!==""&&t!==""&&!Number.isNaN(o)&&!Number.isNaN(l)?o-l:String(e).localeCompare(String(t),void 0,{sensitivity:"base"})}function tl(e,t,n,o){const l=e.map(({rowId:r,run:i})=>({rowId:r,key:Zo(i,t,o)})),s=r=>r===""||r==null;return l.sort((r,i)=>{const d=s(r.key),f=s(i.key);if(d&&f)return 0;if(d)return 1;if(f)return-1;const m=el(r.key,i.key,t);return n==="desc"?-m:m}),l.map(r=>r.rowId)}const Zt=["none","count","count-values","count-empty","sum","average","min","max"],en={none:"None",count:"Count all","count-values":"Count filled","count-empty":"Count empty",sum:"Sum",average:"Average",min:"Min",max:"Max"},nl={count:"Count","count-values":"Filled","count-empty":"Empty",sum:"Sum",average:"Avg",min:"Min",max:"Max"};function tn(e,t,n,o){if(!n||n==="none")return null;if(n==="count")return e.length;const l=e.map(r=>Se(r,o).trim());if(n==="count-values")return l.filter(r=>r!=="").length;if(n==="count-empty")return l.filter(r=>r==="").length;const s=l.map(Number).filter((r,i)=>l[i]!==""&&!Number.isNaN(r));return s.length===0?null:n==="sum"?s.reduce((r,i)=>r+i,0):n==="average"?s.reduce((r,i)=>r+i,0)/s.length:n==="min"?Math.min(...s):n==="max"?Math.max(...s):null}function nn(e){return e==null?"":Number.isInteger(e)?String(e):e.toFixed(2)}function he(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function on(e,t){const o=e.getBlock(t.parentId).contentIds.indexOf(t.id);he(e,[c.removeBlock(t.id)]);const l=Ge(e);if(l)return C.focusBlockStart(e,l),null;const s=e.getBlock(t.parentId),r=s.contentIds[o]??s.contentIds[o-1];return r&&C.focusBlockStart(e,r),null}function ln(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=J(o,n.contentIds.length),r=c.genId(),i=[],d=[],f=[];for(const p of s){const h=We(r,p);i.push(h.block),d.push(h.run),f.push(h.block.id)}const m={id:r,type:"tableRow",parentId:o.id,contentIds:f,props:{}};return e.applyOperation(c.insertBlock(m,o.id,l+1,{blocks:[m,...i],runs:d})),C.focusBlockStart(e,r),r}function sn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId);if(o.contentIds.length<=1)return on(e,o);const l=o.contentIds.indexOf(t);he(e,[c.removeBlock(t)]);const s=e.getBlock(o.id),r=Math.min(l,s.contentIds.length-1),i=s.contentIds[r];return i&&C.focusBlockStart(e,i),i??null}function ot(e,t,n){const o=e.getBlock(t),l=J(o,o.contentIds[0]?e.getBlock(o.contentIds[0]).contentIds.length:0),s={id:c.genId(),label:"New Column",type:De,width:qe},r=[];let i=null;for(const f of o.contentIds){const m=We(f,s);i===null&&(i=m.block.id),r.push(c.insertBlock(m.block,f,n+1,{blocks:[m.block],runs:[m.run]}))}const d=[...l];return d.splice(n+1,0,s),r.push(c.updateBlockProps(t,{columns:d})),he(e,r),i&&C.focusBlockStart(e,i),i}function rn(e,t,n){const o=e.getBlock(t),l=e.getBlock(o.contentIds[0]);if(!l||l.contentIds.length<=1)return on(e,o);const s=J(o,l.contentIds.length),r=o.contentIds.map(p=>{const h=e.getBlock(p);return c.removeBlock(h.contentIds[n])}),i=s.filter((p,h)=>h!==n);r.push(c.updateBlockProps(t,{columns:i})),he(e,r);const d=e.getBlock(o.contentIds[0]),f=Math.min(n,d.contentIds.length-1),m=d.contentIds[f];return m&&C.focusBlockStart(e,m),m??null}function lt(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0);if(!r[n])return;const i=[...r];i[n]={...r[n],width:Math.max(me,Math.round(o))},e.applyOperation(c.updateBlockProps(t,{columns:i}))}function an(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),i=[...J(l,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:o},e.applyOperation(c.updateBlockProps(t,{columns:i})))}function st(e,t,n,o,l){var m;const s=e.getBlock(t),r=s.contentIds.map(p=>{const h=e.getBlock(p),k=e.getBlock(h.contentIds[n]);return{rowId:p,run:k?e.getRun(k.contentIds[0]):null}}),d=((m=J(s,r.length?e.getBlock(s.contentIds[0]).contentIds.length:0)[n])==null?void 0:m.type)??De,f=tl(r,d,o,l);e.applyOperation(c.setBlockContentIds(t,f))}function cn(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0);if(!r[n])return;const i=[...r];i[n]={...r[n],aggregate:o},e.applyOperation(c.updateBlockProps(t,{columns:i}))}function ft(e,t,n){return t.contentIds.map(o=>{const s=e.getBlock(o).contentIds[n],r=e.getBlock(s);return{cellId:s,run:e.getRun(r.contentIds[0])}})}function ol(e,t,n,o){const l=ft(e,t,n),s=[],r=new Map;for(const{run:d}of l){const f=Se(d,o).trim();if(!f||r.has(f))continue;const m={value:c.genId(),label:f};r.set(f,m),s.push(m)}const i=l.map(({cellId:d,run:f})=>{const m=Se(f,o).trim(),p=r.get(m);return{cellId:d,run:{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(p==null?void 0:p.value)??"",selectedLabel:(p==null?void 0:p.label)??""}}}});return{options:s,newRuns:i}}function un(e,t,n,o,l){const s=e.getBlock(t),r=e.getBlock(s.contentIds[0]),i=J(s,r?r.contentIds.length:0),d=i[n];if(!d||d.type===o)return;const f=[...i];if(o==="select"){const{options:p,newRuns:h}=ol(e,s,n,l);f[n]={...d,type:o,options:p};const k=[c.updateBlockProps(t,{columns:f})];for(const{cellId:x,run:b}of h)k.push(c.setBlockRuns(x,[b]));he(e,k);return}f[n]={...d,type:o};const m=[c.updateBlockProps(t,{columns:f})];for(const{cellId:p,run:h}of ft(e,s,n)){if(!h)continue;const k=Jt(h,o,l);m.push(c.setBlockRuns(p,[k]))}he(e,m)}function Ee(e,t,n,o){var p,h;const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0),i=r[n];if(!i)return;const d=[...r];d[n]={...i,options:o};const f=[c.updateBlockProps(t,{columns:d})],m=new Map(o.map(k=>[k.value,k]));for(const{run:k}of ft(e,l,n)){if(!k||k.type!=="tableSelect")continue;const x=((p=k.data)==null?void 0:p.selectedValue)??"",b=m.get(x),I=b?x:"",B=b?b.label:"";(I!==x||B!==(((h=k.data)==null?void 0:h.selectedLabel)??""))&&f.push(c.updateRun(k.id,{data:{selectedValue:I,selectedLabel:B}}))}he(e,f)}const ll="$fieldTypes";function dn(){const e=c.useEditorStore(),t=u.useCallback(o=>e.subscribe(ll,o),[e]),n=u.useCallback(()=>e.getFieldTypes(),[e]);return u.useSyncExternalStore(t,n)}function vt(){if(typeof window>"u"||!window.visualViewport)return 0;const e=window.visualViewport,t=window.innerHeight-(e.height+e.offsetTop);return t>0?Math.round(t):0}function pn(){const[e,t]=u.useState(vt);return u.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,o=()=>t(vt());return o(),n.addEventListener("resize",o),n.addEventListener("scroll",o),()=>{n.removeEventListener("resize",o),n.removeEventListener("scroll",o)}},[]),e}const sl=280,Tt=220,rl=32,wt=6;function al(e,t){return t?e.label.toLowerCase().includes(t.toLowerCase()):!0}function ge({value:e,options:t,onChange:n,placeholder:o="Select…",ariaLabel:l,className:s="",variant:r="default",selectedLabel:i,selectedColor:d,onManageOptions:f,manageOptionsLabel:m="Manage options…",mention:p=!1,autoOpen:h=!1}){var Be,ve;const[k,x]=u.useState(!1),[b,I]=u.useState(""),[B,g]=u.useState(0),[y,w]=u.useState(null),j=pn(),[O,$]=u.useState([]),[S,L]=u.useState(!1),[_,T]=u.useState(!1),A=u.useRef(null),M=u.useRef(null),D=u.useRef(null),E=u.useRef(null),P=u.useRef(null),z=u.useRef(null),G=u.useMemo(()=>[A,D],[]),U=r==="tag",F=typeof t=="function",[V,ne]=u.useState(rl),[Z,X]=u.useState(0),se=F?void 0:t.find(R=>R.value===e),ee=e?se??(i?{label:i,color:d}:void 0):void 0,Q=u.useMemo(()=>F?O:t.filter(R=>al(R,b)),[F,O,t,b]),fe=Math.max(0,(Q.length-1)*V),le=Math.min(Z,fe),W=Q.length?Math.max(0,Math.floor(le/V)-wt):0,Pe=Math.ceil(Tt/V)+wt*2,Ce=Math.min(Q.length,W+Pe),He=Q.slice(W,Ce),N=W*V,K=Math.max(0,(Q.length-Ce)*V);u.useLayoutEffect(()=>{var Y;const R=(Y=z.current)==null?void 0:Y.getBoundingClientRect().height;R&&Math.abs(R-V)>.5&&ne(R)}),u.useEffect(()=>{if(!F||!k)return;let R=!1;L(!0),T(!1);const Y=setTimeout(()=>{Promise.resolve(t(b)).then(oe=>{R||($(oe??[]),L(!1))}).catch(()=>{R||($([]),L(!1),T(!0))})},250);return()=>{R=!0,clearTimeout(Y)}},[F,k,t,b]);const H=u.useCallback(()=>x(!1),[]);v.useOutsideClickAndEscape(G,k,H);const q=ae.useHorizontalAutoAdjustedLeft(D,k,y==null?void 0:y.left),re=u.useCallback(()=>{var R;w(((R=M.current)==null?void 0:R.getBoundingClientRect())??null),I(""),g(0),X(0),x(!0)},[]);u.useEffect(()=>{h&&re()},[]),u.useEffect(()=>{var R;k&&((R=E.current)==null||R.focus())},[k,q]),u.useEffect(()=>{const R=P.current;if(!R)return;const Y=B*V,oe=Y+V,Te=R.scrollTop,we=R.clientHeight||Tt,Ye=Te+we;let Re=null;Y<Te?Re=Y:oe>Ye&&(Re=oe-we),Re!==null&&(R.scrollTop=Re,X(Re))},[B,V]);const xe=u.useCallback(R=>{var Y;n(R.value,R),H(),(Y=M.current)==null||Y.focus()},[n,H]),_e=u.useCallback(R=>{var Y;R.key==="ArrowDown"?(R.preventDefault(),g(oe=>Math.min(oe+1,Math.max(Q.length-1,0)))):R.key==="ArrowUp"?(R.preventDefault(),g(oe=>Math.max(oe-1,0))):R.key==="Enter"?(R.preventDefault(),Q[B]&&xe(Q[B])):R.key==="Escape"&&(R.preventDefault(),H(),(Y=M.current)==null||Y.focus())},[Q,B,xe,H]);return a.jsxs("span",{className:`be-select ${s}`.trim(),ref:A,children:[a.jsx("button",{type:"button",ref:M,className:`be-select-trigger${U?" be-select-trigger-tag":""}${p?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":k,"aria-label":l,onClick:()=>k?H():re(),children:U?ee?a.jsx("span",{className:`be-select-tag${p?" be-select-tag-mention":""}`,style:p?void 0:{background:(Be=ee.color)==null?void 0:Be.bg,color:(ve=ee.color)==null?void 0:ve.text},children:p?`@${ee.label}`:ee.label}):a.jsx("span",{className:"be-select-value be-select-value-placeholder",children:o}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-select-value",children:ee?ee.label:o}),a.jsx(c.ChevronDownIcon,{size:14,className:"be-select-chevron"})]})}),k&&y&&q!=null&&be.createPortal(a.jsxs("div",{ref:D,className:"be-select-popover",style:{position:"fixed",left:q,minWidth:y.width,...y.bottom+sl>window.innerHeight-j?{bottom:window.innerHeight-y.top+4}:{top:y.bottom+4}},children:[a.jsx("input",{ref:E,type:"text",className:"be-select-search",value:b,onChange:R=>{I(R.target.value),g(0)},onKeyDown:_e,placeholder:"Search…","aria-label":l?`Search ${l}`:"Search options"}),a.jsxs("div",{className:"be-select-options",role:"listbox",ref:P,onScroll:R=>X(R.currentTarget.scrollTop),children:[F&&S&&a.jsx("div",{className:"be-select-empty",children:"Loading…"}),F&&!S&&_&&a.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!S&&!_&&Q.length===0&&a.jsx("div",{className:"be-select-empty",children:"No results"}),!S&&!_&&Q.length>0&&a.jsxs(a.Fragment,{children:[N>0&&a.jsx("div",{style:{height:N},"aria-hidden":"true"}),He.map((R,Y)=>{var Te,we;const oe=W+Y;return a.jsx("div",{ref:Y===0?z:void 0,role:"option","aria-selected":R.value===e,className:`be-select-option${oe===B?" be-select-option-active":""}${R.value===e?" be-select-option-selected":""}`,onMouseDown:Ye=>{Ye.preventDefault(),xe(R)},onMouseEnter:()=>g(oe),children:U?a.jsx("span",{className:"be-select-tag",style:{background:(Te=R.color)==null?void 0:Te.bg,color:(we=R.color)==null?void 0:we.text},children:R.label}):R.label},R.value)}),K>0&&a.jsx("div",{style:{height:K},"aria-hidden":"true"})]})]}),f&&a.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:R=>{R.preventDefault(),H(),f()},children:m})]}),document.body)]})}const Fe=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function ze(e){return Fe[(e%Fe.length+Fe.length)%Fe.length]}const cl={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},il=Zt.map(e=>({value:e,label:en[e]})),ul=Yt.map(e=>({value:e,label:cl[e]})),Je=800;function dl({tableId:e,colIndex:t}){const n=c.useEditorStore(),o=dn(),{openCreate:l}=c.useFieldTypeEditor(),s=u.useCallback(r=>{const i=n.getFieldType(r);i&&Ee(n,e,t,i.options??[])},[n,e,t]);return a.jsxs("div",{className:"be-table-header-menu-field-type",children:[o.length>0&&a.jsx(ge,{value:"",options:o.map(r=>({value:r.id,label:r.label})),onChange:s,placeholder:"Copy options from…",ariaLabel:"Copy options from an existing field type"}),a.jsx("button",{type:"button",className:"be-table-header-menu-item",onClick:l,children:"+ New field type"})]})}function pl({tableId:e,colIndex:t,options:n}){const o=c.useEditorStore(),[l,s]=u.useState(""),r=u.useCallback((f,m)=>{Ee(o,e,t,n.map(p=>p.value===f?{...p,label:m}:p))},[o,e,t,n]),i=u.useCallback(f=>Ee(o,e,t,n.filter(m=>m.value!==f)),[o,e,t,n]),d=u.useCallback(()=>{const f=l.trim();s(""),f&&Ee(o,e,t,[...n,{value:c.genId(),label:f,color:ze(n.length)}])},[o,e,t,n,l]);return a.jsxs("div",{className:"be-table-header-menu-options",children:[a.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((f,m)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(f.color??ze(m)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:f.label,onChange:p=>r(f.value,p.target.value),"aria-label":`Rename option ${f.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(f.value),"aria-label":`Remove option ${f.label}`,children:a.jsx(c.XIcon,{size:14})})]},f.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:l,onChange:f=>s(f.target.value),placeholder:"New option…",onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),d())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:d,"aria-label":"Add option",children:"+"})]})]})}function fl({tableId:e,column:t,colIndex:n,colCount:o,filterValue:l,onFilterChange:s}){const r=c.useEditorStore(),i=c.useInlineRegistry(),[d,f]=u.useState(!1),[m,p]=u.useState(null),[h,k]=u.useState(null),x=u.useRef(null),b=u.useRef(null),I=u.useRef(null),B=u.useMemo(()=>[x,b],[]),g=u.useCallback(()=>f(!1),[]);v.useOutsideClickAndEscape(B,d,g),Ve(b,d,g,x);const y=ae.useAutoAdjustedRightLeft(b,d,m==null?void 0:m.right),w=u.useCallback(()=>{var E;p(((E=I.current)==null?void 0:E.getBoundingClientRect())??null),f(!0)},[]),j=u.useCallback(E=>an(r,e,n,E.target.value),[r,e,n]),O=u.useCallback(()=>{ot(r,e,n-1),g()},[r,e,n,g]),$=u.useCallback(()=>{ot(r,e,n),g()},[r,e,n,g]),S=u.useCallback(()=>{rn(r,e,n),g()},[r,e,n,g]),L=u.useCallback(E=>un(r,e,n,E,i),[r,e,n,i]),_=u.useCallback(()=>{st(r,e,n,"asc",i),g()},[r,e,n,i,g]),T=u.useCallback(()=>{st(r,e,n,"desc",i),g()},[r,e,n,i,g]),A=u.useCallback(E=>cn(r,e,n,E),[r,e,n]),M=u.useCallback(E=>{var Z;E.preventDefault();const P=(Z=I.current)==null?void 0:Z.closest("table"),z=P==null?void 0:P.querySelector(`col[data-col-index="${n}"]`);if(!z)return;const G=I.current.getBoundingClientRect().width,U=E.clientX,F=X=>Math.max(me,Math.round(G+(X.clientX-U))),V=X=>{const se=F(X);z.style.width=`${se}px`,k(se)},ne=X=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",ne),lt(r,e,n,F(X)),k(null)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",ne)},[r,e,n]),D=u.useCallback(E=>{const P=t.width??me,z=E.shiftKey?1:16;let G;if(E.key==="ArrowLeft"||E.key==="ArrowDown")G=Math.max(me,P-z);else if(E.key==="ArrowRight"||E.key==="ArrowUp")G=Math.min(Je,P+z);else if(E.key==="Home")G=me;else if(E.key==="End")G=Je;else return;E.preventDefault(),lt(r,e,n,G)},[r,e,n,t.width]);return a.jsxs("th",{ref:I,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[a.jsx("input",{className:"be-table-header-label",value:t.label,onChange:j,"aria-label":`Column ${n+1} name`}),a.jsx("button",{ref:x,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":d,onClick:()=>d?g():w(),children:"⋮"}),a.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:M,onKeyDown:D,role:"slider",tabIndex:0,"aria-label":`Resize column ${n+1}`,"aria-valuemin":me,"aria-valuemax":Je,"aria-valuenow":h??t.width}),d&&m&&y!=null&&be.createPortal(a.jsxs("div",{ref:b,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:m.bottom+4,left:y,transform:"translateX(-100%)"},children:[a.jsxs("div",{className:"be-table-header-menu-type",children:[a.jsx("span",{id:`be-table-col-type-${t.id}`,children:"Type"}),a.jsx(ge,{value:t.type,options:ul,onChange:L,ariaLabel:"Column type",className:""})]}),t.type==="select"&&a.jsxs(a.Fragment,{children:[a.jsx(dl,{tableId:e,colIndex:n}),a.jsx(pl,{tableId:e,colIndex:n,options:t.options??[]})]}),a.jsxs("div",{className:"be-table-header-menu-sort",children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:_,children:[a.jsx(c.ArrowUpIcon,{size:13})," Sort ascending"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:T,children:[a.jsx(c.ArrowDownIcon,{size:13})," Sort descending"]})]}),a.jsxs("label",{className:"be-table-header-menu-filter",children:[a.jsx("span",{children:"Filter"}),a.jsx("input",{type:"text",className:"be-table-header-menu-filter-input",placeholder:"Rows containing…",value:l??"",onChange:E=>s(t.id,E.target.value),"aria-label":`Filter column ${n+1}`})]}),a.jsxs("div",{className:"be-table-header-menu-type be-table-header-menu-aggregate",children:[a.jsx("span",{id:`be-table-col-aggregate-${t.id}`,children:"Footer"}),a.jsx(ge,{value:t.aggregate??"none",options:il,onChange:A,ariaLabel:"Column footer aggregate",className:""})]}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:O,children:"Insert column left"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:$,children:"Insert column right"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:S,disabled:o<=1,children:"Delete column"})]}),document.body)]})}function fn({tableId:e,columns:t,filters:n,onFilterChange:o}){return a.jsx("thead",{children:a.jsxs("tr",{className:"be-table-header-row",children:[t.map((l,s)=>a.jsx(fl,{tableId:e,column:l,colIndex:s,colCount:t.length,filterValue:n==null?void 0:n[l.id],onFilterChange:o},l.id)),a.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function ml({id:e}){var b;const t=c.useEditorStore(),n=c.useInlineRegistry(),o=v.useBlock(e),[l,s]=u.useState({}),r=u.useCallback((I,B)=>{s(g=>B?{...g,[I]:B}:Object.fromEntries(Object.entries(g).filter(([y])=>y!==I)))},[]),i=u.useCallback(()=>{var B;const I=(B=o==null?void 0:o.contentIds)==null?void 0:B[o.contentIds.length-1];I&&ln(t,I)},[t,o]),d=c.useBlockClassName("be-table-wrapper",o),f=u.useMemo(()=>Object.entries(l).filter(([,I])=>I),[l]),m=u.useCallback((I,B)=>{const g=t.getBlock(I),y=g&&t.getBlock(g.contentIds[B]);return y?t.getRun(y.contentIds[0]):null},[t]);if(!o)return null;const p=t.getBlock(o.contentIds[0]),h=J(o,((b=p==null?void 0:p.contentIds)==null?void 0:b.length)??0),k=f.length===0?o.contentIds:o.contentIds.filter(I=>f.every(([B,g])=>{const y=h.findIndex(j=>j.id===B);return y===-1?!0:Se(m(I,y),n).toLowerCase().includes(g.toLowerCase())})),x=h.some(I=>I.aggregate&&I.aggregate!=="none");return a.jsx("div",{className:"be-table-scroll",children:a.jsxs("div",{className:d,"data-block-id":e,children:[a.jsxs("table",{className:"be-table",children:[a.jsxs("colgroup",{children:[h.map((I,B)=>a.jsx("col",{"data-col-index":B,style:{width:I.width}},I.id)),a.jsx("col",{className:"be-table-header-spacer-col"})]}),a.jsx(fn,{tableId:e,columns:h,filters:l,onFilterChange:r}),a.jsx("tbody",{children:a.jsx(pe,{parentId:e,filterIds:k})}),x&&a.jsx("tfoot",{children:a.jsxs("tr",{className:"be-table-footer-row",children:[h.map((I,B)=>{const g=k.map(w=>m(w,B)),y=tn(g,I.type,I.aggregate,n);return a.jsx("td",{className:"be-table-footer-cell",children:y!=null&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-table-footer-label",children:nl[I.aggregate]}),nn(y)]})},I.id)}),a.jsx("td",{className:"be-table-footer-spacer","aria-hidden":"true"})]})})]}),a.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:i,children:[a.jsx(c.PlusIcon,{size:14})," Add row"]})]})})}function hl({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),o=c.useBlockClassName("be-table-row",n),l=u.useCallback(()=>sn(t,e),[t,e]);return a.jsxs("tr",{className:o,"data-block-id":e,children:[a.jsx(pe,{parentId:e}),a.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:a.jsx("button",{type:"button",className:"be-table-delete-row",onClick:l,"aria-label":"Delete row",title:"Delete row",children:a.jsx(c.XIcon,{size:14})})})]})}function mn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=e.getBlock(o.parentId);return{table:l,row:o,rowIndex:l.contentIds.indexOf(o.id),colIndex:o.contentIds.indexOf(t)}}function gl(e,t,n){const{table:o,row:l,rowIndex:s,colIndex:r}=mn(e,t);if(n==="left"||n==="right"){const m=n==="right"?1:-1,p=r+m;if(p>=0&&p<l.contentIds.length)return l.contentIds[p];const h=s+m;if(h<0||h>=o.contentIds.length)return null;const k=e.getBlock(o.contentIds[h]),x=n==="right"?0:k.contentIds.length-1;return k.contentIds[x]}const d=s+(n==="down"?1:-1);if(d<0||d>=o.contentIds.length)return null;const f=e.getBlock(o.contentIds[d]);return f.contentIds[r]??f.contentIds[f.contentIds.length-1]??null}function bl(e,t){const n=C.resolveAdjacentFocusTarget(e,t,"down");if(n){C.focusRunEnd(n);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function je(e,t,n){var l;const o=gl(e,t,n);if(o){const s=e.getBlock(o),r=(l=s==null?void 0:s.contentIds)==null?void 0:l[0];r&&C.focusRunEnd(r);return}if(n==="right"){const{table:s}=mn(e,t);bl(e,s.id)}}function kl({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),o=u.useCallback(()=>je(t,e,"right"),[t,e]),l=u.useCallback(()=>je(t,e,"left"),[t,e]),s=u.useCallback(()=>je(t,e,"up"),[t,e]),r=u.useCallback(()=>je(t,e,"down"),[t,e]),i=u.useCallback(()=>je(t,e,"down"),[t,e]),d=c.useBlockClassName("be-table-cell",n);if(!n)return null;const f=ce(t,n);return a.jsx("td",{className:d,"data-block-id":e,dir:f,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:f,onTab:o,onShiftTab:l,onArrowUp:s,onArrowDown:r,onEnter:i})})}function yl(e,t){const n=c.genId(),o=[],l=[],s=[];for(const r of t){const i=We(n,r);o.push(i.block),l.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:e,contentIds:s,props:{}},blocks:o,runs:l}}function Il({rows:e=2,cols:t=2}={}){return function(o){const l=c.genId(),s=pt(t),r=[],i=[],d=[];for(let m=0;m<e;m+=1){const p=yl(l,s);r.push(p.block,...p.blocks),i.push(...p.runs),d.push(p.block.id)}return{block:{id:l,type:"table",parentId:o,contentIds:d,props:{columns:s}},runs:i,subtreeBlocks:r}}}function Cl(e,t){return`<td>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</td>`}function xl(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Bl(e,t){return v.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t).replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function vl(e,t){if(e.tagName!=="TD"&&e.tagName!=="TH")return null;const n=ie(e,t);return{block:{id:c.genId(),type:"tableCell",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}function Tl(e,t){return`<tr>${e.contentIds.map(o=>{const l=t.store.getBlock(o);return t.registry.get(l.type).toHTML(l,t)}).join("")}</tr>`}function wl(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(" ")}function Rl(e,t){return`| ${e.contentIds.map(o=>{const l=t.store.getBlock(o);return t.registry.get(l.type).toMarkdown(l,t)}).join(" | ")} |`}function Al(e,t){if(e.tagName!=="TR")return null;const n=[...e.children].filter(d=>d.tagName==="TD"||d.tagName==="TH"),o=c.genId(),l=[],s=[],r=[];for(const d of n){const f=t.registry.get("tableCell").fromHTML(d,t);f&&(f.block.parentId=o,l.push(f.block),s.push(...f.runs),r.push(f.block.id))}return{block:{id:o,type:"tableRow",parentId:null,contentIds:r,props:{}},runs:s,subtreeBlocks:l}}function jl(e,t){var r;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=J(e,((r=n==null?void 0:n.contentIds)==null?void 0:r.length)??0),l=o.length?`<thead><tr>${o.map(i=>`<th>${v.escapeHTML(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=e.contentIds.map(i=>{const d=t.store.getBlock(i);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<table>${l}<tbody>${s}</tbody></table>`}function Ll(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(`
6
+ `)}function Nl(e,t){var i;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=J(e,((i=n==null?void 0:n.contentIds)==null?void 0:i.length)??0);if(o.length===0)return"";const l=`| ${o.map(d=>(d.label??"").replace(/\|/g,"\\|")).join(" | ")} |`,s=`| ${o.map(()=>"---").join(" | ")} |`,r=e.contentIds.map(d=>{const f=t.store.getBlock(d);return t.registry.get(f.type).toMarkdown(f,t)}).join(`
7
+ `);return r?`${l}
8
+ ${s}
9
+ ${r}`:`${l}
10
+ ${s}`}function El(e,t){if(e.tagName!=="TABLE")return null;const n=e.querySelector("thead tr"),o=e.querySelector("tbody")?[...e.querySelectorAll("tbody tr")]:[...e.querySelectorAll("tr")].filter(m=>m!==n),l=c.genId(),s=[],r=[],i=[];for(const m of o){const p=t.registry.get("tableRow").fromHTML(m,t);if(p){p.block.parentId=l;for(const h of p.subtreeBlocks)h.parentId=p.block.id;s.push(p.block,...p.subtreeBlocks),r.push(...p.runs),i.push(p.block.id)}}const d={};if(n){const m=[...n.children].filter(p=>p.tagName==="TH"||p.tagName==="TD");d.columns=m.map(p=>({id:c.genId(),label:p.textContent??""}))}return{block:{id:l,type:"table",parentId:null,contentIds:i,props:d},runs:r,subtreeBlocks:s}}const hn=v.defineBlock({name:"tableCell",contentModel:"runs",component:kl,defaultProps:{},toHTML:Cl,toPlainText:xl,toMarkdown:Bl,fromHTML:vl}),gn=v.defineBlock({name:"tableRow",contentModel:"blocks",component:hl,defaultProps:{},toHTML:Tl,toPlainText:wl,toMarkdown:Rl,fromHTML:Al}),bn=v.defineBlock({name:"table",contentModel:"blocks",component:ml,defaultProps:{},toHTML:jl,toPlainText:Ll,toMarkdown:Nl,fromHTML:El,slashCommand:{label:"Table",icon:c.TableIcon,keywords:["table","grid"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Il({rows:2,cols:2}))}});function Sl({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-layout",t);return a.jsx("div",{className:n,"data-block-id":e,style:{display:"flex",gap:"1em"},children:a.jsx(pe,{parentId:e})})}function Ml({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-layout-column",t);return a.jsx("div",{className:n,"data-block-id":e,children:a.jsx(pe,{parentId:e})})}function $l({columns:e=2}={}){return function(n){const o=c.genId(),l=[],s=[],r=[];for(let d=0;d<e;d+=1){const f=c.genId(),{block:m,runs:p}=C.createTextLeafBlock("paragraph")(f),h={id:f,type:"layoutColumn",parentId:o,contentIds:[m.id],props:{}};l.push(h,m),s.push(...p),r.push(f)}return{block:{id:o,type:"layout",parentId:n,contentIds:r,props:{}},runs:s,subtreeBlocks:l}}}function kn(e,t){return(n,o)=>`${e}${n.contentIds.map(l=>{const s=o.store.getBlock(l);return o.registry.get(s.type).toHTML(s,o)}).join("")}${t}`}function yn(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(`
11
+ `)}function In(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n),l=t.registry.get(o.type);return(l.toMarkdown??l.toPlainText)(o,t)}).join(`
12
+
13
+ `)}const Cn=v.defineBlock({name:"layoutColumn",contentModel:"blocks",component:Ml,defaultProps:{},toHTML:kn("<div>","</div>"),toPlainText:yn,toMarkdown:In}),xn=v.defineBlock({name:"layout",contentModel:"blocks",component:Sl,defaultProps:{},toHTML:kn('<div style="display:flex;gap:1em">',"</div>"),toPlainText:yn,toMarkdown:In,slashCommands:[2,3,4,5].map(e=>({label:`${e} columns`,icon:c.ColumnsIcon,keywords:["layout","columns","column",String(e)],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,$l({columns:e}))}))});function Ol({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-divider",t);return a.jsx("hr",{className:n,"data-block-id":e,contentEditable:!1,tabIndex:-1})}function Dl(){return function(t){return{block:{id:c.genId(),type:"divider",parentId:t,contentIds:[],props:{}},runs:[]}}}function Pl(){return"<hr />"}function Hl(){return"---"}function _l(){return"---"}function Fl(e){return e.tagName!=="HR"?null:{block:{id:c.genId(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const Bn=v.defineBlock({name:"divider",contentModel:"void",component:Ol,defaultProps:{},toHTML:Pl,toPlainText:Hl,toMarkdown:_l,fromHTML:Fl,slashCommand:{label:"Divider",icon:c.DividerIcon,keywords:["divider","hr","separator","line"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>{const s=e.getRun(n),r=(s==null?void 0:s.value)??"";e.applyOperation(c.updateRun(n,{value:r.slice(0,o)+r.slice(l)}));const i=C.insertSiblingAfter(e,t,Dl());return C.insertSiblingAfterAndFocus(e,i,C.createTextLeafBlock("paragraph")),i}}}),vn=[{value:"gray",label:"Gray"},{value:"blue",label:"Blue"},{value:"green",label:"Green"},{value:"yellow",label:"Yellow"},{value:"orange",label:"Orange"},{value:"red",label:"Red"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"}];function Ul({id:e}){var B,g;const t=c.useEditorStore(),n=v.useBlock(e),[o,l]=u.useState(!1),[s,r]=u.useState(!1),i=u.useRef(null),d=u.useRef(null),f=u.useMemo(()=>[i,d],[]),m=u.useCallback(()=>r(!1),[]);v.useOutsideClickAndEscape(f,s,m);const p=((B=n==null?void 0:n.props)==null?void 0:B.icon)??ke,h=((g=n==null?void 0:n.props)==null?void 0:g.color)??Pt,k=u.useCallback(y=>{const w=y.target.value.trim();w&&t.applyOperation(c.updateBlockProps(e,{icon:w})),l(!1)},[t,e]),x=u.useCallback(y=>{y.key==="Enter"&&y.currentTarget.blur(),y.key==="Escape"&&l(!1)},[]),b=u.useCallback(y=>{t.applyOperation(c.updateBlockProps(e,{color:y})),r(!1)},[t,e]),I=c.useBlockClassName("be-callout",n);return n?a.jsxs("div",{className:I,"data-block-id":e,"data-color":h,children:[a.jsx("div",{className:"be-callout-icon-wrap",children:o?a.jsx("input",{type:"text",className:"be-callout-icon-input",defaultValue:p,autoFocus:!0,onBlur:k,onKeyDown:x,"aria-label":"Callout icon (paste or type an emoji)"}):a.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>l(!0),"aria-label":"Change callout icon",title:"Change icon",children:p})}),a.jsx("div",{className:"be-callout-content",children:a.jsx(pe,{parentId:e})}),a.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[a.jsx("button",{ref:i,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":s,title:"Callout color",onClick:()=>r(y=>!y),children:a.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&a.jsx("div",{ref:d,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:vn.map(y=>a.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${y.value}${y.value===h?" be-callout-color-option-active":""}`,title:y.label,"aria-label":y.label,onClick:()=>b(y.value)},y.value))})]})]}):null}function Kl(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toHTML(o,t)}).join("")}function zl(e,t){var o;const n=((o=e.props)==null?void 0:o.icon)??ke;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${Kl(e,t)}</div></div>`}function Gl(e,t){var l;const n=((l=e.props)==null?void 0:l.icon)??ke,o=e.contentIds.map(s=>{const r=t.store.getBlock(s);return t.registry.get(r.type).toPlainText(r,t)}).join(`
14
+ `);return`${n} ${o}`}function Vl(e,t){var l;const n=((l=e.props)==null?void 0:l.icon)??ke;return e.contentIds.map(s=>{const r=t.store.getBlock(s),i=t.registry.get(r.type);return(i.toMarkdown??i.toPlainText)(r,t)}).join(`
15
+ `).split(`
16
+ `).map((s,r)=>`> ${r===0?`${n} `:""}${s}`).join(`
17
+ `)}const Tn=v.defineBlock({name:"callout",contentModel:"blocks",component:Ul,defaultProps:{icon:ke},toHTML:zl,toPlainText:Gl,toMarkdown:Vl,slashCommand:{label:"Callout",icon:c.CalloutIcon,keywords:["callout","aside","note","info","tip","warning"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ao())}});function ql({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),s=u.useCallback(()=>{const p=Oe(t,e);Ie(t,p,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=c.useBlockClassName("be-blockquote",n);if(!n)return null;const f=te(t,n.contentIds),m=ce(t,n);return a.jsx("blockquote",{className:d,"data-block-id":e,"data-empty":f?"":void 0,"data-placeholder":"Empty quote",dir:m,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:m,onEnter:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})}function Wl(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</p>`}function Ql(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Yl(e,t){return`> ${v.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t)}`}function Xl(e,t){if(e.tagName!=="BLOCKQUOTE")return null;const n=ie(e,t);return{block:{id:c.genId(),type:"blockquote",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}const wn=v.defineBlock({name:"blockquote",contentModel:"runs",component:ql,defaultProps:{},toHTML:Wl,toPlainText:Ql,toMarkdown:Yl,fromHTML:Xl,slashCommand:{label:"Quote",icon:c.QuoteIcon,keywords:["quote","blockquote","citation"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("blockquote"))}}),Rn=["plaintext","javascript","python","html","css","json","bash","sql"],Jl=Rn.map(e=>({value:e,label:e}));function Rt(e,t,n){const o=C.resolveCollapsedCaret();if(!o||o.blockId!==t)return;const l=e.getRun(o.runId);if(!l||l.type!=="text")return;const s=l.value??"",r=s.slice(0,o.offset)+n+s.slice(o.offset);e.applyOperation(c.updateRun(l.id,{value:r})),C.focusRunAtOffset(l.id,o.offset+n.length)}function Zl({id:e}){var b,I;const t=c.useEditorStore(),n=v.useBlock(e),o=c.useShowLineNumbers(),l=u.useCallback(()=>Rt(t,e,`
18
+ `),[t,e]),s=u.useCallback(()=>Rt(t,e," "),[t,e]),r=u.useCallback(()=>{var w;const B=Oe(t,e);if(!B||B===e)return;const g=t.getBlock(B),y=(w=g==null?void 0:g.contentIds)==null?void 0:w[g.contentIds.length-1];y&&C.focusRunEnd(y)},[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),d=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),f=u.useCallback(B=>t.applyOperation(c.updateBlockProps(e,{language:B})),[t,e]),m=u.useCallback(()=>dt(t,e),[t,e]),p=c.useBlockClassName("be-code-block",n);if(!n)return null;const h=((b=n.props)==null?void 0:b.language)??"plaintext",k=te(t,n.contentIds),x=o?(((I=n.contentIds.map(B=>{var g;return((g=t.getRun(B))==null?void 0:g.value)??""}).join("").match(/\n/g))==null?void 0:I.length)??0)+1:0;return a.jsxs("div",{className:p,"data-block-id":e,children:[a.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[a.jsx(ge,{className:"be-code-block-language",value:h,options:Jl,onChange:f,ariaLabel:"Code language"}),a.jsx("button",{type:"button",className:"be-code-block-delete",onClick:m,"aria-label":"Delete code block",title:"Delete code block",children:a.jsx(c.TrashIcon,{size:14})})]}),a.jsxs("div",{className:"be-code-block-body",children:[o&&a.jsx("div",{className:"be-code-block-gutter",contentEditable:!1,"aria-hidden":"true",children:Array.from({length:x},(B,g)=>a.jsx("span",{children:g+1},g))}),a.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:a.jsx("code",{"data-empty":k?"":void 0,"data-placeholder":"Empty code block",children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:"ltr",onEnter:l,onTab:s,onBackspaceAtStart:r,onArrowUp:i,onArrowDown:d})})})]})]})}function es(e,t){var s;const n=e.contentIds.map(r=>t.store.getRun(r)),o=(s=e.props)==null?void 0:s.language;return`<pre><code${o&&o!=="plaintext"?` data-language="${v.escapeHTML(o)}"`:""}>${n.map(r=>v.runToHTML(r,t)).join("")}</code></pre>`}function ts(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function ns(e,t){var s;const n=(s=e.props)==null?void 0:s.language,o=n&&n!=="plaintext"?n:"",l=e.contentIds.map(r=>{var i;return((i=t.store.getRun(r))==null?void 0:i.value)??""}).join("");return`\`\`\`${o}
19
+ ${l}
20
+ \`\`\``}function os(e,t){var r;if(e.tagName!=="PRE")return null;const n=e.querySelector("code")??e,o=(r=n.getAttribute)==null?void 0:r.call(n,"data-language"),l=c.genId();return{block:{id:c.genId(),type:"code",parentId:null,contentIds:[l],props:o?{language:o}:{}},runs:[{id:l,type:"text",value:n.textContent??"",marks:{}}]}}const An=v.defineBlock({name:"code",contentModel:"runs",component:Zl,defaultProps:{language:"plaintext"},toHTML:es,toPlainText:ts,toMarkdown:ns,fromHTML:os,slashCommand:{label:"Code",icon:c.CodeIcon,keywords:["code","codeblock","snippet","pre"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("code"))}});function ls(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function ss(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const o=e.getBlock(n[0]);return!!o&&o.type==="paragraph"&&te(e,o.contentIds)}function Ue(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function rs(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.props.titleRunIds??[],r=ls(e,s)&&ss(e,n);if(l<=0){if(!r)return null;if(o.contentIds.length>1)return Ue(e,[c.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:f,runs:m}=C.createTextLeafBlock("paragraph")(o.id);return Ue(e,[c.insertBlock(f,o.id,l,{blocks:[f],runs:m}),c.removeBlock(t)]),{focusBlockId:f.id,needsRefocus:!0}}const i=o.contentIds[l-1],d=e.getBlock(i);return r?(Ue(e,[c.removeBlock(t)]),{focusBlockId:i,needsRefocus:!0}):Me(e,d)?(Ue(e,[c.removeBlock(i)]),{focusBlockId:t,needsRefocus:!1}):null}function as(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function cs({id:e}){var I;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{var w,j;const B=((w=n==null?void 0:n.props)==null?void 0:w.titleRunIds)??[],g=(((j=n==null?void 0:n.contentIds)==null?void 0:j.length)??0)>0,y=C.createTextLeafBlock("paragraph");g?C.insertFirstChildSplitAtCaretAndFocus(t,e,B,y):C.insertSiblingSplitAtCaretAndFocus(t,e,B,y)},[t,e,n]),s=u.useCallback(()=>{const B=rs(t,e);!B||!B.needsRefocus||Ie(t,B.focusBlockId,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=u.useCallback(()=>{var g,y;if(!((((g=n==null?void 0:n.contentIds)==null?void 0:g.length)??0)>0)){const{block:w,runs:j}=C.createTextLeafBlock("paragraph")(e);as(t,[c.insertBlock(w,e,0,{blocks:[w],runs:j}),c.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(w.contentIds[0]);return}t.applyOperation(c.updateBlockProps(e,{collapsed:!((y=n==null?void 0:n.props)!=null&&y.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(I=n==null?void 0:n.props)==null?void 0:I.collapsed]),f=c.useBlockClassName("be-toggle-heading",n);if(!n)return null;const{level:m=2,collapsed:p,titleRunIds:h=[]}=n.props,k=n.contentIds.length>0,x=`h${m}`,b=ce(t,n);return a.jsxs("div",{className:f,"data-block-id":e,dir:b,children:[a.jsxs("div",{className:"be-toggle-heading-row",children:[a.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:d,"aria-expanded":!p,"aria-label":k?p?"Expand section":"Collapse section":"Add content to section",children:p?a.jsx(c.ChevronRightIcon,{}):a.jsx(c.ChevronDownIcon,{})}),a.jsx(x,{className:`be-heading be-heading-${m} be-toggle-heading-title`,"data-empty":te(t,h)?"":void 0,"data-placeholder":`Toggle heading ${m}`,children:a.jsx(ue,{blockId:e,runIds:h,dir:b,onEnter:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})]}),!p&&a.jsx("div",{className:"be-toggle-heading-children",children:a.jsx(pe,{parentId:e})})]})}function is({level:e=2,collapsed:t=!1}={}){return function(o,l){const s=c.genId(),r=l!=null&&l.length?l:[{id:c.genId(),type:"text",value:"",marks:{}}],{block:i,runs:d}=C.createTextLeafBlock("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:o,contentIds:[i.id],props:{level:e,collapsed:t,titleRunIds:r.map(f=>f.id)}},runs:[...r,...d],subtreeBlocks:[i]}}}function us(e,t){const{titleRunIds:n=[],level:o=2,collapsed:l}=e.props,s=n.map(i=>v.runToHTML(t.store.getRun(i),t)).join(""),r=e.contentIds.map(i=>{const d=t.store.getBlock(i);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<details${l?"":" open"}><summary><h${o}>${s}</h${o}></summary>${r}</details>`}function ds(e,t){const{titleRunIds:n=[]}=e.props,o=n.map(s=>v.runToPlainText(t.store.getRun(s),t)).join(""),l=e.contentIds.map(s=>{const r=t.store.getBlock(s);return t.registry.get(r.type).toPlainText(r,t)}).join(`
21
+ `);return l?`${o}
22
+ ${l}`:o}function ps(e,t){const{titleRunIds:n=[],level:o=2}=e.props,l=v.runsToMarkdown(n.map(i=>t.store.getRun(i)),t),s=`${"#".repeat(Math.min(6,o))} ${l}`,r=e.contentIds.map(i=>{const d=t.store.getBlock(i),f=t.registry.get(d.type);return(f.toMarkdown??f.toPlainText)(d,t)}).join(`
23
+
24
+ `);return r?`${s}
25
+
26
+ ${r}`:s}function fs(e,t){if(e.tagName!=="DETAILS")return null;const n=[...e.children].find(p=>p.tagName==="SUMMARY"),o=n==null?void 0:n.querySelector("h1,h2,h3,h4,h5,h6"),l=o?Math.min(6,Math.max(1,Number(o.tagName[1]))):2,s=o?ie(o,t):[{id:c.genId(),type:"text",value:"",marks:{}}],r=c.genId(),i=[],d=[],f=[];for(const p of e.children){if(p===n||p.tagName!=="P")continue;const h=ie(p,t),k={id:c.genId(),type:"paragraph",parentId:r,contentIds:h.map(x=>x.id),props:{}};i.push(k),d.push(...h),f.push(k.id)}if(f.length===0){const{block:p,runs:h}=C.createTextLeafBlock("paragraph")(r);i.push(p),d.push(...h),f.push(p.id)}return{block:{id:r,type:"toggleHeading",parentId:null,contentIds:f,props:{level:l,collapsed:!e.hasAttribute("open"),titleRunIds:s.map(p=>p.id)}},runs:[...s,...d],subtreeBlocks:i}}const jn=v.defineBlock({name:"toggleHeading",contentModel:"blocks",component:cs,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:us,toPlainText:ds,toMarkdown:ps,fromHTML:fs,slashCommands:[1,2,3].map(e=>({label:`Toggle heading ${e}`,icon:c.ChevronRightIcon,keywords:["toggle","heading","collapse","section"],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,is({level:e}))}))}),Ze=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function ms(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function hs({isOpen:e,onClose:t,store:n,blockId:o}){const[l,s]=u.useState(""),[r,i]=u.useState(""),[d,f]=u.useState(Ze[0].value),[m,p]=u.useState([{key:"",value:""}]);u.useEffect(()=>{var g,y,w;if(!e)return;const b=n.getBlock(o);if(!b)return;const I=b.contentIds.map(j=>{var O;return((O=n.getRun(j))==null?void 0:O.value)??""}).join(""),B=((g=b.props)==null?void 0:g.customAttrs)??[];s(I),i(((y=b.props)==null?void 0:y.href)??""),f(((w=b.props)==null?void 0:w.color)??Ze[0].value),p([...B,{key:"",value:""}])},[e,o,n]);const h=u.useCallback((b,I)=>{p(B=>{const g=B.map((w,j)=>j===b?{...w,...I}:w),y=g[g.length-1];return(y.key.trim()||y.value.trim())&&g.push({key:"",value:""}),g})},[]),k=u.useCallback(b=>{p(I=>I.filter((B,g)=>g!==b))},[]),x=u.useCallback(()=>{const b={id:c.genId(),type:"text",value:l,marks:{}},I=m.filter(B=>B.key.trim());ms(n,[c.setBlockRuns(o,[b]),c.updateBlockProps(o,{href:r.trim(),color:d,customAttrs:I})]),t()},[n,o,l,r,d,m,t]);return a.jsxs(ae.Modal,{isOpen:e,onClose:t,title:"Edit button",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Label"}),a.jsx("input",{type:"text",value:l,onChange:b=>s(b.target.value),placeholder:"Button"})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Link URL"}),a.jsx("input",{type:"url",value:r,onChange:b=>i(b.target.value),placeholder:"https://example.com"})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Color"}),a.jsx("div",{className:"be-modal-color-row",children:Ze.map(b=>a.jsx("button",{type:"button",className:`be-modal-color-swatch${d===b.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:b.value},title:b.label,"aria-label":b.label,onClick:()=>f(b.value)},b.value))})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Custom attributes"}),m.map((b,I)=>a.jsxs("div",{className:"be-modal-attr-row",children:[a.jsx("input",{type:"text",placeholder:"name",value:b.key,onChange:B=>h(I,{key:B.target.value})}),a.jsx("input",{type:"text",placeholder:"value",value:b.value,onChange:B=>h(I,{value:B.target.value})}),(b.key||b.value)&&a.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>k(I),"aria-label":"Remove attribute",children:a.jsx(c.XIcon,{size:14})})]},I))]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:t,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:x,children:"Save"})]})]})}const gs="#2b6fd6";function bs({id:e}){var g,y,w,j;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),[l,s]=u.useState(!1),r=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),i=u.useCallback(()=>{const O=Oe(t,e);Ie(t,O,e,o)},[t,e,o]),d=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),f=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),m=u.useCallback(()=>{var $;const O=($=n==null?void 0:n.props)==null?void 0:$.href;O&&window.open(O,"_blank","noopener,noreferrer")},[(g=n==null?void 0:n.props)==null?void 0:g.href]),p=c.useBlockClassName("be-button-block",n);if(!n)return null;const h=((y=n.props)==null?void 0:y.href)??"",k=((w=n.props)==null?void 0:w.color)??gs,x=((j=n.props)==null?void 0:j.customAttrs)??[],b=te(t,n.contentIds),I={};for(const{key:O,value:$}of x)O.trim()&&(I[`data-${O.trim()}`]=$);const B=ce(t,n);return a.jsxs("div",{className:p,"data-block-id":e,dir:B,children:[a.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:k},...I,children:[a.jsx("span",{className:"be-button-block-label","data-empty":b?"":void 0,"data-placeholder":"Button",children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:B,onEnter:r,onBackspaceAtStart:i,onArrowUp:d,onArrowDown:f})}),a.jsx("button",{type:"button",className:"be-button-block-open",onClick:m,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),a.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),a.jsx(hs,{isOpen:l,onClose:()=>s(!1),store:t,blockId:e})]})}function ks({href:e="",label:t="Button",color:n="",customAttrs:o=[]}={}){return function(s,r){const i=c.genId(),d=r!=null&&r.length?r:[{id:c.genId(),type:"text",value:t,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:d.map(f=>f.id),props:{href:e,color:n,customAttrs:o}},runs:d}}}const Ln="be-button-block-link";function ys(e,t){var d,f,m;const n=e.contentIds.map(p=>t.store.getRun(p)),o=((d=e.props)==null?void 0:d.href)??"",l=(f=e.props)==null?void 0:f.color,s=l?` style="background-color:${v.escapeAttr(l)}"`:"",i=(((m=e.props)==null?void 0:m.customAttrs)??[]).filter(p=>{var h;return(h=p.key)==null?void 0:h.trim()}).map(p=>` data-${v.escapeAttr(p.key.trim())}="${v.escapeAttr(p.value??"")}"`).join("");return`<a class="${Ln}" href="${v.escapeAttr(o)}"${s}${i}>${n.map(p=>v.runToHTML(p,t)).join("")}</a>`}function Is(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Cs(e,t){var l;const n=((l=e.props)==null?void 0:l.href)??"";return`[${v.runsToMarkdown(e.contentIds.map(s=>t.store.getRun(s)),t)||n}](${n})`}function xs(e,t){var s;if(e.tagName!=="A"||!e.classList.contains(Ln))return null;const n=ie(e,t),o=[];for(const r of e.attributes)r.name.startsWith("data-")&&o.push({key:r.name.slice(5),value:r.value});return{block:{id:c.genId(),type:"button",parentId:null,contentIds:n.map(r=>r.id),props:{href:e.getAttribute("href")??"",color:((s=e.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:o}},runs:n}}const Nn=v.defineBlock({name:"button",contentModel:"runs",component:bs,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:ys,toPlainText:Is,toMarkdown:Cs,fromHTML:xs,slashCommand:{label:"Button",icon:c.ButtonIcon,keywords:["button","link","cta","action"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,ks())}});function Bs(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>n(o.error),o.readAsDataURL(e)})}function At(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function vs(e){return e!=null&&e.startsWith("image/")?"image":e!=null&&e.startsWith("video/")?"video":e!=null&&e.startsWith("audio/")?"audio":"file"}async function En(e,{uploadFile:t,maxFileSize:n,kind:o}){if(t){const s=await t(e,{kind:o});return{src:s.src,name:s.name??e.name,mimeType:s.mimeType??e.type}}if(n&&e.size>n)throw new Error(`This file is ${At(e.size)} — larger than the ${At(n)} limit.`);return{src:await Bs(e),name:e.name,mimeType:e.type}}async function Ts(e,t){const n=vs(e.type),{src:o,name:l,mimeType:s}=await En(e,{...t,kind:n});return{block:{id:c.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:n,src:o,name:l,mimeType:s,align:"left",width:100}},runs:[],subtreeBlocks:[]}}const ws=[{name:"youtube",test:/(?:youtube\.com\/watch\?(?:.*&)?v=|youtu\.be\/|youtube\.com\/shorts\/|youtube\.com\/embed\/)([\w-]{6,})/,embed:e=>`https://www.youtube.com/embed/${e[1]}`},{name:"vimeo",test:/vimeo\.com\/(?:video\/)?(\d+)/,embed:e=>`https://player.vimeo.com/video/${e[1]}`},{name:"loom",test:/loom\.com\/share\/([\w-]+)/,embed:e=>`https://www.loom.com/embed/${e[1]}`},{name:"figma",test:/figma\.com\/(?:file|design|proto)\/[\w-]+/,embed:(e,t)=>`https://www.figma.com/embed?embed_host=noteloom&url=${encodeURIComponent(t)}`},{name:"codepen",test:/codepen\.io\/([\w-]+)\/pen\/([\w-]+)/,embed:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{name:"spotify",test:/open\.spotify\.com\/(track|album|playlist|episode|show)\/([\w]+)/,embed:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`}];function Rs(e){if(!e)return null;for(const t of ws){const n=e.match(t.test);if(n)return{provider:t.name,embedUrl:t.embed(n,e)}}return null}const Ke={image:"image",video:"video",audio:"audio",file:"file",oembed:"embed"},As={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},rt=20,at=100,js=[{value:"left",Icon:c.AlignLeftIcon,label:"Align left"},{value:"center",Icon:c.AlignCenterIcon,label:"Align center"},{value:"right",Icon:c.AlignRightIcon,label:"Align right"}];function et(e){return Math.min(at,Math.max(rt,Math.round(e)))}function Ls({kind:e,src:t,name:n,alt:o,provider:l}){return e==="image"?a.jsx("img",{className:"be-embed-image",src:t,alt:o||""}):e==="video"?a.jsx("video",{className:"be-embed-video",src:t,controls:!0}):e==="audio"?a.jsx("audio",{className:"be-embed-audio",src:t,controls:!0}):e==="oembed"?a.jsx("iframe",{className:"be-embed-oembed",src:t,title:l?`${l} embed`:"embed",sandbox:"allow-scripts allow-same-origin allow-presentation allow-popups",allow:"autoplay; encrypted-media; picture-in-picture; fullscreen",allowFullScreen:!0,loading:"lazy"}):a.jsxs("a",{className:"be-embed-file-link",href:t,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[a.jsx(c.PaperclipIcon,{size:14})," ",n||t]})}function Ns({id:e}){var W,Pe,Ce,He;const t=c.useEditorStore(),n=v.useBlock(e),{uploadFile:o,maxFileSize:l}=c.useFileUpload(),[s,r]=u.useState(""),[i,d]=u.useState(!1),[f,m]=u.useState(null),[p,h]=u.useState(!1),[k,x]=u.useState(""),[b,I]=u.useState(!1),[B,g]=u.useState(null),y=u.useRef(null),w=u.useRef(null),j=u.useCallback(N=>t.applyOperation(c.updateBlockProps(e,N)),[t,e]),O=u.useCallback(()=>{var N;x(((N=n==null?void 0:n.props)==null?void 0:N.alt)??""),h(!0)},[(W=n==null?void 0:n.props)==null?void 0:W.alt]),$=u.useCallback(()=>h(!1),[]),S=u.useCallback(N=>{N.preventDefault(),j({alt:k.trim()}),h(!1)},[k,j]),L=u.useCallback(async(N,K)=>{g(null),I(!0);try{const{src:H,name:q,mimeType:re}=await En(N,{uploadFile:o,maxFileSize:l,kind:K});j({src:H,name:q,mimeType:re})}catch(H){g((H==null?void 0:H.message)||"Upload failed. Please try again.")}finally{I(!1)}},[o,l,j]),_=u.useCallback(N=>{var H,q;const K=(H=N.target.files)==null?void 0:H[0];N.target.value="",K&&L(K,((q=n==null?void 0:n.props)==null?void 0:q.kind)??"file")},[L,(Pe=n==null?void 0:n.props)==null?void 0:Pe.kind]),T=u.useCallback(N=>{var H,q;N.preventDefault(),d(!1);const K=(H=N.dataTransfer.files)==null?void 0:H[0];K&&L(K,((q=n==null?void 0:n.props)==null?void 0:q.kind)??"file")},[L,(Ce=n==null?void 0:n.props)==null?void 0:Ce.kind]),A=u.useCallback(N=>{N.preventDefault(),d(!0)},[]),M=u.useCallback(()=>d(!1),[]),D=u.useCallback(()=>{const N=s.trim();if(!N)return;const K=Rs(N);j(K?{kind:"oembed",src:K.embedUrl,name:N,mimeType:"",provider:K.provider,originalUrl:N}:{src:N,name:N}),r("")},[s,j]),E=u.useCallback(()=>j({src:"",name:"",mimeType:"",provider:"",originalUrl:""}),[j]),P=u.useCallback(N=>{N.preventDefault();const K=y.current,H=w.current;if(!K||!H)return;const q=K.getBoundingClientRect().width,re=H.getBoundingClientRect().width,xe=N.clientX,_e=R=>et((re+(R.clientX-xe))/q*100),Be=R=>m(_e(R)),ve=R=>{document.removeEventListener("mousemove",Be),document.removeEventListener("mouseup",ve),j({width:_e(R)}),m(null)};document.addEventListener("mousemove",Be),document.addEventListener("mouseup",ve)},[j]),z=u.useCallback(N=>{var re;const K=((re=n==null?void 0:n.props)==null?void 0:re.width)??100,H=N.shiftKey?1:5;let q;if(N.key==="ArrowLeft"||N.key==="ArrowDown")q=et(K-H);else if(N.key==="ArrowRight"||N.key==="ArrowUp")q=et(K+H);else if(N.key==="Home")q=rt;else if(N.key==="End")q=at;else return;N.preventDefault(),j({width:q})},[(He=n==null?void 0:n.props)==null?void 0:He.width,j]),G=c.useBlockClassName("be-embed",n);if(!n)return null;const{kind:U="file",src:F,name:V,alt:ne="",align:Z="left",width:X=100,provider:se="",originalUrl:ee=""}=n.props,Q=U==="image"||U==="video"||U==="oembed",fe=f??X,le=U==="oembed";return a.jsxs("div",{className:G,"data-block-id":e,"data-kind":U,contentEditable:!1,tabIndex:-1,children:[F?a.jsx("div",{ref:y,className:`be-embed-preview be-embed-align-${Z}`,children:a.jsxs("div",{ref:w,className:"be-embed-frame",style:Q?{width:`${fe}%`}:void 0,children:[a.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[js.map(({value:N,Icon:K,label:H})=>a.jsx("button",{type:"button",className:`be-embed-toolbar-btn${Z===N?" be-embed-toolbar-btn-active":""}`,title:H,"aria-label":H,"aria-pressed":Z===N,onClick:()=>j({align:N}),children:a.jsx(K,{size:14})},N)),U==="image"&&a.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:O,children:"Alt text"}),le&&ee&&a.jsx("a",{className:"be-embed-toolbar-btn be-embed-open-original",href:ee,target:"_blank",rel:"noopener noreferrer",title:"Open original link","aria-label":"Open original link",children:a.jsx(c.LinkIcon,{size:14})}),a.jsx("button",{type:"button",className:"be-embed-remove",onClick:E,"aria-label":`Remove ${Ke[U]}`,children:"Remove"})]}),a.jsx(Ls,{kind:U,src:F,name:V,alt:ne,provider:se}),Q&&a.jsx("div",{className:"be-embed-resize-handle",onMouseDown:P,onKeyDown:z,role:"slider",tabIndex:0,"aria-label":`Resize ${Ke[U]}`,"aria-valuemin":rt,"aria-valuemax":at,"aria-valuenow":fe})]})}):a.jsxs("div",{className:`be-embed-dropzone${i?" be-embed-dropzone-active":""}`,onDrop:le||b?void 0:T,onDragOver:le||b?void 0:A,onDragLeave:M,children:[b?a.jsx("span",{className:"be-embed-uploading",children:"Uploading…"}):a.jsxs(a.Fragment,{children:[!le&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Ke[U],a.jsx("input",{type:"file",accept:As[U],onChange:_,hidden:!0})]}),a.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"})]}),a.jsxs("div",{className:"be-embed-url-row",children:[a.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:le?"Paste a YouTube, Vimeo, Loom, Figma, CodePen, or Spotify link":`https://... ${Ke[U]} URL`,value:s,onChange:N=>r(N.target.value),onKeyDown:N=>N.key==="Enter"&&D()}),a.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:D,children:"Embed"})]})]}),B&&a.jsxs("div",{className:"be-embed-upload-error",role:"alert",children:[B,a.jsx("button",{type:"button",onClick:()=>g(null),"aria-label":"Dismiss error",children:"×"})]})]}),a.jsx(ae.Modal,{isOpen:p,onClose:$,title:"Alt text",children:a.jsxs("form",{onSubmit:S,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Describe this image for screen readers"}),a.jsx("input",{type:"text",value:k,onChange:N=>x(N.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:$,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function Es({kind:e="file",src:t="",name:n="",alt:o="",mimeType:l="",align:s="left",width:r=100,provider:i="",originalUrl:d=""}={}){return function(m){return{block:{id:c.genId(),type:"embed",parentId:m,contentIds:[],props:{kind:e,src:t,name:n,alt:o,mimeType:l,align:s,width:r,provider:i,originalUrl:d}},runs:[]}}}const jt={image:c.ImageIcon,video:c.VideoIcon,audio:c.AudioIcon,file:c.PaperclipIcon,oembed:c.LinkIcon},Sn="be-embed-file-link",Mn="be-embed-oembed-link";function Ss(e,t,n){if(e!=="image"&&e!=="video"&&e!=="oembed")return"";const o=[];return n!==100&&o.push(`width:${n}%`),t==="center"?o.push("display:block","margin-left:auto","margin-right:auto"):t==="right"&&o.push("display:block","margin-left:auto"),o.length?` style="${o.join(";")}"`:""}function tt(e){var l,s,r,i;const t=(l=e.style)==null?void 0:l.width,n=t&&t.endsWith("%")?parseInt(t,10):100;let o="left";return((s=e.style)==null?void 0:s.marginLeft)==="auto"&&((r=e.style)==null?void 0:r.marginRight)==="auto"?o="center":((i=e.style)==null?void 0:i.marginLeft)==="auto"&&(o="right"),{align:o,width:Number.isFinite(n)?n:100}}function Ms(e){const{kind:t,src:n,name:o,alt:l="",align:s="left",width:r=100,provider:i="",originalUrl:d=""}=e.props;if(!n)return"<p></p>";const f=Ss(t,s,r);return t==="image"?`<img src="${v.escapeAttr(n)}" alt="${v.escapeAttr(l)}"${f}>`:t==="video"?`<video src="${v.escapeAttr(n)}" controls${f}></video>`:t==="audio"?`<audio src="${v.escapeAttr(n)}" controls></audio>`:t==="oembed"?`<a class="${Mn}" href="${v.escapeAttr(d||n)}" data-embed-url="${v.escapeAttr(n)}" data-embed-provider="${v.escapeAttr(i)}">${v.escapeHTML(d||n)}</a>`:`<a class="${Sn}" href="${v.escapeAttr(n)}">${v.escapeHTML(o||n)}</a>`}function $s(e){const{kind:t,src:n,name:o,originalUrl:l=""}=e.props;return n?t==="oembed"?`[embed: ${l||n}]`:`[${t}: ${o||n}]`:""}function Os(e){const{kind:t,src:n,name:o,alt:l="",originalUrl:s=""}=e.props;return n?t==="image"?`![${l}](${n})`:t==="oembed"?`[${s||n}](${s||n})`:`[${o||n}](${n})`:""}function Ds(e){return e.tagName==="IMG"?Le("image",e.getAttribute("src")??"","",{...tt(e),alt:e.getAttribute("alt")??""}):e.tagName==="VIDEO"?Le("video",e.getAttribute("src")??"","",tt(e)):e.tagName==="AUDIO"?Le("audio",e.getAttribute("src")??"",""):e.tagName==="A"&&e.classList.contains(Mn)?Le("oembed",e.getAttribute("data-embed-url")??"","",{...tt(e),provider:e.getAttribute("data-embed-provider")??"",originalUrl:e.getAttribute("href")??""}):e.tagName==="A"&&e.classList.contains(Sn)?Le("file",e.getAttribute("href")??"",e.textContent??""):null}function Le(e,t,n,{align:o="left",width:l=100,alt:s="",provider:r="",originalUrl:i=""}={}){return{block:{id:c.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:e,src:t,name:n,alt:s,align:o,width:l,provider:r,originalUrl:i}},runs:[]}}function Lt(e){return(t,{blockId:n,runId:o,sliceStart:l,sliceEnd:s})=>{const r=t.getRun(o),i=(r==null?void 0:r.value)??"";t.applyOperation(c.updateRun(o,{value:i.slice(0,l)+i.slice(s)}));const d=C.insertSiblingAfter(t,n,Es({kind:e}));return C.insertSiblingAfterAndFocus(t,d,C.createTextLeafBlock("paragraph")),d}}const $n=v.defineBlock({name:"embed",contentModel:"void",component:Ns,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100,provider:"",originalUrl:""},toHTML:Ms,toPlainText:$s,toMarkdown:Os,fromHTML:Ds,slashCommands:[...["image","video","audio","file"].map(e=>({label:e.charAt(0).toUpperCase()+e.slice(1),icon:jt[e],keywords:["embed","upload","insert",e],run:Lt(e)})),{label:"Embed link",icon:jt.oembed,keywords:["embed","link","youtube","vimeo","loom","figma","codepen","spotify"],run:Lt("oembed")}]}),ct=new Set;function Ps(e){ct.add(e)}function On(e){return ct.has(e)?(ct.delete(e),!0):!1}function Dn(e,t,n){var i;const o=e.getBlock(t),l=((i=o==null?void 0:o.props)==null?void 0:i.titleRunIds)??(o==null?void 0:o.contentIds)??[],s=l.indexOf(n),r=s>=0?l[s+1]:void 0;if(r){C.focusRunEnd(r);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function Hs({id:e,blockId:t}){const n=c.useEditorStore(),o=v.useRun(e),l=u.useRef(null);l.current===null&&(l.current=On(e));const s=u.useCallback(f=>{n.applyOperation(c.updateRun(e,{data:{...o==null?void 0:o.data,selectedValue:f}})),l.current&&Dn(n,t,e)},[n,e,o==null?void 0:o.data,t]);if(!o)return null;const{options:r=[],selectedValue:i="",placeholder:d="Select…"}=o.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:f=>{f.preventDefault(),f.stopPropagation()},onKeyDown:f=>f.stopPropagation(),children:a.jsx(ge,{value:i,options:r,onChange:s,placeholder:d,ariaLabel:"Select an option",autoOpen:l.current})})}function Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},s,{autoOpen:r=!1}={}){const i=e.getRun(n),d=(i==null?void 0:i.value)??"",f=d.slice(0,o),m=d.slice(l),p=s(),h={...i,value:f},k={id:c.genId(),type:"text",value:m,marks:{...i==null?void 0:i.marks}};e.applyOperation(c.replaceRunSpan(t,[n],[h,p,k])),r?Ps(p.id):C.focusRunEnd(k.id)}function _s(e){return String(e).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Pn(e){var o;const{options:t=[],selectedValue:n=""}=e.data??{};return((o=t.find(l=>l.value===n))==null?void 0:o.label)??""}function Fs(e){var n,o;const t=Pn(e)||((n=e.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${_s(((o=e.data)==null?void 0:o.selectedValue)??"")}">${t}</span>`}function Us(e){return Pn(e)}function Ks(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="select"?null:{id:c.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:e.getAttribute("data-selected-value")??""}}}const Hn=v.defineInline({name:"select",component:Hs,toHTML:Fs,toPlainText:Us,fromHTML:Ks,slashCommand:{label:"Select",icon:c.SelectIcon,keywords:["select","dropdown","choice","picker"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}),{autoOpen:!0})}});function zs({id:e}){const t=c.useEditorStore(),n=v.useRun(e),o=u.useCallback(s=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{isoDate:l=""}=n.data??{};return a.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:a.jsx("input",{type:"date",value:l,onChange:o})})}function Gs(e){return String(e).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function _n(e){if(!e)return"";const t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Vs(e){var n;const t=((n=e.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Gs(t)}">${_n(t)}</span>`}function qs(e){var t;return _n(((t=e.data)==null?void 0:t.isoDate)??"")}function Ws(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="date"?null:{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:e.getAttribute("data-iso-date")??""}}}function Qs(){return new Date().toISOString().slice(0,10)}const Fn=v.defineInline({name:"date",component:zs,toHTML:Vs,toPlainText:qs,fromHTML:Ws,slashCommand:{label:"Date",icon:c.DateIcon,keywords:["date","when","schedule","calendar"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:Qs()}}))}});function Ys({id:e}){const t=c.useEditorStore(),n=v.useRun(e),o=u.useCallback(i=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[t,e,n==null?void 0:n.data]),l=u.useCallback(i=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:r=""}=n.data??{};return a.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[a.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:o}),a.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:r,onChange:l,placeholder:"Label…"})]})}function Xs(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Js(e){const{checked:t=!1,label:n=""}=e.data??{};return`<span data-inline-type="checkbox" data-checked="${t}">${t?"☑":"☐"} ${Xs(n)}</span>`}function Zs(e){const{checked:t=!1,label:n=""}=e.data??{};return`${t?"[x]":"[ ]"} ${n}`.trim()}function er(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="checkbox"?null:{id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:e.getAttribute("data-checked")==="true",label:(e.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Un=v.defineInline({name:"checkbox",component:Ys,toHTML:Js,toPlainText:Zs,fromHTML:er,slashCommand:{label:"Checkbox",icon:c.CheckboxIcon,keywords:["checkbox","todo","check","toggle"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}});function tr({id:e,blockId:t}){var k;const n=c.useEditorStore(),o=v.useRun(e),l=t?n.getBlock(t):null,s=l?n.getBlock(l.parentId):null,r=(s==null?void 0:s.parentId)??null,i=v.useBlock(r),d=s?s.contentIds.indexOf(t):-1,m=(((k=(i&&s?J(i,s.contentIds.length):[])[d])==null?void 0:k.options)??[]).map((x,b)=>({...x,color:x.color??ze(b)})),p=u.useCallback((x,b)=>{n.applyOperation(c.updateRun(e,{data:{selectedValue:x,selectedLabel:(b==null?void 0:b.label)??""}}))},[n,e]);if(!o)return null;const{selectedValue:h=""}=o.data??{};return a.jsx("span",{className:"be-inline-table-select",onMouseDown:x=>{x.preventDefault(),x.stopPropagation()},onKeyDown:x=>x.stopPropagation(),children:a.jsx(ge,{value:h,options:m,onChange:p,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Kn(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function nr(e){return Kn(e).replace(/"/g,"&quot;")}function or(e){const{selectedValue:t="",selectedLabel:n=""}=e.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${nr(t)}">${Kn(n)}</span>`}function lr(e){var t;return((t=e.data)==null?void 0:t.selectedLabel)??""}function sr(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="tableSelect"?null:{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:e.getAttribute("data-selected-value")??"",selectedLabel:e.textContent??""}}}const zn=v.defineInline({name:"tableSelect",component:tr,toHTML:or,toPlainText:lr,fromHTML:sr}),Gn={name:"emoji",kind:"inline"},rr=[$t,Ot,Qt,bn,gn,hn,xn,Cn,Bn,Tn,wn,An,jn,Nn,$n,v.canvasBlockType,Hn,Fn,Un,zn,Gn];function ar({exclude:e=[]}={}){const t=new Set(e);return rr.filter(n=>!t.has(n.name))}exports.AGGREGATE_LABELS=en;exports.AGGREGATE_TYPES=Zt;exports.BlockChildren=pe;exports.BlockErrorBoundary=Dt;exports.BlockGutterRow=Vt;exports.BlockRenderer=ut;exports.CALLOUT_COLORS=vn;exports.COLUMN_TYPES=Yt;exports.CommentPopoverHeader=St;exports.DEFAULT_COLUMN_TYPE=De;exports.DEFAULT_COLUMN_WIDTH=qe;exports.EditableBlockContent=ue;exports.LANGUAGES=Rn;exports.LinkEditModal=Et;exports.MIN_COLUMN_WIDTH=me;exports.Select=ge;exports.TableHeaderRow=fn;exports.TurnIntoSubmenu=Ut;exports.announce=de;exports.blankRunForType=Xt;exports.blockquoteBlockType=wn;exports.buttonBlockType=Nn;exports.calloutBlockType=Tn;exports.canMergeTypes=Mt;exports.checkboxInlineType=Un;exports.codeBlockType=An;exports.computeColumnAggregate=tn;exports.consumePendingAutoOpen=On;exports.convertRunToType=Jt;exports.createCellForColumn=We;exports.createDefaultColumns=pt;exports.dateInlineType=Fn;exports.deleteBlockAndFocusSibling=dt;exports.deleteColumn=rn;exports.deleteRow=sn;exports.dividerBlockType=Bn;exports.domInlineToRuns=ie;exports.duplicateBlock=Kt;exports.embedBlockType=$n;exports.emojiInlineType=Gn;exports.ensureRootNonEmpty=Ge;exports.focusAfterChip=Dn;exports.formatAggregateValue=nn;exports.headingBlockType=Ot;exports.insertColumnAfter=ot;exports.insertInlineRunAtCursor=Qe;exports.insertRowAfter=ln;exports.isContentlessBlock=Me;exports.isRunsEmpty=te;exports.isTurnIntoEligible=_t;exports.layoutBlockType=xn;exports.layoutColumnBlockType=Cn;exports.listItemBlockType=Qt;exports.moveBlockDown=Gt;exports.moveBlockUp=zt;exports.paragraphBlockType=$t;exports.pickTagColor=ze;exports.renameColumn=an;exports.resolveColumns=J;exports.resolveFileToEmbedInsert=Ts;exports.selectInlineType=Hn;exports.setColumnAggregate=cn;exports.setColumnOptions=Ee;exports.setColumnType=un;exports.setColumnWidth=lt;exports.sortTableByColumn=st;exports.starterKit=ar;exports.tableBlockType=bn;exports.tableCellBlockType=hn;exports.tableRowBlockType=gn;exports.tableSelectInlineType=zn;exports.toggleHeadingBlockType=jn;exports.turnBlockInto=Ft;exports.useAutoAdjustedPosition=$e;exports.useBlockChildren=it;exports.useFieldTypes=dn;exports.useMenuKeyboardNav=Ve;exports.useVirtualKeyboardInset=pn;
27
+ //# sourceMappingURL=starter-kit-DyX1U84W.cjs.map