autoblogger 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ai/prompts.ts","../src/ai/models.ts","../src/ai/provider.ts","../src/ai/builders.ts","../src/lib/url-extractor.ts","../src/ai/generate.ts","../src/ai/chat.ts","../src/index.ts","../src/data/posts.ts","../src/data/comments.ts","../src/data/factory.ts","../src/data/tags.ts","../src/data/revisions.ts","../src/data/ai-settings.ts","../src/data/topics.ts","../src/data/news-items.ts","../src/data/users.ts","../src/api/posts.ts","../src/api/utils.ts","../src/api/comments.ts","../src/api/tags.ts","../src/api/ai.ts","../src/api/upload.ts","../src/api/topics.ts","../src/api/users.ts","../src/api/admin.ts","../src/api/settings.ts","../src/api/revisions.ts","../src/api/chat-history.ts","../src/api/index.ts","../src/auto-draft/rss.ts","../src/auto-draft/keywords.ts","../src/ai/index.ts","../src/ai/parse.ts","../src/lib/markdown.ts","../src/auto-draft/runner.ts","../src/types/config.ts","../src/server.ts","../src/schema.ts","../src/lib/format.ts","../src/lib/seo.ts","../src/lib/comments.ts","../node_modules/@tiptap/core/src/helpers/createChainableState.ts","../node_modules/@tiptap/core/src/CommandManager.ts","../node_modules/@tiptap/core/src/commands/index.ts","../node_modules/@tiptap/core/src/commands/blur.ts","../node_modules/@tiptap/core/src/commands/clearContent.ts","../node_modules/@tiptap/core/src/commands/clearNodes.ts","../node_modules/@tiptap/core/src/commands/command.ts","../node_modules/@tiptap/core/src/commands/createParagraphNear.ts","../node_modules/@tiptap/core/src/commands/cut.ts","../node_modules/@tiptap/core/src/commands/deleteCurrentNode.ts","../node_modules/@tiptap/core/src/helpers/getNodeType.ts","../node_modules/@tiptap/core/src/commands/deleteNode.ts","../node_modules/@tiptap/core/src/commands/deleteRange.ts","../node_modules/@tiptap/core/src/commands/deleteSelection.ts","../node_modules/@tiptap/core/src/commands/enter.ts","../node_modules/@tiptap/core/src/commands/exitCode.ts","../node_modules/@tiptap/core/src/commands/extendMarkRange.ts","../node_modules/@tiptap/core/src/utilities/isRegExp.ts","../node_modules/@tiptap/core/src/utilities/objectIncludes.ts","../node_modules/@tiptap/core/src/helpers/getMarkRange.ts","../node_modules/@tiptap/core/src/helpers/getMarkType.ts","../node_modules/@tiptap/core/src/commands/first.ts","../node_modules/@tiptap/core/src/helpers/isTextSelection.ts","../node_modules/@tiptap/core/src/helpers/resolveFocusPosition.ts","../node_modules/@tiptap/core/src/utilities/minMax.ts","../node_modules/@tiptap/core/src/utilities/isAndroid.ts","../node_modules/@tiptap/core/src/utilities/isiOS.ts","../node_modules/@tiptap/core/src/utilities/isSafari.ts","../node_modules/@tiptap/core/src/commands/focus.ts","../node_modules/@tiptap/core/src/commands/forEach.ts","../node_modules/@tiptap/core/src/commands/insertContent.ts","../node_modules/@tiptap/core/src/commands/insertContentAt.ts","../node_modules/@tiptap/core/src/helpers/createNodeFromContent.ts","../node_modules/@tiptap/core/src/utilities/elementFromString.ts","../node_modules/@tiptap/core/src/helpers/selectionToInsertionEnd.ts","../node_modules/@tiptap/core/src/commands/join.ts","../node_modules/@tiptap/core/src/commands/joinItemBackward.ts","../node_modules/@tiptap/core/src/commands/joinItemForward.ts","../node_modules/@tiptap/core/src/commands/joinTextblockBackward.ts","../node_modules/@tiptap/core/src/commands/joinTextblockForward.ts","../node_modules/@tiptap/core/src/utilities/isMacOS.ts","../node_modules/@tiptap/core/src/commands/keyboardShortcut.ts","../node_modules/@tiptap/core/src/commands/lift.ts","../node_modules/@tiptap/core/src/helpers/isNodeActive.ts","../node_modules/@tiptap/core/src/commands/liftEmptyBlock.ts","../node_modules/@tiptap/core/src/commands/liftListItem.ts","../node_modules/@tiptap/core/src/commands/newlineInCode.ts","../node_modules/@tiptap/core/src/helpers/getSchemaTypeNameByName.ts","../node_modules/@tiptap/core/src/utilities/deleteProps.ts","../node_modules/@tiptap/core/src/commands/resetAttributes.ts","../node_modules/@tiptap/core/src/commands/scrollIntoView.ts","../node_modules/@tiptap/core/src/commands/selectAll.ts","../node_modules/@tiptap/core/src/commands/selectNodeBackward.ts","../node_modules/@tiptap/core/src/commands/selectNodeForward.ts","../node_modules/@tiptap/core/src/commands/selectParentNode.ts","../node_modules/@tiptap/core/src/commands/selectTextblockEnd.ts","../node_modules/@tiptap/core/src/commands/selectTextblockStart.ts","../node_modules/@tiptap/core/src/helpers/createDocument.ts","../node_modules/@tiptap/core/src/commands/setContent.ts","../node_modules/@tiptap/core/src/helpers/getMarkAttributes.ts","../node_modules/@tiptap/core/src/helpers/combineTransactionSteps.ts","../node_modules/@tiptap/core/src/helpers/defaultBlockAt.ts","../node_modules/@tiptap/core/src/helpers/findChildren.ts","../node_modules/@tiptap/core/src/helpers/findChildrenInRange.ts","../node_modules/@tiptap/core/src/helpers/findParentNodeClosestToPos.ts","../node_modules/@tiptap/core/src/helpers/findParentNode.ts","../node_modules/@tiptap/core/src/helpers/getExtensionField.ts","../node_modules/@tiptap/core/src/helpers/flattenExtensions.ts","../node_modules/@tiptap/core/src/helpers/generateHTML.ts","../node_modules/@tiptap/core/src/helpers/getHTMLFromFragment.ts","../node_modules/@tiptap/core/src/helpers/getSchemaByResolvedExtensions.ts","../node_modules/@tiptap/core/src/utilities/isFunction.ts","../node_modules/@tiptap/core/src/utilities/callOrReturn.ts","../node_modules/@tiptap/core/src/utilities/isEmptyObject.ts","../node_modules/@tiptap/core/src/helpers/splitExtensions.ts","../node_modules/@tiptap/core/src/helpers/getAttributesFromExtensions.ts","../node_modules/@tiptap/core/src/utilities/mergeAttributes.ts","../node_modules/@tiptap/core/src/helpers/getRenderedAttributes.ts","../node_modules/@tiptap/core/src/utilities/fromString.ts","../node_modules/@tiptap/core/src/helpers/injectExtensionAttributesToParseRule.ts","../node_modules/@tiptap/core/src/utilities/findDuplicates.ts","../node_modules/@tiptap/core/src/helpers/sortExtensions.ts","../node_modules/@tiptap/core/src/helpers/resolveExtensions.ts","../node_modules/@tiptap/core/src/helpers/getSchema.ts","../node_modules/@tiptap/core/src/helpers/generateJSON.ts","../node_modules/@tiptap/core/src/helpers/generateText.ts","../node_modules/@tiptap/core/src/helpers/getTextBetween.ts","../node_modules/@tiptap/core/src/helpers/getText.ts","../node_modules/@tiptap/core/src/helpers/getTextSerializersFromSchema.ts","../node_modules/@tiptap/core/src/helpers/getNodeAttributes.ts","../node_modules/@tiptap/core/src/helpers/getAttributes.ts","../node_modules/@tiptap/core/src/utilities/removeDuplicates.ts","../node_modules/@tiptap/core/src/helpers/getChangedRanges.ts","../node_modules/@tiptap/core/src/helpers/getDebugJSON.ts","../node_modules/@tiptap/core/src/helpers/getMarksBetween.ts","../node_modules/@tiptap/core/src/helpers/getNodeAtPosition.ts","../node_modules/@tiptap/core/src/helpers/getSchemaTypeByName.ts","../node_modules/@tiptap/core/src/helpers/getSplittedAttributes.ts","../node_modules/@tiptap/core/src/helpers/getTextContentFromNodes.ts","../node_modules/@tiptap/core/src/helpers/isMarkActive.ts","../node_modules/@tiptap/core/src/helpers/isActive.ts","../node_modules/@tiptap/core/src/helpers/isAtEndOfNode.ts","../node_modules/@tiptap/core/src/helpers/isAtStartOfNode.ts","../node_modules/@tiptap/core/src/helpers/isExtensionRulesEnabled.ts","../node_modules/@tiptap/core/src/helpers/isList.ts","../node_modules/@tiptap/core/src/helpers/isNodeEmpty.ts","../node_modules/@tiptap/core/src/helpers/isNodeSelection.ts","../node_modules/@tiptap/core/src/helpers/MappablePosition.ts","../node_modules/@tiptap/core/src/helpers/posToDOMRect.ts","../node_modules/@tiptap/core/src/helpers/rewriteUnknownContent.ts","../node_modules/@tiptap/core/src/commands/setMark.ts","../node_modules/@tiptap/core/src/commands/setMeta.ts","../node_modules/@tiptap/core/src/commands/setNode.ts","../node_modules/@tiptap/core/src/commands/setNodeSelection.ts","../node_modules/@tiptap/core/src/commands/setTextDirection.ts","../node_modules/@tiptap/core/src/commands/setTextSelection.ts","../node_modules/@tiptap/core/src/commands/sinkListItem.ts","../node_modules/@tiptap/core/src/commands/splitBlock.ts","../node_modules/@tiptap/core/src/commands/splitListItem.ts","../node_modules/@tiptap/core/src/commands/toggleList.ts","../node_modules/@tiptap/core/src/commands/toggleMark.ts","../node_modules/@tiptap/core/src/commands/toggleNode.ts","../node_modules/@tiptap/core/src/commands/toggleWrap.ts","../node_modules/@tiptap/core/src/commands/undoInputRule.ts","../node_modules/@tiptap/core/src/commands/unsetAllMarks.ts","../node_modules/@tiptap/core/src/commands/unsetMark.ts","../node_modules/@tiptap/core/src/commands/unsetTextDirection.ts","../node_modules/@tiptap/core/src/commands/updateAttributes.ts","../node_modules/@tiptap/core/src/commands/wrapIn.ts","../node_modules/@tiptap/core/src/commands/wrapInList.ts","../node_modules/@tiptap/core/src/Editor.ts","../node_modules/@tiptap/core/src/EventEmitter.ts","../node_modules/@tiptap/core/src/ExtensionManager.ts","../node_modules/@tiptap/core/src/InputRule.ts","../node_modules/@tiptap/core/src/utilities/isPlainObject.ts","../node_modules/@tiptap/core/src/utilities/mergeDeep.ts","../node_modules/@tiptap/core/src/Extendable.ts","../node_modules/@tiptap/core/src/Mark.ts","../node_modules/@tiptap/core/src/PasteRule.ts","../node_modules/@tiptap/core/src/utilities/isNumber.ts","../node_modules/@tiptap/core/src/extensions/index.ts","../node_modules/@tiptap/core/src/extensions/clipboardTextSerializer.ts","../node_modules/@tiptap/core/src/Extension.ts","../node_modules/@tiptap/core/src/extensions/commands.ts","../node_modules/@tiptap/core/src/extensions/delete.ts","../node_modules/@tiptap/core/src/extensions/drop.ts","../node_modules/@tiptap/core/src/extensions/editable.ts","../node_modules/@tiptap/core/src/extensions/focusEvents.ts","../node_modules/@tiptap/core/src/extensions/keymap.ts","../node_modules/@tiptap/core/src/extensions/paste.ts","../node_modules/@tiptap/core/src/extensions/tabindex.ts","../node_modules/@tiptap/core/src/extensions/textDirection.ts","../node_modules/@tiptap/core/src/NodePos.ts","../node_modules/@tiptap/core/src/style.ts","../node_modules/@tiptap/core/src/utilities/createStyleTag.ts","../node_modules/@tiptap/core/src/inputRules/markInputRule.ts","../node_modules/@tiptap/core/src/inputRules/nodeInputRule.ts","../node_modules/@tiptap/core/src/inputRules/textblockTypeInputRule.ts","../node_modules/@tiptap/core/src/inputRules/textInputRule.ts","../node_modules/@tiptap/core/src/inputRules/wrappingInputRule.ts","../node_modules/@tiptap/core/src/jsx-runtime.ts","../node_modules/@tiptap/core/src/lib/ResizableNodeView.ts","../node_modules/@tiptap/core/src/utilities/canInsertNode.ts","../node_modules/@tiptap/core/src/utilities/escapeForRegEx.ts","../node_modules/@tiptap/core/src/utilities/isString.ts","../node_modules/@tiptap/core/src/utilities/markdown/index.ts","../node_modules/@tiptap/core/src/utilities/markdown/attributeUtils.ts","../node_modules/@tiptap/core/src/utilities/markdown/createAtomBlockMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/createBlockMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/createInlineMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/parseIndentedBlocks.ts","../node_modules/@tiptap/core/src/utilities/markdown/renderNestedMarkdownContent.ts","../node_modules/@tiptap/core/src/MarkView.ts","../node_modules/@tiptap/core/src/Node.ts","../node_modules/@tiptap/core/src/NodeView.ts","../node_modules/@tiptap/core/src/pasteRules/markPasteRule.ts","../node_modules/@tiptap/core/src/pasteRules/nodePasteRule.ts","../node_modules/@tiptap/core/src/pasteRules/textPasteRule.ts","../node_modules/@tiptap/core/src/Tracker.ts","../src/lib/comment-mark.ts"],"sourcesContent":["// ============================================\n// GENERATION PROMPTS\n// ============================================\n\n/**\n * Default template for essay generation.\n * Placeholders: {{RULES}}, {{STYLE_EXAMPLES}}, {{WORD_COUNT}}\n */\nexport const DEFAULT_GENERATE_TEMPLATE = `<system>\n<role>Expert essay writer creating engaging, thoughtful content</role>\n\n<critical>\nALWAYS output a complete essay. NEVER respond conversationally.\n- Do NOT ask questions or request clarification\n- Do NOT say \"Here is your essay\" or similar preamble\n- Do NOT explain what you're going to write\n- If the prompt is vague, make creative choices and proceed\n- Output ONLY the essay in markdown format\n</critical>\n\n<rules>\n{{RULES}}\n</rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<constraints>\n<word_count>{{WORD_COUNT}}</word_count>\n</constraints>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Your Title Here]\nLine 2: *[Your subtitle here]*\nLine 3: (blank line)\nLine 4+: Essay body in markdown\n\n<title_guidelines>\n- Be SPECIFIC, not generic (avoid \"The Power of\", \"Why X Matters\", \"A Guide to\")\n- Include a concrete detail, angle, or unexpected element\n- Create curiosity or make a bold claim\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that hooks the reader\n- Tease the main argument or reveal a key insight\n- Create tension, curiosity, or promise value\n- Make readers want to continue reading\n</subtitle_guidelines>\n</output_format>\n</system>`\n\n// ============================================\n// CHAT PROMPTS\n// ============================================\n\n/**\n * Default template for chat interactions.\n * Placeholders: {{CHAT_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}, {{ESSAY_CONTEXT}}\n */\nexport const DEFAULT_CHAT_TEMPLATE = `<system>\n<role>Helpful writing assistant for essay creation and editing</role>\n\n<chat_rules>\n{{CHAT_RULES}}\n</chat_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<context>\n{{ESSAY_CONTEXT}}\n</context>\n\n<behavior>\n- Be concise and actionable\n- When suggesting edits, be specific about what to change\n- Match the author's voice and style when writing\n- Ask clarifying questions if the request is ambiguous\n</behavior>\n</system>`\n\n// ============================================\n// REWRITE PROMPTS\n// ============================================\n\n/**\n * Default template for text rewriting.\n * Placeholders: {{REWRITE_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}\n */\nexport const DEFAULT_REWRITE_TEMPLATE = `<system>\n<role>Writing assistant that improves text quality</role>\n\n<rewrite_rules>\n{{REWRITE_RULES}}\n</rewrite_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<behavior>\n- Preserve the original meaning exactly\n- Improve clarity, flow, and readability\n- Fix grammar and punctuation issues\n- Maintain the author's voice and tone\n- Output only the improved text, no explanations\n</behavior>\n</system>`\n\n// ============================================\n// AUTO-DRAFT PROMPTS\n// ============================================\n\n/**\n * Default template for auto-drafting from news articles.\n * Placeholders: {{AUTO_DRAFT_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}, {{TOPIC_NAME}}, {{ARTICLE_TITLE}}, {{ARTICLE_SUMMARY}}, {{ARTICLE_URL}}, {{AUTO_DRAFT_WORD_COUNT}}\n */\nexport const DEFAULT_AUTO_DRAFT_TEMPLATE = `<system>\n<role>Expert essay writer creating engaging content from news articles</role>\n\n<auto_draft_rules>\n{{AUTO_DRAFT_RULES}}\n</auto_draft_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<source_article>\n<topic>{{TOPIC_NAME}}</topic>\n<title>{{ARTICLE_TITLE}}</title>\n<summary>{{ARTICLE_SUMMARY}}</summary>\n<url>{{ARTICLE_URL}}</url>\n</source_article>\n\n<constraints>\n<word_count>{{AUTO_DRAFT_WORD_COUNT}}</word_count>\n</constraints>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Your Title Here]\nLine 2: *[Your subtitle here]*\nLine 3: (blank line)\nLine 4+: Essay body in markdown\n\n<title_guidelines>\n- Be SPECIFIC about the news angle, not generic\n- Include a concrete detail or unexpected element\n- Create curiosity or make a bold claim\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that hooks the reader\n- Tease the main argument or unique perspective\n- Create tension, curiosity, or promise value\n</subtitle_guidelines>\n</output_format>\n</system>`\n\n// ============================================\n// PLAN PROMPTS\n// ============================================\n\n/**\n * Default template for essay outline generation.\n * Placeholders: {{PLAN_RULES}}, {{STYLE_EXAMPLES}}\n */\nexport const DEFAULT_PLAN_TEMPLATE = `<system>\n<role>Writing assistant that creates essay outlines</role>\n\n<critical>\nWrap your ENTIRE response in <plan> tags. Output NOTHING outside the tags.\n</critical>\n\n<rules>\n{{PLAN_RULES}}\n</rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n</system>`\n\n/**\n * Default rules for plan generation format.\n */\nexport const DEFAULT_PLAN_RULES = `<format>\nSTRICT LIMIT: Maximum 3 bullets per section. Most sections should have 1-2 bullets.\n\n<plan>\n# Essay Title\n*One-line subtitle*\n\n## Section Name\n- Key point\n\n## Section Name\n- Key point\n- Another point\n\n## Section Name\n- Key point\n</plan>\n</format>\n\n<constraints>\n- 4-6 section headings (## lines)\n- 1-3 bullets per section — NEVER 4 or more\n- Bullets are short phrases, not sentences\n- No prose, no paragraphs, no explanations\n- When revising, output the complete updated plan\n</constraints>\n\n<title_guidelines>\n- Be SPECIFIC about the essay's angle\n- Include a concrete detail or unexpected element\n- Avoid generic patterns like \"The Power of\", \"Why X Matters\"\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that previews the main argument\n- Create curiosity or make a bold claim\n</subtitle_guidelines>`\n\n// ============================================\n// AGENT MODE PROMPTS\n// ============================================\n\n/**\n * Default template for agent mode (direct editing).\n * No placeholders - this is appended to chat prompt when in agent mode.\n */\nexport const DEFAULT_AGENT_TEMPLATE = `<agent_mode>\nYou are in AGENT MODE - you can directly edit the essay. Wrap edits in :::edit and ::: tags with a JSON object.\n\nEDIT COMMANDS (use valid JSON):\n\n1. Replace specific text:\n:::edit\n{\"type\": \"replace_section\", \"find\": \"exact text to find\", \"replace\": \"replacement text\"}\n:::\n\n2. Replace entire essay:\n:::edit\n{\"type\": \"replace_all\", \"title\": \"New Title\", \"subtitle\": \"New subtitle\", \"markdown\": \"Full essay content...\"}\n:::\n\n3. Insert text:\n:::edit\n{\"type\": \"insert\", \"position\": \"after\", \"find\": \"text to find\", \"replace\": \"text to insert\"}\n:::\n(position can be: \"before\", \"after\", \"start\", \"end\")\n\n4. Delete text:\n:::edit\n{\"type\": \"delete\", \"find\": \"text to delete\"}\n:::\n\nRULES:\n- Use EXACT text matches for \"find\" - copy precisely from the essay\n- One edit block per change\n- You can include multiple edit blocks in one response\n- Add brief explanation before/after edit blocks\n- Edits are applied automatically - the user will see the changes\n</agent_mode>`\n\n// ============================================\n// EXPAND PLAN PROMPTS\n// ============================================\n\n/**\n * Default template for expanding outlines into full essays.\n * Placeholders: {{RULES}}, {{STYLE_EXAMPLES}}, {{PLAN}}\n */\nexport const DEFAULT_EXPAND_PLAN_TEMPLATE = `<system>\n<role>Writing assistant that expands essay outlines into full drafts</role>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<plan_to_expand>\n{{PLAN}}\n</plan_to_expand>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Title from plan, refined if needed]\nLine 2: *[Subtitle from plan, refined if needed]*\nLine 3: (blank line)\nLine 4+: Essay body with ## section headings\n\n<requirements>\n- Use the section headers from the plan as H2 headings\n- Expand each section's bullet points into full paragraphs\n- Match the author's voice and style from the examples\n- Output ONLY markdown — no preamble, no \"Here is...\", no explanations\n</requirements>\n\n<title_refinement>\nIf the plan title is generic, improve it to be:\n- More specific and concrete\n- Curiosity-inducing or bold\n- 5-12 words\n</title_refinement>\n</output_format>\n</system>`\n\n// ============================================\n// SEARCH MODE PROMPTS\n// ============================================\n\n/**\n * Default template for search-only mode (fact-finding).\n * Used when user wants to research a topic before writing.\n */\nexport const DEFAULT_SEARCH_ONLY_PROMPT = `You are a research assistant helping a writer gather facts and information.\n\nYour task is to provide accurate, well-sourced information to help with essay writing.\n\nGuidelines:\n- Focus on facts, data, and specific examples\n- Include dates, names, and sources when relevant\n- Present information clearly and concisely\n- Note any conflicting information or debates\n- Suggest interesting angles or perspectives the writer might explore\n\nDo NOT write the essay - just provide research findings.`\n\n// ============================================\n// PROMPT BUILDERS\n// ============================================\n\nexport interface EssayContext {\n title?: string\n subtitle?: string\n markdown?: string\n}\n\nexport interface StyleContext {\n rules?: string\n chatRules?: string\n rewriteRules?: string\n planRules?: string\n styleExamples?: string\n}\n\n/**\n * Build the search-only prompt for fact-finding queries.\n */\nexport function buildSearchOnlyPrompt(query: string): string {\n return `${DEFAULT_SEARCH_ONLY_PROMPT}\n\nResearch Topic: ${query}`\n}\n\n/**\n * Build the full plan prompt with context and essay state.\n */\nexport function buildPlanPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n let prompt = DEFAULT_PLAN_TEMPLATE\n .replace('{{PLAN_RULES}}', context.planRules || DEFAULT_PLAN_RULES)\n .replace('{{STYLE_EXAMPLES}}', context.styleExamples || 'No style examples provided.')\n\n if (essayContext) {\n const currentState = formatEssayContext(essayContext)\n prompt += `\\n\\n<current_essay>\\n${currentState}\\n</current_essay>`\n }\n\n return prompt\n}\n\n/**\n * Build the chat prompt with essay context.\n */\nexport function buildChatPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n let essayContextStr = 'No essay currently open.'\n if (essayContext) {\n essayContextStr = formatEssayContext(essayContext)\n }\n\n return DEFAULT_CHAT_TEMPLATE\n .replace('{{CHAT_RULES}}', context.chatRules || 'Be helpful and concise.')\n .replace('{{ESSAY_CONTEXT}}', essayContextStr)\n}\n\n/**\n * Build the agent chat prompt for direct editing mode.\n */\nexport function buildAgentChatPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n const basePrompt = buildChatPrompt(context, essayContext)\n return basePrompt + '\\n\\n' + DEFAULT_AGENT_TEMPLATE\n}\n\n/**\n * Build the generate prompt for essay creation.\n */\nexport function buildGeneratePrompt(\n context: StyleContext,\n wordCount: number = 800\n): string {\n return DEFAULT_GENERATE_TEMPLATE\n .replace('{{RULES}}', context.rules || '')\n .replace('{{WORD_COUNT}}', wordCount.toString())\n}\n\n/**\n * Build the rewrite prompt.\n */\nexport function buildRewritePrompt(context: StyleContext): string {\n return DEFAULT_REWRITE_TEMPLATE\n .replace('{{REWRITE_RULES}}', context.rewriteRules || 'Improve clarity and flow.')\n}\n\n/**\n * Build the expand plan prompt.\n */\nexport function buildExpandPlanPrompt(\n context: StyleContext,\n plan: string\n): string {\n return DEFAULT_EXPAND_PLAN_TEMPLATE\n .replace('{{RULES}}', context.rules || '')\n .replace('{{STYLE_EXAMPLES}}', context.styleExamples || 'No style examples provided.')\n .replace('{{PLAN}}', plan)\n}\n\n/**\n * Format essay context for inclusion in prompts.\n */\nfunction formatEssayContext(essayContext: EssayContext): string {\n const parts: string[] = []\n \n if (essayContext.title) {\n parts.push(`Title: ${essayContext.title}`)\n }\n if (essayContext.subtitle) {\n parts.push(`Subtitle: ${essayContext.subtitle}`)\n }\n if (essayContext.markdown) {\n parts.push(`Content:\\n${essayContext.markdown}`)\n }\n \n return parts.join('\\n') || 'Empty essay'\n}\n","/** Word count options for essay generation */\nexport const LENGTH_OPTIONS = [300, 500, 800, 1000] as const\nexport type LengthOption = (typeof LENGTH_OPTIONS)[number]\n\n/** Full model definition with provider details */\nexport interface AIModel {\n id: string\n name: string\n provider: 'anthropic' | 'openai'\n modelId: string\n description?: string\n searchModel: 'native' | null // 'native' for GPT (uses tools), null for Claude (uses 2-call flow)\n}\n\nexport const AI_MODELS: AIModel[] = [\n {\n id: 'claude-sonnet',\n name: 'Sonnet 4.5',\n provider: 'anthropic',\n modelId: 'claude-sonnet-4-5-20250929',\n description: 'Fast, capable, best value',\n searchModel: null, // No native search, uses search-first flow\n },\n {\n id: 'claude-opus',\n name: 'Opus 4.5',\n provider: 'anthropic',\n modelId: 'claude-opus-4-5-20251101',\n description: 'Highest quality, slower',\n searchModel: null,\n },\n {\n id: 'gpt-5.2',\n name: 'GPT-5.2',\n provider: 'openai',\n modelId: 'gpt-5.2',\n description: 'Latest OpenAI flagship',\n searchModel: 'native', // Uses tools-based web search\n },\n {\n id: 'gpt-5-mini',\n name: 'GPT-5 Mini',\n provider: 'openai',\n modelId: 'gpt-5-mini',\n description: 'Fast and cost-efficient',\n searchModel: 'native', // Uses tools-based web search\n },\n]\n\nexport type ModelId = (typeof AI_MODELS)[number]['id']\n\n/** Subset of AIModel for UI dropdowns */\nexport interface AIModelOption {\n id: string\n name: string\n description?: string\n hasNativeSearch: boolean\n}\n\nexport function getModel(id: string): AIModel | undefined {\n return AI_MODELS.find(m => m.id === id)\n}\n\nexport function getDefaultModel(): AIModel {\n return AI_MODELS[0]\n}\n\n/** Check if a model has native search (via tools, not a separate model) */\nexport function modelHasNativeSearch(id: string): boolean {\n return AI_MODELS.find(m => m.id === id)?.searchModel === 'native'\n}\n\n/** Get the search model variant for a model, or null if it uses 2-call flow */\nexport function getSearchModel(id: string): string | null {\n return AI_MODELS.find(m => m.id === id)?.searchModel ?? null\n}\n\n/**\n * Resolve a model ID, falling back to database default or hardcoded default.\n * Used by AI API routes to avoid duplicating model resolution logic.\n * \n * @param providedModelId - Optional model ID from request\n * @param getDefaultModelId - Async function to get default from DB (avoids Prisma import here)\n * @returns Resolved AIModel\n * @throws Error if model not found\n */\nexport async function resolveModel(\n providedModelId: string | undefined,\n getDefaultModelId: () => Promise<string | null>\n): Promise<AIModel> {\n let modelId = providedModelId\n \n if (!modelId) {\n modelId = (await getDefaultModelId()) || 'claude-sonnet'\n }\n \n const model = getModel(modelId)\n if (!model) {\n throw new Error(`Unknown model: ${modelId}. Available: ${AI_MODELS.map(m => m.id).join(', ')}`)\n }\n \n return model\n}\n\n/** Convert AIModel to AIModelOption for UI */\nexport function toModelOption(model: AIModel): AIModelOption {\n return {\n id: model.id,\n name: model.name,\n description: model.description,\n hasNativeSearch: model.searchModel === 'native',\n }\n}\n\n/** Get all models as options for UI dropdowns */\nexport function getModelOptions(): AIModelOption[] {\n return AI_MODELS.map(toModelOption)\n}\n","import Anthropic from '@anthropic-ai/sdk'\nimport OpenAI from 'openai'\nimport { getModel } from './models'\n\n/** Message format for chat conversations */\nexport interface ChatMessage {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\ninterface StreamOptions {\n model: string\n messages: ChatMessage[]\n anthropicKey?: string\n openaiKey?: string\n maxTokens?: number\n useThinking?: boolean\n useWebSearch?: boolean\n}\n\ninterface GenerateResult {\n text: string\n inputTokens?: number\n outputTokens?: number\n}\n\n/**\n * Get API key for a provider, checking DB first then falling back to env var.\n * Accepts a prisma client to avoid importing it directly.\n */\nexport async function getApiKey(\n provider: 'anthropic' | 'openai',\n prisma?: { aISettings?: { findUnique: (args: any) => Promise<any> } }\n): Promise<string | null> {\n // Try AISettings DB first if prisma is provided\n if (prisma?.aISettings) {\n try {\n const settings = await prisma.aISettings.findUnique({\n where: { id: 'default' },\n })\n \n if (provider === 'anthropic' && settings?.anthropicKey) {\n return settings.anthropicKey\n }\n if (provider === 'openai' && settings?.openaiKey) {\n return settings.openaiKey\n }\n } catch {\n // DB lookup failed, fall back to env vars\n }\n }\n \n // Fall back to env vars\n if (provider === 'anthropic') {\n return process.env.ANTHROPIC_API_KEY || null\n }\n return process.env.OPENAI_API_KEY || null\n}\n\n/**\n * Fetch web search results using OpenAI's Responses API with web_search tool.\n * Returns a summary of search results to be used as context.\n */\nasync function fetchSearchResults(query: string, openaiKey?: string): Promise<string | null> {\n try {\n console.log('[Web Search] Fetching search results for:', query.slice(0, 100))\n const openai = new OpenAI({\n ...(openaiKey && { apiKey: openaiKey }),\n })\n \n const response = await (openai as any).responses.create({\n model: 'gpt-5-mini',\n input: `You are a research assistant. Provide a concise summary of the most relevant and recent information from the web about the following query. Include key facts, dates, and sources when available. Keep your response under 500 words.\\n\\nQuery: ${query}`,\n tools: [{ type: 'web_search' }],\n })\n \n const result = response.output_text || null\n console.log('[Web Search] Got results:', result ? `${result.length} chars` : 'null')\n return result\n } catch (error) {\n console.error('[Web Search] Failed:', error)\n return null\n }\n}\n\n/**\n * Extract the most recent user message to use as search query.\n */\nfunction extractSearchQuery(messages: ChatMessage[]): string {\n const userMessages = messages.filter(m => m.role === 'user')\n return userMessages[userMessages.length - 1]?.content || ''\n}\n\n/**\n * Generate text using the specified model (non-streaming).\n * Used for search mode and other non-streaming requests.\n */\nexport async function generate(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: {\n anthropicKey?: string\n openaiKey?: string\n maxTokens?: number\n useWebSearch?: boolean\n } = {}\n): Promise<GenerateResult> {\n const model = getModel(modelId)\n if (!model) {\n throw new Error(`Unknown model: ${modelId}`)\n }\n\n if (model.provider === 'anthropic') {\n return generateWithAnthropic(model.modelId, systemPrompt, userPrompt, options)\n }\n return generateWithOpenAI(model.modelId, systemPrompt, userPrompt, options)\n}\n\nasync function generateWithAnthropic(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: { anthropicKey?: string; maxTokens?: number }\n): Promise<GenerateResult> {\n const anthropic = new Anthropic({\n ...(options.anthropicKey && { apiKey: options.anthropicKey }),\n })\n\n const response = await anthropic.messages.create({\n model: modelId,\n max_tokens: options.maxTokens || 4096,\n system: systemPrompt,\n messages: [{ role: 'user', content: userPrompt }],\n })\n\n const textContent = response.content.find(c => c.type === 'text')\n if (!textContent || textContent.type !== 'text') {\n throw new Error('No text content in response')\n }\n\n return {\n text: textContent.text,\n inputTokens: response.usage?.input_tokens,\n outputTokens: response.usage?.output_tokens,\n }\n}\n\nasync function generateWithOpenAI(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: { openaiKey?: string; maxTokens?: number; useWebSearch?: boolean }\n): Promise<GenerateResult> {\n const openai = new OpenAI({\n ...(options.openaiKey && { apiKey: options.openaiKey }),\n })\n\n // Use Responses API for web search\n if (options.useWebSearch) {\n const response = await (openai as any).responses.create({\n model: modelId,\n instructions: systemPrompt,\n input: userPrompt,\n max_output_tokens: options.maxTokens || 4096,\n tools: [{ type: 'web_search' }],\n })\n\n const textOutput = response.output?.find((item: { type: string }) => item.type === 'message')\n const content = textOutput?.content?.find((c: { type: string }) => c.type === 'output_text')?.text\n\n if (!content) {\n throw new Error('No content in response')\n }\n\n return {\n text: content,\n inputTokens: response.usage?.input_tokens,\n outputTokens: response.usage?.output_tokens,\n }\n }\n\n // Standard chat completions\n const response = await openai.chat.completions.create({\n model: modelId,\n max_completion_tokens: options.maxTokens || 4096,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: userPrompt },\n ],\n })\n\n const content = response.choices[0]?.message?.content\n if (!content) {\n throw new Error('No content in response')\n }\n\n return {\n text: content,\n inputTokens: response.usage?.prompt_tokens,\n outputTokens: response.usage?.completion_tokens,\n }\n}\n\nexport async function createStream(options: StreamOptions): Promise<ReadableStream> {\n const modelConfig = getModel(options.model)\n if (!modelConfig) {\n throw new Error(`Unknown model: ${options.model}`)\n }\n\n // For Anthropic with web search enabled, fetch search results first using OpenAI\n let searchContext = ''\n if (options.useWebSearch && modelConfig.provider === 'anthropic') {\n const query = extractSearchQuery(options.messages)\n if (query) {\n const searchResults = await fetchSearchResults(query, options.openaiKey)\n if (searchResults) {\n searchContext = `\\n\\n<web_search_results>\\n${searchResults}\\n</web_search_results>\\n\\nUse the search results above to inform your response with current, accurate information.`\n }\n }\n }\n\n if (modelConfig.provider === 'anthropic') {\n return createAnthropicStream(options, modelConfig.modelId, searchContext)\n } else {\n return createOpenAIStream(options, modelConfig.modelId, options.useWebSearch)\n }\n}\n\n/** Helper to safely enqueue data to controller */\nfunction safeEnqueue(controller: ReadableStreamDefaultController, data: Uint8Array): boolean {\n try {\n controller.enqueue(data)\n return true\n } catch {\n // Controller already closed\n return false\n }\n}\n\n/** Helper to safely close controller */\nfunction safeClose(controller: ReadableStreamDefaultController): void {\n try {\n controller.close()\n } catch {\n // Controller already closed\n }\n}\n\nasync function createAnthropicStream(options: StreamOptions, modelId: string, searchContext: string = ''): Promise<ReadableStream> {\n const anthropic = new Anthropic({\n ...(options.anthropicKey && { apiKey: options.anthropicKey }),\n })\n\n const systemMessage = (options.messages.find(m => m.role === 'system')?.content || '') + searchContext\n const chatMessages = options.messages\n .filter(m => m.role !== 'system')\n .map(m => ({ role: m.role as 'user' | 'assistant', content: m.content }))\n\n const requestParams: any = {\n model: modelId,\n max_tokens: options.maxTokens || 4096,\n system: systemMessage,\n messages: chatMessages,\n }\n\n if (options.useThinking && (modelId.includes('claude-sonnet') || modelId.includes('claude-opus'))) {\n requestParams.thinking = {\n type: 'enabled',\n budget_tokens: 10000,\n }\n requestParams.max_tokens = Math.max(requestParams.max_tokens, 16000)\n }\n\n try {\n const stream = await anthropic.messages.stream(requestParams)\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const event of stream) {\n if (event.type === 'content_block_delta') {\n const delta = event.delta as { type: string; text?: string; thinking?: string }\n if (delta.type === 'text_delta' && delta.text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text: delta.text })}\\n\\n`))) {\n return // Controller closed, stop processing\n }\n } else if (delta.type === 'thinking_delta' && delta.thinking) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ thinking: delta.thinking })}\\n\\n`))) {\n return\n }\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[Anthropic Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Anthropic API error'\n console.error('[Anthropic API Error]', error)\n throw new Error(errorMessage)\n }\n}\n\nasync function createOpenAIStream(options: StreamOptions, modelId: string, useWebSearch: boolean = false): Promise<ReadableStream> {\n const openai = new OpenAI({\n ...(options.openaiKey && { apiKey: options.openaiKey }),\n })\n\n if (useWebSearch) {\n return createOpenAIResponsesStream(openai, options, modelId)\n }\n\n const requestParams: any = {\n model: modelId,\n messages: options.messages,\n max_completion_tokens: options.maxTokens || 4096,\n stream: true,\n }\n\n try {\n const stream = await openai.chat.completions.create(requestParams) as unknown as AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const chunk of stream) {\n const text = chunk.choices[0]?.delta?.content\n if (text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text })}\\n\\n`))) {\n return\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[OpenAI Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'OpenAI API error'\n console.error('[OpenAI API Error]', error)\n throw new Error(errorMessage)\n }\n}\n\nasync function createOpenAIResponsesStream(openai: OpenAI, options: StreamOptions, modelId: string): Promise<ReadableStream> {\n const systemMessage = options.messages.find(m => m.role === 'system')?.content || ''\n const conversationMessages = options.messages.filter(m => m.role !== 'system')\n \n const lastUserMessage = conversationMessages[conversationMessages.length - 1]?.content || ''\n const conversationContext = conversationMessages.slice(0, -1)\n .map(m => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}`)\n .join('\\n\\n')\n \n const fullInput = conversationContext \n ? `${systemMessage}\\n\\nPrevious conversation:\\n${conversationContext}\\n\\nUser: ${lastUserMessage}`\n : `${systemMessage}\\n\\n${lastUserMessage}`\n\n try {\n const response = await (openai as any).responses.create({\n model: modelId,\n input: fullInput,\n tools: [{ type: 'web_search' }],\n stream: true,\n })\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const event of response) {\n if (event.type === 'response.output_text.delta') {\n const text = event.delta\n if (text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text })}\\n\\n`))) {\n return\n }\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[OpenAI Responses Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'OpenAI Responses API error'\n console.error('[OpenAI Responses API Error]', error)\n throw new Error(errorMessage)\n }\n}\n","import { \n DEFAULT_GENERATE_TEMPLATE, \n DEFAULT_CHAT_TEMPLATE, \n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n} from './prompts'\n\n/**\n * Build a system prompt for essay generation.\n */\nexport function buildGeneratePrompt(options: {\n rules?: string\n template?: string | null\n wordCount?: number\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_GENERATE_TEMPLATE\n \n return template\n .replace('{{RULES}}', options.rules || '')\n .replace('{{WORD_COUNT}}', String(options.wordCount || 800))\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for chat interactions.\n */\nexport function buildChatPrompt(options: {\n chatRules?: string\n rules?: string\n template?: string | null\n essayContext?: { title: string; subtitle?: string; markdown: string } | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_CHAT_TEMPLATE\n \n let essaySection = ''\n if (options.essayContext) {\n essaySection = `\nCurrent essay being edited:\nTitle: ${options.essayContext.title}\n${options.essayContext.subtitle ? `Subtitle: ${options.essayContext.subtitle}` : ''}\n\nContent:\n${options.essayContext.markdown}\n`\n }\n \n return template\n .replace('{{CHAT_RULES}}', options.chatRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{ESSAY_CONTEXT}}', essaySection)\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for expanding a plan into a full essay.\n */\nexport function buildExpandPlanPrompt(options: {\n rules?: string\n template?: string | null\n plan: string\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_EXPAND_PLAN_TEMPLATE\n \n return template\n .replace('{{RULES}}', options.rules || '')\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n .replace('{{PLAN}}', options.plan)\n}\n\n/**\n * Build a system prompt for plan/outline generation.\n */\nexport function buildPlanPrompt(options: {\n planRules?: string\n template?: string | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_PLAN_TEMPLATE\n const rules = options.planRules || DEFAULT_PLAN_RULES\n \n return template\n .replace('{{PLAN_RULES}}', rules)\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for text rewriting.\n */\nexport function buildRewritePrompt(options: {\n rewriteRules?: string\n rules?: string\n template?: string | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_REWRITE_TEMPLATE\n \n return template\n .replace('{{REWRITE_RULES}}', options.rewriteRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for auto-drafting essays from news articles.\n */\nexport function buildAutoDraftPrompt(options: {\n autoDraftRules?: string\n rules?: string\n template?: string | null\n wordCount?: number\n styleExamples?: string\n // Article context\n topicName?: string\n articleTitle?: string\n articleSummary?: string\n articleUrl?: string\n}): string {\n const template = options.template || DEFAULT_AUTO_DRAFT_TEMPLATE\n \n return template\n .replace('{{AUTO_DRAFT_RULES}}', options.autoDraftRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{AUTO_DRAFT_WORD_COUNT}}', String(options.wordCount || 800))\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n .replace('{{TOPIC_NAME}}', options.topicName || '')\n .replace('{{ARTICLE_TITLE}}', options.articleTitle || '')\n .replace('{{ARTICLE_SUMMARY}}', options.articleSummary || '')\n .replace('{{ARTICLE_URL}}', options.articleUrl || '')\n}\n","import type { Browser } from 'puppeteer-core'\n\n// Regex to match URLs in text - supports both with and without protocol\n// Matches: https://example.com, http://example.com, www.example.com, example.com/path\nconst URL_WITH_PROTOCOL = /https?:\\/\\/[^\\s<>\\[\\]()]+(?:\\([^\\s<>\\[\\]()]*\\))?[^\\s<>\\[\\]().,;:!?\"']*(?<![.,;:!?\"'])/gi\nconst URL_WITHOUT_PROTOCOL = /(?:www\\.)[a-zA-Z0-9][-a-zA-Z0-9]*(?:\\.[a-zA-Z]{2,})+(?:\\/[^\\s<>\\[\\]()]*)?/gi\nconst DOMAIN_ONLY = /(?<![/@])(?:[a-zA-Z0-9][-a-zA-Z0-9]*\\.)+(?:com|org|net|edu|gov|io|co|app|dev|news|info)(?:\\/[^\\s<>\\[\\]()]*)?(?![a-zA-Z])/gi\n\n// Puppeteer configuration\nconst PUPPETEER_TIMEOUT = 15000 // 15 seconds max for page load\nconst CONTENT_WAIT_TIME = 2000 // Wait 2s after load for JS to render\n\n/**\n * Detect if we're running in a serverless environment (Vercel, AWS Lambda, etc.)\n * In serverless, we use @sparticuz/chromium. Locally, we use regular puppeteer.\n */\nfunction isServerlessEnvironment(): boolean {\n return !!(\n process.env.AWS_LAMBDA_FUNCTION_NAME ||\n process.env.VERCEL ||\n process.env.NETLIFY ||\n process.env.AWS_EXECUTION_ENV\n )\n}\n\n/**\n * Extract URLs from text.\n * Supports URLs with protocol (https://), www prefix, or bare domains.\n */\nexport function extractUrls(text: string): string[] {\n const urls: string[] = []\n \n // Match URLs with protocol first (highest priority)\n const withProtocol = text.match(URL_WITH_PROTOCOL)\n if (withProtocol) urls.push(...withProtocol)\n \n // Match www. URLs\n const wwwUrls = text.match(URL_WITHOUT_PROTOCOL)\n if (wwwUrls) {\n for (const url of wwwUrls) {\n // Add https:// prefix for consistency\n const normalized = `https://${url}`\n if (!urls.some(u => u.includes(url))) {\n urls.push(normalized)\n }\n }\n }\n \n // Match bare domain URLs (newsday.com, example.org, etc.)\n const bareUrls = text.match(DOMAIN_ONLY)\n if (bareUrls) {\n for (const url of bareUrls) {\n // Add https:// prefix for consistency\n const normalized = `https://${url}`\n if (!urls.some(u => u.includes(url.split('/')[0]))) {\n urls.push(normalized)\n }\n }\n }\n \n return [...new Set(urls)]\n}\n\nexport interface FetchedContent {\n url: string\n title?: string\n content: string\n error?: string\n}\n\n/**\n * Simple HTML text extraction without JSDOM.\n * Used as fallback when JSDOM fails (common with npm link).\n */\nfunction extractTextFromHtml(html: string, url: string): FetchedContent {\n // Extract title\n const titleMatch = html.match(/<title[^>]*>([^<]+)<\\/title>/i)\n const title = titleMatch ? titleMatch[1].trim() : undefined\n\n // Remove scripts, styles, and other non-content elements\n let text = html\n .replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, '')\n .replace(/<style[^>]*>[\\s\\S]*?<\\/style>/gi, '')\n .replace(/<nav[^>]*>[\\s\\S]*?<\\/nav>/gi, '')\n .replace(/<footer[^>]*>[\\s\\S]*?<\\/footer>/gi, '')\n .replace(/<header[^>]*>[\\s\\S]*?<\\/header>/gi, '')\n .replace(/<aside[^>]*>[\\s\\S]*?<\\/aside>/gi, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n // Replace tags with appropriate spacing\n .replace(/<(p|div|br|h[1-6]|li|tr)[^>]*>/gi, '\\n')\n .replace(/<[^>]+>/g, ' ')\n // Decode common HTML entities\n .replace(/&nbsp;/g, ' ')\n .replace(/&amp;/g, '&')\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&quot;/g, '\"')\n .replace(/&#39;/g, \"'\")\n .replace(/&[a-z]+;/gi, ' ')\n // Clean up whitespace\n .replace(/\\s+/g, ' ')\n .replace(/\\n\\s+/g, '\\n')\n .replace(/\\n+/g, '\\n')\n .trim()\n\n // Limit content\n if (text.length > 4000) {\n text = text.slice(0, 4000) + '\\n\\n[Content truncated...]'\n }\n\n if (text.length < 50) {\n return { url, content: '', error: 'Could not extract meaningful content' }\n }\n\n return { url, title, content: text }\n}\n\n/**\n * Parse HTML with Mozilla Readability.\n * Falls back to simple regex extraction if JSDOM fails.\n */\nasync function parseWithReadability(html: string, url: string): Promise<FetchedContent> {\n try {\n const { JSDOM } = await import('jsdom')\n const { Readability } = await import('@mozilla/readability')\n\n // CRITICAL: Do NOT load any external resources\n // Explicitly set resources to undefined to prevent Next.js/npm link issues\n const doc = new JSDOM(html, { \n url,\n resources: undefined, // Don't load ANY external resources (stylesheets, etc.)\n runScripts: undefined, // Don't run any scripts\n })\n const reader = new Readability(doc.window.document)\n const article = reader.parse()\n\n if (!article || !article.textContent) {\n // Readability couldn't parse - try simple extraction\n console.log('[Readability] No article content, falling back to simple extraction')\n return extractTextFromHtml(html, url)\n }\n\n // Limit content to avoid token bloat (~4000 chars ≈ 1000 tokens)\n let content = article.textContent.trim()\n if (content.length > 4000) {\n content = content.slice(0, 4000) + '\\n\\n[Content truncated...]'\n }\n\n return {\n url,\n title: article.title || undefined,\n content,\n }\n } catch (error) {\n // JSDOM failed (common with npm link due to native module issues)\n console.error('[JSDOM] Failed, using simple extraction:', error instanceof Error ? error.message : error)\n return extractTextFromHtml(html, url)\n }\n}\n\n/**\n * Fetch URL content using Puppeteer (headless browser).\n * This handles JavaScript-rendered pages and some paywalls.\n * \n * Environment detection:\n * - Local development: Uses regular `puppeteer` (auto-downloads Chrome)\n * - Serverless (Vercel/Lambda): Uses `@sparticuz/chromium` + `puppeteer-core`\n */\nasync function fetchWithPuppeteer(url: string): Promise<FetchedContent> {\n let browser: Browser | null = null\n const isServerless = isServerlessEnvironment()\n \n try {\n console.log(`[Puppeteer] Launching browser for: ${url} (serverless: ${isServerless})`)\n \n if (isServerless) {\n // Serverless environment: use @sparticuz/chromium\n const chromium = await import('@sparticuz/chromium')\n const puppeteerCore = await import('puppeteer-core')\n \n const executablePath = await chromium.default.executablePath()\n \n browser = await puppeteerCore.default.launch({\n args: chromium.default.args,\n defaultViewport: chromium.default.defaultViewport,\n executablePath,\n headless: chromium.default.headless,\n })\n } else {\n // Local development: use regular puppeteer (has its own Chrome)\n try {\n const puppeteer = await import('puppeteer')\n \n browser = await puppeteer.default.launch({\n headless: true,\n args: [\n '--no-sandbox',\n '--disable-setuid-sandbox',\n '--disable-dev-shm-usage',\n '--disable-accelerated-2d-canvas',\n '--disable-gpu',\n ],\n })\n } catch (puppeteerImportError) {\n // Puppeteer import/launch failed - this can happen with npm link or missing Chrome\n console.error('[Puppeteer] Import/launch failed:', puppeteerImportError)\n return { url, content: '', error: 'Puppeteer unavailable - falling back to simple fetch' }\n }\n }\n \n const page = await browser.newPage()\n \n // Set viewport and user agent\n await page.setViewport({ width: 1920, height: 1080 })\n await page.setUserAgent(\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'\n )\n \n // Block unnecessary resources to speed up loading\n await page.setRequestInterception(true)\n page.on('request', (req) => {\n const resourceType = req.resourceType()\n if (['image', 'stylesheet', 'font', 'media'].includes(resourceType)) {\n req.abort()\n } else {\n req.continue()\n }\n })\n \n // Navigate with timeout\n await page.goto(url, {\n waitUntil: 'networkidle2',\n timeout: PUPPETEER_TIMEOUT,\n })\n \n // Wait a bit for any remaining JS to execute\n await new Promise(resolve => setTimeout(resolve, CONTENT_WAIT_TIME))\n \n // Get the rendered HTML\n const html = await page.content()\n \n // Close browser before parsing to free resources\n await browser.close()\n browser = null\n \n console.log('[Puppeteer] Got HTML, parsing with Readability...')\n \n // Parse with Readability\n return await parseWithReadability(html, url)\n \n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Puppeteer error'\n console.error('[Puppeteer] Failed:', errorMessage)\n return { url, content: '', error: `Puppeteer: ${errorMessage}` }\n } finally {\n // Ensure browser is closed even on error\n if (browser) {\n try {\n await browser.close()\n } catch {\n // Ignore close errors\n }\n }\n }\n}\n\n/**\n * Fetch URL content using simple HTTP request + Mozilla Readability.\n * This is the fallback method when Puppeteer fails or isn't available.\n */\nasync function fetchWithSimpleRequest(url: string): Promise<FetchedContent> {\n try {\n console.log('[SimpleFetch] Fetching:', url)\n \n const res = await fetch(url, {\n headers: {\n 'User-Agent':\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.9',\n },\n })\n\n if (!res.ok) {\n return { url, content: '', error: `HTTP ${res.status}` }\n }\n\n const html = await res.text()\n return parseWithReadability(html, url)\n } catch (error) {\n return {\n url,\n content: '',\n error: error instanceof Error ? error.message : 'Failed to fetch',\n }\n }\n}\n\n/**\n * Fetch URL content - tries Puppeteer first for JavaScript-rendered pages,\n * falls back to simple HTTP request if Puppeteer fails.\n */\nexport async function fetchUrlContent(url: string): Promise<FetchedContent> {\n console.log('[URL Extractor] Fetching content from:', url)\n \n // Try Puppeteer first (better for JS-rendered and paywalled sites)\n const puppeteerResult = await fetchWithPuppeteer(url)\n \n // Check if Puppeteer succeeded with actual content\n if (!puppeteerResult.error && puppeteerResult.content && puppeteerResult.content.length > 100) {\n console.log('[URL Extractor] Puppeteer succeeded, got', puppeteerResult.content.length, 'chars')\n return puppeteerResult\n }\n \n // Puppeteer failed or got minimal content - try simple fetch as fallback\n console.log('[URL Extractor] Puppeteer failed or got minimal content, trying simple fetch...')\n const simpleResult = await fetchWithSimpleRequest(url)\n \n // Return whichever got more content\n if (simpleResult.content && simpleResult.content.length > (puppeteerResult.content?.length || 0)) {\n console.log('[URL Extractor] Simple fetch got more content:', simpleResult.content.length, 'chars')\n return simpleResult\n }\n \n // Return Puppeteer result (even if it failed, it has better error info)\n if (puppeteerResult.content && puppeteerResult.content.length > 0) {\n return puppeteerResult\n }\n \n // Both failed - return the simple fetch error (usually more informative)\n return simpleResult.error ? simpleResult : puppeteerResult\n}\n\n/**\n * Extract URLs from text and fetch their content.\n * Returns fetched content for all URLs found.\n */\nexport async function extractAndFetchUrls(text: string): Promise<FetchedContent[]> {\n const urls = extractUrls(text)\n if (urls.length === 0) return []\n\n // Limit to 3 URLs to avoid abuse and long waits\n const toFetch = urls.slice(0, 3)\n\n // Fetch in parallel for speed\n const results = await Promise.all(toFetch.map(url => fetchUrlContent(url)))\n\n return results\n}\n\n/**\n * Build context string from fetched URLs for AI prompts.\n */\nexport function buildUrlContext(fetched: FetchedContent[]): string {\n const successful = fetched.filter((f) => !f.error && f.content)\n if (successful.length === 0) return ''\n\n return `\n<referenced_urls>\n${successful\n .map(\n (f) =>\n `<url src=\"${f.url}\"${f.title ? ` title=\"${f.title}\"` : ''}>\n${f.content}\n</url>`\n )\n .join('\\n\\n')}\n</referenced_urls>\n\nUse the content from these URLs when relevant to the conversation.`\n}\n","import { createStream } from './provider'\nimport { buildGeneratePrompt, buildExpandPlanPrompt } from './builders'\nimport { extractAndFetchUrls } from '../lib/url-extractor'\n\ninterface GenerateOptions {\n prompt: string\n model: string\n wordCount?: number\n rules?: string\n template?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n useWebSearch?: boolean // Controls ALL internet access: URL extraction AND web search\n useThinking?: boolean\n}\n\nexport async function generateStream(options: GenerateOptions): Promise<ReadableStream> {\n const systemPrompt = buildGeneratePrompt({\n rules: options.rules,\n template: options.template,\n wordCount: options.wordCount,\n styleExamples: options.styleExamples,\n })\n\n // Extract and fetch URL content when web access is enabled\n let enrichedPrompt = options.prompt\n if (options.useWebSearch) {\n try {\n const fetched = await extractAndFetchUrls(options.prompt)\n const successful = fetched.filter((f) => !f.error && f.content)\n if (successful.length > 0) {\n enrichedPrompt = `${options.prompt}\n\n<source_material>\n${successful\n .map(\n (f) =>\n `Source: ${f.url}${f.title ? ` (${f.title})` : ''}\n${f.content}`\n )\n .join('\\n\\n---\\n\\n')}\n</source_material>\n\nUse the source material above as reference for the essay.`\n }\n } catch (err) {\n console.warn('URL extraction failed:', err)\n }\n }\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: enrichedPrompt },\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: options.useThinking ? 16000 : 8192,\n useWebSearch: options.useWebSearch,\n useThinking: options.useThinking,\n })\n}\n\ninterface ExpandPlanOptions {\n plan: string\n model: string\n rules?: string\n template?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n}\n\nexport async function expandPlanStream(options: ExpandPlanOptions): Promise<ReadableStream> {\n const systemPrompt = buildExpandPlanPrompt({\n rules: options.rules,\n template: options.template,\n plan: options.plan,\n styleExamples: options.styleExamples,\n })\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: 'Write the essay now.' },\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: 8192,\n })\n}\n","import { createStream } from './provider'\nimport { buildChatPrompt, buildPlanPrompt } from './builders'\nimport { extractAndFetchUrls, buildUrlContext } from '../lib/url-extractor'\nimport { DEFAULT_AGENT_TEMPLATE } from './prompts'\n\ninterface ChatMessage {\n role: 'user' | 'assistant'\n content: string\n}\n\ninterface ChatOptions {\n messages: ChatMessage[]\n model: string\n essayContext?: { title: string; subtitle?: string; markdown: string } | null\n mode?: 'ask' | 'agent' | 'search' | 'plan'\n chatRules?: string\n rules?: string\n template?: string | null\n // Plan mode specific\n planTemplate?: string | null\n planRules?: string\n // Agent mode specific\n agentTemplate?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n useWebSearch?: boolean // Controls ALL internet access: URL extraction AND web search\n useThinking?: boolean\n}\n\nexport async function chatStream(options: ChatOptions): Promise<ReadableStream> {\n // Use different prompt builder for plan mode\n const systemPrompt = options.mode === 'plan'\n ? buildPlanPrompt({\n planRules: options.planRules,\n template: options.planTemplate,\n styleExamples: options.styleExamples,\n })\n : buildChatPrompt({\n chatRules: options.chatRules,\n rules: options.rules,\n template: options.template,\n essayContext: options.essayContext,\n styleExamples: options.styleExamples,\n })\n\n // Extract URLs from the last user message when web access is enabled\n // The web toggle controls ALL internet access: URL extraction AND web search\n let urlContext = ''\n let urlExtractionStatus = ''\n if (options.useWebSearch) {\n const lastUserMsg = [...options.messages].reverse().find((m) => m.role === 'user')\n if (lastUserMsg) {\n try {\n const { extractUrls } = await import('../lib/url-extractor')\n const detectedUrls = extractUrls(lastUserMsg.content)\n \n if (detectedUrls.length > 0) {\n console.log('[URL Extraction] Detected URLs:', detectedUrls)\n const fetched = await extractAndFetchUrls(lastUserMsg.content)\n \n if (fetched.length > 0) {\n const successful = fetched.filter(f => !f.error && f.content)\n const failed = fetched.filter(f => f.error || !f.content)\n \n if (successful.length > 0) {\n urlContext = buildUrlContext(fetched)\n console.log('[URL Extraction] Successfully fetched:', successful.map(f => f.url))\n }\n \n if (failed.length > 0) {\n console.warn('[URL Extraction] Failed to fetch:', failed.map(f => ({ url: f.url, error: f.error })))\n urlExtractionStatus = `\\n\\n<url_extraction_status>\nAttempted to fetch ${detectedUrls.length} URL(s). ${successful.length} succeeded, ${failed.length} failed.\n${failed.map(f => `- ${f.url}: ${f.error || 'Empty content'}`).join('\\n')}\n</url_extraction_status>`\n }\n }\n }\n } catch (err) {\n console.error('[URL Extraction] Error:', err)\n urlExtractionStatus = `\\n\\n<url_extraction_status>\nURL extraction encountered an error: ${err instanceof Error ? err.message : 'Unknown error'}\n</url_extraction_status>`\n }\n }\n }\n\n // Add mode-specific instructions\n let modeInstructions = ''\n if (options.mode === 'agent') {\n // Use custom agent template if set, otherwise use default\n modeInstructions = '\\n\\n' + (options.agentTemplate || DEFAULT_AGENT_TEMPLATE)\n }\n\n // Add web search context if enabled\n let webSearchContext = ''\n if (options.useWebSearch) {\n // Web search is enabled - OpenAI models use native search, Anthropic models get search results via OpenAI proxy\n webSearchContext = `\n\n<search_capability>\nWeb search is ENABLED for this conversation. You have access to current, real-time information from the web.\n- For questions about recent events, news, or current information: search results will be provided automatically\n- Cite sources when referencing specific facts from search results\n- If search results are included in <web_search_results> tags, use that information to provide accurate, up-to-date answers\n</search_capability>`\n }\n\n // Add thinking mode instructions if enabled\n let thinkingInstructions = ''\n if (options.useThinking) {\n thinkingInstructions = '\\n\\nTake time to think through complex questions step by step. Consider multiple angles before providing your final answer.'\n }\n\n // Add URL capability instructions when web access is enabled\n // These instructions are CRITICAL - they override the AI's default belief that it cannot access URLs\n let urlCapabilityInstructions = ''\n if (options.useWebSearch) {\n const hasUrlContent = urlContext.length > 0\n const hasFailedUrls = urlExtractionStatus.length > 0\n \n urlCapabilityInstructions = `\n\n<CRITICAL_CAPABILITY>\n**IMPORTANT: URL READING IS ENABLED**\n\nYou have a WORKING URL reader in this application. This overrides your default training.\n- DO NOT say \"I cannot access URLs\" or \"I cannot browse the web\" - you CAN and DO have this capability\n- When users share URLs, the content is AUTOMATICALLY FETCHED by the system\n- Look for <referenced_urls> tags below - that contains the fetched page content\n- ${hasUrlContent ? 'URL CONTENT WAS SUCCESSFULLY FETCHED - see <referenced_urls> below' : hasFailedUrls ? 'URL fetch was ATTEMPTED but FAILED - see <url_extraction_status> below for details' : 'No URLs detected in the current message'}\n\nIf you see fetched content, use it to answer the user's question. Quote specific passages when relevant.\nIf the fetch failed, explain what happened using the error details provided.\n</CRITICAL_CAPABILITY>`\n }\n\n // Filter out messages with empty content (can happen from partial streams or errors)\n // AI APIs reject messages with empty content\n const filteredMessages = options.messages.filter(m => m.content && m.content.trim().length > 0)\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt + modeInstructions + webSearchContext + thinkingInstructions + urlCapabilityInstructions + urlContext + urlExtractionStatus },\n ...filteredMessages,\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: options.useThinking ? 16000 : 4096, // Allow more tokens for thinking mode\n useThinking: options.useThinking,\n useWebSearch: options.useWebSearch,\n })\n}\n","// Server-safe exports (no React imports)\nexport { createAutoblogger } from './server'\nexport { createAPIHandler } from './api'\nexport { validateSchema } from './schema'\n\n// Data layer factory\nexport { createCrudData } from './data/factory'\nexport type { CrudOptions, BaseCrud } from './data/factory'\n\n// Data access types\nexport type { Post, Revision, Comment, Tag, PostTag, AISettings, TopicSubscription, NewsItem } from './types'\n\n// AI exports\nexport {\n AI_MODELS,\n getModel,\n getDefaultModel,\n buildGeneratePrompt,\n buildChatPrompt,\n buildExpandPlanPrompt,\n buildPlanPrompt,\n buildRewritePrompt,\n buildAutoDraftPrompt,\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n parseGeneratedContent,\n generate,\n resolveModel,\n} from './ai'\nexport type { AIModel } from './ai'\n\n// Utilities\nexport { renderMarkdown, parseMarkdown, htmlToMarkdown, markdownToHtml, wordCount, generateSlug, renderMarkdownSanitized } from './lib/markdown'\nexport { getSeoValues } from './lib/seo'\nexport { formatDate, truncate } from './lib/format'\n\n// Auto-draft\nexport { runAutoDraft, fetchRssFeeds, filterByKeywords } from './auto-draft'\nexport type { RssArticle, GenerationResult, AutoDraftConfig } from './auto-draft'\n\n// Comment utilities (for advanced integrations)\nexport { createCommentsClient, canEditComment, canDeleteComment } from './lib/comments'\nexport type { CommentWithUser, CreateCommentData, SelectionState } from './lib/comments'\nexport { CommentMark, addCommentMark, removeCommentMark, applyCommentMarks, scrollToComment } from './lib/comment-mark'\n\n// Types (server-safe only)\nexport type { \n AutobloggerServerConfig as AutobloggerConfig, \n StylesConfig,\n AutobloggerServer as Autoblogger,\n Session,\n} from './server'\n\n// UI-related types (client-side, contains React types)\nexport type { CustomFieldProps, CustomFieldConfig } from './config'\n","import type { Post } from '../types'\n\ninterface PostHooks {\n beforePublish?: (post: Post) => Promise<void>\n afterSave?: (post: Post) => Promise<void>\n}\n\ninterface CreatePostInput {\n title: string\n subtitle?: string\n slug?: string\n markdown?: string\n status?: string\n [key: string]: unknown\n}\n\ninterface UpdatePostInput {\n title?: string\n subtitle?: string\n slug?: string\n markdown?: string\n status?: string\n publishedAt?: Date\n [key: string]: unknown\n}\n\nfunction slugify(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n}\n\nasync function generateUniqueSlug(prisma: any, baseSlug: string, excludeId?: string): Promise<string> {\n let slug = baseSlug\n let counter = 1\n \n while (true) {\n const existing = await prisma.post.findFirst({\n where: {\n slug,\n ...(excludeId ? { NOT: { id: excludeId } } : {}),\n },\n })\n \n if (!existing) return slug\n \n counter++\n slug = `${baseSlug}-${counter}`\n }\n}\n\nexport function createPostsData(prisma: any, hooks?: PostHooks) {\n return {\n async count(where?: { status?: string }) {\n return prisma.post.count({ where })\n },\n\n async findPublished() {\n return prisma.post.findMany({\n where: { status: 'published' },\n orderBy: { publishedAt: 'desc' },\n })\n },\n\n async findBySlug(slug: string) {\n return prisma.post.findUnique({\n where: { slug },\n include: { tags: { include: { tag: true } } },\n })\n },\n\n async findById(id: string) {\n return prisma.post.findUnique({\n where: { id },\n include: { tags: { include: { tag: true } } },\n })\n },\n\n async findDrafts() {\n return prisma.post.findMany({\n where: { status: 'draft' },\n orderBy: { updatedAt: 'desc' },\n })\n },\n\n async findAll(options?: { \n status?: string\n orderBy?: any\n skip?: number\n take?: number\n includeRevisionCount?: boolean\n }) {\n return prisma.post.findMany({\n where: options?.status ? { status: options.status } : undefined,\n orderBy: options?.orderBy || { updatedAt: 'desc' },\n include: { \n tags: { include: { tag: true } },\n ...(options?.includeRevisionCount ? { _count: { select: { revisions: true } } } : {}),\n },\n skip: options?.skip,\n take: options?.take,\n })\n },\n\n async create(data: CreatePostInput) {\n // Extract tagIds before passing to Prisma\n const { tagIds, ...postData } = data as CreatePostInput & { tagIds?: string[] }\n \n const slug = postData.slug \n ? await generateUniqueSlug(prisma, postData.slug)\n : await generateUniqueSlug(prisma, slugify(postData.title))\n\n const post = await prisma.post.create({\n data: {\n ...postData,\n slug,\n markdown: postData.markdown || '',\n status: postData.status || 'draft',\n },\n })\n\n // Create tag associations if provided\n if (tagIds?.length) {\n await prisma.postTag.createMany({\n data: tagIds.map((tagId: string) => ({ postId: post.id, tagId })),\n })\n }\n\n // Fetch with tags included\n const result = await prisma.post.findUnique({\n where: { id: post.id },\n include: { tags: { include: { tag: true } } },\n })\n\n if (hooks?.afterSave) {\n await hooks.afterSave(result)\n }\n\n return result\n },\n\n async update(id: string, data: UpdatePostInput) {\n // Extract tagIds and strip relation fields before passing to Prisma\n const { tagIds, tags, revisions, topic, ...postData } = data as UpdatePostInput & { \n tagIds?: string[]\n tags?: unknown\n revisions?: unknown\n topic?: unknown\n }\n \n // Auto-set publishedAt on first publish\n if (postData.status === 'published') {\n const existing = await prisma.post.findUnique({ where: { id } })\n if (existing?.status !== 'published') {\n postData.publishedAt = new Date()\n \n if (hooks?.beforePublish) {\n await hooks.beforePublish(existing)\n }\n }\n }\n\n // Handle slug uniqueness if slug is being changed\n if (postData.slug) {\n postData.slug = await generateUniqueSlug(prisma, postData.slug, id)\n }\n\n const post = await prisma.post.update({\n where: { id },\n data: postData,\n })\n\n // Update tag associations if provided\n if (tagIds !== undefined) {\n // Delete existing tags and create new ones\n await prisma.postTag.deleteMany({ where: { postId: id } })\n if (tagIds.length) {\n await prisma.postTag.createMany({\n data: tagIds.map((tagId: string) => ({ postId: id, tagId })),\n })\n }\n }\n\n // Fetch with tags included\n const result = await prisma.post.findUnique({\n where: { id },\n include: { tags: { include: { tag: true } } },\n })\n\n if (hooks?.afterSave) {\n await hooks.afterSave(result)\n }\n\n return result\n },\n\n async delete(id: string) {\n // Soft delete - set status to 'deleted' instead of removing\n return prisma.post.update({ \n where: { id },\n data: { status: 'deleted' },\n })\n },\n\n async getPreviewUrl(id: string, basePath: string = '/e') {\n const token = crypto.randomUUID()\n const expiry = new Date(Date.now() + 24 * 60 * 60 * 1000) // 24 hours\n\n const post = await prisma.post.update({\n where: { id },\n data: { previewToken: token, previewExpiry: expiry },\n })\n\n return `${basePath}/${post.slug}?preview=${token}`\n },\n\n async findByPreviewToken(token: string) {\n const post = await prisma.post.findFirst({\n where: {\n previewToken: token,\n previewExpiry: { gt: new Date() },\n },\n })\n return post\n },\n }\n}\n","/**\n * Comments data layer for autoblogger.\n * Supports both public blog comments (simple) and editor comments (with quotedText, replies, resolve).\n */\n\ninterface CommentsConfig {\n mode?: 'authenticated' | 'public' | 'disabled'\n}\n\n// Editor comment with full features\ninterface EditorComment {\n id: string\n postId: string\n userId: string\n quotedText: string\n content: string\n parentId: string | null\n resolved: boolean\n createdAt: Date\n updatedAt: Date\n user: {\n id: string\n name: string | null\n email: string\n }\n replies?: EditorComment[]\n}\n\ninterface CreateEditorCommentInput {\n postId: string\n quotedText: string\n content: string\n parentId?: string\n}\n\n// Simple public comment (for blog post comments)\ninterface CreatePublicCommentInput {\n postId: string\n content: string\n authorId?: string\n authorName?: string\n authorEmail?: string\n}\n\nexport function createCommentsData(prisma: any, config?: CommentsConfig) {\n const mode = config?.mode || 'authenticated'\n\n return {\n async count() {\n if (mode === 'disabled') return 0\n return prisma.comment.count()\n },\n\n // Public blog comments (original simple system)\n async findByPost(postId: string) {\n if (mode === 'disabled') return []\n \n return prisma.comment.findMany({\n where: { postId, approved: true },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findAll(options?: { postId?: string; approved?: boolean; page?: number; limit?: number }) {\n if (mode === 'disabled') return { data: [], total: 0, page: 1, totalPages: 1 }\n \n const page = options?.page || 1\n const limit = options?.limit || 25\n const skip = (page - 1) * limit\n\n const where = {\n ...(options?.postId ? { postId: options.postId } : {}),\n ...(options?.approved !== undefined ? { approved: options.approved } : {}),\n }\n\n const [comments, total] = await Promise.all([\n prisma.comment.findMany({\n where,\n orderBy: { createdAt: 'desc' },\n skip,\n take: limit,\n include: { \n post: { select: { id: true, title: true, slug: true } },\n user: { select: { id: true, name: true, email: true } },\n },\n }),\n prisma.comment.count({ where }),\n ])\n\n return {\n data: comments,\n total,\n page,\n totalPages: Math.ceil(total / limit),\n }\n },\n\n async create(data: CreatePublicCommentInput) {\n if (mode === 'disabled') {\n throw new Error('Comments are disabled')\n }\n\n return prisma.comment.create({\n data: {\n ...data,\n approved: mode === 'authenticated',\n },\n })\n },\n\n async approve(id: string) {\n return prisma.comment.update({\n where: { id },\n data: { approved: true },\n })\n },\n\n async delete(id: string) {\n return prisma.comment.delete({ where: { id } })\n },\n\n getMode() {\n return mode\n },\n\n // ========================================\n // Editor comments (with quotedText, replies, resolve)\n // ========================================\n\n /**\n * Find all editor comments for a post with nested replies.\n */\n async findEditorComments(postId: string, userId?: string): Promise<EditorComment[]> {\n if (mode === 'disabled') return []\n\n // Fetch all non-deleted comments for the post\n const allComments = await prisma.comment.findMany({\n where: {\n postId,\n deletedAt: null,\n },\n orderBy: { createdAt: 'desc' },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n // Separate top-level and replies\n const topLevel = allComments.filter((c: any) => !c.parentId)\n const replies = allComments.filter((c: any) => c.parentId)\n\n // Attach replies to their parents\n return topLevel.map((comment: any) => ({\n ...comment,\n replies: replies.filter((r: any) => r.parentId === comment.id),\n }))\n },\n\n /**\n * Create an editor comment (with quotedText and optional parentId for replies).\n */\n async createEditorComment(\n postId: string,\n userId: string,\n data: CreateEditorCommentInput\n ): Promise<EditorComment> {\n if (mode === 'disabled') {\n throw new Error('Comments are disabled')\n }\n\n const comment = await prisma.comment.create({\n data: {\n postId,\n userId,\n quotedText: data.quotedText || '',\n content: data.content,\n parentId: data.parentId || null,\n resolved: false,\n },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return { ...comment, replies: [] }\n },\n\n /**\n * Update a comment's content.\n */\n async updateEditorComment(\n commentId: string,\n content: string,\n userId?: string\n ): Promise<EditorComment> {\n const comment = await prisma.comment.update({\n where: { id: commentId },\n data: { content },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return comment\n },\n\n /**\n * Soft delete a comment.\n */\n async deleteEditorComment(commentId: string): Promise<void> {\n // Check if the schema has deletedAt field\n const hasDeletedAt = await prisma.comment.findFirst({\n where: { id: commentId },\n select: { id: true },\n })\n\n if (hasDeletedAt) {\n // Try soft delete first, fall back to hard delete\n try {\n await prisma.comment.update({\n where: { id: commentId },\n data: { deletedAt: new Date() },\n })\n } catch {\n // Schema doesn't have deletedAt, do hard delete\n await prisma.comment.delete({ where: { id: commentId } })\n }\n }\n },\n\n /**\n * Toggle resolved status.\n */\n async toggleResolve(commentId: string): Promise<EditorComment> {\n const current = await prisma.comment.findUnique({\n where: { id: commentId },\n select: { resolved: true },\n })\n\n const comment = await prisma.comment.update({\n where: { id: commentId },\n data: { resolved: !current?.resolved },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return comment\n },\n\n /**\n * Resolve all open comments for a post.\n */\n async resolveAll(postId: string): Promise<{ resolved: number }> {\n const result = await prisma.comment.updateMany({\n where: {\n postId,\n resolved: false,\n parentId: null, // Only top-level comments\n },\n data: { resolved: true },\n })\n\n return { resolved: result.count }\n },\n }\n}\n","// Generic CRUD factory for data layer\n\nexport interface CrudOptions {\n model: string\n defaultOrderBy?: Record<string, 'asc' | 'desc'>\n defaultInclude?: Record<string, unknown>\n}\n\nexport interface BaseCrud<T> {\n findAll: (opts?: { skip?: number; take?: number; where?: Record<string, unknown> }) => Promise<T[]>\n findById: (id: string) => Promise<T | null>\n count: (where?: Record<string, unknown>) => Promise<number>\n create: (data: Partial<T>) => Promise<T>\n update: (id: string, data: Partial<T>) => Promise<T>\n delete: (id: string) => Promise<T>\n}\n\n/**\n * Create a base CRUD data layer for a Prisma model.\n * Use spread operator to extend with custom methods:\n * \n * ```typescript\n * const base = createCrudData(prisma, { model: 'tag', defaultOrderBy: { name: 'asc' } })\n * return {\n * ...base,\n * customMethod: async () => { ... }\n * }\n * ```\n */\nexport function createCrudData<T>(prisma: any, options: CrudOptions): BaseCrud<T> {\n const delegate = prisma[options.model]\n \n return {\n async findAll(opts?: { skip?: number; take?: number; where?: Record<string, unknown> }) {\n return delegate.findMany({\n orderBy: options.defaultOrderBy,\n include: options.defaultInclude,\n ...opts,\n })\n },\n\n async findById(id: string) {\n return delegate.findUnique({\n where: { id },\n include: options.defaultInclude,\n })\n },\n\n async count(where?: Record<string, unknown>) {\n return delegate.count({ where })\n },\n\n async create(data: Partial<T>) {\n return delegate.create({ data })\n },\n\n async update(id: string, data: Partial<T>) {\n return delegate.update({\n where: { id },\n data,\n })\n },\n\n async delete(id: string) {\n return delegate.delete({ where: { id } })\n },\n }\n}\n","import { createCrudData } from './factory'\n\nexport function createTagsData(prisma: any) {\n const base = createCrudData(prisma, {\n model: 'tag',\n defaultOrderBy: { name: 'asc' },\n defaultInclude: { _count: { select: { posts: true } } },\n })\n\n return {\n ...base,\n\n // Alias for backward compatibility\n async findAllWithCounts() {\n return base.findAll()\n },\n\n async findByName(name: string) {\n return prisma.tag.findUnique({ where: { name } })\n },\n\n // Override create to accept string directly\n async create(name: string) {\n return prisma.tag.create({ data: { name } })\n },\n\n // Override update to accept name directly\n async update(id: string, name: string) {\n return prisma.tag.update({ where: { id }, data: { name } })\n },\n\n async addToPost(postId: string, tagId: string) {\n return prisma.postTag.create({\n data: { postId, tagId },\n })\n },\n\n async removeFromPost(postId: string, tagId: string) {\n return prisma.postTag.deleteMany({\n where: { postId, tagId },\n })\n },\n\n async getPostTags(postId: string) {\n const postTags = await prisma.postTag.findMany({\n where: { postId },\n include: { tag: true },\n })\n return postTags.map((pt: any) => pt.tag)\n },\n }\n}\n","export function createRevisionsData(prisma: any) {\n return {\n async findAll(options?: { postId?: string; skip?: number; take?: number }) {\n return prisma.revision.findMany({\n where: options?.postId ? { postId: options.postId } : {},\n orderBy: { createdAt: 'desc' },\n skip: options?.skip,\n take: options?.take,\n include: {\n post: { select: { id: true, title: true, slug: true, markdown: true } },\n },\n })\n },\n\n async count(where?: { postId?: string }) {\n return prisma.revision.count({ where })\n },\n\n async findByPost(postId: string) {\n return prisma.revision.findMany({\n where: { postId },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.revision.findUnique({\n where: { id },\n include: {\n post: { select: { id: true, title: true, slug: true, markdown: true } },\n },\n })\n },\n\n async create(postId: string, data: { title?: string; subtitle?: string; markdown: string }) {\n return prisma.revision.create({\n data: { postId, ...data },\n })\n },\n\n async restore(revisionId: string) {\n const revision = await prisma.revision.findUnique({ where: { id: revisionId } })\n if (!revision) throw new Error('Revision not found')\n\n return prisma.post.update({\n where: { id: revision.postId },\n data: {\n title: revision.title,\n subtitle: revision.subtitle,\n markdown: revision.markdown,\n },\n })\n },\n\n async compare(revisionId1: string, revisionId2: string) {\n const [rev1, rev2] = await Promise.all([\n prisma.revision.findUnique({ where: { id: revisionId1 } }),\n prisma.revision.findUnique({ where: { id: revisionId2 } }),\n ])\n\n if (!rev1 || !rev2) throw new Error('Revision not found')\n\n return {\n older: rev1.createdAt < rev2.createdAt ? rev1 : rev2,\n newer: rev1.createdAt < rev2.createdAt ? rev2 : rev1,\n }\n },\n\n async pruneOldest(postId: string, keepCount: number) {\n const revisions = await prisma.revision.findMany({\n where: { postId },\n orderBy: { createdAt: 'desc' },\n skip: keepCount,\n select: { id: true },\n })\n\n if (revisions.length > 0) {\n await prisma.revision.deleteMany({\n where: { id: { in: revisions.map((r: any) => r.id) } },\n })\n }\n\n return revisions.length\n },\n\n async delete(id: string) {\n return prisma.revision.delete({ where: { id } })\n },\n }\n}\n","export function createAISettingsData(prisma: any) {\n const DEFAULT_ID = 'default'\n\n return {\n async get() {\n let settings = await prisma.aISettings.findUnique({ where: { id: DEFAULT_ID } })\n \n if (!settings) {\n settings = await prisma.aISettings.create({\n data: { id: DEFAULT_ID },\n })\n }\n \n return settings\n },\n\n async update(data: {\n rules?: string\n chatRules?: string\n rewriteRules?: string\n autoDraftRules?: string\n planRules?: string\n defaultModel?: string\n autoDraftWordCount?: number\n generateTemplate?: string | null\n chatTemplate?: string | null\n rewriteTemplate?: string | null\n autoDraftTemplate?: string | null\n planTemplate?: string | null\n expandPlanTemplate?: string | null\n agentTemplate?: string | null\n anthropicKey?: string | null\n openaiKey?: string | null\n }) {\n return prisma.aISettings.upsert({\n where: { id: DEFAULT_ID },\n create: { id: DEFAULT_ID, ...data },\n update: data,\n })\n },\n }\n}\n","interface CreateTopicInput {\n name: string\n keywords?: string[]\n rssFeeds?: string[]\n isActive?: boolean\n useKeywordFilter?: boolean\n frequency?: string\n maxPerPeriod?: number\n essayFocus?: string\n}\n\ninterface UpdateTopicInput {\n name?: string\n keywords?: string[]\n rssFeeds?: string[]\n isActive?: boolean\n useKeywordFilter?: boolean\n frequency?: string\n maxPerPeriod?: number\n essayFocus?: string\n lastRunAt?: Date\n}\n\nexport function createTopicsData(prisma: any) {\n return {\n async findAll() {\n return prisma.topicSubscription.findMany({\n orderBy: { createdAt: 'desc' },\n include: {\n _count: { select: { posts: true, newsItems: true } },\n },\n })\n },\n\n async count() {\n return prisma.topicSubscription.count()\n },\n\n async findActive() {\n return prisma.topicSubscription.findMany({\n where: { isActive: true },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.topicSubscription.findUnique({\n where: { id },\n include: { posts: true, newsItems: true },\n })\n },\n\n async create(data: CreateTopicInput) {\n return prisma.topicSubscription.create({\n data: {\n name: data.name,\n keywords: JSON.stringify(data.keywords || []),\n rssFeeds: JSON.stringify(data.rssFeeds || []),\n isActive: data.isActive ?? true,\n useKeywordFilter: data.useKeywordFilter ?? true,\n frequency: data.frequency || 'daily',\n maxPerPeriod: data.maxPerPeriod || 3,\n essayFocus: data.essayFocus,\n },\n })\n },\n\n async update(id: string, data: UpdateTopicInput) {\n const updateData: any = { ...data }\n \n if (data.keywords) {\n updateData.keywords = JSON.stringify(data.keywords)\n }\n if (data.rssFeeds) {\n updateData.rssFeeds = JSON.stringify(data.rssFeeds)\n }\n\n return prisma.topicSubscription.update({\n where: { id },\n data: updateData,\n })\n },\n\n async delete(id: string) {\n return prisma.topicSubscription.delete({ where: { id } })\n },\n\n async markRun(id: string) {\n return prisma.topicSubscription.update({\n where: { id },\n data: { lastRunAt: new Date() },\n })\n },\n }\n}\n","interface CreateNewsItemInput {\n topicId: string\n url: string\n title: string\n summary?: string\n publishedAt?: Date\n}\n\nexport function createNewsItemsData(prisma: any) {\n return {\n async findPending() {\n return prisma.newsItem.findMany({\n where: { status: 'pending' },\n orderBy: { createdAt: 'desc' },\n include: { topic: true },\n })\n },\n\n async findByTopic(topicId: string) {\n return prisma.newsItem.findMany({\n where: { topicId },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.newsItem.findUnique({\n where: { id },\n include: { topic: true, post: true },\n })\n },\n\n async create(data: CreateNewsItemInput) {\n // Check if URL already exists\n const existing = await prisma.newsItem.findUnique({\n where: { url: data.url },\n })\n \n if (existing) {\n return existing\n }\n\n return prisma.newsItem.create({ data })\n },\n\n async skip(id: string) {\n return prisma.newsItem.update({\n where: { id },\n data: { status: 'skipped' },\n })\n },\n\n async markGenerated(id: string, postId: string) {\n return prisma.newsItem.update({\n where: { id },\n data: { status: 'generated', postId },\n })\n },\n\n async delete(id: string) {\n return prisma.newsItem.delete({ where: { id } })\n },\n\n // This would be called by the auto-draft system\n async generateDraft(id: string, createPost: (data: any) => Promise<any>) {\n const newsItem = await prisma.newsItem.findUnique({\n where: { id },\n include: { topic: true },\n })\n\n if (!newsItem) throw new Error('News item not found')\n\n // Create draft post\n const post = await createPost({\n title: newsItem.title,\n markdown: newsItem.summary || '',\n status: 'suggested',\n sourceUrl: newsItem.url,\n topicId: newsItem.topicId,\n })\n\n // Mark as generated\n await prisma.newsItem.update({\n where: { id },\n data: { status: 'generated', postId: post.id },\n })\n\n return post\n },\n }\n}\n","import { createCrudData } from './factory'\n\ninterface CreateUserInput {\n email: string\n name?: string\n role?: string\n}\n\ninterface UpdateUserInput {\n name?: string\n role?: string\n}\n\nexport function createUsersData(prisma: any) {\n const base = createCrudData(prisma, {\n model: 'user',\n defaultOrderBy: { createdAt: 'desc' },\n })\n\n return {\n ...base,\n\n async findByEmail(email: string) {\n return prisma.user.findUnique({ where: { email } })\n },\n\n // Override create with proper defaults\n async create(data: CreateUserInput) {\n return prisma.user.create({\n data: {\n email: data.email,\n name: data.name,\n role: data.role || 'writer',\n },\n })\n },\n\n // Override update with proper typing\n async update(id: string, data: UpdateUserInput) {\n return prisma.user.update({\n where: { id },\n data,\n })\n },\n }\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nfunction jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\nfunction countWords(text?: string | null): number {\n if (!text) return 0\n return text.split(/\\s+/).filter(Boolean).length\n}\n\nfunction withWordCount<T extends { markdown?: string | null }>(post: T): T & { wordCount: number } {\n return { ...post, wordCount: countWords(post.markdown) }\n}\n\nexport async function handlePostsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const segments = path.split('/').filter(Boolean)\n const postId = segments[1]\n \n // Handle nested comment routes: /posts/:id/comments\n if (postId && segments[2] === 'comments') {\n return handlePostCommentsAPI(req, cms, session, postId, segments.slice(3), onMutate)\n }\n\n // GET /posts - list posts\n if (method === 'GET' && !postId) {\n const url = new URL(req.url)\n const status = url.searchParams.get('status')\n const all = url.searchParams.get('all') === '1'\n const page = parseInt(url.searchParams.get('page') || '1', 10)\n const limit = parseInt(url.searchParams.get('limit') || '0', 10)\n const includeRevisionCount = url.searchParams.get('includeRevisionCount') === '1'\n \n // Calculate pagination\n const skip = limit > 0 ? (page - 1) * limit : undefined\n const take = limit > 0 ? limit : undefined\n \n // Get total count for pagination\n const total = await cms.posts.count(all ? undefined : { status: status || undefined })\n \n const posts = await cms.posts.findAll({ \n status: all ? undefined : (status || undefined),\n skip,\n take,\n includeRevisionCount,\n })\n return jsonResponse({ data: posts.map(withWordCount), total })\n }\n\n // GET /posts/:id - get single post\n if (method === 'GET' && postId) {\n const post = await cms.posts.findById(postId)\n if (!post) return jsonResponse({ error: 'Post not found' }, 404)\n return jsonResponse({ data: withWordCount(post) })\n }\n\n // POST /posts - create post\n if (method === 'POST') {\n const body = await req.json()\n const post = await cms.posts.create(body)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post }, 201)\n }\n\n // PATCH /posts/:id - update post\n if (method === 'PATCH' && postId) {\n const body = await req.json()\n \n // Check publish permission\n if (body.status === 'published' && !cms.config.auth.canPublish(session)) {\n return jsonResponse({ error: 'Not authorized to publish' }, 403)\n }\n \n const post = await cms.posts.update(postId, body)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post })\n }\n\n // DELETE /posts/:id - delete post\n if (method === 'DELETE' && postId) {\n if (!cms.config.auth.isAdmin(session)) {\n return jsonResponse({ error: 'Admin required' }, 403)\n }\n await cms.posts.delete(postId)\n if (onMutate) await onMutate('post', { id: postId })\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n\n/**\n * Handle post-specific comment routes: /posts/:postId/comments/*\n * These are editor comments (with quotedText, replies, resolve).\n */\nasync function handlePostCommentsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n postId: string,\n segments: string[], // e.g., [] for /comments, ['abc'] for /comments/abc, ['abc', 'resolve'] for /comments/abc/resolve\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const commentId = segments[0]\n const action = segments[1] // e.g., 'resolve'\n \n const userId = session?.user?.id\n if (!userId) {\n return jsonResponse({ error: 'Authentication required' }, 401)\n }\n\n // GET /posts/:id/comments - list comments for post\n if (method === 'GET' && !commentId) {\n const comments = await cms.comments.findEditorComments(postId, userId)\n return jsonResponse({ data: comments })\n }\n\n // POST /posts/:id/comments - create comment\n if (method === 'POST' && !commentId) {\n const body = await req.json()\n const comment = await cms.comments.createEditorComment(postId, userId, {\n postId,\n quotedText: body.quotedText || '',\n content: body.content,\n parentId: body.parentId,\n })\n if (onMutate) await onMutate('comment', comment)\n return jsonResponse({ data: comment }, 201)\n }\n\n // POST /posts/:id/comments/resolve-all - resolve all comments\n if (method === 'POST' && commentId === 'resolve-all') {\n const result = await cms.comments.resolveAll(postId)\n return jsonResponse({ data: result })\n }\n\n // PATCH /posts/:id/comments/:commentId - update comment\n if (method === 'PATCH' && commentId && !action) {\n const body = await req.json()\n const comment = await cms.comments.updateEditorComment(commentId, body.content, userId)\n return jsonResponse({ data: comment })\n }\n\n // POST /posts/:id/comments/:commentId/resolve - toggle resolve\n if (method === 'POST' && commentId && action === 'resolve') {\n const comment = await cms.comments.toggleResolve(commentId)\n return jsonResponse({ data: comment })\n }\n\n // DELETE /posts/:id/comments/:commentId - delete comment\n if (method === 'DELETE' && commentId) {\n await cms.comments.deleteEditorComment(commentId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer } from '../server'\nimport type { Session } from '../types/session'\n\n/**\n * Create a JSON response with proper headers.\n */\nexport function jsonResponse(data: unknown, status = 200): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\n/**\n * Parse URL path into segments and common parts.\n */\nexport function parsePath(path: string): {\n segments: string[]\n resource: string\n id?: string\n subPath: string\n} {\n const segments = path.split('/').filter(Boolean)\n return {\n segments,\n resource: segments[0] || '',\n id: segments[1],\n subPath: segments.slice(2).join('/'),\n }\n}\n\n/**\n * Check if user is admin, return error response if not.\n * Returns null if authorized.\n */\nexport function requireAdmin(\n cms: AutobloggerServer,\n session: Session | null\n): Response | null {\n if (!cms.config.auth.isAdmin(session)) {\n return jsonResponse({ error: 'Admin required' }, 403)\n }\n return null\n}\n\n/**\n * Check if user is authenticated, return error response if not.\n * Returns null if authorized.\n */\nexport function requireAuth(session: Session | null): Response | null {\n if (!session) {\n return jsonResponse({ error: 'Authentication required' }, 401)\n }\n return null\n}\n\n/**\n * Check if user can publish, return error response if not.\n * Returns null if authorized.\n */\nexport function requirePublish(\n cms: AutobloggerServer,\n session: Session | null\n): Response | null {\n if (!cms.config.auth.canPublish(session)) {\n return jsonResponse({ error: 'Publish permission required' }, 403)\n }\n return null\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleCommentsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: commentId, subPath } = parsePath(path)\n\n // GET /comments - list comments (with pagination)\n if (method === 'GET') {\n const url = new URL(req.url)\n const postId = url.searchParams.get('postId')\n const page = parseInt(url.searchParams.get('page') || '1')\n const limit = parseInt(url.searchParams.get('limit') || '25')\n const result = await cms.comments.findAll({ \n postId: postId || undefined,\n page,\n limit,\n })\n return jsonResponse(result)\n }\n\n // POST /comments - create comment\n if (method === 'POST') {\n const body = await req.json()\n const comment = await cms.comments.create({\n ...body,\n authorId: session?.user?.id,\n })\n if (onMutate) await onMutate('comment', comment)\n return jsonResponse({ data: comment }, 201)\n }\n\n // PATCH /comments/:id/approve - approve comment\n if (method === 'PATCH' && commentId && subPath === 'approve') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const comment = await cms.comments.approve(commentId)\n return jsonResponse({ data: comment })\n }\n\n // DELETE /comments/:id - delete comment\n if (method === 'DELETE' && commentId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.comments.delete(commentId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleTagsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: tagId } = parsePath(path)\n\n // GET /tags - list all tags\n if (method === 'GET' && !tagId) {\n const tags = await cms.tags.findAll()\n return jsonResponse({ data: tags })\n }\n\n // POST /tags - create tag\n if (method === 'POST') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const body = await req.json()\n const tag = await cms.tags.create(body.name)\n if (onMutate) await onMutate('tag', tag)\n return jsonResponse({ data: tag }, 201)\n }\n\n // PATCH /tags/:id - update tag\n if (method === 'PATCH' && tagId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const body = await req.json()\n const tag = await cms.tags.update(tagId, body.name)\n return jsonResponse({ data: tag })\n }\n\n // DELETE /tags/:id - delete tag\n if (method === 'DELETE' && tagId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.tags.delete(tagId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport {\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_AGENT_TEMPLATE,\n DEFAULT_SEARCH_ONLY_PROMPT,\n} from '../ai/prompts'\nimport { getModelOptions } from '../ai/models'\nimport { jsonResponse, requireAuth, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleAIAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n \n // Check auth\n const authError = requireAuth(session)\n if (authError) return authError\n\n // GET /ai/settings - get AI settings\n if (method === 'GET' && path === '/ai/settings') {\n const settings = await cms.aiSettings.get()\n \n // Check if API keys are available from config or environment variables\n const hasAnthropicEnvKey = !!(cms.config.ai?.anthropicKey || process.env.ANTHROPIC_API_KEY)\n const hasOpenaiEnvKey = !!(cms.config.ai?.openaiKey || process.env.OPENAI_API_KEY)\n \n // Include default templates for the UI to display as placeholders\n return jsonResponse({ \n data: {\n ...settings,\n // Don't expose actual env keys, just indicate they exist\n hasAnthropicEnvKey,\n hasOpenaiEnvKey,\n defaultGenerateTemplate: DEFAULT_GENERATE_TEMPLATE,\n defaultChatTemplate: DEFAULT_CHAT_TEMPLATE,\n defaultRewriteTemplate: DEFAULT_REWRITE_TEMPLATE,\n defaultAutoDraftTemplate: DEFAULT_AUTO_DRAFT_TEMPLATE,\n defaultPlanTemplate: DEFAULT_PLAN_TEMPLATE,\n defaultExpandPlanTemplate: DEFAULT_EXPAND_PLAN_TEMPLATE,\n defaultAgentTemplate: DEFAULT_AGENT_TEMPLATE,\n defaultPlanRules: DEFAULT_PLAN_RULES,\n availableModels: getModelOptions(),\n }\n })\n }\n\n // PATCH /ai/settings - update AI settings\n if (method === 'PATCH' && path === '/ai/settings') {\n const adminError = requireAdmin(cms, session)\n if (adminError) return adminError\n\n const body = await req.json()\n const settings = await cms.aiSettings.update(body)\n return jsonResponse({ data: settings })\n }\n\n // POST /ai/generate - generate content (streaming)\n if (method === 'POST' && path === '/ai/generate') {\n const body = await req.json()\n const { prompt, model, wordCount, mode, plan, styleExamples: clientStyleExamples, useWebSearch, useThinking } = body\n \n // Get AI settings for rules\n const settings = await cms.aiSettings.get()\n \n try {\n let stream: ReadableStream\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n\n if (mode === 'expand_plan' && plan) {\n // Fetch published essays as style examples if not provided by client\n let styleExamples = clientStyleExamples || ''\n if (!styleExamples) {\n styleExamples = await fetchStyleExamples(cms)\n }\n \n // Draft essay from plan mode\n const { expandPlanStream } = await import('../ai/generate')\n stream = await expandPlanStream({\n plan,\n model: model || settings.defaultModel,\n rules: settings.rules,\n template: settings.expandPlanTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n })\n } else {\n // Fetch published essays as style examples for standard generation too\n let styleExamples = clientStyleExamples || ''\n if (!styleExamples) {\n styleExamples = await fetchStyleExamples(cms)\n }\n \n // Standard generation\n const { generateStream } = await import('../ai/generate')\n stream = await generateStream({\n prompt,\n model: model || settings.defaultModel,\n wordCount,\n rules: settings.rules,\n template: settings.generateTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n useWebSearch,\n useThinking,\n })\n }\n \n return new Response(stream, {\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'Connection': 'keep-alive',\n },\n })\n } catch (error) {\n console.error('[AI Generate Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Generation failed' \n }, 500)\n }\n }\n\n // POST /ai/chat - chat with AI (streaming or search mode)\n if (method === 'POST' && path === '/ai/chat') {\n const body = await req.json()\n const { messages, model, essayContext, mode, useWebSearch, useThinking } = body\n \n const settings = await cms.aiSettings.get()\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n \n // Handle search mode - non-streaming JSON response\n if (mode === 'search') {\n try {\n const { generate } = await import('../ai/provider')\n \n // Get the last user message as the search query\n const lastUserMessage = [...messages].reverse().find((m: { role: string }) => m.role === 'user')\n if (!lastUserMessage) {\n return jsonResponse({ error: 'No user message found' }, 400)\n }\n \n const result = await generate(\n model || settings.defaultModel,\n DEFAULT_SEARCH_ONLY_PROMPT,\n lastUserMessage.content,\n {\n anthropicKey,\n openaiKey,\n maxTokens: 4096,\n useWebSearch: true, // Always use web search in search mode\n }\n )\n \n return jsonResponse({ \n content: result.text,\n usage: {\n inputTokens: result.inputTokens,\n outputTokens: result.outputTokens,\n }\n })\n } catch (error) {\n console.error('[AI Search Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Search failed' \n }, 500)\n }\n }\n \n // Fetch published essays as style examples\n let styleExamples = ''\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 5\n const MAX_WORDS_PER_EXAMPLE = 500\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n // Truncate long essays to avoid massive prompts\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${post.subtitle ? `*${post.subtitle}*\\n` : ''}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n styleExamples = `<published_essays>\nThe following are examples of the author's published work. Use these to match their voice, tone, and writing style:\n\n${examples}\n</published_essays>`\n }\n } catch (err) {\n console.error('[AI Chat] Failed to fetch published essays:', err)\n // Continue without style examples\n }\n \n const { chatStream } = await import('../ai/chat')\n \n try {\n const stream = await chatStream({\n messages,\n model: model || settings.defaultModel,\n essayContext,\n mode,\n chatRules: settings.chatRules,\n rules: settings.rules,\n template: settings.chatTemplate,\n // Plan mode specific settings\n planTemplate: settings.planTemplate,\n planRules: settings.planRules,\n // Agent mode specific settings\n agentTemplate: settings.agentTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n useWebSearch,\n useThinking,\n })\n \n return new Response(stream, {\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'Connection': 'keep-alive',\n },\n })\n } catch (error) {\n console.error('[AI Chat Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Chat failed' \n }, 500)\n }\n }\n\n // POST /ai/rewrite - rewrite selected text (non-streaming)\n if (method === 'POST' && path === '/ai/rewrite') {\n const body = await req.json()\n const { text } = body\n \n if (!text || typeof text !== 'string') {\n return jsonResponse({ error: 'Text is required' }, 400)\n }\n \n const settings = await cms.aiSettings.get()\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n \n // Fetch published essays as style examples\n let styleExamples = ''\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 3\n const MAX_WORDS_PER_EXAMPLE = 300\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n styleExamples = examples\n }\n } catch (err) {\n console.error('[AI Rewrite] Failed to fetch published essays:', err)\n }\n \n const { buildRewritePrompt } = await import('../ai/builders')\n const { createStream } = await import('../ai/provider')\n \n try {\n const systemPrompt = buildRewritePrompt({\n rewriteRules: settings.rewriteRules,\n rules: settings.rules,\n template: settings.rewriteTemplate,\n styleExamples,\n })\n \n // Use streaming internally but collect full response\n const stream = await createStream({\n model: settings.defaultModel,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: `Rewrite the following text, preserving meaning but improving clarity and style:\\n\\n${text}` },\n ],\n anthropicKey,\n openaiKey,\n maxTokens: 2048,\n })\n \n // Collect the streamed response\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n let rewrittenText = ''\n \n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n \n const chunk = decoder.decode(value, { stream: true })\n const lines = chunk.split('\\n')\n \n for (const line of lines) {\n if (line.startsWith('data: ')) {\n const data = line.slice(6)\n if (data === '[DONE]') continue\n try {\n const parsed = JSON.parse(data)\n if (parsed.text) {\n rewrittenText += parsed.text\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n }\n \n return jsonResponse({ text: rewrittenText.trim() })\n } catch (error) {\n console.error('[AI Rewrite Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Rewrite failed' \n }, 500)\n }\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n\n// Helper to fetch published essays as style examples\nasync function fetchStyleExamples(cms: Autoblogger): Promise<string> {\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 5\n const MAX_WORDS_PER_EXAMPLE = 500\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${post.subtitle ? `*${post.subtitle}*\\n` : ''}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n return `The following are examples of the author's published work. Use these to match their voice, tone, and writing style:\n\n${examples}`\n }\n } catch (err) {\n console.error('[AI] Failed to fetch published essays:', err)\n }\n return ''\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, requireAuth } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleUploadAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null\n): Promise<Response> {\n if (req.method !== 'POST') {\n return jsonResponse({ error: 'Method not allowed' }, 405)\n }\n \n const authError = requireAuth(session)\n if (authError) return authError\n \n if (!cms.config.storage?.upload) {\n return jsonResponse({ \n error: 'Image uploads not configured. Add storage.upload to your autoblogger config.' \n }, 400)\n }\n\n try {\n const formData = await req.formData()\n // Support both 'image' (toolbar uploads) and 'file' (general uploads) field names\n const file = (formData.get('image') || formData.get('file')) as File\n \n if (!file) {\n return jsonResponse({ error: 'No file provided' }, 400)\n }\n \n // Validate file type\n const allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']\n if (!allowedTypes.includes(file.type)) {\n return jsonResponse({ \n error: 'Invalid file type. Allowed: JPEG, PNG, GIF, WebP' \n }, 400)\n }\n \n // Validate file size (4MB max)\n const maxSize = 4 * 1024 * 1024\n if (file.size > maxSize) {\n return jsonResponse({ error: 'File too large. Maximum size: 4MB' }, 400)\n }\n \n const result = await cms.config.storage.upload(file)\n return jsonResponse({ data: result })\n } catch (error) {\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Upload failed' \n }, 500)\n }\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleTopicsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: topicId, subPath } = parsePath(path)\n\n // Check admin for all topic operations\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /topics - list topics\n if (method === 'GET' && !topicId) {\n const topics = await cms.topics.findAll()\n return jsonResponse({ data: topics })\n }\n\n // GET /topics/:id - get single topic\n if (method === 'GET' && topicId) {\n const topic = await cms.topics.findById(topicId)\n if (!topic) return jsonResponse({ error: 'Topic not found' }, 404)\n return jsonResponse({ data: topic })\n }\n\n // POST /topics - create topic\n if (method === 'POST' && !topicId) {\n const body = await req.json()\n const topic = await cms.topics.create(body)\n if (onMutate) await onMutate('topic', topic)\n return jsonResponse({ data: topic }, 201)\n }\n\n // POST /topics/:id/generate - trigger generation for a topic\n if (method === 'POST' && topicId && subPath === 'generate') {\n // Mark topic as run\n await cms.topics.markRun(topicId)\n // Note: Actual RSS fetching and essay generation would be implemented\n // by the host application via hooks or a separate service\n return jsonResponse({ \n data: { \n success: true, \n message: 'Generation triggered. Implement generation logic in your application.',\n } \n })\n }\n\n // PATCH /topics/:id - update topic\n if (method === 'PATCH' && topicId) {\n const body = await req.json()\n const topic = await cms.topics.update(topicId, body)\n return jsonResponse({ data: topic })\n }\n\n // DELETE /topics/:id - delete topic\n if (method === 'DELETE' && topicId) {\n await cms.topics.delete(topicId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\n/**\n * Normalize email address (lowercase, trim)\n */\nfunction normalizeEmail(email: string): string {\n return email.toLowerCase().trim()\n}\n\nexport async function handleUsersAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n const { id: userId } = parsePath(path)\n\n // All user operations require admin\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /users - list all users\n if (method === 'GET' && !userId) {\n const users = await cms.users.findAll()\n return jsonResponse({ data: users })\n }\n\n // GET /users/:id - get single user\n if (method === 'GET' && userId) {\n const user = await cms.users.findById(userId)\n if (!user) return jsonResponse({ error: 'User not found' }, 404)\n return jsonResponse({ data: user })\n }\n\n // POST /users - create user\n if (method === 'POST') {\n const body = await req.json()\n if (!body.email) {\n return jsonResponse({ error: 'Email required' }, 400)\n }\n\n const email = normalizeEmail(body.email)\n \n // Check for duplicate email\n const existing = await cms.users.findByEmail(email)\n if (existing) {\n return jsonResponse({ error: 'User with this email already exists' }, 400)\n }\n\n const user = await cms.users.create({\n ...body,\n email, // Use normalized email\n })\n return jsonResponse({ data: user }, 201)\n }\n\n // PATCH /users/:id - update user\n if (method === 'PATCH' && userId) {\n const body = await req.json()\n const user = await cms.users.update(userId, body)\n return jsonResponse({ data: user })\n }\n\n // DELETE /users/:id - delete user\n if (method === 'DELETE' && userId) {\n await cms.users.delete(userId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleAdminAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n\n // All admin operations require admin role\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /admin/counts - get counts for dashboard\n if (method === 'GET' && path === '/admin/counts') {\n const [users, posts, tags, topics] = await Promise.all([\n cms.users.count(),\n cms.posts.findAll().then(p => p.length),\n cms.tags.findAll().then(t => t.length),\n cms.topics.findAll().then(t => t.length),\n ])\n return jsonResponse({ \n data: { users, posts, tags, topics } \n })\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, requireAuth, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleSettingsAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n const prisma = cms.config.prisma as any\n\n // Check auth\n const authError = requireAuth(session)\n if (authError) return authError\n\n // GET /settings - get general settings\n if (method === 'GET' && path === '/settings') {\n // Get autoDraftEnabled from IntegrationSettings\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n })\n \n return jsonResponse({ \n data: { \n autoDraftEnabled: integrationSettings?.autoDraftEnabled ?? false,\n postUrlPattern: integrationSettings?.postUrlPattern ?? '/e/{slug}',\n } \n })\n }\n\n // PATCH /settings - update general settings\n if (method === 'PATCH' && path === '/settings') {\n // Check admin\n const adminError = requireAdmin(cms, session)\n if (adminError) return adminError\n\n const body = await req.json()\n \n // Build update object\n const updateData: { autoDraftEnabled?: boolean; postUrlPattern?: string } = {}\n if (typeof body.autoDraftEnabled === 'boolean') {\n updateData.autoDraftEnabled = body.autoDraftEnabled\n }\n if (typeof body.postUrlPattern === 'string') {\n updateData.postUrlPattern = body.postUrlPattern\n }\n \n // Upsert IntegrationSettings\n if (Object.keys(updateData).length > 0) {\n await prisma.integrationSettings.upsert({\n where: { id: 'default' },\n create: { id: 'default', ...updateData },\n update: updateData,\n })\n }\n\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n })\n\n return jsonResponse({ \n data: { \n autoDraftEnabled: integrationSettings?.autoDraftEnabled ?? false,\n postUrlPattern: integrationSettings?.postUrlPattern ?? '/e/{slug}',\n } \n })\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleRevisionsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const url = new URL(req.url)\n const { id: revisionId, subPath } = parsePath(path)\n\n // GET /revisions - list all revisions (paginated)\n if (method === 'GET' && !revisionId) {\n const page = parseInt(url.searchParams.get('page') || '1')\n const limit = parseInt(url.searchParams.get('limit') || '25')\n const postId = url.searchParams.get('postId')\n\n const where = postId ? { postId } : {}\n \n const [revisions, total] = await Promise.all([\n cms.revisions.findAll({ ...where, skip: (page - 1) * limit, take: limit }),\n cms.revisions.count(where),\n ])\n\n return jsonResponse({\n data: revisions,\n total,\n page,\n totalPages: Math.ceil(total / limit),\n })\n }\n\n // GET /revisions/:id - get single revision\n if (method === 'GET' && revisionId) {\n const revision = await cms.revisions.findById(revisionId)\n if (!revision) return jsonResponse({ error: 'Revision not found' }, 404)\n return jsonResponse({ data: revision })\n }\n\n // POST /revisions/:id/restore - restore a revision\n if (method === 'POST' && revisionId && subPath === 'restore') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const post = await cms.revisions.restore(revisionId)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post })\n }\n\n // DELETE /revisions/:id - delete a revision\n if (method === 'DELETE' && revisionId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.revisions.delete(revisionId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { PrismaClient } from '@prisma/client'\n\ninterface ChatHistoryRequest {\n role: 'user' | 'assistant'\n content: string\n}\n\n/**\n * Handle chat history API requests.\n * GET - Fetch recent messages\n * POST - Save a new message\n * DELETE - Clear all messages\n */\nexport async function handleChatHistoryAPI(\n req: Request,\n prisma: PrismaClient,\n isAuthenticated: boolean\n): Promise<Response> {\n // Require authentication\n if (!isAuthenticated) {\n return new Response(JSON.stringify({ error: 'Unauthorized' }), {\n status: 401,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const method = req.method\n\n // Check if ChatMessage model exists\n const hasChatMessage = !!(prisma as any).chatMessage\n\n try {\n // GET - Fetch recent messages\n if (method === 'GET') {\n if (!hasChatMessage) {\n return new Response(JSON.stringify([]), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n \n const messages = await (prisma as any).chatMessage.findMany({\n orderBy: { createdAt: 'desc' },\n take: 50,\n })\n \n // Return in chronological order\n return new Response(JSON.stringify(messages.reverse()), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n // POST - Save a new message\n if (method === 'POST') {\n if (!hasChatMessage) {\n // Silently succeed - chat still works, just not persisted\n return new Response(JSON.stringify({ id: 'temp', role: 'user', content: '' }), {\n status: 201,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const body: ChatHistoryRequest = await req.json()\n \n if (!body.role || !body.content) {\n return new Response(JSON.stringify({ error: 'Missing role or content' }), {\n status: 400,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const message = await (prisma as any).chatMessage.create({\n data: {\n role: body.role,\n content: body.content,\n },\n })\n\n return new Response(JSON.stringify(message), {\n status: 201,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n // DELETE - Clear all messages\n if (method === 'DELETE') {\n if (!hasChatMessage) {\n return new Response(JSON.stringify({ success: true }), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n await (prisma as any).chatMessage.deleteMany({})\n \n return new Response(JSON.stringify({ success: true }), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n return new Response(JSON.stringify({ error: 'Method not allowed' }), {\n status: 405,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n console.error('[Chat History API Error]', error)\n return new Response(JSON.stringify({ error: 'Internal server error' }), {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { handlePostsAPI } from './posts'\nimport { handleCommentsAPI } from './comments'\nimport { handleTagsAPI } from './tags'\nimport { handleAIAPI } from './ai'\nimport { handleUploadAPI } from './upload'\nimport { handleTopicsAPI } from './topics'\nimport { handleUsersAPI } from './users'\nimport { handleAdminAPI } from './admin'\nimport { handleSettingsAPI } from './settings'\nimport { handleRevisionsAPI } from './revisions'\nimport { handleChatHistoryAPI } from './chat-history'\n\ninterface APIHandlerOptions {\n basePath?: string\n onMutate?: (type: string, data: unknown) => Promise<void>\n}\n\ntype NextRequest = Request & { nextUrl: URL }\n\nfunction extractPath(pathname: string, basePath: string): string {\n const normalized = pathname.replace(/\\/$/, '')\n const base = basePath.replace(/\\/$/, '')\n \n if (normalized === base) return '/'\n if (normalized.startsWith(base + '/')) {\n return normalized.slice(base.length)\n }\n return '/'\n}\n\nfunction jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\nexport function createAPIHandler(cms: AutobloggerServer, options: APIHandlerOptions = {}) {\n const basePath = options.basePath || '/api/cms'\n \n return async (req: NextRequest): Promise<Response> => {\n const path = extractPath(req.nextUrl.pathname, basePath)\n const method = req.method\n \n // Get session for auth\n let session: Session | null = null\n try {\n session = await cms.config.auth.getSession()\n } catch {\n // Session retrieval failed\n }\n \n // Check auth for protected routes\n const isPublicRoute = path.startsWith('/posts') && method === 'GET'\n if (!isPublicRoute && !session) {\n return jsonResponse({ error: 'Unauthorized' }, 401)\n }\n \n try {\n // Route to handlers\n if (path.startsWith('/posts')) {\n return handlePostsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/comments')) {\n return handleCommentsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/tags')) {\n return handleTagsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/ai')) {\n return handleAIAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/upload')) {\n return handleUploadAPI(req, cms, session)\n }\n \n if (path.startsWith('/topics')) {\n return handleTopicsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/users')) {\n return handleUsersAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/admin')) {\n return handleAdminAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/settings')) {\n return handleSettingsAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/revisions')) {\n return handleRevisionsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/chat/history')) {\n return handleChatHistoryAPI(req, cms.config.prisma, !!session)\n }\n \n return jsonResponse({ error: 'Not found' }, 404)\n } catch (error) {\n console.error('API error:', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Internal server error' \n }, 500)\n }\n }\n}\n\nexport { handlePostsAPI } from './posts'\nexport { handleCommentsAPI } from './comments'\nexport { handleTagsAPI } from './tags'\nexport { handleAIAPI } from './ai'\nexport { handleUploadAPI } from './upload'\nexport { handleTopicsAPI } from './topics'\nexport { handleUsersAPI } from './users'\nexport { handleAdminAPI } from './admin'\nexport { handleSettingsAPI } from './settings'\nexport { handleRevisionsAPI } from './revisions'\nexport { handleChatHistoryAPI } from './chat-history'\n","import Parser from 'rss-parser'\n\nexport interface RssArticle {\n title: string\n url: string\n summary: string | null\n publishedAt: Date | null\n}\n\nconst parser = new Parser({\n timeout: 10000,\n headers: {\n 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n },\n})\n\n/**\n * Fetch and parse multiple RSS feeds, combining all articles.\n */\nexport async function fetchRssFeeds(feedUrls: string[]): Promise<RssArticle[]> {\n const articles: RssArticle[] = []\n\n for (const url of feedUrls) {\n try {\n const feed = await parser.parseURL(url)\n \n for (const item of feed.items) {\n if (!item.title || !item.link) continue\n \n articles.push({\n title: item.title,\n url: item.link,\n summary: item.contentSnippet || item.content || null,\n publishedAt: item.pubDate ? new Date(item.pubDate) : null,\n })\n }\n } catch (error) {\n console.error(`Failed to fetch RSS feed: ${url}`, error)\n // Continue with other feeds\n }\n }\n\n return articles\n}\n","import type { RssArticle } from './rss'\n\n/**\n * Filter articles by keyword matching.\n * Case-insensitive substring match on title and summary.\n */\nexport function filterByKeywords(\n articles: RssArticle[],\n keywords: string[]\n): RssArticle[] {\n if (keywords.length === 0) return articles\n\n const lowerKeywords = keywords.map(k => k.toLowerCase().trim())\n\n return articles.filter(article => {\n const searchText = `${article.title} ${article.summary || ''}`.toLowerCase()\n return lowerKeywords.some(keyword => searchText.includes(keyword))\n })\n}\n","// Models\nexport { \n AI_MODELS, \n getModel, \n getDefaultModel,\n modelHasNativeSearch,\n getSearchModel,\n resolveModel,\n getModelOptions,\n toModelOption,\n LENGTH_OPTIONS,\n} from './models'\nexport type { AIModel, AIModelOption, ModelId, LengthOption } from './models'\n\n// Provider\nexport { createStream, generate, getApiKey } from './provider'\nexport type { ChatMessage } from './provider'\n\n// Generate\nexport { generateStream, expandPlanStream } from './generate'\n\n// Chat\nexport { chatStream } from './chat'\n\n// Builders\nexport { \n buildGeneratePrompt, \n buildChatPrompt, \n buildExpandPlanPrompt, \n buildPlanPrompt, \n buildRewritePrompt, \n buildAutoDraftPrompt \n} from './builders'\n\n// Prompts\nexport {\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_AGENT_TEMPLATE,\n DEFAULT_SEARCH_ONLY_PROMPT,\n buildSearchOnlyPrompt,\n buildPlanPrompt as buildPlanPromptFromPrompts,\n buildChatPrompt as buildChatPromptFromPrompts,\n buildAgentChatPrompt,\n buildGeneratePrompt as buildGeneratePromptFromPrompts,\n buildRewritePrompt as buildRewritePromptFromPrompts,\n buildExpandPlanPrompt as buildExpandPlanPromptFromPrompts,\n} from './prompts'\nexport type { EssayContext, StyleContext } from './prompts'// Parse\nexport { parseGeneratedContent } from './parse'\n","/**\n * Parse AI-generated markdown to extract title, subtitle, and body.\n * \n * Expects format:\n * # Title\n * *Subtitle*\n * \n * Body content...\n */\nexport function parseGeneratedContent(markdown: string): {\n title: string\n subtitle: string\n body: string\n} {\n const lines = markdown.trim().split('\\n')\n let title = ''\n let subtitle = ''\n let bodyStartIndex = 0\n\n // Look for H1 title at the start\n if (lines[0]?.startsWith('# ')) {\n title = lines[0].replace(/^#\\s+/, '').trim()\n bodyStartIndex = 1\n }\n\n // Look for italic subtitle (next non-empty line starting with * and ending with *)\n for (let i = bodyStartIndex; i < lines.length; i++) {\n const line = lines[i].trim()\n if (line === '') continue // skip empty lines\n\n // Check for italic subtitle: *text* or _text_\n const italicMatch = line.match(/^\\*(.+)\\*$/) || line.match(/^_(.+)_$/)\n if (italicMatch) {\n subtitle = italicMatch[1].trim()\n bodyStartIndex = i + 1\n }\n break // stop after first non-empty line (whether it's subtitle or not)\n }\n\n // Skip any leading empty lines after title/subtitle\n while (bodyStartIndex < lines.length && lines[bodyStartIndex].trim() === '') {\n bodyStartIndex++\n }\n\n const body = lines.slice(bodyStartIndex).join('\\n').trim()\n\n return { title, subtitle, body }\n}\n","import { marked } from 'marked'\nimport TurndownService from 'turndown'\n\n// Configure marked for consistent rendering\nmarked.setOptions({\n gfm: true,\n breaks: false,\n})\n\n/**\n * Render markdown to HTML\n */\nexport function renderMarkdown(markdown: string): string {\n return marked.parse(markdown) as string\n}\n\n/**\n * Convert markdown to HTML with GFM and line breaks enabled.\n * Safe for client-side use in components like ChatPanel.\n */\nexport function markdownToHtml(markdown: string): string {\n return marked.parse(markdown, { gfm: true, breaks: true }) as string\n}\n\n/**\n * Parse markdown to tokens (AST)\n */\nexport function parseMarkdown(markdown: string) {\n return marked.lexer(markdown)\n}\n\n// Configure Turndown for HTML to markdown conversion\nconst turndownService = new TurndownService({\n headingStyle: 'atx',\n codeBlockStyle: 'fenced',\n bulletListMarker: '-',\n})\n\n/**\n * Convert HTML to markdown\n */\nexport function htmlToMarkdown(html: string): string {\n return turndownService.turndown(html)\n}\n\n/**\n * Count words in text (markdown or plain text)\n */\nexport function wordCount(text: string): number {\n if (!text) return 0\n return text.trim().split(/\\s+/).filter(Boolean).length\n}\n\n/**\n * Generate URL-safe slug from title\n */\nexport function generateSlug(title: string): string {\n return title\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/\\s+/g, '-')\n .replace(/-+/g, '-')\n .substring(0, 60)\n}\n\nimport sanitizeHtml from 'sanitize-html'\n\n/**\n * Render markdown to sanitized HTML.\n * Safe for public-facing pages where user content is displayed.\n */\nexport function renderMarkdownSanitized(markdown: string): string {\n const html = renderMarkdown(markdown)\n return sanitizeHtml(html, {\n allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']),\n allowedAttributes: {\n ...sanitizeHtml.defaults.allowedAttributes,\n img: ['src', 'alt', 'title'],\n a: ['href', 'target', 'rel'],\n },\n })\n}\n","import { generate, resolveModel, buildAutoDraftPrompt, parseGeneratedContent } from '../ai'\nimport { generateSlug } from '../lib/markdown'\nimport { fetchRssFeeds, type RssArticle } from './rss'\nimport { filterByKeywords } from './keywords'\n\nexport interface GenerationResult {\n topicId: string\n topicName: string\n generated: number\n skipped: number\n}\n\nexport interface AutoDraftConfig {\n prisma: any\n anthropicKey?: string\n openaiKey?: string\n /** Called after generating an essay, before creating the post. Return additional post fields. */\n onPostCreate?: (article: RssArticle, essay: { title: string; subtitle: string | null; markdown: string }) => Record<string, unknown> | Promise<Record<string, unknown>>\n}\n\n/**\n * Get style context from the database for AI generation.\n */\nasync function getStyleContext(prisma: any) {\n const settings = await prisma.aISettings.findUnique({ where: { id: 'default' } })\n const posts = await prisma.post.findMany({\n where: { status: 'published' },\n select: { title: true, subtitle: true, markdown: true },\n orderBy: { publishedAt: 'desc' },\n take: 10,\n })\n \n const styleExamples = posts\n .map((p: { title: string; subtitle?: string; markdown: string }) => \n `# ${p.title}\\n${p.subtitle ? `*${p.subtitle}*\\n\\n` : ''}${p.markdown}`\n )\n .join('\\n\\n---\\n\\n')\n \n return {\n rules: settings?.rules || '',\n autoDraftRules: settings?.autoDraftRules || '',\n styleExamples,\n }\n}\n\n/**\n * Check if a topic should run based on its frequency and lastRunAt.\n */\nfunction shouldRunTopic(topic: { frequency: string; lastRunAt: Date | null }): boolean {\n if (topic.frequency === 'manual') return false\n if (!topic.lastRunAt) return true\n\n const now = new Date()\n const lastRun = new Date(topic.lastRunAt)\n const hoursSinceLastRun = (now.getTime() - lastRun.getTime()) / (1000 * 60 * 60)\n\n if (topic.frequency === 'daily') return hoursSinceLastRun >= 23\n if (topic.frequency === 'weekly') return hoursSinceLastRun >= 167 // ~7 days\n \n return true\n}\n\n/**\n * Deduplicate articles against existing NewsItems (global, across all topics).\n */\nasync function deduplicateArticles(\n prisma: any,\n articles: RssArticle[]\n): Promise<RssArticle[]> {\n const articleUrls = articles.map(a => a.url)\n const existingUrls = await prisma.newsItem.findMany({\n where: { url: { in: articleUrls } },\n select: { url: true },\n })\n \n const urlSet = new Set(existingUrls.map((n: { url: string }) => n.url))\n return articles.filter(a => !urlSet.has(a.url))\n}\n\n/**\n * Generate a unique slug for a post.\n * If the slug already exists, appends -2, -3, etc.\n */\nasync function generateUniqueSlug(prisma: any, title: string): Promise<string> {\n const baseSlug = generateSlug(title)\n \n // Check if base slug is available\n const existing = await prisma.post.findUnique({ where: { slug: baseSlug } })\n if (!existing) return baseSlug\n\n // Find next available suffix\n let suffix = 2\n while (suffix < 100) {\n const candidateSlug = `${baseSlug}-${suffix}`\n const exists = await prisma.post.findUnique({ where: { slug: candidateSlug } })\n if (!exists) return candidateSlug\n suffix++\n }\n\n // Fallback: add random suffix\n return `${baseSlug}-${Date.now()}`\n}\n\n/**\n * Generate an essay from an article using AI.\n */\nasync function generateEssayFromArticle(\n config: AutoDraftConfig,\n article: RssArticle,\n topicName: string,\n essayFocus?: string | null\n): Promise<{ title: string; subtitle: string | null; markdown: string }> {\n const context = await getStyleContext(config.prisma)\n \n const systemPrompt = buildAutoDraftPrompt({\n autoDraftRules: context.autoDraftRules,\n rules: context.rules,\n wordCount: 800,\n styleExamples: context.styleExamples,\n topicName: topicName,\n articleTitle: article.title,\n articleSummary: article.summary || '',\n articleUrl: article.url,\n })\n \n // Resolve the default model\n const model = await resolveModel(undefined, async () => {\n const settings = await config.prisma.aISettings.findUnique({ where: { id: 'default' } })\n return settings?.defaultModel || null\n })\n\n // User prompt is minimal since all instructions are in the system prompt\n const userPrompt = essayFocus \n ? `Write the essay now. Focus on: ${essayFocus}`\n : 'Write the essay now.'\n \n const result = await generate(model.id, systemPrompt, userPrompt, {\n maxTokens: 4096,\n anthropicKey: config.anthropicKey,\n openaiKey: config.openaiKey,\n })\n const parsed = parseGeneratedContent(result.text)\n\n return {\n title: parsed.title || article.title,\n subtitle: parsed.subtitle || null,\n markdown: parsed.body,\n }\n}\n\n/**\n * Run auto-draft for one or all active topics.\n * @param config - Configuration including prisma client and API keys\n * @param topicId - Optional: run for a specific topic only\n * @param skipFrequencyCheck - If true, ignore frequency settings (for manual trigger)\n */\nexport async function runAutoDraft(\n config: AutoDraftConfig,\n topicId?: string,\n skipFrequencyCheck = false\n): Promise<GenerationResult[]> {\n const { prisma } = config\n\n // Check master toggle first\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n }) as { autoDraftEnabled?: boolean } | null\n if (!integrationSettings?.autoDraftEnabled) {\n console.log('Auto-draft is disabled. Skipping.')\n return []\n }\n\n const topics = topicId\n ? await prisma.topicSubscription.findMany({ where: { id: topicId, isActive: true } })\n : await prisma.topicSubscription.findMany({ where: { isActive: true } })\n\n const results: GenerationResult[] = []\n\n for (const topic of topics) {\n // Skip if frequency check applies and topic shouldn't run\n if (!skipFrequencyCheck && !shouldRunTopic(topic)) {\n continue\n }\n\n try {\n // 1. Fetch RSS feeds\n const feedUrls: string[] = JSON.parse(topic.rssFeeds)\n const articles = await fetchRssFeeds(feedUrls)\n\n // 2. Filter by keywords (if enabled)\n const keywords: string[] = JSON.parse(topic.keywords)\n const relevant = topic.useKeywordFilter\n ? filterByKeywords(articles, keywords)\n : articles\n\n // 3. Deduplicate (skip URLs already processed globally)\n const newArticles = await deduplicateArticles(prisma, relevant)\n\n // 4. Generate essays (up to maxPerPeriod)\n const toGenerate = newArticles.slice(0, topic.maxPerPeriod)\n let generated = 0\n\n for (const article of toGenerate) {\n try {\n // Create NewsItem first\n const newsItem = await prisma.newsItem.create({\n data: {\n topicId: topic.id,\n url: article.url,\n title: article.title,\n summary: article.summary,\n publishedAt: article.publishedAt,\n status: 'pending',\n },\n })\n\n // Generate essay with AI\n const essay = await generateEssayFromArticle(config, article, topic.name, topic.essayFocus)\n\n // Generate unique slug\n const slug = await generateUniqueSlug(prisma, essay.title)\n\n // Get additional fields from hook (e.g., polyhedraShape)\n const extraFields = config.onPostCreate \n ? await config.onPostCreate(article, essay)\n : {}\n\n // Create suggested post\n const post = await prisma.post.create({\n data: {\n title: essay.title,\n subtitle: essay.subtitle,\n slug,\n markdown: essay.markdown,\n status: 'suggested',\n sourceUrl: article.url,\n topicId: topic.id,\n ...extraFields,\n },\n })\n\n // Link NewsItem to Post\n await prisma.newsItem.update({\n where: { id: newsItem.id },\n data: { postId: post.id, status: 'generated' },\n })\n\n generated++\n } catch (articleError) {\n console.error(`Failed to process article: ${article.title}`, articleError)\n // Continue with other articles\n }\n }\n\n // 5. Update lastRunAt\n await prisma.topicSubscription.update({\n where: { id: topic.id },\n data: { lastRunAt: new Date() },\n })\n\n results.push({\n topicId: topic.id,\n topicName: topic.name,\n generated,\n skipped: relevant.length - generated,\n })\n } catch (topicError) {\n console.error(`Failed to process topic: ${topic.name}`, topicError)\n results.push({\n topicId: topic.id,\n topicName: topic.name,\n generated: 0,\n skipped: 0,\n })\n }\n }\n\n return results\n}\n","import type { ComponentType } from 'react'\nimport type { Post } from './models'\nimport type { Session } from './session'\nimport type { RssArticle } from '../auto-draft'\n\n// Style configuration for article rendering\nexport interface StylesConfig {\n container?: string\n title?: string\n subtitle?: string\n byline?: string\n prose?: string\n}\n\n// Default styles\nexport const DEFAULT_STYLES: Required<StylesConfig> = {\n container: 'max-w-ab-content mx-auto px-ab-content-padding',\n title: 'text-ab-title font-bold',\n subtitle: 'text-ab-h2 text-muted-foreground',\n byline: 'text-sm text-muted-foreground',\n prose: 'prose',\n}\n\n// Custom field component props (UI-only)\nexport interface CustomFieldProps<T = unknown> {\n value: T\n onChange: (value: T) => void\n onFieldChange: (name: string, value: unknown) => void // Update any post field\n post: Post\n disabled?: boolean\n}\n\n// Custom field definition (UI-only)\nexport interface CustomFieldConfig {\n name: string\n label?: string\n component: ComponentType<CustomFieldProps<unknown>>\n position?: 'footer' | 'sidebar'\n}\n\n// Server-safe configuration (no React types)\nexport interface AutobloggerServerConfig {\n prisma: unknown\n\n auth: {\n getSession: () => Promise<Session | null>\n isAdmin: (session: Session | null) => boolean\n canPublish: (session: Session | null) => boolean\n }\n\n ai?: {\n anthropicKey?: string\n openaiKey?: string\n }\n\n storage?: {\n upload: (file: File) => Promise<{ url: string }>\n }\n\n comments?: {\n mode: 'authenticated' | 'public' | 'disabled'\n }\n\n styles?: StylesConfig\n\n hooks?: {\n beforePublish?: (post: Post) => Promise<void>\n afterSave?: (post: Post) => Promise<void>\n /** Called during auto-draft after generating essay, return extra fields for post creation */\n onAutoDraftPostCreate?: (article: RssArticle, essay: { title: string; subtitle: string | null; markdown: string }) => Record<string, unknown> | Promise<Record<string, unknown>>\n }\n}\n\n// Full configuration with custom fields (includes React types)\nexport interface AutobloggerConfig extends AutobloggerServerConfig {\n fields?: CustomFieldConfig[]\n}\n","// Server-safe exports - no React imports\nimport { createPostsData } from './data/posts'\nimport { createCommentsData } from './data/comments'\nimport { createTagsData } from './data/tags'\nimport { createRevisionsData } from './data/revisions'\nimport { createAISettingsData } from './data/ai-settings'\nimport { createTopicsData } from './data/topics'\nimport { createNewsItemsData } from './data/news-items'\nimport { createUsersData } from './data/users'\nimport { createAPIHandler } from './api'\nimport { runAutoDraft as runAutoDraftInternal, type AutoDraftConfig } from './auto-draft'\nimport type { AutobloggerServerConfig, StylesConfig } from './types/config'\nimport { DEFAULT_STYLES } from './types/config'\n\n// Re-export types for backward compatibility\nexport type { Session } from './types/session'\nexport type { StylesConfig, AutobloggerServerConfig } from './types/config'\n\n// Autoblogger server instance type\nexport interface AutobloggerServer {\n config: AutobloggerServerConfig & { styles: Required<StylesConfig> }\n posts: ReturnType<typeof createPostsData>\n comments: ReturnType<typeof createCommentsData>\n tags: ReturnType<typeof createTagsData>\n revisions: ReturnType<typeof createRevisionsData>\n aiSettings: ReturnType<typeof createAISettingsData>\n topics: ReturnType<typeof createTopicsData>\n newsItems: ReturnType<typeof createNewsItemsData>\n users: ReturnType<typeof createUsersData>\n /** Handle an API request - convenience method for route handlers */\n handleRequest: (req: Request, path: string) => Promise<Response>\n /** Auto-draft runner */\n autoDraft: {\n run: (topicId?: string, skipFrequencyCheck?: boolean) => Promise<import('./auto-draft').GenerationResult[]>\n }\n}\n\n// Create autoblogger server instance\nexport function createAutoblogger(config: AutobloggerServerConfig): AutobloggerServer {\n const prisma = config.prisma as any\n \n const mergedStyles: Required<StylesConfig> = {\n ...DEFAULT_STYLES,\n ...config.styles,\n }\n\n // Create the base server object first (without handleRequest)\n const baseServer = {\n config: {\n ...config,\n styles: mergedStyles,\n },\n posts: createPostsData(prisma, config.hooks),\n comments: createCommentsData(prisma, config.comments),\n tags: createTagsData(prisma),\n revisions: createRevisionsData(prisma),\n aiSettings: createAISettingsData(prisma),\n topics: createTopicsData(prisma),\n newsItems: createNewsItemsData(prisma),\n users: createUsersData(prisma),\n }\n\n // Create the full server with handleRequest and autoDraft\n const server: AutobloggerServer = {\n ...baseServer,\n handleRequest: async () => new Response('Not initialized', { status: 500 }),\n autoDraft: {\n run: async (topicId?: string, skipFrequencyCheck?: boolean) => {\n const autoDraftConfig: AutoDraftConfig = {\n prisma,\n anthropicKey: config.ai?.anthropicKey,\n openaiKey: config.ai?.openaiKey,\n onPostCreate: config.hooks?.onAutoDraftPostCreate,\n }\n return runAutoDraftInternal(autoDraftConfig, topicId, skipFrequencyCheck)\n },\n },\n }\n\n // Create the API handler with the server\n const apiHandler = createAPIHandler(server)\n\n // Now set the real handleRequest implementation\n server.handleRequest = async (req: Request, path: string): Promise<Response> => {\n // Normalize path to start with /\n const normalizedPath = '/' + path.replace(/^\\//, '')\n \n // Build the full URL the handler expects\n const originalUrl = new URL(req.url)\n const newUrl = new URL(originalUrl.origin + '/api/cms' + normalizedPath)\n \n // Copy search params\n originalUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value)\n })\n \n // Create a new request with nextUrl property (required by the handler)\n const handlerReq = new Request(newUrl.toString(), {\n method: req.method,\n headers: req.headers,\n body: req.method !== 'GET' && req.method !== 'HEAD' ? req.body : undefined,\n // @ts-ignore - duplex is needed for streaming bodies\n duplex: req.method !== 'GET' && req.method !== 'HEAD' ? 'half' : undefined,\n }) as Request & { nextUrl: URL }\n \n // Add nextUrl property\n Object.defineProperty(handlerReq, 'nextUrl', {\n value: newUrl,\n writable: false,\n })\n \n return apiHandler(handlerReq)\n }\n\n return server\n}\n","// Schema validation helper\n\nconst REQUIRED_TABLES = [\n 'Post',\n 'Revision',\n 'Comment',\n 'Tag',\n 'PostTag',\n 'AISettings',\n 'TopicSubscription',\n 'NewsItem',\n]\n\nexport interface SchemaValidationResult {\n valid: boolean\n missingTables: string[]\n}\n\nexport async function validateSchema(prisma: unknown): Promise<SchemaValidationResult> {\n const p = prisma as any\n const missingTables: string[] = []\n\n for (const table of REQUIRED_TABLES) {\n const modelName = table.charAt(0).toLowerCase() + table.slice(1)\n try {\n // Try to access the model - if it doesn't exist, it will throw\n if (!p[modelName]) {\n missingTables.push(table)\n } else {\n // Try a simple query to verify the table exists\n await p[modelName].findFirst({ take: 1 }).catch(() => {\n missingTables.push(table)\n })\n }\n } catch {\n missingTables.push(table)\n }\n }\n\n return {\n valid: missingTables.length === 0,\n missingTables,\n }\n}\n","const MINUTE = 60_000, HOUR = 3_600_000, DAY = 86_400_000\n\n/**\n * Format a date as relative time (e.g., \"5m ago\", \"2h ago\", \"Yesterday\")\n */\nexport function formatRelativeTime(isoDate: string): string {\n const date = new Date(isoDate)\n const diffMs = Date.now() - date.getTime()\n const mins = Math.floor(diffMs / MINUTE)\n const hours = Math.floor(diffMs / HOUR)\n const days = Math.floor(diffMs / DAY)\n \n if (mins < 1) return 'Just now'\n if (mins < 60) return `${mins}m ago`\n if (hours < 24) return `${hours}h ago`\n if (days === 1) return 'Yesterday'\n if (days < 7) return `${days}d ago`\n return date.toLocaleDateString()\n}\n\n/**\n * Format a date for display\n */\nexport function formatDate(date: Date | string, options?: Intl.DateTimeFormatOptions): string {\n const d = typeof date === 'string' ? new Date(date) : date\n \n const defaultOptions: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n }\n \n return d.toLocaleDateString('en-US', options || defaultOptions)\n}\n\n/**\n * Format saved time for display (e.g., \"just now\", \"5m ago\", \"2:30 PM\")\n */\nexport function formatSavedTime(date: Date): string {\n const now = new Date()\n const diffMs = now.getTime() - date.getTime()\n const diffSecs = Math.floor(diffMs / 1000)\n const diffMins = Math.floor(diffMs / MINUTE)\n \n // Show relative time for recent saves\n if (diffSecs < 10) return 'just now'\n if (diffSecs < 60) return `${diffSecs}s ago`\n if (diffMins < 60) return `${diffMins}m ago`\n \n // Show clock time for today\n const isToday = date.toDateString() === now.toDateString()\n if (isToday) {\n return date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })\n }\n \n return date.toLocaleDateString('en-US', { \n month: 'short', \n day: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n })\n}\n\n/**\n * Count words in text\n */\nexport function countWords(text?: string | null): number {\n if (!text) return 0\n return text.split(/\\s+/).filter(Boolean).length\n}\n\n/**\n * Truncate text to a maximum length\n */\nexport function truncate(text: string, maxLength: number): string {\n // Strip markdown formatting for description\n const stripped = text\n .replace(/#+\\s/g, '')\n .replace(/\\*\\*/g, '')\n .replace(/\\*/g, '')\n .replace(/`/g, '')\n .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1')\n .replace(/\\n+/g, ' ')\n .trim()\n \n if (stripped.length <= maxLength) return stripped\n \n return stripped.slice(0, maxLength - 3).trim() + '...'\n}\n","import type { Post } from '../types'\nimport { truncate } from './format'\n\nexport interface SeoValues {\n title: string\n description: string\n keywords?: string | null\n noIndex: boolean\n ogImage?: string | null\n}\n\n/**\n * Get SEO values from a post with fallbacks\n */\nexport function getSeoValues(post: Post): SeoValues {\n return {\n title: post.seoTitle || post.title,\n description: post.seoDescription || post.subtitle || truncate(post.markdown, 160),\n keywords: post.seoKeywords,\n noIndex: post.noIndex,\n ogImage: post.ogImage,\n }\n}\n","/**\n * Comment types and client-side API helpers for the editor commenting system.\n * Used for collaborative inline comments on posts.\n */\n\n// Types matching Prisma schema + includes\nexport interface CommentUser {\n id: string\n name: string | null\n email: string\n}\n\nexport interface CommentWithUser {\n id: string\n postId: string\n userId: string\n quotedText: string\n content: string\n parentId: string | null\n resolved: boolean\n createdAt: string\n updatedAt: string\n user: CommentUser\n replies?: CommentWithUser[]\n}\n\nexport interface CreateCommentData {\n quotedText: string\n content: string\n parentId?: string\n}\n\nexport interface SelectionState {\n text: string\n from: number\n to: number\n hasExistingComment?: boolean\n}\n\n// Permission helpers (compare by email since that's what we have in session)\nexport function canDeleteComment(\n comment: CommentWithUser,\n currentUserEmail: string,\n isAdmin: boolean\n): boolean {\n return comment.user.email === currentUserEmail || isAdmin\n}\n\nexport function canEditComment(\n comment: CommentWithUser,\n currentUserEmail: string\n): boolean {\n return comment.user.email === currentUserEmail\n}\n\n// API client factory - creates functions bound to a specific API base path\nexport function createCommentsClient(apiBasePath: string = '/api/cms') {\n return {\n async fetchComments(postId: string): Promise<CommentWithUser[]> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments`)\n if (!res.ok) throw new Error('Failed to fetch comments')\n const json = await res.json()\n return json.data || json\n },\n\n async createComment(\n postId: string,\n data: CreateCommentData\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(data),\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to create comment')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async updateComment(\n postId: string,\n commentId: string,\n content: string\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}`, {\n method: 'PATCH',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ content }),\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to update comment')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async deleteComment(\n postId: string,\n commentId: string\n ): Promise<void> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}`, {\n method: 'DELETE',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to delete comment')\n }\n },\n\n async toggleResolve(\n postId: string,\n commentId: string\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}/resolve`, {\n method: 'POST',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to toggle resolve')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async resolveAllComments(\n postId: string\n ): Promise<{ resolved: number }> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/resolve-all`, {\n method: 'POST',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to resolve all comments')\n }\n const json = await res.json()\n return json.data || json\n },\n }\n}\n","import type { EditorState, Transaction } from '@tiptap/pm/state'\n\n/**\n * Takes a Transaction & Editor State and turns it into a chainable state object\n * @param config The transaction and state to create the chainable state from\n * @returns A chainable Editor state object\n */\nexport function createChainableState(config: { transaction: Transaction; state: EditorState }): EditorState {\n const { state, transaction } = config\n let { selection } = transaction\n let { doc } = transaction\n let { storedMarks } = transaction\n\n return {\n ...state,\n apply: state.apply.bind(state),\n applyTransaction: state.applyTransaction.bind(state),\n plugins: state.plugins,\n schema: state.schema,\n reconfigure: state.reconfigure.bind(state),\n toJSON: state.toJSON.bind(state),\n get storedMarks() {\n return storedMarks\n },\n get selection() {\n return selection\n },\n get doc() {\n return doc\n },\n get tr() {\n selection = transaction.selection\n doc = transaction.doc\n storedMarks = transaction.storedMarks\n\n return transaction\n },\n }\n}\n","import type { EditorState, Transaction } from '@tiptap/pm/state'\n\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport type { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types.js'\n\nexport class CommandManager {\n editor: Editor\n\n rawCommands: AnyCommands\n\n customState?: EditorState\n\n constructor(props: { editor: Editor; state?: EditorState }) {\n this.editor = props.editor\n this.rawCommands = this.editor.extensionManager.commands\n this.customState = props.state\n }\n\n get hasCustomState(): boolean {\n return !!this.customState\n }\n\n get state(): EditorState {\n return this.customState || this.editor.state\n }\n\n get commands(): SingleCommands {\n const { rawCommands, editor, state } = this\n const { view } = editor\n const { tr } = state\n const props = this.buildProps(tr)\n\n return Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n const method = (...args: any[]) => {\n const callback = command(...args)(props)\n\n if (!tr.getMeta('preventDispatch') && !this.hasCustomState) {\n view.dispatch(tr)\n }\n\n return callback\n }\n\n return [name, method]\n }),\n ) as unknown as SingleCommands\n }\n\n get chain(): () => ChainedCommands {\n return () => this.createChain()\n }\n\n get can(): () => CanCommands {\n return () => this.createCan()\n }\n\n public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {\n const { rawCommands, editor, state } = this\n const { view } = editor\n const callbacks: boolean[] = []\n const hasStartTransaction = !!startTr\n const tr = startTr || state.tr\n\n const run = () => {\n if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch') && !this.hasCustomState) {\n view.dispatch(tr)\n }\n\n return callbacks.every(callback => callback === true)\n }\n\n const chain = {\n ...Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n const chainedCommand = (...args: never[]) => {\n const props = this.buildProps(tr, shouldDispatch)\n const callback = command(...args)(props)\n\n callbacks.push(callback)\n\n return chain\n }\n\n return [name, chainedCommand]\n }),\n ),\n run,\n } as unknown as ChainedCommands\n\n return chain\n }\n\n public createCan(startTr?: Transaction): CanCommands {\n const { rawCommands, state } = this\n const dispatch = false\n const tr = startTr || state.tr\n const props = this.buildProps(tr, dispatch)\n const formattedCommands = Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]\n }),\n ) as unknown as SingleCommands\n\n return {\n ...formattedCommands,\n chain: () => this.createChain(tr, dispatch),\n } as CanCommands\n }\n\n public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {\n const { rawCommands, editor, state } = this\n const { view } = editor\n\n const props: CommandProps = {\n tr,\n editor,\n view,\n state: createChainableState({\n state,\n transaction: tr,\n }),\n dispatch: shouldDispatch ? () => undefined : undefined,\n chain: () => this.createChain(tr, shouldDispatch),\n can: () => this.createCan(tr),\n get commands() {\n return Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n return [name, (...args: never[]) => command(...args)(props)]\n }),\n ) as unknown as SingleCommands\n },\n }\n\n return props\n }\n}\n","export * from './blur.js'\nexport * from './clearContent.js'\nexport * from './clearNodes.js'\nexport * from './command.js'\nexport * from './createParagraphNear.js'\nexport * from './cut.js'\nexport * from './deleteCurrentNode.js'\nexport * from './deleteNode.js'\nexport * from './deleteRange.js'\nexport * from './deleteSelection.js'\nexport * from './enter.js'\nexport * from './exitCode.js'\nexport * from './extendMarkRange.js'\nexport * from './first.js'\nexport * from './focus.js'\nexport * from './forEach.js'\nexport * from './insertContent.js'\nexport * from './insertContentAt.js'\nexport * from './join.js'\nexport * from './joinItemBackward.js'\nexport * from './joinItemForward.js'\nexport * from './joinTextblockBackward.js'\nexport * from './joinTextblockForward.js'\nexport * from './keyboardShortcut.js'\nexport * from './lift.js'\nexport * from './liftEmptyBlock.js'\nexport * from './liftListItem.js'\nexport * from './newlineInCode.js'\nexport * from './resetAttributes.js'\nexport * from './scrollIntoView.js'\nexport * from './selectAll.js'\nexport * from './selectNodeBackward.js'\nexport * from './selectNodeForward.js'\nexport * from './selectParentNode.js'\nexport * from './selectTextblockEnd.js'\nexport * from './selectTextblockStart.js'\nexport * from './setContent.js'\nexport * from './setMark.js'\nexport * from './setMeta.js'\nexport * from './setNode.js'\nexport * from './setNodeSelection.js'\nexport * from './setTextDirection.js'\nexport * from './setTextSelection.js'\nexport * from './sinkListItem.js'\nexport * from './splitBlock.js'\nexport * from './splitListItem.js'\nexport * from './toggleList.js'\nexport * from './toggleMark.js'\nexport * from './toggleNode.js'\nexport * from './toggleWrap.js'\nexport * from './undoInputRule.js'\nexport * from './unsetAllMarks.js'\nexport * from './unsetMark.js'\nexport * from './unsetTextDirection.js'\nexport * from './updateAttributes.js'\nexport * from './wrapIn.js'\nexport * from './wrapInList.js'\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n blur: {\n /**\n * Removes focus from the editor.\n * @example editor.commands.blur()\n */\n blur: () => ReturnType\n }\n }\n}\n\nexport const blur: RawCommands['blur'] =\n () =>\n ({ editor, view }) => {\n requestAnimationFrame(() => {\n if (!editor.isDestroyed) {\n ;(view.dom as HTMLElement).blur()\n\n // Browsers should remove the caret on blur but safari does not.\n // See: https://github.com/ueberdosis/tiptap/issues/2405\n window?.getSelection()?.removeAllRanges()\n }\n })\n\n return true\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n clearContent: {\n /**\n * Clear the whole document.\n * @example editor.commands.clearContent()\n */\n clearContent: (\n /**\n * Whether to emit an update event.\n * @default true\n */\n emitUpdate?: boolean,\n ) => ReturnType\n }\n }\n}\n\nexport const clearContent: RawCommands['clearContent'] =\n (emitUpdate = true) =>\n ({ commands }) => {\n return commands.setContent('', { emitUpdate })\n }\n","import { liftTarget } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n clearNodes: {\n /**\n * Normalize nodes to a simple paragraph.\n * @example editor.commands.clearNodes()\n */\n clearNodes: () => ReturnType\n }\n }\n}\n\nexport const clearNodes: RawCommands['clearNodes'] =\n () =>\n ({ state, tr, dispatch }) => {\n const { selection } = tr\n const { ranges } = selection\n\n if (!dispatch) {\n return true\n }\n\n ranges.forEach(({ $from, $to }) => {\n state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {\n if (node.type.isText) {\n return\n }\n\n const { doc, mapping } = tr\n const $mappedFrom = doc.resolve(mapping.map(pos))\n const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize))\n const nodeRange = $mappedFrom.blockRange($mappedTo)\n\n if (!nodeRange) {\n return\n }\n\n const targetLiftDepth = liftTarget(nodeRange)\n\n if (node.type.isTextblock) {\n const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index())\n\n tr.setNodeMarkup(nodeRange.start, defaultType)\n }\n\n if (targetLiftDepth || targetLiftDepth === 0) {\n tr.lift(nodeRange, targetLiftDepth)\n }\n })\n })\n\n return true\n }\n","import type { Command, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n command: {\n /**\n * Define a command inline.\n * @param fn The command function.\n * @example\n * editor.commands.command(({ tr, state }) => {\n * ...\n * return true\n * })\n */\n command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType\n }\n }\n}\n\nexport const command: RawCommands['command'] = fn => props => {\n return fn(props)\n}\n","import { createParagraphNear as originalCreateParagraphNear } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n createParagraphNear: {\n /**\n * Create a paragraph nearby.\n * @example editor.commands.createParagraphNear()\n */\n createParagraphNear: () => ReturnType\n }\n }\n}\n\nexport const createParagraphNear: RawCommands['createParagraphNear'] =\n () =>\n ({ state, dispatch }) => {\n return originalCreateParagraphNear(state, dispatch)\n }\n","import { TextSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n cut: {\n /**\n * Cuts content from a range and inserts it at a given position.\n * @param range The range to cut.\n * @param range.from The start position of the range.\n * @param range.to The end position of the range.\n * @param targetPos The position to insert the content at.\n * @example editor.commands.cut({ from: 1, to: 3 }, 5)\n */\n cut: ({ from, to }: { from: number; to: number }, targetPos: number) => ReturnType\n }\n }\n}\n\nexport const cut: RawCommands['cut'] =\n (originRange, targetPos) =>\n ({ editor, tr }) => {\n const { state } = editor\n\n const contentSlice = state.doc.slice(originRange.from, originRange.to)\n\n tr.deleteRange(originRange.from, originRange.to)\n const newPos = tr.mapping.map(targetPos)\n\n tr.insert(newPos, contentSlice.content)\n\n tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))))\n\n return true\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteCurrentNode: {\n /**\n * Delete the node that currently has the selection anchor.\n * @example editor.commands.deleteCurrentNode()\n */\n deleteCurrentNode: () => ReturnType\n }\n }\n}\n\nexport const deleteCurrentNode: RawCommands['deleteCurrentNode'] =\n () =>\n ({ tr, dispatch }) => {\n const { selection } = tr\n const currentNode = selection.$anchor.node()\n\n // if there is content inside the current node, break out of this command\n if (currentNode.content.size > 0) {\n return false\n }\n\n const $pos = tr.selection.$anchor\n\n for (let depth = $pos.depth; depth > 0; depth -= 1) {\n const node = $pos.node(depth)\n\n if (node.type === currentNode.type) {\n if (dispatch) {\n const from = $pos.before(depth)\n const to = $pos.after(depth)\n\n tr.delete(from, to).scrollIntoView()\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {\n if (typeof nameOrType === 'string') {\n if (!schema.nodes[nameOrType]) {\n throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`)\n }\n\n return schema.nodes[nameOrType]\n }\n\n return nameOrType\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteNode: {\n /**\n * Delete a node with a given type or name.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.deleteNode('paragraph')\n */\n deleteNode: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const deleteNode: RawCommands['deleteNode'] =\n typeOrName =>\n ({ tr, state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n const $pos = tr.selection.$anchor\n\n for (let depth = $pos.depth; depth > 0; depth -= 1) {\n const node = $pos.node(depth)\n\n if (node.type === type) {\n if (dispatch) {\n const from = $pos.before(depth)\n const to = $pos.after(depth)\n\n tr.delete(from, to).scrollIntoView()\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteRange: {\n /**\n * Delete a given range.\n * @param range The range to delete.\n * @example editor.commands.deleteRange({ from: 1, to: 3 })\n */\n deleteRange: (range: Range) => ReturnType\n }\n }\n}\n\nexport const deleteRange: RawCommands['deleteRange'] =\n range =>\n ({ tr, dispatch }) => {\n const { from, to } = range\n\n if (dispatch) {\n tr.delete(from, to)\n }\n\n return true\n }\n","import { deleteSelection as originalDeleteSelection } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteSelection: {\n /**\n * Delete the selection, if there is one.\n * @example editor.commands.deleteSelection()\n */\n deleteSelection: () => ReturnType\n }\n }\n}\n\nexport const deleteSelection: RawCommands['deleteSelection'] =\n () =>\n ({ state, dispatch }) => {\n return originalDeleteSelection(state, dispatch)\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n enter: {\n /**\n * Trigger enter.\n * @example editor.commands.enter()\n */\n enter: () => ReturnType\n }\n }\n}\n\nexport const enter: RawCommands['enter'] =\n () =>\n ({ commands }) => {\n return commands.keyboardShortcut('Enter')\n }\n","import { exitCode as originalExitCode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n exitCode: {\n /**\n * Exit from a code block.\n * @example editor.commands.exitCode()\n */\n exitCode: () => ReturnType\n }\n }\n}\n\nexport const exitCode: RawCommands['exitCode'] =\n () =>\n ({ state, dispatch }) => {\n return originalExitCode(state, dispatch)\n }\n","import type { MarkType } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\n\nimport { getMarkRange } from '../helpers/getMarkRange.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n extendMarkRange: {\n /**\n * Extends the text selection to the current mark by type or name.\n * @param typeOrName The type or name of the mark.\n * @param attributes The attributes of the mark.\n * @example editor.commands.extendMarkRange('bold')\n * @example editor.commands.extendMarkRange('mention', { userId: \"1\" })\n */\n extendMarkRange: (\n /**\n * The type or name of the mark.\n */\n typeOrName: string | MarkType,\n\n /**\n * The attributes of the mark.\n */\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const extendMarkRange: RawCommands['extendMarkRange'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n const type = getMarkType(typeOrName, state.schema)\n const { doc, selection } = tr\n const { $from, from, to } = selection\n\n if (dispatch) {\n const range = getMarkRange($from, type, attributes)\n\n if (range && range.from <= from && range.to >= to) {\n const newSelection = TextSelection.create(doc, range.from, range.to)\n\n tr.setSelection(newSelection)\n }\n }\n\n return true\n }\n","export function isRegExp(value: any): value is RegExp {\n return Object.prototype.toString.call(value) === '[object RegExp]'\n}\n","import { isRegExp } from './isRegExp.js'\n\n/**\n * Check if object1 includes object2\n * @param object1 Object\n * @param object2 Object\n */\nexport function objectIncludes(\n object1: Record<string, any>,\n object2: Record<string, any>,\n options: { strict: boolean } = { strict: true },\n): boolean {\n const keys = Object.keys(object2)\n\n if (!keys.length) {\n return true\n }\n\n return keys.every(key => {\n if (options.strict) {\n return object2[key] === object1[key]\n }\n\n if (isRegExp(object2[key])) {\n return object2[key].test(object1[key])\n }\n\n return object2[key] === object1[key]\n })\n}\n","import type { Mark as ProseMirrorMark, MarkType, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Range } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\n\nfunction findMarkInSet(\n marks: ProseMirrorMark[],\n type: MarkType,\n attributes: Record<string, any> = {},\n): ProseMirrorMark | undefined {\n return marks.find(item => {\n return (\n item.type === type &&\n objectIncludes(\n // Only check equality for the attributes that are provided\n Object.fromEntries(Object.keys(attributes).map(k => [k, item.attrs[k]])),\n attributes,\n )\n )\n })\n}\n\nfunction isMarkInSet(marks: ProseMirrorMark[], type: MarkType, attributes: Record<string, any> = {}): boolean {\n return !!findMarkInSet(marks, type, attributes)\n}\n\n/**\n * Get the range of a mark at a resolved position.\n */\nexport function getMarkRange(\n /**\n * The position to get the mark range for.\n */\n $pos: ResolvedPos,\n /**\n * The mark type to get the range for.\n */\n type: MarkType,\n /**\n * The attributes to match against.\n * If not provided, only the first mark at the position will be matched.\n */\n attributes?: Record<string, any>,\n): Range | void {\n if (!$pos || !type) {\n return\n }\n let start = $pos.parent.childAfter($pos.parentOffset)\n\n // If the cursor is at the start of a text node that does not have the mark, look backward\n if (!start.node || !start.node.marks.some(mark => mark.type === type)) {\n start = $pos.parent.childBefore($pos.parentOffset)\n }\n\n // If there is no text node with the mark even backward, return undefined\n if (!start.node || !start.node.marks.some(mark => mark.type === type)) {\n return\n }\n\n // Default to only matching against the first mark's attributes\n attributes = attributes || start.node.marks[0]?.attrs\n\n // We now know that the cursor is either at the start, middle or end of a text node with the specified mark\n // so we can look it up on the targeted mark\n const mark = findMarkInSet([...start.node.marks], type, attributes)\n\n if (!mark) {\n return\n }\n\n let startIndex = start.index\n let startPos = $pos.start() + start.offset\n let endIndex = startIndex + 1\n let endPos = startPos + start.node.nodeSize\n\n while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) {\n startIndex -= 1\n startPos -= $pos.parent.child(startIndex).nodeSize\n }\n\n while (endIndex < $pos.parent.childCount && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {\n endPos += $pos.parent.child(endIndex).nodeSize\n endIndex += 1\n }\n\n return {\n from: startPos,\n to: endPos,\n }\n}\n","import type { MarkType, Schema } from '@tiptap/pm/model'\n\nexport function getMarkType(nameOrType: string | MarkType, schema: Schema): MarkType {\n if (typeof nameOrType === 'string') {\n if (!schema.marks[nameOrType]) {\n throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`)\n }\n\n return schema.marks[nameOrType]\n }\n\n return nameOrType\n}\n","import type { Command, CommandProps, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n first: {\n /**\n * Runs one command after the other and stops at the first which returns true.\n * @param commands The commands to run.\n * @example editor.commands.first([command1, command2])\n */\n first: (commands: Command[] | ((props: CommandProps) => Command[])) => ReturnType\n }\n }\n}\n\nexport const first: RawCommands['first'] = commands => props => {\n const items = typeof commands === 'function' ? commands(props) : commands\n\n for (let i = 0; i < items.length; i += 1) {\n if (items[i](props)) {\n return true\n }\n }\n\n return false\n}\n","import { TextSelection } from '@tiptap/pm/state'\n\nexport function isTextSelection(value: unknown): value is TextSelection {\n return value instanceof TextSelection\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Selection, TextSelection } from '@tiptap/pm/state'\n\nimport type { FocusPosition } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\nexport function resolveFocusPosition(doc: ProseMirrorNode, position: FocusPosition = null): Selection | null {\n if (!position) {\n return null\n }\n\n const selectionAtStart = Selection.atStart(doc)\n const selectionAtEnd = Selection.atEnd(doc)\n\n if (position === 'start' || position === true) {\n return selectionAtStart\n }\n\n if (position === 'end') {\n return selectionAtEnd\n }\n\n const minPos = selectionAtStart.from\n const maxPos = selectionAtEnd.to\n\n if (position === 'all') {\n return TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos))\n }\n\n return TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos))\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","export function isAndroid(): boolean {\n return navigator.platform === 'Android' || /android/i.test(navigator.userAgent)\n}\n","export function isiOS(): boolean {\n return (\n ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes('Mac') && 'ontouchend' in document)\n )\n}\n","/**\n * Detects if the current browser is Safari (but not iOS Safari or Chrome).\n * @returns `true` if the browser is Safari, `false` otherwise.\n * @example\n * if (isSafari()) {\n * // Safari-specific handling\n * }\n */\nexport function isSafari(): boolean {\n return typeof navigator !== 'undefined' ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false\n}\n","import { isTextSelection } from '../helpers/isTextSelection.js'\nimport { resolveFocusPosition } from '../helpers/resolveFocusPosition.js'\nimport type { FocusPosition, RawCommands } from '../types.js'\nimport { isAndroid } from '../utilities/isAndroid.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isSafari } from '../utilities/isSafari.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n focus: {\n /**\n * Focus the editor at the given position.\n * @param position The position to focus at.\n * @param options.scrollIntoView Scroll the focused position into view after focusing\n * @example editor.commands.focus()\n * @example editor.commands.focus(32, { scrollIntoView: false })\n */\n focus: (\n /**\n * The position to focus at.\n */\n position?: FocusPosition,\n\n /**\n * Optional options\n * @default { scrollIntoView: true }\n */\n options?: {\n scrollIntoView?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const focus: RawCommands['focus'] =\n (position = null, options = {}) =>\n ({ editor, view, tr, dispatch }) => {\n options = {\n scrollIntoView: true,\n ...options,\n }\n\n const delayedFocus = () => {\n // focus within `requestAnimationFrame` breaks focus on iOS and Android\n // so we have to call this\n if (isiOS() || isAndroid()) {\n ;(view.dom as HTMLElement).focus()\n }\n\n // Safari requires preventScroll to avoid the browser scrolling to the\n // top of the editor when focus is called before the selection is set.\n // We exclude iOS and Android since they are already handled above.\n // see: https://github.com/ueberdosis/tiptap/issues/7318\n if (isSafari() && !isiOS() && !isAndroid()) {\n ;(view.dom as HTMLElement).focus({ preventScroll: true })\n }\n\n // For React we have to focus asynchronously. Otherwise wild things happen.\n // see: https://github.com/ueberdosis/tiptap/issues/1520\n requestAnimationFrame(() => {\n if (!editor.isDestroyed) {\n view.focus()\n\n if (options?.scrollIntoView) {\n editor.commands.scrollIntoView()\n }\n }\n })\n }\n\n if ((view.hasFocus() && position === null) || position === false) {\n return true\n }\n\n // we don’t try to resolve a NodeSelection or CellSelection\n if (dispatch && position === null && !isTextSelection(editor.state.selection)) {\n delayedFocus()\n return true\n }\n\n // pass through tr.doc instead of editor.state.doc\n // since transactions could change the editors state before this command has been run\n const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection\n const isSameSelection = editor.state.selection.eq(selection)\n\n if (dispatch) {\n if (!isSameSelection) {\n tr.setSelection(selection)\n }\n\n // `tr.setSelection` resets the stored marks\n // so we’ll restore them if the selection is the same as before\n if (isSameSelection && tr.storedMarks) {\n tr.setStoredMarks(tr.storedMarks)\n }\n\n delayedFocus()\n }\n\n return true\n }\n","import type { CommandProps, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n forEach: {\n /**\n * Loop through an array of items.\n */\n forEach: <T>(\n items: T[],\n fn: (\n item: T,\n props: CommandProps & {\n index: number\n },\n ) => boolean,\n ) => ReturnType\n }\n }\n}\n\nexport const forEach: RawCommands['forEach'] = (items, fn) => props => {\n return items.every((item, index) => fn(item, { ...props, index }))\n}\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\n\nimport type { Content, RawCommands } from '../types.js'\n\nexport interface InsertContentOptions {\n /**\n * Options for parsing the content.\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to update the selection after inserting the content.\n */\n updateSelection?: boolean\n applyInputRules?: boolean\n applyPasteRules?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertContent: {\n /**\n * Insert a node or string of HTML at the current position.\n * @example editor.commands.insertContent('<h1>Example</h1>')\n * @example editor.commands.insertContent('<h1>Example</h1>', { updateSelection: false })\n */\n insertContent: (\n /**\n * The ProseMirror content to insert.\n */\n value: Content | ProseMirrorNode | Fragment,\n\n /**\n * Optional options\n */\n options?: InsertContentOptions,\n ) => ReturnType\n }\n }\n}\n\nexport const insertContent: RawCommands['insertContent'] =\n (value, options) =>\n ({ tr, commands }) => {\n return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)\n }\n","import type { Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\n\nimport { createNodeFromContent } from '../helpers/createNodeFromContent.js'\nimport { selectionToInsertionEnd } from '../helpers/selectionToInsertionEnd.js'\nimport type { Content, Range, RawCommands } from '../types.js'\n\nexport interface InsertContentAtOptions {\n /**\n * Options for parsing the content.\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to update the selection after inserting the content.\n */\n updateSelection?: boolean\n\n /**\n * Whether to apply input rules after inserting the content.\n */\n applyInputRules?: boolean\n\n /**\n * Whether to apply paste rules after inserting the content.\n */\n applyPasteRules?: boolean\n\n /**\n * Whether to throw an error if the content is invalid.\n */\n errorOnInvalidContent?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertContentAt: {\n /**\n * Insert a node or string of HTML at a specific position.\n * @example editor.commands.insertContentAt(0, '<h1>Example</h1>')\n */\n insertContentAt: (\n /**\n * The position to insert the content at.\n */\n position: number | Range,\n\n /**\n * The ProseMirror content to insert.\n */\n value: Content | ProseMirrorNode | Fragment,\n\n /**\n * Optional options\n */\n options?: InsertContentAtOptions,\n ) => ReturnType\n }\n }\n}\n\nconst isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment is Fragment => {\n return !('type' in nodeOrFragment)\n}\n\nexport const insertContentAt: RawCommands['insertContentAt'] =\n (position, value, options) =>\n ({ tr, dispatch, editor }) => {\n if (dispatch) {\n options = {\n parseOptions: editor.options.parseOptions,\n updateSelection: true,\n applyInputRules: false,\n applyPasteRules: false,\n ...options,\n }\n\n let content: Fragment | ProseMirrorNode\n\n const emitContentError = (error: Error) => {\n editor.emit('contentError', {\n editor,\n error,\n disableCollaboration: () => {\n if (\n 'collaboration' in editor.storage &&\n typeof editor.storage.collaboration === 'object' &&\n editor.storage.collaboration\n ) {\n ;(editor.storage.collaboration as any).isDisabled = true\n }\n },\n })\n }\n\n const parseOptions: ParseOptions = {\n preserveWhitespace: 'full',\n ...options.parseOptions,\n }\n\n // If `emitContentError` is enabled, we want to check the content for errors\n // but ignore them (do not remove the invalid content from the document)\n if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {\n try {\n createNodeFromContent(value, editor.schema, {\n parseOptions,\n errorOnInvalidContent: true,\n })\n } catch (e) {\n emitContentError(e as Error)\n }\n }\n\n try {\n content = createNodeFromContent(value, editor.schema, {\n parseOptions,\n errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n } catch (e) {\n emitContentError(e as Error)\n return false\n }\n\n let { from, to } =\n typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to }\n\n let isOnlyTextContent = true\n let isOnlyBlockContent = true\n const nodes = isFragment(content) ? content : [content]\n\n nodes.forEach(node => {\n // check if added node is valid\n node.check()\n\n isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false\n\n isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false\n })\n\n // check if we can replace the wrapping node by\n // the newly inserted content\n // example:\n // replace an empty paragraph by an inserted image\n // instead of inserting the image below the paragraph\n if (from === to && isOnlyBlockContent) {\n const { parent } = tr.doc.resolve(from)\n const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount\n\n if (isEmptyTextBlock) {\n from -= 1\n to += 1\n }\n }\n\n let newContent\n\n // if there is only plain text we have to use `insertText`\n // because this will keep the current marks\n if (isOnlyTextContent) {\n // if value is string, we can use it directly\n // otherwise if it is an array, we have to join it\n if (Array.isArray(value)) {\n newContent = value.map(v => v.text || '').join('')\n } else if (value instanceof Fragment) {\n let text = ''\n\n value.forEach(node => {\n if (node.text) {\n text += node.text\n }\n })\n\n newContent = text\n } else if (typeof value === 'object' && !!value && !!value.text) {\n newContent = value.text\n } else {\n newContent = value as string\n }\n\n tr.insertText(newContent, from, to)\n } else {\n newContent = content\n\n const $from = tr.doc.resolve(from)\n const $fromNode = $from.node()\n const fromSelectionAtStart = $from.parentOffset === 0\n const isTextSelection = $fromNode.isText || $fromNode.isTextblock\n const hasContent = $fromNode.content.size > 0\n\n if (fromSelectionAtStart && isTextSelection && hasContent) {\n from = Math.max(0, from - 1)\n }\n\n tr.replaceWith(from, to, newContent)\n }\n\n // set cursor at end of inserted content\n if (options.updateSelection) {\n selectionToInsertionEnd(tr, tr.steps.length - 1, -1)\n }\n\n if (options.applyInputRules) {\n tr.setMeta('applyInputRules', { from, text: newContent })\n }\n\n if (options.applyPasteRules) {\n tr.setMeta('applyPasteRules', { from, text: newContent })\n }\n }\n\n return true\n }\n","import type { ParseOptions } from '@tiptap/pm/model'\nimport { DOMParser, Fragment, Node as ProseMirrorNode, Schema } from '@tiptap/pm/model'\n\nimport type { Content } from '../types.js'\nimport { elementFromString } from '../utilities/elementFromString.js'\n\nexport type CreateNodeFromContentOptions = {\n slice?: boolean\n parseOptions?: ParseOptions\n errorOnInvalidContent?: boolean\n}\n\n/**\n * Takes a JSON or HTML content and creates a Prosemirror node or fragment from it.\n * @param content The JSON or HTML content to create the node from\n * @param schema The Prosemirror schema to use for the node\n * @param options Options for the parser\n * @returns The created Prosemirror node or fragment\n */\nexport function createNodeFromContent(\n content: Content | ProseMirrorNode | Fragment,\n schema: Schema,\n options?: CreateNodeFromContentOptions,\n): ProseMirrorNode | Fragment {\n if (content instanceof ProseMirrorNode || content instanceof Fragment) {\n return content\n }\n options = {\n slice: true,\n parseOptions: {},\n ...options,\n }\n\n const isJSONContent = typeof content === 'object' && content !== null\n const isTextContent = typeof content === 'string'\n\n if (isJSONContent) {\n try {\n const isArrayContent = Array.isArray(content) && content.length > 0\n\n // if the JSON Content is an array of nodes, create a fragment for each node\n if (isArrayContent) {\n return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))\n }\n\n const node = schema.nodeFromJSON(content)\n\n if (options.errorOnInvalidContent) {\n node.check()\n }\n\n return node\n } catch (error) {\n if (options.errorOnInvalidContent) {\n throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })\n }\n\n console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)\n\n return createNodeFromContent('', schema, options)\n }\n }\n\n if (isTextContent) {\n // Check for invalid content\n if (options.errorOnInvalidContent) {\n let hasInvalidContent = false\n let invalidContent = ''\n\n // A copy of the current schema with a catch-all node at the end\n const contentCheckSchema = new Schema({\n topNode: schema.spec.topNode,\n marks: schema.spec.marks,\n // Prosemirror's schemas are executed such that: the last to execute, matches last\n // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle\n nodes: schema.spec.nodes.append({\n __tiptap__private__unknown__catch__all__node: {\n content: 'inline*',\n group: 'block',\n parseDOM: [\n {\n tag: '*',\n getAttrs: e => {\n // If this is ever called, we know that the content has something that we don't know how to handle in the schema\n hasInvalidContent = true\n // Try to stringify the element for a more helpful error message\n invalidContent = typeof e === 'string' ? e : e.outerHTML\n return null\n },\n },\n ],\n },\n }),\n })\n\n if (options.slice) {\n DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions)\n } else {\n DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions)\n }\n\n if (options.errorOnInvalidContent && hasInvalidContent) {\n throw new Error('[tiptap error]: Invalid HTML content', {\n cause: new Error(`Invalid element found: ${invalidContent}`),\n })\n }\n }\n\n const parser = DOMParser.fromSchema(schema)\n\n if (options.slice) {\n return parser.parseSlice(elementFromString(content), options.parseOptions).content\n }\n\n return parser.parse(elementFromString(content), options.parseOptions)\n }\n\n return createNodeFromContent('', schema, options)\n}\n","const removeWhitespaces = (node: HTMLElement) => {\n const children = node.childNodes\n\n for (let i = children.length - 1; i >= 0; i -= 1) {\n const child = children[i]\n\n if (child.nodeType === 3 && child.nodeValue && /^(\\n\\s\\s|\\n)$/.test(child.nodeValue)) {\n node.removeChild(child)\n } else if (child.nodeType === 1) {\n removeWhitespaces(child as HTMLElement)\n }\n }\n\n return node\n}\n\nexport function elementFromString(value: string): HTMLElement {\n if (typeof window === 'undefined') {\n throw new Error('[tiptap error]: there is no window object available, so this function cannot be used')\n }\n // add a wrapper to preserve leading and trailing whitespace\n const wrappedValue = `<body>${value}</body>`\n\n const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body\n\n return removeWhitespaces(html)\n}\n","import type { Transaction } from '@tiptap/pm/state'\nimport { Selection } from '@tiptap/pm/state'\nimport { ReplaceAroundStep, ReplaceStep } from '@tiptap/pm/transform'\n\n// source: https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466\nexport function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number) {\n const last = tr.steps.length - 1\n\n if (last < startLen) {\n return\n }\n\n const step = tr.steps[last]\n\n if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {\n return\n }\n\n const map = tr.mapping.maps[last]\n let end = 0\n\n map.forEach((_from, _to, _newFrom, newTo) => {\n if (end === 0) {\n end = newTo\n }\n })\n\n tr.setSelection(Selection.near(tr.doc.resolve(end), bias))\n}\n","import {\n joinBackward as originalJoinBackward,\n joinDown as originalJoinDown,\n joinForward as originalJoinForward,\n joinUp as originalJoinUp,\n} from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinUp: {\n /**\n * Join the selected block or, if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling above it.\n * @example editor.commands.joinUp()\n */\n joinUp: () => ReturnType\n }\n joinDown: {\n /**\n * Join the selected block, or the closest ancestor of the selection that can be joined, with the sibling after it.\n * @example editor.commands.joinDown()\n */\n joinDown: () => ReturnType\n }\n joinBackward: {\n /**\n * If the selection is empty and at the start of a textblock, try to reduce the distance between that block and the one before it—if there's a block directly before it that can be joined, join them.\n * If not, try to move the selected block closer to the next one in the document structure by lifting it out of its\n * parent or moving it into a parent of the previous block. Will use the view for accurate (bidi-aware) start-of-textblock detection if given.\n * @example editor.commands.joinBackward()\n */\n joinBackward: () => ReturnType\n }\n joinForward: {\n /**\n * If the selection is empty and the cursor is at the end of a textblock, try to reduce or remove the boundary between that block and the one after it,\n * either by joining them or by moving the other block closer to this one in the tree structure.\n * Will use the view for accurate start-of-textblock detection if given.\n * @example editor.commands.joinForward()\n */\n joinForward: () => ReturnType\n }\n }\n}\n\nexport const joinUp: RawCommands['joinUp'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinUp(state, dispatch)\n }\n\nexport const joinDown: RawCommands['joinDown'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinDown(state, dispatch)\n }\n\nexport const joinBackward: RawCommands['joinBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinBackward(state, dispatch)\n }\n\nexport const joinForward: RawCommands['joinForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinForward(state, dispatch)\n }\n","import { joinPoint } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinItemBackward: {\n /**\n * Join two items backward.\n * @example editor.commands.joinItemBackward()\n */\n joinItemBackward: () => ReturnType\n }\n }\n}\n\nexport const joinItemBackward: RawCommands['joinItemBackward'] =\n () =>\n ({ state, dispatch, tr }) => {\n try {\n const point = joinPoint(state.doc, state.selection.$from.pos, -1)\n\n if (point === null || point === undefined) {\n return false\n }\n\n tr.join(point, 2)\n\n if (dispatch) {\n dispatch(tr)\n }\n\n return true\n } catch {\n return false\n }\n }\n","import { joinPoint } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinItemForward: {\n /**\n * Join two items Forwards.\n * @example editor.commands.joinItemForward()\n */\n joinItemForward: () => ReturnType\n }\n }\n}\n\nexport const joinItemForward: RawCommands['joinItemForward'] =\n () =>\n ({ state, dispatch, tr }) => {\n try {\n const point = joinPoint(state.doc, state.selection.$from.pos, +1)\n\n if (point === null || point === undefined) {\n return false\n }\n\n tr.join(point, 2)\n\n if (dispatch) {\n dispatch(tr)\n }\n\n return true\n } catch {\n return false\n }\n }\n","import { joinTextblockBackward as originalCommand } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinTextblockBackward: {\n /**\n * A more limited form of joinBackward that only tries to join the current textblock to the one before it, if the cursor is at the start of a textblock.\n */\n joinTextblockBackward: () => ReturnType\n }\n }\n}\n\nexport const joinTextblockBackward: RawCommands['joinTextblockBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalCommand(state, dispatch)\n }\n","import { joinTextblockForward as originalCommand } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinTextblockForward: {\n /**\n * A more limited form of joinForward that only tries to join the current textblock to the one after it, if the cursor is at the end of a textblock.\n */\n joinTextblockForward: () => ReturnType\n }\n }\n}\n\nexport const joinTextblockForward: RawCommands['joinTextblockForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalCommand(state, dispatch)\n }\n","export function isMacOS(): boolean {\n return typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false\n}\n","import type { RawCommands } from '../types.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isMacOS } from '../utilities/isMacOS.js'\n\nfunction normalizeKeyName(name: string) {\n const parts = name.split(/-(?!$)/)\n let result = parts[parts.length - 1]\n\n if (result === 'Space') {\n result = ' '\n }\n\n let alt\n let ctrl\n let shift\n let meta\n\n for (let i = 0; i < parts.length - 1; i += 1) {\n const mod = parts[i]\n\n if (/^(cmd|meta|m)$/i.test(mod)) {\n meta = true\n } else if (/^a(lt)?$/i.test(mod)) {\n alt = true\n } else if (/^(c|ctrl|control)$/i.test(mod)) {\n ctrl = true\n } else if (/^s(hift)?$/i.test(mod)) {\n shift = true\n } else if (/^mod$/i.test(mod)) {\n if (isiOS() || isMacOS()) {\n meta = true\n } else {\n ctrl = true\n }\n } else {\n throw new Error(`Unrecognized modifier name: ${mod}`)\n }\n }\n\n if (alt) {\n result = `Alt-${result}`\n }\n\n if (ctrl) {\n result = `Ctrl-${result}`\n }\n\n if (meta) {\n result = `Meta-${result}`\n }\n\n if (shift) {\n result = `Shift-${result}`\n }\n\n return result\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n keyboardShortcut: {\n /**\n * Trigger a keyboard shortcut.\n * @param name The name of the keyboard shortcut.\n * @example editor.commands.keyboardShortcut('Mod-b')\n */\n keyboardShortcut: (name: string) => ReturnType\n }\n }\n}\n\nexport const keyboardShortcut: RawCommands['keyboardShortcut'] =\n name =>\n ({ editor, view, tr, dispatch }) => {\n const keys = normalizeKeyName(name).split(/-(?!$)/)\n const key = keys.find(item => !['Alt', 'Ctrl', 'Meta', 'Shift'].includes(item))\n const event = new KeyboardEvent('keydown', {\n key: key === 'Space' ? ' ' : key,\n altKey: keys.includes('Alt'),\n ctrlKey: keys.includes('Ctrl'),\n metaKey: keys.includes('Meta'),\n shiftKey: keys.includes('Shift'),\n bubbles: true,\n cancelable: true,\n })\n\n const capturedTransaction = editor.captureTransaction(() => {\n view.someProp('handleKeyDown', f => f(view, event))\n })\n\n capturedTransaction?.steps.forEach(step => {\n const newStep = step.map(tr.mapping)\n\n if (newStep && dispatch) {\n tr.maybeStep(newStep)\n }\n })\n\n return true\n }\n","import { lift as originalLift } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n lift: {\n /**\n * Removes an existing wrap if possible lifting the node out of it\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.lift('paragraph')\n * @example editor.commands.lift('heading', { level: 1 })\n */\n lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const lift: RawCommands['lift'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n if (!isActive) {\n return false\n }\n\n return originalLift(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport type { NodeRange } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\nimport { getNodeType } from './getNodeType.js'\n\nexport function isNodeActive(\n state: EditorState,\n typeOrName: NodeType | string | null,\n attributes: Record<string, any> = {},\n): boolean {\n const { from, to, empty } = state.selection\n const type = typeOrName ? getNodeType(typeOrName, state.schema) : null\n\n const nodeRanges: NodeRange[] = []\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n const relativeFrom = Math.max(from, pos)\n const relativeTo = Math.min(to, pos + node.nodeSize)\n\n nodeRanges.push({\n node,\n from: relativeFrom,\n to: relativeTo,\n })\n })\n\n const selectionRange = to - from\n const matchedNodeRanges = nodeRanges\n .filter(nodeRange => {\n if (!type) {\n return true\n }\n\n return type.name === nodeRange.node.type.name\n })\n .filter(nodeRange => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }))\n\n if (empty) {\n return !!matchedNodeRanges.length\n }\n\n const range = matchedNodeRanges.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0)\n\n return range >= selectionRange\n}\n","import { liftEmptyBlock as originalLiftEmptyBlock } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n liftEmptyBlock: {\n /**\n * If the cursor is in an empty textblock that can be lifted, lift the block.\n * @example editor.commands.liftEmptyBlock()\n */\n liftEmptyBlock: () => ReturnType\n }\n }\n}\n\nexport const liftEmptyBlock: RawCommands['liftEmptyBlock'] =\n () =>\n ({ state, dispatch }) => {\n return originalLiftEmptyBlock(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { liftListItem as originalLiftListItem } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n liftListItem: {\n /**\n * Create a command to lift the list item around the selection up into a wrapping list.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.liftListItem('listItem')\n */\n liftListItem: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const liftListItem: RawCommands['liftListItem'] =\n typeOrName =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalLiftListItem(type)(state, dispatch)\n }\n","import { newlineInCode as originalNewlineInCode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n newlineInCode: {\n /**\n * Add a newline character in code.\n * @example editor.commands.newlineInCode()\n */\n newlineInCode: () => ReturnType\n }\n }\n}\n\nexport const newlineInCode: RawCommands['newlineInCode'] =\n () =>\n ({ state, dispatch }) => {\n return originalNewlineInCode(state, dispatch)\n }\n","import type { Schema } from '@tiptap/pm/model'\n\n/**\n * Get the type of a schema item by its name.\n * @param name The name of the schema item\n * @param schema The Prosemiror schema to search in\n * @returns The type of the schema item (`node` or `mark`), or null if it doesn't exist\n */\nexport function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null {\n if (schema.nodes[name]) {\n return 'node'\n }\n\n if (schema.marks[name]) {\n return 'mark'\n }\n\n return null\n}\n","/**\n * Remove a property or an array of properties from an object\n * @param obj Object\n * @param key Key to remove\n */\nexport function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {\n const props = typeof propOrProps === 'string' ? [propOrProps] : propOrProps\n\n return Object.keys(obj).reduce((newObj: Record<string, any>, prop) => {\n if (!props.includes(prop)) {\n newObj[prop] = obj[prop]\n }\n\n return newObj\n }, {})\n}\n","import type { MarkType, NodeType } from '@tiptap/pm/model'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'\nimport type { RawCommands } from '../types.js'\nimport { deleteProps } from '../utilities/deleteProps.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n resetAttributes: {\n /**\n * Resets some node attributes to the default value.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node to reset.\n * @example editor.commands.resetAttributes('heading', 'level')\n */\n resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => ReturnType\n }\n }\n}\n\nexport const resetAttributes: RawCommands['resetAttributes'] =\n (typeOrName, attributes) =>\n ({ tr, state, dispatch }) => {\n let nodeType: NodeType | null = null\n let markType: MarkType | null = null\n\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (!schemaType) {\n return false\n }\n\n if (schemaType === 'node') {\n nodeType = getNodeType(typeOrName as NodeType, state.schema)\n }\n\n if (schemaType === 'mark') {\n markType = getMarkType(typeOrName as MarkType, state.schema)\n }\n\n let canReset = false\n\n tr.selection.ranges.forEach(range => {\n state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {\n if (nodeType && nodeType === node.type) {\n canReset = true\n\n if (dispatch) {\n tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))\n }\n }\n\n if (markType && node.marks.length) {\n node.marks.forEach(mark => {\n if (markType === mark.type) {\n canReset = true\n\n if (dispatch) {\n tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)))\n }\n }\n })\n }\n })\n })\n\n return canReset\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n scrollIntoView: {\n /**\n * Scroll the selection into view.\n * @example editor.commands.scrollIntoView()\n */\n scrollIntoView: () => ReturnType\n }\n }\n}\n\nexport const scrollIntoView: RawCommands['scrollIntoView'] =\n () =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n tr.scrollIntoView()\n }\n\n return true\n }\n","import { AllSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectAll: {\n /**\n * Select the whole document.\n * @example editor.commands.selectAll()\n */\n selectAll: () => ReturnType\n }\n }\n}\n\nexport const selectAll: RawCommands['selectAll'] =\n () =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = new AllSelection(tr.doc)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import { selectNodeBackward as originalSelectNodeBackward } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectNodeBackward: {\n /**\n * Select a node backward.\n * @example editor.commands.selectNodeBackward()\n */\n selectNodeBackward: () => ReturnType\n }\n }\n}\n\nexport const selectNodeBackward: RawCommands['selectNodeBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectNodeBackward(state, dispatch)\n }\n","import { selectNodeForward as originalSelectNodeForward } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectNodeForward: {\n /**\n * Select a node forward.\n * @example editor.commands.selectNodeForward()\n */\n selectNodeForward: () => ReturnType\n }\n }\n}\n\nexport const selectNodeForward: RawCommands['selectNodeForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectNodeForward(state, dispatch)\n }\n","import { selectParentNode as originalSelectParentNode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectParentNode: {\n /**\n * Select the parent node.\n * @example editor.commands.selectParentNode()\n */\n selectParentNode: () => ReturnType\n }\n }\n}\n\nexport const selectParentNode: RawCommands['selectParentNode'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectParentNode(state, dispatch)\n }\n","// @ts-ignore\n// TODO: add types to @types/prosemirror-commands\nimport { selectTextblockEnd as originalSelectTextblockEnd } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectTextblockEnd: {\n /**\n * Moves the cursor to the end of current text block.\n * @example editor.commands.selectTextblockEnd()\n */\n selectTextblockEnd: () => ReturnType\n }\n }\n}\n\nexport const selectTextblockEnd: RawCommands['selectTextblockEnd'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectTextblockEnd(state, dispatch)\n }\n","// @ts-ignore\n// TODO: add types to @types/prosemirror-commands\nimport { selectTextblockStart as originalSelectTextblockStart } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectTextblockStart: {\n /**\n * Moves the cursor to the start of current text block.\n * @example editor.commands.selectTextblockStart()\n */\n selectTextblockStart: () => ReturnType\n }\n }\n}\n\nexport const selectTextblockStart: RawCommands['selectTextblockStart'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectTextblockStart(state, dispatch)\n }\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions, Schema } from '@tiptap/pm/model'\n\nimport type { Content } from '../types.js'\nimport { createNodeFromContent } from './createNodeFromContent.js'\n\n/**\n * Create a new Prosemirror document node from content.\n * @param content The JSON or HTML content to create the document from\n * @param schema The Prosemirror schema to use for the document\n * @param parseOptions Options for the parser\n * @returns The created Prosemirror document node\n */\nexport function createDocument(\n content: Content | ProseMirrorNode | Fragment,\n schema: Schema,\n parseOptions: ParseOptions = {},\n options: { errorOnInvalidContent?: boolean } = {},\n): ProseMirrorNode {\n return createNodeFromContent(content, schema, {\n slice: false,\n parseOptions,\n errorOnInvalidContent: options.errorOnInvalidContent,\n }) as ProseMirrorNode\n}\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\n\nimport { createDocument } from '../helpers/createDocument.js'\nimport type { Content, RawCommands } from '../types.js'\n\nexport interface SetContentOptions {\n /**\n * Options for parsing the content.\n * @default {}\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to throw an error if the content is invalid.\n */\n errorOnInvalidContent?: boolean\n\n /**\n * Whether to emit an update event.\n * @default true\n */\n emitUpdate?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setContent: {\n /**\n * Replace the whole document with new content.\n * @param content The new content.\n * @param emitUpdate Whether to emit an update event.\n * @param parseOptions Options for parsing the content.\n * @example editor.commands.setContent('<p>Example text</p>')\n */\n setContent: (\n /**\n * The new content.\n */\n content: Content | Fragment | ProseMirrorNode,\n\n /**\n * Options for `setContent`.\n */\n options?: SetContentOptions,\n ) => ReturnType\n }\n }\n}\n\nexport const setContent: RawCommands['setContent'] =\n (content, { errorOnInvalidContent, emitUpdate = true, parseOptions = {} } = {}) =>\n ({ editor, tr, dispatch, commands }) => {\n const { doc } = tr\n\n // This is to keep backward compatibility with the previous behavior\n // TODO remove this in the next major version\n if (parseOptions.preserveWhitespace !== 'full') {\n const document = createDocument(content, editor.schema, parseOptions, {\n errorOnInvalidContent: errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n\n if (dispatch) {\n tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate)\n }\n return true\n }\n\n if (dispatch) {\n tr.setMeta('preventUpdate', !emitUpdate)\n }\n\n return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {\n parseOptions,\n errorOnInvalidContent: errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n }\n","import type { Mark, MarkType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getMarkType } from './getMarkType.js'\n\nexport function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): Record<string, any> {\n const type = getMarkType(typeOrName, state.schema)\n const { from, to, empty } = state.selection\n const marks: Mark[] = []\n\n if (empty) {\n if (state.storedMarks) {\n marks.push(...state.storedMarks)\n }\n\n marks.push(...state.selection.$head.marks())\n } else {\n state.doc.nodesBetween(from, to, node => {\n marks.push(...node.marks)\n })\n }\n\n const mark = marks.find(markItem => markItem.type.name === type.name)\n\n if (!mark) {\n return {}\n }\n\n return { ...mark.attrs }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { Transform } from '@tiptap/pm/transform'\n\n/**\n * Returns a new `Transform` based on all steps of the passed transactions.\n * @param oldDoc The Prosemirror node to start from\n * @param transactions The transactions to combine\n * @returns A new `Transform` with all steps of the passed transactions\n */\nexport function combineTransactionSteps(oldDoc: ProseMirrorNode, transactions: Transaction[]): Transform {\n const transform = new Transform(oldDoc)\n\n transactions.forEach(transaction => {\n transaction.steps.forEach(step => {\n transform.step(step)\n })\n })\n\n return transform\n}\n","import type { ContentMatch, NodeType } from '@tiptap/pm/model'\n\n/**\n * Gets the default block type at a given match\n * @param match The content match to get the default block type from\n * @returns The default block type or null\n */\nexport function defaultBlockAt(match: ContentMatch): NodeType | null {\n for (let i = 0; i < match.edgeCount; i += 1) {\n const { type } = match.edge(i)\n\n if (type.isTextblock && !type.hasRequiredAttrs()) {\n return type\n }\n }\n\n return null\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { NodeWithPos, Predicate } from '../types.js'\n\n/**\n * Find children inside a Prosemirror node that match a predicate.\n * @param node The Prosemirror node to search in\n * @param predicate The predicate to match\n * @returns An array of nodes with their positions\n */\nexport function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {\n const nodesWithPos: NodeWithPos[] = []\n\n node.descendants((child, pos) => {\n if (predicate(child)) {\n nodesWithPos.push({\n node: child,\n pos,\n })\n }\n })\n\n return nodesWithPos\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { NodeWithPos, Predicate, Range } from '../types.js'\n\n/**\n * Same as `findChildren` but searches only within a `range`.\n * @param node The Prosemirror node to search in\n * @param range The range to search in\n * @param predicate The predicate to match\n * @returns An array of nodes with their positions\n */\nexport function findChildrenInRange(node: ProseMirrorNode, range: Range, predicate: Predicate): NodeWithPos[] {\n const nodesWithPos: NodeWithPos[] = []\n\n // if (range.from === range.to) {\n // const nodeAt = node.nodeAt(range.from)\n\n // if (nodeAt) {\n // nodesWithPos.push({\n // node: nodeAt,\n // pos: range.from,\n // })\n // }\n // }\n\n node.nodesBetween(range.from, range.to, (child, pos) => {\n if (predicate(child)) {\n nodesWithPos.push({\n node: child,\n pos,\n })\n }\n })\n\n return nodesWithPos\n}\n","import type { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Predicate } from '../types.js'\n\n/**\n * Finds the closest parent node to a resolved position that matches a predicate.\n * @param $pos The resolved position to search from\n * @param predicate The predicate to match\n * @returns The closest parent node to the resolved position that matches the predicate\n * @example ```js\n * findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')\n * ```\n */\nexport function findParentNodeClosestToPos(\n $pos: ResolvedPos,\n predicate: Predicate,\n):\n | {\n pos: number\n start: number\n depth: number\n node: ProseMirrorNode\n }\n | undefined {\n for (let i = $pos.depth; i > 0; i -= 1) {\n const node = $pos.node(i)\n\n if (predicate(node)) {\n return {\n pos: i > 0 ? $pos.before(i) : 0,\n start: $pos.start(i),\n depth: i,\n node,\n }\n }\n }\n}\n","import type { Selection } from '@tiptap/pm/state'\n\nimport type { Predicate } from '../types.js'\nimport { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'\n\n/**\n * Finds the closest parent node to the current selection that matches a predicate.\n * @param predicate The predicate to match\n * @returns A command that finds the closest parent node to the current selection that matches the predicate\n * @example ```js\n * findParentNode(node => node.type.name === 'paragraph')\n * ```\n */\nexport function findParentNode(\n predicate: Predicate,\n): (selection: Selection) => ReturnType<typeof findParentNodeClosestToPos> {\n return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)\n}\n","import type { ExtensionConfig } from '../Extension.js'\nimport type { MarkConfig } from '../Mark.js'\nimport type { NodeConfig } from '../Node.js'\nimport type { AnyExtension, MaybeThisParameterType, RemoveThis } from '../types.js'\n\n/**\n * Returns a field from an extension\n * @param extension The Tiptap extension\n * @param field The field, for example `renderHTML` or `priority`\n * @param context The context object that should be passed as `this` into the function\n * @returns The field value\n */\nexport function getExtensionField<T = any, E extends AnyExtension = any>(\n extension: E,\n field: keyof ExtensionConfig | keyof MarkConfig | keyof NodeConfig,\n context?: Omit<MaybeThisParameterType<T>, 'parent'>,\n): RemoveThis<T> {\n if (extension.config[field as keyof typeof extension.config] === undefined && extension.parent) {\n return getExtensionField(extension.parent, field, context)\n }\n\n if (typeof extension.config[field as keyof typeof extension.config] === 'function') {\n const value = (extension.config[field as keyof typeof extension.config] as any).bind({\n ...context,\n parent: extension.parent ? getExtensionField(extension.parent, field, context) : null,\n })\n\n return value\n }\n\n return extension.config[field as keyof typeof extension.config] as RemoveThis<T>\n}\n","import type { AnyConfig, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\n\n/**\n * Create a flattened array of extensions by traversing the `addExtensions` field.\n * @param extensions An array of Tiptap extensions\n * @returns A flattened array of Tiptap extensions\n */\nexport function flattenExtensions(extensions: Extensions): Extensions {\n return (\n extensions\n .map(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n const addExtensions = getExtensionField<AnyConfig['addExtensions']>(extension, 'addExtensions', context)\n\n if (addExtensions) {\n return [extension, ...flattenExtensions(addExtensions())]\n }\n\n return extension\n })\n // `Infinity` will break TypeScript so we set a number that is probably high enough\n .flat(10)\n )\n}\n","import { Node } from '@tiptap/pm/model'\n\nimport type { Extensions, JSONContent } from '../types.js'\nimport { getHTMLFromFragment } from './getHTMLFromFragment.js'\nimport { getSchema } from './getSchema.js'\n\n/**\n * Generate HTML from a JSONContent\n * @param doc The JSONContent to generate HTML from\n * @param extensions The extensions to use for the schema\n * @returns The generated HTML\n */\nexport function generateHTML(doc: JSONContent, extensions: Extensions): string {\n const schema = getSchema(extensions)\n const contentNode = Node.fromJSON(schema, doc)\n\n return getHTMLFromFragment(contentNode.content, schema)\n}\n","import type { Fragment, Schema } from '@tiptap/pm/model'\nimport { DOMSerializer } from '@tiptap/pm/model'\n\nexport function getHTMLFromFragment(fragment: Fragment, schema: Schema): string {\n const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment)\n\n const temporaryDocument = document.implementation.createHTMLDocument()\n const container = temporaryDocument.createElement('div')\n\n container.appendChild(documentFragment)\n\n return container.innerHTML\n}\n","import type { MarkSpec, NodeSpec, TagParseRule } from '@tiptap/pm/model'\nimport { Schema } from '@tiptap/pm/model'\n\nimport type { Editor, MarkConfig, NodeConfig } from '../index.js'\nimport type { AnyConfig, Extensions } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\nimport { isEmptyObject } from '../utilities/isEmptyObject.js'\nimport { getAttributesFromExtensions } from './getAttributesFromExtensions.js'\nimport { getExtensionField } from './getExtensionField.js'\nimport { getRenderedAttributes } from './getRenderedAttributes.js'\nimport { injectExtensionAttributesToParseRule } from './injectExtensionAttributesToParseRule.js'\nimport { splitExtensions } from './splitExtensions.js'\n\nfunction cleanUpSchemaItem<T>(data: T) {\n return Object.fromEntries(\n // @ts-ignore\n Object.entries(data).filter(([key, value]) => {\n if (key === 'attrs' && isEmptyObject(value as object | undefined)) {\n return false\n }\n\n return value !== null && value !== undefined\n }),\n ) as T\n}\n\n/**\n * Builds an attribute spec tuple for ProseMirror schema from an extension attribute.\n * @param extensionAttribute The extension attribute to build the spec for\n * @returns A tuple of [attributeName, spec]\n */\nfunction buildAttributeSpec(\n extensionAttribute: ReturnType<typeof getAttributesFromExtensions>[number],\n): [string, Record<string, any>] {\n const spec: Record<string, any> = {}\n\n // Only include 'default' if the attribute is not required and default is set on the attribute\n if (!extensionAttribute?.attribute?.isRequired && 'default' in (extensionAttribute?.attribute || {})) {\n spec.default = extensionAttribute.attribute.default\n }\n\n // Only include 'validate' if it's defined\n if (extensionAttribute?.attribute?.validate !== undefined) {\n spec.validate = extensionAttribute.attribute.validate\n }\n\n return [extensionAttribute.name, spec]\n}\n\n/**\n * Creates a new Prosemirror schema based on the given extensions.\n * @param extensions An array of Tiptap extensions\n * @param editor The editor instance\n * @returns A Prosemirror schema\n */\nexport function getSchemaByResolvedExtensions(extensions: Extensions, editor?: Editor): Schema {\n const allAttributes = getAttributesFromExtensions(extensions)\n const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n const topNode = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))?.name\n\n const nodes = Object.fromEntries(\n nodeExtensions.map(extension => {\n const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n editor,\n }\n\n const extraNodeFields = extensions.reduce((fields, e) => {\n const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(e, 'extendNodeSchema', context)\n\n return {\n ...fields,\n ...(extendNodeSchema ? extendNodeSchema(extension) : {}),\n }\n }, {})\n\n const schema: NodeSpec = cleanUpSchemaItem({\n ...extraNodeFields,\n content: callOrReturn(getExtensionField<NodeConfig['content']>(extension, 'content', context)),\n marks: callOrReturn(getExtensionField<NodeConfig['marks']>(extension, 'marks', context)),\n group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),\n inline: callOrReturn(getExtensionField<NodeConfig['inline']>(extension, 'inline', context)),\n atom: callOrReturn(getExtensionField<NodeConfig['atom']>(extension, 'atom', context)),\n selectable: callOrReturn(getExtensionField<NodeConfig['selectable']>(extension, 'selectable', context)),\n draggable: callOrReturn(getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context)),\n code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),\n whitespace: callOrReturn(getExtensionField<NodeConfig['whitespace']>(extension, 'whitespace', context)),\n linebreakReplacement: callOrReturn(\n getExtensionField<NodeConfig['linebreakReplacement']>(extension, 'linebreakReplacement', context),\n ),\n defining: callOrReturn(getExtensionField<NodeConfig['defining']>(extension, 'defining', context)),\n isolating: callOrReturn(getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context)),\n attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)),\n })\n\n const parseHTML = callOrReturn(getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context))\n\n if (parseHTML) {\n schema.parseDOM = parseHTML.map(parseRule =>\n injectExtensionAttributesToParseRule(parseRule, extensionAttributes),\n ) as TagParseRule[]\n }\n\n const renderHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (renderHTML) {\n schema.toDOM = node =>\n renderHTML({\n node,\n HTMLAttributes: getRenderedAttributes(node, extensionAttributes),\n })\n }\n\n const renderText = getExtensionField<NodeConfig['renderText']>(extension, 'renderText', context)\n\n if (renderText) {\n schema.toText = renderText\n }\n\n return [extension.name, schema]\n }),\n )\n\n const marks = Object.fromEntries(\n markExtensions.map(extension => {\n const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n editor,\n }\n\n const extraMarkFields = extensions.reduce((fields, e) => {\n const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(e, 'extendMarkSchema', context)\n\n return {\n ...fields,\n ...(extendMarkSchema ? extendMarkSchema(extension as any) : {}),\n }\n }, {})\n\n const schema: MarkSpec = cleanUpSchemaItem({\n ...extraMarkFields,\n inclusive: callOrReturn(getExtensionField<MarkConfig['inclusive']>(extension, 'inclusive', context)),\n excludes: callOrReturn(getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context)),\n group: callOrReturn(getExtensionField<MarkConfig['group']>(extension, 'group', context)),\n spanning: callOrReturn(getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context)),\n code: callOrReturn(getExtensionField<MarkConfig['code']>(extension, 'code', context)),\n attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)),\n })\n\n const parseHTML = callOrReturn(getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context))\n\n if (parseHTML) {\n schema.parseDOM = parseHTML.map(parseRule =>\n injectExtensionAttributesToParseRule(parseRule, extensionAttributes),\n )\n }\n\n const renderHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (renderHTML) {\n schema.toDOM = mark =>\n renderHTML({\n mark,\n HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),\n })\n }\n\n return [extension.name, schema]\n }),\n )\n\n return new Schema({\n topNode,\n nodes,\n marks,\n })\n}\n","// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function isFunction(value: any): value is Function {\n return typeof value === 'function'\n}\n","import type { MaybeReturnType } from '../types.js'\nimport { isFunction } from './isFunction.js'\n\n/**\n * Optionally calls `value` as a function.\n * Otherwise it is returned directly.\n * @param value Function or any value.\n * @param context Optional context to bind to function.\n * @param props Optional props to pass to function.\n */\nexport function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {\n if (isFunction(value)) {\n if (context) {\n return value.bind(context)(...props)\n }\n\n return value(...props)\n }\n\n return value as MaybeReturnType<T>\n}\n","export function isEmptyObject(value = {}): boolean {\n return Object.keys(value).length === 0 && value.constructor === Object\n}\n","import type { Extension } from '../Extension.js'\nimport type { Mark } from '../Mark.js'\nimport type { Node } from '../Node.js'\nimport type { Extensions } from '../types.js'\n\nexport function splitExtensions(extensions: Extensions) {\n const baseExtensions = extensions.filter(extension => extension.type === 'extension') as Extension[]\n const nodeExtensions = extensions.filter(extension => extension.type === 'node') as Node[]\n const markExtensions = extensions.filter(extension => extension.type === 'mark') as Mark[]\n\n return {\n baseExtensions,\n nodeExtensions,\n markExtensions,\n }\n}\n","import type { MarkConfig, NodeConfig } from '../index.js'\nimport type { AnyConfig, Attribute, Attributes, ExtensionAttribute, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\nimport { splitExtensions } from './splitExtensions.js'\n\n/**\n * Get a list of all extension attributes defined in `addAttribute` and `addGlobalAttribute`.\n * @param extensions List of extensions\n */\nexport function getAttributesFromExtensions(extensions: Extensions): ExtensionAttribute[] {\n const extensionAttributes: ExtensionAttribute[] = []\n const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n const nodeAndMarkExtensions = [...nodeExtensions, ...markExtensions]\n const defaultAttribute: Required<Omit<Attribute, 'validate'>> & Pick<Attribute, 'validate'> = {\n default: null,\n validate: undefined,\n rendered: true,\n renderHTML: null,\n parseHTML: null,\n keepOnSplit: true,\n isRequired: false,\n }\n\n extensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n extensions: nodeAndMarkExtensions,\n }\n\n const addGlobalAttributes = getExtensionField<AnyConfig['addGlobalAttributes']>(\n extension,\n 'addGlobalAttributes',\n context,\n )\n\n if (!addGlobalAttributes) {\n return\n }\n\n const globalAttributes = addGlobalAttributes()\n\n globalAttributes.forEach(globalAttribute => {\n globalAttribute.types.forEach(type => {\n Object.entries(globalAttribute.attributes).forEach(([name, attribute]) => {\n extensionAttributes.push({\n type,\n name,\n attribute: {\n ...defaultAttribute,\n ...attribute,\n },\n })\n })\n })\n })\n })\n\n nodeAndMarkExtensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n const addAttributes = getExtensionField<NodeConfig['addAttributes'] | MarkConfig['addAttributes']>(\n extension,\n 'addAttributes',\n context,\n )\n\n if (!addAttributes) {\n return\n }\n\n // TODO: remove `as Attributes`\n const attributes = addAttributes() as Attributes\n\n Object.entries(attributes).forEach(([name, attribute]) => {\n const mergedAttr = {\n ...defaultAttribute,\n ...attribute,\n }\n\n if (typeof mergedAttr?.default === 'function') {\n mergedAttr.default = mergedAttr.default()\n }\n\n if (mergedAttr?.isRequired && mergedAttr?.default === undefined) {\n delete mergedAttr.default\n }\n\n extensionAttributes.push({\n type: extension.name,\n name,\n attribute: mergedAttr,\n })\n })\n })\n\n return extensionAttributes\n}\n","export function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {\n return objects\n .filter(item => !!item)\n .reduce((items, item) => {\n const mergedAttributes = { ...items }\n\n Object.entries(item).forEach(([key, value]) => {\n const exists = mergedAttributes[key]\n\n if (!exists) {\n mergedAttributes[key] = value\n\n return\n }\n\n if (key === 'class') {\n const valueClasses: string[] = value ? String(value).split(' ') : []\n const existingClasses: string[] = mergedAttributes[key] ? mergedAttributes[key].split(' ') : []\n\n const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass))\n\n mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ')\n } else if (key === 'style') {\n const newStyles: string[] = value\n ? value\n .split(';')\n .map((style: string) => style.trim())\n .filter(Boolean)\n : []\n const existingStyles: string[] = mergedAttributes[key]\n ? mergedAttributes[key]\n .split(';')\n .map((style: string) => style.trim())\n .filter(Boolean)\n : []\n\n const styleMap = new Map<string, string>()\n\n existingStyles.forEach(style => {\n const [property, val] = style.split(':').map(part => part.trim())\n\n styleMap.set(property, val)\n })\n\n newStyles.forEach(style => {\n const [property, val] = style.split(':').map(part => part.trim())\n\n styleMap.set(property, val)\n })\n\n mergedAttributes[key] = Array.from(styleMap.entries())\n .map(([property, val]) => `${property}: ${val}`)\n .join('; ')\n } else {\n mergedAttributes[key] = value\n }\n })\n\n return mergedAttributes\n }, {})\n}\n","import type { Mark, Node } from '@tiptap/pm/model'\n\nimport type { ExtensionAttribute } from '../types.js'\nimport { mergeAttributes } from '../utilities/mergeAttributes.js'\n\nexport function getRenderedAttributes(\n nodeOrMark: Node | Mark,\n extensionAttributes: ExtensionAttribute[],\n): Record<string, any> {\n return extensionAttributes\n .filter(attribute => attribute.type === nodeOrMark.type.name)\n .filter(item => item.attribute.rendered)\n .map(item => {\n if (!item.attribute.renderHTML) {\n return {\n [item.name]: nodeOrMark.attrs[item.name],\n }\n }\n\n return item.attribute.renderHTML(nodeOrMark.attrs) || {}\n })\n .reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})\n}\n","export function fromString(value: any): any {\n if (typeof value !== 'string') {\n return value\n }\n\n if (value.match(/^[+-]?(?:\\d*\\.)?\\d+$/)) {\n return Number(value)\n }\n\n if (value === 'true') {\n return true\n }\n\n if (value === 'false') {\n return false\n }\n\n return value\n}\n","import type { ParseRule } from '@tiptap/pm/model'\n\nimport type { ExtensionAttribute } from '../types.js'\nimport { fromString } from '../utilities/fromString.js'\n\n/**\n * This function merges extension attributes into parserule attributes (`attrs` or `getAttrs`).\n * Cancels when `getAttrs` returned `false`.\n * @param parseRule ProseMirror ParseRule\n * @param extensionAttributes List of attributes to inject\n */\nexport function injectExtensionAttributesToParseRule(\n parseRule: ParseRule,\n extensionAttributes: ExtensionAttribute[],\n): ParseRule {\n if ('style' in parseRule) {\n return parseRule\n }\n\n return {\n ...parseRule,\n getAttrs: (node: HTMLElement) => {\n const oldAttributes = parseRule.getAttrs ? parseRule.getAttrs(node) : parseRule.attrs\n\n if (oldAttributes === false) {\n return false\n }\n\n const newAttributes = extensionAttributes.reduce((items, item) => {\n const value = item.attribute.parseHTML\n ? item.attribute.parseHTML(node)\n : fromString(node.getAttribute(item.name))\n\n if (value === null || value === undefined) {\n return items\n }\n\n return {\n ...items,\n [item.name]: value,\n }\n }, {})\n\n return { ...oldAttributes, ...newAttributes }\n },\n }\n}\n","/**\n * Find duplicates in an array.\n */\nexport function findDuplicates<T>(items: T[]): T[] {\n const filtered = items.filter((el, index) => items.indexOf(el) !== index)\n\n return Array.from(new Set(filtered))\n}\n","import type { AnyConfig, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\n\n/**\n * Sort extensions by priority.\n * @param extensions An array of Tiptap extensions\n * @returns A sorted array of Tiptap extensions by priority\n */\nexport function sortExtensions(extensions: Extensions): Extensions {\n const defaultPriority = 100\n\n return extensions.sort((a, b) => {\n const priorityA = getExtensionField<AnyConfig['priority']>(a, 'priority') || defaultPriority\n const priorityB = getExtensionField<AnyConfig['priority']>(b, 'priority') || defaultPriority\n\n if (priorityA > priorityB) {\n return -1\n }\n\n if (priorityA < priorityB) {\n return 1\n }\n\n return 0\n })\n}\n","import type { Extensions } from '../types.js'\nimport { findDuplicates } from '../utilities/findDuplicates.js'\nimport { flattenExtensions } from './flattenExtensions.js'\nimport { sortExtensions } from './sortExtensions.js'\n\n/**\n * Returns a flattened and sorted extension list while\n * also checking for duplicated extensions and warns the user.\n * @param extensions An array of Tiptap extensions\n * @returns An flattened and sorted array of Tiptap extensions\n */\nexport function resolveExtensions(extensions: Extensions): Extensions {\n const resolvedExtensions = sortExtensions(flattenExtensions(extensions))\n const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))\n\n if (duplicatedNames.length) {\n console.warn(\n `[tiptap warn]: Duplicate extension names found: [${duplicatedNames\n .map(item => `'${item}'`)\n .join(', ')}]. This can lead to issues.`,\n )\n }\n\n return resolvedExtensions\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { Editor } from '../Editor.js'\nimport type { Extensions } from '../types.js'\nimport { getSchemaByResolvedExtensions } from './getSchemaByResolvedExtensions.js'\nimport { resolveExtensions } from './resolveExtensions.js'\n\nexport function getSchema(extensions: Extensions, editor?: Editor): Schema {\n const resolvedExtensions = resolveExtensions(extensions)\n\n return getSchemaByResolvedExtensions(resolvedExtensions, editor)\n}\n","import { DOMParser } from '@tiptap/pm/model'\n\nimport type { Extensions } from '../types.js'\nimport { elementFromString } from '../utilities/elementFromString.js'\nimport { getSchema } from './getSchema.js'\n\n/**\n * Generate JSONContent from HTML\n * @param html The HTML to generate JSONContent from\n * @param extensions The extensions to use for the schema\n * @returns The generated JSONContent\n */\nexport function generateJSON(html: string, extensions: Extensions): Record<string, any> {\n const schema = getSchema(extensions)\n const dom = elementFromString(html)\n\n return DOMParser.fromSchema(schema).parse(dom).toJSON()\n}\n","import { Node } from '@tiptap/pm/model'\n\nimport type { Extensions, JSONContent, TextSerializer } from '../types.js'\nimport { getSchema } from './getSchema.js'\nimport { getText } from './getText.js'\nimport { getTextSerializersFromSchema } from './getTextSerializersFromSchema.js'\n\n/**\n * Generate raw text from a JSONContent\n * @param doc The JSONContent to generate text from\n * @param extensions The extensions to use for the schema\n * @param options Options for the text generation f.e. blockSeparator or textSerializers\n * @returns The generated text\n */\nexport function generateText(\n doc: JSONContent,\n extensions: Extensions,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n): string {\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n const schema = getSchema(extensions)\n const contentNode = Node.fromJSON(schema, doc)\n\n return getText(contentNode, {\n blockSeparator,\n textSerializers: {\n ...getTextSerializersFromSchema(schema),\n ...textSerializers,\n },\n })\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { Range, TextSerializer } from '../types.js'\n\n/**\n * Gets the text between two positions in a Prosemirror node\n * and serializes it using the given text serializers and block separator (see getText)\n * @param startNode The Prosemirror node to start from\n * @param range The range of the text to get\n * @param options Options for the text serializer & block separator\n * @returns The text between the two positions\n */\nexport function getTextBetween(\n startNode: ProseMirrorNode,\n range: Range,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n): string {\n const { from, to } = range\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n let text = ''\n\n startNode.nodesBetween(from, to, (node, pos, parent, index) => {\n if (node.isBlock && pos > from) {\n text += blockSeparator\n }\n\n const textSerializer = textSerializers?.[node.type.name]\n\n if (textSerializer) {\n if (parent) {\n text += textSerializer({\n node,\n pos,\n parent,\n index,\n range,\n })\n }\n // do not descend into child nodes when there exists a serializer\n return false\n }\n\n if (node.isText) {\n text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line\n }\n })\n\n return text\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { TextSerializer } from '../types.js'\nimport { getTextBetween } from './getTextBetween.js'\n\n/**\n * Gets the text of a Prosemirror node\n * @param node The Prosemirror node\n * @param options Options for the text serializer & block separator\n * @returns The text of the node\n * @example ```js\n * const text = getText(node, { blockSeparator: '\\n' })\n * ```\n */\nexport function getText(\n node: ProseMirrorNode,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n) {\n const range = {\n from: 0,\n to: node.content.size,\n }\n\n return getTextBetween(node, range, options)\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { TextSerializer } from '../types.js'\n\n/**\n * Find text serializers `toText` in a Prosemirror schema\n * @param schema The Prosemirror schema to search in\n * @returns A record of text serializers by node name\n */\nexport function getTextSerializersFromSchema(schema: Schema): Record<string, TextSerializer> {\n return Object.fromEntries(\n Object.entries(schema.nodes)\n .filter(([, node]) => node.spec.toText)\n .map(([name, node]) => [name, node.spec.toText]),\n )\n}\n","import type { Node, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getNodeType } from './getNodeType.js'\n\nexport function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): Record<string, any> {\n const type = getNodeType(typeOrName, state.schema)\n const { from, to } = state.selection\n const nodes: Node[] = []\n\n state.doc.nodesBetween(from, to, node => {\n nodes.push(node)\n })\n\n const node = nodes.reverse().find(nodeItem => nodeItem.type.name === type.name)\n\n if (!node) {\n return {}\n }\n\n return { ...node.attrs }\n}\n","import type { MarkType, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getMarkAttributes } from './getMarkAttributes.js'\nimport { getNodeAttributes } from './getNodeAttributes.js'\nimport { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'\n\n/**\n * Get node or mark attributes by type or name on the current editor state\n * @param state The current editor state\n * @param typeOrName The node or mark type or name\n * @returns The attributes of the node or mark or an empty object\n */\nexport function getAttributes(state: EditorState, typeOrName: string | NodeType | MarkType): Record<string, any> {\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (schemaType === 'node') {\n return getNodeAttributes(state, typeOrName as NodeType)\n }\n\n if (schemaType === 'mark') {\n return getMarkAttributes(state, typeOrName as MarkType)\n }\n\n return {}\n}\n","/**\n * Removes duplicated values within an array.\n * Supports numbers, strings and objects.\n */\nexport function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {\n const seen: Record<any, any> = {}\n\n return array.filter(item => {\n const key = by(item)\n\n return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true)\n })\n}\n","import type { Step, Transform } from '@tiptap/pm/transform'\n\nimport type { Range } from '../types.js'\nimport { removeDuplicates } from '../utilities/removeDuplicates.js'\n\nexport type ChangedRange = {\n oldRange: Range\n newRange: Range\n}\n\n/**\n * Removes duplicated ranges and ranges that are\n * fully captured by other ranges.\n */\nfunction simplifyChangedRanges(changes: ChangedRange[]): ChangedRange[] {\n const uniqueChanges = removeDuplicates(changes)\n\n return uniqueChanges.length === 1\n ? uniqueChanges\n : uniqueChanges.filter((change, index) => {\n const rest = uniqueChanges.filter((_, i) => i !== index)\n\n return !rest.some(otherChange => {\n return (\n change.oldRange.from >= otherChange.oldRange.from &&\n change.oldRange.to <= otherChange.oldRange.to &&\n change.newRange.from >= otherChange.newRange.from &&\n change.newRange.to <= otherChange.newRange.to\n )\n })\n })\n}\n\n/**\n * Returns a list of changed ranges\n * based on the first and last state of all steps.\n */\nexport function getChangedRanges(transform: Transform): ChangedRange[] {\n const { mapping, steps } = transform\n const changes: ChangedRange[] = []\n\n mapping.maps.forEach((stepMap, index) => {\n const ranges: Range[] = []\n\n // This accounts for step changes where no range was actually altered\n // e.g. when setting a mark, node attribute, etc.\n // @ts-ignore\n if (!stepMap.ranges.length) {\n const { from, to } = steps[index] as Step & {\n from?: number\n to?: number\n }\n\n if (from === undefined || to === undefined) {\n return\n }\n\n ranges.push({ from, to })\n } else {\n stepMap.forEach((from, to) => {\n ranges.push({ from, to })\n })\n }\n\n ranges.forEach(({ from, to }) => {\n const newStart = mapping.slice(index).map(from, -1)\n const newEnd = mapping.slice(index).map(to)\n const oldStart = mapping.invert().map(newStart, -1)\n const oldEnd = mapping.invert().map(newEnd)\n\n changes.push({\n oldRange: {\n from: oldStart,\n to: oldEnd,\n },\n newRange: {\n from: newStart,\n to: newEnd,\n },\n })\n })\n })\n\n return simplifyChangedRanges(changes)\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { JSONContent } from '../types.js'\n\ninterface DebugJSONContent extends JSONContent {\n from: number\n to: number\n}\n\nexport function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent {\n const isTopNode = node.type === node.type.schema.topNodeType\n const increment = isTopNode ? 0 : 1\n const from = startOffset\n const to = from + node.nodeSize\n const marks = node.marks.map(mark => {\n const output: { type: string; attrs?: Record<string, any> } = {\n type: mark.type.name,\n }\n\n if (Object.keys(mark.attrs).length) {\n output.attrs = { ...mark.attrs }\n }\n\n return output\n })\n const attrs = { ...node.attrs }\n const output: DebugJSONContent = {\n type: node.type.name,\n from,\n to,\n }\n\n if (Object.keys(attrs).length) {\n output.attrs = attrs\n }\n\n if (marks.length) {\n output.marks = marks\n }\n\n if (node.content.childCount) {\n output.content = []\n\n node.forEach((child, offset) => {\n output.content?.push(getDebugJSON(child, startOffset + offset + increment))\n })\n }\n\n if (node.text) {\n output.text = node.text\n }\n\n return output\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { MarkRange } from '../types.js'\nimport { getMarkRange } from './getMarkRange.js'\n\nexport function getMarksBetween(from: number, to: number, doc: ProseMirrorNode): MarkRange[] {\n const marks: MarkRange[] = []\n\n // get all inclusive marks on empty selection\n if (from === to) {\n doc\n .resolve(from)\n .marks()\n .forEach(mark => {\n const $pos = doc.resolve(from)\n const range = getMarkRange($pos, mark.type)\n\n if (!range) {\n return\n }\n\n marks.push({\n mark,\n ...range,\n })\n })\n } else {\n doc.nodesBetween(from, to, (node, pos) => {\n if (!node || node?.nodeSize === undefined) {\n return\n }\n\n marks.push(\n ...node.marks.map(mark => ({\n from: pos,\n to: pos + node.nodeSize,\n mark,\n })),\n )\n })\n }\n\n return marks\n}\n","import type { Node, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\n/**\n * Finds the first node of a given type or name in the current selection.\n * @param state The editor state.\n * @param typeOrName The node type or name.\n * @param pos The position to start searching from.\n * @param maxDepth The maximum depth to search.\n * @returns The node and the depth as an array.\n */\nexport const getNodeAtPosition = (state: EditorState, typeOrName: string | NodeType, pos: number, maxDepth = 20) => {\n const $pos = state.doc.resolve(pos)\n\n let currentDepth = maxDepth\n let node: Node | null = null\n\n while (currentDepth > 0 && node === null) {\n const currentNode = $pos.node(currentDepth)\n\n if (currentNode?.type.name === typeOrName) {\n node = currentNode\n } else {\n currentDepth -= 1\n }\n }\n\n return [node, currentDepth] as [Node | null, number]\n}\n","import type { MarkType, NodeType, Schema } from '@tiptap/pm/model'\n\n/**\n * Tries to get a node or mark type by its name.\n * @param name The name of the node or mark type\n * @param schema The Prosemiror schema to search in\n * @returns The node or mark type, or null if it doesn't exist\n */\nexport function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {\n return schema.nodes[name] || schema.marks[name] || null\n}\n","import type { ExtensionAttribute } from '../types.js'\n\n/**\n * Return attributes of an extension that should be splitted by keepOnSplit flag\n * @param extensionAttributes Array of extension attributes\n * @param typeName The type of the extension\n * @param attributes The attributes of the extension\n * @returns The splitted attributes\n */\nexport function getSplittedAttributes(\n extensionAttributes: ExtensionAttribute[],\n typeName: string,\n attributes: Record<string, any>,\n): Record<string, any> {\n return Object.fromEntries(\n Object.entries(attributes).filter(([name]) => {\n const extensionAttribute = extensionAttributes.find(item => {\n return item.type === typeName && item.name === name\n })\n\n if (!extensionAttribute) {\n return false\n }\n\n return extensionAttribute.attribute.keepOnSplit\n }),\n )\n}\n","import type { ResolvedPos } from '@tiptap/pm/model'\n\n/**\n * Returns the text content of a resolved prosemirror position\n * @param $from The resolved position to get the text content from\n * @param maxMatch The maximum number of characters to match\n * @returns The text content\n */\nexport const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {\n let textBefore = ''\n\n const sliceEndPos = $from.parentOffset\n\n $from.parent.nodesBetween(Math.max(0, sliceEndPos - maxMatch), sliceEndPos, (node, pos, parent, index) => {\n const chunk =\n node.type.spec.toText?.({\n node,\n pos,\n parent,\n index,\n }) ||\n node.textContent ||\n '%leaf%'\n\n textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos))\n })\n\n return textBefore\n}\n","import type { MarkType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport type { MarkRange } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\nimport { getMarkType } from './getMarkType.js'\n\nexport function isMarkActive(\n state: EditorState,\n typeOrName: MarkType | string | null,\n attributes: Record<string, any> = {},\n): boolean {\n const { empty, ranges } = state.selection\n const type = typeOrName ? getMarkType(typeOrName, state.schema) : null\n\n if (empty) {\n return !!(state.storedMarks || state.selection.$from.marks())\n .filter(mark => {\n if (!type) {\n return true\n }\n\n return type.name === mark.type.name\n })\n .find(mark => objectIncludes(mark.attrs, attributes, { strict: false }))\n }\n\n let selectionRange = 0\n const markRanges: MarkRange[] = []\n\n ranges.forEach(({ $from, $to }) => {\n const from = $from.pos\n const to = $to.pos\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isText && !node.marks.length) {\n return\n }\n\n const relativeFrom = Math.max(from, pos)\n const relativeTo = Math.min(to, pos + node.nodeSize)\n const range = relativeTo - relativeFrom\n\n selectionRange += range\n\n markRanges.push(\n ...node.marks.map(mark => ({\n mark,\n from: relativeFrom,\n to: relativeTo,\n })),\n )\n })\n })\n\n if (selectionRange === 0) {\n return false\n }\n\n // calculate range of matched mark\n const matchedRange = markRanges\n .filter(markRange => {\n if (!type) {\n return true\n }\n\n return type.name === markRange.mark.type.name\n })\n .filter(markRange => objectIncludes(markRange.mark.attrs, attributes, { strict: false }))\n .reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)\n\n // calculate range of marks that excludes the searched mark\n // for example `code` doesn’t allow any other marks\n const excludedRange = markRanges\n .filter(markRange => {\n if (!type) {\n return true\n }\n\n return markRange.mark.type !== type && markRange.mark.type.excludes(type)\n })\n .reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)\n\n // we only include the result of `excludedRange`\n // if there is a match at all\n const range = matchedRange > 0 ? matchedRange + excludedRange : matchedRange\n\n return range >= selectionRange\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nimport { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'\nimport { isMarkActive } from './isMarkActive.js'\nimport { isNodeActive } from './isNodeActive.js'\n\nexport function isActive(state: EditorState, name: string | null, attributes: Record<string, any> = {}): boolean {\n if (!name) {\n return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes)\n }\n\n const schemaType = getSchemaTypeNameByName(name, state.schema)\n\n if (schemaType === 'node') {\n return isNodeActive(state, name, attributes)\n }\n\n if (schemaType === 'mark') {\n return isMarkActive(state, name, attributes)\n }\n\n return false\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nimport { findParentNode } from './findParentNode.js'\n\nexport const isAtEndOfNode = (state: EditorState, nodeType?: string) => {\n const { $from, $to, $anchor } = state.selection\n\n if (nodeType) {\n const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection)\n\n if (!parentNode) {\n return false\n }\n\n const $parentPos = state.doc.resolve(parentNode.pos + 1)\n\n if ($anchor.pos + 1 === $parentPos.end()) {\n return true\n }\n\n return false\n }\n\n if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {\n return false\n }\n\n return true\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nexport const isAtStartOfNode = (state: EditorState) => {\n const { $from, $to } = state.selection\n\n if ($from.parentOffset > 0 || $from.pos !== $to.pos) {\n return false\n }\n\n return true\n}\n","import type { AnyExtension, EnableRules } from '../types.js'\n\nexport function isExtensionRulesEnabled(extension: AnyExtension, enabled: EnableRules): boolean {\n if (Array.isArray(enabled)) {\n return enabled.some(enabledExtension => {\n const name = typeof enabledExtension === 'string' ? enabledExtension : enabledExtension.name\n\n return name === extension.name\n })\n }\n\n return enabled\n}\n","import { getExtensionField } from '../helpers/getExtensionField.js'\nimport type { NodeConfig } from '../index.js'\nimport type { Extensions } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\nimport { splitExtensions } from './splitExtensions.js'\n\nexport function isList(name: string, extensions: Extensions): boolean {\n const { nodeExtensions } = splitExtensions(extensions)\n const extension = nodeExtensions.find(item => item.name === name)\n\n if (!extension) {\n return false\n }\n\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n const group = callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context))\n\n if (typeof group !== 'string') {\n return false\n }\n\n return group.split(' ').includes('list')\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\n/**\n * Returns true if the given prosemirror node is empty.\n */\nexport function isNodeEmpty(\n node: ProseMirrorNode,\n {\n checkChildren = true,\n ignoreWhitespace = false,\n }: {\n /**\n * When true (default), it will also check if all children are empty.\n */\n checkChildren?: boolean\n /**\n * When true, it will ignore whitespace when checking for emptiness.\n */\n ignoreWhitespace?: boolean\n } = {},\n): boolean {\n if (ignoreWhitespace) {\n if (node.type.name === 'hardBreak') {\n // Hard breaks are considered empty\n return true\n }\n if (node.isText) {\n return /^\\s*$/m.test(node.text ?? '')\n }\n }\n\n if (node.isText) {\n return !node.text\n }\n\n if (node.isAtom || node.isLeaf) {\n return false\n }\n\n if (node.content.childCount === 0) {\n return true\n }\n\n if (checkChildren) {\n let isContentEmpty = true\n\n node.content.forEach(childNode => {\n if (isContentEmpty === false) {\n // Exit early for perf\n return\n }\n\n if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {\n isContentEmpty = false\n }\n })\n\n return isContentEmpty\n }\n\n return false\n}\n","import { NodeSelection } from '@tiptap/pm/state'\n\nexport function isNodeSelection(value: unknown): value is NodeSelection {\n return value instanceof NodeSelection\n}\n","import type { Transaction } from '@tiptap/pm/state'\nimport type { MapResult } from '@tiptap/pm/transform'\n\n/**\n * A class that represents a mappable position in the editor. It can be extended\n * by other extensions to add additional position mapping capabilities.\n */\nexport class MappablePosition {\n /**\n * The absolute position in the editor.\n */\n public position: number\n\n constructor(position: number) {\n this.position = position\n }\n\n /**\n * Creates a MappablePosition from a JSON object.\n */\n static fromJSON(json: any): MappablePosition {\n return new MappablePosition(json.position)\n }\n\n /**\n * Converts the MappablePosition to a JSON object.\n */\n toJSON(): any {\n return {\n position: this.position,\n }\n }\n}\n\n/**\n * The result of the getUpdatedPosition function.\n */\nexport interface GetUpdatedPositionResult {\n position: MappablePosition\n mapResult: MapResult | null\n}\n\n/**\n * Calculates the new position after applying a transaction.\n *\n * @returns The new mappable position and the map result.\n */\nexport function getUpdatedPosition(position: MappablePosition, transaction: Transaction): GetUpdatedPositionResult {\n const mapResult = transaction.mapping.mapResult(position.position)\n return {\n position: new MappablePosition(mapResult.pos),\n mapResult,\n }\n}\n\n/**\n * Creates a MappablePosition from a position number. This is the default\n * implementation for Tiptap core. It can be overridden by other Tiptap\n * extensions.\n *\n * @param position The position (as a number) where the MappablePosition will be created.\n * @returns A new MappablePosition instance at the given position.\n */\nexport function createMappablePosition(position: number): MappablePosition {\n return new MappablePosition(position)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { minMax } from '../utilities/minMax.js'\n\nexport function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {\n const minPos = 0\n const maxPos = view.state.doc.content.size\n const resolvedFrom = minMax(from, minPos, maxPos)\n const resolvedEnd = minMax(to, minPos, maxPos)\n const start = view.coordsAtPos(resolvedFrom)\n const end = view.coordsAtPos(resolvedEnd, -1)\n const top = Math.min(start.top, end.top)\n const bottom = Math.max(start.bottom, end.bottom)\n const left = Math.min(start.left, end.left)\n const right = Math.max(start.right, end.right)\n const width = right - left\n const height = bottom - top\n const x = left\n const y = top\n const data = {\n top,\n bottom,\n left,\n right,\n width,\n height,\n x,\n y,\n }\n\n return {\n ...data,\n toJSON: () => data,\n }\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { JSONContent } from '../types.js'\n\ntype RewriteUnknownContentOptions = {\n /**\n * If true, unknown nodes will be treated as paragraphs\n * @default true\n */\n fallbackToParagraph?: boolean\n}\n\ntype RewrittenContent = {\n /**\n * The original JSON content that was rewritten\n */\n original: JSONContent\n /**\n * The name of the node or mark that was unsupported\n */\n unsupported: string\n}[]\n\n/**\n * The actual implementation of the rewriteUnknownContent function\n */\nfunction rewriteUnknownContentInner({\n json,\n validMarks,\n validNodes,\n options,\n rewrittenContent = [],\n}: {\n json: JSONContent\n validMarks: Set<string>\n validNodes: Set<string>\n options?: RewriteUnknownContentOptions\n rewrittenContent?: RewrittenContent\n}): {\n /**\n * The cleaned JSON content\n */\n json: JSONContent | null\n /**\n * The array of nodes and marks that were rewritten\n */\n rewrittenContent: RewrittenContent\n} {\n if (json.marks && Array.isArray(json.marks)) {\n json.marks = json.marks.filter(mark => {\n const name = typeof mark === 'string' ? mark : mark.type\n\n if (validMarks.has(name)) {\n return true\n }\n\n rewrittenContent.push({\n original: JSON.parse(JSON.stringify(mark)),\n unsupported: name,\n })\n // Just ignore any unknown marks\n return false\n })\n }\n\n if (json.content && Array.isArray(json.content)) {\n json.content = json.content\n .map(\n value =>\n rewriteUnknownContentInner({\n json: value,\n validMarks,\n validNodes,\n options,\n rewrittenContent,\n }).json,\n )\n .filter(a => a !== null && a !== undefined)\n }\n\n if (json.type && !validNodes.has(json.type)) {\n rewrittenContent.push({\n original: JSON.parse(JSON.stringify(json)),\n unsupported: json.type,\n })\n\n if (json.content && Array.isArray(json.content) && options?.fallbackToParagraph !== false) {\n // Just treat it like a paragraph and hope for the best\n json.type = 'paragraph'\n\n return {\n json,\n rewrittenContent,\n }\n }\n\n // or just omit it entirely\n return {\n json: null,\n rewrittenContent,\n }\n }\n\n return { json, rewrittenContent }\n}\n\n/**\n * Rewrite unknown nodes and marks within JSON content\n * Allowing for user within the editor\n */\nexport function rewriteUnknownContent(\n /**\n * The JSON content to clean of unknown nodes and marks\n */\n json: JSONContent,\n /**\n * The schema to use for validation\n */\n schema: Schema,\n /**\n * Options for the cleaning process\n */\n options?: RewriteUnknownContentOptions,\n): {\n /**\n * The cleaned JSON content\n */\n json: JSONContent | null\n /**\n * The array of nodes and marks that were rewritten\n */\n rewrittenContent: {\n /**\n * The original JSON content that was rewritten\n */\n original: JSONContent\n /**\n * The name of the node or mark that was unsupported\n */\n unsupported: string\n }[]\n} {\n return rewriteUnknownContentInner({\n json,\n validNodes: new Set(Object.keys(schema.nodes)),\n validMarks: new Set(Object.keys(schema.marks)),\n options,\n })\n}\n","import type { MarkType, ResolvedPos } from '@tiptap/pm/model'\nimport type { EditorState, Transaction } from '@tiptap/pm/state'\n\nimport { getMarkAttributes } from '../helpers/getMarkAttributes.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { isTextSelection } from '../helpers/index.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setMark: {\n /**\n * Add a mark with new attributes.\n * @param typeOrName The mark type or name.\n * @example editor.commands.setMark('bold', { level: 1 })\n */\n setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nfunction canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType) {\n const { selection } = tr\n let cursor: ResolvedPos | null = null\n\n if (isTextSelection(selection)) {\n cursor = selection.$cursor\n }\n\n if (cursor) {\n const currentMarks = state.storedMarks ?? cursor.marks()\n const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType)\n\n // There can be no current marks that exclude the new mark, and the parent must allow this mark type\n return (\n parentAllowsMarkType &&\n (!!newMarkType.isInSet(currentMarks) || !currentMarks.some(mark => mark.type.excludes(newMarkType)))\n )\n }\n\n const { ranges } = selection\n\n return ranges.some(({ $from, $to }) => {\n let someNodeSupportsMark =\n $from.depth === 0 ? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType) : false\n\n state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => {\n // If we already found a mark that we can enable, return false to bypass the remaining search\n if (someNodeSupportsMark) {\n return false\n }\n\n if (node.isInline) {\n const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType)\n const currentMarksAllowMarkType =\n !!newMarkType.isInSet(node.marks) || !node.marks.some(otherMark => otherMark.type.excludes(newMarkType))\n\n someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType\n }\n return !someNodeSupportsMark\n })\n\n return someNodeSupportsMark\n })\n}\nexport const setMark: RawCommands['setMark'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n const { selection } = tr\n const { empty, ranges } = selection\n const type = getMarkType(typeOrName, state.schema)\n\n if (dispatch) {\n if (empty) {\n const oldAttributes = getMarkAttributes(state, type)\n\n tr.addStoredMark(\n type.create({\n ...oldAttributes,\n ...attributes,\n }),\n )\n } else {\n ranges.forEach(range => {\n const from = range.$from.pos\n const to = range.$to.pos\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n const trimmedFrom = Math.max(pos, from)\n const trimmedTo = Math.min(pos + node.nodeSize, to)\n const someHasMark = node.marks.find(mark => mark.type === type)\n\n // if there is already a mark of this type\n // we know that we have to merge its attributes\n // otherwise we add a fresh new mark\n if (someHasMark) {\n node.marks.forEach(mark => {\n if (type === mark.type) {\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n type.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n })\n } else {\n tr.addMark(trimmedFrom, trimmedTo, type.create(attributes))\n }\n })\n })\n }\n }\n\n return canSetMark(state, tr, type)\n }\n","import type { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setMeta: {\n /**\n * Store a metadata property in the current transaction.\n * @param key The key of the metadata property.\n * @param value The value to store.\n * @example editor.commands.setMeta('foo', 'bar')\n */\n setMeta: (key: string | Plugin | PluginKey, value: any) => ReturnType\n }\n }\n}\n\nexport const setMeta: RawCommands['setMeta'] =\n (key, value) =>\n ({ tr }) => {\n tr.setMeta(key, value)\n\n return true\n }\n","import { setBlockType } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setNode: {\n /**\n * Replace a given range with a node.\n * @param typeOrName The type or name of the node\n * @param attributes The attributes of the node\n * @example editor.commands.setNode('paragraph')\n */\n setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const setNode: RawCommands['setNode'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch, chain }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n let attributesToCopy: Record<string, any> | undefined\n\n if (state.selection.$anchor.sameParent(state.selection.$head)) {\n // only copy attributes if the selection is pointing to a node of the same type\n attributesToCopy = state.selection.$anchor.parent.attrs\n }\n\n // TODO: use a fallback like insertContent?\n if (!type.isTextblock) {\n console.warn('[tiptap warn]: Currently \"setNode()\" only supports text block nodes.')\n\n return false\n }\n\n return (\n chain()\n // try to convert node to default node if needed\n .command(({ commands }) => {\n const canSetBlock = setBlockType(type, { ...attributesToCopy, ...attributes })(state)\n\n if (canSetBlock) {\n return true\n }\n\n return commands.clearNodes()\n })\n .command(({ state: updatedState }) => {\n return setBlockType(type, { ...attributesToCopy, ...attributes })(updatedState, dispatch)\n })\n .run()\n )\n }\n","import { NodeSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setNodeSelection: {\n /**\n * Creates a NodeSelection.\n * @param position - Position of the node.\n * @example editor.commands.setNodeSelection(10)\n */\n setNodeSelection: (position: number) => ReturnType\n }\n }\n}\n\nexport const setNodeSelection: RawCommands['setNodeSelection'] =\n position =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const { doc } = tr\n const from = minMax(position, 0, doc.content.size)\n const selection = NodeSelection.create(doc, from)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setTextDirection: {\n /**\n * Set the text direction for nodes.\n * If no position is provided, it will use the current selection.\n * @param direction The text direction to set ('ltr', 'rtl', or 'auto')\n * @param position Optional position or range to apply the direction to\n * @example editor.commands.setTextDirection('rtl')\n * @example editor.commands.setTextDirection('ltr', { from: 0, to: 10 })\n */\n setTextDirection: (direction: 'ltr' | 'rtl' | 'auto', position?: number | Range) => ReturnType\n }\n }\n}\n\nexport const setTextDirection: RawCommands['setTextDirection'] =\n (direction, position) =>\n ({ tr, state, dispatch }) => {\n const { selection } = state\n let from: number\n let to: number\n\n if (typeof position === 'number') {\n from = position\n to = position\n } else if (position && 'from' in position && 'to' in position) {\n from = position.from\n to = position.to\n } else {\n from = selection.from\n to = selection.to\n }\n\n if (dispatch) {\n tr.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n dir: direction,\n })\n })\n }\n\n return true\n }\n","import { TextSelection } from '@tiptap/pm/state'\n\nimport type { Range, RawCommands } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setTextSelection: {\n /**\n * Creates a TextSelection.\n * @param position The position of the selection.\n * @example editor.commands.setTextSelection(10)\n */\n setTextSelection: (position: number | Range) => ReturnType\n }\n }\n}\n\nexport const setTextSelection: RawCommands['setTextSelection'] =\n position =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const { doc } = tr\n const { from, to } = typeof position === 'number' ? { from: position, to: position } : position\n const minPos = TextSelection.atStart(doc).from\n const maxPos = TextSelection.atEnd(doc).to\n const resolvedFrom = minMax(from, minPos, maxPos)\n const resolvedEnd = minMax(to, minPos, maxPos)\n const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { sinkListItem as originalSinkListItem } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n sinkListItem: {\n /**\n * Sink the list item down into an inner list.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.sinkListItem('listItem')\n */\n sinkListItem: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const sinkListItem: RawCommands['sinkListItem'] =\n typeOrName =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalSinkListItem(type)(state, dispatch)\n }\n","import type { EditorState } from '@tiptap/pm/state'\nimport { NodeSelection, TextSelection } from '@tiptap/pm/state'\nimport { canSplit } from '@tiptap/pm/transform'\n\nimport { defaultBlockAt } from '../helpers/defaultBlockAt.js'\nimport { getSplittedAttributes } from '../helpers/getSplittedAttributes.js'\nimport type { RawCommands } from '../types.js'\n\nfunction ensureMarks(state: EditorState, splittableMarks?: string[]) {\n const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks())\n\n if (marks) {\n const filteredMarks = marks.filter(mark => splittableMarks?.includes(mark.type.name))\n\n state.tr.ensureMarks(filteredMarks)\n }\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n splitBlock: {\n /**\n * Forks a new node from an existing node.\n * @param options.keepMarks Keep marks from the previous node.\n * @example editor.commands.splitBlock()\n * @example editor.commands.splitBlock({ keepMarks: true })\n */\n splitBlock: (options?: { keepMarks?: boolean }) => ReturnType\n }\n }\n}\n\nexport const splitBlock: RawCommands['splitBlock'] =\n ({ keepMarks = true } = {}) =>\n ({ tr, state, dispatch, editor }) => {\n const { selection, doc } = tr\n const { $from, $to } = selection\n const extensionAttributes = editor.extensionManager.attributes\n const newAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs)\n\n if (selection instanceof NodeSelection && selection.node.isBlock) {\n if (!$from.parentOffset || !canSplit(doc, $from.pos)) {\n return false\n }\n\n if (dispatch) {\n if (keepMarks) {\n ensureMarks(state, editor.extensionManager.splittableMarks)\n }\n\n tr.split($from.pos).scrollIntoView()\n }\n\n return true\n }\n\n if (!$from.parent.isBlock) {\n return false\n }\n\n const atEnd = $to.parentOffset === $to.parent.content.size\n\n const deflt = $from.depth === 0 ? undefined : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))\n\n let types =\n atEnd && deflt\n ? [\n {\n type: deflt,\n attrs: newAttributes,\n },\n ]\n : undefined\n\n let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)\n\n if (!types && !can && canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {\n can = true\n types = deflt\n ? [\n {\n type: deflt,\n attrs: newAttributes,\n },\n ]\n : undefined\n }\n\n if (dispatch) {\n if (can) {\n if (selection instanceof TextSelection) {\n tr.deleteSelection()\n }\n\n tr.split(tr.mapping.map($from.pos), 1, types)\n\n if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {\n const first = tr.mapping.map($from.before())\n const $first = tr.doc.resolve(first)\n\n if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) {\n tr.setNodeMarkup(tr.mapping.map($from.before()), deflt)\n }\n }\n }\n\n if (keepMarks) {\n ensureMarks(state, editor.extensionManager.splittableMarks)\n }\n\n tr.scrollIntoView()\n }\n\n return can\n }\n","import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'\nimport { Fragment, Slice } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport { canSplit } from '@tiptap/pm/transform'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSplittedAttributes } from '../helpers/getSplittedAttributes.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n splitListItem: {\n /**\n * Splits one list item into two list items.\n * @param typeOrName The type or name of the node.\n * @param overrideAttrs The attributes to ensure on the new node.\n * @example editor.commands.splitListItem('listItem')\n */\n splitListItem: (typeOrName: string | NodeType, overrideAttrs?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const splitListItem: RawCommands['splitListItem'] =\n (typeOrName, overrideAttrs = {}) =>\n ({ tr, state, dispatch, editor }) => {\n const type = getNodeType(typeOrName, state.schema)\n const { $from, $to } = state.selection\n\n // @ts-ignore\n // eslint-disable-next-line\n const node: ProseMirrorNode = state.selection.node\n\n if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) {\n return false\n }\n\n const grandParent = $from.node(-1)\n\n if (grandParent.type !== type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes\n\n if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {\n // In an empty block. If this is a nested list, the wrapping\n // list item should be split. Otherwise, bail out and let next\n // command handle lifting.\n if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) {\n return false\n }\n\n if (dispatch) {\n let wrap = Fragment.empty\n // eslint-disable-next-line\n const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3\n\n // Build a fragment containing empty versions of the structure\n // from the outer list item to the parent node of the cursor\n for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) {\n wrap = Fragment.from($from.node(d).copy(wrap))\n }\n\n const depthAfter =\n // eslint-disable-next-line no-nested-ternary\n $from.indexAfter(-1) < $from.node(-2).childCount\n ? 1\n : $from.indexAfter(-2) < $from.node(-3).childCount\n ? 2\n : 3\n\n // Add a second list item with an empty default start node\n const newNextTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),\n ...overrideAttrs,\n }\n const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined\n\n wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined))\n\n const start = $from.before($from.depth - (depthBefore - 1))\n\n tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0))\n\n let sel = -1\n\n tr.doc.nodesBetween(start, tr.doc.content.size, (n, pos) => {\n if (sel > -1) {\n return false\n }\n\n if (n.isTextblock && n.content.size === 0) {\n sel = pos + 1\n }\n })\n\n if (sel > -1) {\n tr.setSelection(TextSelection.near(tr.doc.resolve(sel)))\n }\n\n tr.scrollIntoView()\n }\n\n return true\n }\n\n const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null\n\n const newTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),\n ...overrideAttrs,\n }\n const newNextTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),\n ...overrideAttrs,\n }\n\n tr.delete($from.pos, $to.pos)\n\n const types = nextType\n ? [\n { type, attrs: newTypeAttributes },\n { type: nextType, attrs: newNextTypeAttributes },\n ]\n : [{ type, attrs: newTypeAttributes }]\n\n if (!canSplit(tr.doc, $from.pos, 2)) {\n return false\n }\n\n if (dispatch) {\n const { selection, storedMarks } = state\n const { splittableMarks } = editor.extensionManager\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n tr.split($from.pos, 2, types).scrollIntoView()\n\n if (!marks || !dispatch) {\n return true\n }\n\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n }\n\n return true\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { canJoin } from '@tiptap/pm/transform'\n\nimport { findParentNode } from '../helpers/findParentNode.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isList } from '../helpers/isList.js'\nimport type { RawCommands } from '../types.js'\n\nconst joinListBackwards = (tr: Transaction, listType: NodeType): boolean => {\n const list = findParentNode(node => node.type === listType)(tr.selection)\n\n if (!list) {\n return true\n }\n\n const before = tr.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth)\n\n if (before === undefined) {\n return true\n }\n\n const nodeBefore = tr.doc.nodeAt(before)\n const canJoinBackwards = list.node.type === nodeBefore?.type && canJoin(tr.doc, list.pos)\n\n if (!canJoinBackwards) {\n return true\n }\n\n tr.join(list.pos)\n\n return true\n}\n\nconst joinListForwards = (tr: Transaction, listType: NodeType): boolean => {\n const list = findParentNode(node => node.type === listType)(tr.selection)\n\n if (!list) {\n return true\n }\n\n const after = tr.doc.resolve(list.start).after(list.depth)\n\n if (after === undefined) {\n return true\n }\n\n const nodeAfter = tr.doc.nodeAt(after)\n const canJoinForwards = list.node.type === nodeAfter?.type && canJoin(tr.doc, after)\n\n if (!canJoinForwards) {\n return true\n }\n\n tr.join(after)\n\n return true\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleList: {\n /**\n * Toggle between different list types.\n * @param listTypeOrName The type or name of the list.\n * @param itemTypeOrName The type or name of the list item.\n * @param keepMarks Keep marks when toggling.\n * @param attributes Attributes for the new list.\n * @example editor.commands.toggleList('bulletList', 'listItem')\n */\n toggleList: (\n listTypeOrName: string | NodeType,\n itemTypeOrName: string | NodeType,\n keepMarks?: boolean,\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const toggleList: RawCommands['toggleList'] =\n (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>\n ({ editor, tr, state, dispatch, chain, commands, can }) => {\n const { extensions, splittableMarks } = editor.extensionManager\n const listType = getNodeType(listTypeOrName, state.schema)\n const itemType = getNodeType(itemTypeOrName, state.schema)\n const { selection, storedMarks } = state\n const { $from, $to } = selection\n const range = $from.blockRange($to)\n\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n if (!range) {\n return false\n }\n\n const parentList = findParentNode(node => isList(node.type.name, extensions))(selection)\n\n if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {\n // remove list\n if (parentList.node.type === listType) {\n return commands.liftListItem(itemType)\n }\n\n // change list type\n if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {\n return chain()\n .command(() => {\n tr.setNodeMarkup(parentList.pos, listType)\n\n return true\n })\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n }\n }\n if (!keepMarks || !marks || !dispatch) {\n return (\n chain()\n // try to convert node to default node if needed\n .command(() => {\n const canWrapInList = can().wrapInList(listType, attributes)\n\n if (canWrapInList) {\n return true\n }\n\n return commands.clearNodes()\n })\n .wrapInList(listType, attributes)\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n )\n }\n\n return (\n chain()\n // try to convert node to default node if needed\n .command(() => {\n const canWrapInList = can().wrapInList(listType, attributes)\n\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n\n if (canWrapInList) {\n return true\n }\n\n return commands.clearNodes()\n })\n .wrapInList(listType, attributes)\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n )\n }\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { isMarkActive } from '../helpers/isMarkActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleMark: {\n /**\n * Toggle a mark on and off.\n * @param typeOrName The mark type or name.\n * @param attributes The attributes of the mark.\n * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.\n * @example editor.commands.toggleMark('bold')\n */\n toggleMark: (\n /**\n * The mark type or name.\n */\n typeOrName: string | MarkType,\n\n /**\n * The attributes of the mark.\n */\n attributes?: Record<string, any>,\n\n options?: {\n /**\n * Removes the mark even across the current selection. Defaults to `false`.\n */\n extendEmptyMarkRange?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const toggleMark: RawCommands['toggleMark'] =\n (typeOrName, attributes = {}, options = {}) =>\n ({ state, commands }) => {\n const { extendEmptyMarkRange = false } = options\n const type = getMarkType(typeOrName, state.schema)\n const isActive = isMarkActive(state, type, attributes)\n\n if (isActive) {\n return commands.unsetMark(type, { extendEmptyMarkRange })\n }\n\n return commands.setMark(type, attributes)\n }\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleNode: {\n /**\n * Toggle a node with another node.\n * @param typeOrName The type or name of the node.\n * @param toggleTypeOrName The type or name of the node to toggle.\n * @param attributes The attributes of the node.\n * @example editor.commands.toggleNode('heading', 'paragraph')\n */\n toggleNode: (\n typeOrName: string | NodeType,\n toggleTypeOrName: string | NodeType,\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const toggleNode: RawCommands['toggleNode'] =\n (typeOrName, toggleTypeOrName, attributes = {}) =>\n ({ state, commands }) => {\n const type = getNodeType(typeOrName, state.schema)\n const toggleType = getNodeType(toggleTypeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n let attributesToCopy: Record<string, any> | undefined\n\n if (state.selection.$anchor.sameParent(state.selection.$head)) {\n // only copy attributes if the selection is pointing to a node of the same type\n attributesToCopy = state.selection.$anchor.parent.attrs\n }\n\n if (isActive) {\n return commands.setNode(toggleType, attributesToCopy)\n }\n\n // If the node is not active, we want to set the new node type with the given attributes\n // Copying over the attributes from the current node if the selection is pointing to a node of the same type\n return commands.setNode(type, { ...attributesToCopy, ...attributes })\n }\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleWrap: {\n /**\n * Wraps nodes in another node, or removes an existing wrap.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.toggleWrap('blockquote')\n */\n toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const toggleWrap: RawCommands['toggleWrap'] =\n (typeOrName, attributes = {}) =>\n ({ state, commands }) => {\n const type = getNodeType(typeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n if (isActive) {\n return commands.lift(type)\n }\n\n return commands.wrapIn(type, attributes)\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoInputRule: {\n /**\n * Undo an input rule.\n * @example editor.commands.undoInputRule()\n */\n undoInputRule: () => ReturnType\n }\n }\n}\n\nexport const undoInputRule: RawCommands['undoInputRule'] =\n () =>\n ({ state, dispatch }) => {\n const plugins = state.plugins\n\n for (let i = 0; i < plugins.length; i += 1) {\n const plugin = plugins[i]\n let undoable\n\n // @ts-ignore\n // eslint-disable-next-line\n if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {\n if (dispatch) {\n const tr = state.tr\n const toUndo = undoable.transform\n\n for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {\n tr.step(toUndo.steps[j].invert(toUndo.docs[j]))\n }\n\n if (undoable.text) {\n const marks = tr.doc.resolve(undoable.from).marks()\n\n tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))\n } else {\n tr.delete(undoable.from, undoable.to)\n }\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetAllMarks: {\n /**\n * Remove all marks in the current selection.\n * @example editor.commands.unsetAllMarks()\n */\n unsetAllMarks: () => ReturnType\n }\n }\n}\n\nexport const unsetAllMarks: RawCommands['unsetAllMarks'] =\n () =>\n ({ tr, dispatch }) => {\n const { selection } = tr\n const { empty, ranges } = selection\n\n if (empty) {\n return true\n }\n\n if (dispatch) {\n ranges.forEach(range => {\n tr.removeMark(range.$from.pos, range.$to.pos)\n })\n }\n\n return true\n }\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarkRange } from '../helpers/getMarkRange.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetMark: {\n /**\n * Remove all marks in the current selection.\n * @param typeOrName The mark type or name.\n * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.\n * @example editor.commands.unsetMark('bold')\n */\n unsetMark: (\n /**\n * The mark type or name.\n */\n typeOrName: string | MarkType,\n\n options?: {\n /**\n * Removes the mark even across the current selection. Defaults to `false`.\n */\n extendEmptyMarkRange?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const unsetMark: RawCommands['unsetMark'] =\n (typeOrName, options = {}) =>\n ({ tr, state, dispatch }) => {\n const { extendEmptyMarkRange = false } = options\n const { selection } = tr\n const type = getMarkType(typeOrName, state.schema)\n const { $from, empty, ranges } = selection\n\n if (!dispatch) {\n return true\n }\n\n if (empty && extendEmptyMarkRange) {\n let { from, to } = selection\n const attrs = $from.marks().find(mark => mark.type === type)?.attrs\n const range = getMarkRange($from, type, attrs)\n\n if (range) {\n from = range.from\n to = range.to\n }\n\n tr.removeMark(from, to, type)\n } else {\n ranges.forEach(range => {\n tr.removeMark(range.$from.pos, range.$to.pos, type)\n })\n }\n\n tr.removeStoredMark(type)\n\n return true\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetTextDirection: {\n /**\n * Remove the text direction attribute from nodes.\n * If no position is provided, it will use the current selection.\n * @param position Optional position or range to remove the direction from\n * @example editor.commands.unsetTextDirection()\n * @example editor.commands.unsetTextDirection({ from: 0, to: 10 })\n */\n unsetTextDirection: (position?: number | Range) => ReturnType\n }\n }\n}\n\nexport const unsetTextDirection: RawCommands['unsetTextDirection'] =\n position =>\n ({ tr, state, dispatch }) => {\n const { selection } = state\n let from: number\n let to: number\n\n if (typeof position === 'number') {\n from = position\n to = position\n } else if (position && 'from' in position && 'to' in position) {\n from = position.from\n to = position.to\n } else {\n from = selection.from\n to = selection.to\n }\n\n if (dispatch) {\n tr.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n const newAttrs = { ...node.attrs }\n\n delete newAttrs.dir\n\n tr.setNodeMarkup(pos, undefined, newAttrs)\n })\n }\n\n return true\n }\n","import type { Mark, MarkType, Node, NodeType } from '@tiptap/pm/model'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n updateAttributes: {\n /**\n * Update attributes of a node or mark.\n * @param typeOrName The type or name of the node or mark.\n * @param attributes The attributes of the node or mark.\n * @example editor.commands.updateAttributes('mention', { userId: \"2\" })\n */\n updateAttributes: (\n /**\n * The type or name of the node or mark.\n */\n typeOrName: string | NodeType | MarkType,\n\n /**\n * The attributes of the node or mark.\n */\n attributes: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const updateAttributes: RawCommands['updateAttributes'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n let nodeType: NodeType | null = null\n let markType: MarkType | null = null\n\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (!schemaType) {\n return false\n }\n\n if (schemaType === 'node') {\n nodeType = getNodeType(typeOrName as NodeType, state.schema)\n }\n\n if (schemaType === 'mark') {\n markType = getMarkType(typeOrName as MarkType, state.schema)\n }\n\n let canUpdate = false\n\n tr.selection.ranges.forEach((range: SelectionRange) => {\n const from = range.$from.pos\n const to = range.$to.pos\n\n let lastPos: number | undefined\n let lastNode: Node | undefined\n let trimmedFrom: number\n let trimmedTo: number\n\n if (tr.selection.empty) {\n state.doc.nodesBetween(from, to, (node: Node, pos: number) => {\n if (nodeType && nodeType === node.type) {\n canUpdate = true\n trimmedFrom = Math.max(pos, from)\n trimmedTo = Math.min(pos + node.nodeSize, to)\n lastPos = pos\n lastNode = node\n }\n })\n } else {\n state.doc.nodesBetween(from, to, (node: Node, pos: number) => {\n if (pos < from && nodeType && nodeType === node.type) {\n canUpdate = true\n trimmedFrom = Math.max(pos, from)\n trimmedTo = Math.min(pos + node.nodeSize, to)\n lastPos = pos\n lastNode = node\n }\n\n if (pos >= from && pos <= to) {\n if (nodeType && nodeType === node.type) {\n canUpdate = true\n\n if (dispatch) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n ...attributes,\n })\n }\n }\n\n if (markType && node.marks.length) {\n node.marks.forEach((mark: Mark) => {\n if (markType === mark.type) {\n canUpdate = true\n\n if (dispatch) {\n const trimmedFrom2 = Math.max(pos, from)\n const trimmedTo2 = Math.min(pos + node.nodeSize, to)\n\n tr.addMark(\n trimmedFrom2,\n trimmedTo2,\n markType.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n }\n })\n }\n }\n })\n }\n\n if (lastNode) {\n if (lastPos !== undefined && dispatch) {\n tr.setNodeMarkup(lastPos, undefined, {\n ...lastNode.attrs,\n ...attributes,\n })\n }\n\n if (markType && lastNode.marks.length) {\n lastNode.marks.forEach((mark: Mark) => {\n if (markType === mark.type && dispatch) {\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n markType.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n })\n }\n }\n })\n\n return canUpdate\n }\n","import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n wrapIn: {\n /**\n * Wraps nodes in another node.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.wrapIn('blockquote')\n */\n wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const wrapIn: RawCommands['wrapIn'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalWrapIn(type, attributes)(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n wrapInList: {\n /**\n * Wrap a node in a list.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.wrapInList('bulletList')\n */\n wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const wrapInList: RawCommands['wrapInList'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalWrapInList(type, attributes)(state, dispatch)\n }\n","/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport type { MarkType, Node as ProseMirrorNode, NodeType, Schema } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey, Transaction } from '@tiptap/pm/state'\nimport { EditorState } from '@tiptap/pm/state'\nimport { EditorView } from '@tiptap/pm/view'\n\nimport { CommandManager } from './CommandManager.js'\nimport { EventEmitter } from './EventEmitter.js'\nimport { ExtensionManager } from './ExtensionManager.js'\nimport {\n ClipboardTextSerializer,\n Commands,\n Delete,\n Drop,\n Editable,\n FocusEvents,\n Keymap,\n Paste,\n Tabindex,\n TextDirection,\n} from './extensions/index.js'\nimport { createDocument } from './helpers/createDocument.js'\nimport { getAttributes } from './helpers/getAttributes.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport { getText } from './helpers/getText.js'\nimport { getTextSerializersFromSchema } from './helpers/getTextSerializersFromSchema.js'\nimport { isActive } from './helpers/isActive.js'\nimport { isNodeEmpty } from './helpers/isNodeEmpty.js'\nimport { createMappablePosition, getUpdatedPosition } from './helpers/MappablePosition.js'\nimport { resolveFocusPosition } from './helpers/resolveFocusPosition.js'\nimport type { Storage } from './index.js'\nimport { NodePos } from './NodePos.js'\nimport { style } from './style.js'\nimport type {\n CanCommands,\n ChainedCommands,\n DocumentType,\n EditorEvents,\n EditorOptions,\n NodeType as TNodeType,\n SingleCommands,\n TextSerializer,\n TextType as TTextType,\n Utils,\n} from './types.js'\nimport { createStyleTag } from './utilities/createStyleTag.js'\nimport { isFunction } from './utilities/isFunction.js'\n\nexport * as extensions from './extensions/index.js'\n\n// @ts-ignore\nexport interface TiptapEditorHTMLElement extends HTMLElement {\n editor?: Editor\n}\n\nexport class Editor extends EventEmitter<EditorEvents> {\n private commandManager!: CommandManager\n\n public extensionManager!: ExtensionManager\n\n private css: HTMLStyleElement | null = null\n\n private className = 'tiptap'\n\n public schema!: Schema\n\n private editorView: EditorView | null = null\n\n public isFocused = false\n\n private editorState!: EditorState\n\n /**\n * The editor is considered initialized after the `create` event has been emitted.\n */\n public isInitialized = false\n\n public extensionStorage: Storage = {} as Storage\n\n /**\n * A unique ID for this editor instance.\n */\n public instanceId = Math.random().toString(36).slice(2, 9)\n\n public options: EditorOptions = {\n element: typeof document !== 'undefined' ? document.createElement('div') : null,\n content: '',\n injectCSS: true,\n injectNonce: undefined,\n extensions: [],\n autofocus: false,\n editable: true,\n textDirection: undefined,\n editorProps: {},\n parseOptions: {},\n coreExtensionOptions: {},\n enableInputRules: true,\n enablePasteRules: true,\n enableCoreExtensions: true,\n enableContentCheck: false,\n emitContentError: false,\n onBeforeCreate: () => null,\n onCreate: () => null,\n onMount: () => null,\n onUnmount: () => null,\n onUpdate: () => null,\n onSelectionUpdate: () => null,\n onTransaction: () => null,\n onFocus: () => null,\n onBlur: () => null,\n onDestroy: () => null,\n onContentError: ({ error }) => {\n throw error\n },\n onPaste: () => null,\n onDrop: () => null,\n onDelete: () => null,\n enableExtensionDispatchTransaction: true,\n }\n\n constructor(options: Partial<EditorOptions> = {}) {\n super()\n this.setOptions(options)\n this.createExtensionManager()\n this.createCommandManager()\n this.createSchema()\n this.on('beforeCreate', this.options.onBeforeCreate)\n this.emit('beforeCreate', { editor: this })\n this.on('mount', this.options.onMount)\n this.on('unmount', this.options.onUnmount)\n this.on('contentError', this.options.onContentError)\n this.on('create', this.options.onCreate)\n this.on('update', this.options.onUpdate)\n this.on('selectionUpdate', this.options.onSelectionUpdate)\n this.on('transaction', this.options.onTransaction)\n this.on('focus', this.options.onFocus)\n this.on('blur', this.options.onBlur)\n this.on('destroy', this.options.onDestroy)\n this.on('drop', ({ event, slice, moved }) => this.options.onDrop(event, slice, moved))\n this.on('paste', ({ event, slice }) => this.options.onPaste(event, slice))\n this.on('delete', this.options.onDelete)\n\n const initialDoc = this.createDoc()\n const selection = resolveFocusPosition(initialDoc, this.options.autofocus)\n\n // Set editor state immediately, so that it's available independently from the view\n this.editorState = EditorState.create({\n doc: initialDoc,\n schema: this.schema,\n selection: selection || undefined,\n })\n\n if (this.options.element) {\n this.mount(this.options.element)\n }\n }\n\n /**\n * Attach the editor to the DOM, creating a new editor view.\n */\n public mount(el: NonNullable<EditorOptions['element']> & {}) {\n if (typeof document === 'undefined') {\n throw new Error(\n `[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`,\n )\n }\n this.createView(el)\n this.emit('mount', { editor: this })\n\n if (this.css && !document.head.contains(this.css)) {\n document.head.appendChild(this.css)\n }\n\n window.setTimeout(() => {\n if (this.isDestroyed) {\n return\n }\n\n if (this.options.autofocus !== false && this.options.autofocus !== null) {\n this.commands.focus(this.options.autofocus)\n }\n this.emit('create', { editor: this })\n this.isInitialized = true\n }, 0)\n }\n\n /**\n * Remove the editor from the DOM, but still allow remounting at a different point in time\n */\n public unmount() {\n if (this.editorView) {\n // Cleanup our reference to prevent circular references which caused memory leaks\n // @ts-ignore\n const dom = this.editorView.dom as TiptapEditorHTMLElement\n\n if (dom?.editor) {\n delete dom.editor\n }\n this.editorView.destroy()\n }\n this.editorView = null\n this.isInitialized = false\n\n // Safely remove CSS element with fallback for test environments\n // Only remove CSS if no other editors exist in the document after unmount\n if (this.css && !document.querySelectorAll(`.${this.className}`).length) {\n try {\n if (typeof this.css.remove === 'function') {\n this.css.remove()\n } else if (this.css.parentNode) {\n this.css.parentNode.removeChild(this.css)\n }\n } catch (error) {\n // Silently handle any unexpected DOM removal errors in test environments\n console.warn('Failed to remove CSS element:', error)\n }\n }\n this.css = null\n this.emit('unmount', { editor: this })\n }\n\n /**\n * Returns the editor storage.\n */\n public get storage(): Storage {\n return this.extensionStorage\n }\n\n /**\n * An object of all registered commands.\n */\n public get commands(): SingleCommands {\n return this.commandManager.commands\n }\n\n /**\n * Create a command chain to call multiple commands at once.\n */\n public chain(): ChainedCommands {\n return this.commandManager.chain()\n }\n\n /**\n * Check if a command or a command chain can be executed. Without executing it.\n */\n public can(): CanCommands {\n return this.commandManager.can()\n }\n\n /**\n * Inject CSS styles.\n */\n private injectCSS(): void {\n if (this.options.injectCSS && typeof document !== 'undefined') {\n this.css = createStyleTag(style, this.options.injectNonce)\n }\n }\n\n /**\n * Update editor options.\n *\n * @param options A list of options\n */\n public setOptions(options: Partial<EditorOptions> = {}): void {\n this.options = {\n ...this.options,\n ...options,\n }\n\n if (!this.editorView || !this.state || this.isDestroyed) {\n return\n }\n\n if (this.options.editorProps) {\n this.view.setProps(this.options.editorProps)\n }\n\n this.view.updateState(this.state)\n }\n\n /**\n * Update editable state of the editor.\n */\n public setEditable(editable: boolean, emitUpdate = true): void {\n this.setOptions({ editable })\n\n if (emitUpdate) {\n this.emit('update', { editor: this, transaction: this.state.tr, appendedTransactions: [] })\n }\n }\n\n /**\n * Returns whether the editor is editable.\n */\n public get isEditable(): boolean {\n // since plugins are applied after creating the view\n // `editable` is always `true` for one tick.\n // that’s why we also have to check for `options.editable`\n return this.options.editable && this.view && this.view.editable\n }\n\n /**\n * Returns the editor state.\n */\n public get view(): EditorView {\n if (this.editorView) {\n return this.editorView\n }\n\n return new Proxy(\n {\n state: this.editorState,\n updateState: (state: EditorState): ReturnType<EditorView['updateState']> => {\n this.editorState = state\n },\n dispatch: (tr: Transaction): ReturnType<EditorView['dispatch']> => {\n this.dispatchTransaction(tr)\n },\n\n // Stub some commonly accessed properties to prevent errors\n composing: false,\n dragging: null,\n editable: true,\n isDestroyed: false,\n } as EditorView,\n {\n get: (obj, key) => {\n if (this.editorView) {\n // If the editor view is available, but the caller has a stale reference to the proxy,\n // Just return what the editor view has.\n return this.editorView[key as keyof EditorView]\n }\n // Specifically always return the most recent editorState\n if (key === 'state') {\n return this.editorState\n }\n if (key in obj) {\n return Reflect.get(obj, key)\n }\n\n // We throw an error here, because we know the view is not available\n throw new Error(\n `[tiptap error]: The editor view is not available. Cannot access view['${key as string}']. The editor may not be mounted yet.`,\n )\n },\n },\n ) as EditorView\n }\n\n /**\n * Returns the editor state.\n */\n public get state(): EditorState {\n if (this.editorView) {\n this.editorState = this.view.state\n }\n\n return this.editorState\n }\n\n /**\n * Register a ProseMirror plugin.\n *\n * @param plugin A ProseMirror plugin\n * @param handlePlugins Control how to merge the plugin into the existing plugins.\n * @returns The new editor state\n */\n public registerPlugin(\n plugin: Plugin,\n handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],\n ): EditorState {\n const plugins = isFunction(handlePlugins)\n ? handlePlugins(plugin, [...this.state.plugins])\n : [...this.state.plugins, plugin]\n\n const state = this.state.reconfigure({ plugins })\n\n this.view.updateState(state)\n\n return state\n }\n\n /**\n * Unregister a ProseMirror plugin.\n *\n * @param nameOrPluginKeyToRemove The plugins name\n * @returns The new editor state or undefined if the editor is destroyed\n */\n public unregisterPlugin(\n nameOrPluginKeyToRemove: string | PluginKey | (string | PluginKey)[],\n ): EditorState | undefined {\n if (this.isDestroyed) {\n return undefined\n }\n\n const prevPlugins = this.state.plugins\n let plugins = prevPlugins\n\n ;([] as (string | PluginKey)[]).concat(nameOrPluginKeyToRemove).forEach(nameOrPluginKey => {\n // @ts-ignore\n const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key\n\n // @ts-ignore\n plugins = plugins.filter(plugin => !plugin.key.startsWith(name))\n })\n\n if (prevPlugins.length === plugins.length) {\n // No plugin was removed, so we don’t need to update the state\n return undefined\n }\n\n const state = this.state.reconfigure({\n plugins,\n })\n\n this.view.updateState(state)\n\n return state\n }\n\n /**\n * Creates an extension manager.\n */\n private createExtensionManager(): void {\n const coreExtensions = this.options.enableCoreExtensions\n ? [\n Editable,\n ClipboardTextSerializer.configure({\n blockSeparator: this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator,\n }),\n Commands,\n FocusEvents,\n Keymap,\n Tabindex,\n Drop,\n Paste,\n Delete,\n TextDirection.configure({\n direction: this.options.textDirection,\n }),\n ].filter(ext => {\n if (typeof this.options.enableCoreExtensions === 'object') {\n return (\n this.options.enableCoreExtensions[ext.name as keyof typeof this.options.enableCoreExtensions] !== false\n )\n }\n return true\n })\n : []\n const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {\n return ['extension', 'node', 'mark'].includes(extension?.type)\n })\n\n this.extensionManager = new ExtensionManager(allExtensions, this)\n }\n\n /**\n * Creates an command manager.\n */\n private createCommandManager(): void {\n this.commandManager = new CommandManager({\n editor: this,\n })\n }\n\n /**\n * Creates a ProseMirror schema.\n */\n private createSchema(): void {\n this.schema = this.extensionManager.schema\n }\n\n /**\n * Creates the initial document.\n */\n private createDoc(): ProseMirrorNode {\n let doc: ProseMirrorNode\n\n try {\n doc = createDocument(this.options.content, this.schema, this.options.parseOptions, {\n errorOnInvalidContent: this.options.enableContentCheck,\n })\n } catch (e) {\n if (\n !(e instanceof Error) ||\n !['[tiptap error]: Invalid JSON content', '[tiptap error]: Invalid HTML content'].includes(e.message)\n ) {\n // Not the content error we were expecting\n throw e\n }\n this.emit('contentError', {\n editor: this,\n error: e as Error,\n disableCollaboration: () => {\n if (\n 'collaboration' in this.storage &&\n typeof this.storage.collaboration === 'object' &&\n this.storage.collaboration\n ) {\n ;(this.storage.collaboration as any).isDisabled = true\n }\n // To avoid syncing back invalid content, reinitialize the extensions without the collaboration extension\n this.options.extensions = this.options.extensions.filter(extension => extension.name !== 'collaboration')\n\n // Restart the initialization process by recreating the extension manager with the new set of extensions\n this.createExtensionManager()\n },\n })\n\n // Content is invalid, but attempt to create it anyway, stripping out the invalid parts\n doc = createDocument(this.options.content, this.schema, this.options.parseOptions, {\n errorOnInvalidContent: false,\n })\n }\n return doc\n }\n\n /**\n * Creates a ProseMirror view.\n */\n private createView(element: NonNullable<EditorOptions['element']>): void {\n const { editorProps, enableExtensionDispatchTransaction } = this.options\n // If a user provided a custom `dispatchTransaction` through `editorProps`,\n // we use that as the base dispatch function.\n // Otherwise, we use Tiptap's internal `dispatchTransaction` method.\n const baseDispatch = (editorProps as any).dispatchTransaction || this.dispatchTransaction.bind(this)\n const dispatch = enableExtensionDispatchTransaction\n ? this.extensionManager.dispatchTransaction(baseDispatch)\n : baseDispatch\n\n this.editorView = new EditorView(element, {\n ...editorProps,\n attributes: {\n // add `role=\"textbox\"` to the editor element\n role: 'textbox',\n ...editorProps?.attributes,\n },\n dispatchTransaction: dispatch,\n state: this.editorState,\n markViews: this.extensionManager.markViews,\n nodeViews: this.extensionManager.nodeViews,\n })\n\n // `editor.view` is not yet available at this time.\n // Therefore we will add all plugins and node views directly afterwards.\n const newState = this.state.reconfigure({\n plugins: this.extensionManager.plugins,\n })\n\n this.view.updateState(newState)\n\n this.prependClass()\n this.injectCSS()\n\n // Let’s store the editor instance in the DOM element.\n // So we’ll have access to it for tests.\n // @ts-ignore\n const dom = this.view.dom as TiptapEditorHTMLElement\n\n dom.editor = this\n }\n\n /**\n * Creates all node and mark views.\n */\n public createNodeViews(): void {\n if (this.view.isDestroyed) {\n return\n }\n\n this.view.setProps({\n markViews: this.extensionManager.markViews,\n nodeViews: this.extensionManager.nodeViews,\n })\n }\n\n /**\n * Prepend class name to element.\n */\n public prependClass(): void {\n this.view.dom.className = `${this.className} ${this.view.dom.className}`\n }\n\n public isCapturingTransaction = false\n\n private capturedTransaction: Transaction | null = null\n\n public captureTransaction(fn: () => void) {\n this.isCapturingTransaction = true\n fn()\n this.isCapturingTransaction = false\n\n const tr = this.capturedTransaction\n\n this.capturedTransaction = null\n\n return tr\n }\n\n /**\n * The callback over which to send transactions (state updates) produced by the view.\n *\n * @param transaction An editor state transaction\n */\n private dispatchTransaction(transaction: Transaction): void {\n // if the editor / the view of the editor was destroyed\n // the transaction should not be dispatched as there is no view anymore.\n if (this.view.isDestroyed) {\n return\n }\n\n if (this.isCapturingTransaction) {\n if (!this.capturedTransaction) {\n this.capturedTransaction = transaction\n\n return\n }\n\n transaction.steps.forEach(step => this.capturedTransaction?.step(step))\n\n return\n }\n\n // Apply transaction and get resulting state and transactions\n const { state, transactions } = this.state.applyTransaction(transaction)\n const selectionHasChanged = !this.state.selection.eq(state.selection)\n const rootTrWasApplied = transactions.includes(transaction)\n const prevState = this.state\n\n this.emit('beforeTransaction', {\n editor: this,\n transaction,\n nextState: state,\n })\n\n // If transaction was filtered out, we can return early\n if (!rootTrWasApplied) {\n return\n }\n\n this.view.updateState(state)\n\n // Emit transaction event with appended transactions info\n this.emit('transaction', {\n editor: this,\n transaction,\n appendedTransactions: transactions.slice(1),\n })\n\n if (selectionHasChanged) {\n this.emit('selectionUpdate', {\n editor: this,\n transaction,\n })\n }\n\n // Only emit the latest between focus and blur events\n const mostRecentFocusTr = transactions.findLast(tr => tr.getMeta('focus') || tr.getMeta('blur'))\n const focus = mostRecentFocusTr?.getMeta('focus')\n const blur = mostRecentFocusTr?.getMeta('blur')\n\n if (focus) {\n this.emit('focus', {\n editor: this,\n event: focus.event,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n transaction: mostRecentFocusTr!,\n })\n }\n\n if (blur) {\n this.emit('blur', {\n editor: this,\n event: blur.event,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n transaction: mostRecentFocusTr!,\n })\n }\n\n // Compare states for update event\n if (\n transaction.getMeta('preventUpdate') ||\n !transactions.some(tr => tr.docChanged) ||\n prevState.doc.eq(state.doc)\n ) {\n return\n }\n\n this.emit('update', {\n editor: this,\n transaction,\n appendedTransactions: transactions.slice(1),\n })\n }\n\n /**\n * Get attributes of the currently selected node or mark.\n */\n public getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any> {\n return getAttributes(this.state, nameOrType)\n }\n\n /**\n * Returns if the currently selected node or mark is active.\n *\n * @param name Name of the node or mark\n * @param attributes Attributes of the node or mark\n */\n public isActive(name: string, attributes?: {}): boolean\n public isActive(attributes: {}): boolean\n public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {\n const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null\n\n const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes\n\n return isActive(this.state, name, attributes)\n }\n\n /**\n * Get the document as JSON.\n */\n public getJSON(): DocumentType<\n Record<string, any> | undefined,\n TNodeType<string, undefined | Record<string, any>, any, (TNodeType | TTextType)[]>[]\n > {\n return this.state.doc.toJSON()\n }\n\n /**\n * Get the document as HTML.\n */\n public getHTML(): string {\n return getHTMLFromFragment(this.state.doc.content, this.schema)\n }\n\n /**\n * Get the document as text.\n */\n public getText(options?: { blockSeparator?: string; textSerializers?: Record<string, TextSerializer> }): string {\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n\n return getText(this.state.doc, {\n blockSeparator,\n textSerializers: {\n ...getTextSerializersFromSchema(this.schema),\n ...textSerializers,\n },\n })\n }\n\n /**\n * Check if there is no content.\n */\n public get isEmpty(): boolean {\n return isNodeEmpty(this.state.doc)\n }\n\n /**\n * Destroy the editor.\n */\n public destroy(): void {\n this.emit('destroy')\n\n this.unmount()\n\n this.removeAllListeners()\n }\n\n /**\n * Check if the editor is already destroyed.\n */\n public get isDestroyed(): boolean {\n return this.editorView?.isDestroyed ?? true\n }\n\n public $node(selector: string, attributes?: { [key: string]: any }): NodePos | null {\n return this.$doc?.querySelector(selector, attributes) || null\n }\n\n public $nodes(selector: string, attributes?: { [key: string]: any }): NodePos[] | null {\n return this.$doc?.querySelectorAll(selector, attributes) || null\n }\n\n public $pos(pos: number) {\n const $pos = this.state.doc.resolve(pos)\n\n return new NodePos($pos, this)\n }\n\n get $doc() {\n return this.$pos(0)\n }\n\n /**\n * Returns a set of utilities for working with positions and ranges.\n */\n public utils: Utils = {\n getUpdatedPosition,\n createMappablePosition,\n }\n}\n","type StringKeyOf<T> = Extract<keyof T, string>\ntype CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[]\n ? T[EventName]\n : [T[EventName]]\ntype CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (\n ...props: CallbackType<T, EventName>\n) => any\n\nexport class EventEmitter<T extends Record<string, any>> {\n private callbacks: { [key: string]: Array<(...args: any[]) => void> } = {}\n\n public on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {\n if (!this.callbacks[event]) {\n this.callbacks[event] = []\n }\n\n this.callbacks[event].push(fn)\n\n return this\n }\n\n public emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this {\n const callbacks = this.callbacks[event]\n\n if (callbacks) {\n callbacks.forEach(callback => callback.apply(this, args))\n }\n\n return this\n }\n\n public off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this {\n const callbacks = this.callbacks[event]\n\n if (callbacks) {\n if (fn) {\n this.callbacks[event] = callbacks.filter(callback => callback !== fn)\n } else {\n delete this.callbacks[event]\n }\n }\n\n return this\n }\n\n public once<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {\n const onceFn = (...args: CallbackType<T, EventName>) => {\n this.off(event, onceFn)\n fn.apply(this, args)\n }\n\n return this.on(event, onceFn)\n }\n\n public removeAllListeners(): void {\n this.callbacks = {}\n }\n}\n","import { keymap } from '@tiptap/pm/keymap'\nimport type { Schema } from '@tiptap/pm/model'\nimport type { Plugin, Transaction } from '@tiptap/pm/state'\nimport type { MarkViewConstructor, NodeViewConstructor } from '@tiptap/pm/view'\n\nimport type { Editor } from './Editor.js'\nimport {\n flattenExtensions,\n getAttributesFromExtensions,\n getExtensionField,\n getNodeType,\n getRenderedAttributes,\n getSchemaByResolvedExtensions,\n getSchemaTypeByName,\n isExtensionRulesEnabled,\n resolveExtensions,\n sortExtensions,\n splitExtensions,\n} from './helpers/index.js'\nimport { type MarkConfig, type NodeConfig, type Storage, getMarkType, updateMarkViewAttributes } from './index.js'\nimport { inputRulesPlugin } from './InputRule.js'\nimport { Mark } from './Mark.js'\nimport { pasteRulesPlugin } from './PasteRule.js'\nimport type { AnyConfig, Extensions, RawCommands } from './types.js'\nimport { callOrReturn } from './utilities/callOrReturn.js'\n\nexport class ExtensionManager {\n editor: Editor\n\n schema: Schema\n\n /**\n * A flattened and sorted array of all extensions\n */\n extensions: Extensions\n\n /**\n * A non-flattened array of base extensions (no sub-extensions)\n */\n baseExtensions: Extensions\n\n splittableMarks: string[] = []\n\n constructor(extensions: Extensions, editor: Editor) {\n this.editor = editor\n this.baseExtensions = extensions\n this.extensions = resolveExtensions(extensions)\n this.schema = getSchemaByResolvedExtensions(this.extensions, editor)\n this.setupExtensions()\n }\n\n static resolve = resolveExtensions\n\n static sort = sortExtensions\n\n static flatten = flattenExtensions\n\n /**\n * Get all commands from the extensions.\n * @returns An object with all commands where the key is the command name and the value is the command function\n */\n get commands(): RawCommands {\n return this.extensions.reduce((commands, extension) => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor: this.editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const addCommands = getExtensionField<AnyConfig['addCommands']>(extension, 'addCommands', context)\n\n if (!addCommands) {\n return commands\n }\n\n return {\n ...commands,\n ...addCommands(),\n }\n }, {} as RawCommands)\n }\n\n /**\n * Get all registered Prosemirror plugins from the extensions.\n * @returns An array of Prosemirror plugins\n */\n get plugins(): Plugin[] {\n const { editor } = this\n\n // With ProseMirror, first plugins within an array are executed first.\n // In Tiptap, we provide the ability to override plugins,\n // so it feels more natural to run plugins at the end of an array first.\n // That’s why we have to reverse the `extensions` array and sort again\n // based on the `priority` option.\n const extensions = sortExtensions([...this.extensions].reverse())\n\n const allPlugins = extensions.flatMap(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const plugins: Plugin[] = []\n\n const addKeyboardShortcuts = getExtensionField<AnyConfig['addKeyboardShortcuts']>(\n extension,\n 'addKeyboardShortcuts',\n context,\n )\n\n let defaultBindings: Record<string, () => boolean> = {}\n\n // bind exit handling\n if (extension.type === 'mark' && getExtensionField<MarkConfig['exitable']>(extension, 'exitable', context)) {\n defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })\n }\n\n if (addKeyboardShortcuts) {\n const bindings = Object.fromEntries(\n Object.entries(addKeyboardShortcuts()).map(([shortcut, method]) => {\n return [shortcut, () => method({ editor })]\n }),\n )\n\n defaultBindings = { ...defaultBindings, ...bindings }\n }\n\n const keyMapPlugin = keymap(defaultBindings)\n\n plugins.push(keyMapPlugin)\n\n const addInputRules = getExtensionField<AnyConfig['addInputRules']>(extension, 'addInputRules', context)\n\n if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {\n const rules = addInputRules()\n\n if (rules && rules.length) {\n const inputResult = inputRulesPlugin({\n editor,\n rules,\n })\n\n const inputPlugins = Array.isArray(inputResult) ? inputResult : [inputResult]\n\n plugins.push(...inputPlugins)\n }\n }\n\n const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(extension, 'addPasteRules', context)\n\n if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {\n const rules = addPasteRules()\n\n if (rules && rules.length) {\n const pasteRules = pasteRulesPlugin({ editor, rules })\n\n plugins.push(...pasteRules)\n }\n }\n\n const addProseMirrorPlugins = getExtensionField<AnyConfig['addProseMirrorPlugins']>(\n extension,\n 'addProseMirrorPlugins',\n context,\n )\n\n if (addProseMirrorPlugins) {\n const proseMirrorPlugins = addProseMirrorPlugins()\n\n plugins.push(...proseMirrorPlugins)\n }\n\n return plugins\n })\n\n return allPlugins\n }\n\n /**\n * Get all attributes from the extensions.\n * @returns An array of attributes\n */\n get attributes() {\n return getAttributesFromExtensions(this.extensions)\n }\n\n /**\n * Get all node views from the extensions.\n * @returns An object with all node views where the key is the node name and the value is the node view function\n */\n get nodeViews(): Record<string, NodeViewConstructor> {\n const { editor } = this\n const { nodeExtensions } = splitExtensions(this.extensions)\n\n return Object.fromEntries(\n nodeExtensions\n .filter(extension => !!getExtensionField(extension, 'addNodeView'))\n .map(extension => {\n const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getNodeType(extension.name, this.schema),\n }\n const addNodeView = getExtensionField<NodeConfig['addNodeView']>(extension, 'addNodeView', context)\n\n if (!addNodeView) {\n return []\n }\n\n const nodeViewResult = addNodeView()\n\n if (!nodeViewResult) {\n return []\n }\n\n const nodeview: NodeViewConstructor = (node, view, getPos, decorations, innerDecorations) => {\n const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)\n\n return nodeViewResult({\n // pass-through\n node,\n view,\n getPos: getPos as () => number,\n decorations,\n innerDecorations,\n // tiptap-specific\n editor,\n extension,\n HTMLAttributes,\n })\n }\n\n return [extension.name, nodeview]\n }),\n )\n }\n\n /**\n * Get the composed dispatchTransaction function from all extensions.\n * @param baseDispatch The base dispatch function (e.g. from the editor or user props)\n * @returns A composed dispatch function\n */\n dispatchTransaction(baseDispatch: (tr: Transaction) => void): (tr: Transaction) => void {\n const { editor } = this\n const extensions = sortExtensions([...this.extensions].reverse())\n\n return extensions.reduceRight((next, extension) => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const dispatchTransaction = getExtensionField<AnyConfig['dispatchTransaction']>(\n extension,\n 'dispatchTransaction',\n context,\n )\n\n if (!dispatchTransaction) {\n return next\n }\n\n return (transaction: Transaction) => {\n dispatchTransaction.call(context, { transaction, next })\n }\n }, baseDispatch)\n }\n\n get markViews(): Record<string, MarkViewConstructor> {\n const { editor } = this\n const { markExtensions } = splitExtensions(this.extensions)\n\n return Object.fromEntries(\n markExtensions\n .filter(extension => !!getExtensionField(extension, 'addMarkView'))\n .map(extension => {\n const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getMarkType(extension.name, this.schema),\n }\n const addMarkView = getExtensionField<MarkConfig['addMarkView']>(extension, 'addMarkView', context)\n\n if (!addMarkView) {\n return []\n }\n\n const markView: MarkViewConstructor = (mark, view, inline) => {\n const HTMLAttributes = getRenderedAttributes(mark, extensionAttributes)\n\n return addMarkView()({\n // pass-through\n mark,\n view,\n inline,\n // tiptap-specific\n editor,\n extension,\n HTMLAttributes,\n updateAttributes: (attrs: Record<string, any>) => {\n updateMarkViewAttributes(mark, editor, attrs)\n },\n })\n }\n\n return [extension.name, markView]\n }),\n )\n }\n\n /**\n * Go through all extensions, create extension storages & setup marks\n * & bind editor event listener.\n */\n private setupExtensions() {\n const extensions = this.extensions\n // re-initialize the extension storage object instance\n this.editor.extensionStorage = Object.fromEntries(\n extensions.map(extension => [extension.name, extension.storage]),\n ) as unknown as Storage\n\n extensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor: this.editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n if (extension.type === 'mark') {\n const keepOnSplit = callOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true\n\n if (keepOnSplit) {\n this.splittableMarks.push(extension.name)\n }\n }\n\n const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(extension, 'onBeforeCreate', context)\n const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)\n const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)\n const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(\n extension,\n 'onSelectionUpdate',\n context,\n )\n const onTransaction = getExtensionField<AnyConfig['onTransaction']>(extension, 'onTransaction', context)\n const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)\n const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)\n const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)\n\n if (onBeforeCreate) {\n this.editor.on('beforeCreate', onBeforeCreate)\n }\n\n if (onCreate) {\n this.editor.on('create', onCreate)\n }\n\n if (onUpdate) {\n this.editor.on('update', onUpdate)\n }\n\n if (onSelectionUpdate) {\n this.editor.on('selectionUpdate', onSelectionUpdate)\n }\n\n if (onTransaction) {\n this.editor.on('transaction', onTransaction)\n }\n\n if (onFocus) {\n this.editor.on('focus', onFocus)\n }\n\n if (onBlur) {\n this.editor.on('blur', onBlur)\n }\n\n if (onDestroy) {\n this.editor.on('destroy', onDestroy)\n }\n })\n }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\nimport type { EditorState, TextSelection } from '@tiptap/pm/state'\nimport { Plugin } from '@tiptap/pm/state'\n\nimport { CommandManager } from './CommandManager.js'\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport { getTextContentFromNodes } from './helpers/getTextContentFromNodes.js'\nimport type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'\nimport { isRegExp } from './utilities/isRegExp.js'\n\nexport type InputRuleMatch = {\n index: number\n text: string\n replaceWith?: string\n match?: RegExpMatchArray\n data?: Record<string, any>\n}\n\nexport type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null)\n\nexport class InputRule {\n find: InputRuleFinder\n\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n }) => void | null\n\n undoable: boolean\n\n constructor(config: {\n find: InputRuleFinder\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n }) => void | null\n undoable?: boolean\n }) {\n this.find = config.find\n this.handler = config.handler\n this.undoable = config.undoable ?? true\n }\n}\n\nconst inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedRegExpMatchArray | null => {\n if (isRegExp(find)) {\n return find.exec(text)\n }\n\n const inputRuleMatch = find(text)\n\n if (!inputRuleMatch) {\n return null\n }\n\n const result: ExtendedRegExpMatchArray = [inputRuleMatch.text]\n\n result.index = inputRuleMatch.index\n result.input = text\n result.data = inputRuleMatch.data\n\n if (inputRuleMatch.replaceWith) {\n if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {\n console.warn('[tiptap warn]: \"inputRuleMatch.replaceWith\" must be part of \"inputRuleMatch.text\".')\n }\n\n result.push(inputRuleMatch.replaceWith)\n }\n\n return result\n}\n\nfunction run(config: {\n editor: Editor\n from: number\n to: number\n text: string\n rules: InputRule[]\n plugin: Plugin\n}): boolean {\n const { editor, from, to, text, rules, plugin } = config\n const { view } = editor\n\n if (view.composing) {\n return false\n }\n\n const $from = view.state.doc.resolve(from)\n\n if (\n // check for code node\n $from.parent.type.spec.code ||\n // check for code mark\n !!($from.nodeBefore || $from.nodeAfter)?.marks.find(mark => mark.type.spec.code)\n ) {\n return false\n }\n\n let matched = false\n\n const textBefore = getTextContentFromNodes($from) + text\n\n rules.forEach(rule => {\n if (matched) {\n return\n }\n\n const match = inputRuleMatcherHandler(textBefore, rule.find)\n\n if (!match) {\n return\n }\n\n const tr = view.state.tr\n const state = createChainableState({\n state: view.state,\n transaction: tr,\n })\n const range = {\n from: from - (match[0].length - text.length),\n to,\n }\n\n const { commands, chain, can } = new CommandManager({\n editor,\n state,\n })\n\n const handler = rule.handler({\n state,\n range,\n match,\n commands,\n chain,\n can,\n })\n\n // stop if there are no changes\n if (handler === null || !tr.steps.length) {\n return\n }\n\n // store transform as meta data\n // so we can undo input rules within the `undoInputRules` command\n if (rule.undoable) {\n tr.setMeta(plugin, {\n transform: tr,\n from,\n to,\n text,\n })\n }\n\n view.dispatch(tr)\n matched = true\n })\n\n return matched\n}\n\n/**\n * Create an input rules plugin. When enabled, it will cause text\n * input that matches any of the given rules to trigger the rule’s\n * action.\n */\nexport function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }): Plugin {\n const { editor, rules } = props\n const plugin = new Plugin({\n state: {\n init() {\n return null\n },\n apply(tr, prev, state) {\n const stored = tr.getMeta(plugin)\n\n if (stored) {\n return stored\n }\n\n // if InputRule is triggered by insertContent()\n const simulatedInputMeta = tr.getMeta('applyInputRules') as\n | undefined\n | {\n from: number\n text: string | ProseMirrorNode | Fragment\n }\n const isSimulatedInput = !!simulatedInputMeta\n\n if (isSimulatedInput) {\n setTimeout(() => {\n let { text } = simulatedInputMeta\n\n if (typeof text === 'string') {\n text = text as string\n } else {\n text = getHTMLFromFragment(Fragment.from(text), state.schema)\n }\n\n const { from } = simulatedInputMeta\n const to = from + text.length\n\n run({\n editor,\n from,\n to,\n text,\n rules,\n plugin,\n })\n })\n }\n\n return tr.selectionSet || tr.docChanged ? null : prev\n },\n },\n\n props: {\n handleTextInput(view, from, to, text) {\n return run({\n editor,\n from,\n to,\n text,\n rules,\n plugin,\n })\n },\n\n handleDOMEvents: {\n compositionend: view => {\n setTimeout(() => {\n const { $cursor } = view.state.selection as TextSelection\n\n if ($cursor) {\n run({\n editor,\n from: $cursor.pos,\n to: $cursor.pos,\n text: '',\n rules,\n plugin,\n })\n }\n })\n\n return false\n },\n },\n\n // add support for input rules to trigger on enter\n // this is useful for example for code blocks\n handleKeyDown(view, event) {\n if (event.key !== 'Enter') {\n return false\n }\n\n const { $cursor } = view.state.selection as TextSelection\n\n if ($cursor) {\n return run({\n editor,\n from: $cursor.pos,\n to: $cursor.pos,\n text: '\\n',\n rules,\n plugin,\n })\n }\n\n return false\n },\n },\n\n // @ts-ignore\n isInputRules: true,\n }) as Plugin\n\n return plugin\n}\n","// see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts\n\nfunction getType(value: any): string {\n return Object.prototype.toString.call(value).slice(8, -1)\n}\n\nexport function isPlainObject(value: any): value is Record<string, any> {\n if (getType(value) !== 'Object') {\n return false\n }\n\n return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype\n}\n","import { isPlainObject } from './isPlainObject.js'\n\nexport function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {\n const output = { ...target }\n\n if (isPlainObject(target) && isPlainObject(source)) {\n Object.keys(source).forEach(key => {\n if (isPlainObject(source[key]) && isPlainObject(target[key])) {\n output[key] = mergeDeep(target[key], source[key])\n } else {\n output[key] = source[key]\n }\n })\n }\n\n return output\n}\n","import type { Plugin } from '@tiptap/pm/state'\n\nimport type { Editor } from './Editor.js'\nimport { getExtensionField } from './helpers/getExtensionField.js'\nimport type { ExtensionConfig, MarkConfig, NodeConfig } from './index.js'\nimport type { InputRule } from './InputRule.js'\nimport type { Mark } from './Mark.js'\nimport type { Node } from './Node.js'\nimport type { PasteRule } from './PasteRule.js'\nimport type {\n AnyConfig,\n DispatchTransactionProps,\n EditorEvents,\n Extensions,\n GlobalAttributes,\n JSONContent,\n KeyboardShortcutCommand,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownRendererHelpers,\n MarkdownToken,\n MarkdownTokenizer,\n ParentConfig,\n RawCommands,\n RenderContext,\n} from './types.js'\nimport { callOrReturn } from './utilities/callOrReturn.js'\nimport { mergeDeep } from './utilities/mergeDeep.js'\n\nexport interface ExtendableConfig<\n Options = any,\n Storage = any,\n Config extends\n | ExtensionConfig<Options, Storage>\n | NodeConfig<Options, Storage>\n | MarkConfig<Options, Storage>\n | ExtendableConfig<Options, Storage> = ExtendableConfig<Options, Storage, any, any>,\n PMType = any,\n> {\n /**\n * The extension name - this must be unique.\n * It will be used to identify the extension.\n *\n * @example 'myExtension'\n */\n name: string\n\n /**\n * The priority of your extension. The higher, the earlier it will be called\n * and will take precedence over other extensions with a lower priority.\n * @default 100\n * @example 101\n */\n priority?: number\n\n /**\n * This method will add options to this extension\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#settings\n * @example\n * addOptions() {\n * return {\n * myOption: 'foo',\n * myOtherOption: 10,\n * }\n */\n addOptions?: (this: { name: string; parent: ParentConfig<Config>['addOptions'] }) => Options\n\n /**\n * The default storage this extension can save data to.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#storage\n * @example\n * defaultStorage: {\n * prefetchedUsers: [],\n * loading: false,\n * }\n */\n addStorage?: (this: { name: string; options: Options; parent: ParentConfig<Config>['addStorage'] }) => Storage\n\n /**\n * This function adds globalAttributes to specific nodes.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#global-attributes\n * @example\n * addGlobalAttributes() {\n * return [\n * {\n // Extend the following extensions\n * types: [\n * 'heading',\n * 'paragraph',\n * ],\n * // … with those attributes\n * attributes: {\n * textAlign: {\n * default: 'left',\n * renderHTML: attributes => ({\n * style: `text-align: ${attributes.textAlign}`,\n * }),\n * parseHTML: element => element.style.textAlign || 'left',\n * },\n * },\n * },\n * ]\n * }\n */\n addGlobalAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n extensions: (Node | Mark)[]\n parent: ParentConfig<Config>['addGlobalAttributes']\n }) => GlobalAttributes\n\n /**\n * This function adds commands to the editor\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#commands\n * @example\n * addCommands() {\n * return {\n * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),\n * }\n * }\n */\n addCommands?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addCommands']\n }) => Partial<RawCommands>\n\n /**\n * This function registers keyboard shortcuts.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#keyboard-shortcuts\n * @example\n * addKeyboardShortcuts() {\n * return {\n * 'Mod-l': () => this.editor.commands.toggleBulletList(),\n * }\n * },\n */\n addKeyboardShortcuts?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addKeyboardShortcuts']\n }) => {\n [key: string]: KeyboardShortcutCommand\n }\n\n /**\n * This function adds input rules to the editor.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#input-rules\n * @example\n * addInputRules() {\n * return [\n * markInputRule({\n * find: inputRegex,\n * type: this.type,\n * }),\n * ]\n * },\n */\n addInputRules?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addInputRules']\n }) => InputRule[]\n\n /**\n * This function adds paste rules to the editor.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#paste-rules\n * @example\n * addPasteRules() {\n * return [\n * markPasteRule({\n * find: pasteRegex,\n * type: this.type,\n * }),\n * ]\n * },\n */\n addPasteRules?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addPasteRules']\n }) => PasteRule[]\n\n /**\n * This function adds Prosemirror plugins to the editor\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#prosemirror-plugins\n * @example\n * addProseMirrorPlugins() {\n * return [\n * customPlugin(),\n * ]\n * }\n */\n addProseMirrorPlugins?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addProseMirrorPlugins']\n }) => Plugin[]\n\n /**\n * This function adds additional extensions to the editor. This is useful for\n * building extension kits.\n * @example\n * addExtensions() {\n * return [\n * BulletList,\n * OrderedList,\n * ListItem\n * ]\n * }\n */\n addExtensions?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['addExtensions']\n }) => Extensions\n\n /**\n * The markdown token name\n *\n * This is the name of the token that this extension uses to parse and render markdown and comes from the Marked Lexer.\n *\n * @see https://github.com/markedjs/marked/blob/master/src/Tokens.ts\n *\n */\n markdownTokenName?: string\n\n /**\n * The parse function used by the markdown parser to convert markdown tokens to ProseMirror nodes.\n */\n parseMarkdown?: (token: MarkdownToken, helpers: MarkdownParseHelpers) => MarkdownParseResult\n\n /**\n * The serializer function used by the markdown serializer to convert ProseMirror nodes to markdown tokens.\n */\n renderMarkdown?: (node: JSONContent, helpers: MarkdownRendererHelpers, ctx: RenderContext) => string\n\n /**\n * The markdown tokenizer responsible for turning a markdown string into tokens\n *\n * Custom tokenizers are only needed when you want to parse non-standard markdown token.\n */\n markdownTokenizer?: MarkdownTokenizer\n\n /**\n * Optional markdown options for indentation\n */\n markdownOptions?: {\n /**\n * Defines if this markdown element should indent it's child elements\n */\n indentsContent?: boolean\n }\n\n /**\n * This function extends the schema of the node.\n * @example\n * extendNodeSchema() {\n * return {\n * group: 'inline',\n * selectable: false,\n * }\n * }\n */\n extendNodeSchema?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['extendNodeSchema']\n },\n extension: Node,\n ) => Record<string, any>)\n | null\n\n /**\n * This function extends the schema of the mark.\n * @example\n * extendMarkSchema() {\n * return {\n * group: 'inline',\n * selectable: false,\n * }\n * }\n */\n extendMarkSchema?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['extendMarkSchema']\n },\n extension: Mark,\n ) => Record<string, any>)\n | null\n\n /**\n * The editor is not ready yet.\n */\n onBeforeCreate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onBeforeCreate']\n },\n event: EditorEvents['beforeCreate'],\n ) => void)\n | null\n\n /**\n * The editor is ready.\n */\n onCreate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onCreate']\n },\n event: EditorEvents['create'],\n ) => void)\n | null\n\n /**\n * The content has changed.\n */\n onUpdate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onUpdate']\n },\n event: EditorEvents['update'],\n ) => void)\n | null\n\n /**\n * The selection has changed.\n */\n onSelectionUpdate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onSelectionUpdate']\n },\n event: EditorEvents['selectionUpdate'],\n ) => void)\n | null\n\n /**\n * The editor state has changed.\n */\n onTransaction?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onTransaction']\n },\n event: EditorEvents['transaction'],\n ) => void)\n | null\n\n /**\n * The editor is focused.\n */\n onFocus?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onFocus']\n },\n event: EditorEvents['focus'],\n ) => void)\n | null\n\n /**\n * The editor isn’t focused anymore.\n */\n onBlur?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onBlur']\n },\n event: EditorEvents['blur'],\n ) => void)\n | null\n\n /**\n * The editor is destroyed.\n */\n onDestroy?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onDestroy']\n },\n event: EditorEvents['destroy'],\n ) => void)\n | null\n\n /**\n * This hook allows you to intercept and modify transactions before they are dispatched.\n *\n * Example\n * ```ts\n * dispatchTransaction({ transaction, next }) {\n * console.log('Dispatching transaction:', transaction)\n * next(transaction)\n * }\n * ```\n *\n * @param props - The dispatch transaction props\n */\n dispatchTransaction?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['dispatchTransaction']\n },\n props: DispatchTransactionProps,\n ) => void)\n | null\n}\n\nexport class Extendable<\n Options = any,\n Storage = any,\n Config = ExtensionConfig<Options, Storage> | NodeConfig<Options, Storage> | MarkConfig<Options, Storage>,\n> {\n type = 'extendable'\n parent: Extendable | null = null\n\n child: Extendable | null = null\n\n name = ''\n\n config: Config = {\n name: this.name,\n } as Config\n\n constructor(config: Partial<Config> = {}) {\n this.config = {\n ...this.config,\n ...config,\n }\n\n this.name = (this.config as any).name\n }\n\n get options(): Options {\n return {\n ...(callOrReturn(\n getExtensionField<AnyConfig['addOptions']>(this as any, 'addOptions', {\n name: this.name,\n }),\n ) || {}),\n }\n }\n\n get storage(): Readonly<Storage> {\n return {\n ...(callOrReturn(\n getExtensionField<AnyConfig['addStorage']>(this as any, 'addStorage', {\n name: this.name,\n options: this.options,\n }),\n ) || {}),\n }\n }\n\n configure(options: Partial<Options> = {}) {\n const extension = this.extend<Options, Storage, Config>({\n ...this.config,\n addOptions: () => {\n return mergeDeep(this.options as Record<string, any>, options) as Options\n },\n })\n\n extension.name = this.name\n extension.parent = this.parent\n\n return extension\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig =\n | ExtensionConfig<ExtendedOptions, ExtendedStorage>\n | NodeConfig<ExtendedOptions, ExtendedStorage>\n | MarkConfig<ExtendedOptions, ExtendedStorage>,\n >(extendedConfig: Partial<ExtendedConfig> = {}): Extendable<ExtendedOptions, ExtendedStorage> {\n const extension = new (this.constructor as any)({ ...this.config, ...extendedConfig })\n\n extension.parent = this\n this.child = extension\n extension.name = 'name' in extendedConfig ? extendedConfig.name : extension.parent.name\n\n return extension\n }\n}\n","import type { DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { ExtendableConfig } from './Extendable.js'\nimport { Extendable } from './Extendable.js'\nimport type { Attributes, MarkViewRenderer, ParentConfig } from './types.js'\n\nexport interface MarkConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, MarkConfig<Options, Storage>, MarkType> {\n /**\n * Mark View\n */\n addMarkView?:\n | ((this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: MarkType\n parent: ParentConfig<MarkConfig<Options, Storage>>['addMarkView']\n }) => MarkViewRenderer)\n | null\n\n /**\n * Keep mark after split node\n */\n keepOnSplit?: boolean | (() => boolean)\n\n /**\n * Inclusive\n */\n inclusive?:\n | MarkSpec['inclusive']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']\n editor?: Editor\n }) => MarkSpec['inclusive'])\n\n /**\n * Excludes\n */\n excludes?:\n | MarkSpec['excludes']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']\n editor?: Editor\n }) => MarkSpec['excludes'])\n\n /**\n * Marks this Mark as exitable\n */\n exitable?: boolean | (() => boolean)\n\n /**\n * Group\n */\n group?:\n | MarkSpec['group']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['group']\n editor?: Editor\n }) => MarkSpec['group'])\n\n /**\n * Spanning\n */\n spanning?:\n | MarkSpec['spanning']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']\n editor?: Editor\n }) => MarkSpec['spanning'])\n\n /**\n * Code\n */\n code?:\n | boolean\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['code']\n editor?: Editor\n }) => boolean)\n\n /**\n * Parse HTML\n */\n parseHTML?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']\n editor?: Editor\n }) => MarkSpec['parseDOM']\n\n /**\n * Render HTML\n */\n renderHTML?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']\n editor?: Editor\n },\n props: {\n mark: ProseMirrorMark\n HTMLAttributes: Record<string, any>\n },\n ) => DOMOutputSpec)\n | null\n\n /**\n * Attributes\n */\n addAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']\n editor?: Editor\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n }) => Attributes | {}\n}\n\n/**\n * The Mark class is used to create custom mark extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {\n type = 'mark'\n\n /**\n * Create a new Mark instance\n * @param config - Mark configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>) = {}) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Mark<O, S>(resolvedConfig)\n }\n\n static handleExit({ editor, mark }: { editor: Editor; mark: Mark }) {\n const { tr } = editor.state\n const currentPos = editor.state.selection.$from\n const isAtEnd = currentPos.pos === currentPos.end()\n\n if (isAtEnd) {\n const currentMarks = currentPos.marks()\n const isInMark = !!currentMarks.find(m => m?.type.name === mark.name)\n\n if (!isInMark) {\n return false\n }\n\n const removeMark = currentMarks.find(m => m?.type.name === mark.name)\n\n if (removeMark) {\n tr.removeStoredMark(removeMark)\n }\n tr.insertText(' ', currentPos.pos)\n\n editor.view.dispatch(tr)\n\n return true\n }\n\n return false\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Mark<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig extends MarkConfig<ExtendedOptions, ExtendedStorage> = MarkConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: MarkType\n }>),\n ): Mark<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Mark<ExtendedOptions, ExtendedStorage>\n }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\nimport { Plugin } from '@tiptap/pm/state'\n\nimport { CommandManager } from './CommandManager.js'\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'\nimport { isNumber } from './utilities/isNumber.js'\nimport { isRegExp } from './utilities/isRegExp.js'\n\nexport type PasteRuleMatch = {\n index: number\n text: string\n replaceWith?: string\n match?: RegExpMatchArray\n data?: Record<string, any>\n}\n\nexport type PasteRuleFinder =\n | RegExp\n | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)\n\n/**\n * Paste rules are used to react to pasted content.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport class PasteRule {\n find: PasteRuleFinder\n\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n pasteEvent: ClipboardEvent | null\n dropEvent: DragEvent | null\n }) => void | null\n\n constructor(config: {\n find: PasteRuleFinder\n handler: (props: {\n can: () => CanCommands\n chain: () => ChainedCommands\n commands: SingleCommands\n dropEvent: DragEvent | null\n match: ExtendedRegExpMatchArray\n pasteEvent: ClipboardEvent | null\n range: Range\n state: EditorState\n }) => void | null\n }) {\n this.find = config.find\n this.handler = config.handler\n }\n}\n\nconst pasteRuleMatcherHandler = (\n text: string,\n find: PasteRuleFinder,\n event?: ClipboardEvent | null,\n): ExtendedRegExpMatchArray[] => {\n if (isRegExp(find)) {\n return [...text.matchAll(find)]\n }\n\n const matches = find(text, event)\n\n if (!matches) {\n return []\n }\n\n return matches.map(pasteRuleMatch => {\n const result: ExtendedRegExpMatchArray = [pasteRuleMatch.text]\n\n result.index = pasteRuleMatch.index\n result.input = text\n result.data = pasteRuleMatch.data\n\n if (pasteRuleMatch.replaceWith) {\n if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) {\n console.warn('[tiptap warn]: \"pasteRuleMatch.replaceWith\" must be part of \"pasteRuleMatch.text\".')\n }\n\n result.push(pasteRuleMatch.replaceWith)\n }\n\n return result\n })\n}\n\nfunction run(config: {\n editor: Editor\n state: EditorState\n from: number\n to: number\n rule: PasteRule\n pasteEvent: ClipboardEvent | null\n dropEvent: DragEvent | null\n}): boolean {\n const { editor, state, from, to, rule, pasteEvent, dropEvent } = config\n\n const { commands, chain, can } = new CommandManager({\n editor,\n state,\n })\n\n const handlers: (void | null)[] = []\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n // Skip code blocks and non-textual nodes.\n // Be defensive: `node` may be a Fragment without a `type`. Only text,\n // inline, or textblock nodes are processed by paste rules.\n if (node.type?.spec?.code || !(node.isText || node.isTextblock || node.isInline)) {\n return\n }\n\n // For textblock and inline/text nodes, compute the range relative to the node.\n // Prefer `node.nodeSize` when available (some Node shapes expose this),\n // otherwise fall back to `node.content?.size`. Default to 0 if neither exists.\n const contentSize = node.content?.size ?? node.nodeSize ?? 0\n const resolvedFrom = Math.max(from, pos)\n const resolvedTo = Math.min(to, pos + contentSize)\n\n // If the resolved range is empty or invalid for this node, skip it. This\n // avoids calling `textBetween` with start > end which can cause internal\n // Fragment/Node traversal to access undefined `nodeSize` values.\n if (resolvedFrom >= resolvedTo) {\n return\n }\n\n const textToMatch = node.isText\n ? node.text || ''\n : node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\\ufffc')\n\n const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent)\n\n matches.forEach(match => {\n if (match.index === undefined) {\n return\n }\n\n const start = resolvedFrom + match.index + 1\n const end = start + match[0].length\n const range = {\n from: state.tr.mapping.map(start),\n to: state.tr.mapping.map(end),\n }\n\n const handler = rule.handler({\n state,\n range,\n match,\n commands,\n chain,\n can,\n pasteEvent,\n dropEvent,\n })\n\n handlers.push(handler)\n })\n })\n\n const success = handlers.every(handler => handler !== null)\n\n return success\n}\n\n// When dragging across editors, must get another editor instance to delete selection content.\nlet tiptapDragFromOtherEditor: Editor | null = null\n\nconst createClipboardPasteEvent = (text: string) => {\n const event = new ClipboardEvent('paste', {\n clipboardData: new DataTransfer(),\n })\n\n event.clipboardData?.setData('text/html', text)\n\n return event\n}\n\n/**\n * Create an paste rules plugin. When enabled, it will cause pasted\n * text that matches any of the given rules to trigger the rule’s\n * action.\n */\nexport function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }): Plugin[] {\n const { editor, rules } = props\n let dragSourceElement: Element | null = null\n let isPastedFromProseMirror = false\n let isDroppedFromProseMirror = false\n let pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null\n let dropEvent: DragEvent | null\n\n try {\n dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null\n } catch {\n dropEvent = null\n }\n\n const processEvent = ({\n state,\n from,\n to,\n rule,\n pasteEvt,\n }: {\n state: EditorState\n from: number\n to: { b: number }\n rule: PasteRule\n pasteEvt: ClipboardEvent | null\n }) => {\n const tr = state.tr\n const chainableState = createChainableState({\n state,\n transaction: tr,\n })\n\n const handler = run({\n editor,\n state: chainableState,\n from: Math.max(from - 1, 0),\n to: to.b - 1,\n rule,\n pasteEvent: pasteEvt,\n dropEvent,\n })\n\n if (!handler || !tr.steps.length) {\n return\n }\n\n try {\n dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null\n } catch {\n dropEvent = null\n }\n pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null\n\n return tr\n }\n\n const plugins = rules.map(rule => {\n return new Plugin({\n // we register a global drag handler to track the current drag source element\n view(view) {\n const handleDragstart = (event: DragEvent) => {\n dragSourceElement = view.dom.parentElement?.contains(event.target as Element) ? view.dom.parentElement : null\n\n if (dragSourceElement) {\n tiptapDragFromOtherEditor = editor\n }\n }\n\n const handleDragend = () => {\n if (tiptapDragFromOtherEditor) {\n tiptapDragFromOtherEditor = null\n }\n }\n\n window.addEventListener('dragstart', handleDragstart)\n window.addEventListener('dragend', handleDragend)\n\n return {\n destroy() {\n window.removeEventListener('dragstart', handleDragstart)\n window.removeEventListener('dragend', handleDragend)\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n drop: (view, event: Event) => {\n isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement\n dropEvent = event as DragEvent\n\n if (!isDroppedFromProseMirror) {\n const dragFromOtherEditor = tiptapDragFromOtherEditor\n\n if (dragFromOtherEditor?.isEditable) {\n // setTimeout to avoid the wrong content after drop, timeout arg can't be empty or 0\n setTimeout(() => {\n const selection = dragFromOtherEditor.state.selection\n\n if (selection) {\n dragFromOtherEditor.commands.deleteRange({ from: selection.from, to: selection.to })\n }\n }, 10)\n }\n }\n return false\n },\n\n paste: (_view, event: Event) => {\n const html = (event as ClipboardEvent).clipboardData?.getData('text/html')\n\n pasteEvent = event as ClipboardEvent\n\n isPastedFromProseMirror = !!html?.includes('data-pm-slice')\n\n return false\n },\n },\n },\n\n appendTransaction: (transactions, oldState, state) => {\n const transaction = transactions[0]\n const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror\n const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror\n\n // if PasteRule is triggered by insertContent()\n const simulatedPasteMeta = transaction.getMeta('applyPasteRules') as\n | undefined\n | { from: number; text: string | ProseMirrorNode | Fragment }\n const isSimulatedPaste = !!simulatedPasteMeta\n\n if (!isPaste && !isDrop && !isSimulatedPaste) {\n return\n }\n\n // Handle simulated paste\n if (isSimulatedPaste) {\n let { text } = simulatedPasteMeta\n\n if (typeof text === 'string') {\n text = text as string\n } else {\n text = getHTMLFromFragment(Fragment.from(text), state.schema)\n }\n\n const { from } = simulatedPasteMeta\n const to = from + text.length\n\n const pasteEvt = createClipboardPasteEvent(text)\n\n return processEvent({\n rule,\n state,\n from,\n to: { b: to },\n pasteEvt,\n })\n }\n\n // handle actual paste/drop\n const from = oldState.doc.content.findDiffStart(state.doc.content)\n const to = oldState.doc.content.findDiffEnd(state.doc.content)\n\n // stop if there is no changed range\n if (!isNumber(from) || !to || from === to.b) {\n return\n }\n\n return processEvent({\n rule,\n state,\n from,\n to,\n pasteEvt: pasteEvent,\n })\n },\n })\n })\n\n return plugins\n}\n","export function isNumber(value: any): value is number {\n return typeof value === 'number'\n}\n","export { ClipboardTextSerializer } from './clipboardTextSerializer.js'\nexport { Commands } from './commands.js'\nexport { Delete } from './delete.js'\nexport { Drop } from './drop.js'\nexport { Editable } from './editable.js'\nexport { FocusEvents, focusEventsPluginKey } from './focusEvents.js'\nexport { Keymap } from './keymap.js'\nexport { Paste } from './paste.js'\nexport { Tabindex } from './tabindex.js'\nexport { TextDirection } from './textDirection.js'\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\nimport { getTextBetween } from '../helpers/getTextBetween.js'\nimport { getTextSerializersFromSchema } from '../helpers/getTextSerializersFromSchema.js'\n\nexport type ClipboardTextSerializerOptions = {\n blockSeparator?: string\n}\n\nexport const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerOptions>({\n name: 'clipboardTextSerializer',\n\n addOptions() {\n return {\n blockSeparator: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('clipboardTextSerializer'),\n props: {\n clipboardTextSerializer: () => {\n const { editor } = this\n const { state, schema } = editor\n const { doc, selection } = state\n const { ranges } = selection\n const from = Math.min(...ranges.map(range => range.$from.pos))\n const to = Math.max(...ranges.map(range => range.$to.pos))\n const textSerializers = getTextSerializersFromSchema(schema)\n const range = { from, to }\n\n return getTextBetween(doc, range, {\n ...(this.options.blockSeparator !== undefined ? { blockSeparator: this.options.blockSeparator } : {}),\n textSerializers,\n })\n },\n },\n }),\n ]\n },\n})\n","import type { Editor } from './Editor.js'\nimport { type ExtendableConfig, Extendable } from './Extendable.js'\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface ExtensionConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, ExtensionConfig<Options, Storage>, null> {}\n\n/**\n * The Extension class is the base class for all extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Extension<Options = any, Storage = any> extends Extendable<\n Options,\n Storage,\n ExtensionConfig<Options, Storage>\n> {\n type = 'extension'\n\n /**\n * Create a new Extension instance\n * @param config - Extension configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(\n config: Partial<ExtensionConfig<O, S>> | (() => Partial<ExtensionConfig<O, S>>) = {},\n ) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Extension<O, S>(resolvedConfig)\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Extension<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: null\n }>),\n ): Extension<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Extension<ExtendedOptions, ExtendedStorage>\n }\n}\n","import * as commands from '../commands/index.js'\nimport { Extension } from '../Extension.js'\n\nexport * from '../commands/index.js'\n\nexport const Commands = Extension.create({\n name: 'commands',\n\n addCommands() {\n return {\n ...commands,\n }\n },\n})\n","import { RemoveMarkStep } from '@tiptap/pm/transform'\n\nimport { Extension } from '../Extension.js'\nimport { combineTransactionSteps, getChangedRanges } from '../helpers/index.js'\n\n/**\n * This extension allows you to be notified when the user deletes content you are interested in.\n */\nexport const Delete = Extension.create({\n name: 'delete',\n\n onUpdate({ transaction, appendedTransactions }) {\n const callback = () => {\n if (\n this.editor.options.coreExtensionOptions?.delete?.filterTransaction?.(transaction) ??\n transaction.getMeta('y-sync$')\n ) {\n return\n }\n const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions])\n const changes = getChangedRanges(nextTransaction)\n\n changes.forEach(change => {\n if (\n nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter &&\n nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore\n ) {\n nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from) => {\n const to = from + node.nodeSize - 2\n const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to\n\n this.editor.emit('delete', {\n type: 'node',\n node,\n from,\n to,\n newFrom: nextTransaction.mapping.map(from),\n newTo: nextTransaction.mapping.map(to),\n deletedRange: change.oldRange,\n newRange: change.newRange,\n partial: !isFullyWithinRange,\n editor: this.editor,\n transaction,\n combinedTransform: nextTransaction,\n })\n })\n }\n })\n\n const mapping = nextTransaction.mapping\n nextTransaction.steps.forEach((step, index) => {\n if (step instanceof RemoveMarkStep) {\n const newStart = mapping.slice(index).map(step.from, -1)\n const newEnd = mapping.slice(index).map(step.to)\n const oldStart = mapping.invert().map(newStart, -1)\n const oldEnd = mapping.invert().map(newEnd)\n\n const foundBeforeMark = nextTransaction.doc.nodeAt(newStart - 1)?.marks.some(mark => mark.eq(step.mark))\n const foundAfterMark = nextTransaction.doc.nodeAt(newEnd)?.marks.some(mark => mark.eq(step.mark))\n\n this.editor.emit('delete', {\n type: 'mark',\n mark: step.mark,\n from: step.from,\n to: step.to,\n deletedRange: {\n from: oldStart,\n to: oldEnd,\n },\n newRange: {\n from: newStart,\n to: newEnd,\n },\n partial: Boolean(foundAfterMark || foundBeforeMark),\n editor: this.editor,\n transaction,\n combinedTransform: nextTransaction,\n })\n }\n })\n }\n\n if (this.editor.options.coreExtensionOptions?.delete?.async ?? true) {\n setTimeout(callback, 0)\n } else {\n callback()\n }\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Drop = Extension.create({\n name: 'drop',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tiptapDrop'),\n\n props: {\n handleDrop: (_, e, slice, moved) => {\n this.editor.emit('drop', {\n editor: this.editor,\n event: e,\n slice,\n moved,\n })\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Editable = Extension.create({\n name: 'editable',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('editable'),\n props: {\n editable: () => this.editor.options.editable,\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const focusEventsPluginKey = new PluginKey('focusEvents')\n\nexport const FocusEvents = Extension.create({\n name: 'focusEvents',\n\n addProseMirrorPlugins() {\n const { editor } = this\n\n return [\n new Plugin({\n key: focusEventsPluginKey,\n props: {\n handleDOMEvents: {\n focus: (view, event: Event) => {\n editor.isFocused = true\n\n const transaction = editor.state.tr.setMeta('focus', { event }).setMeta('addToHistory', false)\n\n view.dispatch(transaction)\n\n return false\n },\n blur: (view, event: Event) => {\n editor.isFocused = false\n\n const transaction = editor.state.tr.setMeta('blur', { event }).setMeta('addToHistory', false)\n\n view.dispatch(transaction)\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey, Selection } from '@tiptap/pm/state'\n\nimport { CommandManager } from '../CommandManager.js'\nimport { Extension } from '../Extension.js'\nimport { createChainableState } from '../helpers/createChainableState.js'\nimport { isNodeEmpty } from '../helpers/isNodeEmpty.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isMacOS } from '../utilities/isMacOS.js'\n\nexport const Keymap = Extension.create({\n name: 'keymap',\n\n addKeyboardShortcuts() {\n const handleBackspace = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.undoInputRule(),\n\n // maybe convert first text block node to default node\n () =>\n commands.command(({ tr }) => {\n const { selection, doc } = tr\n const { empty, $anchor } = selection\n const { pos, parent } = $anchor\n const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor\n const parentIsIsolating = $parentPos.parent.type.spec.isolating\n\n const parentPos = $anchor.pos - $anchor.parentOffset\n\n const isAtStart =\n parentIsIsolating && $parentPos.parent.childCount === 1\n ? parentPos === $anchor.pos\n : Selection.atStart(doc).from === pos\n\n if (\n !empty ||\n !parent.type.isTextblock ||\n parent.textContent.length ||\n !isAtStart ||\n (isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended\n ) {\n return false\n }\n\n return commands.clearNodes()\n }),\n\n () => commands.deleteSelection(),\n () => commands.joinBackward(),\n () => commands.selectNodeBackward(),\n ])\n\n const handleDelete = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.deleteSelection(),\n () => commands.deleteCurrentNode(),\n () => commands.joinForward(),\n () => commands.selectNodeForward(),\n ])\n\n const handleEnter = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.newlineInCode(),\n () => commands.createParagraphNear(),\n () => commands.liftEmptyBlock(),\n () => commands.splitBlock(),\n ])\n\n const baseKeymap = {\n Enter: handleEnter,\n 'Mod-Enter': () => this.editor.commands.exitCode(),\n Backspace: handleBackspace,\n 'Mod-Backspace': handleBackspace,\n 'Shift-Backspace': handleBackspace,\n Delete: handleDelete,\n 'Mod-Delete': handleDelete,\n 'Mod-a': () => this.editor.commands.selectAll(),\n }\n\n const pcKeymap = {\n ...baseKeymap,\n }\n\n const macKeymap = {\n ...baseKeymap,\n 'Ctrl-h': handleBackspace,\n 'Alt-Backspace': handleBackspace,\n 'Ctrl-d': handleDelete,\n 'Ctrl-Alt-Backspace': handleDelete,\n 'Alt-Delete': handleDelete,\n 'Alt-d': handleDelete,\n 'Ctrl-a': () => this.editor.commands.selectTextblockStart(),\n 'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),\n }\n\n if (isiOS() || isMacOS()) {\n return macKeymap\n }\n\n return pcKeymap\n },\n\n addProseMirrorPlugins() {\n return [\n // With this plugin we check if the whole document was selected and deleted.\n // In this case we will additionally call `clearNodes()` to convert e.g. a heading\n // to a paragraph if necessary.\n // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well\n // with many other commands.\n new Plugin({\n key: new PluginKey('clearDocument'),\n appendTransaction: (transactions, oldState, newState) => {\n if (transactions.some(tr => tr.getMeta('composition'))) {\n return\n }\n\n const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)\n\n const ignoreTr = transactions.some(transaction => transaction.getMeta('preventClearDocument'))\n\n if (!docChanges || ignoreTr) {\n return\n }\n\n const { empty, from, to } = oldState.selection\n const allFrom = Selection.atStart(oldState.doc).from\n const allEnd = Selection.atEnd(oldState.doc).to\n const allWasSelected = from === allFrom && to === allEnd\n\n if (empty || !allWasSelected) {\n return\n }\n\n const isEmpty = isNodeEmpty(newState.doc)\n\n if (!isEmpty) {\n return\n }\n\n const tr = newState.tr\n const state = createChainableState({\n state: newState,\n transaction: tr,\n })\n const { commands } = new CommandManager({\n editor: this.editor,\n state,\n })\n\n commands.clearNodes()\n\n if (!tr.steps.length) {\n return\n }\n\n return tr\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Paste = Extension.create({\n name: 'paste',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tiptapPaste'),\n\n props: {\n handlePaste: (_view, e, slice) => {\n this.editor.emit('paste', {\n editor: this.editor,\n event: e,\n slice,\n })\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Tabindex = Extension.create({\n name: 'tabindex',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tabindex'),\n props: {\n attributes: (): { [name: string]: string } => (this.editor.isEditable ? { tabindex: '0' } : {}),\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\nimport { splitExtensions } from '../helpers/splitExtensions.js'\n\nexport interface TextDirectionOptions {\n direction: 'ltr' | 'rtl' | 'auto' | undefined\n}\n\n/**\n * The TextDirection extension adds support for setting text direction (LTR/RTL/auto)\n * on all nodes in the editor.\n *\n * This extension adds a global `dir` attribute to all node types, which can be used\n * to control bidirectional text rendering. The direction can be set globally via\n * editor options or per-node using commands.\n */\nexport const TextDirection = Extension.create<TextDirectionOptions>({\n name: 'textDirection',\n\n addOptions() {\n return {\n direction: undefined,\n }\n },\n\n addGlobalAttributes() {\n // Only add the dir attribute to nodes if text direction is configured\n // This prevents null/undefined values from appearing in JSON exports\n if (!this.options.direction) {\n return []\n }\n\n const { nodeExtensions } = splitExtensions(this.extensions)\n\n return [\n {\n types: nodeExtensions.filter(extension => extension.name !== 'text').map(extension => extension.name),\n attributes: {\n dir: {\n default: this.options.direction,\n parseHTML: element => {\n const dir = element.getAttribute('dir')\n\n if (dir && (dir === 'ltr' || dir === 'rtl' || dir === 'auto')) {\n return dir\n }\n\n return this.options.direction\n },\n renderHTML: attributes => {\n if (!attributes.dir) {\n return {}\n }\n\n return {\n dir: attributes.dir,\n }\n },\n },\n },\n },\n ]\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('textDirection'),\n props: {\n attributes: (): { [name: string]: string } => {\n const direction = this.options.direction\n\n if (!direction) {\n return {}\n }\n\n return {\n dir: direction,\n }\n },\n },\n }),\n ]\n },\n})\n","import type { Fragment, Node, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { Content, Range } from './types.js'\n\nexport class NodePos {\n private resolvedPos: ResolvedPos\n\n private isBlock: boolean\n\n private editor: Editor\n\n private get name(): string {\n return this.node.type.name\n }\n\n constructor(pos: ResolvedPos, editor: Editor, isBlock = false, node: Node | null = null) {\n this.isBlock = isBlock\n this.resolvedPos = pos\n this.editor = editor\n this.currentNode = node\n }\n\n private currentNode: Node | null = null\n\n get node(): Node {\n return this.currentNode || this.resolvedPos.node()\n }\n\n get element(): HTMLElement {\n return this.editor.view.domAtPos(this.pos).node as HTMLElement\n }\n\n public actualDepth: number | null = null\n\n get depth(): number {\n return this.actualDepth ?? this.resolvedPos.depth\n }\n\n get pos(): number {\n return this.resolvedPos.pos\n }\n\n get content(): Fragment {\n return this.node.content\n }\n\n set content(content: Content) {\n let from = this.from\n let to = this.to\n\n if (this.isBlock) {\n if (this.content.size === 0) {\n console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`)\n return\n }\n\n from = this.from + 1\n to = this.to - 1\n }\n\n this.editor.commands.insertContentAt({ from, to }, content)\n }\n\n get attributes(): { [key: string]: any } {\n return this.node.attrs\n }\n\n get textContent(): string {\n return this.node.textContent\n }\n\n get size(): number {\n return this.node.nodeSize\n }\n\n get from(): number {\n if (this.isBlock) {\n return this.pos\n }\n\n return this.resolvedPos.start(this.resolvedPos.depth)\n }\n\n get range(): Range {\n return {\n from: this.from,\n to: this.to,\n }\n }\n\n get to(): number {\n if (this.isBlock) {\n return this.pos + this.size\n }\n\n return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1)\n }\n\n get parent(): NodePos | null {\n if (this.depth === 0) {\n return null\n }\n\n const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1)\n const $pos = this.resolvedPos.doc.resolve(parentPos)\n\n return new NodePos($pos, this.editor)\n }\n\n get before(): NodePos | null {\n let $pos = this.resolvedPos.doc.resolve(this.from - (this.isBlock ? 1 : 2))\n\n if ($pos.depth !== this.depth) {\n $pos = this.resolvedPos.doc.resolve(this.from - 3)\n }\n\n return new NodePos($pos, this.editor)\n }\n\n get after(): NodePos | null {\n let $pos = this.resolvedPos.doc.resolve(this.to + (this.isBlock ? 2 : 1))\n\n if ($pos.depth !== this.depth) {\n $pos = this.resolvedPos.doc.resolve(this.to + 3)\n }\n\n return new NodePos($pos, this.editor)\n }\n\n get children(): NodePos[] {\n const children: NodePos[] = []\n\n this.node.content.forEach((node, offset) => {\n const isBlock = node.isBlock && !node.isTextblock\n const isNonTextAtom = node.isAtom && !node.isText\n\n const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)\n\n // Check if targetPos is within valid document range\n if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {\n return\n }\n\n const $pos = this.resolvedPos.doc.resolve(targetPos)\n\n if (!isBlock && $pos.depth <= this.depth) {\n return\n }\n\n const childNodePos = new NodePos($pos, this.editor, isBlock, isBlock ? node : null)\n\n if (isBlock) {\n childNodePos.actualDepth = this.depth + 1\n }\n\n children.push(new NodePos($pos, this.editor, isBlock, isBlock ? node : null))\n })\n\n return children\n }\n\n get firstChild(): NodePos | null {\n return this.children[0] || null\n }\n\n get lastChild(): NodePos | null {\n const children = this.children\n\n return children[children.length - 1] || null\n }\n\n closest(selector: string, attributes: { [key: string]: any } = {}): NodePos | null {\n let node: NodePos | null = null\n let currentNode = this.parent\n\n while (currentNode && !node) {\n if (currentNode.node.type.name === selector) {\n if (Object.keys(attributes).length > 0) {\n const nodeAttributes = currentNode.node.attrs\n const attrKeys = Object.keys(attributes)\n\n for (let index = 0; index < attrKeys.length; index += 1) {\n const key = attrKeys[index]\n\n if (nodeAttributes[key] !== attributes[key]) {\n break\n }\n }\n } else {\n node = currentNode\n }\n }\n\n currentNode = currentNode.parent\n }\n\n return node\n }\n\n querySelector(selector: string, attributes: { [key: string]: any } = {}): NodePos | null {\n return this.querySelectorAll(selector, attributes, true)[0] || null\n }\n\n querySelectorAll(selector: string, attributes: { [key: string]: any } = {}, firstItemOnly = false): NodePos[] {\n let nodes: NodePos[] = []\n\n if (!this.children || this.children.length === 0) {\n return nodes\n }\n const attrKeys = Object.keys(attributes)\n\n /**\n * Finds all children recursively that match the selector and attributes\n * If firstItemOnly is true, it will return the first item found\n */\n this.children.forEach(childPos => {\n // If we already found a node and we only want the first item, we dont need to keep going\n if (firstItemOnly && nodes.length > 0) {\n return\n }\n\n if (childPos.node.type.name === selector) {\n const doesAllAttributesMatch = attrKeys.every(key => attributes[key] === childPos.node.attrs[key])\n\n if (doesAllAttributesMatch) {\n nodes.push(childPos)\n }\n }\n\n // If we already found a node and we only want the first item, we can stop here and skip the recursion\n if (firstItemOnly && nodes.length > 0) {\n return\n }\n\n nodes = nodes.concat(childPos.querySelectorAll(selector, attributes, firstItemOnly))\n })\n\n return nodes\n }\n\n setAttribute(attributes: { [key: string]: any }) {\n const { tr } = this.editor.state\n\n tr.setNodeMarkup(this.from, undefined, {\n ...this.node.attrs,\n ...attributes,\n })\n\n this.editor.view.dispatch(tr)\n }\n}\n","export const style = `.ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n font-feature-settings: \"liga\" 0; /* the above doesn't seem to work in Edge */\n}\n\n.ProseMirror [contenteditable=\"false\"] {\n white-space: normal;\n}\n\n.ProseMirror [contenteditable=\"false\"] [contenteditable=\"true\"] {\n white-space: pre-wrap;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\nimg.ProseMirror-separator {\n display: inline !important;\n border: none !important;\n margin: 0 !important;\n width: 0 !important;\n height: 0 !important;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n margin: 0;\n}\n\n.ProseMirror-gapcursor:after {\n content: \"\";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}`\n","export function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement {\n const tiptapStyleTag = <HTMLStyleElement>(\n document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`)\n )\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarksBetween } from '../helpers/getMarksBetween.js'\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that adds a mark when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function markInputRule(config: {\n find: InputRuleFinder\n type: MarkType\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const { tr } = state\n const captureGroup = match[match.length - 1]\n const fullMatch = match[0]\n\n if (captureGroup) {\n const startSpaces = fullMatch.search(/\\S/)\n const textStart = range.from + fullMatch.indexOf(captureGroup)\n const textEnd = textStart + captureGroup.length\n\n const excludedMarks = getMarksBetween(range.from, range.to, state.doc)\n .filter(item => {\n // @ts-ignore\n const excluded = item.mark.type.excluded as MarkType[]\n\n return excluded.find(type => type === config.type && type !== item.mark.type)\n })\n .filter(item => item.to > textStart)\n\n if (excludedMarks.length) {\n return null\n }\n\n if (textEnd < range.to) {\n tr.delete(textEnd, range.to)\n }\n\n if (textStart > range.from) {\n tr.delete(range.from + startSpaces, textStart)\n }\n\n const markEnd = range.from + startSpaces + captureGroup.length\n\n tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}))\n\n tr.removeStoredMark(config.type)\n }\n },\n undoable: config.undoable,\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that adds a node when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function nodeInputRule(config: {\n /**\n * The regex to match.\n */\n find: InputRuleFinder\n\n /**\n * The node type to add.\n */\n type: NodeType\n\n /**\n * Whether the input rule should be undoable\n * when the user presses backspace.\n */\n undoable?: boolean\n\n /**\n * A function that returns the attributes for the node\n * can also be an object of attributes\n */\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n const { tr } = state\n const start = range.from\n let end = range.to\n\n const newNode = config.type.create(attributes)\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n let matchStart = start + offset\n\n if (matchStart > end) {\n matchStart = end\n } else {\n end = matchStart + match[1].length\n }\n\n // insert last typed character\n const lastChar = match[0][match[0].length - 1]\n\n tr.insertText(lastChar, start + match[0].length - 1)\n\n // insert node from input rule\n tr.replaceWith(matchStart, end, newNode)\n } else if (match[0]) {\n const insertionStart = config.type.isInline ? start : start - 1\n\n tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end))\n }\n\n tr.scrollIntoView()\n },\n undoable: config.undoable,\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that changes the type of a textblock when the\n * matched text is typed into it. When using a regular expresion you’ll\n * probably want the regexp to start with `^`, so that the pattern can\n * only occur at the start of a textblock.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function textblockTypeInputRule(config: {\n find: InputRuleFinder\n type: NodeType\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const $start = state.doc.resolve(range.from)\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n\n if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), config.type)) {\n return null\n }\n\n state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes)\n },\n undoable: config.undoable,\n })\n}\n","import type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\n\n/**\n * Build an input rule that replaces text when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function textInputRule(config: { find: InputRuleFinder; replace: string; undoable?: boolean }) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n let insert = config.replace\n let start = range.from\n const end = range.to\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n\n insert += match[0].slice(offset + match[1].length)\n start += offset\n\n const cutOff = start - end\n\n if (cutOff > 0) {\n insert = match[0].slice(offset - cutOff, offset) + insert\n start = end\n }\n }\n\n state.tr.insertText(insert, start, end)\n },\n undoable: config.undoable,\n })\n}\n","import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'\nimport { canJoin, findWrapping } from '@tiptap/pm/transform'\n\nimport type { Editor } from '../Editor.js'\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule for automatically wrapping a textblock when a\n * given string is typed. When using a regular expresion you’ll\n * probably want the regexp to start with `^`, so that the pattern can\n * only occur at the start of a textblock.\n *\n * `type` is the type of node to wrap in.\n *\n * By default, if there’s a node with the same type above the newly\n * wrapped node, the rule will try to join those\n * two nodes. You can pass a join predicate, which takes a regular\n * expression match and the node before the wrapped node, and can\n * return a boolean to indicate whether a join should happen.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function wrappingInputRule(config: {\n find: InputRuleFinder\n type: NodeType\n keepMarks?: boolean\n keepAttributes?: boolean\n editor?: Editor\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match, chain }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n const tr = state.tr.delete(range.from, range.to)\n const $start = tr.doc.resolve(range.from)\n const blockRange = $start.blockRange()\n const wrapping = blockRange && findWrapping(blockRange, config.type, attributes)\n\n if (!wrapping) {\n return null\n }\n\n tr.wrap(blockRange, wrapping)\n\n if (config.keepMarks && config.editor) {\n const { selection, storedMarks } = state\n const { splittableMarks } = config.editor.extensionManager\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n if (marks) {\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n }\n }\n if (config.keepAttributes) {\n /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */\n const nodeType =\n config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList'\n\n chain().updateAttributes(nodeType, attributes).run()\n }\n\n const before = tr.doc.resolve(range.from - 1).nodeBefore\n\n if (\n before &&\n before.type === config.type &&\n canJoin(tr.doc, range.from - 1) &&\n (!config.joinPredicate || config.joinPredicate(match, before))\n ) {\n tr.join(range.from - 1)\n }\n },\n undoable: config.undoable,\n })\n}\n","export type Attributes = Record<string, any>\n\nexport type DOMOutputSpecElement = 0 | Attributes | DOMOutputSpecArray\n/**\n * Better describes the output of a `renderHTML` function in prosemirror\n * @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec\n */\nexport type DOMOutputSpecArray =\n | [string]\n | [string, Attributes]\n | [string, 0]\n | [string, Attributes, 0]\n | [string, Attributes, DOMOutputSpecArray | 0]\n | [string, DOMOutputSpecArray]\n\n// JSX types for Tiptap's JSX runtime\n// These types only apply when using @jsxImportSource @tiptap/core\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace JSX {\n export type Element = DOMOutputSpecArray\n export interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n }\n export interface ElementChildrenAttribute {\n children: unknown\n }\n}\n\nexport type JSXRenderer = (\n tag: 'slot' | string | ((props?: Attributes) => DOMOutputSpecArray | DOMOutputSpecElement),\n props?: Attributes,\n ...children: JSXRenderer[]\n) => DOMOutputSpecArray | DOMOutputSpecElement\n\nexport function Fragment(props: { children: JSXRenderer[] }) {\n return props.children\n}\n\nexport const h: JSXRenderer = (tag, attributes) => {\n // Treat the slot tag as the Prosemirror hole to render content into\n if (tag === 'slot') {\n return 0\n }\n\n // If the tag is a function, call it with the props\n if (tag instanceof Function) {\n return tag(attributes)\n }\n\n const { children, ...rest } = attributes ?? {}\n\n if (tag === 'svg') {\n throw new Error('SVG elements are not supported in the JSX syntax, use the array syntax instead')\n }\n\n // Otherwise, return the tag, attributes, and children\n return [tag, rest, children]\n}\n\n// See\n// https://esbuild.github.io/api/#jsx-import-source\n// https://www.typescriptlang.org/tsconfig/#jsxImportSource\n\nexport { h as createElement, h as jsx, h as jsxDEV, h as jsxs }\n","import type { Node as PMNode } from '@tiptap/pm/model'\nimport type { Decoration, DecorationSource, NodeView } from '@tiptap/pm/view'\n\nimport type { Editor } from '../Editor.js'\n\nconst isTouchEvent = (e: MouseEvent | TouchEvent): e is TouchEvent => {\n return 'touches' in e\n}\n\n/**\n * Directions where resize handles can be placed\n *\n * @example\n * - `'top'` - Top edge handle\n * - `'bottom-right'` - Bottom-right corner handle\n */\nexport type ResizableNodeViewDirection =\n | 'top'\n | 'right'\n | 'bottom'\n | 'left'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-left'\n\n/**\n * Dimensions for the resizable node in pixels\n */\nexport type ResizableNodeDimensions = {\n /** Width in pixels */\n width: number\n /** Height in pixels */\n height: number\n}\n\n/**\n * Configuration options for creating a ResizableNodeView\n *\n * @example\n * ```ts\n * new ResizableNodeView({\n * element: imgElement,\n * node,\n * getPos,\n * onResize: (width, height) => {\n * imgElement.style.width = `${width}px`\n * imgElement.style.height = `${height}px`\n * },\n * onCommit: (width, height) => {\n * editor.commands.updateAttributes('image', { width, height })\n * },\n * onUpdate: (node) => true,\n * options: {\n * directions: ['bottom-right', 'bottom-left'],\n * min: { width: 100, height: 100 },\n * preserveAspectRatio: true\n * }\n * })\n * ```\n */\nexport type ResizableNodeViewOptions = {\n /**\n * The DOM element to make resizable (e.g., an img, video, or iframe element)\n */\n element: HTMLElement\n\n /**\n * The DOM element that will hold the editable content element\n */\n contentElement?: HTMLElement\n\n /**\n * The ProseMirror node instance\n */\n node: PMNode\n\n /**\n * The Tiptap editor instance\n */\n editor: Editor\n\n /**\n * Function that returns the current position of the node in the document\n */\n getPos: () => number | undefined\n\n /**\n * Callback fired continuously during resize with current dimensions.\n * Use this to update the element's visual size in real-time.\n *\n * @param width - Current width in pixels\n * @param height - Current height in pixels\n *\n * @example\n * ```ts\n * onResize: (width, height) => {\n * element.style.width = `${width}px`\n * element.style.height = `${height}px`\n * }\n * ```\n */\n onResize?: (width: number, height: number) => void\n\n /**\n * Callback fired once when resize completes with final dimensions.\n * Use this to persist the new size to the node's attributes.\n *\n * @param width - Final width in pixels\n * @param height - Final height in pixels\n *\n * @example\n * ```ts\n * onCommit: (width, height) => {\n * const pos = getPos()\n * if (pos !== undefined) {\n * editor.commands.updateAttributes('image', { width, height })\n * }\n * }\n * ```\n */\n onCommit: (width: number, height: number) => void\n\n /**\n * Callback for handling node updates.\n * Return `true` to accept the update, `false` to reject it.\n *\n * @example\n * ```ts\n * onUpdate: (node, decorations, innerDecorations) => {\n * if (node.type !== this.node.type) return false\n * return true\n * }\n * ```\n */\n onUpdate: NodeView['update']\n\n /**\n * Optional configuration for resize behavior and styling\n */\n options?: {\n /**\n * Which resize handles to display.\n * @default ['bottom-left', 'bottom-right', 'top-left', 'top-right']\n *\n * @example\n * ```ts\n * // Only show corner handles\n * directions: ['top-left', 'top-right', 'bottom-left', 'bottom-right']\n *\n * // Only show right edge handle\n * directions: ['right']\n * ```\n */\n directions?: ResizableNodeViewDirection[]\n\n /**\n * Minimum dimensions in pixels\n * @default { width: 8, height: 8 }\n *\n * @example\n * ```ts\n * min: { width: 100, height: 50 }\n * ```\n */\n min?: Partial<ResizableNodeDimensions>\n\n /**\n * Maximum dimensions in pixels\n * @default undefined (no maximum)\n *\n * @example\n * ```ts\n * max: { width: 1000, height: 800 }\n * ```\n */\n max?: Partial<ResizableNodeDimensions>\n\n /**\n * Always preserve aspect ratio when resizing.\n * When `false`, aspect ratio is preserved only when Shift key is pressed.\n * @default false\n *\n * @example\n * ```ts\n * preserveAspectRatio: true // Always lock aspect ratio\n * ```\n */\n preserveAspectRatio?: boolean\n\n /**\n * Custom CSS class names for styling\n *\n * @example\n * ```ts\n * className: {\n * container: 'resize-container',\n * wrapper: 'resize-wrapper',\n * handle: 'resize-handle',\n * resizing: 'is-resizing'\n * }\n * ```\n */\n className?: {\n /** Class for the outer container element */\n container?: string\n /** Class for the wrapper element that contains the resizable element */\n wrapper?: string\n /** Class applied to all resize handles */\n handle?: string\n /** Class added to container while actively resizing */\n resizing?: string\n }\n\n /**\n * Optional callback for creating custom resize handle elements.\n *\n * This function allows developers to define their own handle element\n * (e.g., custom icons, classes, or styles) for a given resize direction.\n * It is called internally for each handle direction.\n *\n * @param direction - The direction of the handle being created (e.g., 'top', 'bottom-right').\n * @returns The custom handle HTMLElement.\n *\n * @example\n * ```ts\n * createCustomHandle: (direction) => {\n * const handle = document.createElement('div')\n * handle.dataset.resizeHandle = direction\n * handle.style.position = 'absolute'\n * handle.className = 'tiptap-custom-handle'\n *\n * const isTop = direction.includes('top')\n * const isBottom = direction.includes('bottom')\n * const isLeft = direction.includes('left')\n * const isRight = direction.includes('right')\n *\n * if (isTop) handle.style.top = '0'\n * if (isBottom) handle.style.bottom = '0'\n * if (isLeft) handle.style.left = '0'\n * if (isRight) handle.style.right = '0'\n *\n * // Edge handles span the full width or height\n * if (direction === 'top' || direction === 'bottom') {\n * handle.style.left = '0'\n * handle.style.right = '0'\n * }\n *\n * if (direction === 'left' || direction === 'right') {\n * handle.style.top = '0'\n * handle.style.bottom = '0'\n * }\n *\n * return handle\n * }\n * ```\n */\n createCustomHandle?: (direction: ResizableNodeViewDirection) => HTMLElement\n }\n}\n\n/**\n * A NodeView implementation that adds resize handles to any DOM element.\n *\n * This class creates a resizable node view for Tiptap/ProseMirror editors.\n * It wraps your element with resize handles and manages the resize interaction,\n * including aspect ratio preservation, min/max constraints, and keyboard modifiers.\n *\n * @example\n * ```ts\n * // Basic usage in a Tiptap extension\n * addNodeView() {\n * return ({ node, getPos }) => {\n * const img = document.createElement('img')\n * img.src = node.attrs.src\n *\n * return new ResizableNodeView({\n * element: img,\n * node,\n * getPos,\n * onResize: (width, height) => {\n * img.style.width = `${width}px`\n * img.style.height = `${height}px`\n * },\n * onCommit: (width, height) => {\n * this.editor.commands.updateAttributes('image', { width, height })\n * },\n * onUpdate: () => true,\n * options: {\n * min: { width: 100, height: 100 },\n * preserveAspectRatio: true\n * }\n * })\n * }\n * }\n * ```\n */\nexport class ResizableNodeView {\n /** The ProseMirror node instance */\n node: PMNode\n\n /** The Tiptap editor instance */\n editor: Editor\n\n /** The DOM element being made resizable */\n element: HTMLElement\n\n /** The editable DOM element inside the DOM */\n contentElement?: HTMLElement\n\n /** The outer container element (returned as NodeView.dom) */\n container: HTMLElement\n\n /** The wrapper element that contains the element and handles */\n wrapper: HTMLElement\n\n /** Function to get the current node position */\n getPos: () => number | undefined\n\n /** Callback fired during resize */\n onResize?: (width: number, height: number) => void\n\n /** Callback fired when resize completes */\n onCommit: (width: number, height: number) => void\n\n /** Callback for node updates */\n onUpdate?: NodeView['update']\n\n /** Active resize handle directions */\n directions: ResizableNodeViewDirection[] = ['bottom-left', 'bottom-right', 'top-left', 'top-right']\n\n /** Minimum allowed dimensions */\n minSize: ResizableNodeDimensions = {\n height: 8,\n width: 8,\n }\n\n /** Maximum allowed dimensions (optional) */\n maxSize?: Partial<ResizableNodeDimensions>\n\n /** Whether to always preserve aspect ratio */\n preserveAspectRatio: boolean = false\n\n /** CSS class names for elements */\n classNames = {\n container: '',\n wrapper: '',\n handle: '',\n resizing: '',\n }\n\n /** Optional callback for creating custom resize handles */\n createCustomHandle?: (direction: ResizableNodeViewDirection) => HTMLElement\n\n /** Initial width of the element (for aspect ratio calculation) */\n private initialWidth: number = 0\n\n /** Initial height of the element (for aspect ratio calculation) */\n private initialHeight: number = 0\n\n /** Calculated aspect ratio (width / height) */\n private aspectRatio: number = 1\n\n /** Whether a resize operation is currently active */\n private isResizing: boolean = false\n\n /** The handle currently being dragged */\n private activeHandle: ResizableNodeViewDirection | null = null\n\n /** Starting mouse X position when resize began */\n private startX: number = 0\n\n /** Starting mouse Y position when resize began */\n private startY: number = 0\n\n /** Element width when resize began */\n private startWidth: number = 0\n\n /** Element height when resize began */\n private startHeight: number = 0\n\n /** Whether Shift key is currently pressed (for temporary aspect ratio lock) */\n private isShiftKeyPressed: boolean = false\n\n /** Last known editable state of the editor */\n private lastEditableState: boolean | undefined = undefined\n\n /** Map of handle elements by direction */\n private handleMap = new Map<ResizableNodeViewDirection, HTMLElement>()\n\n /**\n * Creates a new ResizableNodeView instance.\n *\n * The constructor sets up the resize handles, applies initial sizing from\n * node attributes, and configures all resize behavior options.\n *\n * @param options - Configuration options for the resizable node view\n */\n constructor(options: ResizableNodeViewOptions) {\n this.node = options.node\n this.editor = options.editor\n this.element = options.element\n this.contentElement = options.contentElement\n\n this.getPos = options.getPos\n\n this.onResize = options.onResize\n this.onCommit = options.onCommit\n this.onUpdate = options.onUpdate\n\n if (options.options?.min) {\n this.minSize = {\n ...this.minSize,\n ...options.options.min,\n }\n }\n\n if (options.options?.max) {\n this.maxSize = options.options.max\n }\n\n if (options?.options?.directions) {\n this.directions = options.options.directions\n }\n\n if (options.options?.preserveAspectRatio) {\n this.preserveAspectRatio = options.options.preserveAspectRatio\n }\n\n if (options.options?.className) {\n this.classNames = {\n container: options.options.className.container || '',\n wrapper: options.options.className.wrapper || '',\n handle: options.options.className.handle || '',\n resizing: options.options.className.resizing || '',\n }\n }\n\n if (options.options?.createCustomHandle) {\n this.createCustomHandle = options.options.createCustomHandle\n }\n\n this.wrapper = this.createWrapper()\n this.container = this.createContainer()\n\n this.applyInitialSize()\n this.attachHandles()\n\n this.editor.on('update', this.handleEditorUpdate.bind(this))\n }\n\n /**\n * Returns the top-level DOM node that should be placed in the editor.\n *\n * This is required by the ProseMirror NodeView interface. The container\n * includes the wrapper, handles, and the actual content element.\n *\n * @returns The container element to be inserted into the editor\n */\n get dom() {\n return this.container\n }\n\n get contentDOM() {\n return this.contentElement\n }\n\n private handleEditorUpdate() {\n const isEditable = this.editor.isEditable\n\n // Only if state actually changed\n if (isEditable === this.lastEditableState) {\n return\n }\n\n this.lastEditableState = isEditable\n\n if (!isEditable) {\n this.removeHandles()\n } else if (isEditable && this.handleMap.size === 0) {\n this.attachHandles()\n }\n }\n\n /**\n * Called when the node's content or attributes change.\n *\n * Updates the internal node reference. If a custom `onUpdate` callback\n * was provided, it will be called to handle additional update logic.\n *\n * @param node - The new/updated node\n * @param decorations - Node decorations\n * @param innerDecorations - Inner decorations\n * @returns `false` if the node type has changed (requires full rebuild), otherwise the result of `onUpdate` or `true`\n */\n update(node: PMNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n\n if (this.onUpdate) {\n return this.onUpdate(node, decorations, innerDecorations)\n }\n\n return true\n }\n\n /**\n * Cleanup method called when the node view is being removed.\n *\n * Removes all event listeners to prevent memory leaks. This is required\n * by the ProseMirror NodeView interface. If a resize is active when\n * destroy is called, it will be properly cancelled.\n */\n destroy() {\n if (this.isResizing) {\n this.container.dataset.resizeState = 'false'\n\n if (this.classNames.resizing) {\n this.container.classList.remove(this.classNames.resizing)\n }\n\n document.removeEventListener('mousemove', this.handleMouseMove)\n document.removeEventListener('mouseup', this.handleMouseUp)\n document.removeEventListener('keydown', this.handleKeyDown)\n document.removeEventListener('keyup', this.handleKeyUp)\n this.isResizing = false\n this.activeHandle = null\n }\n\n this.editor.off('update', this.handleEditorUpdate.bind(this))\n\n this.container.remove()\n }\n\n /**\n * Creates the outer container element.\n *\n * The container is the top-level element returned by the NodeView and\n * wraps the entire resizable node. It's set up with flexbox to handle\n * alignment and includes data attributes for styling and identification.\n *\n * @returns The container element\n */\n createContainer() {\n const element = document.createElement('div')\n element.dataset.resizeContainer = ''\n element.dataset.node = this.node.type.name\n element.style.display = 'flex'\n\n if (this.classNames.container) {\n element.className = this.classNames.container\n }\n\n element.appendChild(this.wrapper)\n\n return element\n }\n\n /**\n * Creates the wrapper element that contains the content and handles.\n *\n * The wrapper uses relative positioning so that resize handles can be\n * positioned absolutely within it. This is the direct parent of the\n * content element being made resizable.\n *\n * @returns The wrapper element\n */\n createWrapper() {\n const element = document.createElement('div')\n element.style.position = 'relative'\n element.style.display = 'block'\n element.dataset.resizeWrapper = ''\n\n if (this.classNames.wrapper) {\n element.className = this.classNames.wrapper\n }\n\n element.appendChild(this.element)\n\n return element\n }\n\n /**\n * Creates a resize handle element for a specific direction.\n *\n * Each handle is absolutely positioned and includes a data attribute\n * identifying its direction for styling purposes.\n *\n * @param direction - The resize direction for this handle\n * @returns The handle element\n */\n private createHandle(direction: ResizableNodeViewDirection): HTMLElement {\n const handle = document.createElement('div')\n handle.dataset.resizeHandle = direction\n handle.style.position = 'absolute'\n\n if (this.classNames.handle) {\n handle.className = this.classNames.handle\n }\n\n return handle\n }\n\n /**\n * Positions a handle element according to its direction.\n *\n * Corner handles (e.g., 'top-left') are positioned at the intersection\n * of two edges. Edge handles (e.g., 'top') span the full width or height.\n *\n * @param handle - The handle element to position\n * @param direction - The direction determining the position\n */\n private positionHandle(handle: HTMLElement, direction: ResizableNodeViewDirection): void {\n const isTop = direction.includes('top')\n const isBottom = direction.includes('bottom')\n const isLeft = direction.includes('left')\n const isRight = direction.includes('right')\n\n if (isTop) {\n handle.style.top = '0'\n }\n\n if (isBottom) {\n handle.style.bottom = '0'\n }\n\n if (isLeft) {\n handle.style.left = '0'\n }\n\n if (isRight) {\n handle.style.right = '0'\n }\n\n // Edge handles span the full width or height\n if (direction === 'top' || direction === 'bottom') {\n handle.style.left = '0'\n handle.style.right = '0'\n }\n\n if (direction === 'left' || direction === 'right') {\n handle.style.top = '0'\n handle.style.bottom = '0'\n }\n }\n\n /**\n * Creates and attaches all resize handles to the wrapper.\n *\n * Iterates through the configured directions, creates a handle for each,\n * positions it, attaches the mousedown listener, and appends it to the DOM.\n */\n private attachHandles(): void {\n this.directions.forEach(direction => {\n let handle: HTMLElement\n\n if (this.createCustomHandle) {\n handle = this.createCustomHandle(direction)\n } else {\n handle = this.createHandle(direction)\n }\n\n if (!(handle instanceof HTMLElement)) {\n console.warn(\n `[ResizableNodeView] createCustomHandle(\"${direction}\") did not return an HTMLElement. Falling back to default handle.`,\n )\n handle = this.createHandle(direction)\n }\n\n if (!this.createCustomHandle) {\n this.positionHandle(handle, direction)\n }\n\n handle.addEventListener('mousedown', event => this.handleResizeStart(event, direction))\n handle.addEventListener('touchstart', event => this.handleResizeStart(event as unknown as MouseEvent, direction))\n\n this.handleMap.set(direction, handle)\n\n this.wrapper.appendChild(handle)\n })\n }\n\n /**\n * Removes all resize handles from the wrapper.\n *\n * Cleans up the handle map and removes each handle element from the DOM.\n */\n private removeHandles(): void {\n this.handleMap.forEach(el => el.remove())\n this.handleMap.clear()\n }\n\n /**\n * Applies initial sizing from node attributes to the element.\n *\n * If width/height attributes exist on the node, they're applied to the element.\n * Otherwise, the element's natural/current dimensions are measured. The aspect\n * ratio is calculated for later use in aspect-ratio-preserving resizes.\n */\n private applyInitialSize(): void {\n const width = this.node.attrs.width as number | undefined\n const height = this.node.attrs.height as number | undefined\n\n if (width) {\n this.element.style.width = `${width}px`\n this.initialWidth = width\n } else {\n this.initialWidth = this.element.offsetWidth\n }\n\n if (height) {\n this.element.style.height = `${height}px`\n this.initialHeight = height\n } else {\n this.initialHeight = this.element.offsetHeight\n }\n\n // Calculate aspect ratio for use during resizing\n if (this.initialWidth > 0 && this.initialHeight > 0) {\n this.aspectRatio = this.initialWidth / this.initialHeight\n }\n }\n\n /**\n * Initiates a resize operation when a handle is clicked.\n *\n * Captures the starting mouse position and element dimensions, sets up\n * the resize state, adds the resizing class and state attribute, and\n * attaches document-level listeners for mouse movement and keyboard input.\n *\n * @param event - The mouse down event\n * @param direction - The direction of the handle being dragged\n */\n private handleResizeStart(event: MouseEvent | TouchEvent, direction: ResizableNodeViewDirection): void {\n event.preventDefault()\n event.stopPropagation()\n\n // Capture initial state\n this.isResizing = true\n this.activeHandle = direction\n\n if (isTouchEvent(event)) {\n this.startX = event.touches[0].clientX\n this.startY = event.touches[0].clientY\n } else {\n this.startX = event.clientX\n this.startY = event.clientY\n }\n\n this.startWidth = this.element.offsetWidth\n this.startHeight = this.element.offsetHeight\n\n // Recalculate aspect ratio at resize start for accuracy\n if (this.startWidth > 0 && this.startHeight > 0) {\n this.aspectRatio = this.startWidth / this.startHeight\n }\n\n const pos = this.getPos()\n if (pos !== undefined) {\n // TODO: Select the node in the editor\n }\n\n // Update UI state\n this.container.dataset.resizeState = 'true'\n\n if (this.classNames.resizing) {\n this.container.classList.add(this.classNames.resizing)\n }\n\n // Attach document-level listeners for resize\n document.addEventListener('mousemove', this.handleMouseMove)\n document.addEventListener('touchmove', this.handleTouchMove)\n document.addEventListener('mouseup', this.handleMouseUp)\n document.addEventListener('keydown', this.handleKeyDown)\n document.addEventListener('keyup', this.handleKeyUp)\n }\n\n /**\n * Handles mouse movement during an active resize.\n *\n * Calculates the delta from the starting position, computes new dimensions\n * based on the active handle direction, applies constraints and aspect ratio,\n * then updates the element's style and calls the onResize callback.\n *\n * @param event - The mouse move event\n */\n private handleMouseMove = (event: MouseEvent): void => {\n if (!this.isResizing || !this.activeHandle) {\n return\n }\n\n const deltaX = event.clientX - this.startX\n const deltaY = event.clientY - this.startY\n\n this.handleResize(deltaX, deltaY)\n }\n\n private handleTouchMove = (event: TouchEvent): void => {\n if (!this.isResizing || !this.activeHandle) {\n return\n }\n\n const touch = event.touches[0]\n if (!touch) {\n return\n }\n\n const deltaX = touch.clientX - this.startX\n const deltaY = touch.clientY - this.startY\n\n this.handleResize(deltaX, deltaY)\n }\n\n private handleResize(deltaX: number, deltaY: number) {\n if (!this.activeHandle) {\n return\n }\n\n const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed\n const { width, height } = this.calculateNewDimensions(this.activeHandle, deltaX, deltaY)\n const constrained = this.applyConstraints(width, height, shouldPreserveAspectRatio)\n\n this.element.style.width = `${constrained.width}px`\n this.element.style.height = `${constrained.height}px`\n\n if (this.onResize) {\n this.onResize(constrained.width, constrained.height)\n }\n }\n\n /**\n * Completes the resize operation when the mouse button is released.\n *\n * Captures final dimensions, calls the onCommit callback to persist changes,\n * removes the resizing state and class, and cleans up document-level listeners.\n */\n private handleMouseUp = (): void => {\n if (!this.isResizing) {\n return\n }\n\n const finalWidth = this.element.offsetWidth\n const finalHeight = this.element.offsetHeight\n\n this.onCommit(finalWidth, finalHeight)\n\n this.isResizing = false\n this.activeHandle = null\n\n // Remove UI state\n this.container.dataset.resizeState = 'false'\n\n if (this.classNames.resizing) {\n this.container.classList.remove(this.classNames.resizing)\n }\n\n // Clean up document-level listeners\n document.removeEventListener('mousemove', this.handleMouseMove)\n document.removeEventListener('mouseup', this.handleMouseUp)\n document.removeEventListener('keydown', this.handleKeyDown)\n document.removeEventListener('keyup', this.handleKeyUp)\n }\n\n /**\n * Tracks Shift key state to enable temporary aspect ratio locking.\n *\n * When Shift is pressed during resize, aspect ratio is preserved even if\n * preserveAspectRatio is false.\n *\n * @param event - The keyboard event\n */\n private handleKeyDown = (event: KeyboardEvent): void => {\n if (event.key === 'Shift') {\n this.isShiftKeyPressed = true\n }\n }\n\n /**\n * Tracks Shift key release to disable temporary aspect ratio locking.\n *\n * @param event - The keyboard event\n */\n private handleKeyUp = (event: KeyboardEvent): void => {\n if (event.key === 'Shift') {\n this.isShiftKeyPressed = false\n }\n }\n\n /**\n * Calculates new dimensions based on mouse delta and resize direction.\n *\n * Takes the starting dimensions and applies the mouse movement delta\n * according to the handle direction. For corner handles, both dimensions\n * are affected. For edge handles, only one dimension changes. If aspect\n * ratio should be preserved, delegates to applyAspectRatio.\n *\n * @param direction - The active resize handle direction\n * @param deltaX - Horizontal mouse movement since resize start\n * @param deltaY - Vertical mouse movement since resize start\n * @returns The calculated width and height\n */\n private calculateNewDimensions(\n direction: ResizableNodeViewDirection,\n deltaX: number,\n deltaY: number,\n ): ResizableNodeDimensions {\n let newWidth = this.startWidth\n let newHeight = this.startHeight\n\n const isRight = direction.includes('right')\n const isLeft = direction.includes('left')\n const isBottom = direction.includes('bottom')\n const isTop = direction.includes('top')\n\n // Apply horizontal delta\n if (isRight) {\n newWidth = this.startWidth + deltaX\n } else if (isLeft) {\n newWidth = this.startWidth - deltaX\n }\n\n // Apply vertical delta\n if (isBottom) {\n newHeight = this.startHeight + deltaY\n } else if (isTop) {\n newHeight = this.startHeight - deltaY\n }\n\n // For pure horizontal/vertical handles, only one dimension changes\n if (direction === 'right' || direction === 'left') {\n newWidth = this.startWidth + (isRight ? deltaX : -deltaX)\n }\n\n if (direction === 'top' || direction === 'bottom') {\n newHeight = this.startHeight + (isBottom ? deltaY : -deltaY)\n }\n\n const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed\n\n if (shouldPreserveAspectRatio) {\n return this.applyAspectRatio(newWidth, newHeight, direction)\n }\n\n return { width: newWidth, height: newHeight }\n }\n\n /**\n * Applies min/max constraints to dimensions.\n *\n * When aspect ratio is NOT preserved, constraints are applied independently\n * to width and height. When aspect ratio IS preserved, constraints are\n * applied while maintaining the aspect ratio—if one dimension hits a limit,\n * the other is recalculated proportionally.\n *\n * This ensures that aspect ratio is never broken when constrained.\n *\n * @param width - The unconstrained width\n * @param height - The unconstrained height\n * @param preserveAspectRatio - Whether to maintain aspect ratio while constraining\n * @returns The constrained dimensions\n */\n private applyConstraints(width: number, height: number, preserveAspectRatio: boolean): ResizableNodeDimensions {\n if (!preserveAspectRatio) {\n // Independent constraints for each dimension\n let constrainedWidth = Math.max(this.minSize.width, width)\n let constrainedHeight = Math.max(this.minSize.height, height)\n\n if (this.maxSize?.width) {\n constrainedWidth = Math.min(this.maxSize.width, constrainedWidth)\n }\n\n if (this.maxSize?.height) {\n constrainedHeight = Math.min(this.maxSize.height, constrainedHeight)\n }\n\n return { width: constrainedWidth, height: constrainedHeight }\n }\n\n // Aspect-ratio-aware constraints: adjust both dimensions proportionally\n let constrainedWidth = width\n let constrainedHeight = height\n\n // Check minimum constraints\n if (constrainedWidth < this.minSize.width) {\n constrainedWidth = this.minSize.width\n constrainedHeight = constrainedWidth / this.aspectRatio\n }\n\n if (constrainedHeight < this.minSize.height) {\n constrainedHeight = this.minSize.height\n constrainedWidth = constrainedHeight * this.aspectRatio\n }\n\n // Check maximum constraints\n if (this.maxSize?.width && constrainedWidth > this.maxSize.width) {\n constrainedWidth = this.maxSize.width\n constrainedHeight = constrainedWidth / this.aspectRatio\n }\n\n if (this.maxSize?.height && constrainedHeight > this.maxSize.height) {\n constrainedHeight = this.maxSize.height\n constrainedWidth = constrainedHeight * this.aspectRatio\n }\n\n return { width: constrainedWidth, height: constrainedHeight }\n }\n\n /**\n * Adjusts dimensions to maintain the original aspect ratio.\n *\n * For horizontal handles (left/right), uses width as the primary dimension\n * and calculates height from it. For vertical handles (top/bottom), uses\n * height as primary and calculates width. For corner handles, uses width\n * as the primary dimension.\n *\n * @param width - The new width\n * @param height - The new height\n * @param direction - The active resize direction\n * @returns Dimensions adjusted to preserve aspect ratio\n */\n private applyAspectRatio(\n width: number,\n height: number,\n direction: ResizableNodeViewDirection,\n ): ResizableNodeDimensions {\n const isHorizontal = direction === 'left' || direction === 'right'\n const isVertical = direction === 'top' || direction === 'bottom'\n\n if (isHorizontal) {\n // For horizontal resize, width is primary\n return {\n width,\n height: width / this.aspectRatio,\n }\n }\n\n if (isVertical) {\n // For vertical resize, height is primary\n return {\n width: height * this.aspectRatio,\n height,\n }\n }\n\n // For corner resize, width is primary\n return {\n width,\n height: width / this.aspectRatio,\n }\n }\n}\n\n/**\n * Alias for ResizableNodeView to maintain consistent naming.\n * @deprecated Use ResizableNodeView instead - will be removed in future versions.\n */\nexport const ResizableNodeview = ResizableNodeView\n","import type { NodeType } from '@tiptap/pm/model'\nimport { type EditorState, NodeSelection } from '@tiptap/pm/state'\n\nexport function canInsertNode(state: EditorState, nodeType: NodeType): boolean {\n const { selection } = state\n const { $from } = selection\n\n // Special handling for NodeSelection\n if (selection instanceof NodeSelection) {\n const index = $from.index()\n const parent = $from.parent\n\n // Can we replace the selected node with the horizontal rule?\n return parent.canReplaceWith(index, index + 1, nodeType)\n }\n\n // Default: check if we can insert at the current position\n let depth = $from.depth\n\n while (depth >= 0) {\n const index = $from.index(depth)\n const parent = $from.node(depth)\n const match = parent.contentMatchAt(index)\n if (match.matchType(nodeType)) {\n return true\n }\n depth -= 1\n }\n return false\n}\n","// source: https://stackoverflow.com/a/6969486\nexport function escapeForRegEx(string: string): string {\n return string.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&')\n}\n","export function isString(value: any): value is string {\n return typeof value === 'string'\n}\n","/**\n * @fileoverview Markdown utilities for creating standardized markdown specs.\n *\n * This module provides utilities for creating complete markdown specifications\n * for different types of nodes using unified syntax patterns.\n */\n\nexport * from './attributeUtils.js'\nexport * from './createAtomBlockMarkdownSpec.js'\nexport * from './createBlockMarkdownSpec.js'\nexport * from './createInlineMarkdownSpec.js'\nexport * from './parseIndentedBlocks.js'\nexport * from './renderNestedMarkdownContent.js'\n","/**\n * @fileoverview Utility functions for parsing and serializing markdown attributes.\n *\n * These utilities handle the common patterns for parsing attribute strings\n * in various markdown syntaxes like Pandoc attributes.\n */\n\n/**\n * Parses a Pandoc-style attribute string into an object.\n *\n * Supports the following patterns:\n * - Classes: `.className` → `{ class: 'className' }`\n * - IDs: `#myId` → `{ id: 'myId' }`\n * - Key-value pairs: `key=\"value\"` → `{ key: 'value' }`\n * - Boolean attributes: `disabled` → `{ disabled: true }`\n *\n * @param attrString - The attribute string to parse\n * @returns Parsed attributes object\n *\n * @example\n * ```ts\n * parseAttributes('.btn #submit disabled type=\"button\"')\n * // → { class: 'btn', id: 'submit', disabled: true, type: 'button' }\n * ```\n */\nexport function parseAttributes(attrString: string): Record<string, any> {\n if (!attrString?.trim()) {\n return {}\n }\n\n const attributes: Record<string, any> = {}\n\n // First, extract and remove quoted strings to avoid parsing content inside them\n const quotedStrings: string[] = []\n const tempString = attrString.replace(/[\"']([^\"']*)[\"']/g, match => {\n quotedStrings.push(match)\n return `__QUOTED_${quotedStrings.length - 1}__`\n })\n\n // Parse classes (.className) - only outside of quoted strings\n const classMatches = tempString.match(/(?:^|\\s)\\.([a-zA-Z][\\w-]*)/g)\n if (classMatches) {\n const classes = classMatches.map(match => match.trim().slice(1)) // Remove the dot\n attributes.class = classes.join(' ')\n }\n\n // Parse IDs (#myId) - only outside of quoted strings\n const idMatch = tempString.match(/(?:^|\\s)#([a-zA-Z][\\w-]*)/)\n if (idMatch) {\n attributes.id = idMatch[1]\n }\n\n // Parse key-value pairs (key=\"value\" or key='value') - restore quoted strings\n const kvRegex = /([a-zA-Z][\\w-]*)\\s*=\\s*(__QUOTED_\\d+__)/g\n const kvMatches = Array.from(tempString.matchAll(kvRegex))\n kvMatches.forEach(([, key, quotedRef]) => {\n const quotedIndex = parseInt(quotedRef.match(/__QUOTED_(\\d+)__/)?.[1] || '0', 10)\n const quotedValue = quotedStrings[quotedIndex]\n if (quotedValue) {\n // Remove the outer quotes\n attributes[key] = quotedValue.slice(1, -1)\n }\n })\n\n // Parse boolean attributes (standalone words that aren't classes/IDs)\n const cleanString = tempString\n .replace(/(?:^|\\s)\\.([a-zA-Z][\\w-]*)/g, '') // Remove classes\n .replace(/(?:^|\\s)#([a-zA-Z][\\w-]*)/g, '') // Remove IDs\n .replace(/([a-zA-Z][\\w-]*)\\s*=\\s*__QUOTED_\\d+__/g, '') // Remove key-value pairs\n .trim()\n\n if (cleanString) {\n const booleanAttrs = cleanString.split(/\\s+/).filter(Boolean)\n booleanAttrs.forEach(attr => {\n if (attr.match(/^[a-zA-Z][\\w-]*$/)) {\n attributes[attr] = true\n }\n })\n }\n\n return attributes\n}\n\n/**\n * Serializes an attributes object back to a Pandoc-style attribute string.\n *\n * @param attributes - The attributes object to serialize\n * @returns Serialized attribute string\n *\n * @example\n * ```ts\n * serializeAttributes({ class: 'btn primary', id: 'submit', disabled: true, type: 'button' })\n * // → '.btn.primary #submit disabled type=\"button\"'\n * ```\n */\nexport function serializeAttributes(attributes: Record<string, any>): string {\n if (!attributes || Object.keys(attributes).length === 0) {\n return ''\n }\n\n const parts: string[] = []\n\n // Handle classes\n if (attributes.class) {\n const classes = String(attributes.class).split(/\\s+/).filter(Boolean)\n classes.forEach(cls => parts.push(`.${cls}`))\n }\n\n // Handle ID\n if (attributes.id) {\n parts.push(`#${attributes.id}`)\n }\n\n // Handle other attributes\n Object.entries(attributes).forEach(([key, value]) => {\n if (key === 'class' || key === 'id') {\n return // Already handled\n }\n\n if (value === true) {\n // Boolean attribute\n parts.push(key)\n } else if (value !== false && value != null) {\n // Key-value attribute\n parts.push(`${key}=\"${String(value)}\"`)\n }\n })\n\n return parts.join(' ')\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\nimport {\n parseAttributes as defaultParseAttributes,\n serializeAttributes as defaultSerializeAttributes,\n} from './attributeUtils.js'\n\nexport interface AtomBlockMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The markdown syntax name (defaults to nodeName if not provided) */\n name?: string\n /** Function to parse attributes from token attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes back to string for rendering */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Required attributes that must be present for successful parsing */\n requiredAttributes?: string[]\n /** Attributes that are allowed to be rendered back to markdown (whitelist) */\n allowedAttributes?: string[]\n}\n\n/**\n * Creates a complete markdown spec for atomic block nodes using Pandoc syntax.\n *\n * The generated spec handles:\n * - Parsing self-closing blocks with `:::blockName {attributes}`\n * - Extracting and parsing attributes\n * - Validating required attributes\n * - Rendering blocks back to markdown\n *\n * @param options - Configuration for the atomic block markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * const youtubeSpec = createAtomBlockMarkdownSpec({\n * nodeName: 'youtube',\n * requiredAttributes: ['src'],\n * defaultAttributes: { start: 0 },\n * allowedAttributes: ['src', 'start', 'width', 'height'] // Only these get rendered to markdown\n * })\n *\n * // Usage in extension:\n * export const Youtube = Node.create({\n * // ... other config\n * markdown: youtubeSpec\n * })\n * ```\n */\nexport function createAtomBlockMarkdownSpec(options: AtomBlockMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent) => string\n} {\n const {\n nodeName,\n name: markdownName,\n parseAttributes = defaultParseAttributes,\n serializeAttributes = defaultSerializeAttributes,\n defaultAttributes = {},\n requiredAttributes = [],\n allowedAttributes,\n } = options\n\n // Use markdownName for syntax, fallback to nodeName\n const blockName = markdownName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(key => {\n if (key in attrs) {\n filtered[key] = attrs[key]\n }\n })\n return filtered\n }\n\n return {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => {\n const attrs = { ...defaultAttributes, ...token.attributes }\n return h.createNode(nodeName, attrs, [])\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'block' as const,\n start(src: string) {\n const regex = new RegExp(`^:::${blockName}(?:\\\\s|$)`, 'm')\n const index = src.match(regex)?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, _lexer) {\n // Use non-global regex to match from the start of the string\n // Include optional newline to ensure we consume the entire line\n const regex = new RegExp(`^:::${blockName}(?:\\\\s+\\\\{([^}]*)\\\\})?\\\\s*:::(?:\\\\n|$)`)\n const match = src.match(regex)\n\n if (!match) {\n return undefined\n }\n\n // Parse attributes if present\n const attrString = match[1] || ''\n const attributes = parseAttributes(attrString)\n\n // Validate required attributes\n const missingRequired = requiredAttributes.find(required => !(required in attributes))\n if (missingRequired) {\n return undefined\n }\n\n return {\n type: nodeName,\n raw: match[0],\n attributes,\n }\n },\n },\n\n renderMarkdown: node => {\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` {${attrs}}` : ''\n\n return `:::${blockName}${attrString} :::`\n },\n }\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownRendererHelpers,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\nimport {\n parseAttributes as defaultParseAttributes,\n serializeAttributes as defaultSerializeAttributes,\n} from './attributeUtils.js'\n\nexport interface BlockMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The markdown syntax name (defaults to nodeName if not provided) */\n name?: string\n /** Function to extract content from the node for serialization */\n getContent?: (token: MarkdownToken) => string\n /** Function to parse attributes from the attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes to string */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Content type: 'block' allows paragraphs/lists/etc, 'inline' only allows bold/italic/links/etc */\n content?: 'block' | 'inline'\n /** Allowlist of attributes to include in markdown (if not provided, all attributes are included) */\n allowedAttributes?: string[]\n}\n\n/**\n * Creates a complete markdown spec for block-level nodes using Pandoc syntax.\n *\n * The generated spec handles:\n * - Parsing blocks with `:::blockName {attributes}` syntax\n * - Extracting and parsing attributes\n * - Rendering blocks back to markdown with proper formatting\n * - Nested content support\n *\n * @param options - Configuration for the block markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * const calloutSpec = createBlockMarkdownSpec({\n * nodeName: 'callout',\n * defaultAttributes: { type: 'info' },\n * allowedAttributes: ['type', 'title'] // Only these get rendered to markdown\n * })\n *\n * // Usage in extension:\n * export const Callout = Node.create({\n * // ... other config\n * markdown: calloutSpec\n * })\n * ```\n */\nexport function createBlockMarkdownSpec(options: BlockMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent, h: MarkdownRendererHelpers) => string\n} {\n const {\n nodeName,\n name: markdownName,\n getContent,\n parseAttributes = defaultParseAttributes,\n serializeAttributes = defaultSerializeAttributes,\n defaultAttributes = {},\n content = 'block',\n allowedAttributes,\n } = options\n\n // Use markdownName for syntax, fallback to nodeName\n const blockName = markdownName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(key => {\n if (key in attrs) {\n filtered[key] = attrs[key]\n }\n })\n return filtered\n }\n\n return {\n parseMarkdown: (token, h) => {\n let nodeContent: JSONContent[]\n\n if (getContent) {\n const contentResult = getContent(token)\n // If getContent returns a string, wrap it in a text node\n nodeContent = typeof contentResult === 'string' ? [{ type: 'text', text: contentResult }] : contentResult\n } else if (content === 'block') {\n nodeContent = h.parseChildren(token.tokens || [])\n } else {\n nodeContent = h.parseInline(token.tokens || [])\n }\n\n const attrs = { ...defaultAttributes, ...token.attributes }\n\n return h.createNode(nodeName, attrs, nodeContent)\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'block' as const,\n start(src) {\n const regex = new RegExp(`^:::${blockName}`, 'm')\n const index = src.match(regex)?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, lexer) {\n // Match the opening tag with optional attributes\n const openingRegex = new RegExp(`^:::${blockName}(?:\\\\s+\\\\{([^}]*)\\\\})?\\\\s*\\\\n`)\n const openingMatch = src.match(openingRegex)\n\n if (!openingMatch) {\n return undefined\n }\n\n const [openingTag, attrString = ''] = openingMatch\n const attributes = parseAttributes(attrString)\n\n // Find the matching closing tag by tracking nesting level\n let level = 1\n const position = openingTag.length\n let matchedContent = ''\n\n // Pattern to match any block opening (:::word) or closing (:::)\n const blockPattern = /^:::([\\w-]*)(\\s.*)?/gm\n const remaining = src.slice(position)\n\n blockPattern.lastIndex = 0\n\n // run until no more matches are found\n for (;;) {\n const match = blockPattern.exec(remaining)\n if (match === null) {\n break\n }\n const matchPos = match.index\n const blockType = match[1] // Empty string for closing tag, block name for opening\n\n if (match[2]?.endsWith(':::')) {\n // this is an atom ::: node, we skip it\n continue\n }\n\n if (blockType) {\n // Opening tag found - increase level\n level += 1\n } else {\n // Closing tag found - decrease level\n level -= 1\n\n if (level === 0) {\n // Found our matching closing tag\n // Don't trim yet - keep newlines for tokenizer regex matching\n const rawContent = remaining.slice(0, matchPos)\n matchedContent = rawContent.trim()\n const fullMatch = src.slice(0, position + matchPos + match[0].length)\n\n // Tokenize the content\n let contentTokens: MarkdownToken[] = []\n if (matchedContent) {\n if (content === 'block') {\n // Use rawContent for tokenization to preserve line boundaries for regex matching\n contentTokens = lexer.blockTokens(rawContent)\n\n // Parse inline tokens for any token that has text content but no tokens\n contentTokens.forEach(token => {\n if (token.text && (!token.tokens || token.tokens.length === 0)) {\n token.tokens = lexer.inlineTokens(token.text)\n }\n })\n\n // Clean up empty trailing paragraphs\n while (contentTokens.length > 0) {\n const lastToken = contentTokens[contentTokens.length - 1]\n if (lastToken.type === 'paragraph' && (!lastToken.text || lastToken.text.trim() === '')) {\n contentTokens.pop()\n } else {\n break\n }\n }\n } else {\n contentTokens = lexer.inlineTokens(matchedContent)\n }\n }\n\n return {\n type: nodeName,\n raw: fullMatch,\n attributes,\n content: matchedContent,\n tokens: contentTokens,\n }\n }\n }\n }\n\n // No matching closing tag found\n return undefined\n },\n },\n\n renderMarkdown: (node, h) => {\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` {${attrs}}` : ''\n const renderedContent = h.renderChildren(node.content || [], '\\n\\n')\n\n return `:::${blockName}${attrString}\\n\\n${renderedContent}\\n\\n:::`\n },\n }\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\n\n/**\n * Parse shortcode attributes like 'id=\"madonna\" handle=\"john\" name=\"John Doe\"'\n * Requires all values to be quoted with either single or double quotes\n */\nfunction parseShortcodeAttributes(attrString: string): Record<string, any> {\n if (!attrString.trim()) {\n return {}\n }\n\n const attributes: Record<string, any> = {}\n // Match key=value pairs, only accepting quoted values\n const regex = /(\\w+)=(?:\"([^\"]*)\"|'([^']*)')/g\n let match = regex.exec(attrString)\n\n while (match !== null) {\n const [, key, doubleQuoted, singleQuoted] = match\n attributes[key] = doubleQuoted || singleQuoted\n match = regex.exec(attrString)\n }\n\n return attributes\n}\n\n/**\n * Serialize attributes back to shortcode format\n * Always quotes all values with double quotes\n */\nfunction serializeShortcodeAttributes(attrs: Record<string, any>): string {\n return Object.entries(attrs)\n .filter(([, value]) => value !== undefined && value !== null)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ')\n}\n\n/**\n * Configuration for an allowed attribute in markdown serialization.\n * Can be a simple string (attribute name) or an object with additional options.\n */\nexport type AllowedAttribute =\n | string\n | {\n /** The attribute name */\n name: string\n /**\n * If provided, the attribute will be skipped during serialization when its value\n * equals this default value. This keeps markdown output clean by omitting\n * attributes that have their default values.\n */\n skipIfDefault?: any\n }\n\nexport interface InlineMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The shortcode name (defaults to nodeName if not provided) */\n name?: string\n /** Function to extract content from the node for serialization */\n getContent?: (node: any) => string\n /** Function to parse attributes from the attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes to string */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Whether this is a self-closing shortcode (no content, like [emoji name=party]) */\n selfClosing?: boolean\n /**\n * Allowlist of attributes to include in markdown serialization.\n * If not provided, all attributes are included.\n *\n * Each item can be either:\n * - A string: the attribute name (always included if present)\n * - An object: `{ name: string, skipIfDefault?: any }` for conditional inclusion\n *\n * @example\n * // Simple string attributes (backward compatible)\n * allowedAttributes: ['id', 'label']\n *\n * // Mixed with conditional attributes\n * allowedAttributes: [\n * 'id',\n * 'label',\n * { name: 'mentionSuggestionChar', skipIfDefault: '@' }\n * ]\n */\n allowedAttributes?: AllowedAttribute[]\n}\n\n/**\n * Creates a complete markdown spec for inline nodes using attribute syntax.\n *\n * The generated spec handles:\n * - Parsing shortcode syntax with `[nodeName attributes]content[/nodeName]` format\n * - Self-closing shortcodes like `[emoji name=party_popper]`\n * - Extracting and parsing attributes from the opening tag\n * - Rendering inline elements back to shortcode markdown\n * - Supporting both content-based and self-closing inline elements\n *\n * @param options - Configuration for the inline markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * // Self-closing mention: [mention id=\"madonna\" label=\"Madonna\"]\n * const mentionSpec = createInlineMarkdownSpec({\n * nodeName: 'mention',\n * selfClosing: true,\n * defaultAttributes: { type: 'user' },\n * allowedAttributes: ['id', 'label'] // Only these get rendered to markdown\n * })\n *\n * // Self-closing emoji: [emoji name=\"party_popper\"]\n * const emojiSpec = createInlineMarkdownSpec({\n * nodeName: 'emoji',\n * selfClosing: true,\n * allowedAttributes: ['name']\n * })\n *\n * // With content: [highlight color=\"yellow\"]text[/highlight]\n * const highlightSpec = createInlineMarkdownSpec({\n * nodeName: 'highlight',\n * selfClosing: false,\n * allowedAttributes: ['color', 'style']\n * })\n *\n * // Usage in extension:\n * export const Mention = Node.create({\n * name: 'mention', // Must match nodeName\n * // ... other config\n * markdown: mentionSpec\n * })\n * ```\n */\nexport function createInlineMarkdownSpec(options: InlineMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent) => string\n} {\n const {\n nodeName,\n name: shortcodeName,\n getContent,\n parseAttributes = parseShortcodeAttributes,\n serializeAttributes = serializeShortcodeAttributes,\n defaultAttributes = {},\n selfClosing = false,\n allowedAttributes,\n } = options\n\n // Use shortcodeName for markdown syntax, fallback to nodeName\n const shortcode = shortcodeName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(attr => {\n // Handle both string and object formats for backward compatibility\n const attrName = typeof attr === 'string' ? attr : attr.name\n const skipIfDefault = typeof attr === 'string' ? undefined : attr.skipIfDefault\n\n if (attrName in attrs) {\n const value = attrs[attrName]\n\n // Skip if value equals the default (when skipIfDefault is specified)\n if (skipIfDefault !== undefined && value === skipIfDefault) {\n return\n }\n\n filtered[attrName] = value\n }\n })\n return filtered\n }\n\n // Escape special regex characters in shortcode name\n const escapedShortcode = shortcode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => {\n const attrs = { ...defaultAttributes, ...token.attributes }\n\n if (selfClosing) {\n // Self-closing nodes like mentions are atomic - no content\n return h.createNode(nodeName, attrs)\n }\n\n // Nodes with content\n const content = getContent ? getContent(token) : token.content || ''\n if (content) {\n // For inline content, create text nodes using the proper helper\n return h.createNode(nodeName, attrs, [h.createTextNode(content)])\n }\n return h.createNode(nodeName, attrs, [])\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'inline' as const,\n start(src: string) {\n // Create a non-global version for finding the start position\n const startPattern = selfClosing\n ? new RegExp(`\\\\[${escapedShortcode}\\\\s*[^\\\\]]*\\\\]`)\n : new RegExp(`\\\\[${escapedShortcode}\\\\s*[^\\\\]]*\\\\][\\\\s\\\\S]*?\\\\[\\\\/${escapedShortcode}\\\\]`)\n\n const match = src.match(startPattern)\n const index = match?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, _lexer) {\n // Use non-global regex to match from the start of the string\n const tokenPattern = selfClosing\n ? new RegExp(`^\\\\[${escapedShortcode}\\\\s*([^\\\\]]*)\\\\]`)\n : new RegExp(`^\\\\[${escapedShortcode}\\\\s*([^\\\\]]*)\\\\]([\\\\s\\\\S]*?)\\\\[\\\\/${escapedShortcode}\\\\]`)\n\n const match = src.match(tokenPattern)\n\n if (!match) {\n return undefined\n }\n\n let content = ''\n let attrString = ''\n\n if (selfClosing) {\n // Self-closing: [shortcode attr=\"value\"]\n const [, attrs] = match\n attrString = attrs\n } else {\n // With content: [shortcode attr=\"value\"]content[/shortcode]\n const [, attrs, contentMatch] = match\n attrString = attrs\n content = contentMatch || ''\n }\n\n // Parse attributes from the attribute string\n const attributes = parseAttributes(attrString.trim())\n\n return {\n type: nodeName,\n raw: match[0],\n content: content.trim(),\n attributes,\n }\n },\n },\n\n renderMarkdown: (node: JSONContent) => {\n let content = ''\n if (getContent) {\n content = getContent(node)\n } else if (node.content && node.content.length > 0) {\n // Extract text from content array for inline nodes\n content = node.content\n .filter((child: any) => child.type === 'text')\n .map((child: any) => child.text)\n .join('')\n }\n\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` ${attrs}` : ''\n\n if (selfClosing) {\n return `[${shortcode}${attrString}]`\n }\n\n return `[${shortcode}${attrString}]${content}[/${shortcode}]`\n },\n }\n}\n","/**\n * @fileoverview Utility for parsing indented markdown blocks with hierarchical nesting.\n *\n * This utility handles the complex logic of parsing markdown blocks that can contain\n * nested content based on indentation levels, maintaining proper hierarchical structure\n * for lists, task lists, and other indented block types.\n */\n\nexport interface ParsedBlock {\n type: string\n raw: string\n mainContent: string\n indentLevel: number\n nestedContent?: string\n nestedTokens?: any[]\n [key: string]: any\n}\n\nexport interface BlockParserConfig {\n /** Regex pattern to match block items */\n itemPattern: RegExp\n /** Function to extract data from regex match */\n extractItemData: (match: RegExpMatchArray) => {\n mainContent: string\n indentLevel: number\n [key: string]: any\n }\n /** Function to create the final token */\n createToken: (data: any, nestedTokens?: any[]) => ParsedBlock\n /** Base indentation to remove from nested content (default: 2 spaces) */\n baseIndentSize?: number\n /**\n * Custom parser for nested content. If provided, this will be called instead\n * of the default lexer.blockTokens() for parsing nested content.\n * This allows recursive parsing of the same block type.\n */\n customNestedParser?: (dedentedContent: string) => any[] | undefined\n}\n\n/**\n * Parses markdown text into hierarchical indented blocks with proper nesting.\n *\n * This utility handles:\n * - Line-by-line parsing with pattern matching\n * - Hierarchical nesting based on indentation levels\n * - Nested content collection and parsing\n * - Empty line handling\n * - Content dedenting for nested blocks\n *\n * The key difference from flat parsing is that this maintains the hierarchical\n * structure where nested items become `nestedTokens` of their parent items,\n * rather than being flattened into a single array.\n *\n * @param src - The markdown source text to parse\n * @param config - Configuration object defining how to parse and create tokens\n * @param lexer - Markdown lexer for parsing nested content\n * @returns Parsed result with hierarchical items, or undefined if no matches\n *\n * @example\n * ```ts\n * const result = parseIndentedBlocks(src, {\n * itemPattern: /^(\\s*)([-+*])\\s+\\[([ xX])\\]\\s+(.*)$/,\n * extractItemData: (match) => ({\n * indentLevel: match[1].length,\n * mainContent: match[4],\n * checked: match[3].toLowerCase() === 'x'\n * }),\n * createToken: (data, nestedTokens) => ({\n * type: 'taskItem',\n * checked: data.checked,\n * text: data.mainContent,\n * nestedTokens\n * })\n * }, lexer)\n * ```\n */\nexport function parseIndentedBlocks(\n src: string,\n config: BlockParserConfig,\n lexer: {\n inlineTokens: (src: string) => any[]\n blockTokens: (src: string) => any[]\n },\n):\n | {\n items: ParsedBlock[]\n raw: string\n }\n | undefined {\n const lines = src.split('\\n')\n const items: ParsedBlock[] = []\n let totalRaw = ''\n let i = 0\n const baseIndentSize = config.baseIndentSize || 2\n\n while (i < lines.length) {\n const currentLine = lines[i]\n const itemMatch = currentLine.match(config.itemPattern)\n\n if (!itemMatch) {\n // Not a matching item - stop if we have items, otherwise this isn't our block type\n if (items.length > 0) {\n break\n } else if (currentLine.trim() === '') {\n i += 1\n totalRaw = `${totalRaw}${currentLine}\\n`\n continue\n } else {\n return undefined\n }\n }\n\n const itemData = config.extractItemData(itemMatch)\n const { indentLevel, mainContent } = itemData\n totalRaw = `${totalRaw}${currentLine}\\n`\n\n // Collect content for this item (including nested items)\n const itemContent = [mainContent] // Start with the main text\n i += 1\n\n // Look ahead for nested content (indented more than current item)\n while (i < lines.length) {\n const nextLine = lines[i]\n\n if (nextLine.trim() === '') {\n // Empty line - might be end of nested content\n const nextNonEmptyIndex = lines.slice(i + 1).findIndex(l => l.trim() !== '')\n if (nextNonEmptyIndex === -1) {\n // No more content\n break\n }\n\n const nextNonEmpty = lines[i + 1 + nextNonEmptyIndex]\n const nextIndent = nextNonEmpty.match(/^(\\s*)/)?.[1]?.length || 0\n\n if (nextIndent > indentLevel) {\n // Nested content continues after empty line\n itemContent.push(nextLine)\n totalRaw = `${totalRaw}${nextLine}\\n`\n i += 1\n continue\n } else {\n // End of nested content\n break\n }\n }\n\n const nextIndent = nextLine.match(/^(\\s*)/)?.[1]?.length || 0\n\n if (nextIndent > indentLevel) {\n // This is nested content for the current item\n itemContent.push(nextLine)\n totalRaw = `${totalRaw}${nextLine}\\n`\n i += 1\n } else {\n // Same or less indentation - this belongs to parent level\n break\n }\n }\n\n // Parse nested content if present\n let nestedTokens: any[] | undefined\n const nestedContent = itemContent.slice(1)\n\n if (nestedContent.length > 0) {\n // Remove the base indentation from nested content\n const dedentedNested = nestedContent\n .map(nestedLine => nestedLine.slice(indentLevel + baseIndentSize)) // Remove base indent + 2 spaces\n .join('\\n')\n\n if (dedentedNested.trim()) {\n // Use custom nested parser if provided, otherwise fall back to default\n if (config.customNestedParser) {\n nestedTokens = config.customNestedParser(dedentedNested)\n } else {\n nestedTokens = lexer.blockTokens(dedentedNested)\n }\n }\n }\n\n // Create the token using the provided factory function\n const token = config.createToken(itemData, nestedTokens)\n items.push(token)\n }\n\n if (items.length === 0) {\n return undefined\n }\n\n return {\n items,\n raw: totalRaw,\n }\n}\n","import type { JSONContent } from '@tiptap/core'\n\n/**\n * @fileoverview Utility functions for rendering nested content in markdown.\n *\n * This module provides reusable utilities for extensions that need to render\n * content with a prefix on the main line and properly indented nested content.\n */\n\n/**\n * Utility function for rendering content with a main line prefix and nested indented content.\n *\n * This function handles the common pattern of rendering content with:\n * 1. A main line with a prefix (like \"- \" for lists, \"> \" for blockquotes, etc.)\n * 2. Nested content that gets indented properly\n *\n * @param node - The ProseMirror node representing the content\n * @param h - The markdown renderer helper\n * @param prefixOrGenerator - Either a string prefix or a function that generates the prefix from context\n * @param ctx - Optional context object (used when prefixOrGenerator is a function)\n * @returns The rendered markdown string\n *\n * @example\n * ```ts\n * // For a bullet list item with static prefix\n * return renderNestedMarkdownContent(node, h, '- ')\n *\n * // For a task item with static prefix\n * const prefix = `- [${node.attrs?.checked ? 'x' : ' '}] `\n * return renderNestedMarkdownContent(node, h, prefix)\n *\n * // For a blockquote with static prefix\n * return renderNestedMarkdownContent(node, h, '> ')\n *\n * // For content with dynamic prefix based on context\n * return renderNestedMarkdownContent(node, h, ctx => {\n * if (ctx.parentType === 'orderedList') {\n * return `${ctx.index + 1}. `\n * }\n * return '- '\n * }, ctx)\n *\n * // Custom extension example\n * const CustomContainer = Node.create({\n * name: 'customContainer',\n * // ... other config\n * markdown: {\n * render: (node, h) => {\n * const type = node.attrs?.type || 'info'\n * return renderNestedMarkdownContent(node, h, `[${type}] `)\n * }\n * }\n * })\n * ```\n */\nexport function renderNestedMarkdownContent(\n node: JSONContent,\n h: {\n renderChildren: (nodes: JSONContent[]) => string\n indent: (text: string) => string\n },\n prefixOrGenerator: string | ((ctx: any) => string),\n ctx?: any,\n): string {\n if (!node || !Array.isArray(node.content)) {\n return ''\n }\n\n // Determine the prefix based on the input\n const prefix = typeof prefixOrGenerator === 'function' ? prefixOrGenerator(ctx) : prefixOrGenerator\n\n const [content, ...children] = node.content\n\n // Render the main content (typically a paragraph)\n const mainContent = h.renderChildren([content])\n const output = [`${prefix}${mainContent}`]\n\n // Handle nested children with proper indentation\n if (children && children.length > 0) {\n children.forEach(child => {\n const childContent = h.renderChildren([child])\n if (childContent) {\n // Split the child content by lines and indent each line\n const indentedChild = childContent\n .split('\\n')\n .map(line => (line ? h.indent(line) : ''))\n .join('\\n')\n output.push(indentedChild)\n }\n })\n }\n\n return output.join('\\n')\n}\n","import type { Mark } from '@tiptap/pm/model'\nimport type { ViewMutationRecord } from '@tiptap/pm/view'\n\nimport type { Editor } from './Editor.js'\nimport type { MarkViewProps, MarkViewRendererOptions } from './types.js'\nimport { isAndroid, isiOS } from './utilities/index.js'\n\nexport function updateMarkViewAttributes(checkMark: Mark, editor: Editor, attrs: Record<string, any> = {}): void {\n const { state } = editor\n const { doc, tr } = state\n const thisMark = checkMark\n\n doc.descendants((node, pos) => {\n const from = tr.mapping.map(pos)\n const to = tr.mapping.map(pos) + node.nodeSize\n let foundMark: Mark | null = null\n\n // find the mark on the current node\n node.marks.forEach(mark => {\n if (mark !== thisMark) {\n return false\n }\n\n foundMark = mark\n })\n\n if (!foundMark) {\n return\n }\n\n // check if we need to update given the attributes\n let needsUpdate = false\n Object.keys(attrs).forEach(k => {\n if (attrs[k] !== foundMark!.attrs[k]) {\n needsUpdate = true\n }\n })\n\n if (needsUpdate) {\n const updatedMark = checkMark.type.create({\n ...checkMark.attrs,\n ...attrs,\n })\n\n tr.removeMark(from, to, checkMark.type)\n tr.addMark(from, to, updatedMark)\n }\n })\n\n if (tr.docChanged) {\n editor.view.dispatch(tr)\n }\n}\n\nexport class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {\n component: Component\n editor: Editor\n options: Options\n mark: MarkViewProps['mark']\n HTMLAttributes: MarkViewProps['HTMLAttributes']\n\n constructor(component: Component, props: MarkViewProps, options?: Partial<Options>) {\n this.component = component\n this.editor = props.editor\n this.options = { ...options } as Options\n this.mark = props.mark\n this.HTMLAttributes = props.HTMLAttributes\n }\n\n get dom(): HTMLElement {\n return this.editor.view.dom\n }\n\n get contentDOM(): HTMLElement | null {\n return null\n }\n\n /**\n * Update the attributes of the mark in the document.\n * @param attrs The attributes to update.\n */\n updateAttributes(attrs: Record<string, any>, checkMark?: Mark): void {\n updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs)\n }\n\n ignoreMutation(mutation: ViewMutationRecord): boolean {\n if (!this.dom || !this.contentDOM) {\n return true\n }\n\n if (typeof this.options.ignoreMutation === 'function') {\n return this.options.ignoreMutation({ mutation })\n }\n\n if (mutation.type === 'selection') {\n return false\n }\n\n if (\n this.dom.contains(mutation.target) &&\n mutation.type === 'childList' &&\n (isiOS() || isAndroid()) &&\n this.editor.isFocused\n ) {\n const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]\n\n if (changedNodes.every(node => node.isContentEditable)) {\n return false\n }\n }\n\n if (this.contentDOM === mutation.target && mutation.type === 'attributes') {\n return true\n }\n\n if (this.contentDOM.contains(mutation.target)) {\n return false\n }\n\n return true\n }\n}\n","import type { DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { ExtendableConfig } from './Extendable.js'\nimport { Extendable } from './Extendable.js'\nimport type { Attributes, NodeViewRenderer, ParentConfig } from './types.js'\n\nexport interface NodeConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, NodeConfig<Options, Storage>, NodeType> {\n /**\n * Node View\n */\n addNodeView?:\n | ((this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: NodeType\n parent: ParentConfig<NodeConfig<Options, Storage>>['addNodeView']\n }) => NodeViewRenderer | null)\n | null\n\n /**\n * Defines if this node should be a top level node (doc)\n * @default false\n * @example true\n */\n topNode?: boolean\n\n /**\n * The content expression for this node, as described in the [schema\n * guide](/docs/guide/#schema.content_expressions). When not given,\n * the node does not allow any content.\n *\n * You can read more about it on the Prosemirror documentation here\n * @see https://prosemirror.net/docs/guide/#schema.content_expressions\n * @default undefined\n * @example content: 'block+'\n * @example content: 'headline paragraph block*'\n */\n content?:\n | NodeSpec['content']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['content']\n editor?: Editor\n }) => NodeSpec['content'])\n\n /**\n * The marks that are allowed inside of this node. May be a\n * space-separated string referring to mark names or groups, `\"_\"`\n * to explicitly allow all marks, or `\"\"` to disallow marks. When\n * not given, nodes with inline content default to allowing all\n * marks, other nodes default to not allowing marks.\n *\n * @example marks: 'strong em'\n */\n marks?:\n | NodeSpec['marks']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['marks']\n editor?: Editor\n }) => NodeSpec['marks'])\n\n /**\n * The group or space-separated groups to which this node belongs,\n * which can be referred to in the content expressions for the\n * schema.\n *\n * By default Tiptap uses the groups 'block' and 'inline' for nodes. You\n * can also use custom groups if you want to group specific nodes together\n * and handle them in your schema.\n * @example group: 'block'\n * @example group: 'inline'\n * @example group: 'customBlock' // this uses a custom group\n */\n group?:\n | NodeSpec['group']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['group']\n editor?: Editor\n }) => NodeSpec['group'])\n\n /**\n * Should be set to true for inline nodes. (Implied for text nodes.)\n */\n inline?:\n | NodeSpec['inline']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['inline']\n editor?: Editor\n }) => NodeSpec['inline'])\n\n /**\n * Can be set to true to indicate that, though this isn't a [leaf\n * node](https://prosemirror.net/docs/ref/#model.NodeType.isLeaf), it doesn't have directly editable\n * content and should be treated as a single unit in the view.\n *\n * @example atom: true\n */\n atom?:\n | NodeSpec['atom']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['atom']\n editor?: Editor\n }) => NodeSpec['atom'])\n\n /**\n * Controls whether nodes of this type can be selected as a [node\n * selection](https://prosemirror.net/docs/ref/#state.NodeSelection). Defaults to true for non-text\n * nodes.\n *\n * @default true\n * @example selectable: false\n */\n selectable?:\n | NodeSpec['selectable']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['selectable']\n editor?: Editor\n }) => NodeSpec['selectable'])\n\n /**\n * Determines whether nodes of this type can be dragged without\n * being selected. Defaults to false.\n *\n * @default: false\n * @example: draggable: true\n */\n draggable?:\n | NodeSpec['draggable']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['draggable']\n editor?: Editor\n }) => NodeSpec['draggable'])\n\n /**\n * Can be used to indicate that this node contains code, which\n * causes some commands to behave differently.\n */\n code?:\n | NodeSpec['code']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['code']\n editor?: Editor\n }) => NodeSpec['code'])\n\n /**\n * Controls way whitespace in this a node is parsed. The default is\n * `\"normal\"`, which causes the [DOM parser](https://prosemirror.net/docs/ref/#model.DOMParser) to\n * collapse whitespace in normal mode, and normalize it (replacing\n * newlines and such with spaces) otherwise. `\"pre\"` causes the\n * parser to preserve spaces inside the node. When this option isn't\n * given, but [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) is true, `whitespace`\n * will default to `\"pre\"`. Note that this option doesn't influence\n * the way the node is rendered—that should be handled by `toDOM`\n * and/or styling.\n */\n whitespace?:\n | NodeSpec['whitespace']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['whitespace']\n editor?: Editor\n }) => NodeSpec['whitespace'])\n\n /**\n * Allows a **single** node to be set as linebreak equivalent (e.g. hardBreak).\n * When converting between block types that have whitespace set to \"pre\"\n * and don't support the linebreak node (e.g. codeBlock) and other block types\n * that do support the linebreak node (e.g. paragraphs) - this node will be used\n * as the linebreak instead of stripping the newline.\n *\n * See [linebreakReplacement](https://prosemirror.net/docs/ref/#model.NodeSpec.linebreakReplacement).\n */\n linebreakReplacement?:\n | NodeSpec['linebreakReplacement']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['linebreakReplacement']\n editor?: Editor\n }) => NodeSpec['linebreakReplacement'])\n\n /**\n * When enabled, enables both\n * [`definingAsContext`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext) and\n * [`definingForContent`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).\n *\n * @default false\n * @example isolating: true\n */\n defining?:\n | NodeSpec['defining']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['defining']\n editor?: Editor\n }) => NodeSpec['defining'])\n\n /**\n * When enabled (default is false), the sides of nodes of this type\n * count as boundaries that regular editing operations, like\n * backspacing or lifting, won't cross. An example of a node that\n * should probably have this enabled is a table cell.\n */\n isolating?:\n | NodeSpec['isolating']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['isolating']\n editor?: Editor\n }) => NodeSpec['isolating'])\n\n /**\n * Associates DOM parser information with this node, which can be\n * used by [`DOMParser.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMParser^fromSchema) to\n * automatically derive a parser. The `node` field in the rules is\n * implied (the name of this node will be filled in automatically).\n * If you supply your own parser, you do not need to also specify\n * parsing rules in your schema.\n *\n * @example parseHTML: [{ tag: 'div', attrs: { 'data-id': 'my-block' } }]\n */\n parseHTML?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['parseHTML']\n editor?: Editor\n }) => NodeSpec['parseDOM']\n\n /**\n * A description of a DOM structure. Can be either a string, which is\n * interpreted as a text node, a DOM node, which is interpreted as\n * itself, a `{dom, contentDOM}` object, or an array.\n *\n * An array describes a DOM element. The first value in the array\n * should be a string—the name of the DOM element, optionally prefixed\n * by a namespace URL and a space. If the second element is plain\n * object, it is interpreted as a set of attributes for the element.\n * Any elements after that (including the 2nd if it's not an attribute\n * object) are interpreted as children of the DOM elements, and must\n * either be valid `DOMOutputSpec` values, or the number zero.\n *\n * The number zero (pronounced “hole”) is used to indicate the place\n * where a node's child nodes should be inserted. If it occurs in an\n * output spec, it should be the only child element in its parent\n * node.\n *\n * @example toDOM: ['div[data-id=\"my-block\"]', { class: 'my-block' }, 0]\n */\n renderHTML?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML']\n editor?: Editor\n },\n props: {\n node: ProseMirrorNode\n HTMLAttributes: Record<string, any>\n },\n ) => DOMOutputSpec)\n | null\n\n /**\n * renders the node as text\n * @example renderText: () => 'foo\n */\n renderText?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['renderText']\n editor?: Editor\n },\n props: {\n node: ProseMirrorNode\n pos: number\n parent: ProseMirrorNode\n index: number\n },\n ) => string)\n | null\n\n /**\n * Add attributes to the node\n * @example addAttributes: () => ({ class: 'foo' })\n */\n addAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['addAttributes']\n editor?: Editor\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n }) => Attributes | {}\n}\n\n/**\n * The Node class is used to create custom node extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {\n type = 'node'\n\n /**\n * Create a new Node instance\n * @param config - Node configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>) = {}) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Node<O, S>(resolvedConfig)\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Node<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig extends NodeConfig<ExtendedOptions, ExtendedStorage> = NodeConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: NodeType\n }>),\n ): Node<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Node<ExtendedOptions, ExtendedStorage>\n }\n}\n","import { NodeSelection } from '@tiptap/pm/state'\nimport type { NodeView as ProseMirrorNodeView, ViewMutationRecord } from '@tiptap/pm/view'\n\nimport type { Editor as CoreEditor } from './Editor.js'\nimport type { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } from './types.js'\nimport { isAndroid } from './utilities/isAndroid.js'\nimport { isiOS } from './utilities/isiOS.js'\n\n/**\n * Node views are used to customize the rendered DOM structure of a node.\n * @see https://tiptap.dev/guide/node-views\n */\nexport class NodeView<\n Component,\n NodeEditor extends CoreEditor = CoreEditor,\n Options extends NodeViewRendererOptions = NodeViewRendererOptions,\n> implements ProseMirrorNodeView\n{\n component: Component\n\n editor: NodeEditor\n\n options: Options\n\n extension: NodeViewRendererProps['extension']\n\n node: NodeViewRendererProps['node']\n\n decorations: NodeViewRendererProps['decorations']\n\n innerDecorations: NodeViewRendererProps['innerDecorations']\n\n view: NodeViewRendererProps['view']\n\n getPos: NodeViewRendererProps['getPos']\n\n HTMLAttributes: NodeViewRendererProps['HTMLAttributes']\n\n isDragging = false\n\n constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>) {\n this.component = component\n this.editor = props.editor as NodeEditor\n this.options = {\n stopEvent: null,\n ignoreMutation: null,\n ...options,\n } as Options\n this.extension = props.extension\n this.node = props.node\n this.decorations = props.decorations as DecorationWithType[]\n this.innerDecorations = props.innerDecorations\n this.view = props.view\n this.HTMLAttributes = props.HTMLAttributes\n this.getPos = props.getPos\n this.mount()\n }\n\n mount() {\n // eslint-disable-next-line\n return\n }\n\n get dom(): HTMLElement {\n return this.editor.view.dom as HTMLElement\n }\n\n get contentDOM(): HTMLElement | null {\n return null\n }\n\n onDragStart(event: DragEvent) {\n const { view } = this.editor\n const target = event.target as HTMLElement\n\n // get the drag handle element\n // `closest` is not available for text nodes so we may have to use its parent\n const dragHandle =\n target.nodeType === 3 ? target.parentElement?.closest('[data-drag-handle]') : target.closest('[data-drag-handle]')\n\n if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {\n return\n }\n\n let x = 0\n let y = 0\n\n // calculate offset for drag element if we use a different drag handle element\n if (this.dom !== dragHandle) {\n const domBox = this.dom.getBoundingClientRect()\n const handleBox = dragHandle.getBoundingClientRect()\n\n // In React, we have to go through nativeEvent to reach offsetX/offsetY.\n const offsetX = event.offsetX ?? (event as any).nativeEvent?.offsetX\n const offsetY = event.offsetY ?? (event as any).nativeEvent?.offsetY\n\n x = handleBox.x - domBox.x + offsetX\n y = handleBox.y - domBox.y + offsetY\n }\n\n const clonedNode = this.dom.cloneNode(true) as HTMLElement\n\n // Preserve the visual size of the original when using the clone as\n // the drag image.\n try {\n const domBox = this.dom.getBoundingClientRect()\n clonedNode.style.width = `${Math.round(domBox.width)}px`\n clonedNode.style.height = `${Math.round(domBox.height)}px`\n clonedNode.style.boxSizing = 'border-box'\n // Ensure the clone doesn't capture pointer events while offscreen\n clonedNode.style.pointerEvents = 'none'\n } catch {\n // ignore measurement errors (e.g. if element not in DOM)\n }\n\n // Some browsers (notably Safari) require the element passed to\n // setDragImage to be present in the DOM. Using a detached node can\n // cause the drag to immediately end.\n let dragImageWrapper: HTMLElement | null = null\n\n try {\n dragImageWrapper = document.createElement('div')\n dragImageWrapper.style.position = 'absolute'\n dragImageWrapper.style.top = '-9999px'\n dragImageWrapper.style.left = '-9999px'\n dragImageWrapper.style.pointerEvents = 'none'\n dragImageWrapper.appendChild(clonedNode)\n document.body.appendChild(dragImageWrapper)\n\n event.dataTransfer?.setDragImage(clonedNode, x, y)\n } finally {\n // Remove the wrapper on the next tick so the browser can use the\n // element as the drag image. A 0ms timeout is enough in practice.\n if (dragImageWrapper) {\n setTimeout(() => {\n try {\n dragImageWrapper?.remove()\n } catch {\n // ignore removal errors\n }\n }, 0)\n }\n }\n\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n // we need to tell ProseMirror that we want to move the whole node\n // so we create a NodeSelection\n const selection = NodeSelection.create(view.state.doc, pos)\n const transaction = view.state.tr.setSelection(selection)\n\n view.dispatch(transaction)\n }\n\n stopEvent(event: Event) {\n if (!this.dom) {\n return false\n }\n\n if (typeof this.options.stopEvent === 'function') {\n return this.options.stopEvent({ event })\n }\n\n const target = event.target as HTMLElement\n const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target)\n\n // any event from child nodes should be handled by ProseMirror\n if (!isInElement) {\n return false\n }\n\n const isDragEvent = event.type.startsWith('drag')\n const isDropEvent = event.type === 'drop'\n const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName) || target.isContentEditable\n\n // any input event within node views should be ignored by ProseMirror\n if (isInput && !isDropEvent && !isDragEvent) {\n return true\n }\n\n const { isEditable } = this.editor\n const { isDragging } = this\n const isDraggable = !!this.node.type.spec.draggable\n const isSelectable = NodeSelection.isSelectable(this.node)\n const isCopyEvent = event.type === 'copy'\n const isPasteEvent = event.type === 'paste'\n const isCutEvent = event.type === 'cut'\n const isClickEvent = event.type === 'mousedown'\n\n // ProseMirror tries to drag selectable nodes\n // even if `draggable` is set to `false`\n // this fix prevents that\n if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) {\n event.preventDefault()\n }\n\n if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) {\n event.preventDefault()\n return false\n }\n\n // we have to store that dragging started\n if (isDraggable && isEditable && !isDragging && isClickEvent) {\n const dragHandle = target.closest('[data-drag-handle]')\n const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle))\n\n if (isValidDragHandle) {\n this.isDragging = true\n\n document.addEventListener(\n 'dragend',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n\n document.addEventListener(\n 'drop',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n\n document.addEventListener(\n 'mouseup',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n }\n }\n\n // these events are handled by prosemirror\n if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || (isClickEvent && isSelectable)) {\n return false\n }\n\n return true\n }\n\n /**\n * Called when a DOM [mutation](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) or a selection change happens within the view.\n * @return `false` if the editor should re-read the selection or re-parse the range around the mutation\n * @return `true` if it can safely be ignored.\n */\n ignoreMutation(mutation: ViewMutationRecord) {\n if (!this.dom || !this.contentDOM) {\n return true\n }\n\n if (typeof this.options.ignoreMutation === 'function') {\n return this.options.ignoreMutation({ mutation })\n }\n\n // a leaf/atom node is like a black box for ProseMirror\n // and should be fully handled by the node view\n if (this.node.isLeaf || this.node.isAtom) {\n return true\n }\n\n // ProseMirror should handle any selections\n if (mutation.type === 'selection') {\n return false\n }\n\n // try to prevent a bug on iOS and Android that will break node views on enter\n // this is because ProseMirror can’t preventDispatch on enter\n // this will lead to a re-render of the node view on enter\n // see: https://github.com/ueberdosis/tiptap/issues/1214\n // see: https://github.com/ueberdosis/tiptap/issues/2534\n if (\n this.dom.contains(mutation.target) &&\n mutation.type === 'childList' &&\n (isiOS() || isAndroid()) &&\n this.editor.isFocused\n ) {\n const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]\n\n // we’ll check if every changed node is contentEditable\n // to make sure it’s probably mutated by ProseMirror\n if (changedNodes.every(node => node.isContentEditable)) {\n return false\n }\n }\n\n // we will allow mutation contentDOM with attributes\n // so we can for example adding classes within our node view\n if (this.contentDOM === mutation.target && mutation.type === 'attributes') {\n return true\n }\n\n // ProseMirror should handle any changes within contentDOM\n if (this.contentDOM.contains(mutation.target)) {\n return false\n }\n\n return true\n }\n\n /**\n * Update the attributes of the prosemirror node.\n */\n updateAttributes(attributes: Record<string, any>): void {\n this.editor.commands.command(({ tr }) => {\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return false\n }\n\n tr.setNodeMarkup(pos, undefined, {\n ...this.node.attrs,\n ...attributes,\n })\n\n return true\n })\n }\n\n /**\n * Delete the node.\n */\n deleteNode(): void {\n const from = this.getPos()\n\n if (typeof from !== 'number') {\n return\n }\n const to = from + this.node.nodeSize\n\n this.editor.commands.deleteRange({ from, to })\n }\n}\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarksBetween } from '../helpers/getMarksBetween.js'\nimport type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an paste rule that adds a mark when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport function markPasteRule(config: {\n find: PasteRuleFinder\n type: MarkType\n getAttributes?:\n | Record<string, any>\n | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)\n | false\n | null\n}) {\n return new PasteRule({\n find: config.find,\n handler: ({ state, range, match, pasteEvent }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const { tr } = state\n const captureGroup = match[match.length - 1]\n const fullMatch = match[0]\n let markEnd = range.to\n\n if (captureGroup) {\n const startSpaces = fullMatch.search(/\\S/)\n const textStart = range.from + fullMatch.indexOf(captureGroup)\n const textEnd = textStart + captureGroup.length\n\n const excludedMarks = getMarksBetween(range.from, range.to, state.doc)\n .filter(item => {\n // @ts-ignore\n const excluded = item.mark.type.excluded as MarkType[]\n\n return excluded.find(type => type === config.type && type !== item.mark.type)\n })\n .filter(item => item.to > textStart)\n\n if (excludedMarks.length) {\n return null\n }\n\n if (textEnd < range.to) {\n tr.delete(textEnd, range.to)\n }\n\n if (textStart > range.from) {\n tr.delete(range.from + startSpaces, textStart)\n }\n\n markEnd = range.from + startSpaces + captureGroup.length\n\n tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}))\n\n tr.removeStoredMark(config.type)\n }\n },\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\nimport type { ExtendedRegExpMatchArray, JSONContent } from '../types.js'\nimport { callOrReturn } from '../utilities/index.js'\n\n/**\n * Build an paste rule that adds a node when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/api/paste-rules\n */\nexport function nodePasteRule(config: {\n find: PasteRuleFinder\n type: NodeType\n getAttributes?:\n | Record<string, any>\n | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)\n | false\n | null\n getContent?: JSONContent[] | ((attrs: Record<string, any>) => JSONContent[]) | false | null\n}) {\n return new PasteRule({\n find: config.find,\n handler({ match, chain, range, pasteEvent }) {\n const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)\n const content = callOrReturn(config.getContent, undefined, attributes)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const node = { type: config.type.name, attrs: attributes } as JSONContent\n\n if (content) {\n node.content = content\n }\n\n if (match.input) {\n chain().deleteRange(range).insertContentAt(range.from, node)\n }\n },\n })\n}\n","import type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\n\n/**\n * Build an paste rule that replaces text when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport function textPasteRule(config: { find: PasteRuleFinder; replace: string }) {\n return new PasteRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n let insert = config.replace\n let start = range.from\n const end = range.to\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n\n insert += match[0].slice(offset + match[1].length)\n start += offset\n\n const cutOff = start - end\n\n if (cutOff > 0) {\n insert = match[0].slice(offset - cutOff, offset) + insert\n start = end\n }\n }\n\n state.tr.insertText(insert, start, end)\n },\n })\n}\n","import type { Transaction } from '@tiptap/pm/state'\n\nexport interface TrackerResult {\n position: number\n deleted: boolean\n}\n\nexport class Tracker {\n transaction: Transaction\n\n currentStep: number\n\n constructor(transaction: Transaction) {\n this.transaction = transaction\n this.currentStep = this.transaction.steps.length\n }\n\n map(position: number): TrackerResult {\n let deleted = false\n\n const mappedPosition = this.transaction.steps.slice(this.currentStep).reduce((newPosition, step) => {\n const mapResult = step.getMap().mapResult(newPosition)\n\n if (mapResult.deleted) {\n deleted = true\n }\n\n return mapResult.pos\n }, position)\n\n return {\n position: mappedPosition,\n deleted,\n }\n }\n}\n","import { Mark, mergeAttributes } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/core'\nimport type { CommentWithUser } from './comments'\n\nexport interface CommentMarkOptions {\n onCommentClick?: (commentId: string) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n comment: {\n setComment: (commentId: string) => ReturnType\n unsetComment: (commentId: string) => ReturnType\n }\n }\n}\n\nexport const CommentMark = Mark.create<CommentMarkOptions>({\n name: 'comment',\n\n addOptions() {\n return {\n onCommentClick: undefined,\n }\n },\n\n addAttributes() {\n return {\n commentId: {\n default: null,\n parseHTML: (element) => element.getAttribute('data-comment-id'),\n renderHTML: (attributes) => ({\n 'data-comment-id': attributes.commentId,\n }),\n },\n }\n },\n\n parseHTML() {\n return [{ tag: 'mark[data-comment-id]' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'mark',\n mergeAttributes(HTMLAttributes, {\n class:\n 'bg-yellow-200/50 dark:bg-yellow-500/30 dark:text-foreground cursor-pointer hover:bg-yellow-300/60 dark:hover:bg-yellow-500/40 transition-colors rounded-sm',\n }),\n 0,\n ]\n },\n\n addCommands() {\n return {\n setComment:\n (commentId: string) =>\n ({ commands }) => {\n return commands.setMark(this.name, { commentId })\n },\n unsetComment:\n (commentId: string) =>\n ({ tr, state }) => {\n const { doc } = state\n let found = false\n\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === this.name && mark.attrs.commentId === commentId) {\n tr.removeMark(pos, pos + node.nodeSize, mark.type)\n found = true\n }\n })\n })\n\n return found\n },\n }\n },\n\n addProseMirrorPlugins() {\n const { onCommentClick } = this.options\n\n return [\n new Plugin({\n key: new PluginKey('commentClick'),\n props: {\n handleClick(view, pos) {\n if (!onCommentClick) return false\n\n const { state } = view\n const $pos = state.doc.resolve(pos)\n const marks = $pos.marks()\n\n const commentMark = marks.find((mark) => mark.type.name === 'comment')\n if (commentMark && commentMark.attrs.commentId) {\n // Blur the editor to prevent keyboard popup on mobile\n ;(view.dom as HTMLElement).blur()\n onCommentClick(commentMark.attrs.commentId)\n return true\n }\n\n return false\n },\n },\n }),\n ]\n },\n})\n\n/**\n * Apply comment mark to the current selection\n */\nexport function addCommentMark(\n editor: Editor,\n commentId: string,\n from: number,\n to: number\n): void {\n // Guard against editor not being ready\n if (!editor.view || editor.isDestroyed) {\n console.warn('Cannot add comment mark: editor not ready')\n return\n }\n \n editor\n .chain()\n .setTextSelection({ from, to })\n .setComment(commentId)\n .run()\n}\n\n/**\n * Remove comment mark from the document\n */\nexport function removeCommentMark(editor: Editor, commentId: string): void {\n if (!editor.view || editor.isDestroyed) return\n editor.chain().unsetComment(commentId).run()\n}\n\n/**\n * Re-apply comment marks based on quoted text matching.\n * Called when loading a post with existing comments.\n */\nexport function applyCommentMarks(\n editor: Editor,\n comments: CommentWithUser[]\n): void {\n if (!editor.view || editor.isDestroyed) return\n \n const { doc } = editor.state\n const textContent = doc.textContent\n\n comments.forEach((comment) => {\n if (!comment.quotedText || comment.parentId || comment.resolved) return // Skip replies\n\n const index = textContent.indexOf(comment.quotedText)\n if (index === -1) return // Text not found\n\n // Find the actual position in the document\n let currentPos = 0\n let startPos: number | null = null\n let endPos: number | null = null\n\n doc.descendants((node, pos) => {\n if (startPos !== null && endPos !== null) return false\n\n if (node.isText && node.text) {\n const nodeStart = currentPos\n const nodeEnd = currentPos + node.text.length\n\n if (startPos === null && nodeEnd > index) {\n // Start is in this node\n const offsetInNode = index - nodeStart\n startPos = pos + offsetInNode\n }\n\n if (startPos !== null && endPos === null) {\n const targetEnd = index + comment.quotedText.length\n if (nodeEnd >= targetEnd) {\n // End is in this node\n const offsetInNode = targetEnd - nodeStart\n endPos = pos + offsetInNode\n }\n }\n\n currentPos = nodeEnd\n }\n\n return true\n })\n\n if (startPos !== null && endPos !== null) {\n editor\n .chain()\n .setTextSelection({ from: startPos, to: endPos })\n .setComment(comment.id)\n .setTextSelection(endPos) // Deselect\n .run()\n }\n })\n}\n\n/**\n * Scroll to a comment mark in the editor\n */\nexport function scrollToComment(editor: Editor, commentId: string): void {\n if (!editor.view || editor.isDestroyed) return\n \n const { doc } = editor.state\n\n doc.descendants((node, pos) => {\n const commentMark = node.marks.find(\n (mark) => mark.type.name === 'comment' && mark.attrs.commentId === commentId\n )\n\n if (commentMark) {\n editor.chain().setTextSelection(pos).run()\n\n // Scroll to the selection\n const view = editor.view\n const coords = view.coordsAtPos(pos)\n const editorRect = view.dom.getBoundingClientRect()\n\n if (coords.top < editorRect.top || coords.bottom > editorRect.bottom) {\n view.dom.scrollIntoView({ behavior: 'smooth', block: 'center' })\n }\n\n return false // Stop iteration\n }\n\n return true\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAQa,2BAwDA,uBAmCA,0BAgCA,6BAyDA,uBAmBA,oBA+CA,wBA0CA,8BA+CA;AAvVb;AAAA;AAAA;AAQO,IAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDlC,IAAM,wBAAwB;AAAA;AAAA;AAAA;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eAAe,QAAQ;AAC7B,qBAAW,MAAM;AAAA,QACnB;AAEA,YAAI,aAAa,QAAQ,WAAW,MAAM;AACxC,gBAAM,YAAY,QAAQ,QAAQ,WAAW;AAC7C,cAAI,WAAW,WAAW;AAExB,kBAAM,eAAe,YAAY;AACjC,qBAAS,MAAM;AAAA,UACjB;AAAA,QACF;AAEA,qBAAa;AAAA,MACf;AAEA,aAAO;AAAA,IACT,CAAC;AAED,QAAI,aAAa,QAAQ,WAAW,MAAM;AACxC,aACG,MAAM,EACN,iBAAiB,EAAE,MAAM,UAAU,IAAI,OAAO,CAAC,EAC/C,WAAW,QAAQ,EAAE,EACrB,iBAAiB,MAAM,EACvB,IAAI;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAKO,SAAS,gBAAgB,QAAgB,WAAyB;AACvE,MAAI,CAAC,OAAO,QAAQ,OAAO,YAAa;AAExC,QAAM,EAAE,IAAI,IAAI,OAAO;AAEvB,MAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,UAAM,cAAc,KAAK,MAAM;AAAA,MAC7B,CAAC,SAAS,KAAK,KAAK,SAAS,aAAa,KAAK,MAAM,cAAc;AAAA,IACrE;AAEA,QAAI,aAAa;AACf,aAAO,MAAM,EAAE,iBAAiB,GAAG,EAAE,IAAI;AAGzC,YAAM,OAAO,OAAO;AACpB,YAAM,SAAS,KAAK,YAAY,GAAG;AACnC,YAAM,aAAa,KAAK,IAAI,sBAAsB;AAElD,UAAI,OAAO,MAAM,WAAW,OAAO,OAAO,SAAS,WAAW,QAAQ;AACpE,aAAK,IAAI,eAAe,EAAE,UAAU,UAAU,OAAO,SAAS,CAAC;AAAA,MACjE;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AACH;","names":["OpenAI","Anthropic","response","content","extractUrls","jsonResponse","jsonResponse","jsonResponse","jsonResponse","wordCount","expandPlanStream","generateStream","generate","chatStream","buildRewritePrompt","createStream","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","Parser","TurndownService","sanitizeHtml","generateUniqueSlug","import_commands","import_state","import_model","import_transform","import_schema_list","command","run","__export","originalCreateParagraphNear","originalDeleteSelection","originalExitCode","mark","TextSelection","ProseMirrorNode","parser","Selection","Fragment","isTextSelection","originalJoinUp","originalJoinDown","originalJoinBackward","originalJoinForward","joinPoint","originalCommand","isActive","originalLift","originalLiftEmptyBlock","originalLiftListItem","originalNewlineInCode","originalSelectNodeBackward","originalSelectNodeForward","originalSelectParentNode","originalSelectTextblockEnd","originalSelectTextblockStart","document","style","Schema","range","NodeSelection","TextSelection","originalSinkListItem","first","Fragment","newNextTypeAttributes","nextType","canSplit","isActive","originalWrapIn","originalWrapInList","Fragment","run","Plugin","Fragment","from","to","__export","range","_a","_b","_c","PluginKey","Selection","tr","__export","parseAttributes","serializeAttributes","h","nextIndent","import_state"]}
1
+ {"version":3,"sources":["../src/ai/prompts.ts","../src/ai/models.ts","../src/ai/provider.ts","../src/ai/builders.ts","../src/lib/url-extractor.ts","../src/ai/generate.ts","../src/ai/chat.ts","../src/index.ts","../src/data/posts.ts","../src/data/comments.ts","../src/data/factory.ts","../src/data/tags.ts","../src/data/revisions.ts","../src/data/ai-settings.ts","../src/data/topics.ts","../src/data/news-items.ts","../src/data/users.ts","../src/api/posts.ts","../src/api/utils.ts","../src/api/comments.ts","../src/api/tags.ts","../src/api/ai.ts","../src/api/upload.ts","../src/api/topics.ts","../src/api/users.ts","../src/api/admin.ts","../src/api/settings.ts","../src/api/revisions.ts","../src/api/chat-history.ts","../src/api/index.ts","../src/auto-draft/rss.ts","../src/auto-draft/keywords.ts","../src/ai/index.ts","../src/ai/parse.ts","../src/lib/markdown.ts","../src/auto-draft/runner.ts","../src/types/config.ts","../src/server.ts","../src/schema.ts","../src/lib/format.ts","../src/lib/seo.ts","../src/lib/comments.ts","../node_modules/@tiptap/core/src/helpers/createChainableState.ts","../node_modules/@tiptap/core/src/CommandManager.ts","../node_modules/@tiptap/core/src/commands/index.ts","../node_modules/@tiptap/core/src/commands/blur.ts","../node_modules/@tiptap/core/src/commands/clearContent.ts","../node_modules/@tiptap/core/src/commands/clearNodes.ts","../node_modules/@tiptap/core/src/commands/command.ts","../node_modules/@tiptap/core/src/commands/createParagraphNear.ts","../node_modules/@tiptap/core/src/commands/cut.ts","../node_modules/@tiptap/core/src/commands/deleteCurrentNode.ts","../node_modules/@tiptap/core/src/helpers/getNodeType.ts","../node_modules/@tiptap/core/src/commands/deleteNode.ts","../node_modules/@tiptap/core/src/commands/deleteRange.ts","../node_modules/@tiptap/core/src/commands/deleteSelection.ts","../node_modules/@tiptap/core/src/commands/enter.ts","../node_modules/@tiptap/core/src/commands/exitCode.ts","../node_modules/@tiptap/core/src/commands/extendMarkRange.ts","../node_modules/@tiptap/core/src/utilities/isRegExp.ts","../node_modules/@tiptap/core/src/utilities/objectIncludes.ts","../node_modules/@tiptap/core/src/helpers/getMarkRange.ts","../node_modules/@tiptap/core/src/helpers/getMarkType.ts","../node_modules/@tiptap/core/src/commands/first.ts","../node_modules/@tiptap/core/src/helpers/isTextSelection.ts","../node_modules/@tiptap/core/src/helpers/resolveFocusPosition.ts","../node_modules/@tiptap/core/src/utilities/minMax.ts","../node_modules/@tiptap/core/src/utilities/isAndroid.ts","../node_modules/@tiptap/core/src/utilities/isiOS.ts","../node_modules/@tiptap/core/src/utilities/isSafari.ts","../node_modules/@tiptap/core/src/commands/focus.ts","../node_modules/@tiptap/core/src/commands/forEach.ts","../node_modules/@tiptap/core/src/commands/insertContent.ts","../node_modules/@tiptap/core/src/commands/insertContentAt.ts","../node_modules/@tiptap/core/src/helpers/createNodeFromContent.ts","../node_modules/@tiptap/core/src/utilities/elementFromString.ts","../node_modules/@tiptap/core/src/helpers/selectionToInsertionEnd.ts","../node_modules/@tiptap/core/src/commands/join.ts","../node_modules/@tiptap/core/src/commands/joinItemBackward.ts","../node_modules/@tiptap/core/src/commands/joinItemForward.ts","../node_modules/@tiptap/core/src/commands/joinTextblockBackward.ts","../node_modules/@tiptap/core/src/commands/joinTextblockForward.ts","../node_modules/@tiptap/core/src/utilities/isMacOS.ts","../node_modules/@tiptap/core/src/commands/keyboardShortcut.ts","../node_modules/@tiptap/core/src/commands/lift.ts","../node_modules/@tiptap/core/src/helpers/isNodeActive.ts","../node_modules/@tiptap/core/src/commands/liftEmptyBlock.ts","../node_modules/@tiptap/core/src/commands/liftListItem.ts","../node_modules/@tiptap/core/src/commands/newlineInCode.ts","../node_modules/@tiptap/core/src/helpers/getSchemaTypeNameByName.ts","../node_modules/@tiptap/core/src/utilities/deleteProps.ts","../node_modules/@tiptap/core/src/commands/resetAttributes.ts","../node_modules/@tiptap/core/src/commands/scrollIntoView.ts","../node_modules/@tiptap/core/src/commands/selectAll.ts","../node_modules/@tiptap/core/src/commands/selectNodeBackward.ts","../node_modules/@tiptap/core/src/commands/selectNodeForward.ts","../node_modules/@tiptap/core/src/commands/selectParentNode.ts","../node_modules/@tiptap/core/src/commands/selectTextblockEnd.ts","../node_modules/@tiptap/core/src/commands/selectTextblockStart.ts","../node_modules/@tiptap/core/src/helpers/createDocument.ts","../node_modules/@tiptap/core/src/commands/setContent.ts","../node_modules/@tiptap/core/src/helpers/getMarkAttributes.ts","../node_modules/@tiptap/core/src/helpers/combineTransactionSteps.ts","../node_modules/@tiptap/core/src/helpers/defaultBlockAt.ts","../node_modules/@tiptap/core/src/helpers/findChildren.ts","../node_modules/@tiptap/core/src/helpers/findChildrenInRange.ts","../node_modules/@tiptap/core/src/helpers/findParentNodeClosestToPos.ts","../node_modules/@tiptap/core/src/helpers/findParentNode.ts","../node_modules/@tiptap/core/src/helpers/getExtensionField.ts","../node_modules/@tiptap/core/src/helpers/flattenExtensions.ts","../node_modules/@tiptap/core/src/helpers/generateHTML.ts","../node_modules/@tiptap/core/src/helpers/getHTMLFromFragment.ts","../node_modules/@tiptap/core/src/helpers/getSchemaByResolvedExtensions.ts","../node_modules/@tiptap/core/src/utilities/isFunction.ts","../node_modules/@tiptap/core/src/utilities/callOrReturn.ts","../node_modules/@tiptap/core/src/utilities/isEmptyObject.ts","../node_modules/@tiptap/core/src/helpers/splitExtensions.ts","../node_modules/@tiptap/core/src/helpers/getAttributesFromExtensions.ts","../node_modules/@tiptap/core/src/utilities/mergeAttributes.ts","../node_modules/@tiptap/core/src/helpers/getRenderedAttributes.ts","../node_modules/@tiptap/core/src/utilities/fromString.ts","../node_modules/@tiptap/core/src/helpers/injectExtensionAttributesToParseRule.ts","../node_modules/@tiptap/core/src/utilities/findDuplicates.ts","../node_modules/@tiptap/core/src/helpers/sortExtensions.ts","../node_modules/@tiptap/core/src/helpers/resolveExtensions.ts","../node_modules/@tiptap/core/src/helpers/getSchema.ts","../node_modules/@tiptap/core/src/helpers/generateJSON.ts","../node_modules/@tiptap/core/src/helpers/generateText.ts","../node_modules/@tiptap/core/src/helpers/getTextBetween.ts","../node_modules/@tiptap/core/src/helpers/getText.ts","../node_modules/@tiptap/core/src/helpers/getTextSerializersFromSchema.ts","../node_modules/@tiptap/core/src/helpers/getNodeAttributes.ts","../node_modules/@tiptap/core/src/helpers/getAttributes.ts","../node_modules/@tiptap/core/src/utilities/removeDuplicates.ts","../node_modules/@tiptap/core/src/helpers/getChangedRanges.ts","../node_modules/@tiptap/core/src/helpers/getDebugJSON.ts","../node_modules/@tiptap/core/src/helpers/getMarksBetween.ts","../node_modules/@tiptap/core/src/helpers/getNodeAtPosition.ts","../node_modules/@tiptap/core/src/helpers/getSchemaTypeByName.ts","../node_modules/@tiptap/core/src/helpers/getSplittedAttributes.ts","../node_modules/@tiptap/core/src/helpers/getTextContentFromNodes.ts","../node_modules/@tiptap/core/src/helpers/isMarkActive.ts","../node_modules/@tiptap/core/src/helpers/isActive.ts","../node_modules/@tiptap/core/src/helpers/isAtEndOfNode.ts","../node_modules/@tiptap/core/src/helpers/isAtStartOfNode.ts","../node_modules/@tiptap/core/src/helpers/isExtensionRulesEnabled.ts","../node_modules/@tiptap/core/src/helpers/isList.ts","../node_modules/@tiptap/core/src/helpers/isNodeEmpty.ts","../node_modules/@tiptap/core/src/helpers/isNodeSelection.ts","../node_modules/@tiptap/core/src/helpers/MappablePosition.ts","../node_modules/@tiptap/core/src/helpers/posToDOMRect.ts","../node_modules/@tiptap/core/src/helpers/rewriteUnknownContent.ts","../node_modules/@tiptap/core/src/commands/setMark.ts","../node_modules/@tiptap/core/src/commands/setMeta.ts","../node_modules/@tiptap/core/src/commands/setNode.ts","../node_modules/@tiptap/core/src/commands/setNodeSelection.ts","../node_modules/@tiptap/core/src/commands/setTextDirection.ts","../node_modules/@tiptap/core/src/commands/setTextSelection.ts","../node_modules/@tiptap/core/src/commands/sinkListItem.ts","../node_modules/@tiptap/core/src/commands/splitBlock.ts","../node_modules/@tiptap/core/src/commands/splitListItem.ts","../node_modules/@tiptap/core/src/commands/toggleList.ts","../node_modules/@tiptap/core/src/commands/toggleMark.ts","../node_modules/@tiptap/core/src/commands/toggleNode.ts","../node_modules/@tiptap/core/src/commands/toggleWrap.ts","../node_modules/@tiptap/core/src/commands/undoInputRule.ts","../node_modules/@tiptap/core/src/commands/unsetAllMarks.ts","../node_modules/@tiptap/core/src/commands/unsetMark.ts","../node_modules/@tiptap/core/src/commands/unsetTextDirection.ts","../node_modules/@tiptap/core/src/commands/updateAttributes.ts","../node_modules/@tiptap/core/src/commands/wrapIn.ts","../node_modules/@tiptap/core/src/commands/wrapInList.ts","../node_modules/@tiptap/core/src/Editor.ts","../node_modules/@tiptap/core/src/EventEmitter.ts","../node_modules/@tiptap/core/src/ExtensionManager.ts","../node_modules/@tiptap/core/src/InputRule.ts","../node_modules/@tiptap/core/src/utilities/isPlainObject.ts","../node_modules/@tiptap/core/src/utilities/mergeDeep.ts","../node_modules/@tiptap/core/src/Extendable.ts","../node_modules/@tiptap/core/src/Mark.ts","../node_modules/@tiptap/core/src/PasteRule.ts","../node_modules/@tiptap/core/src/utilities/isNumber.ts","../node_modules/@tiptap/core/src/extensions/index.ts","../node_modules/@tiptap/core/src/extensions/clipboardTextSerializer.ts","../node_modules/@tiptap/core/src/Extension.ts","../node_modules/@tiptap/core/src/extensions/commands.ts","../node_modules/@tiptap/core/src/extensions/delete.ts","../node_modules/@tiptap/core/src/extensions/drop.ts","../node_modules/@tiptap/core/src/extensions/editable.ts","../node_modules/@tiptap/core/src/extensions/focusEvents.ts","../node_modules/@tiptap/core/src/extensions/keymap.ts","../node_modules/@tiptap/core/src/extensions/paste.ts","../node_modules/@tiptap/core/src/extensions/tabindex.ts","../node_modules/@tiptap/core/src/extensions/textDirection.ts","../node_modules/@tiptap/core/src/NodePos.ts","../node_modules/@tiptap/core/src/style.ts","../node_modules/@tiptap/core/src/utilities/createStyleTag.ts","../node_modules/@tiptap/core/src/inputRules/markInputRule.ts","../node_modules/@tiptap/core/src/inputRules/nodeInputRule.ts","../node_modules/@tiptap/core/src/inputRules/textblockTypeInputRule.ts","../node_modules/@tiptap/core/src/inputRules/textInputRule.ts","../node_modules/@tiptap/core/src/inputRules/wrappingInputRule.ts","../node_modules/@tiptap/core/src/jsx-runtime.ts","../node_modules/@tiptap/core/src/lib/ResizableNodeView.ts","../node_modules/@tiptap/core/src/utilities/canInsertNode.ts","../node_modules/@tiptap/core/src/utilities/escapeForRegEx.ts","../node_modules/@tiptap/core/src/utilities/isString.ts","../node_modules/@tiptap/core/src/utilities/markdown/index.ts","../node_modules/@tiptap/core/src/utilities/markdown/attributeUtils.ts","../node_modules/@tiptap/core/src/utilities/markdown/createAtomBlockMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/createBlockMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/createInlineMarkdownSpec.ts","../node_modules/@tiptap/core/src/utilities/markdown/parseIndentedBlocks.ts","../node_modules/@tiptap/core/src/utilities/markdown/renderNestedMarkdownContent.ts","../node_modules/@tiptap/core/src/MarkView.ts","../node_modules/@tiptap/core/src/Node.ts","../node_modules/@tiptap/core/src/NodeView.ts","../node_modules/@tiptap/core/src/pasteRules/markPasteRule.ts","../node_modules/@tiptap/core/src/pasteRules/nodePasteRule.ts","../node_modules/@tiptap/core/src/pasteRules/textPasteRule.ts","../node_modules/@tiptap/core/src/Tracker.ts","../src/lib/comment-mark.ts"],"sourcesContent":["// ============================================\n// GENERATION PROMPTS\n// ============================================\n\n/**\n * Default template for essay generation.\n * Placeholders: {{RULES}}, {{STYLE_EXAMPLES}}, {{WORD_COUNT}}\n */\nexport const DEFAULT_GENERATE_TEMPLATE = `<system>\n<role>Expert essay writer creating engaging, thoughtful content</role>\n\n<critical>\nALWAYS output a complete essay. NEVER respond conversationally.\n- Do NOT ask questions or request clarification\n- Do NOT say \"Here is your essay\" or similar preamble\n- Do NOT explain what you're going to write\n- If the prompt is vague, make creative choices and proceed\n- Output ONLY the essay in markdown format\n</critical>\n\n<rules>\n{{RULES}}\n</rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<constraints>\n<word_count>{{WORD_COUNT}}</word_count>\n</constraints>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Your Title Here]\nLine 2: *[Your subtitle here]*\nLine 3: (blank line)\nLine 4+: Essay body in markdown\n\n<title_guidelines>\n- Be SPECIFIC, not generic (avoid \"The Power of\", \"Why X Matters\", \"A Guide to\")\n- Include a concrete detail, angle, or unexpected element\n- Create curiosity or make a bold claim\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that hooks the reader\n- Tease the main argument or reveal a key insight\n- Create tension, curiosity, or promise value\n- Make readers want to continue reading\n</subtitle_guidelines>\n</output_format>\n</system>`\n\n// ============================================\n// CHAT PROMPTS\n// ============================================\n\n/**\n * Default template for chat interactions.\n * Placeholders: {{CHAT_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}, {{ESSAY_CONTEXT}}\n */\nexport const DEFAULT_CHAT_TEMPLATE = `<system>\n<role>Helpful writing assistant for essay creation and editing</role>\n\n<chat_rules>\n{{CHAT_RULES}}\n</chat_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<context>\n{{ESSAY_CONTEXT}}\n</context>\n\n<behavior>\n- Be concise and actionable\n- When suggesting edits, be specific about what to change\n- Match the author's voice and style when writing\n- Ask clarifying questions if the request is ambiguous\n</behavior>\n</system>`\n\n// ============================================\n// REWRITE PROMPTS\n// ============================================\n\n/**\n * Default template for text rewriting.\n * Placeholders: {{REWRITE_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}\n */\nexport const DEFAULT_REWRITE_TEMPLATE = `<system>\n<role>Writing assistant that improves text quality</role>\n\n<rewrite_rules>\n{{REWRITE_RULES}}\n</rewrite_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<behavior>\n- Preserve the original meaning exactly\n- Improve clarity, flow, and readability\n- Fix grammar and punctuation issues\n- Maintain the author's voice and tone\n- Output only the improved text, no explanations\n</behavior>\n</system>`\n\n// ============================================\n// AUTO-DRAFT PROMPTS\n// ============================================\n\n/**\n * Default template for auto-drafting from news articles.\n * Placeholders: {{AUTO_DRAFT_RULES}}, {{RULES}}, {{STYLE_EXAMPLES}}, {{TOPIC_NAME}}, {{ARTICLE_TITLE}}, {{ARTICLE_SUMMARY}}, {{ARTICLE_URL}}, {{AUTO_DRAFT_WORD_COUNT}}\n */\nexport const DEFAULT_AUTO_DRAFT_TEMPLATE = `<system>\n<role>Expert essay writer creating engaging content from news articles</role>\n\n<auto_draft_rules>\n{{AUTO_DRAFT_RULES}}\n</auto_draft_rules>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<source_article>\n<topic>{{TOPIC_NAME}}</topic>\n<title>{{ARTICLE_TITLE}}</title>\n<summary>{{ARTICLE_SUMMARY}}</summary>\n<url>{{ARTICLE_URL}}</url>\n</source_article>\n\n<constraints>\n<word_count>{{AUTO_DRAFT_WORD_COUNT}}</word_count>\n</constraints>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Your Title Here]\nLine 2: *[Your subtitle here]*\nLine 3: (blank line)\nLine 4+: Essay body in markdown\n\n<title_guidelines>\n- Be SPECIFIC about the news angle, not generic\n- Include a concrete detail or unexpected element\n- Create curiosity or make a bold claim\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that hooks the reader\n- Tease the main argument or unique perspective\n- Create tension, curiosity, or promise value\n</subtitle_guidelines>\n</output_format>\n</system>`\n\n// ============================================\n// PLAN PROMPTS\n// ============================================\n\n/**\n * Default template for essay outline generation.\n * Placeholders: {{PLAN_RULES}}, {{STYLE_EXAMPLES}}\n */\nexport const DEFAULT_PLAN_TEMPLATE = `<system>\n<role>Writing assistant that creates essay outlines</role>\n\n<critical>\nWrap your ENTIRE response in <plan> tags. Output NOTHING outside the tags.\n</critical>\n\n<rules>\n{{PLAN_RULES}}\n</rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n</system>`\n\n/**\n * Default rules for plan generation format.\n */\nexport const DEFAULT_PLAN_RULES = `<format>\nSTRICT LIMIT: Maximum 3 bullets per section. Most sections should have 1-2 bullets.\n\n<plan>\n# Essay Title\n*One-line subtitle*\n\n## Section Name\n- Key point\n\n## Section Name\n- Key point\n- Another point\n\n## Section Name\n- Key point\n</plan>\n</format>\n\n<constraints>\n- 4-6 section headings (## lines)\n- 1-3 bullets per section — NEVER 4 or more\n- Bullets are short phrases, not sentences\n- No prose, no paragraphs, no explanations\n- When revising, output the complete updated plan\n</constraints>\n\n<title_guidelines>\n- Be SPECIFIC about the essay's angle\n- Include a concrete detail or unexpected element\n- Avoid generic patterns like \"The Power of\", \"Why X Matters\"\n- 5-12 words ideal\n</title_guidelines>\n\n<subtitle_guidelines>\n- One sentence that previews the main argument\n- Create curiosity or make a bold claim\n</subtitle_guidelines>`\n\n// ============================================\n// AGENT MODE PROMPTS\n// ============================================\n\n/**\n * Default template for agent mode (direct editing).\n * No placeholders - this is appended to chat prompt when in agent mode.\n */\nexport const DEFAULT_AGENT_TEMPLATE = `<agent_mode>\nYou are in AGENT MODE - you can directly edit the essay. Wrap edits in :::edit and ::: tags with a JSON object.\n\nEDIT COMMANDS (use valid JSON):\n\n1. Replace specific text:\n:::edit\n{\"type\": \"replace_section\", \"find\": \"exact text to find\", \"replace\": \"replacement text\"}\n:::\n\n2. Replace entire essay:\n:::edit\n{\"type\": \"replace_all\", \"title\": \"New Title\", \"subtitle\": \"New subtitle\", \"markdown\": \"Full essay content...\"}\n:::\n\n3. Insert text:\n:::edit\n{\"type\": \"insert\", \"position\": \"after\", \"find\": \"text to find\", \"replace\": \"text to insert\"}\n:::\n(position can be: \"before\", \"after\", \"start\", \"end\")\n\n4. Delete text:\n:::edit\n{\"type\": \"delete\", \"find\": \"text to delete\"}\n:::\n\nRULES:\n- Use EXACT text matches for \"find\" - copy precisely from the essay\n- One edit block per change\n- You can include multiple edit blocks in one response\n- Add brief explanation before/after edit blocks\n- Edits are applied automatically - the user will see the changes\n</agent_mode>`\n\n// ============================================\n// EXPAND PLAN PROMPTS\n// ============================================\n\n/**\n * Default template for expanding outlines into full essays.\n * Placeholders: {{RULES}}, {{STYLE_EXAMPLES}}, {{PLAN}}\n */\nexport const DEFAULT_EXPAND_PLAN_TEMPLATE = `<system>\n<role>Writing assistant that expands essay outlines into full drafts</role>\n\n<writing_rules>\n{{RULES}}\n</writing_rules>\n\n<style_reference>\n{{STYLE_EXAMPLES}}\n</style_reference>\n\n<plan_to_expand>\n{{PLAN}}\n</plan_to_expand>\n\n<output_format>\nCRITICAL: Your response MUST start with exactly this format:\n\nLine 1: # [Title from plan, refined if needed]\nLine 2: *[Subtitle from plan, refined if needed]*\nLine 3: (blank line)\nLine 4+: Essay body with ## section headings\n\n<requirements>\n- Use the section headers from the plan as H2 headings\n- Expand each section's bullet points into full paragraphs\n- Match the author's voice and style from the examples\n- Output ONLY markdown — no preamble, no \"Here is...\", no explanations\n</requirements>\n\n<title_refinement>\nIf the plan title is generic, improve it to be:\n- More specific and concrete\n- Curiosity-inducing or bold\n- 5-12 words\n</title_refinement>\n</output_format>\n</system>`\n\n// ============================================\n// SEARCH MODE PROMPTS\n// ============================================\n\n/**\n * Default template for search-only mode (fact-finding).\n * Used when user wants to research a topic before writing.\n */\nexport const DEFAULT_SEARCH_ONLY_PROMPT = `You are a research assistant helping a writer gather facts and information.\n\nYour task is to provide accurate, well-sourced information to help with essay writing.\n\nGuidelines:\n- Focus on facts, data, and specific examples\n- Include dates, names, and sources when relevant\n- Present information clearly and concisely\n- Note any conflicting information or debates\n- Suggest interesting angles or perspectives the writer might explore\n\nDo NOT write the essay - just provide research findings.`\n\n// ============================================\n// PROMPT BUILDERS\n// ============================================\n\nexport interface EssayContext {\n title?: string\n subtitle?: string\n markdown?: string\n}\n\nexport interface StyleContext {\n rules?: string\n chatRules?: string\n rewriteRules?: string\n planRules?: string\n styleExamples?: string\n}\n\n/**\n * Build the search-only prompt for fact-finding queries.\n */\nexport function buildSearchOnlyPrompt(query: string): string {\n return `${DEFAULT_SEARCH_ONLY_PROMPT}\n\nResearch Topic: ${query}`\n}\n\n/**\n * Build the full plan prompt with context and essay state.\n */\nexport function buildPlanPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n let prompt = DEFAULT_PLAN_TEMPLATE\n .replace('{{PLAN_RULES}}', context.planRules || DEFAULT_PLAN_RULES)\n .replace('{{STYLE_EXAMPLES}}', context.styleExamples || 'No style examples provided.')\n\n if (essayContext) {\n const currentState = formatEssayContext(essayContext)\n prompt += `\\n\\n<current_essay>\\n${currentState}\\n</current_essay>`\n }\n\n return prompt\n}\n\n/**\n * Build the chat prompt with essay context.\n */\nexport function buildChatPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n let essayContextStr = 'No essay currently open.'\n if (essayContext) {\n essayContextStr = formatEssayContext(essayContext)\n }\n\n return DEFAULT_CHAT_TEMPLATE\n .replace('{{CHAT_RULES}}', context.chatRules || 'Be helpful and concise.')\n .replace('{{ESSAY_CONTEXT}}', essayContextStr)\n}\n\n/**\n * Build the agent chat prompt for direct editing mode.\n */\nexport function buildAgentChatPrompt(\n context: StyleContext,\n essayContext?: EssayContext | null\n): string {\n const basePrompt = buildChatPrompt(context, essayContext)\n return basePrompt + '\\n\\n' + DEFAULT_AGENT_TEMPLATE\n}\n\n/**\n * Build the generate prompt for essay creation.\n */\nexport function buildGeneratePrompt(\n context: StyleContext,\n wordCount: number = 800\n): string {\n return DEFAULT_GENERATE_TEMPLATE\n .replace('{{RULES}}', context.rules || '')\n .replace('{{WORD_COUNT}}', wordCount.toString())\n}\n\n/**\n * Build the rewrite prompt.\n */\nexport function buildRewritePrompt(context: StyleContext): string {\n return DEFAULT_REWRITE_TEMPLATE\n .replace('{{REWRITE_RULES}}', context.rewriteRules || 'Improve clarity and flow.')\n}\n\n/**\n * Build the expand plan prompt.\n */\nexport function buildExpandPlanPrompt(\n context: StyleContext,\n plan: string\n): string {\n return DEFAULT_EXPAND_PLAN_TEMPLATE\n .replace('{{RULES}}', context.rules || '')\n .replace('{{STYLE_EXAMPLES}}', context.styleExamples || 'No style examples provided.')\n .replace('{{PLAN}}', plan)\n}\n\n/**\n * Format essay context for inclusion in prompts.\n */\nfunction formatEssayContext(essayContext: EssayContext): string {\n const parts: string[] = []\n \n if (essayContext.title) {\n parts.push(`Title: ${essayContext.title}`)\n }\n if (essayContext.subtitle) {\n parts.push(`Subtitle: ${essayContext.subtitle}`)\n }\n if (essayContext.markdown) {\n parts.push(`Content:\\n${essayContext.markdown}`)\n }\n \n return parts.join('\\n') || 'Empty essay'\n}\n","/** Word count options for essay generation */\nexport const LENGTH_OPTIONS = [300, 500, 800, 1000] as const\nexport type LengthOption = (typeof LENGTH_OPTIONS)[number]\n\n/** Full model definition with provider details */\nexport interface AIModel {\n id: string\n name: string\n provider: 'anthropic' | 'openai'\n modelId: string\n description?: string\n searchModel: 'native' | null // 'native' for GPT (uses tools), null for Claude (uses 2-call flow)\n}\n\nexport const AI_MODELS: AIModel[] = [\n {\n id: 'claude-sonnet',\n name: 'Sonnet 4.5',\n provider: 'anthropic',\n modelId: 'claude-sonnet-4-5-20250929',\n description: 'Fast, capable, best value',\n searchModel: null, // No native search, uses search-first flow\n },\n {\n id: 'claude-opus',\n name: 'Opus 4.5',\n provider: 'anthropic',\n modelId: 'claude-opus-4-5-20251101',\n description: 'Highest quality, slower',\n searchModel: null,\n },\n {\n id: 'gpt-5.2',\n name: 'GPT-5.2',\n provider: 'openai',\n modelId: 'gpt-5.2',\n description: 'Latest OpenAI flagship',\n searchModel: 'native', // Uses tools-based web search\n },\n {\n id: 'gpt-5-mini',\n name: 'GPT-5 Mini',\n provider: 'openai',\n modelId: 'gpt-5-mini',\n description: 'Fast and cost-efficient',\n searchModel: 'native', // Uses tools-based web search\n },\n]\n\nexport type ModelId = (typeof AI_MODELS)[number]['id']\n\n/** Subset of AIModel for UI dropdowns */\nexport interface AIModelOption {\n id: string\n name: string\n description?: string\n hasNativeSearch: boolean\n}\n\nexport function getModel(id: string): AIModel | undefined {\n return AI_MODELS.find(m => m.id === id)\n}\n\nexport function getDefaultModel(): AIModel {\n return AI_MODELS[0]\n}\n\n/** Check if a model has native search (via tools, not a separate model) */\nexport function modelHasNativeSearch(id: string): boolean {\n return AI_MODELS.find(m => m.id === id)?.searchModel === 'native'\n}\n\n/** Get the search model variant for a model, or null if it uses 2-call flow */\nexport function getSearchModel(id: string): string | null {\n return AI_MODELS.find(m => m.id === id)?.searchModel ?? null\n}\n\n/**\n * Resolve a model ID, falling back to database default or hardcoded default.\n * Used by AI API routes to avoid duplicating model resolution logic.\n * \n * @param providedModelId - Optional model ID from request\n * @param getDefaultModelId - Async function to get default from DB (avoids Prisma import here)\n * @returns Resolved AIModel\n * @throws Error if model not found\n */\nexport async function resolveModel(\n providedModelId: string | undefined,\n getDefaultModelId: () => Promise<string | null>\n): Promise<AIModel> {\n let modelId = providedModelId\n \n if (!modelId) {\n modelId = (await getDefaultModelId()) || 'claude-sonnet'\n }\n \n const model = getModel(modelId)\n if (!model) {\n throw new Error(`Unknown model: ${modelId}. Available: ${AI_MODELS.map(m => m.id).join(', ')}`)\n }\n \n return model\n}\n\n/** Convert AIModel to AIModelOption for UI */\nexport function toModelOption(model: AIModel): AIModelOption {\n return {\n id: model.id,\n name: model.name,\n description: model.description,\n hasNativeSearch: model.searchModel === 'native',\n }\n}\n\n/** Get all models as options for UI dropdowns */\nexport function getModelOptions(): AIModelOption[] {\n return AI_MODELS.map(toModelOption)\n}\n","import Anthropic from '@anthropic-ai/sdk'\nimport OpenAI from 'openai'\nimport { getModel } from './models'\n\n/** Message format for chat conversations */\nexport interface ChatMessage {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\ninterface StreamOptions {\n model: string\n messages: ChatMessage[]\n anthropicKey?: string\n openaiKey?: string\n maxTokens?: number\n useThinking?: boolean\n useWebSearch?: boolean\n}\n\ninterface GenerateResult {\n text: string\n inputTokens?: number\n outputTokens?: number\n}\n\n/**\n * Get API key for a provider, checking DB first then falling back to env var.\n * Accepts a prisma client to avoid importing it directly.\n */\nexport async function getApiKey(\n provider: 'anthropic' | 'openai',\n prisma?: { aISettings?: { findUnique: (args: any) => Promise<any> } }\n): Promise<string | null> {\n // Try AISettings DB first if prisma is provided\n if (prisma?.aISettings) {\n try {\n const settings = await prisma.aISettings.findUnique({\n where: { id: 'default' },\n })\n \n if (provider === 'anthropic' && settings?.anthropicKey) {\n return settings.anthropicKey\n }\n if (provider === 'openai' && settings?.openaiKey) {\n return settings.openaiKey\n }\n } catch {\n // DB lookup failed, fall back to env vars\n }\n }\n \n // Fall back to env vars\n if (provider === 'anthropic') {\n return process.env.ANTHROPIC_API_KEY || null\n }\n return process.env.OPENAI_API_KEY || null\n}\n\n/**\n * Fetch web search results using OpenAI's Responses API with web_search tool.\n * Returns a summary of search results to be used as context.\n */\nasync function fetchSearchResults(query: string, openaiKey?: string): Promise<string | null> {\n try {\n console.log('[Web Search] Fetching search results for:', query.slice(0, 100))\n const openai = new OpenAI({\n ...(openaiKey && { apiKey: openaiKey }),\n })\n \n const response = await (openai as any).responses.create({\n model: 'gpt-5-mini',\n input: `You are a research assistant. Provide a concise summary of the most relevant and recent information from the web about the following query. Include key facts, dates, and sources when available. Keep your response under 500 words.\\n\\nQuery: ${query}`,\n tools: [{ type: 'web_search' }],\n })\n \n const result = response.output_text || null\n console.log('[Web Search] Got results:', result ? `${result.length} chars` : 'null')\n return result\n } catch (error) {\n console.error('[Web Search] Failed:', error)\n return null\n }\n}\n\n/**\n * Extract the most recent user message to use as search query.\n */\nfunction extractSearchQuery(messages: ChatMessage[]): string {\n const userMessages = messages.filter(m => m.role === 'user')\n return userMessages[userMessages.length - 1]?.content || ''\n}\n\n/**\n * Generate text using the specified model (non-streaming).\n * Used for search mode and other non-streaming requests.\n */\nexport async function generate(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: {\n anthropicKey?: string\n openaiKey?: string\n maxTokens?: number\n useWebSearch?: boolean\n } = {}\n): Promise<GenerateResult> {\n const model = getModel(modelId)\n if (!model) {\n throw new Error(`Unknown model: ${modelId}`)\n }\n\n if (model.provider === 'anthropic') {\n return generateWithAnthropic(model.modelId, systemPrompt, userPrompt, options)\n }\n return generateWithOpenAI(model.modelId, systemPrompt, userPrompt, options)\n}\n\nasync function generateWithAnthropic(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: { anthropicKey?: string; maxTokens?: number }\n): Promise<GenerateResult> {\n const anthropic = new Anthropic({\n ...(options.anthropicKey && { apiKey: options.anthropicKey }),\n })\n\n const response = await anthropic.messages.create({\n model: modelId,\n max_tokens: options.maxTokens || 4096,\n system: systemPrompt,\n messages: [{ role: 'user', content: userPrompt }],\n })\n\n const textContent = response.content.find(c => c.type === 'text')\n if (!textContent || textContent.type !== 'text') {\n throw new Error('No text content in response')\n }\n\n return {\n text: textContent.text,\n inputTokens: response.usage?.input_tokens,\n outputTokens: response.usage?.output_tokens,\n }\n}\n\nasync function generateWithOpenAI(\n modelId: string,\n systemPrompt: string,\n userPrompt: string,\n options: { openaiKey?: string; maxTokens?: number; useWebSearch?: boolean }\n): Promise<GenerateResult> {\n const openai = new OpenAI({\n ...(options.openaiKey && { apiKey: options.openaiKey }),\n })\n\n // Use Responses API for web search\n if (options.useWebSearch) {\n const response = await (openai as any).responses.create({\n model: modelId,\n instructions: systemPrompt,\n input: userPrompt,\n max_output_tokens: options.maxTokens || 4096,\n tools: [{ type: 'web_search' }],\n })\n\n const textOutput = response.output?.find((item: { type: string }) => item.type === 'message')\n const content = textOutput?.content?.find((c: { type: string }) => c.type === 'output_text')?.text\n\n if (!content) {\n throw new Error('No content in response')\n }\n\n return {\n text: content,\n inputTokens: response.usage?.input_tokens,\n outputTokens: response.usage?.output_tokens,\n }\n }\n\n // Standard chat completions\n const response = await openai.chat.completions.create({\n model: modelId,\n max_completion_tokens: options.maxTokens || 4096,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: userPrompt },\n ],\n })\n\n const content = response.choices[0]?.message?.content\n if (!content) {\n throw new Error('No content in response')\n }\n\n return {\n text: content,\n inputTokens: response.usage?.prompt_tokens,\n outputTokens: response.usage?.completion_tokens,\n }\n}\n\nexport async function createStream(options: StreamOptions): Promise<ReadableStream> {\n const modelConfig = getModel(options.model)\n if (!modelConfig) {\n throw new Error(`Unknown model: ${options.model}`)\n }\n\n // For Anthropic with web search enabled, fetch search results first using OpenAI\n let searchContext = ''\n if (options.useWebSearch && modelConfig.provider === 'anthropic') {\n const query = extractSearchQuery(options.messages)\n if (query) {\n const searchResults = await fetchSearchResults(query, options.openaiKey)\n if (searchResults) {\n searchContext = `\\n\\n<web_search_results>\\n${searchResults}\\n</web_search_results>\\n\\nUse the search results above to inform your response with current, accurate information.`\n }\n }\n }\n\n if (modelConfig.provider === 'anthropic') {\n return createAnthropicStream(options, modelConfig.modelId, searchContext)\n } else {\n return createOpenAIStream(options, modelConfig.modelId, options.useWebSearch)\n }\n}\n\n/** Helper to safely enqueue data to controller */\nfunction safeEnqueue(controller: ReadableStreamDefaultController, data: Uint8Array): boolean {\n try {\n controller.enqueue(data)\n return true\n } catch {\n // Controller already closed\n return false\n }\n}\n\n/** Helper to safely close controller */\nfunction safeClose(controller: ReadableStreamDefaultController): void {\n try {\n controller.close()\n } catch {\n // Controller already closed\n }\n}\n\nasync function createAnthropicStream(options: StreamOptions, modelId: string, searchContext: string = ''): Promise<ReadableStream> {\n const anthropic = new Anthropic({\n ...(options.anthropicKey && { apiKey: options.anthropicKey }),\n })\n\n const systemMessage = (options.messages.find(m => m.role === 'system')?.content || '') + searchContext\n const chatMessages = options.messages\n .filter(m => m.role !== 'system')\n .map(m => ({ role: m.role as 'user' | 'assistant', content: m.content }))\n\n const requestParams: any = {\n model: modelId,\n max_tokens: options.maxTokens || 4096,\n system: systemMessage,\n messages: chatMessages,\n }\n\n if (options.useThinking && (modelId.includes('claude-sonnet') || modelId.includes('claude-opus'))) {\n requestParams.thinking = {\n type: 'enabled',\n budget_tokens: 10000,\n }\n requestParams.max_tokens = Math.max(requestParams.max_tokens, 16000)\n }\n\n try {\n const stream = await anthropic.messages.stream(requestParams)\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const event of stream) {\n if (event.type === 'content_block_delta') {\n const delta = event.delta as { type: string; text?: string; thinking?: string }\n if (delta.type === 'text_delta' && delta.text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text: delta.text })}\\n\\n`))) {\n return // Controller closed, stop processing\n }\n } else if (delta.type === 'thinking_delta' && delta.thinking) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ thinking: delta.thinking })}\\n\\n`))) {\n return\n }\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[Anthropic Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Anthropic API error'\n console.error('[Anthropic API Error]', error)\n throw new Error(errorMessage)\n }\n}\n\nasync function createOpenAIStream(options: StreamOptions, modelId: string, useWebSearch: boolean = false): Promise<ReadableStream> {\n const openai = new OpenAI({\n ...(options.openaiKey && { apiKey: options.openaiKey }),\n })\n\n if (useWebSearch) {\n return createOpenAIResponsesStream(openai, options, modelId)\n }\n\n const requestParams: any = {\n model: modelId,\n messages: options.messages,\n max_completion_tokens: options.maxTokens || 4096,\n stream: true,\n }\n\n try {\n const stream = await openai.chat.completions.create(requestParams) as unknown as AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const chunk of stream) {\n const text = chunk.choices[0]?.delta?.content\n if (text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text })}\\n\\n`))) {\n return\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[OpenAI Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'OpenAI API error'\n console.error('[OpenAI API Error]', error)\n throw new Error(errorMessage)\n }\n}\n\nasync function createOpenAIResponsesStream(openai: OpenAI, options: StreamOptions, modelId: string): Promise<ReadableStream> {\n const systemMessage = options.messages.find(m => m.role === 'system')?.content || ''\n const conversationMessages = options.messages.filter(m => m.role !== 'system')\n \n const lastUserMessage = conversationMessages[conversationMessages.length - 1]?.content || ''\n const conversationContext = conversationMessages.slice(0, -1)\n .map(m => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}`)\n .join('\\n\\n')\n \n const fullInput = conversationContext \n ? `${systemMessage}\\n\\nPrevious conversation:\\n${conversationContext}\\n\\nUser: ${lastUserMessage}`\n : `${systemMessage}\\n\\n${lastUserMessage}`\n\n try {\n const response = await (openai as any).responses.create({\n model: modelId,\n input: fullInput,\n tools: [{ type: 'web_search' }],\n stream: true,\n })\n\n return new ReadableStream({\n async start(controller) {\n try {\n for await (const event of response) {\n if (event.type === 'response.output_text.delta') {\n const text = event.delta\n if (text) {\n if (!safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ text })}\\n\\n`))) {\n return\n }\n }\n }\n }\n safeEnqueue(controller, new TextEncoder().encode('data: [DONE]\\n\\n'))\n safeClose(controller)\n } catch (streamError) {\n const errorMessage = streamError instanceof Error ? streamError.message : 'Stream error'\n console.error('[OpenAI Responses Stream Error]', streamError)\n safeEnqueue(controller, new TextEncoder().encode(`data: ${JSON.stringify({ error: errorMessage })}\\n\\n`))\n safeClose(controller)\n }\n },\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'OpenAI Responses API error'\n console.error('[OpenAI Responses API Error]', error)\n throw new Error(errorMessage)\n }\n}\n","import { \n DEFAULT_GENERATE_TEMPLATE, \n DEFAULT_CHAT_TEMPLATE, \n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n} from './prompts'\n\n/**\n * Build a system prompt for essay generation.\n */\nexport function buildGeneratePrompt(options: {\n rules?: string\n template?: string | null\n wordCount?: number\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_GENERATE_TEMPLATE\n \n return template\n .replace('{{RULES}}', options.rules || '')\n .replace('{{WORD_COUNT}}', String(options.wordCount || 800))\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for chat interactions.\n */\nexport function buildChatPrompt(options: {\n chatRules?: string\n rules?: string\n template?: string | null\n essayContext?: { title: string; subtitle?: string; markdown: string } | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_CHAT_TEMPLATE\n \n let essaySection = ''\n if (options.essayContext) {\n essaySection = `\nCurrent essay being edited:\nTitle: ${options.essayContext.title}\n${options.essayContext.subtitle ? `Subtitle: ${options.essayContext.subtitle}` : ''}\n\nContent:\n${options.essayContext.markdown}\n`\n }\n \n return template\n .replace('{{CHAT_RULES}}', options.chatRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{ESSAY_CONTEXT}}', essaySection)\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for expanding a plan into a full essay.\n */\nexport function buildExpandPlanPrompt(options: {\n rules?: string\n template?: string | null\n plan: string\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_EXPAND_PLAN_TEMPLATE\n \n return template\n .replace('{{RULES}}', options.rules || '')\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n .replace('{{PLAN}}', options.plan)\n}\n\n/**\n * Build a system prompt for plan/outline generation.\n */\nexport function buildPlanPrompt(options: {\n planRules?: string\n template?: string | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_PLAN_TEMPLATE\n const rules = options.planRules || DEFAULT_PLAN_RULES\n \n return template\n .replace('{{PLAN_RULES}}', rules)\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for text rewriting.\n */\nexport function buildRewritePrompt(options: {\n rewriteRules?: string\n rules?: string\n template?: string | null\n styleExamples?: string\n}): string {\n const template = options.template || DEFAULT_REWRITE_TEMPLATE\n \n return template\n .replace('{{REWRITE_RULES}}', options.rewriteRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n}\n\n/**\n * Build a system prompt for auto-drafting essays from news articles.\n */\nexport function buildAutoDraftPrompt(options: {\n autoDraftRules?: string\n rules?: string\n template?: string | null\n wordCount?: number\n styleExamples?: string\n // Article context\n topicName?: string\n articleTitle?: string\n articleSummary?: string\n articleUrl?: string\n}): string {\n const template = options.template || DEFAULT_AUTO_DRAFT_TEMPLATE\n \n return template\n .replace('{{AUTO_DRAFT_RULES}}', options.autoDraftRules || '')\n .replace('{{RULES}}', options.rules || '')\n .replace('{{AUTO_DRAFT_WORD_COUNT}}', String(options.wordCount || 800))\n .replace('{{STYLE_EXAMPLES}}', options.styleExamples || '')\n .replace('{{TOPIC_NAME}}', options.topicName || '')\n .replace('{{ARTICLE_TITLE}}', options.articleTitle || '')\n .replace('{{ARTICLE_SUMMARY}}', options.articleSummary || '')\n .replace('{{ARTICLE_URL}}', options.articleUrl || '')\n}\n","import type { Browser } from 'puppeteer-core'\n\n// Regex to match URLs in text - supports both with and without protocol\n// Matches: https://example.com, http://example.com, www.example.com, example.com/path\nconst URL_WITH_PROTOCOL = /https?:\\/\\/[^\\s<>\\[\\]()]+(?:\\([^\\s<>\\[\\]()]*\\))?[^\\s<>\\[\\]().,;:!?\"']*(?<![.,;:!?\"'])/gi\nconst URL_WITHOUT_PROTOCOL = /(?:www\\.)[a-zA-Z0-9][-a-zA-Z0-9]*(?:\\.[a-zA-Z]{2,})+(?:\\/[^\\s<>\\[\\]()]*)?/gi\nconst DOMAIN_ONLY = /(?<![/@])(?:[a-zA-Z0-9][-a-zA-Z0-9]*\\.)+(?:com|org|net|edu|gov|io|co|app|dev|news|info)(?:\\/[^\\s<>\\[\\]()]*)?(?![a-zA-Z])/gi\n\n// Puppeteer configuration\nconst PUPPETEER_TIMEOUT = 15000 // 15 seconds max for page load\nconst CONTENT_WAIT_TIME = 2000 // Wait 2s after load for JS to render\n\n/**\n * Detect if we're running in a serverless environment (Vercel, AWS Lambda, etc.)\n * In serverless, we use @sparticuz/chromium. Locally, we use regular puppeteer.\n */\nfunction isServerlessEnvironment(): boolean {\n return !!(\n process.env.AWS_LAMBDA_FUNCTION_NAME ||\n process.env.VERCEL ||\n process.env.NETLIFY ||\n process.env.AWS_EXECUTION_ENV\n )\n}\n\n/**\n * Extract URLs from text.\n * Supports URLs with protocol (https://), www prefix, or bare domains.\n */\nexport function extractUrls(text: string): string[] {\n const urls: string[] = []\n \n // Match URLs with protocol first (highest priority)\n const withProtocol = text.match(URL_WITH_PROTOCOL)\n if (withProtocol) urls.push(...withProtocol)\n \n // Match www. URLs\n const wwwUrls = text.match(URL_WITHOUT_PROTOCOL)\n if (wwwUrls) {\n for (const url of wwwUrls) {\n // Add https:// prefix for consistency\n const normalized = `https://${url}`\n if (!urls.some(u => u.includes(url))) {\n urls.push(normalized)\n }\n }\n }\n \n // Match bare domain URLs (newsday.com, example.org, etc.)\n const bareUrls = text.match(DOMAIN_ONLY)\n if (bareUrls) {\n for (const url of bareUrls) {\n // Add https:// prefix for consistency\n const normalized = `https://${url}`\n if (!urls.some(u => u.includes(url.split('/')[0]))) {\n urls.push(normalized)\n }\n }\n }\n \n return [...new Set(urls)]\n}\n\nexport interface FetchedContent {\n url: string\n title?: string\n content: string\n error?: string\n}\n\n/**\n * Simple HTML text extraction without JSDOM.\n * Used as fallback when JSDOM fails (common with npm link).\n */\nfunction extractTextFromHtml(html: string, url: string): FetchedContent {\n // Extract title\n const titleMatch = html.match(/<title[^>]*>([^<]+)<\\/title>/i)\n const title = titleMatch ? titleMatch[1].trim() : undefined\n\n // Remove scripts, styles, and other non-content elements\n let text = html\n .replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, '')\n .replace(/<style[^>]*>[\\s\\S]*?<\\/style>/gi, '')\n .replace(/<nav[^>]*>[\\s\\S]*?<\\/nav>/gi, '')\n .replace(/<footer[^>]*>[\\s\\S]*?<\\/footer>/gi, '')\n .replace(/<header[^>]*>[\\s\\S]*?<\\/header>/gi, '')\n .replace(/<aside[^>]*>[\\s\\S]*?<\\/aside>/gi, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n // Replace tags with appropriate spacing\n .replace(/<(p|div|br|h[1-6]|li|tr)[^>]*>/gi, '\\n')\n .replace(/<[^>]+>/g, ' ')\n // Decode common HTML entities\n .replace(/&nbsp;/g, ' ')\n .replace(/&amp;/g, '&')\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&quot;/g, '\"')\n .replace(/&#39;/g, \"'\")\n .replace(/&[a-z]+;/gi, ' ')\n // Clean up whitespace\n .replace(/\\s+/g, ' ')\n .replace(/\\n\\s+/g, '\\n')\n .replace(/\\n+/g, '\\n')\n .trim()\n\n // Limit content\n if (text.length > 4000) {\n text = text.slice(0, 4000) + '\\n\\n[Content truncated...]'\n }\n\n if (text.length < 50) {\n return { url, content: '', error: 'Could not extract meaningful content' }\n }\n\n return { url, title, content: text }\n}\n\n/**\n * Parse HTML with Mozilla Readability.\n * Falls back to simple regex extraction if JSDOM fails.\n */\nasync function parseWithReadability(html: string, url: string): Promise<FetchedContent> {\n try {\n const { JSDOM } = await import('jsdom')\n const { Readability } = await import('@mozilla/readability')\n\n // CRITICAL: Do NOT load any external resources\n // Explicitly set resources to undefined to prevent Next.js/npm link issues\n const doc = new JSDOM(html, { \n url,\n resources: undefined, // Don't load ANY external resources (stylesheets, etc.)\n runScripts: undefined, // Don't run any scripts\n })\n const reader = new Readability(doc.window.document)\n const article = reader.parse()\n\n if (!article || !article.textContent) {\n // Readability couldn't parse - try simple extraction\n console.log('[Readability] No article content, falling back to simple extraction')\n return extractTextFromHtml(html, url)\n }\n\n // Limit content to avoid token bloat (~4000 chars ≈ 1000 tokens)\n let content = article.textContent.trim()\n if (content.length > 4000) {\n content = content.slice(0, 4000) + '\\n\\n[Content truncated...]'\n }\n\n return {\n url,\n title: article.title || undefined,\n content,\n }\n } catch (error) {\n // JSDOM failed (common with npm link due to native module issues)\n console.error('[JSDOM] Failed, using simple extraction:', error instanceof Error ? error.message : error)\n return extractTextFromHtml(html, url)\n }\n}\n\n/**\n * Fetch URL content using Puppeteer (headless browser).\n * This handles JavaScript-rendered pages and some paywalls.\n * \n * Environment detection:\n * - Local development: Uses regular `puppeteer` (auto-downloads Chrome)\n * - Serverless (Vercel/Lambda): Uses `@sparticuz/chromium` + `puppeteer-core`\n */\nasync function fetchWithPuppeteer(url: string): Promise<FetchedContent> {\n let browser: Browser | null = null\n const isServerless = isServerlessEnvironment()\n \n try {\n console.log(`[Puppeteer] Launching browser for: ${url} (serverless: ${isServerless})`)\n \n if (isServerless) {\n // Serverless environment: use @sparticuz/chromium\n const chromium = await import('@sparticuz/chromium')\n const puppeteerCore = await import('puppeteer-core')\n \n const executablePath = await chromium.default.executablePath()\n \n browser = await puppeteerCore.default.launch({\n args: chromium.default.args,\n defaultViewport: chromium.default.defaultViewport,\n executablePath,\n headless: chromium.default.headless,\n })\n } else {\n // Local development: use regular puppeteer (has its own Chrome)\n try {\n const puppeteer = await import('puppeteer')\n \n browser = await puppeteer.default.launch({\n headless: true,\n args: [\n '--no-sandbox',\n '--disable-setuid-sandbox',\n '--disable-dev-shm-usage',\n '--disable-accelerated-2d-canvas',\n '--disable-gpu',\n ],\n })\n } catch (puppeteerImportError) {\n // Puppeteer import/launch failed - this can happen with npm link or missing Chrome\n console.error('[Puppeteer] Import/launch failed:', puppeteerImportError)\n return { url, content: '', error: 'Puppeteer unavailable - falling back to simple fetch' }\n }\n }\n \n const page = await browser.newPage()\n \n // Set viewport and user agent\n await page.setViewport({ width: 1920, height: 1080 })\n await page.setUserAgent(\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'\n )\n \n // Block unnecessary resources to speed up loading\n await page.setRequestInterception(true)\n page.on('request', (req) => {\n const resourceType = req.resourceType()\n if (['image', 'stylesheet', 'font', 'media'].includes(resourceType)) {\n req.abort()\n } else {\n req.continue()\n }\n })\n \n // Navigate with timeout\n await page.goto(url, {\n waitUntil: 'networkidle2',\n timeout: PUPPETEER_TIMEOUT,\n })\n \n // Wait a bit for any remaining JS to execute\n await new Promise(resolve => setTimeout(resolve, CONTENT_WAIT_TIME))\n \n // Get the rendered HTML\n const html = await page.content()\n \n // Close browser before parsing to free resources\n await browser.close()\n browser = null\n \n console.log('[Puppeteer] Got HTML, parsing with Readability...')\n \n // Parse with Readability\n return await parseWithReadability(html, url)\n \n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Puppeteer error'\n console.error('[Puppeteer] Failed:', errorMessage)\n return { url, content: '', error: `Puppeteer: ${errorMessage}` }\n } finally {\n // Ensure browser is closed even on error\n if (browser) {\n try {\n await browser.close()\n } catch {\n // Ignore close errors\n }\n }\n }\n}\n\n/**\n * Fetch URL content using simple HTTP request + Mozilla Readability.\n * This is the fallback method when Puppeteer fails or isn't available.\n */\nasync function fetchWithSimpleRequest(url: string): Promise<FetchedContent> {\n try {\n console.log('[SimpleFetch] Fetching:', url)\n \n const res = await fetch(url, {\n headers: {\n 'User-Agent':\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.9',\n },\n })\n\n if (!res.ok) {\n return { url, content: '', error: `HTTP ${res.status}` }\n }\n\n const html = await res.text()\n return parseWithReadability(html, url)\n } catch (error) {\n return {\n url,\n content: '',\n error: error instanceof Error ? error.message : 'Failed to fetch',\n }\n }\n}\n\n/**\n * Fetch URL content - tries Puppeteer first for JavaScript-rendered pages,\n * falls back to simple HTTP request if Puppeteer fails.\n */\nexport async function fetchUrlContent(url: string): Promise<FetchedContent> {\n console.log('[URL Extractor] Fetching content from:', url)\n \n // Try Puppeteer first (better for JS-rendered and paywalled sites)\n const puppeteerResult = await fetchWithPuppeteer(url)\n \n // Check if Puppeteer succeeded with actual content\n if (!puppeteerResult.error && puppeteerResult.content && puppeteerResult.content.length > 100) {\n console.log('[URL Extractor] Puppeteer succeeded, got', puppeteerResult.content.length, 'chars')\n return puppeteerResult\n }\n \n // Puppeteer failed or got minimal content - try simple fetch as fallback\n console.log('[URL Extractor] Puppeteer failed or got minimal content, trying simple fetch...')\n const simpleResult = await fetchWithSimpleRequest(url)\n \n // Return whichever got more content\n if (simpleResult.content && simpleResult.content.length > (puppeteerResult.content?.length || 0)) {\n console.log('[URL Extractor] Simple fetch got more content:', simpleResult.content.length, 'chars')\n return simpleResult\n }\n \n // Return Puppeteer result (even if it failed, it has better error info)\n if (puppeteerResult.content && puppeteerResult.content.length > 0) {\n return puppeteerResult\n }\n \n // Both failed - return the simple fetch error (usually more informative)\n return simpleResult.error ? simpleResult : puppeteerResult\n}\n\n/**\n * Extract URLs from text and fetch their content.\n * Returns fetched content for all URLs found.\n */\nexport async function extractAndFetchUrls(text: string): Promise<FetchedContent[]> {\n const urls = extractUrls(text)\n if (urls.length === 0) return []\n\n // Limit to 3 URLs to avoid abuse and long waits\n const toFetch = urls.slice(0, 3)\n\n // Fetch in parallel for speed\n const results = await Promise.all(toFetch.map(url => fetchUrlContent(url)))\n\n return results\n}\n\n/**\n * Build context string from fetched URLs for AI prompts.\n */\nexport function buildUrlContext(fetched: FetchedContent[]): string {\n const successful = fetched.filter((f) => !f.error && f.content)\n if (successful.length === 0) return ''\n\n return `\n<referenced_urls>\n${successful\n .map(\n (f) =>\n `<url src=\"${f.url}\"${f.title ? ` title=\"${f.title}\"` : ''}>\n${f.content}\n</url>`\n )\n .join('\\n\\n')}\n</referenced_urls>\n\nUse the content from these URLs when relevant to the conversation.`\n}\n","import { createStream } from './provider'\nimport { buildGeneratePrompt, buildExpandPlanPrompt } from './builders'\nimport { extractAndFetchUrls } from '../lib/url-extractor'\n\ninterface GenerateOptions {\n prompt: string\n model: string\n wordCount?: number\n rules?: string\n template?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n useWebSearch?: boolean // Controls ALL internet access: URL extraction AND web search\n useThinking?: boolean\n}\n\nexport async function generateStream(options: GenerateOptions): Promise<ReadableStream> {\n const systemPrompt = buildGeneratePrompt({\n rules: options.rules,\n template: options.template,\n wordCount: options.wordCount,\n styleExamples: options.styleExamples,\n })\n\n // Extract and fetch URL content when web access is enabled\n let enrichedPrompt = options.prompt\n if (options.useWebSearch) {\n try {\n const fetched = await extractAndFetchUrls(options.prompt)\n const successful = fetched.filter((f) => !f.error && f.content)\n if (successful.length > 0) {\n enrichedPrompt = `${options.prompt}\n\n<source_material>\n${successful\n .map(\n (f) =>\n `Source: ${f.url}${f.title ? ` (${f.title})` : ''}\n${f.content}`\n )\n .join('\\n\\n---\\n\\n')}\n</source_material>\n\nUse the source material above as reference for the essay.`\n }\n } catch (err) {\n console.warn('URL extraction failed:', err)\n }\n }\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: enrichedPrompt },\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: options.useThinking ? 16000 : 8192,\n useWebSearch: options.useWebSearch,\n useThinking: options.useThinking,\n })\n}\n\ninterface ExpandPlanOptions {\n plan: string\n model: string\n rules?: string\n template?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n}\n\nexport async function expandPlanStream(options: ExpandPlanOptions): Promise<ReadableStream> {\n const systemPrompt = buildExpandPlanPrompt({\n rules: options.rules,\n template: options.template,\n plan: options.plan,\n styleExamples: options.styleExamples,\n })\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: 'Write the essay now.' },\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: 8192,\n })\n}\n","import { createStream } from './provider'\nimport { buildChatPrompt, buildPlanPrompt } from './builders'\nimport { extractAndFetchUrls, buildUrlContext } from '../lib/url-extractor'\nimport { DEFAULT_AGENT_TEMPLATE } from './prompts'\n\ninterface ChatMessage {\n role: 'user' | 'assistant'\n content: string\n}\n\ninterface ChatOptions {\n messages: ChatMessage[]\n model: string\n essayContext?: { title: string; subtitle?: string; markdown: string } | null\n mode?: 'ask' | 'agent' | 'search' | 'plan'\n chatRules?: string\n rules?: string\n template?: string | null\n // Plan mode specific\n planTemplate?: string | null\n planRules?: string\n // Agent mode specific\n agentTemplate?: string | null\n styleExamples?: string\n anthropicKey?: string\n openaiKey?: string\n useWebSearch?: boolean // Controls ALL internet access: URL extraction AND web search\n useThinking?: boolean\n}\n\nexport async function chatStream(options: ChatOptions): Promise<ReadableStream> {\n // Use different prompt builder for plan mode\n const systemPrompt = options.mode === 'plan'\n ? buildPlanPrompt({\n planRules: options.planRules,\n template: options.planTemplate,\n styleExamples: options.styleExamples,\n })\n : buildChatPrompt({\n chatRules: options.chatRules,\n rules: options.rules,\n template: options.template,\n essayContext: options.essayContext,\n styleExamples: options.styleExamples,\n })\n\n // Extract URLs from the last user message when web access is enabled\n // The web toggle controls ALL internet access: URL extraction AND web search\n let urlContext = ''\n let urlExtractionStatus = ''\n if (options.useWebSearch) {\n const lastUserMsg = [...options.messages].reverse().find((m) => m.role === 'user')\n if (lastUserMsg) {\n try {\n const { extractUrls } = await import('../lib/url-extractor')\n const detectedUrls = extractUrls(lastUserMsg.content)\n \n if (detectedUrls.length > 0) {\n console.log('[URL Extraction] Detected URLs:', detectedUrls)\n const fetched = await extractAndFetchUrls(lastUserMsg.content)\n \n if (fetched.length > 0) {\n const successful = fetched.filter(f => !f.error && f.content)\n const failed = fetched.filter(f => f.error || !f.content)\n \n if (successful.length > 0) {\n urlContext = buildUrlContext(fetched)\n console.log('[URL Extraction] Successfully fetched:', successful.map(f => f.url))\n }\n \n if (failed.length > 0) {\n console.warn('[URL Extraction] Failed to fetch:', failed.map(f => ({ url: f.url, error: f.error })))\n urlExtractionStatus = `\\n\\n<url_extraction_status>\nAttempted to fetch ${detectedUrls.length} URL(s). ${successful.length} succeeded, ${failed.length} failed.\n${failed.map(f => `- ${f.url}: ${f.error || 'Empty content'}`).join('\\n')}\n</url_extraction_status>`\n }\n }\n }\n } catch (err) {\n console.error('[URL Extraction] Error:', err)\n urlExtractionStatus = `\\n\\n<url_extraction_status>\nURL extraction encountered an error: ${err instanceof Error ? err.message : 'Unknown error'}\n</url_extraction_status>`\n }\n }\n }\n\n // Add mode-specific instructions\n let modeInstructions = ''\n if (options.mode === 'agent') {\n // Use custom agent template if set, otherwise use default\n modeInstructions = '\\n\\n' + (options.agentTemplate || DEFAULT_AGENT_TEMPLATE)\n }\n\n // Add web search context if enabled\n let webSearchContext = ''\n if (options.useWebSearch) {\n // Web search is enabled - OpenAI models use native search, Anthropic models get search results via OpenAI proxy\n webSearchContext = `\n\n<search_capability>\nWeb search is ENABLED for this conversation. You have access to current, real-time information from the web.\n- For questions about recent events, news, or current information: search results will be provided automatically\n- Cite sources when referencing specific facts from search results\n- If search results are included in <web_search_results> tags, use that information to provide accurate, up-to-date answers\n</search_capability>`\n }\n\n // Add thinking mode instructions if enabled\n let thinkingInstructions = ''\n if (options.useThinking) {\n thinkingInstructions = '\\n\\nTake time to think through complex questions step by step. Consider multiple angles before providing your final answer.'\n }\n\n // Add URL capability instructions when web access is enabled\n // These instructions are CRITICAL - they override the AI's default belief that it cannot access URLs\n let urlCapabilityInstructions = ''\n if (options.useWebSearch) {\n const hasUrlContent = urlContext.length > 0\n const hasFailedUrls = urlExtractionStatus.length > 0\n \n urlCapabilityInstructions = `\n\n<CRITICAL_CAPABILITY>\n**IMPORTANT: URL READING IS ENABLED**\n\nYou have a WORKING URL reader in this application. This overrides your default training.\n- DO NOT say \"I cannot access URLs\" or \"I cannot browse the web\" - you CAN and DO have this capability\n- When users share URLs, the content is AUTOMATICALLY FETCHED by the system\n- Look for <referenced_urls> tags below - that contains the fetched page content\n- ${hasUrlContent ? 'URL CONTENT WAS SUCCESSFULLY FETCHED - see <referenced_urls> below' : hasFailedUrls ? 'URL fetch was ATTEMPTED but FAILED - see <url_extraction_status> below for details' : 'No URLs detected in the current message'}\n\nIf you see fetched content, use it to answer the user's question. Quote specific passages when relevant.\nIf the fetch failed, explain what happened using the error details provided.\n</CRITICAL_CAPABILITY>`\n }\n\n // Filter out messages with empty content (can happen from partial streams or errors)\n // AI APIs reject messages with empty content\n const filteredMessages = options.messages.filter(m => m.content && m.content.trim().length > 0)\n\n return createStream({\n model: options.model,\n messages: [\n { role: 'system', content: systemPrompt + modeInstructions + webSearchContext + thinkingInstructions + urlCapabilityInstructions + urlContext + urlExtractionStatus },\n ...filteredMessages,\n ],\n anthropicKey: options.anthropicKey,\n openaiKey: options.openaiKey,\n maxTokens: options.useThinking ? 16000 : 4096, // Allow more tokens for thinking mode\n useThinking: options.useThinking,\n useWebSearch: options.useWebSearch,\n })\n}\n","// Server-safe exports (no React imports)\nexport { createAutoblogger } from './server'\nexport { createAPIHandler } from './api'\nexport { validateSchema } from './schema'\n\n// Data layer factory\nexport { createCrudData } from './data/factory'\nexport type { CrudOptions, BaseCrud } from './data/factory'\n\n// Data access types\nexport type { Post, Revision, Comment, Tag, PostTag, AISettings, TopicSubscription, NewsItem } from './types'\n\n// AI exports\nexport {\n AI_MODELS,\n getModel,\n getDefaultModel,\n buildGeneratePrompt,\n buildChatPrompt,\n buildExpandPlanPrompt,\n buildPlanPrompt,\n buildRewritePrompt,\n buildAutoDraftPrompt,\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n parseGeneratedContent,\n generate,\n resolveModel,\n} from './ai'\nexport type { AIModel } from './ai'\n\n// Utilities\nexport { renderMarkdown, parseMarkdown, htmlToMarkdown, markdownToHtml, wordCount, generateSlug, renderMarkdownSanitized } from './lib/markdown'\nexport { getSeoValues } from './lib/seo'\nexport { formatDate, truncate } from './lib/format'\n\n// Auto-draft\nexport { runAutoDraft, fetchRssFeeds, filterByKeywords } from './auto-draft'\nexport type { RssArticle, GenerationResult, AutoDraftConfig } from './auto-draft'\n\n// Comment utilities (for advanced integrations)\nexport { createCommentsClient, canEditComment, canDeleteComment } from './lib/comments'\nexport type { CommentWithUser, CreateCommentData, SelectionState } from './lib/comments'\nexport { CommentMark, addCommentMark, removeCommentMark, applyCommentMarks, scrollToComment } from './lib/comment-mark'\n\n// Types (server-safe only)\nexport type { \n AutobloggerServerConfig as AutobloggerConfig, \n StylesConfig,\n AutobloggerServer as Autoblogger,\n Session,\n} from './server'\n\n// UI-related types (client-side, contains React types)\nexport type { CustomFieldProps, CustomFieldConfig } from './config'\n","import type { Post } from '../types'\n\ninterface PostHooks {\n beforePublish?: (post: Post) => Promise<void>\n afterSave?: (post: Post) => Promise<void>\n}\n\ninterface CreatePostInput {\n title: string\n subtitle?: string\n slug?: string\n markdown?: string\n status?: string\n [key: string]: unknown\n}\n\ninterface UpdatePostInput {\n title?: string\n subtitle?: string\n slug?: string\n markdown?: string\n status?: string\n publishedAt?: Date\n [key: string]: unknown\n}\n\nfunction slugify(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n}\n\nasync function generateUniqueSlug(prisma: any, baseSlug: string, excludeId?: string): Promise<string> {\n let slug = baseSlug\n let counter = 1\n \n while (true) {\n const existing = await prisma.post.findFirst({\n where: {\n slug,\n ...(excludeId ? { NOT: { id: excludeId } } : {}),\n },\n })\n \n if (!existing) return slug\n \n counter++\n slug = `${baseSlug}-${counter}`\n }\n}\n\nexport function createPostsData(prisma: any, hooks?: PostHooks) {\n return {\n async count(where?: { status?: string }) {\n return prisma.post.count({ where })\n },\n\n async findPublished() {\n return prisma.post.findMany({\n where: { status: 'published' },\n orderBy: { publishedAt: 'desc' },\n })\n },\n\n async findBySlug(slug: string) {\n return prisma.post.findUnique({\n where: { slug },\n include: { tags: { include: { tag: true } } },\n })\n },\n\n async findById(id: string) {\n return prisma.post.findUnique({\n where: { id },\n include: { tags: { include: { tag: true } } },\n })\n },\n\n async findDrafts() {\n return prisma.post.findMany({\n where: { status: 'draft' },\n orderBy: { updatedAt: 'desc' },\n })\n },\n\n async findAll(options?: { \n status?: string\n orderBy?: any\n skip?: number\n take?: number\n includeRevisionCount?: boolean\n }) {\n return prisma.post.findMany({\n where: options?.status ? { status: options.status } : undefined,\n orderBy: options?.orderBy || { updatedAt: 'desc' },\n include: { \n tags: { include: { tag: true } },\n ...(options?.includeRevisionCount ? { _count: { select: { revisions: true } } } : {}),\n },\n skip: options?.skip,\n take: options?.take,\n })\n },\n\n async create(data: CreatePostInput) {\n // Extract tagIds before passing to Prisma\n const { tagIds, ...postData } = data as CreatePostInput & { tagIds?: string[] }\n \n const slug = postData.slug \n ? await generateUniqueSlug(prisma, postData.slug)\n : await generateUniqueSlug(prisma, slugify(postData.title))\n\n const post = await prisma.post.create({\n data: {\n ...postData,\n slug,\n markdown: postData.markdown || '',\n status: postData.status || 'draft',\n },\n })\n\n // Create tag associations if provided\n if (tagIds?.length) {\n await prisma.postTag.createMany({\n data: tagIds.map((tagId: string) => ({ postId: post.id, tagId })),\n })\n }\n\n // Fetch with tags included\n const result = await prisma.post.findUnique({\n where: { id: post.id },\n include: { tags: { include: { tag: true } } },\n })\n\n if (hooks?.afterSave) {\n await hooks.afterSave(result)\n }\n\n return result\n },\n\n async update(id: string, data: UpdatePostInput) {\n // Extract relation IDs, computed fields, and read-only fields before passing to Prisma\n const { \n tagIds, \n tags, \n revisions, \n topic,\n topicId, // Handle separately as relation\n id: _id, // Don't update the ID\n createdAt: _createdAt, // Don't update createdAt\n wordCount: _wordCount, // Computed field, don't save\n ...postData \n } = data as UpdatePostInput & { \n tagIds?: string[]\n tags?: unknown\n revisions?: unknown\n topic?: unknown\n topicId?: string | null\n id?: string\n createdAt?: Date\n wordCount?: number\n }\n \n // Auto-set publishedAt on first publish\n if (postData.status === 'published') {\n const existing = await prisma.post.findUnique({ where: { id } })\n if (existing?.status !== 'published') {\n postData.publishedAt = new Date()\n \n if (hooks?.beforePublish) {\n await hooks.beforePublish(existing)\n }\n }\n }\n\n // Handle slug uniqueness if slug is being changed\n if (postData.slug) {\n postData.slug = await generateUniqueSlug(prisma, postData.slug, id)\n }\n\n // Build the update payload\n const updatePayload: any = { ...postData }\n\n // Handle topic relation properly using connect/disconnect syntax\n if (topicId !== undefined) {\n updatePayload.topic = topicId ? { connect: { id: topicId } } : { disconnect: true }\n }\n\n const post = await prisma.post.update({\n where: { id },\n data: updatePayload,\n })\n\n // Update tag associations if provided\n if (tagIds !== undefined) {\n // Delete existing tags and create new ones\n await prisma.postTag.deleteMany({ where: { postId: id } })\n if (tagIds.length) {\n await prisma.postTag.createMany({\n data: tagIds.map((tagId: string) => ({ postId: id, tagId })),\n })\n }\n }\n\n // Fetch with tags included\n const result = await prisma.post.findUnique({\n where: { id },\n include: { tags: { include: { tag: true } } },\n })\n\n if (hooks?.afterSave) {\n await hooks.afterSave(result)\n }\n\n return result\n },\n\n async delete(id: string) {\n // Soft delete - set status to 'deleted' instead of removing\n return prisma.post.update({ \n where: { id },\n data: { status: 'deleted' },\n })\n },\n\n async getPreviewUrl(id: string, basePath: string = '/e') {\n const token = crypto.randomUUID()\n const expiry = new Date(Date.now() + 24 * 60 * 60 * 1000) // 24 hours\n\n const post = await prisma.post.update({\n where: { id },\n data: { previewToken: token, previewExpiry: expiry },\n })\n\n return `${basePath}/${post.slug}?preview=${token}`\n },\n\n async findByPreviewToken(token: string) {\n const post = await prisma.post.findFirst({\n where: {\n previewToken: token,\n previewExpiry: { gt: new Date() },\n },\n })\n return post\n },\n }\n}\n","/**\n * Comments data layer for autoblogger.\n * Supports both public blog comments (simple) and editor comments (with quotedText, replies, resolve).\n */\n\ninterface CommentsConfig {\n mode?: 'authenticated' | 'public' | 'disabled'\n}\n\n// Editor comment with full features\ninterface EditorComment {\n id: string\n postId: string\n userId: string\n quotedText: string\n content: string\n parentId: string | null\n resolved: boolean\n createdAt: Date\n updatedAt: Date\n user: {\n id: string\n name: string | null\n email: string\n }\n replies?: EditorComment[]\n}\n\ninterface CreateEditorCommentInput {\n postId: string\n quotedText: string\n content: string\n parentId?: string\n}\n\n// Simple public comment (for blog post comments)\ninterface CreatePublicCommentInput {\n postId: string\n content: string\n authorId?: string\n authorName?: string\n authorEmail?: string\n}\n\nexport function createCommentsData(prisma: any, config?: CommentsConfig) {\n const mode = config?.mode || 'authenticated'\n\n return {\n async count() {\n if (mode === 'disabled') return 0\n return prisma.comment.count()\n },\n\n // Public blog comments (original simple system)\n async findByPost(postId: string) {\n if (mode === 'disabled') return []\n \n return prisma.comment.findMany({\n where: { postId, approved: true },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findAll(options?: { postId?: string; approved?: boolean; page?: number; limit?: number }) {\n if (mode === 'disabled') return { data: [], total: 0, page: 1, totalPages: 1 }\n \n const page = options?.page || 1\n const limit = options?.limit || 25\n const skip = (page - 1) * limit\n\n const where = {\n ...(options?.postId ? { postId: options.postId } : {}),\n ...(options?.approved !== undefined ? { approved: options.approved } : {}),\n }\n\n const [comments, total] = await Promise.all([\n prisma.comment.findMany({\n where,\n orderBy: { createdAt: 'desc' },\n skip,\n take: limit,\n include: { \n post: { select: { id: true, title: true, slug: true } },\n user: { select: { id: true, name: true, email: true } },\n },\n }),\n prisma.comment.count({ where }),\n ])\n\n return {\n data: comments,\n total,\n page,\n totalPages: Math.ceil(total / limit),\n }\n },\n\n async create(data: CreatePublicCommentInput) {\n if (mode === 'disabled') {\n throw new Error('Comments are disabled')\n }\n\n return prisma.comment.create({\n data: {\n ...data,\n approved: mode === 'authenticated',\n },\n })\n },\n\n async approve(id: string) {\n return prisma.comment.update({\n where: { id },\n data: { approved: true },\n })\n },\n\n async delete(id: string) {\n return prisma.comment.delete({ where: { id } })\n },\n\n getMode() {\n return mode\n },\n\n // ========================================\n // Editor comments (with quotedText, replies, resolve)\n // ========================================\n\n /**\n * Find all editor comments for a post with nested replies.\n */\n async findEditorComments(postId: string, userId?: string): Promise<EditorComment[]> {\n if (mode === 'disabled') return []\n\n // Fetch all non-deleted comments for the post\n const allComments = await prisma.comment.findMany({\n where: {\n postId,\n deletedAt: null,\n },\n orderBy: { createdAt: 'desc' },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n // Separate top-level and replies\n const topLevel = allComments.filter((c: any) => !c.parentId)\n const replies = allComments.filter((c: any) => c.parentId)\n\n // Attach replies to their parents\n return topLevel.map((comment: any) => ({\n ...comment,\n replies: replies.filter((r: any) => r.parentId === comment.id),\n }))\n },\n\n /**\n * Create an editor comment (with quotedText and optional parentId for replies).\n */\n async createEditorComment(\n postId: string,\n userId: string,\n data: CreateEditorCommentInput\n ): Promise<EditorComment> {\n if (mode === 'disabled') {\n throw new Error('Comments are disabled')\n }\n\n const comment = await prisma.comment.create({\n data: {\n postId,\n userId,\n quotedText: data.quotedText || '',\n content: data.content,\n parentId: data.parentId || null,\n resolved: false,\n },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return { ...comment, replies: [] }\n },\n\n /**\n * Update a comment's content.\n */\n async updateEditorComment(\n commentId: string,\n content: string,\n userId?: string\n ): Promise<EditorComment> {\n const comment = await prisma.comment.update({\n where: { id: commentId },\n data: { content },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return comment\n },\n\n /**\n * Soft delete a comment.\n */\n async deleteEditorComment(commentId: string): Promise<void> {\n // Check if the schema has deletedAt field\n const hasDeletedAt = await prisma.comment.findFirst({\n where: { id: commentId },\n select: { id: true },\n })\n\n if (hasDeletedAt) {\n // Try soft delete first, fall back to hard delete\n try {\n await prisma.comment.update({\n where: { id: commentId },\n data: { deletedAt: new Date() },\n })\n } catch {\n // Schema doesn't have deletedAt, do hard delete\n await prisma.comment.delete({ where: { id: commentId } })\n }\n }\n },\n\n /**\n * Toggle resolved status.\n */\n async toggleResolve(commentId: string): Promise<EditorComment> {\n const current = await prisma.comment.findUnique({\n where: { id: commentId },\n select: { resolved: true },\n })\n\n const comment = await prisma.comment.update({\n where: { id: commentId },\n data: { resolved: !current?.resolved },\n include: {\n user: {\n select: { id: true, name: true, email: true },\n },\n },\n })\n\n return comment\n },\n\n /**\n * Resolve all open comments for a post.\n */\n async resolveAll(postId: string): Promise<{ resolved: number }> {\n const result = await prisma.comment.updateMany({\n where: {\n postId,\n resolved: false,\n parentId: null, // Only top-level comments\n },\n data: { resolved: true },\n })\n\n return { resolved: result.count }\n },\n }\n}\n","// Generic CRUD factory for data layer\n\nexport interface CrudOptions {\n model: string\n defaultOrderBy?: Record<string, 'asc' | 'desc'>\n defaultInclude?: Record<string, unknown>\n}\n\nexport interface BaseCrud<T> {\n findAll: (opts?: { skip?: number; take?: number; where?: Record<string, unknown> }) => Promise<T[]>\n findById: (id: string) => Promise<T | null>\n count: (where?: Record<string, unknown>) => Promise<number>\n create: (data: Partial<T>) => Promise<T>\n update: (id: string, data: Partial<T>) => Promise<T>\n delete: (id: string) => Promise<T>\n}\n\n/**\n * Create a base CRUD data layer for a Prisma model.\n * Use spread operator to extend with custom methods:\n * \n * ```typescript\n * const base = createCrudData(prisma, { model: 'tag', defaultOrderBy: { name: 'asc' } })\n * return {\n * ...base,\n * customMethod: async () => { ... }\n * }\n * ```\n */\nexport function createCrudData<T>(prisma: any, options: CrudOptions): BaseCrud<T> {\n const delegate = prisma[options.model]\n \n return {\n async findAll(opts?: { skip?: number; take?: number; where?: Record<string, unknown> }) {\n return delegate.findMany({\n orderBy: options.defaultOrderBy,\n include: options.defaultInclude,\n ...opts,\n })\n },\n\n async findById(id: string) {\n return delegate.findUnique({\n where: { id },\n include: options.defaultInclude,\n })\n },\n\n async count(where?: Record<string, unknown>) {\n return delegate.count({ where })\n },\n\n async create(data: Partial<T>) {\n return delegate.create({ data })\n },\n\n async update(id: string, data: Partial<T>) {\n return delegate.update({\n where: { id },\n data,\n })\n },\n\n async delete(id: string) {\n return delegate.delete({ where: { id } })\n },\n }\n}\n","import { createCrudData } from './factory'\n\nexport function createTagsData(prisma: any) {\n const base = createCrudData(prisma, {\n model: 'tag',\n defaultOrderBy: { name: 'asc' },\n defaultInclude: { _count: { select: { posts: true } } },\n })\n\n return {\n ...base,\n\n // Alias for backward compatibility\n async findAllWithCounts() {\n return base.findAll()\n },\n\n async findByName(name: string) {\n return prisma.tag.findUnique({ where: { name } })\n },\n\n // Override create to accept string directly\n async create(name: string) {\n return prisma.tag.create({ data: { name } })\n },\n\n // Override update to accept name directly\n async update(id: string, name: string) {\n return prisma.tag.update({ where: { id }, data: { name } })\n },\n\n async addToPost(postId: string, tagId: string) {\n return prisma.postTag.create({\n data: { postId, tagId },\n })\n },\n\n async removeFromPost(postId: string, tagId: string) {\n return prisma.postTag.deleteMany({\n where: { postId, tagId },\n })\n },\n\n async getPostTags(postId: string) {\n const postTags = await prisma.postTag.findMany({\n where: { postId },\n include: { tag: true },\n })\n return postTags.map((pt: any) => pt.tag)\n },\n }\n}\n","export function createRevisionsData(prisma: any) {\n return {\n async findAll(options?: { postId?: string; skip?: number; take?: number }) {\n return prisma.revision.findMany({\n where: options?.postId ? { postId: options.postId } : {},\n orderBy: { createdAt: 'desc' },\n skip: options?.skip,\n take: options?.take,\n include: {\n post: { select: { id: true, title: true, slug: true, markdown: true } },\n },\n })\n },\n\n async count(where?: { postId?: string }) {\n return prisma.revision.count({ where })\n },\n\n async findByPost(postId: string) {\n return prisma.revision.findMany({\n where: { postId },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.revision.findUnique({\n where: { id },\n include: {\n post: { select: { id: true, title: true, slug: true, markdown: true } },\n },\n })\n },\n\n async create(postId: string, data: { title?: string; subtitle?: string; markdown: string }) {\n return prisma.revision.create({\n data: { postId, ...data },\n })\n },\n\n async restore(revisionId: string) {\n const revision = await prisma.revision.findUnique({ where: { id: revisionId } })\n if (!revision) throw new Error('Revision not found')\n\n return prisma.post.update({\n where: { id: revision.postId },\n data: {\n title: revision.title,\n subtitle: revision.subtitle,\n markdown: revision.markdown,\n },\n })\n },\n\n async compare(revisionId1: string, revisionId2: string) {\n const [rev1, rev2] = await Promise.all([\n prisma.revision.findUnique({ where: { id: revisionId1 } }),\n prisma.revision.findUnique({ where: { id: revisionId2 } }),\n ])\n\n if (!rev1 || !rev2) throw new Error('Revision not found')\n\n return {\n older: rev1.createdAt < rev2.createdAt ? rev1 : rev2,\n newer: rev1.createdAt < rev2.createdAt ? rev2 : rev1,\n }\n },\n\n async pruneOldest(postId: string, keepCount: number) {\n const revisions = await prisma.revision.findMany({\n where: { postId },\n orderBy: { createdAt: 'desc' },\n skip: keepCount,\n select: { id: true },\n })\n\n if (revisions.length > 0) {\n await prisma.revision.deleteMany({\n where: { id: { in: revisions.map((r: any) => r.id) } },\n })\n }\n\n return revisions.length\n },\n\n async delete(id: string) {\n return prisma.revision.delete({ where: { id } })\n },\n }\n}\n","export function createAISettingsData(prisma: any) {\n const DEFAULT_ID = 'default'\n\n return {\n async get() {\n let settings = await prisma.aISettings.findUnique({ where: { id: DEFAULT_ID } })\n \n if (!settings) {\n settings = await prisma.aISettings.create({\n data: { id: DEFAULT_ID },\n })\n }\n \n return settings\n },\n\n async update(data: {\n rules?: string\n chatRules?: string\n rewriteRules?: string\n autoDraftRules?: string\n planRules?: string\n defaultModel?: string\n autoDraftWordCount?: number\n generateTemplate?: string | null\n chatTemplate?: string | null\n rewriteTemplate?: string | null\n autoDraftTemplate?: string | null\n planTemplate?: string | null\n expandPlanTemplate?: string | null\n agentTemplate?: string | null\n anthropicKey?: string | null\n openaiKey?: string | null\n }) {\n return prisma.aISettings.upsert({\n where: { id: DEFAULT_ID },\n create: { id: DEFAULT_ID, ...data },\n update: data,\n })\n },\n }\n}\n","interface CreateTopicInput {\n name: string\n keywords?: string[]\n rssFeeds?: string[]\n isActive?: boolean\n useKeywordFilter?: boolean\n frequency?: string\n maxPerPeriod?: number\n essayFocus?: string\n}\n\ninterface UpdateTopicInput {\n name?: string\n keywords?: string[]\n rssFeeds?: string[]\n isActive?: boolean\n useKeywordFilter?: boolean\n frequency?: string\n maxPerPeriod?: number\n essayFocus?: string\n lastRunAt?: Date\n}\n\nexport function createTopicsData(prisma: any) {\n return {\n async findAll() {\n return prisma.topicSubscription.findMany({\n orderBy: { createdAt: 'desc' },\n include: {\n _count: { select: { posts: true, newsItems: true } },\n },\n })\n },\n\n async count() {\n return prisma.topicSubscription.count()\n },\n\n async findActive() {\n return prisma.topicSubscription.findMany({\n where: { isActive: true },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.topicSubscription.findUnique({\n where: { id },\n include: { posts: true, newsItems: true },\n })\n },\n\n async create(data: CreateTopicInput) {\n return prisma.topicSubscription.create({\n data: {\n name: data.name,\n keywords: JSON.stringify(data.keywords || []),\n rssFeeds: JSON.stringify(data.rssFeeds || []),\n isActive: data.isActive ?? true,\n useKeywordFilter: data.useKeywordFilter ?? true,\n frequency: data.frequency || 'daily',\n maxPerPeriod: data.maxPerPeriod || 3,\n essayFocus: data.essayFocus,\n },\n })\n },\n\n async update(id: string, data: UpdateTopicInput) {\n const updateData: any = { ...data }\n \n if (data.keywords) {\n updateData.keywords = JSON.stringify(data.keywords)\n }\n if (data.rssFeeds) {\n updateData.rssFeeds = JSON.stringify(data.rssFeeds)\n }\n\n return prisma.topicSubscription.update({\n where: { id },\n data: updateData,\n })\n },\n\n async delete(id: string) {\n return prisma.topicSubscription.delete({ where: { id } })\n },\n\n async markRun(id: string) {\n return prisma.topicSubscription.update({\n where: { id },\n data: { lastRunAt: new Date() },\n })\n },\n }\n}\n","interface CreateNewsItemInput {\n topicId: string\n url: string\n title: string\n summary?: string\n publishedAt?: Date\n}\n\nexport function createNewsItemsData(prisma: any) {\n return {\n async findPending() {\n return prisma.newsItem.findMany({\n where: { status: 'pending' },\n orderBy: { createdAt: 'desc' },\n include: { topic: true },\n })\n },\n\n async findByTopic(topicId: string) {\n return prisma.newsItem.findMany({\n where: { topicId },\n orderBy: { createdAt: 'desc' },\n })\n },\n\n async findById(id: string) {\n return prisma.newsItem.findUnique({\n where: { id },\n include: { topic: true, post: true },\n })\n },\n\n async create(data: CreateNewsItemInput) {\n // Check if URL already exists\n const existing = await prisma.newsItem.findUnique({\n where: { url: data.url },\n })\n \n if (existing) {\n return existing\n }\n\n return prisma.newsItem.create({ data })\n },\n\n async skip(id: string) {\n return prisma.newsItem.update({\n where: { id },\n data: { status: 'skipped' },\n })\n },\n\n async markGenerated(id: string, postId: string) {\n return prisma.newsItem.update({\n where: { id },\n data: { status: 'generated', postId },\n })\n },\n\n async delete(id: string) {\n return prisma.newsItem.delete({ where: { id } })\n },\n\n // This would be called by the auto-draft system\n async generateDraft(id: string, createPost: (data: any) => Promise<any>) {\n const newsItem = await prisma.newsItem.findUnique({\n where: { id },\n include: { topic: true },\n })\n\n if (!newsItem) throw new Error('News item not found')\n\n // Create draft post\n const post = await createPost({\n title: newsItem.title,\n markdown: newsItem.summary || '',\n status: 'suggested',\n sourceUrl: newsItem.url,\n topicId: newsItem.topicId,\n })\n\n // Mark as generated\n await prisma.newsItem.update({\n where: { id },\n data: { status: 'generated', postId: post.id },\n })\n\n return post\n },\n }\n}\n","import { createCrudData } from './factory'\n\ninterface CreateUserInput {\n email: string\n name?: string\n role?: string\n}\n\ninterface UpdateUserInput {\n name?: string\n role?: string\n}\n\nexport function createUsersData(prisma: any) {\n const base = createCrudData(prisma, {\n model: 'user',\n defaultOrderBy: { createdAt: 'desc' },\n })\n\n return {\n ...base,\n\n async findByEmail(email: string) {\n return prisma.user.findUnique({ where: { email } })\n },\n\n // Override create with proper defaults\n async create(data: CreateUserInput) {\n return prisma.user.create({\n data: {\n email: data.email,\n name: data.name,\n role: data.role || 'writer',\n },\n })\n },\n\n // Override update with proper typing\n async update(id: string, data: UpdateUserInput) {\n return prisma.user.update({\n where: { id },\n data,\n })\n },\n }\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nfunction jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\nfunction countWords(text?: string | null): number {\n if (!text) return 0\n return text.split(/\\s+/).filter(Boolean).length\n}\n\nfunction withWordCount<T extends { markdown?: string | null }>(post: T): T & { wordCount: number } {\n return { ...post, wordCount: countWords(post.markdown) }\n}\n\nexport async function handlePostsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const segments = path.split('/').filter(Boolean)\n const postId = segments[1]\n \n // Handle nested comment routes: /posts/:id/comments\n if (postId && segments[2] === 'comments') {\n return handlePostCommentsAPI(req, cms, session, postId, segments.slice(3), onMutate)\n }\n\n // GET /posts - list posts\n if (method === 'GET' && !postId) {\n const url = new URL(req.url)\n const status = url.searchParams.get('status')\n const all = url.searchParams.get('all') === '1'\n const page = parseInt(url.searchParams.get('page') || '1', 10)\n const limit = parseInt(url.searchParams.get('limit') || '0', 10)\n const includeRevisionCount = url.searchParams.get('includeRevisionCount') === '1'\n \n // Calculate pagination\n const skip = limit > 0 ? (page - 1) * limit : undefined\n const take = limit > 0 ? limit : undefined\n \n // Get total count for pagination\n const total = await cms.posts.count(all ? undefined : { status: status || undefined })\n \n const posts = await cms.posts.findAll({ \n status: all ? undefined : (status || undefined),\n skip,\n take,\n includeRevisionCount,\n })\n return jsonResponse({ data: posts.map(withWordCount), total })\n }\n\n // GET /posts/:id - get single post\n if (method === 'GET' && postId) {\n const post = await cms.posts.findById(postId)\n if (!post) return jsonResponse({ error: 'Post not found' }, 404)\n return jsonResponse({ data: withWordCount(post) })\n }\n\n // POST /posts - create post\n if (method === 'POST') {\n const body = await req.json()\n const post = await cms.posts.create(body)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post }, 201)\n }\n\n // PATCH /posts/:id - update post\n if (method === 'PATCH' && postId) {\n const body = await req.json()\n \n // Check publish permission\n if (body.status === 'published' && !cms.config.auth.canPublish(session)) {\n return jsonResponse({ error: 'Not authorized to publish' }, 403)\n }\n \n const post = await cms.posts.update(postId, body)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post })\n }\n\n // DELETE /posts/:id - delete post\n if (method === 'DELETE' && postId) {\n if (!cms.config.auth.isAdmin(session)) {\n return jsonResponse({ error: 'Admin required' }, 403)\n }\n await cms.posts.delete(postId)\n if (onMutate) await onMutate('post', { id: postId })\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n\n/**\n * Handle post-specific comment routes: /posts/:postId/comments/*\n * These are editor comments (with quotedText, replies, resolve).\n */\nasync function handlePostCommentsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n postId: string,\n segments: string[], // e.g., [] for /comments, ['abc'] for /comments/abc, ['abc', 'resolve'] for /comments/abc/resolve\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const commentId = segments[0]\n const action = segments[1] // e.g., 'resolve'\n \n const userId = session?.user?.id\n if (!userId) {\n return jsonResponse({ error: 'Authentication required' }, 401)\n }\n\n // GET /posts/:id/comments - list comments for post\n if (method === 'GET' && !commentId) {\n const comments = await cms.comments.findEditorComments(postId, userId)\n return jsonResponse({ data: comments })\n }\n\n // POST /posts/:id/comments - create comment\n if (method === 'POST' && !commentId) {\n const body = await req.json()\n const comment = await cms.comments.createEditorComment(postId, userId, {\n postId,\n quotedText: body.quotedText || '',\n content: body.content,\n parentId: body.parentId,\n })\n if (onMutate) await onMutate('comment', comment)\n return jsonResponse({ data: comment }, 201)\n }\n\n // POST /posts/:id/comments/resolve-all - resolve all comments\n if (method === 'POST' && commentId === 'resolve-all') {\n const result = await cms.comments.resolveAll(postId)\n return jsonResponse({ data: result })\n }\n\n // PATCH /posts/:id/comments/:commentId - update comment\n if (method === 'PATCH' && commentId && !action) {\n const body = await req.json()\n const comment = await cms.comments.updateEditorComment(commentId, body.content, userId)\n return jsonResponse({ data: comment })\n }\n\n // POST /posts/:id/comments/:commentId/resolve - toggle resolve\n if (method === 'POST' && commentId && action === 'resolve') {\n const comment = await cms.comments.toggleResolve(commentId)\n return jsonResponse({ data: comment })\n }\n\n // DELETE /posts/:id/comments/:commentId - delete comment\n if (method === 'DELETE' && commentId) {\n await cms.comments.deleteEditorComment(commentId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer } from '../server'\nimport type { Session } from '../types/session'\n\n/**\n * Create a JSON response with proper headers.\n */\nexport function jsonResponse(data: unknown, status = 200): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\n/**\n * Parse URL path into segments and common parts.\n */\nexport function parsePath(path: string): {\n segments: string[]\n resource: string\n id?: string\n subPath: string\n} {\n const segments = path.split('/').filter(Boolean)\n return {\n segments,\n resource: segments[0] || '',\n id: segments[1],\n subPath: segments.slice(2).join('/'),\n }\n}\n\n/**\n * Check if user is admin, return error response if not.\n * Returns null if authorized.\n */\nexport function requireAdmin(\n cms: AutobloggerServer,\n session: Session | null\n): Response | null {\n if (!cms.config.auth.isAdmin(session)) {\n return jsonResponse({ error: 'Admin required' }, 403)\n }\n return null\n}\n\n/**\n * Check if user is authenticated, return error response if not.\n * Returns null if authorized.\n */\nexport function requireAuth(session: Session | null): Response | null {\n if (!session) {\n return jsonResponse({ error: 'Authentication required' }, 401)\n }\n return null\n}\n\n/**\n * Check if user can publish, return error response if not.\n * Returns null if authorized.\n */\nexport function requirePublish(\n cms: AutobloggerServer,\n session: Session | null\n): Response | null {\n if (!cms.config.auth.canPublish(session)) {\n return jsonResponse({ error: 'Publish permission required' }, 403)\n }\n return null\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleCommentsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: commentId, subPath } = parsePath(path)\n\n // GET /comments - list comments (with pagination)\n if (method === 'GET') {\n const url = new URL(req.url)\n const postId = url.searchParams.get('postId')\n const page = parseInt(url.searchParams.get('page') || '1')\n const limit = parseInt(url.searchParams.get('limit') || '25')\n const result = await cms.comments.findAll({ \n postId: postId || undefined,\n page,\n limit,\n })\n return jsonResponse(result)\n }\n\n // POST /comments - create comment\n if (method === 'POST') {\n const body = await req.json()\n const comment = await cms.comments.create({\n ...body,\n authorId: session?.user?.id,\n })\n if (onMutate) await onMutate('comment', comment)\n return jsonResponse({ data: comment }, 201)\n }\n\n // PATCH /comments/:id/approve - approve comment\n if (method === 'PATCH' && commentId && subPath === 'approve') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const comment = await cms.comments.approve(commentId)\n return jsonResponse({ data: comment })\n }\n\n // DELETE /comments/:id - delete comment\n if (method === 'DELETE' && commentId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.comments.delete(commentId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleTagsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: tagId } = parsePath(path)\n\n // GET /tags - list all tags\n if (method === 'GET' && !tagId) {\n const tags = await cms.tags.findAll()\n return jsonResponse({ data: tags })\n }\n\n // POST /tags - create tag\n if (method === 'POST') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const body = await req.json()\n const tag = await cms.tags.create(body.name)\n if (onMutate) await onMutate('tag', tag)\n return jsonResponse({ data: tag }, 201)\n }\n\n // PATCH /tags/:id - update tag\n if (method === 'PATCH' && tagId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const body = await req.json()\n const tag = await cms.tags.update(tagId, body.name)\n return jsonResponse({ data: tag })\n }\n\n // DELETE /tags/:id - delete tag\n if (method === 'DELETE' && tagId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.tags.delete(tagId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport {\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_AGENT_TEMPLATE,\n DEFAULT_SEARCH_ONLY_PROMPT,\n} from '../ai/prompts'\nimport { getModelOptions } from '../ai/models'\nimport { jsonResponse, requireAuth, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleAIAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n \n // Check auth\n const authError = requireAuth(session)\n if (authError) return authError\n\n // GET /ai/settings - get AI settings\n if (method === 'GET' && path === '/ai/settings') {\n const settings = await cms.aiSettings.get()\n \n // Check if API keys are available from config or environment variables\n const hasAnthropicEnvKey = !!(cms.config.ai?.anthropicKey || process.env.ANTHROPIC_API_KEY)\n const hasOpenaiEnvKey = !!(cms.config.ai?.openaiKey || process.env.OPENAI_API_KEY)\n \n // Include default templates for the UI to display as placeholders\n return jsonResponse({ \n data: {\n ...settings,\n // Don't expose actual env keys, just indicate they exist\n hasAnthropicEnvKey,\n hasOpenaiEnvKey,\n defaultGenerateTemplate: DEFAULT_GENERATE_TEMPLATE,\n defaultChatTemplate: DEFAULT_CHAT_TEMPLATE,\n defaultRewriteTemplate: DEFAULT_REWRITE_TEMPLATE,\n defaultAutoDraftTemplate: DEFAULT_AUTO_DRAFT_TEMPLATE,\n defaultPlanTemplate: DEFAULT_PLAN_TEMPLATE,\n defaultExpandPlanTemplate: DEFAULT_EXPAND_PLAN_TEMPLATE,\n defaultAgentTemplate: DEFAULT_AGENT_TEMPLATE,\n defaultPlanRules: DEFAULT_PLAN_RULES,\n availableModels: getModelOptions(),\n }\n })\n }\n\n // PATCH /ai/settings - update AI settings\n if (method === 'PATCH' && path === '/ai/settings') {\n const adminError = requireAdmin(cms, session)\n if (adminError) return adminError\n\n const body = await req.json()\n const settings = await cms.aiSettings.update(body)\n return jsonResponse({ data: settings })\n }\n\n // POST /ai/generate - generate content (streaming)\n if (method === 'POST' && path === '/ai/generate') {\n const body = await req.json()\n const { prompt, model, wordCount, mode, plan, styleExamples: clientStyleExamples, useWebSearch, useThinking } = body\n \n // Get AI settings for rules\n const settings = await cms.aiSettings.get()\n \n try {\n let stream: ReadableStream\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n\n if (mode === 'expand_plan' && plan) {\n // Fetch published essays as style examples if not provided by client\n let styleExamples = clientStyleExamples || ''\n if (!styleExamples) {\n styleExamples = await fetchStyleExamples(cms)\n }\n \n // Draft essay from plan mode\n const { expandPlanStream } = await import('../ai/generate')\n stream = await expandPlanStream({\n plan,\n model: model || settings.defaultModel,\n rules: settings.rules,\n template: settings.expandPlanTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n })\n } else {\n // Fetch published essays as style examples for standard generation too\n let styleExamples = clientStyleExamples || ''\n if (!styleExamples) {\n styleExamples = await fetchStyleExamples(cms)\n }\n \n // Standard generation\n const { generateStream } = await import('../ai/generate')\n stream = await generateStream({\n prompt,\n model: model || settings.defaultModel,\n wordCount,\n rules: settings.rules,\n template: settings.generateTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n useWebSearch,\n useThinking,\n })\n }\n \n return new Response(stream, {\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'Connection': 'keep-alive',\n },\n })\n } catch (error) {\n console.error('[AI Generate Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Generation failed' \n }, 500)\n }\n }\n\n // POST /ai/chat - chat with AI (streaming or search mode)\n if (method === 'POST' && path === '/ai/chat') {\n const body = await req.json()\n const { messages, model, essayContext, mode, useWebSearch, useThinking } = body\n \n const settings = await cms.aiSettings.get()\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n \n // Handle search mode - non-streaming JSON response\n if (mode === 'search') {\n try {\n const { generate } = await import('../ai/provider')\n \n // Get the last user message as the search query\n const lastUserMessage = [...messages].reverse().find((m: { role: string }) => m.role === 'user')\n if (!lastUserMessage) {\n return jsonResponse({ error: 'No user message found' }, 400)\n }\n \n const result = await generate(\n model || settings.defaultModel,\n DEFAULT_SEARCH_ONLY_PROMPT,\n lastUserMessage.content,\n {\n anthropicKey,\n openaiKey,\n maxTokens: 4096,\n useWebSearch: true, // Always use web search in search mode\n }\n )\n \n return jsonResponse({ \n content: result.text,\n usage: {\n inputTokens: result.inputTokens,\n outputTokens: result.outputTokens,\n }\n })\n } catch (error) {\n console.error('[AI Search Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Search failed' \n }, 500)\n }\n }\n \n // Fetch published essays as style examples\n let styleExamples = ''\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 5\n const MAX_WORDS_PER_EXAMPLE = 500\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n // Truncate long essays to avoid massive prompts\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${post.subtitle ? `*${post.subtitle}*\\n` : ''}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n styleExamples = `<published_essays>\nThe following are examples of the author's published work. Use these to match their voice, tone, and writing style:\n\n${examples}\n</published_essays>`\n }\n } catch (err) {\n console.error('[AI Chat] Failed to fetch published essays:', err)\n // Continue without style examples\n }\n \n const { chatStream } = await import('../ai/chat')\n \n try {\n const stream = await chatStream({\n messages,\n model: model || settings.defaultModel,\n essayContext,\n mode,\n chatRules: settings.chatRules,\n rules: settings.rules,\n template: settings.chatTemplate,\n // Plan mode specific settings\n planTemplate: settings.planTemplate,\n planRules: settings.planRules,\n // Agent mode specific settings\n agentTemplate: settings.agentTemplate,\n styleExamples,\n anthropicKey,\n openaiKey,\n useWebSearch,\n useThinking,\n })\n \n return new Response(stream, {\n headers: {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'Connection': 'keep-alive',\n },\n })\n } catch (error) {\n console.error('[AI Chat Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Chat failed' \n }, 500)\n }\n }\n\n // POST /ai/rewrite - rewrite selected text (non-streaming)\n if (method === 'POST' && path === '/ai/rewrite') {\n const body = await req.json()\n const { text } = body\n \n if (!text || typeof text !== 'string') {\n return jsonResponse({ error: 'Text is required' }, 400)\n }\n \n const settings = await cms.aiSettings.get()\n \n // Use keys from config, falling back to database settings\n const anthropicKey = cms.config.ai?.anthropicKey || settings.anthropicKey\n const openaiKey = cms.config.ai?.openaiKey || settings.openaiKey\n \n // Fetch published essays as style examples\n let styleExamples = ''\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 3\n const MAX_WORDS_PER_EXAMPLE = 300\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n styleExamples = examples\n }\n } catch (err) {\n console.error('[AI Rewrite] Failed to fetch published essays:', err)\n }\n \n const { buildRewritePrompt } = await import('../ai/builders')\n const { createStream } = await import('../ai/provider')\n \n try {\n const systemPrompt = buildRewritePrompt({\n rewriteRules: settings.rewriteRules,\n rules: settings.rules,\n template: settings.rewriteTemplate,\n styleExamples,\n })\n \n // Use streaming internally but collect full response\n const stream = await createStream({\n model: settings.defaultModel,\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: `Rewrite the following text, preserving meaning but improving clarity and style:\\n\\n${text}` },\n ],\n anthropicKey,\n openaiKey,\n maxTokens: 2048,\n })\n \n // Collect the streamed response\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n let rewrittenText = ''\n \n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n \n const chunk = decoder.decode(value, { stream: true })\n const lines = chunk.split('\\n')\n \n for (const line of lines) {\n if (line.startsWith('data: ')) {\n const data = line.slice(6)\n if (data === '[DONE]') continue\n try {\n const parsed = JSON.parse(data)\n if (parsed.text) {\n rewrittenText += parsed.text\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n }\n \n return jsonResponse({ text: rewrittenText.trim() })\n } catch (error) {\n console.error('[AI Rewrite Error]', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Rewrite failed' \n }, 500)\n }\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n\n// Helper to fetch published essays as style examples\nasync function fetchStyleExamples(cms: Autoblogger): Promise<string> {\n try {\n const publishedPosts = await cms.posts.findPublished()\n const MAX_STYLE_EXAMPLES = 5\n const MAX_WORDS_PER_EXAMPLE = 500\n \n if (publishedPosts.length > 0) {\n const examples = publishedPosts\n .slice(0, MAX_STYLE_EXAMPLES)\n .map((post: { title: string; subtitle?: string; markdown: string }) => {\n const words = post.markdown.split(/\\s+/)\n const truncatedContent = words.length > MAX_WORDS_PER_EXAMPLE\n ? words.slice(0, MAX_WORDS_PER_EXAMPLE).join(' ') + '...'\n : post.markdown\n \n return `## ${post.title}\n${post.subtitle ? `*${post.subtitle}*\\n` : ''}\n${truncatedContent}`\n })\n .join('\\n\\n---\\n\\n')\n \n return `The following are examples of the author's published work. Use these to match their voice, tone, and writing style:\n\n${examples}`\n }\n } catch (err) {\n console.error('[AI] Failed to fetch published essays:', err)\n }\n return ''\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, requireAuth } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleUploadAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null\n): Promise<Response> {\n if (req.method !== 'POST') {\n return jsonResponse({ error: 'Method not allowed' }, 405)\n }\n \n const authError = requireAuth(session)\n if (authError) return authError\n \n if (!cms.config.storage?.upload) {\n return jsonResponse({ \n error: 'Image uploads not configured. Add storage.upload to your autoblogger config.' \n }, 400)\n }\n\n try {\n const formData = await req.formData()\n // Support both 'image' (toolbar uploads) and 'file' (general uploads) field names\n const file = (formData.get('image') || formData.get('file')) as File\n \n if (!file) {\n return jsonResponse({ error: 'No file provided' }, 400)\n }\n \n // Validate file type\n const allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']\n if (!allowedTypes.includes(file.type)) {\n return jsonResponse({ \n error: 'Invalid file type. Allowed: JPEG, PNG, GIF, WebP' \n }, 400)\n }\n \n // Validate file size (4MB max)\n const maxSize = 4 * 1024 * 1024\n if (file.size > maxSize) {\n return jsonResponse({ error: 'File too large. Maximum size: 4MB' }, 400)\n }\n \n const result = await cms.config.storage.upload(file)\n return jsonResponse({ data: result })\n } catch (error) {\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Upload failed' \n }, 500)\n }\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleTopicsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const { id: topicId, subPath } = parsePath(path)\n\n // Check admin for all topic operations\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /topics - list topics\n if (method === 'GET' && !topicId) {\n const topics = await cms.topics.findAll()\n return jsonResponse({ data: topics })\n }\n\n // GET /topics/:id - get single topic\n if (method === 'GET' && topicId) {\n const topic = await cms.topics.findById(topicId)\n if (!topic) return jsonResponse({ error: 'Topic not found' }, 404)\n return jsonResponse({ data: topic })\n }\n\n // POST /topics - create topic\n if (method === 'POST' && !topicId) {\n const body = await req.json()\n const topic = await cms.topics.create(body)\n if (onMutate) await onMutate('topic', topic)\n return jsonResponse({ data: topic }, 201)\n }\n\n // POST /topics/:id/generate - trigger generation for a topic\n if (method === 'POST' && topicId && subPath === 'generate') {\n // Mark topic as run\n await cms.topics.markRun(topicId)\n // Note: Actual RSS fetching and essay generation would be implemented\n // by the host application via hooks or a separate service\n return jsonResponse({ \n data: { \n success: true, \n message: 'Generation triggered. Implement generation logic in your application.',\n } \n })\n }\n\n // PATCH /topics/:id - update topic\n if (method === 'PATCH' && topicId) {\n const body = await req.json()\n const topic = await cms.topics.update(topicId, body)\n return jsonResponse({ data: topic })\n }\n\n // DELETE /topics/:id - delete topic\n if (method === 'DELETE' && topicId) {\n await cms.topics.delete(topicId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\n/**\n * Normalize email address (lowercase, trim)\n */\nfunction normalizeEmail(email: string): string {\n return email.toLowerCase().trim()\n}\n\nexport async function handleUsersAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n const { id: userId } = parsePath(path)\n\n // All user operations require admin\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /users - list all users\n if (method === 'GET' && !userId) {\n const users = await cms.users.findAll()\n return jsonResponse({ data: users })\n }\n\n // GET /users/:id - get single user\n if (method === 'GET' && userId) {\n const user = await cms.users.findById(userId)\n if (!user) return jsonResponse({ error: 'User not found' }, 404)\n return jsonResponse({ data: user })\n }\n\n // POST /users - create user\n if (method === 'POST') {\n const body = await req.json()\n if (!body.email) {\n return jsonResponse({ error: 'Email required' }, 400)\n }\n\n const email = normalizeEmail(body.email)\n \n // Check for duplicate email\n const existing = await cms.users.findByEmail(email)\n if (existing) {\n return jsonResponse({ error: 'User with this email already exists' }, 400)\n }\n\n const user = await cms.users.create({\n ...body,\n email, // Use normalized email\n })\n return jsonResponse({ data: user }, 201)\n }\n\n // PATCH /users/:id - update user\n if (method === 'PATCH' && userId) {\n const body = await req.json()\n const user = await cms.users.update(userId, body)\n return jsonResponse({ data: user })\n }\n\n // DELETE /users/:id - delete user\n if (method === 'DELETE' && userId) {\n await cms.users.delete(userId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleAdminAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n\n // All admin operations require admin role\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n // GET /admin/counts - get counts for dashboard\n if (method === 'GET' && path === '/admin/counts') {\n const [users, posts, tags, topics] = await Promise.all([\n cms.users.count(),\n cms.posts.findAll().then(p => p.length),\n cms.tags.findAll().then(t => t.length),\n cms.topics.findAll().then(t => t.length),\n ])\n return jsonResponse({ \n data: { users, posts, tags, topics } \n })\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { jsonResponse, requireAuth, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleSettingsAPI(\n req: NextRequest,\n cms: AutobloggerServer,\n session: Session | null,\n path: string\n): Promise<Response> {\n const method = req.method\n const prisma = cms.config.prisma as any\n\n // Check auth\n const authError = requireAuth(session)\n if (authError) return authError\n\n // GET /settings - get general settings\n if (method === 'GET' && path === '/settings') {\n // Get autoDraftEnabled from IntegrationSettings\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n })\n \n return jsonResponse({ \n data: { \n autoDraftEnabled: integrationSettings?.autoDraftEnabled ?? false,\n postUrlPattern: integrationSettings?.postUrlPattern ?? '/e/{slug}',\n } \n })\n }\n\n // PATCH /settings - update general settings\n if (method === 'PATCH' && path === '/settings') {\n // Check admin\n const adminError = requireAdmin(cms, session)\n if (adminError) return adminError\n\n const body = await req.json()\n \n // Build update object\n const updateData: { autoDraftEnabled?: boolean; postUrlPattern?: string } = {}\n if (typeof body.autoDraftEnabled === 'boolean') {\n updateData.autoDraftEnabled = body.autoDraftEnabled\n }\n if (typeof body.postUrlPattern === 'string') {\n updateData.postUrlPattern = body.postUrlPattern\n }\n \n // Upsert IntegrationSettings\n if (Object.keys(updateData).length > 0) {\n await prisma.integrationSettings.upsert({\n where: { id: 'default' },\n create: { id: 'default', ...updateData },\n update: updateData,\n })\n }\n\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n })\n\n return jsonResponse({ \n data: { \n autoDraftEnabled: integrationSettings?.autoDraftEnabled ?? false,\n postUrlPattern: integrationSettings?.postUrlPattern ?? '/e/{slug}',\n } \n })\n }\n\n return jsonResponse({ error: 'Not found' }, 404)\n}\n","import type { AutobloggerServer as Autoblogger, Session } from '../server'\nimport { jsonResponse, parsePath, requireAdmin } from './utils'\n\ntype NextRequest = Request & { nextUrl: URL }\n\nexport async function handleRevisionsAPI(\n req: NextRequest,\n cms: Autoblogger,\n session: Session | null,\n path: string,\n onMutate?: (type: string, data: unknown) => Promise<void>\n): Promise<Response> {\n const method = req.method\n const url = new URL(req.url)\n const { id: revisionId, subPath } = parsePath(path)\n\n // GET /revisions - list all revisions (paginated)\n if (method === 'GET' && !revisionId) {\n const page = parseInt(url.searchParams.get('page') || '1')\n const limit = parseInt(url.searchParams.get('limit') || '25')\n const postId = url.searchParams.get('postId')\n\n const where = postId ? { postId } : {}\n \n const [revisions, total] = await Promise.all([\n cms.revisions.findAll({ ...where, skip: (page - 1) * limit, take: limit }),\n cms.revisions.count(where),\n ])\n\n return jsonResponse({\n data: revisions,\n total,\n page,\n totalPages: Math.ceil(total / limit),\n })\n }\n\n // GET /revisions/:id - get single revision\n if (method === 'GET' && revisionId) {\n const revision = await cms.revisions.findById(revisionId)\n if (!revision) return jsonResponse({ error: 'Revision not found' }, 404)\n return jsonResponse({ data: revision })\n }\n\n // POST /revisions/:id/restore - restore a revision\n if (method === 'POST' && revisionId && subPath === 'restore') {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n const post = await cms.revisions.restore(revisionId)\n if (onMutate) await onMutate('post', post)\n return jsonResponse({ data: post })\n }\n\n // DELETE /revisions/:id - delete a revision\n if (method === 'DELETE' && revisionId) {\n const authError = requireAdmin(cms, session)\n if (authError) return authError\n\n await cms.revisions.delete(revisionId)\n return jsonResponse({ data: { success: true } })\n }\n\n return jsonResponse({ error: 'Method not allowed' }, 405)\n}\n","import type { PrismaClient } from '@prisma/client'\n\ninterface ChatHistoryRequest {\n role: 'user' | 'assistant'\n content: string\n}\n\n/**\n * Handle chat history API requests.\n * GET - Fetch recent messages\n * POST - Save a new message\n * DELETE - Clear all messages\n */\nexport async function handleChatHistoryAPI(\n req: Request,\n prisma: PrismaClient,\n isAuthenticated: boolean\n): Promise<Response> {\n // Require authentication\n if (!isAuthenticated) {\n return new Response(JSON.stringify({ error: 'Unauthorized' }), {\n status: 401,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const method = req.method\n\n // Check if ChatMessage model exists\n const hasChatMessage = !!(prisma as any).chatMessage\n\n try {\n // GET - Fetch recent messages\n if (method === 'GET') {\n if (!hasChatMessage) {\n return new Response(JSON.stringify([]), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n \n const messages = await (prisma as any).chatMessage.findMany({\n orderBy: { createdAt: 'desc' },\n take: 50,\n })\n \n // Return in chronological order\n return new Response(JSON.stringify(messages.reverse()), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n // POST - Save a new message\n if (method === 'POST') {\n if (!hasChatMessage) {\n // Silently succeed - chat still works, just not persisted\n return new Response(JSON.stringify({ id: 'temp', role: 'user', content: '' }), {\n status: 201,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const body: ChatHistoryRequest = await req.json()\n \n if (!body.role || !body.content) {\n return new Response(JSON.stringify({ error: 'Missing role or content' }), {\n status: 400,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n const message = await (prisma as any).chatMessage.create({\n data: {\n role: body.role,\n content: body.content,\n },\n })\n\n return new Response(JSON.stringify(message), {\n status: 201,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n // DELETE - Clear all messages\n if (method === 'DELETE') {\n if (!hasChatMessage) {\n return new Response(JSON.stringify({ success: true }), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n await (prisma as any).chatMessage.deleteMany({})\n \n return new Response(JSON.stringify({ success: true }), {\n status: 200,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n return new Response(JSON.stringify({ error: 'Method not allowed' }), {\n status: 405,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n console.error('[Chat History API Error]', error)\n return new Response(JSON.stringify({ error: 'Internal server error' }), {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n","import type { AutobloggerServer, Session } from '../server'\nimport { handlePostsAPI } from './posts'\nimport { handleCommentsAPI } from './comments'\nimport { handleTagsAPI } from './tags'\nimport { handleAIAPI } from './ai'\nimport { handleUploadAPI } from './upload'\nimport { handleTopicsAPI } from './topics'\nimport { handleUsersAPI } from './users'\nimport { handleAdminAPI } from './admin'\nimport { handleSettingsAPI } from './settings'\nimport { handleRevisionsAPI } from './revisions'\nimport { handleChatHistoryAPI } from './chat-history'\n\ninterface APIHandlerOptions {\n basePath?: string\n onMutate?: (type: string, data: unknown) => Promise<void>\n}\n\ntype NextRequest = Request & { nextUrl: URL }\n\nfunction extractPath(pathname: string, basePath: string): string {\n const normalized = pathname.replace(/\\/$/, '')\n const base = basePath.replace(/\\/$/, '')\n \n if (normalized === base) return '/'\n if (normalized.startsWith(base + '/')) {\n return normalized.slice(base.length)\n }\n return '/'\n}\n\nfunction jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\nexport function createAPIHandler(cms: AutobloggerServer, options: APIHandlerOptions = {}) {\n const basePath = options.basePath || '/api/cms'\n \n return async (req: NextRequest): Promise<Response> => {\n const path = extractPath(req.nextUrl.pathname, basePath)\n const method = req.method\n \n // Get session for auth\n let session: Session | null = null\n try {\n session = await cms.config.auth.getSession()\n } catch {\n // Session retrieval failed\n }\n \n // Check auth for protected routes\n const isPublicRoute = path.startsWith('/posts') && method === 'GET'\n if (!isPublicRoute && !session) {\n return jsonResponse({ error: 'Unauthorized' }, 401)\n }\n \n try {\n // Route to handlers\n if (path.startsWith('/posts')) {\n return handlePostsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/comments')) {\n return handleCommentsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/tags')) {\n return handleTagsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/ai')) {\n return handleAIAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/upload')) {\n return handleUploadAPI(req, cms, session)\n }\n \n if (path.startsWith('/topics')) {\n return handleTopicsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/users')) {\n return handleUsersAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/admin')) {\n return handleAdminAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/settings')) {\n return handleSettingsAPI(req, cms, session, path)\n }\n \n if (path.startsWith('/revisions')) {\n return handleRevisionsAPI(req, cms, session, path, options.onMutate)\n }\n \n if (path.startsWith('/chat/history')) {\n return handleChatHistoryAPI(req, cms.config.prisma, !!session)\n }\n \n return jsonResponse({ error: 'Not found' }, 404)\n } catch (error) {\n console.error('API error:', error)\n return jsonResponse({ \n error: error instanceof Error ? error.message : 'Internal server error' \n }, 500)\n }\n }\n}\n\nexport { handlePostsAPI } from './posts'\nexport { handleCommentsAPI } from './comments'\nexport { handleTagsAPI } from './tags'\nexport { handleAIAPI } from './ai'\nexport { handleUploadAPI } from './upload'\nexport { handleTopicsAPI } from './topics'\nexport { handleUsersAPI } from './users'\nexport { handleAdminAPI } from './admin'\nexport { handleSettingsAPI } from './settings'\nexport { handleRevisionsAPI } from './revisions'\nexport { handleChatHistoryAPI } from './chat-history'\n","import Parser from 'rss-parser'\n\nexport interface RssArticle {\n title: string\n url: string\n summary: string | null\n publishedAt: Date | null\n}\n\nconst parser = new Parser({\n timeout: 10000,\n headers: {\n 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n },\n})\n\n/**\n * Fetch and parse multiple RSS feeds, combining all articles.\n */\nexport async function fetchRssFeeds(feedUrls: string[]): Promise<RssArticle[]> {\n const articles: RssArticle[] = []\n\n for (const url of feedUrls) {\n try {\n const feed = await parser.parseURL(url)\n \n for (const item of feed.items) {\n if (!item.title || !item.link) continue\n \n articles.push({\n title: item.title,\n url: item.link,\n summary: item.contentSnippet || item.content || null,\n publishedAt: item.pubDate ? new Date(item.pubDate) : null,\n })\n }\n } catch (error) {\n console.error(`Failed to fetch RSS feed: ${url}`, error)\n // Continue with other feeds\n }\n }\n\n return articles\n}\n","import type { RssArticle } from './rss'\n\n/**\n * Filter articles by keyword matching.\n * Case-insensitive substring match on title and summary.\n */\nexport function filterByKeywords(\n articles: RssArticle[],\n keywords: string[]\n): RssArticle[] {\n if (keywords.length === 0) return articles\n\n const lowerKeywords = keywords.map(k => k.toLowerCase().trim())\n\n return articles.filter(article => {\n const searchText = `${article.title} ${article.summary || ''}`.toLowerCase()\n return lowerKeywords.some(keyword => searchText.includes(keyword))\n })\n}\n","// Models\nexport { \n AI_MODELS, \n getModel, \n getDefaultModel,\n modelHasNativeSearch,\n getSearchModel,\n resolveModel,\n getModelOptions,\n toModelOption,\n LENGTH_OPTIONS,\n} from './models'\nexport type { AIModel, AIModelOption, ModelId, LengthOption } from './models'\n\n// Provider\nexport { createStream, generate, getApiKey } from './provider'\nexport type { ChatMessage } from './provider'\n\n// Generate\nexport { generateStream, expandPlanStream } from './generate'\n\n// Chat\nexport { chatStream } from './chat'\n\n// Builders\nexport { \n buildGeneratePrompt, \n buildChatPrompt, \n buildExpandPlanPrompt, \n buildPlanPrompt, \n buildRewritePrompt, \n buildAutoDraftPrompt \n} from './builders'\n\n// Prompts\nexport {\n DEFAULT_GENERATE_TEMPLATE,\n DEFAULT_CHAT_TEMPLATE,\n DEFAULT_REWRITE_TEMPLATE,\n DEFAULT_AUTO_DRAFT_TEMPLATE,\n DEFAULT_PLAN_TEMPLATE,\n DEFAULT_PLAN_RULES,\n DEFAULT_EXPAND_PLAN_TEMPLATE,\n DEFAULT_AGENT_TEMPLATE,\n DEFAULT_SEARCH_ONLY_PROMPT,\n buildSearchOnlyPrompt,\n buildPlanPrompt as buildPlanPromptFromPrompts,\n buildChatPrompt as buildChatPromptFromPrompts,\n buildAgentChatPrompt,\n buildGeneratePrompt as buildGeneratePromptFromPrompts,\n buildRewritePrompt as buildRewritePromptFromPrompts,\n buildExpandPlanPrompt as buildExpandPlanPromptFromPrompts,\n} from './prompts'\nexport type { EssayContext, StyleContext } from './prompts'// Parse\nexport { parseGeneratedContent } from './parse'\n","/**\n * Parse AI-generated markdown to extract title, subtitle, and body.\n * \n * Expects format:\n * # Title\n * *Subtitle*\n * \n * Body content...\n */\nexport function parseGeneratedContent(markdown: string): {\n title: string\n subtitle: string\n body: string\n} {\n const lines = markdown.trim().split('\\n')\n let title = ''\n let subtitle = ''\n let bodyStartIndex = 0\n\n // Look for H1 title at the start\n if (lines[0]?.startsWith('# ')) {\n title = lines[0].replace(/^#\\s+/, '').trim()\n bodyStartIndex = 1\n }\n\n // Look for italic subtitle (next non-empty line starting with * and ending with *)\n for (let i = bodyStartIndex; i < lines.length; i++) {\n const line = lines[i].trim()\n if (line === '') continue // skip empty lines\n\n // Check for italic subtitle: *text* or _text_\n const italicMatch = line.match(/^\\*(.+)\\*$/) || line.match(/^_(.+)_$/)\n if (italicMatch) {\n subtitle = italicMatch[1].trim()\n bodyStartIndex = i + 1\n }\n break // stop after first non-empty line (whether it's subtitle or not)\n }\n\n // Skip any leading empty lines after title/subtitle\n while (bodyStartIndex < lines.length && lines[bodyStartIndex].trim() === '') {\n bodyStartIndex++\n }\n\n const body = lines.slice(bodyStartIndex).join('\\n').trim()\n\n return { title, subtitle, body }\n}\n","import { marked } from 'marked'\nimport TurndownService from 'turndown'\n\n// Configure marked for consistent rendering\nmarked.setOptions({\n gfm: true,\n breaks: false,\n})\n\n/**\n * Render markdown to HTML\n */\nexport function renderMarkdown(markdown: string): string {\n return marked.parse(markdown) as string\n}\n\n/**\n * Convert markdown to HTML with GFM and line breaks enabled.\n * Safe for client-side use in components like ChatPanel.\n */\nexport function markdownToHtml(markdown: string): string {\n return marked.parse(markdown, { gfm: true, breaks: true }) as string\n}\n\n/**\n * Parse markdown to tokens (AST)\n */\nexport function parseMarkdown(markdown: string) {\n return marked.lexer(markdown)\n}\n\n// Configure Turndown for HTML to markdown conversion\nconst turndownService = new TurndownService({\n headingStyle: 'atx',\n codeBlockStyle: 'fenced',\n bulletListMarker: '-',\n})\n\n/**\n * Convert HTML to markdown\n */\nexport function htmlToMarkdown(html: string): string {\n return turndownService.turndown(html)\n}\n\n/**\n * Count words in text (markdown or plain text)\n */\nexport function wordCount(text: string): number {\n if (!text) return 0\n return text.trim().split(/\\s+/).filter(Boolean).length\n}\n\n/**\n * Generate URL-safe slug from title\n */\nexport function generateSlug(title: string): string {\n return title\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/\\s+/g, '-')\n .replace(/-+/g, '-')\n .substring(0, 60)\n}\n\nimport sanitizeHtml from 'sanitize-html'\n\n/**\n * Render markdown to sanitized HTML.\n * Safe for public-facing pages where user content is displayed.\n */\nexport function renderMarkdownSanitized(markdown: string): string {\n const html = renderMarkdown(markdown)\n return sanitizeHtml(html, {\n allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']),\n allowedAttributes: {\n ...sanitizeHtml.defaults.allowedAttributes,\n img: ['src', 'alt', 'title'],\n a: ['href', 'target', 'rel'],\n },\n })\n}\n","import { generate, resolveModel, buildAutoDraftPrompt, parseGeneratedContent } from '../ai'\nimport { generateSlug } from '../lib/markdown'\nimport { fetchRssFeeds, type RssArticle } from './rss'\nimport { filterByKeywords } from './keywords'\n\nexport interface GenerationResult {\n topicId: string\n topicName: string\n generated: number\n skipped: number\n}\n\nexport interface AutoDraftConfig {\n prisma: any\n anthropicKey?: string\n openaiKey?: string\n /** Called after generating an essay, before creating the post. Return additional post fields. */\n onPostCreate?: (article: RssArticle, essay: { title: string; subtitle: string | null; markdown: string }) => Record<string, unknown> | Promise<Record<string, unknown>>\n}\n\n/**\n * Get style context from the database for AI generation.\n */\nasync function getStyleContext(prisma: any) {\n const settings = await prisma.aISettings.findUnique({ where: { id: 'default' } })\n const posts = await prisma.post.findMany({\n where: { status: 'published' },\n select: { title: true, subtitle: true, markdown: true },\n orderBy: { publishedAt: 'desc' },\n take: 10,\n })\n \n const styleExamples = posts\n .map((p: { title: string; subtitle?: string; markdown: string }) => \n `# ${p.title}\\n${p.subtitle ? `*${p.subtitle}*\\n\\n` : ''}${p.markdown}`\n )\n .join('\\n\\n---\\n\\n')\n \n return {\n rules: settings?.rules || '',\n autoDraftRules: settings?.autoDraftRules || '',\n styleExamples,\n }\n}\n\n/**\n * Check if a topic should run based on its frequency and lastRunAt.\n */\nfunction shouldRunTopic(topic: { frequency: string; lastRunAt: Date | null }): boolean {\n if (topic.frequency === 'manual') return false\n if (!topic.lastRunAt) return true\n\n const now = new Date()\n const lastRun = new Date(topic.lastRunAt)\n const hoursSinceLastRun = (now.getTime() - lastRun.getTime()) / (1000 * 60 * 60)\n\n if (topic.frequency === 'daily') return hoursSinceLastRun >= 23\n if (topic.frequency === 'weekly') return hoursSinceLastRun >= 167 // ~7 days\n \n return true\n}\n\n/**\n * Deduplicate articles against existing NewsItems (global, across all topics).\n */\nasync function deduplicateArticles(\n prisma: any,\n articles: RssArticle[]\n): Promise<RssArticle[]> {\n const articleUrls = articles.map(a => a.url)\n const existingUrls = await prisma.newsItem.findMany({\n where: { url: { in: articleUrls } },\n select: { url: true },\n })\n \n const urlSet = new Set(existingUrls.map((n: { url: string }) => n.url))\n return articles.filter(a => !urlSet.has(a.url))\n}\n\n/**\n * Generate a unique slug for a post.\n * If the slug already exists, appends -2, -3, etc.\n */\nasync function generateUniqueSlug(prisma: any, title: string): Promise<string> {\n const baseSlug = generateSlug(title)\n \n // Check if base slug is available\n const existing = await prisma.post.findUnique({ where: { slug: baseSlug } })\n if (!existing) return baseSlug\n\n // Find next available suffix\n let suffix = 2\n while (suffix < 100) {\n const candidateSlug = `${baseSlug}-${suffix}`\n const exists = await prisma.post.findUnique({ where: { slug: candidateSlug } })\n if (!exists) return candidateSlug\n suffix++\n }\n\n // Fallback: add random suffix\n return `${baseSlug}-${Date.now()}`\n}\n\n/**\n * Generate an essay from an article using AI.\n */\nasync function generateEssayFromArticle(\n config: AutoDraftConfig,\n article: RssArticle,\n topicName: string,\n essayFocus?: string | null\n): Promise<{ title: string; subtitle: string | null; markdown: string }> {\n const context = await getStyleContext(config.prisma)\n \n const systemPrompt = buildAutoDraftPrompt({\n autoDraftRules: context.autoDraftRules,\n rules: context.rules,\n wordCount: 800,\n styleExamples: context.styleExamples,\n topicName: topicName,\n articleTitle: article.title,\n articleSummary: article.summary || '',\n articleUrl: article.url,\n })\n \n // Resolve the default model\n const model = await resolveModel(undefined, async () => {\n const settings = await config.prisma.aISettings.findUnique({ where: { id: 'default' } })\n return settings?.defaultModel || null\n })\n\n // User prompt is minimal since all instructions are in the system prompt\n const userPrompt = essayFocus \n ? `Write the essay now. Focus on: ${essayFocus}`\n : 'Write the essay now.'\n \n const result = await generate(model.id, systemPrompt, userPrompt, {\n maxTokens: 4096,\n anthropicKey: config.anthropicKey,\n openaiKey: config.openaiKey,\n })\n const parsed = parseGeneratedContent(result.text)\n\n return {\n title: parsed.title || article.title,\n subtitle: parsed.subtitle || null,\n markdown: parsed.body,\n }\n}\n\n/**\n * Run auto-draft for one or all active topics.\n * @param config - Configuration including prisma client and API keys\n * @param topicId - Optional: run for a specific topic only\n * @param skipFrequencyCheck - If true, ignore frequency settings (for manual trigger)\n */\nexport async function runAutoDraft(\n config: AutoDraftConfig,\n topicId?: string,\n skipFrequencyCheck = false\n): Promise<GenerationResult[]> {\n const { prisma } = config\n\n // Check master toggle first\n const integrationSettings = await prisma.integrationSettings.findUnique({\n where: { id: 'default' },\n }) as { autoDraftEnabled?: boolean } | null\n if (!integrationSettings?.autoDraftEnabled) {\n console.log('Auto-draft is disabled. Skipping.')\n return []\n }\n\n const topics = topicId\n ? await prisma.topicSubscription.findMany({ where: { id: topicId, isActive: true } })\n : await prisma.topicSubscription.findMany({ where: { isActive: true } })\n\n const results: GenerationResult[] = []\n\n for (const topic of topics) {\n // Skip if frequency check applies and topic shouldn't run\n if (!skipFrequencyCheck && !shouldRunTopic(topic)) {\n continue\n }\n\n try {\n // 1. Fetch RSS feeds\n const feedUrls: string[] = JSON.parse(topic.rssFeeds)\n const articles = await fetchRssFeeds(feedUrls)\n\n // 2. Filter by keywords (if enabled)\n const keywords: string[] = JSON.parse(topic.keywords)\n const relevant = topic.useKeywordFilter\n ? filterByKeywords(articles, keywords)\n : articles\n\n // 3. Deduplicate (skip URLs already processed globally)\n const newArticles = await deduplicateArticles(prisma, relevant)\n\n // 4. Generate essays (up to maxPerPeriod)\n const toGenerate = newArticles.slice(0, topic.maxPerPeriod)\n let generated = 0\n\n for (const article of toGenerate) {\n try {\n // Create NewsItem first\n const newsItem = await prisma.newsItem.create({\n data: {\n topicId: topic.id,\n url: article.url,\n title: article.title,\n summary: article.summary,\n publishedAt: article.publishedAt,\n status: 'pending',\n },\n })\n\n // Generate essay with AI\n const essay = await generateEssayFromArticle(config, article, topic.name, topic.essayFocus)\n\n // Generate unique slug\n const slug = await generateUniqueSlug(prisma, essay.title)\n\n // Get additional fields from hook (e.g., polyhedraShape)\n const extraFields = config.onPostCreate \n ? await config.onPostCreate(article, essay)\n : {}\n\n // Create suggested post\n const post = await prisma.post.create({\n data: {\n title: essay.title,\n subtitle: essay.subtitle,\n slug,\n markdown: essay.markdown,\n status: 'suggested',\n sourceUrl: article.url,\n topicId: topic.id,\n ...extraFields,\n },\n })\n\n // Link NewsItem to Post\n await prisma.newsItem.update({\n where: { id: newsItem.id },\n data: { postId: post.id, status: 'generated' },\n })\n\n generated++\n } catch (articleError) {\n console.error(`Failed to process article: ${article.title}`, articleError)\n // Continue with other articles\n }\n }\n\n // 5. Update lastRunAt\n await prisma.topicSubscription.update({\n where: { id: topic.id },\n data: { lastRunAt: new Date() },\n })\n\n results.push({\n topicId: topic.id,\n topicName: topic.name,\n generated,\n skipped: relevant.length - generated,\n })\n } catch (topicError) {\n console.error(`Failed to process topic: ${topic.name}`, topicError)\n results.push({\n topicId: topic.id,\n topicName: topic.name,\n generated: 0,\n skipped: 0,\n })\n }\n }\n\n return results\n}\n","import type { ComponentType } from 'react'\nimport type { Post } from './models'\nimport type { Session } from './session'\nimport type { RssArticle } from '../auto-draft'\n\n// Style configuration for article rendering\nexport interface StylesConfig {\n container?: string\n title?: string\n subtitle?: string\n byline?: string\n prose?: string\n}\n\n// Default styles\nexport const DEFAULT_STYLES: Required<StylesConfig> = {\n container: 'max-w-ab-content mx-auto px-ab-content-padding',\n title: 'text-ab-title font-bold',\n subtitle: 'text-ab-h2 text-muted-foreground',\n byline: 'text-sm text-muted-foreground',\n prose: 'prose',\n}\n\n// Custom field component props (UI-only)\nexport interface CustomFieldProps<T = unknown> {\n value: T\n onChange: (value: T) => void\n onFieldChange: (name: string, value: unknown) => void // Update any post field\n post: Post\n disabled?: boolean\n}\n\n// Custom field definition (UI-only)\nexport interface CustomFieldConfig {\n name: string\n label?: string\n component: ComponentType<CustomFieldProps<unknown>>\n position?: 'footer' | 'sidebar'\n}\n\n// Server-safe configuration (no React types)\nexport interface AutobloggerServerConfig {\n prisma: unknown\n\n auth: {\n getSession: () => Promise<Session | null>\n isAdmin: (session: Session | null) => boolean\n canPublish: (session: Session | null) => boolean\n }\n\n ai?: {\n anthropicKey?: string\n openaiKey?: string\n }\n\n storage?: {\n upload: (file: File) => Promise<{ url: string }>\n }\n\n comments?: {\n mode: 'authenticated' | 'public' | 'disabled'\n }\n\n styles?: StylesConfig\n\n hooks?: {\n beforePublish?: (post: Post) => Promise<void>\n afterSave?: (post: Post) => Promise<void>\n /** Called during auto-draft after generating essay, return extra fields for post creation */\n onAutoDraftPostCreate?: (article: RssArticle, essay: { title: string; subtitle: string | null; markdown: string }) => Record<string, unknown> | Promise<Record<string, unknown>>\n }\n}\n\n// Full configuration with custom fields (includes React types)\nexport interface AutobloggerConfig extends AutobloggerServerConfig {\n fields?: CustomFieldConfig[]\n}\n","// Server-safe exports - no React imports\nimport { createPostsData } from './data/posts'\nimport { createCommentsData } from './data/comments'\nimport { createTagsData } from './data/tags'\nimport { createRevisionsData } from './data/revisions'\nimport { createAISettingsData } from './data/ai-settings'\nimport { createTopicsData } from './data/topics'\nimport { createNewsItemsData } from './data/news-items'\nimport { createUsersData } from './data/users'\nimport { createAPIHandler } from './api'\nimport { runAutoDraft as runAutoDraftInternal, type AutoDraftConfig } from './auto-draft'\nimport type { AutobloggerServerConfig, StylesConfig } from './types/config'\nimport { DEFAULT_STYLES } from './types/config'\n\n// Re-export types for backward compatibility\nexport type { Session } from './types/session'\nexport type { StylesConfig, AutobloggerServerConfig } from './types/config'\n\n// Autoblogger server instance type\nexport interface AutobloggerServer {\n config: AutobloggerServerConfig & { styles: Required<StylesConfig> }\n posts: ReturnType<typeof createPostsData>\n comments: ReturnType<typeof createCommentsData>\n tags: ReturnType<typeof createTagsData>\n revisions: ReturnType<typeof createRevisionsData>\n aiSettings: ReturnType<typeof createAISettingsData>\n topics: ReturnType<typeof createTopicsData>\n newsItems: ReturnType<typeof createNewsItemsData>\n users: ReturnType<typeof createUsersData>\n /** Handle an API request - convenience method for route handlers */\n handleRequest: (req: Request, path: string) => Promise<Response>\n /** Auto-draft runner */\n autoDraft: {\n run: (topicId?: string, skipFrequencyCheck?: boolean) => Promise<import('./auto-draft').GenerationResult[]>\n }\n}\n\n// Create autoblogger server instance\nexport function createAutoblogger(config: AutobloggerServerConfig): AutobloggerServer {\n const prisma = config.prisma as any\n \n const mergedStyles: Required<StylesConfig> = {\n ...DEFAULT_STYLES,\n ...config.styles,\n }\n\n // Create the base server object first (without handleRequest)\n const baseServer = {\n config: {\n ...config,\n styles: mergedStyles,\n },\n posts: createPostsData(prisma, config.hooks),\n comments: createCommentsData(prisma, config.comments),\n tags: createTagsData(prisma),\n revisions: createRevisionsData(prisma),\n aiSettings: createAISettingsData(prisma),\n topics: createTopicsData(prisma),\n newsItems: createNewsItemsData(prisma),\n users: createUsersData(prisma),\n }\n\n // Create the full server with handleRequest and autoDraft\n const server: AutobloggerServer = {\n ...baseServer,\n handleRequest: async () => new Response('Not initialized', { status: 500 }),\n autoDraft: {\n run: async (topicId?: string, skipFrequencyCheck?: boolean) => {\n const autoDraftConfig: AutoDraftConfig = {\n prisma,\n anthropicKey: config.ai?.anthropicKey,\n openaiKey: config.ai?.openaiKey,\n onPostCreate: config.hooks?.onAutoDraftPostCreate,\n }\n return runAutoDraftInternal(autoDraftConfig, topicId, skipFrequencyCheck)\n },\n },\n }\n\n // Create the API handler with the server\n const apiHandler = createAPIHandler(server)\n\n // Now set the real handleRequest implementation\n server.handleRequest = async (req: Request, path: string): Promise<Response> => {\n // Normalize path to start with /\n const normalizedPath = '/' + path.replace(/^\\//, '')\n \n // Build the full URL the handler expects\n const originalUrl = new URL(req.url)\n const newUrl = new URL(originalUrl.origin + '/api/cms' + normalizedPath)\n \n // Copy search params\n originalUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value)\n })\n \n // Create a new request with nextUrl property (required by the handler)\n const handlerReq = new Request(newUrl.toString(), {\n method: req.method,\n headers: req.headers,\n body: req.method !== 'GET' && req.method !== 'HEAD' ? req.body : undefined,\n // @ts-ignore - duplex is needed for streaming bodies\n duplex: req.method !== 'GET' && req.method !== 'HEAD' ? 'half' : undefined,\n }) as Request & { nextUrl: URL }\n \n // Add nextUrl property\n Object.defineProperty(handlerReq, 'nextUrl', {\n value: newUrl,\n writable: false,\n })\n \n return apiHandler(handlerReq)\n }\n\n return server\n}\n","// Schema validation helper\n\nconst REQUIRED_TABLES = [\n 'Post',\n 'Revision',\n 'Comment',\n 'Tag',\n 'PostTag',\n 'AISettings',\n 'TopicSubscription',\n 'NewsItem',\n]\n\nexport interface SchemaValidationResult {\n valid: boolean\n missingTables: string[]\n}\n\nexport async function validateSchema(prisma: unknown): Promise<SchemaValidationResult> {\n const p = prisma as any\n const missingTables: string[] = []\n\n for (const table of REQUIRED_TABLES) {\n const modelName = table.charAt(0).toLowerCase() + table.slice(1)\n try {\n // Try to access the model - if it doesn't exist, it will throw\n if (!p[modelName]) {\n missingTables.push(table)\n } else {\n // Try a simple query to verify the table exists\n await p[modelName].findFirst({ take: 1 }).catch(() => {\n missingTables.push(table)\n })\n }\n } catch {\n missingTables.push(table)\n }\n }\n\n return {\n valid: missingTables.length === 0,\n missingTables,\n }\n}\n","const MINUTE = 60_000, HOUR = 3_600_000, DAY = 86_400_000\n\n/**\n * Format a date as relative time (e.g., \"5m ago\", \"2h ago\", \"Yesterday\")\n */\nexport function formatRelativeTime(isoDate: string): string {\n const date = new Date(isoDate)\n const diffMs = Date.now() - date.getTime()\n const mins = Math.floor(diffMs / MINUTE)\n const hours = Math.floor(diffMs / HOUR)\n const days = Math.floor(diffMs / DAY)\n \n if (mins < 1) return 'Just now'\n if (mins < 60) return `${mins}m ago`\n if (hours < 24) return `${hours}h ago`\n if (days === 1) return 'Yesterday'\n if (days < 7) return `${days}d ago`\n return date.toLocaleDateString()\n}\n\n/**\n * Format a date for display\n */\nexport function formatDate(date: Date | string, options?: Intl.DateTimeFormatOptions): string {\n const d = typeof date === 'string' ? new Date(date) : date\n \n const defaultOptions: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n }\n \n return d.toLocaleDateString('en-US', options || defaultOptions)\n}\n\n/**\n * Format saved time for display (e.g., \"just now\", \"5m ago\", \"2:30 PM\")\n */\nexport function formatSavedTime(date: Date): string {\n const now = new Date()\n const diffMs = now.getTime() - date.getTime()\n const diffSecs = Math.floor(diffMs / 1000)\n const diffMins = Math.floor(diffMs / MINUTE)\n \n // Show relative time for recent saves\n if (diffSecs < 10) return 'just now'\n if (diffSecs < 60) return `${diffSecs}s ago`\n if (diffMins < 60) return `${diffMins}m ago`\n \n // Show clock time for today\n const isToday = date.toDateString() === now.toDateString()\n if (isToday) {\n return date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })\n }\n \n return date.toLocaleDateString('en-US', { \n month: 'short', \n day: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n })\n}\n\n/**\n * Count words in text\n */\nexport function countWords(text?: string | null): number {\n if (!text) return 0\n return text.split(/\\s+/).filter(Boolean).length\n}\n\n/**\n * Truncate text to a maximum length\n */\nexport function truncate(text: string, maxLength: number): string {\n // Strip markdown formatting for description\n const stripped = text\n .replace(/#+\\s/g, '')\n .replace(/\\*\\*/g, '')\n .replace(/\\*/g, '')\n .replace(/`/g, '')\n .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1')\n .replace(/\\n+/g, ' ')\n .trim()\n \n if (stripped.length <= maxLength) return stripped\n \n return stripped.slice(0, maxLength - 3).trim() + '...'\n}\n","import type { Post } from '../types'\nimport { truncate } from './format'\n\nexport interface SeoValues {\n title: string\n description: string\n keywords?: string | null\n noIndex: boolean\n ogImage?: string | null\n}\n\n/**\n * Get SEO values from a post with fallbacks\n */\nexport function getSeoValues(post: Post): SeoValues {\n return {\n title: post.seoTitle || post.title,\n description: post.seoDescription || post.subtitle || truncate(post.markdown, 160),\n keywords: post.seoKeywords,\n noIndex: post.noIndex,\n ogImage: post.ogImage,\n }\n}\n","/**\n * Comment types and client-side API helpers for the editor commenting system.\n * Used for collaborative inline comments on posts.\n */\n\n// Types matching Prisma schema + includes\nexport interface CommentUser {\n id: string\n name: string | null\n email: string\n}\n\nexport interface CommentWithUser {\n id: string\n postId: string\n userId: string\n quotedText: string\n content: string\n parentId: string | null\n resolved: boolean\n createdAt: string\n updatedAt: string\n user: CommentUser\n replies?: CommentWithUser[]\n}\n\nexport interface CreateCommentData {\n quotedText: string\n content: string\n parentId?: string\n}\n\nexport interface SelectionState {\n text: string\n from: number\n to: number\n hasExistingComment?: boolean\n}\n\n// Permission helpers (compare by email since that's what we have in session)\nexport function canDeleteComment(\n comment: CommentWithUser,\n currentUserEmail: string,\n isAdmin: boolean\n): boolean {\n return comment.user.email === currentUserEmail || isAdmin\n}\n\nexport function canEditComment(\n comment: CommentWithUser,\n currentUserEmail: string\n): boolean {\n return comment.user.email === currentUserEmail\n}\n\n// API client factory - creates functions bound to a specific API base path\nexport function createCommentsClient(apiBasePath: string = '/api/cms') {\n return {\n async fetchComments(postId: string): Promise<CommentWithUser[]> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments`)\n if (!res.ok) throw new Error('Failed to fetch comments')\n const json = await res.json()\n return json.data || json\n },\n\n async createComment(\n postId: string,\n data: CreateCommentData\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(data),\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to create comment')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async updateComment(\n postId: string,\n commentId: string,\n content: string\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}`, {\n method: 'PATCH',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ content }),\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to update comment')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async deleteComment(\n postId: string,\n commentId: string\n ): Promise<void> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}`, {\n method: 'DELETE',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to delete comment')\n }\n },\n\n async toggleResolve(\n postId: string,\n commentId: string\n ): Promise<CommentWithUser> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/${commentId}/resolve`, {\n method: 'POST',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to toggle resolve')\n }\n const json = await res.json()\n return json.data || json\n },\n\n async resolveAllComments(\n postId: string\n ): Promise<{ resolved: number }> {\n const res = await fetch(`${apiBasePath}/posts/${postId}/comments/resolve-all`, {\n method: 'POST',\n })\n if (!res.ok) {\n const error = await res.json()\n throw new Error(error.error || 'Failed to resolve all comments')\n }\n const json = await res.json()\n return json.data || json\n },\n }\n}\n","import type { EditorState, Transaction } from '@tiptap/pm/state'\n\n/**\n * Takes a Transaction & Editor State and turns it into a chainable state object\n * @param config The transaction and state to create the chainable state from\n * @returns A chainable Editor state object\n */\nexport function createChainableState(config: { transaction: Transaction; state: EditorState }): EditorState {\n const { state, transaction } = config\n let { selection } = transaction\n let { doc } = transaction\n let { storedMarks } = transaction\n\n return {\n ...state,\n apply: state.apply.bind(state),\n applyTransaction: state.applyTransaction.bind(state),\n plugins: state.plugins,\n schema: state.schema,\n reconfigure: state.reconfigure.bind(state),\n toJSON: state.toJSON.bind(state),\n get storedMarks() {\n return storedMarks\n },\n get selection() {\n return selection\n },\n get doc() {\n return doc\n },\n get tr() {\n selection = transaction.selection\n doc = transaction.doc\n storedMarks = transaction.storedMarks\n\n return transaction\n },\n }\n}\n","import type { EditorState, Transaction } from '@tiptap/pm/state'\n\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport type { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types.js'\n\nexport class CommandManager {\n editor: Editor\n\n rawCommands: AnyCommands\n\n customState?: EditorState\n\n constructor(props: { editor: Editor; state?: EditorState }) {\n this.editor = props.editor\n this.rawCommands = this.editor.extensionManager.commands\n this.customState = props.state\n }\n\n get hasCustomState(): boolean {\n return !!this.customState\n }\n\n get state(): EditorState {\n return this.customState || this.editor.state\n }\n\n get commands(): SingleCommands {\n const { rawCommands, editor, state } = this\n const { view } = editor\n const { tr } = state\n const props = this.buildProps(tr)\n\n return Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n const method = (...args: any[]) => {\n const callback = command(...args)(props)\n\n if (!tr.getMeta('preventDispatch') && !this.hasCustomState) {\n view.dispatch(tr)\n }\n\n return callback\n }\n\n return [name, method]\n }),\n ) as unknown as SingleCommands\n }\n\n get chain(): () => ChainedCommands {\n return () => this.createChain()\n }\n\n get can(): () => CanCommands {\n return () => this.createCan()\n }\n\n public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {\n const { rawCommands, editor, state } = this\n const { view } = editor\n const callbacks: boolean[] = []\n const hasStartTransaction = !!startTr\n const tr = startTr || state.tr\n\n const run = () => {\n if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch') && !this.hasCustomState) {\n view.dispatch(tr)\n }\n\n return callbacks.every(callback => callback === true)\n }\n\n const chain = {\n ...Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n const chainedCommand = (...args: never[]) => {\n const props = this.buildProps(tr, shouldDispatch)\n const callback = command(...args)(props)\n\n callbacks.push(callback)\n\n return chain\n }\n\n return [name, chainedCommand]\n }),\n ),\n run,\n } as unknown as ChainedCommands\n\n return chain\n }\n\n public createCan(startTr?: Transaction): CanCommands {\n const { rawCommands, state } = this\n const dispatch = false\n const tr = startTr || state.tr\n const props = this.buildProps(tr, dispatch)\n const formattedCommands = Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]\n }),\n ) as unknown as SingleCommands\n\n return {\n ...formattedCommands,\n chain: () => this.createChain(tr, dispatch),\n } as CanCommands\n }\n\n public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {\n const { rawCommands, editor, state } = this\n const { view } = editor\n\n const props: CommandProps = {\n tr,\n editor,\n view,\n state: createChainableState({\n state,\n transaction: tr,\n }),\n dispatch: shouldDispatch ? () => undefined : undefined,\n chain: () => this.createChain(tr, shouldDispatch),\n can: () => this.createCan(tr),\n get commands() {\n return Object.fromEntries(\n Object.entries(rawCommands).map(([name, command]) => {\n return [name, (...args: never[]) => command(...args)(props)]\n }),\n ) as unknown as SingleCommands\n },\n }\n\n return props\n }\n}\n","export * from './blur.js'\nexport * from './clearContent.js'\nexport * from './clearNodes.js'\nexport * from './command.js'\nexport * from './createParagraphNear.js'\nexport * from './cut.js'\nexport * from './deleteCurrentNode.js'\nexport * from './deleteNode.js'\nexport * from './deleteRange.js'\nexport * from './deleteSelection.js'\nexport * from './enter.js'\nexport * from './exitCode.js'\nexport * from './extendMarkRange.js'\nexport * from './first.js'\nexport * from './focus.js'\nexport * from './forEach.js'\nexport * from './insertContent.js'\nexport * from './insertContentAt.js'\nexport * from './join.js'\nexport * from './joinItemBackward.js'\nexport * from './joinItemForward.js'\nexport * from './joinTextblockBackward.js'\nexport * from './joinTextblockForward.js'\nexport * from './keyboardShortcut.js'\nexport * from './lift.js'\nexport * from './liftEmptyBlock.js'\nexport * from './liftListItem.js'\nexport * from './newlineInCode.js'\nexport * from './resetAttributes.js'\nexport * from './scrollIntoView.js'\nexport * from './selectAll.js'\nexport * from './selectNodeBackward.js'\nexport * from './selectNodeForward.js'\nexport * from './selectParentNode.js'\nexport * from './selectTextblockEnd.js'\nexport * from './selectTextblockStart.js'\nexport * from './setContent.js'\nexport * from './setMark.js'\nexport * from './setMeta.js'\nexport * from './setNode.js'\nexport * from './setNodeSelection.js'\nexport * from './setTextDirection.js'\nexport * from './setTextSelection.js'\nexport * from './sinkListItem.js'\nexport * from './splitBlock.js'\nexport * from './splitListItem.js'\nexport * from './toggleList.js'\nexport * from './toggleMark.js'\nexport * from './toggleNode.js'\nexport * from './toggleWrap.js'\nexport * from './undoInputRule.js'\nexport * from './unsetAllMarks.js'\nexport * from './unsetMark.js'\nexport * from './unsetTextDirection.js'\nexport * from './updateAttributes.js'\nexport * from './wrapIn.js'\nexport * from './wrapInList.js'\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n blur: {\n /**\n * Removes focus from the editor.\n * @example editor.commands.blur()\n */\n blur: () => ReturnType\n }\n }\n}\n\nexport const blur: RawCommands['blur'] =\n () =>\n ({ editor, view }) => {\n requestAnimationFrame(() => {\n if (!editor.isDestroyed) {\n ;(view.dom as HTMLElement).blur()\n\n // Browsers should remove the caret on blur but safari does not.\n // See: https://github.com/ueberdosis/tiptap/issues/2405\n window?.getSelection()?.removeAllRanges()\n }\n })\n\n return true\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n clearContent: {\n /**\n * Clear the whole document.\n * @example editor.commands.clearContent()\n */\n clearContent: (\n /**\n * Whether to emit an update event.\n * @default true\n */\n emitUpdate?: boolean,\n ) => ReturnType\n }\n }\n}\n\nexport const clearContent: RawCommands['clearContent'] =\n (emitUpdate = true) =>\n ({ commands }) => {\n return commands.setContent('', { emitUpdate })\n }\n","import { liftTarget } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n clearNodes: {\n /**\n * Normalize nodes to a simple paragraph.\n * @example editor.commands.clearNodes()\n */\n clearNodes: () => ReturnType\n }\n }\n}\n\nexport const clearNodes: RawCommands['clearNodes'] =\n () =>\n ({ state, tr, dispatch }) => {\n const { selection } = tr\n const { ranges } = selection\n\n if (!dispatch) {\n return true\n }\n\n ranges.forEach(({ $from, $to }) => {\n state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {\n if (node.type.isText) {\n return\n }\n\n const { doc, mapping } = tr\n const $mappedFrom = doc.resolve(mapping.map(pos))\n const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize))\n const nodeRange = $mappedFrom.blockRange($mappedTo)\n\n if (!nodeRange) {\n return\n }\n\n const targetLiftDepth = liftTarget(nodeRange)\n\n if (node.type.isTextblock) {\n const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index())\n\n tr.setNodeMarkup(nodeRange.start, defaultType)\n }\n\n if (targetLiftDepth || targetLiftDepth === 0) {\n tr.lift(nodeRange, targetLiftDepth)\n }\n })\n })\n\n return true\n }\n","import type { Command, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n command: {\n /**\n * Define a command inline.\n * @param fn The command function.\n * @example\n * editor.commands.command(({ tr, state }) => {\n * ...\n * return true\n * })\n */\n command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType\n }\n }\n}\n\nexport const command: RawCommands['command'] = fn => props => {\n return fn(props)\n}\n","import { createParagraphNear as originalCreateParagraphNear } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n createParagraphNear: {\n /**\n * Create a paragraph nearby.\n * @example editor.commands.createParagraphNear()\n */\n createParagraphNear: () => ReturnType\n }\n }\n}\n\nexport const createParagraphNear: RawCommands['createParagraphNear'] =\n () =>\n ({ state, dispatch }) => {\n return originalCreateParagraphNear(state, dispatch)\n }\n","import { TextSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n cut: {\n /**\n * Cuts content from a range and inserts it at a given position.\n * @param range The range to cut.\n * @param range.from The start position of the range.\n * @param range.to The end position of the range.\n * @param targetPos The position to insert the content at.\n * @example editor.commands.cut({ from: 1, to: 3 }, 5)\n */\n cut: ({ from, to }: { from: number; to: number }, targetPos: number) => ReturnType\n }\n }\n}\n\nexport const cut: RawCommands['cut'] =\n (originRange, targetPos) =>\n ({ editor, tr }) => {\n const { state } = editor\n\n const contentSlice = state.doc.slice(originRange.from, originRange.to)\n\n tr.deleteRange(originRange.from, originRange.to)\n const newPos = tr.mapping.map(targetPos)\n\n tr.insert(newPos, contentSlice.content)\n\n tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))))\n\n return true\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteCurrentNode: {\n /**\n * Delete the node that currently has the selection anchor.\n * @example editor.commands.deleteCurrentNode()\n */\n deleteCurrentNode: () => ReturnType\n }\n }\n}\n\nexport const deleteCurrentNode: RawCommands['deleteCurrentNode'] =\n () =>\n ({ tr, dispatch }) => {\n const { selection } = tr\n const currentNode = selection.$anchor.node()\n\n // if there is content inside the current node, break out of this command\n if (currentNode.content.size > 0) {\n return false\n }\n\n const $pos = tr.selection.$anchor\n\n for (let depth = $pos.depth; depth > 0; depth -= 1) {\n const node = $pos.node(depth)\n\n if (node.type === currentNode.type) {\n if (dispatch) {\n const from = $pos.before(depth)\n const to = $pos.after(depth)\n\n tr.delete(from, to).scrollIntoView()\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { NodeType, Schema } from '@tiptap/pm/model'\n\nexport function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {\n if (typeof nameOrType === 'string') {\n if (!schema.nodes[nameOrType]) {\n throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`)\n }\n\n return schema.nodes[nameOrType]\n }\n\n return nameOrType\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteNode: {\n /**\n * Delete a node with a given type or name.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.deleteNode('paragraph')\n */\n deleteNode: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const deleteNode: RawCommands['deleteNode'] =\n typeOrName =>\n ({ tr, state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n const $pos = tr.selection.$anchor\n\n for (let depth = $pos.depth; depth > 0; depth -= 1) {\n const node = $pos.node(depth)\n\n if (node.type === type) {\n if (dispatch) {\n const from = $pos.before(depth)\n const to = $pos.after(depth)\n\n tr.delete(from, to).scrollIntoView()\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteRange: {\n /**\n * Delete a given range.\n * @param range The range to delete.\n * @example editor.commands.deleteRange({ from: 1, to: 3 })\n */\n deleteRange: (range: Range) => ReturnType\n }\n }\n}\n\nexport const deleteRange: RawCommands['deleteRange'] =\n range =>\n ({ tr, dispatch }) => {\n const { from, to } = range\n\n if (dispatch) {\n tr.delete(from, to)\n }\n\n return true\n }\n","import { deleteSelection as originalDeleteSelection } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n deleteSelection: {\n /**\n * Delete the selection, if there is one.\n * @example editor.commands.deleteSelection()\n */\n deleteSelection: () => ReturnType\n }\n }\n}\n\nexport const deleteSelection: RawCommands['deleteSelection'] =\n () =>\n ({ state, dispatch }) => {\n return originalDeleteSelection(state, dispatch)\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n enter: {\n /**\n * Trigger enter.\n * @example editor.commands.enter()\n */\n enter: () => ReturnType\n }\n }\n}\n\nexport const enter: RawCommands['enter'] =\n () =>\n ({ commands }) => {\n return commands.keyboardShortcut('Enter')\n }\n","import { exitCode as originalExitCode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n exitCode: {\n /**\n * Exit from a code block.\n * @example editor.commands.exitCode()\n */\n exitCode: () => ReturnType\n }\n }\n}\n\nexport const exitCode: RawCommands['exitCode'] =\n () =>\n ({ state, dispatch }) => {\n return originalExitCode(state, dispatch)\n }\n","import type { MarkType } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\n\nimport { getMarkRange } from '../helpers/getMarkRange.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n extendMarkRange: {\n /**\n * Extends the text selection to the current mark by type or name.\n * @param typeOrName The type or name of the mark.\n * @param attributes The attributes of the mark.\n * @example editor.commands.extendMarkRange('bold')\n * @example editor.commands.extendMarkRange('mention', { userId: \"1\" })\n */\n extendMarkRange: (\n /**\n * The type or name of the mark.\n */\n typeOrName: string | MarkType,\n\n /**\n * The attributes of the mark.\n */\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const extendMarkRange: RawCommands['extendMarkRange'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n const type = getMarkType(typeOrName, state.schema)\n const { doc, selection } = tr\n const { $from, from, to } = selection\n\n if (dispatch) {\n const range = getMarkRange($from, type, attributes)\n\n if (range && range.from <= from && range.to >= to) {\n const newSelection = TextSelection.create(doc, range.from, range.to)\n\n tr.setSelection(newSelection)\n }\n }\n\n return true\n }\n","export function isRegExp(value: any): value is RegExp {\n return Object.prototype.toString.call(value) === '[object RegExp]'\n}\n","import { isRegExp } from './isRegExp.js'\n\n/**\n * Check if object1 includes object2\n * @param object1 Object\n * @param object2 Object\n */\nexport function objectIncludes(\n object1: Record<string, any>,\n object2: Record<string, any>,\n options: { strict: boolean } = { strict: true },\n): boolean {\n const keys = Object.keys(object2)\n\n if (!keys.length) {\n return true\n }\n\n return keys.every(key => {\n if (options.strict) {\n return object2[key] === object1[key]\n }\n\n if (isRegExp(object2[key])) {\n return object2[key].test(object1[key])\n }\n\n return object2[key] === object1[key]\n })\n}\n","import type { Mark as ProseMirrorMark, MarkType, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Range } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\n\nfunction findMarkInSet(\n marks: ProseMirrorMark[],\n type: MarkType,\n attributes: Record<string, any> = {},\n): ProseMirrorMark | undefined {\n return marks.find(item => {\n return (\n item.type === type &&\n objectIncludes(\n // Only check equality for the attributes that are provided\n Object.fromEntries(Object.keys(attributes).map(k => [k, item.attrs[k]])),\n attributes,\n )\n )\n })\n}\n\nfunction isMarkInSet(marks: ProseMirrorMark[], type: MarkType, attributes: Record<string, any> = {}): boolean {\n return !!findMarkInSet(marks, type, attributes)\n}\n\n/**\n * Get the range of a mark at a resolved position.\n */\nexport function getMarkRange(\n /**\n * The position to get the mark range for.\n */\n $pos: ResolvedPos,\n /**\n * The mark type to get the range for.\n */\n type: MarkType,\n /**\n * The attributes to match against.\n * If not provided, only the first mark at the position will be matched.\n */\n attributes?: Record<string, any>,\n): Range | void {\n if (!$pos || !type) {\n return\n }\n let start = $pos.parent.childAfter($pos.parentOffset)\n\n // If the cursor is at the start of a text node that does not have the mark, look backward\n if (!start.node || !start.node.marks.some(mark => mark.type === type)) {\n start = $pos.parent.childBefore($pos.parentOffset)\n }\n\n // If there is no text node with the mark even backward, return undefined\n if (!start.node || !start.node.marks.some(mark => mark.type === type)) {\n return\n }\n\n // Default to only matching against the first mark's attributes\n attributes = attributes || start.node.marks[0]?.attrs\n\n // We now know that the cursor is either at the start, middle or end of a text node with the specified mark\n // so we can look it up on the targeted mark\n const mark = findMarkInSet([...start.node.marks], type, attributes)\n\n if (!mark) {\n return\n }\n\n let startIndex = start.index\n let startPos = $pos.start() + start.offset\n let endIndex = startIndex + 1\n let endPos = startPos + start.node.nodeSize\n\n while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) {\n startIndex -= 1\n startPos -= $pos.parent.child(startIndex).nodeSize\n }\n\n while (endIndex < $pos.parent.childCount && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {\n endPos += $pos.parent.child(endIndex).nodeSize\n endIndex += 1\n }\n\n return {\n from: startPos,\n to: endPos,\n }\n}\n","import type { MarkType, Schema } from '@tiptap/pm/model'\n\nexport function getMarkType(nameOrType: string | MarkType, schema: Schema): MarkType {\n if (typeof nameOrType === 'string') {\n if (!schema.marks[nameOrType]) {\n throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`)\n }\n\n return schema.marks[nameOrType]\n }\n\n return nameOrType\n}\n","import type { Command, CommandProps, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n first: {\n /**\n * Runs one command after the other and stops at the first which returns true.\n * @param commands The commands to run.\n * @example editor.commands.first([command1, command2])\n */\n first: (commands: Command[] | ((props: CommandProps) => Command[])) => ReturnType\n }\n }\n}\n\nexport const first: RawCommands['first'] = commands => props => {\n const items = typeof commands === 'function' ? commands(props) : commands\n\n for (let i = 0; i < items.length; i += 1) {\n if (items[i](props)) {\n return true\n }\n }\n\n return false\n}\n","import { TextSelection } from '@tiptap/pm/state'\n\nexport function isTextSelection(value: unknown): value is TextSelection {\n return value instanceof TextSelection\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Selection, TextSelection } from '@tiptap/pm/state'\n\nimport type { FocusPosition } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\nexport function resolveFocusPosition(doc: ProseMirrorNode, position: FocusPosition = null): Selection | null {\n if (!position) {\n return null\n }\n\n const selectionAtStart = Selection.atStart(doc)\n const selectionAtEnd = Selection.atEnd(doc)\n\n if (position === 'start' || position === true) {\n return selectionAtStart\n }\n\n if (position === 'end') {\n return selectionAtEnd\n }\n\n const minPos = selectionAtStart.from\n const maxPos = selectionAtEnd.to\n\n if (position === 'all') {\n return TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos))\n }\n\n return TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos))\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","export function isAndroid(): boolean {\n return navigator.platform === 'Android' || /android/i.test(navigator.userAgent)\n}\n","export function isiOS(): boolean {\n return (\n ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes('Mac') && 'ontouchend' in document)\n )\n}\n","/**\n * Detects if the current browser is Safari (but not iOS Safari or Chrome).\n * @returns `true` if the browser is Safari, `false` otherwise.\n * @example\n * if (isSafari()) {\n * // Safari-specific handling\n * }\n */\nexport function isSafari(): boolean {\n return typeof navigator !== 'undefined' ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false\n}\n","import { isTextSelection } from '../helpers/isTextSelection.js'\nimport { resolveFocusPosition } from '../helpers/resolveFocusPosition.js'\nimport type { FocusPosition, RawCommands } from '../types.js'\nimport { isAndroid } from '../utilities/isAndroid.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isSafari } from '../utilities/isSafari.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n focus: {\n /**\n * Focus the editor at the given position.\n * @param position The position to focus at.\n * @param options.scrollIntoView Scroll the focused position into view after focusing\n * @example editor.commands.focus()\n * @example editor.commands.focus(32, { scrollIntoView: false })\n */\n focus: (\n /**\n * The position to focus at.\n */\n position?: FocusPosition,\n\n /**\n * Optional options\n * @default { scrollIntoView: true }\n */\n options?: {\n scrollIntoView?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const focus: RawCommands['focus'] =\n (position = null, options = {}) =>\n ({ editor, view, tr, dispatch }) => {\n options = {\n scrollIntoView: true,\n ...options,\n }\n\n const delayedFocus = () => {\n // focus within `requestAnimationFrame` breaks focus on iOS and Android\n // so we have to call this\n if (isiOS() || isAndroid()) {\n ;(view.dom as HTMLElement).focus()\n }\n\n // Safari requires preventScroll to avoid the browser scrolling to the\n // top of the editor when focus is called before the selection is set.\n // We exclude iOS and Android since they are already handled above.\n // see: https://github.com/ueberdosis/tiptap/issues/7318\n if (isSafari() && !isiOS() && !isAndroid()) {\n ;(view.dom as HTMLElement).focus({ preventScroll: true })\n }\n\n // For React we have to focus asynchronously. Otherwise wild things happen.\n // see: https://github.com/ueberdosis/tiptap/issues/1520\n requestAnimationFrame(() => {\n if (!editor.isDestroyed) {\n view.focus()\n\n if (options?.scrollIntoView) {\n editor.commands.scrollIntoView()\n }\n }\n })\n }\n\n if ((view.hasFocus() && position === null) || position === false) {\n return true\n }\n\n // we don’t try to resolve a NodeSelection or CellSelection\n if (dispatch && position === null && !isTextSelection(editor.state.selection)) {\n delayedFocus()\n return true\n }\n\n // pass through tr.doc instead of editor.state.doc\n // since transactions could change the editors state before this command has been run\n const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection\n const isSameSelection = editor.state.selection.eq(selection)\n\n if (dispatch) {\n if (!isSameSelection) {\n tr.setSelection(selection)\n }\n\n // `tr.setSelection` resets the stored marks\n // so we’ll restore them if the selection is the same as before\n if (isSameSelection && tr.storedMarks) {\n tr.setStoredMarks(tr.storedMarks)\n }\n\n delayedFocus()\n }\n\n return true\n }\n","import type { CommandProps, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n forEach: {\n /**\n * Loop through an array of items.\n */\n forEach: <T>(\n items: T[],\n fn: (\n item: T,\n props: CommandProps & {\n index: number\n },\n ) => boolean,\n ) => ReturnType\n }\n }\n}\n\nexport const forEach: RawCommands['forEach'] = (items, fn) => props => {\n return items.every((item, index) => fn(item, { ...props, index }))\n}\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\n\nimport type { Content, RawCommands } from '../types.js'\n\nexport interface InsertContentOptions {\n /**\n * Options for parsing the content.\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to update the selection after inserting the content.\n */\n updateSelection?: boolean\n applyInputRules?: boolean\n applyPasteRules?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertContent: {\n /**\n * Insert a node or string of HTML at the current position.\n * @example editor.commands.insertContent('<h1>Example</h1>')\n * @example editor.commands.insertContent('<h1>Example</h1>', { updateSelection: false })\n */\n insertContent: (\n /**\n * The ProseMirror content to insert.\n */\n value: Content | ProseMirrorNode | Fragment,\n\n /**\n * Optional options\n */\n options?: InsertContentOptions,\n ) => ReturnType\n }\n }\n}\n\nexport const insertContent: RawCommands['insertContent'] =\n (value, options) =>\n ({ tr, commands }) => {\n return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)\n }\n","import type { Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\n\nimport { createNodeFromContent } from '../helpers/createNodeFromContent.js'\nimport { selectionToInsertionEnd } from '../helpers/selectionToInsertionEnd.js'\nimport type { Content, Range, RawCommands } from '../types.js'\n\nexport interface InsertContentAtOptions {\n /**\n * Options for parsing the content.\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to update the selection after inserting the content.\n */\n updateSelection?: boolean\n\n /**\n * Whether to apply input rules after inserting the content.\n */\n applyInputRules?: boolean\n\n /**\n * Whether to apply paste rules after inserting the content.\n */\n applyPasteRules?: boolean\n\n /**\n * Whether to throw an error if the content is invalid.\n */\n errorOnInvalidContent?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertContentAt: {\n /**\n * Insert a node or string of HTML at a specific position.\n * @example editor.commands.insertContentAt(0, '<h1>Example</h1>')\n */\n insertContentAt: (\n /**\n * The position to insert the content at.\n */\n position: number | Range,\n\n /**\n * The ProseMirror content to insert.\n */\n value: Content | ProseMirrorNode | Fragment,\n\n /**\n * Optional options\n */\n options?: InsertContentAtOptions,\n ) => ReturnType\n }\n }\n}\n\nconst isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment is Fragment => {\n return !('type' in nodeOrFragment)\n}\n\nexport const insertContentAt: RawCommands['insertContentAt'] =\n (position, value, options) =>\n ({ tr, dispatch, editor }) => {\n if (dispatch) {\n options = {\n parseOptions: editor.options.parseOptions,\n updateSelection: true,\n applyInputRules: false,\n applyPasteRules: false,\n ...options,\n }\n\n let content: Fragment | ProseMirrorNode\n\n const emitContentError = (error: Error) => {\n editor.emit('contentError', {\n editor,\n error,\n disableCollaboration: () => {\n if (\n 'collaboration' in editor.storage &&\n typeof editor.storage.collaboration === 'object' &&\n editor.storage.collaboration\n ) {\n ;(editor.storage.collaboration as any).isDisabled = true\n }\n },\n })\n }\n\n const parseOptions: ParseOptions = {\n preserveWhitespace: 'full',\n ...options.parseOptions,\n }\n\n // If `emitContentError` is enabled, we want to check the content for errors\n // but ignore them (do not remove the invalid content from the document)\n if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {\n try {\n createNodeFromContent(value, editor.schema, {\n parseOptions,\n errorOnInvalidContent: true,\n })\n } catch (e) {\n emitContentError(e as Error)\n }\n }\n\n try {\n content = createNodeFromContent(value, editor.schema, {\n parseOptions,\n errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n } catch (e) {\n emitContentError(e as Error)\n return false\n }\n\n let { from, to } =\n typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to }\n\n let isOnlyTextContent = true\n let isOnlyBlockContent = true\n const nodes = isFragment(content) ? content : [content]\n\n nodes.forEach(node => {\n // check if added node is valid\n node.check()\n\n isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false\n\n isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false\n })\n\n // check if we can replace the wrapping node by\n // the newly inserted content\n // example:\n // replace an empty paragraph by an inserted image\n // instead of inserting the image below the paragraph\n if (from === to && isOnlyBlockContent) {\n const { parent } = tr.doc.resolve(from)\n const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount\n\n if (isEmptyTextBlock) {\n from -= 1\n to += 1\n }\n }\n\n let newContent\n\n // if there is only plain text we have to use `insertText`\n // because this will keep the current marks\n if (isOnlyTextContent) {\n // if value is string, we can use it directly\n // otherwise if it is an array, we have to join it\n if (Array.isArray(value)) {\n newContent = value.map(v => v.text || '').join('')\n } else if (value instanceof Fragment) {\n let text = ''\n\n value.forEach(node => {\n if (node.text) {\n text += node.text\n }\n })\n\n newContent = text\n } else if (typeof value === 'object' && !!value && !!value.text) {\n newContent = value.text\n } else {\n newContent = value as string\n }\n\n tr.insertText(newContent, from, to)\n } else {\n newContent = content\n\n const $from = tr.doc.resolve(from)\n const $fromNode = $from.node()\n const fromSelectionAtStart = $from.parentOffset === 0\n const isTextSelection = $fromNode.isText || $fromNode.isTextblock\n const hasContent = $fromNode.content.size > 0\n\n if (fromSelectionAtStart && isTextSelection && hasContent) {\n from = Math.max(0, from - 1)\n }\n\n tr.replaceWith(from, to, newContent)\n }\n\n // set cursor at end of inserted content\n if (options.updateSelection) {\n selectionToInsertionEnd(tr, tr.steps.length - 1, -1)\n }\n\n if (options.applyInputRules) {\n tr.setMeta('applyInputRules', { from, text: newContent })\n }\n\n if (options.applyPasteRules) {\n tr.setMeta('applyPasteRules', { from, text: newContent })\n }\n }\n\n return true\n }\n","import type { ParseOptions } from '@tiptap/pm/model'\nimport { DOMParser, Fragment, Node as ProseMirrorNode, Schema } from '@tiptap/pm/model'\n\nimport type { Content } from '../types.js'\nimport { elementFromString } from '../utilities/elementFromString.js'\n\nexport type CreateNodeFromContentOptions = {\n slice?: boolean\n parseOptions?: ParseOptions\n errorOnInvalidContent?: boolean\n}\n\n/**\n * Takes a JSON or HTML content and creates a Prosemirror node or fragment from it.\n * @param content The JSON or HTML content to create the node from\n * @param schema The Prosemirror schema to use for the node\n * @param options Options for the parser\n * @returns The created Prosemirror node or fragment\n */\nexport function createNodeFromContent(\n content: Content | ProseMirrorNode | Fragment,\n schema: Schema,\n options?: CreateNodeFromContentOptions,\n): ProseMirrorNode | Fragment {\n if (content instanceof ProseMirrorNode || content instanceof Fragment) {\n return content\n }\n options = {\n slice: true,\n parseOptions: {},\n ...options,\n }\n\n const isJSONContent = typeof content === 'object' && content !== null\n const isTextContent = typeof content === 'string'\n\n if (isJSONContent) {\n try {\n const isArrayContent = Array.isArray(content) && content.length > 0\n\n // if the JSON Content is an array of nodes, create a fragment for each node\n if (isArrayContent) {\n return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))\n }\n\n const node = schema.nodeFromJSON(content)\n\n if (options.errorOnInvalidContent) {\n node.check()\n }\n\n return node\n } catch (error) {\n if (options.errorOnInvalidContent) {\n throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })\n }\n\n console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)\n\n return createNodeFromContent('', schema, options)\n }\n }\n\n if (isTextContent) {\n // Check for invalid content\n if (options.errorOnInvalidContent) {\n let hasInvalidContent = false\n let invalidContent = ''\n\n // A copy of the current schema with a catch-all node at the end\n const contentCheckSchema = new Schema({\n topNode: schema.spec.topNode,\n marks: schema.spec.marks,\n // Prosemirror's schemas are executed such that: the last to execute, matches last\n // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle\n nodes: schema.spec.nodes.append({\n __tiptap__private__unknown__catch__all__node: {\n content: 'inline*',\n group: 'block',\n parseDOM: [\n {\n tag: '*',\n getAttrs: e => {\n // If this is ever called, we know that the content has something that we don't know how to handle in the schema\n hasInvalidContent = true\n // Try to stringify the element for a more helpful error message\n invalidContent = typeof e === 'string' ? e : e.outerHTML\n return null\n },\n },\n ],\n },\n }),\n })\n\n if (options.slice) {\n DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions)\n } else {\n DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions)\n }\n\n if (options.errorOnInvalidContent && hasInvalidContent) {\n throw new Error('[tiptap error]: Invalid HTML content', {\n cause: new Error(`Invalid element found: ${invalidContent}`),\n })\n }\n }\n\n const parser = DOMParser.fromSchema(schema)\n\n if (options.slice) {\n return parser.parseSlice(elementFromString(content), options.parseOptions).content\n }\n\n return parser.parse(elementFromString(content), options.parseOptions)\n }\n\n return createNodeFromContent('', schema, options)\n}\n","const removeWhitespaces = (node: HTMLElement) => {\n const children = node.childNodes\n\n for (let i = children.length - 1; i >= 0; i -= 1) {\n const child = children[i]\n\n if (child.nodeType === 3 && child.nodeValue && /^(\\n\\s\\s|\\n)$/.test(child.nodeValue)) {\n node.removeChild(child)\n } else if (child.nodeType === 1) {\n removeWhitespaces(child as HTMLElement)\n }\n }\n\n return node\n}\n\nexport function elementFromString(value: string): HTMLElement {\n if (typeof window === 'undefined') {\n throw new Error('[tiptap error]: there is no window object available, so this function cannot be used')\n }\n // add a wrapper to preserve leading and trailing whitespace\n const wrappedValue = `<body>${value}</body>`\n\n const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body\n\n return removeWhitespaces(html)\n}\n","import type { Transaction } from '@tiptap/pm/state'\nimport { Selection } from '@tiptap/pm/state'\nimport { ReplaceAroundStep, ReplaceStep } from '@tiptap/pm/transform'\n\n// source: https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466\nexport function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number) {\n const last = tr.steps.length - 1\n\n if (last < startLen) {\n return\n }\n\n const step = tr.steps[last]\n\n if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {\n return\n }\n\n const map = tr.mapping.maps[last]\n let end = 0\n\n map.forEach((_from, _to, _newFrom, newTo) => {\n if (end === 0) {\n end = newTo\n }\n })\n\n tr.setSelection(Selection.near(tr.doc.resolve(end), bias))\n}\n","import {\n joinBackward as originalJoinBackward,\n joinDown as originalJoinDown,\n joinForward as originalJoinForward,\n joinUp as originalJoinUp,\n} from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinUp: {\n /**\n * Join the selected block or, if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling above it.\n * @example editor.commands.joinUp()\n */\n joinUp: () => ReturnType\n }\n joinDown: {\n /**\n * Join the selected block, or the closest ancestor of the selection that can be joined, with the sibling after it.\n * @example editor.commands.joinDown()\n */\n joinDown: () => ReturnType\n }\n joinBackward: {\n /**\n * If the selection is empty and at the start of a textblock, try to reduce the distance between that block and the one before it—if there's a block directly before it that can be joined, join them.\n * If not, try to move the selected block closer to the next one in the document structure by lifting it out of its\n * parent or moving it into a parent of the previous block. Will use the view for accurate (bidi-aware) start-of-textblock detection if given.\n * @example editor.commands.joinBackward()\n */\n joinBackward: () => ReturnType\n }\n joinForward: {\n /**\n * If the selection is empty and the cursor is at the end of a textblock, try to reduce or remove the boundary between that block and the one after it,\n * either by joining them or by moving the other block closer to this one in the tree structure.\n * Will use the view for accurate start-of-textblock detection if given.\n * @example editor.commands.joinForward()\n */\n joinForward: () => ReturnType\n }\n }\n}\n\nexport const joinUp: RawCommands['joinUp'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinUp(state, dispatch)\n }\n\nexport const joinDown: RawCommands['joinDown'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinDown(state, dispatch)\n }\n\nexport const joinBackward: RawCommands['joinBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinBackward(state, dispatch)\n }\n\nexport const joinForward: RawCommands['joinForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalJoinForward(state, dispatch)\n }\n","import { joinPoint } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinItemBackward: {\n /**\n * Join two items backward.\n * @example editor.commands.joinItemBackward()\n */\n joinItemBackward: () => ReturnType\n }\n }\n}\n\nexport const joinItemBackward: RawCommands['joinItemBackward'] =\n () =>\n ({ state, dispatch, tr }) => {\n try {\n const point = joinPoint(state.doc, state.selection.$from.pos, -1)\n\n if (point === null || point === undefined) {\n return false\n }\n\n tr.join(point, 2)\n\n if (dispatch) {\n dispatch(tr)\n }\n\n return true\n } catch {\n return false\n }\n }\n","import { joinPoint } from '@tiptap/pm/transform'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinItemForward: {\n /**\n * Join two items Forwards.\n * @example editor.commands.joinItemForward()\n */\n joinItemForward: () => ReturnType\n }\n }\n}\n\nexport const joinItemForward: RawCommands['joinItemForward'] =\n () =>\n ({ state, dispatch, tr }) => {\n try {\n const point = joinPoint(state.doc, state.selection.$from.pos, +1)\n\n if (point === null || point === undefined) {\n return false\n }\n\n tr.join(point, 2)\n\n if (dispatch) {\n dispatch(tr)\n }\n\n return true\n } catch {\n return false\n }\n }\n","import { joinTextblockBackward as originalCommand } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinTextblockBackward: {\n /**\n * A more limited form of joinBackward that only tries to join the current textblock to the one before it, if the cursor is at the start of a textblock.\n */\n joinTextblockBackward: () => ReturnType\n }\n }\n}\n\nexport const joinTextblockBackward: RawCommands['joinTextblockBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalCommand(state, dispatch)\n }\n","import { joinTextblockForward as originalCommand } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n joinTextblockForward: {\n /**\n * A more limited form of joinForward that only tries to join the current textblock to the one after it, if the cursor is at the end of a textblock.\n */\n joinTextblockForward: () => ReturnType\n }\n }\n}\n\nexport const joinTextblockForward: RawCommands['joinTextblockForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalCommand(state, dispatch)\n }\n","export function isMacOS(): boolean {\n return typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false\n}\n","import type { RawCommands } from '../types.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isMacOS } from '../utilities/isMacOS.js'\n\nfunction normalizeKeyName(name: string) {\n const parts = name.split(/-(?!$)/)\n let result = parts[parts.length - 1]\n\n if (result === 'Space') {\n result = ' '\n }\n\n let alt\n let ctrl\n let shift\n let meta\n\n for (let i = 0; i < parts.length - 1; i += 1) {\n const mod = parts[i]\n\n if (/^(cmd|meta|m)$/i.test(mod)) {\n meta = true\n } else if (/^a(lt)?$/i.test(mod)) {\n alt = true\n } else if (/^(c|ctrl|control)$/i.test(mod)) {\n ctrl = true\n } else if (/^s(hift)?$/i.test(mod)) {\n shift = true\n } else if (/^mod$/i.test(mod)) {\n if (isiOS() || isMacOS()) {\n meta = true\n } else {\n ctrl = true\n }\n } else {\n throw new Error(`Unrecognized modifier name: ${mod}`)\n }\n }\n\n if (alt) {\n result = `Alt-${result}`\n }\n\n if (ctrl) {\n result = `Ctrl-${result}`\n }\n\n if (meta) {\n result = `Meta-${result}`\n }\n\n if (shift) {\n result = `Shift-${result}`\n }\n\n return result\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n keyboardShortcut: {\n /**\n * Trigger a keyboard shortcut.\n * @param name The name of the keyboard shortcut.\n * @example editor.commands.keyboardShortcut('Mod-b')\n */\n keyboardShortcut: (name: string) => ReturnType\n }\n }\n}\n\nexport const keyboardShortcut: RawCommands['keyboardShortcut'] =\n name =>\n ({ editor, view, tr, dispatch }) => {\n const keys = normalizeKeyName(name).split(/-(?!$)/)\n const key = keys.find(item => !['Alt', 'Ctrl', 'Meta', 'Shift'].includes(item))\n const event = new KeyboardEvent('keydown', {\n key: key === 'Space' ? ' ' : key,\n altKey: keys.includes('Alt'),\n ctrlKey: keys.includes('Ctrl'),\n metaKey: keys.includes('Meta'),\n shiftKey: keys.includes('Shift'),\n bubbles: true,\n cancelable: true,\n })\n\n const capturedTransaction = editor.captureTransaction(() => {\n view.someProp('handleKeyDown', f => f(view, event))\n })\n\n capturedTransaction?.steps.forEach(step => {\n const newStep = step.map(tr.mapping)\n\n if (newStep && dispatch) {\n tr.maybeStep(newStep)\n }\n })\n\n return true\n }\n","import { lift as originalLift } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n lift: {\n /**\n * Removes an existing wrap if possible lifting the node out of it\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.lift('paragraph')\n * @example editor.commands.lift('heading', { level: 1 })\n */\n lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const lift: RawCommands['lift'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n if (!isActive) {\n return false\n }\n\n return originalLift(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport type { NodeRange } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\nimport { getNodeType } from './getNodeType.js'\n\nexport function isNodeActive(\n state: EditorState,\n typeOrName: NodeType | string | null,\n attributes: Record<string, any> = {},\n): boolean {\n const { from, to, empty } = state.selection\n const type = typeOrName ? getNodeType(typeOrName, state.schema) : null\n\n const nodeRanges: NodeRange[] = []\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n const relativeFrom = Math.max(from, pos)\n const relativeTo = Math.min(to, pos + node.nodeSize)\n\n nodeRanges.push({\n node,\n from: relativeFrom,\n to: relativeTo,\n })\n })\n\n const selectionRange = to - from\n const matchedNodeRanges = nodeRanges\n .filter(nodeRange => {\n if (!type) {\n return true\n }\n\n return type.name === nodeRange.node.type.name\n })\n .filter(nodeRange => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }))\n\n if (empty) {\n return !!matchedNodeRanges.length\n }\n\n const range = matchedNodeRanges.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0)\n\n return range >= selectionRange\n}\n","import { liftEmptyBlock as originalLiftEmptyBlock } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n liftEmptyBlock: {\n /**\n * If the cursor is in an empty textblock that can be lifted, lift the block.\n * @example editor.commands.liftEmptyBlock()\n */\n liftEmptyBlock: () => ReturnType\n }\n }\n}\n\nexport const liftEmptyBlock: RawCommands['liftEmptyBlock'] =\n () =>\n ({ state, dispatch }) => {\n return originalLiftEmptyBlock(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { liftListItem as originalLiftListItem } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n liftListItem: {\n /**\n * Create a command to lift the list item around the selection up into a wrapping list.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.liftListItem('listItem')\n */\n liftListItem: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const liftListItem: RawCommands['liftListItem'] =\n typeOrName =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalLiftListItem(type)(state, dispatch)\n }\n","import { newlineInCode as originalNewlineInCode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n newlineInCode: {\n /**\n * Add a newline character in code.\n * @example editor.commands.newlineInCode()\n */\n newlineInCode: () => ReturnType\n }\n }\n}\n\nexport const newlineInCode: RawCommands['newlineInCode'] =\n () =>\n ({ state, dispatch }) => {\n return originalNewlineInCode(state, dispatch)\n }\n","import type { Schema } from '@tiptap/pm/model'\n\n/**\n * Get the type of a schema item by its name.\n * @param name The name of the schema item\n * @param schema The Prosemiror schema to search in\n * @returns The type of the schema item (`node` or `mark`), or null if it doesn't exist\n */\nexport function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null {\n if (schema.nodes[name]) {\n return 'node'\n }\n\n if (schema.marks[name]) {\n return 'mark'\n }\n\n return null\n}\n","/**\n * Remove a property or an array of properties from an object\n * @param obj Object\n * @param key Key to remove\n */\nexport function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {\n const props = typeof propOrProps === 'string' ? [propOrProps] : propOrProps\n\n return Object.keys(obj).reduce((newObj: Record<string, any>, prop) => {\n if (!props.includes(prop)) {\n newObj[prop] = obj[prop]\n }\n\n return newObj\n }, {})\n}\n","import type { MarkType, NodeType } from '@tiptap/pm/model'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'\nimport type { RawCommands } from '../types.js'\nimport { deleteProps } from '../utilities/deleteProps.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n resetAttributes: {\n /**\n * Resets some node attributes to the default value.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node to reset.\n * @example editor.commands.resetAttributes('heading', 'level')\n */\n resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => ReturnType\n }\n }\n}\n\nexport const resetAttributes: RawCommands['resetAttributes'] =\n (typeOrName, attributes) =>\n ({ tr, state, dispatch }) => {\n let nodeType: NodeType | null = null\n let markType: MarkType | null = null\n\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (!schemaType) {\n return false\n }\n\n if (schemaType === 'node') {\n nodeType = getNodeType(typeOrName as NodeType, state.schema)\n }\n\n if (schemaType === 'mark') {\n markType = getMarkType(typeOrName as MarkType, state.schema)\n }\n\n let canReset = false\n\n tr.selection.ranges.forEach(range => {\n state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {\n if (nodeType && nodeType === node.type) {\n canReset = true\n\n if (dispatch) {\n tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))\n }\n }\n\n if (markType && node.marks.length) {\n node.marks.forEach(mark => {\n if (markType === mark.type) {\n canReset = true\n\n if (dispatch) {\n tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)))\n }\n }\n })\n }\n })\n })\n\n return canReset\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n scrollIntoView: {\n /**\n * Scroll the selection into view.\n * @example editor.commands.scrollIntoView()\n */\n scrollIntoView: () => ReturnType\n }\n }\n}\n\nexport const scrollIntoView: RawCommands['scrollIntoView'] =\n () =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n tr.scrollIntoView()\n }\n\n return true\n }\n","import { AllSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectAll: {\n /**\n * Select the whole document.\n * @example editor.commands.selectAll()\n */\n selectAll: () => ReturnType\n }\n }\n}\n\nexport const selectAll: RawCommands['selectAll'] =\n () =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const selection = new AllSelection(tr.doc)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import { selectNodeBackward as originalSelectNodeBackward } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectNodeBackward: {\n /**\n * Select a node backward.\n * @example editor.commands.selectNodeBackward()\n */\n selectNodeBackward: () => ReturnType\n }\n }\n}\n\nexport const selectNodeBackward: RawCommands['selectNodeBackward'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectNodeBackward(state, dispatch)\n }\n","import { selectNodeForward as originalSelectNodeForward } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectNodeForward: {\n /**\n * Select a node forward.\n * @example editor.commands.selectNodeForward()\n */\n selectNodeForward: () => ReturnType\n }\n }\n}\n\nexport const selectNodeForward: RawCommands['selectNodeForward'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectNodeForward(state, dispatch)\n }\n","import { selectParentNode as originalSelectParentNode } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectParentNode: {\n /**\n * Select the parent node.\n * @example editor.commands.selectParentNode()\n */\n selectParentNode: () => ReturnType\n }\n }\n}\n\nexport const selectParentNode: RawCommands['selectParentNode'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectParentNode(state, dispatch)\n }\n","// @ts-ignore\n// TODO: add types to @types/prosemirror-commands\nimport { selectTextblockEnd as originalSelectTextblockEnd } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectTextblockEnd: {\n /**\n * Moves the cursor to the end of current text block.\n * @example editor.commands.selectTextblockEnd()\n */\n selectTextblockEnd: () => ReturnType\n }\n }\n}\n\nexport const selectTextblockEnd: RawCommands['selectTextblockEnd'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectTextblockEnd(state, dispatch)\n }\n","// @ts-ignore\n// TODO: add types to @types/prosemirror-commands\nimport { selectTextblockStart as originalSelectTextblockStart } from '@tiptap/pm/commands'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n selectTextblockStart: {\n /**\n * Moves the cursor to the start of current text block.\n * @example editor.commands.selectTextblockStart()\n */\n selectTextblockStart: () => ReturnType\n }\n }\n}\n\nexport const selectTextblockStart: RawCommands['selectTextblockStart'] =\n () =>\n ({ state, dispatch }) => {\n return originalSelectTextblockStart(state, dispatch)\n }\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions, Schema } from '@tiptap/pm/model'\n\nimport type { Content } from '../types.js'\nimport { createNodeFromContent } from './createNodeFromContent.js'\n\n/**\n * Create a new Prosemirror document node from content.\n * @param content The JSON or HTML content to create the document from\n * @param schema The Prosemirror schema to use for the document\n * @param parseOptions Options for the parser\n * @returns The created Prosemirror document node\n */\nexport function createDocument(\n content: Content | ProseMirrorNode | Fragment,\n schema: Schema,\n parseOptions: ParseOptions = {},\n options: { errorOnInvalidContent?: boolean } = {},\n): ProseMirrorNode {\n return createNodeFromContent(content, schema, {\n slice: false,\n parseOptions,\n errorOnInvalidContent: options.errorOnInvalidContent,\n }) as ProseMirrorNode\n}\n","import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'\n\nimport { createDocument } from '../helpers/createDocument.js'\nimport type { Content, RawCommands } from '../types.js'\n\nexport interface SetContentOptions {\n /**\n * Options for parsing the content.\n * @default {}\n */\n parseOptions?: ParseOptions\n\n /**\n * Whether to throw an error if the content is invalid.\n */\n errorOnInvalidContent?: boolean\n\n /**\n * Whether to emit an update event.\n * @default true\n */\n emitUpdate?: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setContent: {\n /**\n * Replace the whole document with new content.\n * @param content The new content.\n * @param emitUpdate Whether to emit an update event.\n * @param parseOptions Options for parsing the content.\n * @example editor.commands.setContent('<p>Example text</p>')\n */\n setContent: (\n /**\n * The new content.\n */\n content: Content | Fragment | ProseMirrorNode,\n\n /**\n * Options for `setContent`.\n */\n options?: SetContentOptions,\n ) => ReturnType\n }\n }\n}\n\nexport const setContent: RawCommands['setContent'] =\n (content, { errorOnInvalidContent, emitUpdate = true, parseOptions = {} } = {}) =>\n ({ editor, tr, dispatch, commands }) => {\n const { doc } = tr\n\n // This is to keep backward compatibility with the previous behavior\n // TODO remove this in the next major version\n if (parseOptions.preserveWhitespace !== 'full') {\n const document = createDocument(content, editor.schema, parseOptions, {\n errorOnInvalidContent: errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n\n if (dispatch) {\n tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate)\n }\n return true\n }\n\n if (dispatch) {\n tr.setMeta('preventUpdate', !emitUpdate)\n }\n\n return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {\n parseOptions,\n errorOnInvalidContent: errorOnInvalidContent ?? editor.options.enableContentCheck,\n })\n }\n","import type { Mark, MarkType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getMarkType } from './getMarkType.js'\n\nexport function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): Record<string, any> {\n const type = getMarkType(typeOrName, state.schema)\n const { from, to, empty } = state.selection\n const marks: Mark[] = []\n\n if (empty) {\n if (state.storedMarks) {\n marks.push(...state.storedMarks)\n }\n\n marks.push(...state.selection.$head.marks())\n } else {\n state.doc.nodesBetween(from, to, node => {\n marks.push(...node.marks)\n })\n }\n\n const mark = marks.find(markItem => markItem.type.name === type.name)\n\n if (!mark) {\n return {}\n }\n\n return { ...mark.attrs }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { Transform } from '@tiptap/pm/transform'\n\n/**\n * Returns a new `Transform` based on all steps of the passed transactions.\n * @param oldDoc The Prosemirror node to start from\n * @param transactions The transactions to combine\n * @returns A new `Transform` with all steps of the passed transactions\n */\nexport function combineTransactionSteps(oldDoc: ProseMirrorNode, transactions: Transaction[]): Transform {\n const transform = new Transform(oldDoc)\n\n transactions.forEach(transaction => {\n transaction.steps.forEach(step => {\n transform.step(step)\n })\n })\n\n return transform\n}\n","import type { ContentMatch, NodeType } from '@tiptap/pm/model'\n\n/**\n * Gets the default block type at a given match\n * @param match The content match to get the default block type from\n * @returns The default block type or null\n */\nexport function defaultBlockAt(match: ContentMatch): NodeType | null {\n for (let i = 0; i < match.edgeCount; i += 1) {\n const { type } = match.edge(i)\n\n if (type.isTextblock && !type.hasRequiredAttrs()) {\n return type\n }\n }\n\n return null\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { NodeWithPos, Predicate } from '../types.js'\n\n/**\n * Find children inside a Prosemirror node that match a predicate.\n * @param node The Prosemirror node to search in\n * @param predicate The predicate to match\n * @returns An array of nodes with their positions\n */\nexport function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {\n const nodesWithPos: NodeWithPos[] = []\n\n node.descendants((child, pos) => {\n if (predicate(child)) {\n nodesWithPos.push({\n node: child,\n pos,\n })\n }\n })\n\n return nodesWithPos\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { NodeWithPos, Predicate, Range } from '../types.js'\n\n/**\n * Same as `findChildren` but searches only within a `range`.\n * @param node The Prosemirror node to search in\n * @param range The range to search in\n * @param predicate The predicate to match\n * @returns An array of nodes with their positions\n */\nexport function findChildrenInRange(node: ProseMirrorNode, range: Range, predicate: Predicate): NodeWithPos[] {\n const nodesWithPos: NodeWithPos[] = []\n\n // if (range.from === range.to) {\n // const nodeAt = node.nodeAt(range.from)\n\n // if (nodeAt) {\n // nodesWithPos.push({\n // node: nodeAt,\n // pos: range.from,\n // })\n // }\n // }\n\n node.nodesBetween(range.from, range.to, (child, pos) => {\n if (predicate(child)) {\n nodesWithPos.push({\n node: child,\n pos,\n })\n }\n })\n\n return nodesWithPos\n}\n","import type { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Predicate } from '../types.js'\n\n/**\n * Finds the closest parent node to a resolved position that matches a predicate.\n * @param $pos The resolved position to search from\n * @param predicate The predicate to match\n * @returns The closest parent node to the resolved position that matches the predicate\n * @example ```js\n * findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')\n * ```\n */\nexport function findParentNodeClosestToPos(\n $pos: ResolvedPos,\n predicate: Predicate,\n):\n | {\n pos: number\n start: number\n depth: number\n node: ProseMirrorNode\n }\n | undefined {\n for (let i = $pos.depth; i > 0; i -= 1) {\n const node = $pos.node(i)\n\n if (predicate(node)) {\n return {\n pos: i > 0 ? $pos.before(i) : 0,\n start: $pos.start(i),\n depth: i,\n node,\n }\n }\n }\n}\n","import type { Selection } from '@tiptap/pm/state'\n\nimport type { Predicate } from '../types.js'\nimport { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'\n\n/**\n * Finds the closest parent node to the current selection that matches a predicate.\n * @param predicate The predicate to match\n * @returns A command that finds the closest parent node to the current selection that matches the predicate\n * @example ```js\n * findParentNode(node => node.type.name === 'paragraph')\n * ```\n */\nexport function findParentNode(\n predicate: Predicate,\n): (selection: Selection) => ReturnType<typeof findParentNodeClosestToPos> {\n return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)\n}\n","import type { ExtensionConfig } from '../Extension.js'\nimport type { MarkConfig } from '../Mark.js'\nimport type { NodeConfig } from '../Node.js'\nimport type { AnyExtension, MaybeThisParameterType, RemoveThis } from '../types.js'\n\n/**\n * Returns a field from an extension\n * @param extension The Tiptap extension\n * @param field The field, for example `renderHTML` or `priority`\n * @param context The context object that should be passed as `this` into the function\n * @returns The field value\n */\nexport function getExtensionField<T = any, E extends AnyExtension = any>(\n extension: E,\n field: keyof ExtensionConfig | keyof MarkConfig | keyof NodeConfig,\n context?: Omit<MaybeThisParameterType<T>, 'parent'>,\n): RemoveThis<T> {\n if (extension.config[field as keyof typeof extension.config] === undefined && extension.parent) {\n return getExtensionField(extension.parent, field, context)\n }\n\n if (typeof extension.config[field as keyof typeof extension.config] === 'function') {\n const value = (extension.config[field as keyof typeof extension.config] as any).bind({\n ...context,\n parent: extension.parent ? getExtensionField(extension.parent, field, context) : null,\n })\n\n return value\n }\n\n return extension.config[field as keyof typeof extension.config] as RemoveThis<T>\n}\n","import type { AnyConfig, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\n\n/**\n * Create a flattened array of extensions by traversing the `addExtensions` field.\n * @param extensions An array of Tiptap extensions\n * @returns A flattened array of Tiptap extensions\n */\nexport function flattenExtensions(extensions: Extensions): Extensions {\n return (\n extensions\n .map(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n const addExtensions = getExtensionField<AnyConfig['addExtensions']>(extension, 'addExtensions', context)\n\n if (addExtensions) {\n return [extension, ...flattenExtensions(addExtensions())]\n }\n\n return extension\n })\n // `Infinity` will break TypeScript so we set a number that is probably high enough\n .flat(10)\n )\n}\n","import { Node } from '@tiptap/pm/model'\n\nimport type { Extensions, JSONContent } from '../types.js'\nimport { getHTMLFromFragment } from './getHTMLFromFragment.js'\nimport { getSchema } from './getSchema.js'\n\n/**\n * Generate HTML from a JSONContent\n * @param doc The JSONContent to generate HTML from\n * @param extensions The extensions to use for the schema\n * @returns The generated HTML\n */\nexport function generateHTML(doc: JSONContent, extensions: Extensions): string {\n const schema = getSchema(extensions)\n const contentNode = Node.fromJSON(schema, doc)\n\n return getHTMLFromFragment(contentNode.content, schema)\n}\n","import type { Fragment, Schema } from '@tiptap/pm/model'\nimport { DOMSerializer } from '@tiptap/pm/model'\n\nexport function getHTMLFromFragment(fragment: Fragment, schema: Schema): string {\n const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment)\n\n const temporaryDocument = document.implementation.createHTMLDocument()\n const container = temporaryDocument.createElement('div')\n\n container.appendChild(documentFragment)\n\n return container.innerHTML\n}\n","import type { MarkSpec, NodeSpec, TagParseRule } from '@tiptap/pm/model'\nimport { Schema } from '@tiptap/pm/model'\n\nimport type { Editor, MarkConfig, NodeConfig } from '../index.js'\nimport type { AnyConfig, Extensions } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\nimport { isEmptyObject } from '../utilities/isEmptyObject.js'\nimport { getAttributesFromExtensions } from './getAttributesFromExtensions.js'\nimport { getExtensionField } from './getExtensionField.js'\nimport { getRenderedAttributes } from './getRenderedAttributes.js'\nimport { injectExtensionAttributesToParseRule } from './injectExtensionAttributesToParseRule.js'\nimport { splitExtensions } from './splitExtensions.js'\n\nfunction cleanUpSchemaItem<T>(data: T) {\n return Object.fromEntries(\n // @ts-ignore\n Object.entries(data).filter(([key, value]) => {\n if (key === 'attrs' && isEmptyObject(value as object | undefined)) {\n return false\n }\n\n return value !== null && value !== undefined\n }),\n ) as T\n}\n\n/**\n * Builds an attribute spec tuple for ProseMirror schema from an extension attribute.\n * @param extensionAttribute The extension attribute to build the spec for\n * @returns A tuple of [attributeName, spec]\n */\nfunction buildAttributeSpec(\n extensionAttribute: ReturnType<typeof getAttributesFromExtensions>[number],\n): [string, Record<string, any>] {\n const spec: Record<string, any> = {}\n\n // Only include 'default' if the attribute is not required and default is set on the attribute\n if (!extensionAttribute?.attribute?.isRequired && 'default' in (extensionAttribute?.attribute || {})) {\n spec.default = extensionAttribute.attribute.default\n }\n\n // Only include 'validate' if it's defined\n if (extensionAttribute?.attribute?.validate !== undefined) {\n spec.validate = extensionAttribute.attribute.validate\n }\n\n return [extensionAttribute.name, spec]\n}\n\n/**\n * Creates a new Prosemirror schema based on the given extensions.\n * @param extensions An array of Tiptap extensions\n * @param editor The editor instance\n * @returns A Prosemirror schema\n */\nexport function getSchemaByResolvedExtensions(extensions: Extensions, editor?: Editor): Schema {\n const allAttributes = getAttributesFromExtensions(extensions)\n const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n const topNode = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))?.name\n\n const nodes = Object.fromEntries(\n nodeExtensions.map(extension => {\n const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n editor,\n }\n\n const extraNodeFields = extensions.reduce((fields, e) => {\n const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(e, 'extendNodeSchema', context)\n\n return {\n ...fields,\n ...(extendNodeSchema ? extendNodeSchema(extension) : {}),\n }\n }, {})\n\n const schema: NodeSpec = cleanUpSchemaItem({\n ...extraNodeFields,\n content: callOrReturn(getExtensionField<NodeConfig['content']>(extension, 'content', context)),\n marks: callOrReturn(getExtensionField<NodeConfig['marks']>(extension, 'marks', context)),\n group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),\n inline: callOrReturn(getExtensionField<NodeConfig['inline']>(extension, 'inline', context)),\n atom: callOrReturn(getExtensionField<NodeConfig['atom']>(extension, 'atom', context)),\n selectable: callOrReturn(getExtensionField<NodeConfig['selectable']>(extension, 'selectable', context)),\n draggable: callOrReturn(getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context)),\n code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),\n whitespace: callOrReturn(getExtensionField<NodeConfig['whitespace']>(extension, 'whitespace', context)),\n linebreakReplacement: callOrReturn(\n getExtensionField<NodeConfig['linebreakReplacement']>(extension, 'linebreakReplacement', context),\n ),\n defining: callOrReturn(getExtensionField<NodeConfig['defining']>(extension, 'defining', context)),\n isolating: callOrReturn(getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context)),\n attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)),\n })\n\n const parseHTML = callOrReturn(getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context))\n\n if (parseHTML) {\n schema.parseDOM = parseHTML.map(parseRule =>\n injectExtensionAttributesToParseRule(parseRule, extensionAttributes),\n ) as TagParseRule[]\n }\n\n const renderHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (renderHTML) {\n schema.toDOM = node =>\n renderHTML({\n node,\n HTMLAttributes: getRenderedAttributes(node, extensionAttributes),\n })\n }\n\n const renderText = getExtensionField<NodeConfig['renderText']>(extension, 'renderText', context)\n\n if (renderText) {\n schema.toText = renderText\n }\n\n return [extension.name, schema]\n }),\n )\n\n const marks = Object.fromEntries(\n markExtensions.map(extension => {\n const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n editor,\n }\n\n const extraMarkFields = extensions.reduce((fields, e) => {\n const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(e, 'extendMarkSchema', context)\n\n return {\n ...fields,\n ...(extendMarkSchema ? extendMarkSchema(extension as any) : {}),\n }\n }, {})\n\n const schema: MarkSpec = cleanUpSchemaItem({\n ...extraMarkFields,\n inclusive: callOrReturn(getExtensionField<MarkConfig['inclusive']>(extension, 'inclusive', context)),\n excludes: callOrReturn(getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context)),\n group: callOrReturn(getExtensionField<MarkConfig['group']>(extension, 'group', context)),\n spanning: callOrReturn(getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context)),\n code: callOrReturn(getExtensionField<MarkConfig['code']>(extension, 'code', context)),\n attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)),\n })\n\n const parseHTML = callOrReturn(getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context))\n\n if (parseHTML) {\n schema.parseDOM = parseHTML.map(parseRule =>\n injectExtensionAttributesToParseRule(parseRule, extensionAttributes),\n )\n }\n\n const renderHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (renderHTML) {\n schema.toDOM = mark =>\n renderHTML({\n mark,\n HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),\n })\n }\n\n return [extension.name, schema]\n }),\n )\n\n return new Schema({\n topNode,\n nodes,\n marks,\n })\n}\n","// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function isFunction(value: any): value is Function {\n return typeof value === 'function'\n}\n","import type { MaybeReturnType } from '../types.js'\nimport { isFunction } from './isFunction.js'\n\n/**\n * Optionally calls `value` as a function.\n * Otherwise it is returned directly.\n * @param value Function or any value.\n * @param context Optional context to bind to function.\n * @param props Optional props to pass to function.\n */\nexport function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {\n if (isFunction(value)) {\n if (context) {\n return value.bind(context)(...props)\n }\n\n return value(...props)\n }\n\n return value as MaybeReturnType<T>\n}\n","export function isEmptyObject(value = {}): boolean {\n return Object.keys(value).length === 0 && value.constructor === Object\n}\n","import type { Extension } from '../Extension.js'\nimport type { Mark } from '../Mark.js'\nimport type { Node } from '../Node.js'\nimport type { Extensions } from '../types.js'\n\nexport function splitExtensions(extensions: Extensions) {\n const baseExtensions = extensions.filter(extension => extension.type === 'extension') as Extension[]\n const nodeExtensions = extensions.filter(extension => extension.type === 'node') as Node[]\n const markExtensions = extensions.filter(extension => extension.type === 'mark') as Mark[]\n\n return {\n baseExtensions,\n nodeExtensions,\n markExtensions,\n }\n}\n","import type { MarkConfig, NodeConfig } from '../index.js'\nimport type { AnyConfig, Attribute, Attributes, ExtensionAttribute, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\nimport { splitExtensions } from './splitExtensions.js'\n\n/**\n * Get a list of all extension attributes defined in `addAttribute` and `addGlobalAttribute`.\n * @param extensions List of extensions\n */\nexport function getAttributesFromExtensions(extensions: Extensions): ExtensionAttribute[] {\n const extensionAttributes: ExtensionAttribute[] = []\n const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n const nodeAndMarkExtensions = [...nodeExtensions, ...markExtensions]\n const defaultAttribute: Required<Omit<Attribute, 'validate'>> & Pick<Attribute, 'validate'> = {\n default: null,\n validate: undefined,\n rendered: true,\n renderHTML: null,\n parseHTML: null,\n keepOnSplit: true,\n isRequired: false,\n }\n\n extensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n extensions: nodeAndMarkExtensions,\n }\n\n const addGlobalAttributes = getExtensionField<AnyConfig['addGlobalAttributes']>(\n extension,\n 'addGlobalAttributes',\n context,\n )\n\n if (!addGlobalAttributes) {\n return\n }\n\n const globalAttributes = addGlobalAttributes()\n\n globalAttributes.forEach(globalAttribute => {\n globalAttribute.types.forEach(type => {\n Object.entries(globalAttribute.attributes).forEach(([name, attribute]) => {\n extensionAttributes.push({\n type,\n name,\n attribute: {\n ...defaultAttribute,\n ...attribute,\n },\n })\n })\n })\n })\n })\n\n nodeAndMarkExtensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n const addAttributes = getExtensionField<NodeConfig['addAttributes'] | MarkConfig['addAttributes']>(\n extension,\n 'addAttributes',\n context,\n )\n\n if (!addAttributes) {\n return\n }\n\n // TODO: remove `as Attributes`\n const attributes = addAttributes() as Attributes\n\n Object.entries(attributes).forEach(([name, attribute]) => {\n const mergedAttr = {\n ...defaultAttribute,\n ...attribute,\n }\n\n if (typeof mergedAttr?.default === 'function') {\n mergedAttr.default = mergedAttr.default()\n }\n\n if (mergedAttr?.isRequired && mergedAttr?.default === undefined) {\n delete mergedAttr.default\n }\n\n extensionAttributes.push({\n type: extension.name,\n name,\n attribute: mergedAttr,\n })\n })\n })\n\n return extensionAttributes\n}\n","export function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {\n return objects\n .filter(item => !!item)\n .reduce((items, item) => {\n const mergedAttributes = { ...items }\n\n Object.entries(item).forEach(([key, value]) => {\n const exists = mergedAttributes[key]\n\n if (!exists) {\n mergedAttributes[key] = value\n\n return\n }\n\n if (key === 'class') {\n const valueClasses: string[] = value ? String(value).split(' ') : []\n const existingClasses: string[] = mergedAttributes[key] ? mergedAttributes[key].split(' ') : []\n\n const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass))\n\n mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ')\n } else if (key === 'style') {\n const newStyles: string[] = value\n ? value\n .split(';')\n .map((style: string) => style.trim())\n .filter(Boolean)\n : []\n const existingStyles: string[] = mergedAttributes[key]\n ? mergedAttributes[key]\n .split(';')\n .map((style: string) => style.trim())\n .filter(Boolean)\n : []\n\n const styleMap = new Map<string, string>()\n\n existingStyles.forEach(style => {\n const [property, val] = style.split(':').map(part => part.trim())\n\n styleMap.set(property, val)\n })\n\n newStyles.forEach(style => {\n const [property, val] = style.split(':').map(part => part.trim())\n\n styleMap.set(property, val)\n })\n\n mergedAttributes[key] = Array.from(styleMap.entries())\n .map(([property, val]) => `${property}: ${val}`)\n .join('; ')\n } else {\n mergedAttributes[key] = value\n }\n })\n\n return mergedAttributes\n }, {})\n}\n","import type { Mark, Node } from '@tiptap/pm/model'\n\nimport type { ExtensionAttribute } from '../types.js'\nimport { mergeAttributes } from '../utilities/mergeAttributes.js'\n\nexport function getRenderedAttributes(\n nodeOrMark: Node | Mark,\n extensionAttributes: ExtensionAttribute[],\n): Record<string, any> {\n return extensionAttributes\n .filter(attribute => attribute.type === nodeOrMark.type.name)\n .filter(item => item.attribute.rendered)\n .map(item => {\n if (!item.attribute.renderHTML) {\n return {\n [item.name]: nodeOrMark.attrs[item.name],\n }\n }\n\n return item.attribute.renderHTML(nodeOrMark.attrs) || {}\n })\n .reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})\n}\n","export function fromString(value: any): any {\n if (typeof value !== 'string') {\n return value\n }\n\n if (value.match(/^[+-]?(?:\\d*\\.)?\\d+$/)) {\n return Number(value)\n }\n\n if (value === 'true') {\n return true\n }\n\n if (value === 'false') {\n return false\n }\n\n return value\n}\n","import type { ParseRule } from '@tiptap/pm/model'\n\nimport type { ExtensionAttribute } from '../types.js'\nimport { fromString } from '../utilities/fromString.js'\n\n/**\n * This function merges extension attributes into parserule attributes (`attrs` or `getAttrs`).\n * Cancels when `getAttrs` returned `false`.\n * @param parseRule ProseMirror ParseRule\n * @param extensionAttributes List of attributes to inject\n */\nexport function injectExtensionAttributesToParseRule(\n parseRule: ParseRule,\n extensionAttributes: ExtensionAttribute[],\n): ParseRule {\n if ('style' in parseRule) {\n return parseRule\n }\n\n return {\n ...parseRule,\n getAttrs: (node: HTMLElement) => {\n const oldAttributes = parseRule.getAttrs ? parseRule.getAttrs(node) : parseRule.attrs\n\n if (oldAttributes === false) {\n return false\n }\n\n const newAttributes = extensionAttributes.reduce((items, item) => {\n const value = item.attribute.parseHTML\n ? item.attribute.parseHTML(node)\n : fromString(node.getAttribute(item.name))\n\n if (value === null || value === undefined) {\n return items\n }\n\n return {\n ...items,\n [item.name]: value,\n }\n }, {})\n\n return { ...oldAttributes, ...newAttributes }\n },\n }\n}\n","/**\n * Find duplicates in an array.\n */\nexport function findDuplicates<T>(items: T[]): T[] {\n const filtered = items.filter((el, index) => items.indexOf(el) !== index)\n\n return Array.from(new Set(filtered))\n}\n","import type { AnyConfig, Extensions } from '../types.js'\nimport { getExtensionField } from './getExtensionField.js'\n\n/**\n * Sort extensions by priority.\n * @param extensions An array of Tiptap extensions\n * @returns A sorted array of Tiptap extensions by priority\n */\nexport function sortExtensions(extensions: Extensions): Extensions {\n const defaultPriority = 100\n\n return extensions.sort((a, b) => {\n const priorityA = getExtensionField<AnyConfig['priority']>(a, 'priority') || defaultPriority\n const priorityB = getExtensionField<AnyConfig['priority']>(b, 'priority') || defaultPriority\n\n if (priorityA > priorityB) {\n return -1\n }\n\n if (priorityA < priorityB) {\n return 1\n }\n\n return 0\n })\n}\n","import type { Extensions } from '../types.js'\nimport { findDuplicates } from '../utilities/findDuplicates.js'\nimport { flattenExtensions } from './flattenExtensions.js'\nimport { sortExtensions } from './sortExtensions.js'\n\n/**\n * Returns a flattened and sorted extension list while\n * also checking for duplicated extensions and warns the user.\n * @param extensions An array of Tiptap extensions\n * @returns An flattened and sorted array of Tiptap extensions\n */\nexport function resolveExtensions(extensions: Extensions): Extensions {\n const resolvedExtensions = sortExtensions(flattenExtensions(extensions))\n const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))\n\n if (duplicatedNames.length) {\n console.warn(\n `[tiptap warn]: Duplicate extension names found: [${duplicatedNames\n .map(item => `'${item}'`)\n .join(', ')}]. This can lead to issues.`,\n )\n }\n\n return resolvedExtensions\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { Editor } from '../Editor.js'\nimport type { Extensions } from '../types.js'\nimport { getSchemaByResolvedExtensions } from './getSchemaByResolvedExtensions.js'\nimport { resolveExtensions } from './resolveExtensions.js'\n\nexport function getSchema(extensions: Extensions, editor?: Editor): Schema {\n const resolvedExtensions = resolveExtensions(extensions)\n\n return getSchemaByResolvedExtensions(resolvedExtensions, editor)\n}\n","import { DOMParser } from '@tiptap/pm/model'\n\nimport type { Extensions } from '../types.js'\nimport { elementFromString } from '../utilities/elementFromString.js'\nimport { getSchema } from './getSchema.js'\n\n/**\n * Generate JSONContent from HTML\n * @param html The HTML to generate JSONContent from\n * @param extensions The extensions to use for the schema\n * @returns The generated JSONContent\n */\nexport function generateJSON(html: string, extensions: Extensions): Record<string, any> {\n const schema = getSchema(extensions)\n const dom = elementFromString(html)\n\n return DOMParser.fromSchema(schema).parse(dom).toJSON()\n}\n","import { Node } from '@tiptap/pm/model'\n\nimport type { Extensions, JSONContent, TextSerializer } from '../types.js'\nimport { getSchema } from './getSchema.js'\nimport { getText } from './getText.js'\nimport { getTextSerializersFromSchema } from './getTextSerializersFromSchema.js'\n\n/**\n * Generate raw text from a JSONContent\n * @param doc The JSONContent to generate text from\n * @param extensions The extensions to use for the schema\n * @param options Options for the text generation f.e. blockSeparator or textSerializers\n * @returns The generated text\n */\nexport function generateText(\n doc: JSONContent,\n extensions: Extensions,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n): string {\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n const schema = getSchema(extensions)\n const contentNode = Node.fromJSON(schema, doc)\n\n return getText(contentNode, {\n blockSeparator,\n textSerializers: {\n ...getTextSerializersFromSchema(schema),\n ...textSerializers,\n },\n })\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { Range, TextSerializer } from '../types.js'\n\n/**\n * Gets the text between two positions in a Prosemirror node\n * and serializes it using the given text serializers and block separator (see getText)\n * @param startNode The Prosemirror node to start from\n * @param range The range of the text to get\n * @param options Options for the text serializer & block separator\n * @returns The text between the two positions\n */\nexport function getTextBetween(\n startNode: ProseMirrorNode,\n range: Range,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n): string {\n const { from, to } = range\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n let text = ''\n\n startNode.nodesBetween(from, to, (node, pos, parent, index) => {\n if (node.isBlock && pos > from) {\n text += blockSeparator\n }\n\n const textSerializer = textSerializers?.[node.type.name]\n\n if (textSerializer) {\n if (parent) {\n text += textSerializer({\n node,\n pos,\n parent,\n index,\n range,\n })\n }\n // do not descend into child nodes when there exists a serializer\n return false\n }\n\n if (node.isText) {\n text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line\n }\n })\n\n return text\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { TextSerializer } from '../types.js'\nimport { getTextBetween } from './getTextBetween.js'\n\n/**\n * Gets the text of a Prosemirror node\n * @param node The Prosemirror node\n * @param options Options for the text serializer & block separator\n * @returns The text of the node\n * @example ```js\n * const text = getText(node, { blockSeparator: '\\n' })\n * ```\n */\nexport function getText(\n node: ProseMirrorNode,\n options?: {\n blockSeparator?: string\n textSerializers?: Record<string, TextSerializer>\n },\n) {\n const range = {\n from: 0,\n to: node.content.size,\n }\n\n return getTextBetween(node, range, options)\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { TextSerializer } from '../types.js'\n\n/**\n * Find text serializers `toText` in a Prosemirror schema\n * @param schema The Prosemirror schema to search in\n * @returns A record of text serializers by node name\n */\nexport function getTextSerializersFromSchema(schema: Schema): Record<string, TextSerializer> {\n return Object.fromEntries(\n Object.entries(schema.nodes)\n .filter(([, node]) => node.spec.toText)\n .map(([name, node]) => [name, node.spec.toText]),\n )\n}\n","import type { Node, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getNodeType } from './getNodeType.js'\n\nexport function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): Record<string, any> {\n const type = getNodeType(typeOrName, state.schema)\n const { from, to } = state.selection\n const nodes: Node[] = []\n\n state.doc.nodesBetween(from, to, node => {\n nodes.push(node)\n })\n\n const node = nodes.reverse().find(nodeItem => nodeItem.type.name === type.name)\n\n if (!node) {\n return {}\n }\n\n return { ...node.attrs }\n}\n","import type { MarkType, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { getMarkAttributes } from './getMarkAttributes.js'\nimport { getNodeAttributes } from './getNodeAttributes.js'\nimport { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'\n\n/**\n * Get node or mark attributes by type or name on the current editor state\n * @param state The current editor state\n * @param typeOrName The node or mark type or name\n * @returns The attributes of the node or mark or an empty object\n */\nexport function getAttributes(state: EditorState, typeOrName: string | NodeType | MarkType): Record<string, any> {\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (schemaType === 'node') {\n return getNodeAttributes(state, typeOrName as NodeType)\n }\n\n if (schemaType === 'mark') {\n return getMarkAttributes(state, typeOrName as MarkType)\n }\n\n return {}\n}\n","/**\n * Removes duplicated values within an array.\n * Supports numbers, strings and objects.\n */\nexport function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {\n const seen: Record<any, any> = {}\n\n return array.filter(item => {\n const key = by(item)\n\n return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true)\n })\n}\n","import type { Step, Transform } from '@tiptap/pm/transform'\n\nimport type { Range } from '../types.js'\nimport { removeDuplicates } from '../utilities/removeDuplicates.js'\n\nexport type ChangedRange = {\n oldRange: Range\n newRange: Range\n}\n\n/**\n * Removes duplicated ranges and ranges that are\n * fully captured by other ranges.\n */\nfunction simplifyChangedRanges(changes: ChangedRange[]): ChangedRange[] {\n const uniqueChanges = removeDuplicates(changes)\n\n return uniqueChanges.length === 1\n ? uniqueChanges\n : uniqueChanges.filter((change, index) => {\n const rest = uniqueChanges.filter((_, i) => i !== index)\n\n return !rest.some(otherChange => {\n return (\n change.oldRange.from >= otherChange.oldRange.from &&\n change.oldRange.to <= otherChange.oldRange.to &&\n change.newRange.from >= otherChange.newRange.from &&\n change.newRange.to <= otherChange.newRange.to\n )\n })\n })\n}\n\n/**\n * Returns a list of changed ranges\n * based on the first and last state of all steps.\n */\nexport function getChangedRanges(transform: Transform): ChangedRange[] {\n const { mapping, steps } = transform\n const changes: ChangedRange[] = []\n\n mapping.maps.forEach((stepMap, index) => {\n const ranges: Range[] = []\n\n // This accounts for step changes where no range was actually altered\n // e.g. when setting a mark, node attribute, etc.\n // @ts-ignore\n if (!stepMap.ranges.length) {\n const { from, to } = steps[index] as Step & {\n from?: number\n to?: number\n }\n\n if (from === undefined || to === undefined) {\n return\n }\n\n ranges.push({ from, to })\n } else {\n stepMap.forEach((from, to) => {\n ranges.push({ from, to })\n })\n }\n\n ranges.forEach(({ from, to }) => {\n const newStart = mapping.slice(index).map(from, -1)\n const newEnd = mapping.slice(index).map(to)\n const oldStart = mapping.invert().map(newStart, -1)\n const oldEnd = mapping.invert().map(newEnd)\n\n changes.push({\n oldRange: {\n from: oldStart,\n to: oldEnd,\n },\n newRange: {\n from: newStart,\n to: newEnd,\n },\n })\n })\n })\n\n return simplifyChangedRanges(changes)\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { JSONContent } from '../types.js'\n\ninterface DebugJSONContent extends JSONContent {\n from: number\n to: number\n}\n\nexport function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent {\n const isTopNode = node.type === node.type.schema.topNodeType\n const increment = isTopNode ? 0 : 1\n const from = startOffset\n const to = from + node.nodeSize\n const marks = node.marks.map(mark => {\n const output: { type: string; attrs?: Record<string, any> } = {\n type: mark.type.name,\n }\n\n if (Object.keys(mark.attrs).length) {\n output.attrs = { ...mark.attrs }\n }\n\n return output\n })\n const attrs = { ...node.attrs }\n const output: DebugJSONContent = {\n type: node.type.name,\n from,\n to,\n }\n\n if (Object.keys(attrs).length) {\n output.attrs = attrs\n }\n\n if (marks.length) {\n output.marks = marks\n }\n\n if (node.content.childCount) {\n output.content = []\n\n node.forEach((child, offset) => {\n output.content?.push(getDebugJSON(child, startOffset + offset + increment))\n })\n }\n\n if (node.text) {\n output.text = node.text\n }\n\n return output\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\nimport type { MarkRange } from '../types.js'\nimport { getMarkRange } from './getMarkRange.js'\n\nexport function getMarksBetween(from: number, to: number, doc: ProseMirrorNode): MarkRange[] {\n const marks: MarkRange[] = []\n\n // get all inclusive marks on empty selection\n if (from === to) {\n doc\n .resolve(from)\n .marks()\n .forEach(mark => {\n const $pos = doc.resolve(from)\n const range = getMarkRange($pos, mark.type)\n\n if (!range) {\n return\n }\n\n marks.push({\n mark,\n ...range,\n })\n })\n } else {\n doc.nodesBetween(from, to, (node, pos) => {\n if (!node || node?.nodeSize === undefined) {\n return\n }\n\n marks.push(\n ...node.marks.map(mark => ({\n from: pos,\n to: pos + node.nodeSize,\n mark,\n })),\n )\n })\n }\n\n return marks\n}\n","import type { Node, NodeType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\n/**\n * Finds the first node of a given type or name in the current selection.\n * @param state The editor state.\n * @param typeOrName The node type or name.\n * @param pos The position to start searching from.\n * @param maxDepth The maximum depth to search.\n * @returns The node and the depth as an array.\n */\nexport const getNodeAtPosition = (state: EditorState, typeOrName: string | NodeType, pos: number, maxDepth = 20) => {\n const $pos = state.doc.resolve(pos)\n\n let currentDepth = maxDepth\n let node: Node | null = null\n\n while (currentDepth > 0 && node === null) {\n const currentNode = $pos.node(currentDepth)\n\n if (currentNode?.type.name === typeOrName) {\n node = currentNode\n } else {\n currentDepth -= 1\n }\n }\n\n return [node, currentDepth] as [Node | null, number]\n}\n","import type { MarkType, NodeType, Schema } from '@tiptap/pm/model'\n\n/**\n * Tries to get a node or mark type by its name.\n * @param name The name of the node or mark type\n * @param schema The Prosemiror schema to search in\n * @returns The node or mark type, or null if it doesn't exist\n */\nexport function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {\n return schema.nodes[name] || schema.marks[name] || null\n}\n","import type { ExtensionAttribute } from '../types.js'\n\n/**\n * Return attributes of an extension that should be splitted by keepOnSplit flag\n * @param extensionAttributes Array of extension attributes\n * @param typeName The type of the extension\n * @param attributes The attributes of the extension\n * @returns The splitted attributes\n */\nexport function getSplittedAttributes(\n extensionAttributes: ExtensionAttribute[],\n typeName: string,\n attributes: Record<string, any>,\n): Record<string, any> {\n return Object.fromEntries(\n Object.entries(attributes).filter(([name]) => {\n const extensionAttribute = extensionAttributes.find(item => {\n return item.type === typeName && item.name === name\n })\n\n if (!extensionAttribute) {\n return false\n }\n\n return extensionAttribute.attribute.keepOnSplit\n }),\n )\n}\n","import type { ResolvedPos } from '@tiptap/pm/model'\n\n/**\n * Returns the text content of a resolved prosemirror position\n * @param $from The resolved position to get the text content from\n * @param maxMatch The maximum number of characters to match\n * @returns The text content\n */\nexport const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {\n let textBefore = ''\n\n const sliceEndPos = $from.parentOffset\n\n $from.parent.nodesBetween(Math.max(0, sliceEndPos - maxMatch), sliceEndPos, (node, pos, parent, index) => {\n const chunk =\n node.type.spec.toText?.({\n node,\n pos,\n parent,\n index,\n }) ||\n node.textContent ||\n '%leaf%'\n\n textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos))\n })\n\n return textBefore\n}\n","import type { MarkType } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport type { MarkRange } from '../types.js'\nimport { objectIncludes } from '../utilities/objectIncludes.js'\nimport { getMarkType } from './getMarkType.js'\n\nexport function isMarkActive(\n state: EditorState,\n typeOrName: MarkType | string | null,\n attributes: Record<string, any> = {},\n): boolean {\n const { empty, ranges } = state.selection\n const type = typeOrName ? getMarkType(typeOrName, state.schema) : null\n\n if (empty) {\n return !!(state.storedMarks || state.selection.$from.marks())\n .filter(mark => {\n if (!type) {\n return true\n }\n\n return type.name === mark.type.name\n })\n .find(mark => objectIncludes(mark.attrs, attributes, { strict: false }))\n }\n\n let selectionRange = 0\n const markRanges: MarkRange[] = []\n\n ranges.forEach(({ $from, $to }) => {\n const from = $from.pos\n const to = $to.pos\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isText && !node.marks.length) {\n return\n }\n\n const relativeFrom = Math.max(from, pos)\n const relativeTo = Math.min(to, pos + node.nodeSize)\n const range = relativeTo - relativeFrom\n\n selectionRange += range\n\n markRanges.push(\n ...node.marks.map(mark => ({\n mark,\n from: relativeFrom,\n to: relativeTo,\n })),\n )\n })\n })\n\n if (selectionRange === 0) {\n return false\n }\n\n // calculate range of matched mark\n const matchedRange = markRanges\n .filter(markRange => {\n if (!type) {\n return true\n }\n\n return type.name === markRange.mark.type.name\n })\n .filter(markRange => objectIncludes(markRange.mark.attrs, attributes, { strict: false }))\n .reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)\n\n // calculate range of marks that excludes the searched mark\n // for example `code` doesn’t allow any other marks\n const excludedRange = markRanges\n .filter(markRange => {\n if (!type) {\n return true\n }\n\n return markRange.mark.type !== type && markRange.mark.type.excludes(type)\n })\n .reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)\n\n // we only include the result of `excludedRange`\n // if there is a match at all\n const range = matchedRange > 0 ? matchedRange + excludedRange : matchedRange\n\n return range >= selectionRange\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nimport { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'\nimport { isMarkActive } from './isMarkActive.js'\nimport { isNodeActive } from './isNodeActive.js'\n\nexport function isActive(state: EditorState, name: string | null, attributes: Record<string, any> = {}): boolean {\n if (!name) {\n return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes)\n }\n\n const schemaType = getSchemaTypeNameByName(name, state.schema)\n\n if (schemaType === 'node') {\n return isNodeActive(state, name, attributes)\n }\n\n if (schemaType === 'mark') {\n return isMarkActive(state, name, attributes)\n }\n\n return false\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nimport { findParentNode } from './findParentNode.js'\n\nexport const isAtEndOfNode = (state: EditorState, nodeType?: string) => {\n const { $from, $to, $anchor } = state.selection\n\n if (nodeType) {\n const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection)\n\n if (!parentNode) {\n return false\n }\n\n const $parentPos = state.doc.resolve(parentNode.pos + 1)\n\n if ($anchor.pos + 1 === $parentPos.end()) {\n return true\n }\n\n return false\n }\n\n if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {\n return false\n }\n\n return true\n}\n","import type { EditorState } from '@tiptap/pm/state'\n\nexport const isAtStartOfNode = (state: EditorState) => {\n const { $from, $to } = state.selection\n\n if ($from.parentOffset > 0 || $from.pos !== $to.pos) {\n return false\n }\n\n return true\n}\n","import type { AnyExtension, EnableRules } from '../types.js'\n\nexport function isExtensionRulesEnabled(extension: AnyExtension, enabled: EnableRules): boolean {\n if (Array.isArray(enabled)) {\n return enabled.some(enabledExtension => {\n const name = typeof enabledExtension === 'string' ? enabledExtension : enabledExtension.name\n\n return name === extension.name\n })\n }\n\n return enabled\n}\n","import { getExtensionField } from '../helpers/getExtensionField.js'\nimport type { NodeConfig } from '../index.js'\nimport type { Extensions } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\nimport { splitExtensions } from './splitExtensions.js'\n\nexport function isList(name: string, extensions: Extensions): boolean {\n const { nodeExtensions } = splitExtensions(extensions)\n const extension = nodeExtensions.find(item => item.name === name)\n\n if (!extension) {\n return false\n }\n\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n const group = callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context))\n\n if (typeof group !== 'string') {\n return false\n }\n\n return group.split(' ').includes('list')\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\n\n/**\n * Returns true if the given prosemirror node is empty.\n */\nexport function isNodeEmpty(\n node: ProseMirrorNode,\n {\n checkChildren = true,\n ignoreWhitespace = false,\n }: {\n /**\n * When true (default), it will also check if all children are empty.\n */\n checkChildren?: boolean\n /**\n * When true, it will ignore whitespace when checking for emptiness.\n */\n ignoreWhitespace?: boolean\n } = {},\n): boolean {\n if (ignoreWhitespace) {\n if (node.type.name === 'hardBreak') {\n // Hard breaks are considered empty\n return true\n }\n if (node.isText) {\n return /^\\s*$/m.test(node.text ?? '')\n }\n }\n\n if (node.isText) {\n return !node.text\n }\n\n if (node.isAtom || node.isLeaf) {\n return false\n }\n\n if (node.content.childCount === 0) {\n return true\n }\n\n if (checkChildren) {\n let isContentEmpty = true\n\n node.content.forEach(childNode => {\n if (isContentEmpty === false) {\n // Exit early for perf\n return\n }\n\n if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {\n isContentEmpty = false\n }\n })\n\n return isContentEmpty\n }\n\n return false\n}\n","import { NodeSelection } from '@tiptap/pm/state'\n\nexport function isNodeSelection(value: unknown): value is NodeSelection {\n return value instanceof NodeSelection\n}\n","import type { Transaction } from '@tiptap/pm/state'\nimport type { MapResult } from '@tiptap/pm/transform'\n\n/**\n * A class that represents a mappable position in the editor. It can be extended\n * by other extensions to add additional position mapping capabilities.\n */\nexport class MappablePosition {\n /**\n * The absolute position in the editor.\n */\n public position: number\n\n constructor(position: number) {\n this.position = position\n }\n\n /**\n * Creates a MappablePosition from a JSON object.\n */\n static fromJSON(json: any): MappablePosition {\n return new MappablePosition(json.position)\n }\n\n /**\n * Converts the MappablePosition to a JSON object.\n */\n toJSON(): any {\n return {\n position: this.position,\n }\n }\n}\n\n/**\n * The result of the getUpdatedPosition function.\n */\nexport interface GetUpdatedPositionResult {\n position: MappablePosition\n mapResult: MapResult | null\n}\n\n/**\n * Calculates the new position after applying a transaction.\n *\n * @returns The new mappable position and the map result.\n */\nexport function getUpdatedPosition(position: MappablePosition, transaction: Transaction): GetUpdatedPositionResult {\n const mapResult = transaction.mapping.mapResult(position.position)\n return {\n position: new MappablePosition(mapResult.pos),\n mapResult,\n }\n}\n\n/**\n * Creates a MappablePosition from a position number. This is the default\n * implementation for Tiptap core. It can be overridden by other Tiptap\n * extensions.\n *\n * @param position The position (as a number) where the MappablePosition will be created.\n * @returns A new MappablePosition instance at the given position.\n */\nexport function createMappablePosition(position: number): MappablePosition {\n return new MappablePosition(position)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { minMax } from '../utilities/minMax.js'\n\nexport function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {\n const minPos = 0\n const maxPos = view.state.doc.content.size\n const resolvedFrom = minMax(from, minPos, maxPos)\n const resolvedEnd = minMax(to, minPos, maxPos)\n const start = view.coordsAtPos(resolvedFrom)\n const end = view.coordsAtPos(resolvedEnd, -1)\n const top = Math.min(start.top, end.top)\n const bottom = Math.max(start.bottom, end.bottom)\n const left = Math.min(start.left, end.left)\n const right = Math.max(start.right, end.right)\n const width = right - left\n const height = bottom - top\n const x = left\n const y = top\n const data = {\n top,\n bottom,\n left,\n right,\n width,\n height,\n x,\n y,\n }\n\n return {\n ...data,\n toJSON: () => data,\n }\n}\n","import type { Schema } from '@tiptap/pm/model'\n\nimport type { JSONContent } from '../types.js'\n\ntype RewriteUnknownContentOptions = {\n /**\n * If true, unknown nodes will be treated as paragraphs\n * @default true\n */\n fallbackToParagraph?: boolean\n}\n\ntype RewrittenContent = {\n /**\n * The original JSON content that was rewritten\n */\n original: JSONContent\n /**\n * The name of the node or mark that was unsupported\n */\n unsupported: string\n}[]\n\n/**\n * The actual implementation of the rewriteUnknownContent function\n */\nfunction rewriteUnknownContentInner({\n json,\n validMarks,\n validNodes,\n options,\n rewrittenContent = [],\n}: {\n json: JSONContent\n validMarks: Set<string>\n validNodes: Set<string>\n options?: RewriteUnknownContentOptions\n rewrittenContent?: RewrittenContent\n}): {\n /**\n * The cleaned JSON content\n */\n json: JSONContent | null\n /**\n * The array of nodes and marks that were rewritten\n */\n rewrittenContent: RewrittenContent\n} {\n if (json.marks && Array.isArray(json.marks)) {\n json.marks = json.marks.filter(mark => {\n const name = typeof mark === 'string' ? mark : mark.type\n\n if (validMarks.has(name)) {\n return true\n }\n\n rewrittenContent.push({\n original: JSON.parse(JSON.stringify(mark)),\n unsupported: name,\n })\n // Just ignore any unknown marks\n return false\n })\n }\n\n if (json.content && Array.isArray(json.content)) {\n json.content = json.content\n .map(\n value =>\n rewriteUnknownContentInner({\n json: value,\n validMarks,\n validNodes,\n options,\n rewrittenContent,\n }).json,\n )\n .filter(a => a !== null && a !== undefined)\n }\n\n if (json.type && !validNodes.has(json.type)) {\n rewrittenContent.push({\n original: JSON.parse(JSON.stringify(json)),\n unsupported: json.type,\n })\n\n if (json.content && Array.isArray(json.content) && options?.fallbackToParagraph !== false) {\n // Just treat it like a paragraph and hope for the best\n json.type = 'paragraph'\n\n return {\n json,\n rewrittenContent,\n }\n }\n\n // or just omit it entirely\n return {\n json: null,\n rewrittenContent,\n }\n }\n\n return { json, rewrittenContent }\n}\n\n/**\n * Rewrite unknown nodes and marks within JSON content\n * Allowing for user within the editor\n */\nexport function rewriteUnknownContent(\n /**\n * The JSON content to clean of unknown nodes and marks\n */\n json: JSONContent,\n /**\n * The schema to use for validation\n */\n schema: Schema,\n /**\n * Options for the cleaning process\n */\n options?: RewriteUnknownContentOptions,\n): {\n /**\n * The cleaned JSON content\n */\n json: JSONContent | null\n /**\n * The array of nodes and marks that were rewritten\n */\n rewrittenContent: {\n /**\n * The original JSON content that was rewritten\n */\n original: JSONContent\n /**\n * The name of the node or mark that was unsupported\n */\n unsupported: string\n }[]\n} {\n return rewriteUnknownContentInner({\n json,\n validNodes: new Set(Object.keys(schema.nodes)),\n validMarks: new Set(Object.keys(schema.marks)),\n options,\n })\n}\n","import type { MarkType, ResolvedPos } from '@tiptap/pm/model'\nimport type { EditorState, Transaction } from '@tiptap/pm/state'\n\nimport { getMarkAttributes } from '../helpers/getMarkAttributes.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { isTextSelection } from '../helpers/index.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setMark: {\n /**\n * Add a mark with new attributes.\n * @param typeOrName The mark type or name.\n * @example editor.commands.setMark('bold', { level: 1 })\n */\n setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nfunction canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType) {\n const { selection } = tr\n let cursor: ResolvedPos | null = null\n\n if (isTextSelection(selection)) {\n cursor = selection.$cursor\n }\n\n if (cursor) {\n const currentMarks = state.storedMarks ?? cursor.marks()\n const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType)\n\n // There can be no current marks that exclude the new mark, and the parent must allow this mark type\n return (\n parentAllowsMarkType &&\n (!!newMarkType.isInSet(currentMarks) || !currentMarks.some(mark => mark.type.excludes(newMarkType)))\n )\n }\n\n const { ranges } = selection\n\n return ranges.some(({ $from, $to }) => {\n let someNodeSupportsMark =\n $from.depth === 0 ? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType) : false\n\n state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => {\n // If we already found a mark that we can enable, return false to bypass the remaining search\n if (someNodeSupportsMark) {\n return false\n }\n\n if (node.isInline) {\n const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType)\n const currentMarksAllowMarkType =\n !!newMarkType.isInSet(node.marks) || !node.marks.some(otherMark => otherMark.type.excludes(newMarkType))\n\n someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType\n }\n return !someNodeSupportsMark\n })\n\n return someNodeSupportsMark\n })\n}\nexport const setMark: RawCommands['setMark'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n const { selection } = tr\n const { empty, ranges } = selection\n const type = getMarkType(typeOrName, state.schema)\n\n if (dispatch) {\n if (empty) {\n const oldAttributes = getMarkAttributes(state, type)\n\n tr.addStoredMark(\n type.create({\n ...oldAttributes,\n ...attributes,\n }),\n )\n } else {\n ranges.forEach(range => {\n const from = range.$from.pos\n const to = range.$to.pos\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n const trimmedFrom = Math.max(pos, from)\n const trimmedTo = Math.min(pos + node.nodeSize, to)\n const someHasMark = node.marks.find(mark => mark.type === type)\n\n // if there is already a mark of this type\n // we know that we have to merge its attributes\n // otherwise we add a fresh new mark\n if (someHasMark) {\n node.marks.forEach(mark => {\n if (type === mark.type) {\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n type.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n })\n } else {\n tr.addMark(trimmedFrom, trimmedTo, type.create(attributes))\n }\n })\n })\n }\n }\n\n return canSetMark(state, tr, type)\n }\n","import type { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setMeta: {\n /**\n * Store a metadata property in the current transaction.\n * @param key The key of the metadata property.\n * @param value The value to store.\n * @example editor.commands.setMeta('foo', 'bar')\n */\n setMeta: (key: string | Plugin | PluginKey, value: any) => ReturnType\n }\n }\n}\n\nexport const setMeta: RawCommands['setMeta'] =\n (key, value) =>\n ({ tr }) => {\n tr.setMeta(key, value)\n\n return true\n }\n","import { setBlockType } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setNode: {\n /**\n * Replace a given range with a node.\n * @param typeOrName The type or name of the node\n * @param attributes The attributes of the node\n * @example editor.commands.setNode('paragraph')\n */\n setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const setNode: RawCommands['setNode'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch, chain }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n let attributesToCopy: Record<string, any> | undefined\n\n if (state.selection.$anchor.sameParent(state.selection.$head)) {\n // only copy attributes if the selection is pointing to a node of the same type\n attributesToCopy = state.selection.$anchor.parent.attrs\n }\n\n // TODO: use a fallback like insertContent?\n if (!type.isTextblock) {\n console.warn('[tiptap warn]: Currently \"setNode()\" only supports text block nodes.')\n\n return false\n }\n\n return (\n chain()\n // try to convert node to default node if needed\n .command(({ commands }) => {\n const canSetBlock = setBlockType(type, { ...attributesToCopy, ...attributes })(state)\n\n if (canSetBlock) {\n return true\n }\n\n return commands.clearNodes()\n })\n .command(({ state: updatedState }) => {\n return setBlockType(type, { ...attributesToCopy, ...attributes })(updatedState, dispatch)\n })\n .run()\n )\n }\n","import { NodeSelection } from '@tiptap/pm/state'\n\nimport type { RawCommands } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setNodeSelection: {\n /**\n * Creates a NodeSelection.\n * @param position - Position of the node.\n * @example editor.commands.setNodeSelection(10)\n */\n setNodeSelection: (position: number) => ReturnType\n }\n }\n}\n\nexport const setNodeSelection: RawCommands['setNodeSelection'] =\n position =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const { doc } = tr\n const from = minMax(position, 0, doc.content.size)\n const selection = NodeSelection.create(doc, from)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setTextDirection: {\n /**\n * Set the text direction for nodes.\n * If no position is provided, it will use the current selection.\n * @param direction The text direction to set ('ltr', 'rtl', or 'auto')\n * @param position Optional position or range to apply the direction to\n * @example editor.commands.setTextDirection('rtl')\n * @example editor.commands.setTextDirection('ltr', { from: 0, to: 10 })\n */\n setTextDirection: (direction: 'ltr' | 'rtl' | 'auto', position?: number | Range) => ReturnType\n }\n }\n}\n\nexport const setTextDirection: RawCommands['setTextDirection'] =\n (direction, position) =>\n ({ tr, state, dispatch }) => {\n const { selection } = state\n let from: number\n let to: number\n\n if (typeof position === 'number') {\n from = position\n to = position\n } else if (position && 'from' in position && 'to' in position) {\n from = position.from\n to = position.to\n } else {\n from = selection.from\n to = selection.to\n }\n\n if (dispatch) {\n tr.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n dir: direction,\n })\n })\n }\n\n return true\n }\n","import { TextSelection } from '@tiptap/pm/state'\n\nimport type { Range, RawCommands } from '../types.js'\nimport { minMax } from '../utilities/minMax.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n setTextSelection: {\n /**\n * Creates a TextSelection.\n * @param position The position of the selection.\n * @example editor.commands.setTextSelection(10)\n */\n setTextSelection: (position: number | Range) => ReturnType\n }\n }\n}\n\nexport const setTextSelection: RawCommands['setTextSelection'] =\n position =>\n ({ tr, dispatch }) => {\n if (dispatch) {\n const { doc } = tr\n const { from, to } = typeof position === 'number' ? { from: position, to: position } : position\n const minPos = TextSelection.atStart(doc).from\n const maxPos = TextSelection.atEnd(doc).to\n const resolvedFrom = minMax(from, minPos, maxPos)\n const resolvedEnd = minMax(to, minPos, maxPos)\n const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)\n\n tr.setSelection(selection)\n }\n\n return true\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { sinkListItem as originalSinkListItem } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n sinkListItem: {\n /**\n * Sink the list item down into an inner list.\n * @param typeOrName The type or name of the node.\n * @example editor.commands.sinkListItem('listItem')\n */\n sinkListItem: (typeOrName: string | NodeType) => ReturnType\n }\n }\n}\n\nexport const sinkListItem: RawCommands['sinkListItem'] =\n typeOrName =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalSinkListItem(type)(state, dispatch)\n }\n","import type { EditorState } from '@tiptap/pm/state'\nimport { NodeSelection, TextSelection } from '@tiptap/pm/state'\nimport { canSplit } from '@tiptap/pm/transform'\n\nimport { defaultBlockAt } from '../helpers/defaultBlockAt.js'\nimport { getSplittedAttributes } from '../helpers/getSplittedAttributes.js'\nimport type { RawCommands } from '../types.js'\n\nfunction ensureMarks(state: EditorState, splittableMarks?: string[]) {\n const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks())\n\n if (marks) {\n const filteredMarks = marks.filter(mark => splittableMarks?.includes(mark.type.name))\n\n state.tr.ensureMarks(filteredMarks)\n }\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n splitBlock: {\n /**\n * Forks a new node from an existing node.\n * @param options.keepMarks Keep marks from the previous node.\n * @example editor.commands.splitBlock()\n * @example editor.commands.splitBlock({ keepMarks: true })\n */\n splitBlock: (options?: { keepMarks?: boolean }) => ReturnType\n }\n }\n}\n\nexport const splitBlock: RawCommands['splitBlock'] =\n ({ keepMarks = true } = {}) =>\n ({ tr, state, dispatch, editor }) => {\n const { selection, doc } = tr\n const { $from, $to } = selection\n const extensionAttributes = editor.extensionManager.attributes\n const newAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs)\n\n if (selection instanceof NodeSelection && selection.node.isBlock) {\n if (!$from.parentOffset || !canSplit(doc, $from.pos)) {\n return false\n }\n\n if (dispatch) {\n if (keepMarks) {\n ensureMarks(state, editor.extensionManager.splittableMarks)\n }\n\n tr.split($from.pos).scrollIntoView()\n }\n\n return true\n }\n\n if (!$from.parent.isBlock) {\n return false\n }\n\n const atEnd = $to.parentOffset === $to.parent.content.size\n\n const deflt = $from.depth === 0 ? undefined : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))\n\n let types =\n atEnd && deflt\n ? [\n {\n type: deflt,\n attrs: newAttributes,\n },\n ]\n : undefined\n\n let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)\n\n if (!types && !can && canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {\n can = true\n types = deflt\n ? [\n {\n type: deflt,\n attrs: newAttributes,\n },\n ]\n : undefined\n }\n\n if (dispatch) {\n if (can) {\n if (selection instanceof TextSelection) {\n tr.deleteSelection()\n }\n\n tr.split(tr.mapping.map($from.pos), 1, types)\n\n if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {\n const first = tr.mapping.map($from.before())\n const $first = tr.doc.resolve(first)\n\n if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) {\n tr.setNodeMarkup(tr.mapping.map($from.before()), deflt)\n }\n }\n }\n\n if (keepMarks) {\n ensureMarks(state, editor.extensionManager.splittableMarks)\n }\n\n tr.scrollIntoView()\n }\n\n return can\n }\n","import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'\nimport { Fragment, Slice } from '@tiptap/pm/model'\nimport { TextSelection } from '@tiptap/pm/state'\nimport { canSplit } from '@tiptap/pm/transform'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSplittedAttributes } from '../helpers/getSplittedAttributes.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n splitListItem: {\n /**\n * Splits one list item into two list items.\n * @param typeOrName The type or name of the node.\n * @param overrideAttrs The attributes to ensure on the new node.\n * @example editor.commands.splitListItem('listItem')\n */\n splitListItem: (typeOrName: string | NodeType, overrideAttrs?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const splitListItem: RawCommands['splitListItem'] =\n (typeOrName, overrideAttrs = {}) =>\n ({ tr, state, dispatch, editor }) => {\n const type = getNodeType(typeOrName, state.schema)\n const { $from, $to } = state.selection\n\n // @ts-ignore\n // eslint-disable-next-line\n const node: ProseMirrorNode = state.selection.node\n\n if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) {\n return false\n }\n\n const grandParent = $from.node(-1)\n\n if (grandParent.type !== type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes\n\n if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {\n // In an empty block. If this is a nested list, the wrapping\n // list item should be split. Otherwise, bail out and let next\n // command handle lifting.\n if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) {\n return false\n }\n\n if (dispatch) {\n let wrap = Fragment.empty\n // eslint-disable-next-line\n const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3\n\n // Build a fragment containing empty versions of the structure\n // from the outer list item to the parent node of the cursor\n for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) {\n wrap = Fragment.from($from.node(d).copy(wrap))\n }\n\n const depthAfter =\n // eslint-disable-next-line no-nested-ternary\n $from.indexAfter(-1) < $from.node(-2).childCount\n ? 1\n : $from.indexAfter(-2) < $from.node(-3).childCount\n ? 2\n : 3\n\n // Add a second list item with an empty default start node\n const newNextTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),\n ...overrideAttrs,\n }\n const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined\n\n wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined))\n\n const start = $from.before($from.depth - (depthBefore - 1))\n\n tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0))\n\n let sel = -1\n\n tr.doc.nodesBetween(start, tr.doc.content.size, (n, pos) => {\n if (sel > -1) {\n return false\n }\n\n if (n.isTextblock && n.content.size === 0) {\n sel = pos + 1\n }\n })\n\n if (sel > -1) {\n tr.setSelection(TextSelection.near(tr.doc.resolve(sel)))\n }\n\n tr.scrollIntoView()\n }\n\n return true\n }\n\n const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null\n\n const newTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),\n ...overrideAttrs,\n }\n const newNextTypeAttributes = {\n ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),\n ...overrideAttrs,\n }\n\n tr.delete($from.pos, $to.pos)\n\n const types = nextType\n ? [\n { type, attrs: newTypeAttributes },\n { type: nextType, attrs: newNextTypeAttributes },\n ]\n : [{ type, attrs: newTypeAttributes }]\n\n if (!canSplit(tr.doc, $from.pos, 2)) {\n return false\n }\n\n if (dispatch) {\n const { selection, storedMarks } = state\n const { splittableMarks } = editor.extensionManager\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n tr.split($from.pos, 2, types).scrollIntoView()\n\n if (!marks || !dispatch) {\n return true\n }\n\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n }\n\n return true\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { canJoin } from '@tiptap/pm/transform'\n\nimport { findParentNode } from '../helpers/findParentNode.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isList } from '../helpers/isList.js'\nimport type { RawCommands } from '../types.js'\n\nconst joinListBackwards = (tr: Transaction, listType: NodeType): boolean => {\n const list = findParentNode(node => node.type === listType)(tr.selection)\n\n if (!list) {\n return true\n }\n\n const before = tr.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth)\n\n if (before === undefined) {\n return true\n }\n\n const nodeBefore = tr.doc.nodeAt(before)\n const canJoinBackwards = list.node.type === nodeBefore?.type && canJoin(tr.doc, list.pos)\n\n if (!canJoinBackwards) {\n return true\n }\n\n tr.join(list.pos)\n\n return true\n}\n\nconst joinListForwards = (tr: Transaction, listType: NodeType): boolean => {\n const list = findParentNode(node => node.type === listType)(tr.selection)\n\n if (!list) {\n return true\n }\n\n const after = tr.doc.resolve(list.start).after(list.depth)\n\n if (after === undefined) {\n return true\n }\n\n const nodeAfter = tr.doc.nodeAt(after)\n const canJoinForwards = list.node.type === nodeAfter?.type && canJoin(tr.doc, after)\n\n if (!canJoinForwards) {\n return true\n }\n\n tr.join(after)\n\n return true\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleList: {\n /**\n * Toggle between different list types.\n * @param listTypeOrName The type or name of the list.\n * @param itemTypeOrName The type or name of the list item.\n * @param keepMarks Keep marks when toggling.\n * @param attributes Attributes for the new list.\n * @example editor.commands.toggleList('bulletList', 'listItem')\n */\n toggleList: (\n listTypeOrName: string | NodeType,\n itemTypeOrName: string | NodeType,\n keepMarks?: boolean,\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const toggleList: RawCommands['toggleList'] =\n (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>\n ({ editor, tr, state, dispatch, chain, commands, can }) => {\n const { extensions, splittableMarks } = editor.extensionManager\n const listType = getNodeType(listTypeOrName, state.schema)\n const itemType = getNodeType(itemTypeOrName, state.schema)\n const { selection, storedMarks } = state\n const { $from, $to } = selection\n const range = $from.blockRange($to)\n\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n if (!range) {\n return false\n }\n\n const parentList = findParentNode(node => isList(node.type.name, extensions))(selection)\n\n if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {\n // remove list\n if (parentList.node.type === listType) {\n return commands.liftListItem(itemType)\n }\n\n // change list type\n if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {\n return chain()\n .command(() => {\n tr.setNodeMarkup(parentList.pos, listType)\n\n return true\n })\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n }\n }\n if (!keepMarks || !marks || !dispatch) {\n return (\n chain()\n // try to convert node to default node if needed\n .command(() => {\n const canWrapInList = can().wrapInList(listType, attributes)\n\n if (canWrapInList) {\n return true\n }\n\n return commands.clearNodes()\n })\n .wrapInList(listType, attributes)\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n )\n }\n\n return (\n chain()\n // try to convert node to default node if needed\n .command(() => {\n const canWrapInList = can().wrapInList(listType, attributes)\n\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n\n if (canWrapInList) {\n return true\n }\n\n return commands.clearNodes()\n })\n .wrapInList(listType, attributes)\n .command(() => joinListBackwards(tr, listType))\n .command(() => joinListForwards(tr, listType))\n .run()\n )\n }\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { isMarkActive } from '../helpers/isMarkActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleMark: {\n /**\n * Toggle a mark on and off.\n * @param typeOrName The mark type or name.\n * @param attributes The attributes of the mark.\n * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.\n * @example editor.commands.toggleMark('bold')\n */\n toggleMark: (\n /**\n * The mark type or name.\n */\n typeOrName: string | MarkType,\n\n /**\n * The attributes of the mark.\n */\n attributes?: Record<string, any>,\n\n options?: {\n /**\n * Removes the mark even across the current selection. Defaults to `false`.\n */\n extendEmptyMarkRange?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const toggleMark: RawCommands['toggleMark'] =\n (typeOrName, attributes = {}, options = {}) =>\n ({ state, commands }) => {\n const { extendEmptyMarkRange = false } = options\n const type = getMarkType(typeOrName, state.schema)\n const isActive = isMarkActive(state, type, attributes)\n\n if (isActive) {\n return commands.unsetMark(type, { extendEmptyMarkRange })\n }\n\n return commands.setMark(type, attributes)\n }\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleNode: {\n /**\n * Toggle a node with another node.\n * @param typeOrName The type or name of the node.\n * @param toggleTypeOrName The type or name of the node to toggle.\n * @param attributes The attributes of the node.\n * @example editor.commands.toggleNode('heading', 'paragraph')\n */\n toggleNode: (\n typeOrName: string | NodeType,\n toggleTypeOrName: string | NodeType,\n attributes?: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const toggleNode: RawCommands['toggleNode'] =\n (typeOrName, toggleTypeOrName, attributes = {}) =>\n ({ state, commands }) => {\n const type = getNodeType(typeOrName, state.schema)\n const toggleType = getNodeType(toggleTypeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n let attributesToCopy: Record<string, any> | undefined\n\n if (state.selection.$anchor.sameParent(state.selection.$head)) {\n // only copy attributes if the selection is pointing to a node of the same type\n attributesToCopy = state.selection.$anchor.parent.attrs\n }\n\n if (isActive) {\n return commands.setNode(toggleType, attributesToCopy)\n }\n\n // If the node is not active, we want to set the new node type with the given attributes\n // Copying over the attributes from the current node if the selection is pointing to a node of the same type\n return commands.setNode(type, { ...attributesToCopy, ...attributes })\n }\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { isNodeActive } from '../helpers/isNodeActive.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n toggleWrap: {\n /**\n * Wraps nodes in another node, or removes an existing wrap.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.toggleWrap('blockquote')\n */\n toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const toggleWrap: RawCommands['toggleWrap'] =\n (typeOrName, attributes = {}) =>\n ({ state, commands }) => {\n const type = getNodeType(typeOrName, state.schema)\n const isActive = isNodeActive(state, type, attributes)\n\n if (isActive) {\n return commands.lift(type)\n }\n\n return commands.wrapIn(type, attributes)\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoInputRule: {\n /**\n * Undo an input rule.\n * @example editor.commands.undoInputRule()\n */\n undoInputRule: () => ReturnType\n }\n }\n}\n\nexport const undoInputRule: RawCommands['undoInputRule'] =\n () =>\n ({ state, dispatch }) => {\n const plugins = state.plugins\n\n for (let i = 0; i < plugins.length; i += 1) {\n const plugin = plugins[i]\n let undoable\n\n // @ts-ignore\n // eslint-disable-next-line\n if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {\n if (dispatch) {\n const tr = state.tr\n const toUndo = undoable.transform\n\n for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {\n tr.step(toUndo.steps[j].invert(toUndo.docs[j]))\n }\n\n if (undoable.text) {\n const marks = tr.doc.resolve(undoable.from).marks()\n\n tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))\n } else {\n tr.delete(undoable.from, undoable.to)\n }\n }\n\n return true\n }\n }\n\n return false\n }\n","import type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetAllMarks: {\n /**\n * Remove all marks in the current selection.\n * @example editor.commands.unsetAllMarks()\n */\n unsetAllMarks: () => ReturnType\n }\n }\n}\n\nexport const unsetAllMarks: RawCommands['unsetAllMarks'] =\n () =>\n ({ tr, dispatch }) => {\n const { selection } = tr\n const { empty, ranges } = selection\n\n if (empty) {\n return true\n }\n\n if (dispatch) {\n ranges.forEach(range => {\n tr.removeMark(range.$from.pos, range.$to.pos)\n })\n }\n\n return true\n }\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarkRange } from '../helpers/getMarkRange.js'\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetMark: {\n /**\n * Remove all marks in the current selection.\n * @param typeOrName The mark type or name.\n * @param options.extendEmptyMarkRange Removes the mark even across the current selection. Defaults to `false`.\n * @example editor.commands.unsetMark('bold')\n */\n unsetMark: (\n /**\n * The mark type or name.\n */\n typeOrName: string | MarkType,\n\n options?: {\n /**\n * Removes the mark even across the current selection. Defaults to `false`.\n */\n extendEmptyMarkRange?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\nexport const unsetMark: RawCommands['unsetMark'] =\n (typeOrName, options = {}) =>\n ({ tr, state, dispatch }) => {\n const { extendEmptyMarkRange = false } = options\n const { selection } = tr\n const type = getMarkType(typeOrName, state.schema)\n const { $from, empty, ranges } = selection\n\n if (!dispatch) {\n return true\n }\n\n if (empty && extendEmptyMarkRange) {\n let { from, to } = selection\n const attrs = $from.marks().find(mark => mark.type === type)?.attrs\n const range = getMarkRange($from, type, attrs)\n\n if (range) {\n from = range.from\n to = range.to\n }\n\n tr.removeMark(from, to, type)\n } else {\n ranges.forEach(range => {\n tr.removeMark(range.$from.pos, range.$to.pos, type)\n })\n }\n\n tr.removeStoredMark(type)\n\n return true\n }\n","import type { Range, RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n unsetTextDirection: {\n /**\n * Remove the text direction attribute from nodes.\n * If no position is provided, it will use the current selection.\n * @param position Optional position or range to remove the direction from\n * @example editor.commands.unsetTextDirection()\n * @example editor.commands.unsetTextDirection({ from: 0, to: 10 })\n */\n unsetTextDirection: (position?: number | Range) => ReturnType\n }\n }\n}\n\nexport const unsetTextDirection: RawCommands['unsetTextDirection'] =\n position =>\n ({ tr, state, dispatch }) => {\n const { selection } = state\n let from: number\n let to: number\n\n if (typeof position === 'number') {\n from = position\n to = position\n } else if (position && 'from' in position && 'to' in position) {\n from = position.from\n to = position.to\n } else {\n from = selection.from\n to = selection.to\n }\n\n if (dispatch) {\n tr.doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n return\n }\n\n const newAttrs = { ...node.attrs }\n\n delete newAttrs.dir\n\n tr.setNodeMarkup(pos, undefined, newAttrs)\n })\n }\n\n return true\n }\n","import type { Mark, MarkType, Node, NodeType } from '@tiptap/pm/model'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { getMarkType } from '../helpers/getMarkType.js'\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n updateAttributes: {\n /**\n * Update attributes of a node or mark.\n * @param typeOrName The type or name of the node or mark.\n * @param attributes The attributes of the node or mark.\n * @example editor.commands.updateAttributes('mention', { userId: \"2\" })\n */\n updateAttributes: (\n /**\n * The type or name of the node or mark.\n */\n typeOrName: string | NodeType | MarkType,\n\n /**\n * The attributes of the node or mark.\n */\n attributes: Record<string, any>,\n ) => ReturnType\n }\n }\n}\n\nexport const updateAttributes: RawCommands['updateAttributes'] =\n (typeOrName, attributes = {}) =>\n ({ tr, state, dispatch }) => {\n let nodeType: NodeType | null = null\n let markType: MarkType | null = null\n\n const schemaType = getSchemaTypeNameByName(\n typeof typeOrName === 'string' ? typeOrName : typeOrName.name,\n state.schema,\n )\n\n if (!schemaType) {\n return false\n }\n\n if (schemaType === 'node') {\n nodeType = getNodeType(typeOrName as NodeType, state.schema)\n }\n\n if (schemaType === 'mark') {\n markType = getMarkType(typeOrName as MarkType, state.schema)\n }\n\n let canUpdate = false\n\n tr.selection.ranges.forEach((range: SelectionRange) => {\n const from = range.$from.pos\n const to = range.$to.pos\n\n let lastPos: number | undefined\n let lastNode: Node | undefined\n let trimmedFrom: number\n let trimmedTo: number\n\n if (tr.selection.empty) {\n state.doc.nodesBetween(from, to, (node: Node, pos: number) => {\n if (nodeType && nodeType === node.type) {\n canUpdate = true\n trimmedFrom = Math.max(pos, from)\n trimmedTo = Math.min(pos + node.nodeSize, to)\n lastPos = pos\n lastNode = node\n }\n })\n } else {\n state.doc.nodesBetween(from, to, (node: Node, pos: number) => {\n if (pos < from && nodeType && nodeType === node.type) {\n canUpdate = true\n trimmedFrom = Math.max(pos, from)\n trimmedTo = Math.min(pos + node.nodeSize, to)\n lastPos = pos\n lastNode = node\n }\n\n if (pos >= from && pos <= to) {\n if (nodeType && nodeType === node.type) {\n canUpdate = true\n\n if (dispatch) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n ...attributes,\n })\n }\n }\n\n if (markType && node.marks.length) {\n node.marks.forEach((mark: Mark) => {\n if (markType === mark.type) {\n canUpdate = true\n\n if (dispatch) {\n const trimmedFrom2 = Math.max(pos, from)\n const trimmedTo2 = Math.min(pos + node.nodeSize, to)\n\n tr.addMark(\n trimmedFrom2,\n trimmedTo2,\n markType.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n }\n })\n }\n }\n })\n }\n\n if (lastNode) {\n if (lastPos !== undefined && dispatch) {\n tr.setNodeMarkup(lastPos, undefined, {\n ...lastNode.attrs,\n ...attributes,\n })\n }\n\n if (markType && lastNode.marks.length) {\n lastNode.marks.forEach((mark: Mark) => {\n if (markType === mark.type && dispatch) {\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n markType.create({\n ...mark.attrs,\n ...attributes,\n }),\n )\n }\n })\n }\n }\n })\n\n return canUpdate\n }\n","import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'\nimport type { NodeType } from '@tiptap/pm/model'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n wrapIn: {\n /**\n * Wraps nodes in another node.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.wrapIn('blockquote')\n */\n wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const wrapIn: RawCommands['wrapIn'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalWrapIn(type, attributes)(state, dispatch)\n }\n","import type { NodeType } from '@tiptap/pm/model'\nimport { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'\n\nimport { getNodeType } from '../helpers/getNodeType.js'\nimport type { RawCommands } from '../types.js'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n wrapInList: {\n /**\n * Wrap a node in a list.\n * @param typeOrName The type or name of the node.\n * @param attributes The attributes of the node.\n * @example editor.commands.wrapInList('bulletList')\n */\n wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType\n }\n }\n}\n\nexport const wrapInList: RawCommands['wrapInList'] =\n (typeOrName, attributes = {}) =>\n ({ state, dispatch }) => {\n const type = getNodeType(typeOrName, state.schema)\n\n return originalWrapInList(type, attributes)(state, dispatch)\n }\n","/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport type { MarkType, Node as ProseMirrorNode, NodeType, Schema } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey, Transaction } from '@tiptap/pm/state'\nimport { EditorState } from '@tiptap/pm/state'\nimport { EditorView } from '@tiptap/pm/view'\n\nimport { CommandManager } from './CommandManager.js'\nimport { EventEmitter } from './EventEmitter.js'\nimport { ExtensionManager } from './ExtensionManager.js'\nimport {\n ClipboardTextSerializer,\n Commands,\n Delete,\n Drop,\n Editable,\n FocusEvents,\n Keymap,\n Paste,\n Tabindex,\n TextDirection,\n} from './extensions/index.js'\nimport { createDocument } from './helpers/createDocument.js'\nimport { getAttributes } from './helpers/getAttributes.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport { getText } from './helpers/getText.js'\nimport { getTextSerializersFromSchema } from './helpers/getTextSerializersFromSchema.js'\nimport { isActive } from './helpers/isActive.js'\nimport { isNodeEmpty } from './helpers/isNodeEmpty.js'\nimport { createMappablePosition, getUpdatedPosition } from './helpers/MappablePosition.js'\nimport { resolveFocusPosition } from './helpers/resolveFocusPosition.js'\nimport type { Storage } from './index.js'\nimport { NodePos } from './NodePos.js'\nimport { style } from './style.js'\nimport type {\n CanCommands,\n ChainedCommands,\n DocumentType,\n EditorEvents,\n EditorOptions,\n NodeType as TNodeType,\n SingleCommands,\n TextSerializer,\n TextType as TTextType,\n Utils,\n} from './types.js'\nimport { createStyleTag } from './utilities/createStyleTag.js'\nimport { isFunction } from './utilities/isFunction.js'\n\nexport * as extensions from './extensions/index.js'\n\n// @ts-ignore\nexport interface TiptapEditorHTMLElement extends HTMLElement {\n editor?: Editor\n}\n\nexport class Editor extends EventEmitter<EditorEvents> {\n private commandManager!: CommandManager\n\n public extensionManager!: ExtensionManager\n\n private css: HTMLStyleElement | null = null\n\n private className = 'tiptap'\n\n public schema!: Schema\n\n private editorView: EditorView | null = null\n\n public isFocused = false\n\n private editorState!: EditorState\n\n /**\n * The editor is considered initialized after the `create` event has been emitted.\n */\n public isInitialized = false\n\n public extensionStorage: Storage = {} as Storage\n\n /**\n * A unique ID for this editor instance.\n */\n public instanceId = Math.random().toString(36).slice(2, 9)\n\n public options: EditorOptions = {\n element: typeof document !== 'undefined' ? document.createElement('div') : null,\n content: '',\n injectCSS: true,\n injectNonce: undefined,\n extensions: [],\n autofocus: false,\n editable: true,\n textDirection: undefined,\n editorProps: {},\n parseOptions: {},\n coreExtensionOptions: {},\n enableInputRules: true,\n enablePasteRules: true,\n enableCoreExtensions: true,\n enableContentCheck: false,\n emitContentError: false,\n onBeforeCreate: () => null,\n onCreate: () => null,\n onMount: () => null,\n onUnmount: () => null,\n onUpdate: () => null,\n onSelectionUpdate: () => null,\n onTransaction: () => null,\n onFocus: () => null,\n onBlur: () => null,\n onDestroy: () => null,\n onContentError: ({ error }) => {\n throw error\n },\n onPaste: () => null,\n onDrop: () => null,\n onDelete: () => null,\n enableExtensionDispatchTransaction: true,\n }\n\n constructor(options: Partial<EditorOptions> = {}) {\n super()\n this.setOptions(options)\n this.createExtensionManager()\n this.createCommandManager()\n this.createSchema()\n this.on('beforeCreate', this.options.onBeforeCreate)\n this.emit('beforeCreate', { editor: this })\n this.on('mount', this.options.onMount)\n this.on('unmount', this.options.onUnmount)\n this.on('contentError', this.options.onContentError)\n this.on('create', this.options.onCreate)\n this.on('update', this.options.onUpdate)\n this.on('selectionUpdate', this.options.onSelectionUpdate)\n this.on('transaction', this.options.onTransaction)\n this.on('focus', this.options.onFocus)\n this.on('blur', this.options.onBlur)\n this.on('destroy', this.options.onDestroy)\n this.on('drop', ({ event, slice, moved }) => this.options.onDrop(event, slice, moved))\n this.on('paste', ({ event, slice }) => this.options.onPaste(event, slice))\n this.on('delete', this.options.onDelete)\n\n const initialDoc = this.createDoc()\n const selection = resolveFocusPosition(initialDoc, this.options.autofocus)\n\n // Set editor state immediately, so that it's available independently from the view\n this.editorState = EditorState.create({\n doc: initialDoc,\n schema: this.schema,\n selection: selection || undefined,\n })\n\n if (this.options.element) {\n this.mount(this.options.element)\n }\n }\n\n /**\n * Attach the editor to the DOM, creating a new editor view.\n */\n public mount(el: NonNullable<EditorOptions['element']> & {}) {\n if (typeof document === 'undefined') {\n throw new Error(\n `[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`,\n )\n }\n this.createView(el)\n this.emit('mount', { editor: this })\n\n if (this.css && !document.head.contains(this.css)) {\n document.head.appendChild(this.css)\n }\n\n window.setTimeout(() => {\n if (this.isDestroyed) {\n return\n }\n\n if (this.options.autofocus !== false && this.options.autofocus !== null) {\n this.commands.focus(this.options.autofocus)\n }\n this.emit('create', { editor: this })\n this.isInitialized = true\n }, 0)\n }\n\n /**\n * Remove the editor from the DOM, but still allow remounting at a different point in time\n */\n public unmount() {\n if (this.editorView) {\n // Cleanup our reference to prevent circular references which caused memory leaks\n // @ts-ignore\n const dom = this.editorView.dom as TiptapEditorHTMLElement\n\n if (dom?.editor) {\n delete dom.editor\n }\n this.editorView.destroy()\n }\n this.editorView = null\n this.isInitialized = false\n\n // Safely remove CSS element with fallback for test environments\n // Only remove CSS if no other editors exist in the document after unmount\n if (this.css && !document.querySelectorAll(`.${this.className}`).length) {\n try {\n if (typeof this.css.remove === 'function') {\n this.css.remove()\n } else if (this.css.parentNode) {\n this.css.parentNode.removeChild(this.css)\n }\n } catch (error) {\n // Silently handle any unexpected DOM removal errors in test environments\n console.warn('Failed to remove CSS element:', error)\n }\n }\n this.css = null\n this.emit('unmount', { editor: this })\n }\n\n /**\n * Returns the editor storage.\n */\n public get storage(): Storage {\n return this.extensionStorage\n }\n\n /**\n * An object of all registered commands.\n */\n public get commands(): SingleCommands {\n return this.commandManager.commands\n }\n\n /**\n * Create a command chain to call multiple commands at once.\n */\n public chain(): ChainedCommands {\n return this.commandManager.chain()\n }\n\n /**\n * Check if a command or a command chain can be executed. Without executing it.\n */\n public can(): CanCommands {\n return this.commandManager.can()\n }\n\n /**\n * Inject CSS styles.\n */\n private injectCSS(): void {\n if (this.options.injectCSS && typeof document !== 'undefined') {\n this.css = createStyleTag(style, this.options.injectNonce)\n }\n }\n\n /**\n * Update editor options.\n *\n * @param options A list of options\n */\n public setOptions(options: Partial<EditorOptions> = {}): void {\n this.options = {\n ...this.options,\n ...options,\n }\n\n if (!this.editorView || !this.state || this.isDestroyed) {\n return\n }\n\n if (this.options.editorProps) {\n this.view.setProps(this.options.editorProps)\n }\n\n this.view.updateState(this.state)\n }\n\n /**\n * Update editable state of the editor.\n */\n public setEditable(editable: boolean, emitUpdate = true): void {\n this.setOptions({ editable })\n\n if (emitUpdate) {\n this.emit('update', { editor: this, transaction: this.state.tr, appendedTransactions: [] })\n }\n }\n\n /**\n * Returns whether the editor is editable.\n */\n public get isEditable(): boolean {\n // since plugins are applied after creating the view\n // `editable` is always `true` for one tick.\n // that’s why we also have to check for `options.editable`\n return this.options.editable && this.view && this.view.editable\n }\n\n /**\n * Returns the editor state.\n */\n public get view(): EditorView {\n if (this.editorView) {\n return this.editorView\n }\n\n return new Proxy(\n {\n state: this.editorState,\n updateState: (state: EditorState): ReturnType<EditorView['updateState']> => {\n this.editorState = state\n },\n dispatch: (tr: Transaction): ReturnType<EditorView['dispatch']> => {\n this.dispatchTransaction(tr)\n },\n\n // Stub some commonly accessed properties to prevent errors\n composing: false,\n dragging: null,\n editable: true,\n isDestroyed: false,\n } as EditorView,\n {\n get: (obj, key) => {\n if (this.editorView) {\n // If the editor view is available, but the caller has a stale reference to the proxy,\n // Just return what the editor view has.\n return this.editorView[key as keyof EditorView]\n }\n // Specifically always return the most recent editorState\n if (key === 'state') {\n return this.editorState\n }\n if (key in obj) {\n return Reflect.get(obj, key)\n }\n\n // We throw an error here, because we know the view is not available\n throw new Error(\n `[tiptap error]: The editor view is not available. Cannot access view['${key as string}']. The editor may not be mounted yet.`,\n )\n },\n },\n ) as EditorView\n }\n\n /**\n * Returns the editor state.\n */\n public get state(): EditorState {\n if (this.editorView) {\n this.editorState = this.view.state\n }\n\n return this.editorState\n }\n\n /**\n * Register a ProseMirror plugin.\n *\n * @param plugin A ProseMirror plugin\n * @param handlePlugins Control how to merge the plugin into the existing plugins.\n * @returns The new editor state\n */\n public registerPlugin(\n plugin: Plugin,\n handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],\n ): EditorState {\n const plugins = isFunction(handlePlugins)\n ? handlePlugins(plugin, [...this.state.plugins])\n : [...this.state.plugins, plugin]\n\n const state = this.state.reconfigure({ plugins })\n\n this.view.updateState(state)\n\n return state\n }\n\n /**\n * Unregister a ProseMirror plugin.\n *\n * @param nameOrPluginKeyToRemove The plugins name\n * @returns The new editor state or undefined if the editor is destroyed\n */\n public unregisterPlugin(\n nameOrPluginKeyToRemove: string | PluginKey | (string | PluginKey)[],\n ): EditorState | undefined {\n if (this.isDestroyed) {\n return undefined\n }\n\n const prevPlugins = this.state.plugins\n let plugins = prevPlugins\n\n ;([] as (string | PluginKey)[]).concat(nameOrPluginKeyToRemove).forEach(nameOrPluginKey => {\n // @ts-ignore\n const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key\n\n // @ts-ignore\n plugins = plugins.filter(plugin => !plugin.key.startsWith(name))\n })\n\n if (prevPlugins.length === plugins.length) {\n // No plugin was removed, so we don’t need to update the state\n return undefined\n }\n\n const state = this.state.reconfigure({\n plugins,\n })\n\n this.view.updateState(state)\n\n return state\n }\n\n /**\n * Creates an extension manager.\n */\n private createExtensionManager(): void {\n const coreExtensions = this.options.enableCoreExtensions\n ? [\n Editable,\n ClipboardTextSerializer.configure({\n blockSeparator: this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator,\n }),\n Commands,\n FocusEvents,\n Keymap,\n Tabindex,\n Drop,\n Paste,\n Delete,\n TextDirection.configure({\n direction: this.options.textDirection,\n }),\n ].filter(ext => {\n if (typeof this.options.enableCoreExtensions === 'object') {\n return (\n this.options.enableCoreExtensions[ext.name as keyof typeof this.options.enableCoreExtensions] !== false\n )\n }\n return true\n })\n : []\n const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {\n return ['extension', 'node', 'mark'].includes(extension?.type)\n })\n\n this.extensionManager = new ExtensionManager(allExtensions, this)\n }\n\n /**\n * Creates an command manager.\n */\n private createCommandManager(): void {\n this.commandManager = new CommandManager({\n editor: this,\n })\n }\n\n /**\n * Creates a ProseMirror schema.\n */\n private createSchema(): void {\n this.schema = this.extensionManager.schema\n }\n\n /**\n * Creates the initial document.\n */\n private createDoc(): ProseMirrorNode {\n let doc: ProseMirrorNode\n\n try {\n doc = createDocument(this.options.content, this.schema, this.options.parseOptions, {\n errorOnInvalidContent: this.options.enableContentCheck,\n })\n } catch (e) {\n if (\n !(e instanceof Error) ||\n !['[tiptap error]: Invalid JSON content', '[tiptap error]: Invalid HTML content'].includes(e.message)\n ) {\n // Not the content error we were expecting\n throw e\n }\n this.emit('contentError', {\n editor: this,\n error: e as Error,\n disableCollaboration: () => {\n if (\n 'collaboration' in this.storage &&\n typeof this.storage.collaboration === 'object' &&\n this.storage.collaboration\n ) {\n ;(this.storage.collaboration as any).isDisabled = true\n }\n // To avoid syncing back invalid content, reinitialize the extensions without the collaboration extension\n this.options.extensions = this.options.extensions.filter(extension => extension.name !== 'collaboration')\n\n // Restart the initialization process by recreating the extension manager with the new set of extensions\n this.createExtensionManager()\n },\n })\n\n // Content is invalid, but attempt to create it anyway, stripping out the invalid parts\n doc = createDocument(this.options.content, this.schema, this.options.parseOptions, {\n errorOnInvalidContent: false,\n })\n }\n return doc\n }\n\n /**\n * Creates a ProseMirror view.\n */\n private createView(element: NonNullable<EditorOptions['element']>): void {\n const { editorProps, enableExtensionDispatchTransaction } = this.options\n // If a user provided a custom `dispatchTransaction` through `editorProps`,\n // we use that as the base dispatch function.\n // Otherwise, we use Tiptap's internal `dispatchTransaction` method.\n const baseDispatch = (editorProps as any).dispatchTransaction || this.dispatchTransaction.bind(this)\n const dispatch = enableExtensionDispatchTransaction\n ? this.extensionManager.dispatchTransaction(baseDispatch)\n : baseDispatch\n\n this.editorView = new EditorView(element, {\n ...editorProps,\n attributes: {\n // add `role=\"textbox\"` to the editor element\n role: 'textbox',\n ...editorProps?.attributes,\n },\n dispatchTransaction: dispatch,\n state: this.editorState,\n markViews: this.extensionManager.markViews,\n nodeViews: this.extensionManager.nodeViews,\n })\n\n // `editor.view` is not yet available at this time.\n // Therefore we will add all plugins and node views directly afterwards.\n const newState = this.state.reconfigure({\n plugins: this.extensionManager.plugins,\n })\n\n this.view.updateState(newState)\n\n this.prependClass()\n this.injectCSS()\n\n // Let’s store the editor instance in the DOM element.\n // So we’ll have access to it for tests.\n // @ts-ignore\n const dom = this.view.dom as TiptapEditorHTMLElement\n\n dom.editor = this\n }\n\n /**\n * Creates all node and mark views.\n */\n public createNodeViews(): void {\n if (this.view.isDestroyed) {\n return\n }\n\n this.view.setProps({\n markViews: this.extensionManager.markViews,\n nodeViews: this.extensionManager.nodeViews,\n })\n }\n\n /**\n * Prepend class name to element.\n */\n public prependClass(): void {\n this.view.dom.className = `${this.className} ${this.view.dom.className}`\n }\n\n public isCapturingTransaction = false\n\n private capturedTransaction: Transaction | null = null\n\n public captureTransaction(fn: () => void) {\n this.isCapturingTransaction = true\n fn()\n this.isCapturingTransaction = false\n\n const tr = this.capturedTransaction\n\n this.capturedTransaction = null\n\n return tr\n }\n\n /**\n * The callback over which to send transactions (state updates) produced by the view.\n *\n * @param transaction An editor state transaction\n */\n private dispatchTransaction(transaction: Transaction): void {\n // if the editor / the view of the editor was destroyed\n // the transaction should not be dispatched as there is no view anymore.\n if (this.view.isDestroyed) {\n return\n }\n\n if (this.isCapturingTransaction) {\n if (!this.capturedTransaction) {\n this.capturedTransaction = transaction\n\n return\n }\n\n transaction.steps.forEach(step => this.capturedTransaction?.step(step))\n\n return\n }\n\n // Apply transaction and get resulting state and transactions\n const { state, transactions } = this.state.applyTransaction(transaction)\n const selectionHasChanged = !this.state.selection.eq(state.selection)\n const rootTrWasApplied = transactions.includes(transaction)\n const prevState = this.state\n\n this.emit('beforeTransaction', {\n editor: this,\n transaction,\n nextState: state,\n })\n\n // If transaction was filtered out, we can return early\n if (!rootTrWasApplied) {\n return\n }\n\n this.view.updateState(state)\n\n // Emit transaction event with appended transactions info\n this.emit('transaction', {\n editor: this,\n transaction,\n appendedTransactions: transactions.slice(1),\n })\n\n if (selectionHasChanged) {\n this.emit('selectionUpdate', {\n editor: this,\n transaction,\n })\n }\n\n // Only emit the latest between focus and blur events\n const mostRecentFocusTr = transactions.findLast(tr => tr.getMeta('focus') || tr.getMeta('blur'))\n const focus = mostRecentFocusTr?.getMeta('focus')\n const blur = mostRecentFocusTr?.getMeta('blur')\n\n if (focus) {\n this.emit('focus', {\n editor: this,\n event: focus.event,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n transaction: mostRecentFocusTr!,\n })\n }\n\n if (blur) {\n this.emit('blur', {\n editor: this,\n event: blur.event,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n transaction: mostRecentFocusTr!,\n })\n }\n\n // Compare states for update event\n if (\n transaction.getMeta('preventUpdate') ||\n !transactions.some(tr => tr.docChanged) ||\n prevState.doc.eq(state.doc)\n ) {\n return\n }\n\n this.emit('update', {\n editor: this,\n transaction,\n appendedTransactions: transactions.slice(1),\n })\n }\n\n /**\n * Get attributes of the currently selected node or mark.\n */\n public getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any> {\n return getAttributes(this.state, nameOrType)\n }\n\n /**\n * Returns if the currently selected node or mark is active.\n *\n * @param name Name of the node or mark\n * @param attributes Attributes of the node or mark\n */\n public isActive(name: string, attributes?: {}): boolean\n public isActive(attributes: {}): boolean\n public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {\n const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null\n\n const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes\n\n return isActive(this.state, name, attributes)\n }\n\n /**\n * Get the document as JSON.\n */\n public getJSON(): DocumentType<\n Record<string, any> | undefined,\n TNodeType<string, undefined | Record<string, any>, any, (TNodeType | TTextType)[]>[]\n > {\n return this.state.doc.toJSON()\n }\n\n /**\n * Get the document as HTML.\n */\n public getHTML(): string {\n return getHTMLFromFragment(this.state.doc.content, this.schema)\n }\n\n /**\n * Get the document as text.\n */\n public getText(options?: { blockSeparator?: string; textSerializers?: Record<string, TextSerializer> }): string {\n const { blockSeparator = '\\n\\n', textSerializers = {} } = options || {}\n\n return getText(this.state.doc, {\n blockSeparator,\n textSerializers: {\n ...getTextSerializersFromSchema(this.schema),\n ...textSerializers,\n },\n })\n }\n\n /**\n * Check if there is no content.\n */\n public get isEmpty(): boolean {\n return isNodeEmpty(this.state.doc)\n }\n\n /**\n * Destroy the editor.\n */\n public destroy(): void {\n this.emit('destroy')\n\n this.unmount()\n\n this.removeAllListeners()\n }\n\n /**\n * Check if the editor is already destroyed.\n */\n public get isDestroyed(): boolean {\n return this.editorView?.isDestroyed ?? true\n }\n\n public $node(selector: string, attributes?: { [key: string]: any }): NodePos | null {\n return this.$doc?.querySelector(selector, attributes) || null\n }\n\n public $nodes(selector: string, attributes?: { [key: string]: any }): NodePos[] | null {\n return this.$doc?.querySelectorAll(selector, attributes) || null\n }\n\n public $pos(pos: number) {\n const $pos = this.state.doc.resolve(pos)\n\n return new NodePos($pos, this)\n }\n\n get $doc() {\n return this.$pos(0)\n }\n\n /**\n * Returns a set of utilities for working with positions and ranges.\n */\n public utils: Utils = {\n getUpdatedPosition,\n createMappablePosition,\n }\n}\n","type StringKeyOf<T> = Extract<keyof T, string>\ntype CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[]\n ? T[EventName]\n : [T[EventName]]\ntype CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (\n ...props: CallbackType<T, EventName>\n) => any\n\nexport class EventEmitter<T extends Record<string, any>> {\n private callbacks: { [key: string]: Array<(...args: any[]) => void> } = {}\n\n public on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {\n if (!this.callbacks[event]) {\n this.callbacks[event] = []\n }\n\n this.callbacks[event].push(fn)\n\n return this\n }\n\n public emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this {\n const callbacks = this.callbacks[event]\n\n if (callbacks) {\n callbacks.forEach(callback => callback.apply(this, args))\n }\n\n return this\n }\n\n public off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this {\n const callbacks = this.callbacks[event]\n\n if (callbacks) {\n if (fn) {\n this.callbacks[event] = callbacks.filter(callback => callback !== fn)\n } else {\n delete this.callbacks[event]\n }\n }\n\n return this\n }\n\n public once<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {\n const onceFn = (...args: CallbackType<T, EventName>) => {\n this.off(event, onceFn)\n fn.apply(this, args)\n }\n\n return this.on(event, onceFn)\n }\n\n public removeAllListeners(): void {\n this.callbacks = {}\n }\n}\n","import { keymap } from '@tiptap/pm/keymap'\nimport type { Schema } from '@tiptap/pm/model'\nimport type { Plugin, Transaction } from '@tiptap/pm/state'\nimport type { MarkViewConstructor, NodeViewConstructor } from '@tiptap/pm/view'\n\nimport type { Editor } from './Editor.js'\nimport {\n flattenExtensions,\n getAttributesFromExtensions,\n getExtensionField,\n getNodeType,\n getRenderedAttributes,\n getSchemaByResolvedExtensions,\n getSchemaTypeByName,\n isExtensionRulesEnabled,\n resolveExtensions,\n sortExtensions,\n splitExtensions,\n} from './helpers/index.js'\nimport { type MarkConfig, type NodeConfig, type Storage, getMarkType, updateMarkViewAttributes } from './index.js'\nimport { inputRulesPlugin } from './InputRule.js'\nimport { Mark } from './Mark.js'\nimport { pasteRulesPlugin } from './PasteRule.js'\nimport type { AnyConfig, Extensions, RawCommands } from './types.js'\nimport { callOrReturn } from './utilities/callOrReturn.js'\n\nexport class ExtensionManager {\n editor: Editor\n\n schema: Schema\n\n /**\n * A flattened and sorted array of all extensions\n */\n extensions: Extensions\n\n /**\n * A non-flattened array of base extensions (no sub-extensions)\n */\n baseExtensions: Extensions\n\n splittableMarks: string[] = []\n\n constructor(extensions: Extensions, editor: Editor) {\n this.editor = editor\n this.baseExtensions = extensions\n this.extensions = resolveExtensions(extensions)\n this.schema = getSchemaByResolvedExtensions(this.extensions, editor)\n this.setupExtensions()\n }\n\n static resolve = resolveExtensions\n\n static sort = sortExtensions\n\n static flatten = flattenExtensions\n\n /**\n * Get all commands from the extensions.\n * @returns An object with all commands where the key is the command name and the value is the command function\n */\n get commands(): RawCommands {\n return this.extensions.reduce((commands, extension) => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor: this.editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const addCommands = getExtensionField<AnyConfig['addCommands']>(extension, 'addCommands', context)\n\n if (!addCommands) {\n return commands\n }\n\n return {\n ...commands,\n ...addCommands(),\n }\n }, {} as RawCommands)\n }\n\n /**\n * Get all registered Prosemirror plugins from the extensions.\n * @returns An array of Prosemirror plugins\n */\n get plugins(): Plugin[] {\n const { editor } = this\n\n // With ProseMirror, first plugins within an array are executed first.\n // In Tiptap, we provide the ability to override plugins,\n // so it feels more natural to run plugins at the end of an array first.\n // That’s why we have to reverse the `extensions` array and sort again\n // based on the `priority` option.\n const extensions = sortExtensions([...this.extensions].reverse())\n\n const allPlugins = extensions.flatMap(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const plugins: Plugin[] = []\n\n const addKeyboardShortcuts = getExtensionField<AnyConfig['addKeyboardShortcuts']>(\n extension,\n 'addKeyboardShortcuts',\n context,\n )\n\n let defaultBindings: Record<string, () => boolean> = {}\n\n // bind exit handling\n if (extension.type === 'mark' && getExtensionField<MarkConfig['exitable']>(extension, 'exitable', context)) {\n defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })\n }\n\n if (addKeyboardShortcuts) {\n const bindings = Object.fromEntries(\n Object.entries(addKeyboardShortcuts()).map(([shortcut, method]) => {\n return [shortcut, () => method({ editor })]\n }),\n )\n\n defaultBindings = { ...defaultBindings, ...bindings }\n }\n\n const keyMapPlugin = keymap(defaultBindings)\n\n plugins.push(keyMapPlugin)\n\n const addInputRules = getExtensionField<AnyConfig['addInputRules']>(extension, 'addInputRules', context)\n\n if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {\n const rules = addInputRules()\n\n if (rules && rules.length) {\n const inputResult = inputRulesPlugin({\n editor,\n rules,\n })\n\n const inputPlugins = Array.isArray(inputResult) ? inputResult : [inputResult]\n\n plugins.push(...inputPlugins)\n }\n }\n\n const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(extension, 'addPasteRules', context)\n\n if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {\n const rules = addPasteRules()\n\n if (rules && rules.length) {\n const pasteRules = pasteRulesPlugin({ editor, rules })\n\n plugins.push(...pasteRules)\n }\n }\n\n const addProseMirrorPlugins = getExtensionField<AnyConfig['addProseMirrorPlugins']>(\n extension,\n 'addProseMirrorPlugins',\n context,\n )\n\n if (addProseMirrorPlugins) {\n const proseMirrorPlugins = addProseMirrorPlugins()\n\n plugins.push(...proseMirrorPlugins)\n }\n\n return plugins\n })\n\n return allPlugins\n }\n\n /**\n * Get all attributes from the extensions.\n * @returns An array of attributes\n */\n get attributes() {\n return getAttributesFromExtensions(this.extensions)\n }\n\n /**\n * Get all node views from the extensions.\n * @returns An object with all node views where the key is the node name and the value is the node view function\n */\n get nodeViews(): Record<string, NodeViewConstructor> {\n const { editor } = this\n const { nodeExtensions } = splitExtensions(this.extensions)\n\n return Object.fromEntries(\n nodeExtensions\n .filter(extension => !!getExtensionField(extension, 'addNodeView'))\n .map(extension => {\n const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getNodeType(extension.name, this.schema),\n }\n const addNodeView = getExtensionField<NodeConfig['addNodeView']>(extension, 'addNodeView', context)\n\n if (!addNodeView) {\n return []\n }\n\n const nodeViewResult = addNodeView()\n\n if (!nodeViewResult) {\n return []\n }\n\n const nodeview: NodeViewConstructor = (node, view, getPos, decorations, innerDecorations) => {\n const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)\n\n return nodeViewResult({\n // pass-through\n node,\n view,\n getPos: getPos as () => number,\n decorations,\n innerDecorations,\n // tiptap-specific\n editor,\n extension,\n HTMLAttributes,\n })\n }\n\n return [extension.name, nodeview]\n }),\n )\n }\n\n /**\n * Get the composed dispatchTransaction function from all extensions.\n * @param baseDispatch The base dispatch function (e.g. from the editor or user props)\n * @returns A composed dispatch function\n */\n dispatchTransaction(baseDispatch: (tr: Transaction) => void): (tr: Transaction) => void {\n const { editor } = this\n const extensions = sortExtensions([...this.extensions].reverse())\n\n return extensions.reduceRight((next, extension) => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n const dispatchTransaction = getExtensionField<AnyConfig['dispatchTransaction']>(\n extension,\n 'dispatchTransaction',\n context,\n )\n\n if (!dispatchTransaction) {\n return next\n }\n\n return (transaction: Transaction) => {\n dispatchTransaction.call(context, { transaction, next })\n }\n }, baseDispatch)\n }\n\n get markViews(): Record<string, MarkViewConstructor> {\n const { editor } = this\n const { markExtensions } = splitExtensions(this.extensions)\n\n return Object.fromEntries(\n markExtensions\n .filter(extension => !!getExtensionField(extension, 'addMarkView'))\n .map(extension => {\n const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor,\n type: getMarkType(extension.name, this.schema),\n }\n const addMarkView = getExtensionField<MarkConfig['addMarkView']>(extension, 'addMarkView', context)\n\n if (!addMarkView) {\n return []\n }\n\n const markView: MarkViewConstructor = (mark, view, inline) => {\n const HTMLAttributes = getRenderedAttributes(mark, extensionAttributes)\n\n return addMarkView()({\n // pass-through\n mark,\n view,\n inline,\n // tiptap-specific\n editor,\n extension,\n HTMLAttributes,\n updateAttributes: (attrs: Record<string, any>) => {\n updateMarkViewAttributes(mark, editor, attrs)\n },\n })\n }\n\n return [extension.name, markView]\n }),\n )\n }\n\n /**\n * Go through all extensions, create extension storages & setup marks\n * & bind editor event listener.\n */\n private setupExtensions() {\n const extensions = this.extensions\n // re-initialize the extension storage object instance\n this.editor.extensionStorage = Object.fromEntries(\n extensions.map(extension => [extension.name, extension.storage]),\n ) as unknown as Storage\n\n extensions.forEach(extension => {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: this.editor.extensionStorage[extension.name as keyof Storage],\n editor: this.editor,\n type: getSchemaTypeByName(extension.name, this.schema),\n }\n\n if (extension.type === 'mark') {\n const keepOnSplit = callOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true\n\n if (keepOnSplit) {\n this.splittableMarks.push(extension.name)\n }\n }\n\n const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(extension, 'onBeforeCreate', context)\n const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)\n const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)\n const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(\n extension,\n 'onSelectionUpdate',\n context,\n )\n const onTransaction = getExtensionField<AnyConfig['onTransaction']>(extension, 'onTransaction', context)\n const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)\n const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)\n const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)\n\n if (onBeforeCreate) {\n this.editor.on('beforeCreate', onBeforeCreate)\n }\n\n if (onCreate) {\n this.editor.on('create', onCreate)\n }\n\n if (onUpdate) {\n this.editor.on('update', onUpdate)\n }\n\n if (onSelectionUpdate) {\n this.editor.on('selectionUpdate', onSelectionUpdate)\n }\n\n if (onTransaction) {\n this.editor.on('transaction', onTransaction)\n }\n\n if (onFocus) {\n this.editor.on('focus', onFocus)\n }\n\n if (onBlur) {\n this.editor.on('blur', onBlur)\n }\n\n if (onDestroy) {\n this.editor.on('destroy', onDestroy)\n }\n })\n }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\nimport type { EditorState, TextSelection } from '@tiptap/pm/state'\nimport { Plugin } from '@tiptap/pm/state'\n\nimport { CommandManager } from './CommandManager.js'\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport { getTextContentFromNodes } from './helpers/getTextContentFromNodes.js'\nimport type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'\nimport { isRegExp } from './utilities/isRegExp.js'\n\nexport type InputRuleMatch = {\n index: number\n text: string\n replaceWith?: string\n match?: RegExpMatchArray\n data?: Record<string, any>\n}\n\nexport type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null)\n\nexport class InputRule {\n find: InputRuleFinder\n\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n }) => void | null\n\n undoable: boolean\n\n constructor(config: {\n find: InputRuleFinder\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n }) => void | null\n undoable?: boolean\n }) {\n this.find = config.find\n this.handler = config.handler\n this.undoable = config.undoable ?? true\n }\n}\n\nconst inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedRegExpMatchArray | null => {\n if (isRegExp(find)) {\n return find.exec(text)\n }\n\n const inputRuleMatch = find(text)\n\n if (!inputRuleMatch) {\n return null\n }\n\n const result: ExtendedRegExpMatchArray = [inputRuleMatch.text]\n\n result.index = inputRuleMatch.index\n result.input = text\n result.data = inputRuleMatch.data\n\n if (inputRuleMatch.replaceWith) {\n if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {\n console.warn('[tiptap warn]: \"inputRuleMatch.replaceWith\" must be part of \"inputRuleMatch.text\".')\n }\n\n result.push(inputRuleMatch.replaceWith)\n }\n\n return result\n}\n\nfunction run(config: {\n editor: Editor\n from: number\n to: number\n text: string\n rules: InputRule[]\n plugin: Plugin\n}): boolean {\n const { editor, from, to, text, rules, plugin } = config\n const { view } = editor\n\n if (view.composing) {\n return false\n }\n\n const $from = view.state.doc.resolve(from)\n\n if (\n // check for code node\n $from.parent.type.spec.code ||\n // check for code mark\n !!($from.nodeBefore || $from.nodeAfter)?.marks.find(mark => mark.type.spec.code)\n ) {\n return false\n }\n\n let matched = false\n\n const textBefore = getTextContentFromNodes($from) + text\n\n rules.forEach(rule => {\n if (matched) {\n return\n }\n\n const match = inputRuleMatcherHandler(textBefore, rule.find)\n\n if (!match) {\n return\n }\n\n const tr = view.state.tr\n const state = createChainableState({\n state: view.state,\n transaction: tr,\n })\n const range = {\n from: from - (match[0].length - text.length),\n to,\n }\n\n const { commands, chain, can } = new CommandManager({\n editor,\n state,\n })\n\n const handler = rule.handler({\n state,\n range,\n match,\n commands,\n chain,\n can,\n })\n\n // stop if there are no changes\n if (handler === null || !tr.steps.length) {\n return\n }\n\n // store transform as meta data\n // so we can undo input rules within the `undoInputRules` command\n if (rule.undoable) {\n tr.setMeta(plugin, {\n transform: tr,\n from,\n to,\n text,\n })\n }\n\n view.dispatch(tr)\n matched = true\n })\n\n return matched\n}\n\n/**\n * Create an input rules plugin. When enabled, it will cause text\n * input that matches any of the given rules to trigger the rule’s\n * action.\n */\nexport function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }): Plugin {\n const { editor, rules } = props\n const plugin = new Plugin({\n state: {\n init() {\n return null\n },\n apply(tr, prev, state) {\n const stored = tr.getMeta(plugin)\n\n if (stored) {\n return stored\n }\n\n // if InputRule is triggered by insertContent()\n const simulatedInputMeta = tr.getMeta('applyInputRules') as\n | undefined\n | {\n from: number\n text: string | ProseMirrorNode | Fragment\n }\n const isSimulatedInput = !!simulatedInputMeta\n\n if (isSimulatedInput) {\n setTimeout(() => {\n let { text } = simulatedInputMeta\n\n if (typeof text === 'string') {\n text = text as string\n } else {\n text = getHTMLFromFragment(Fragment.from(text), state.schema)\n }\n\n const { from } = simulatedInputMeta\n const to = from + text.length\n\n run({\n editor,\n from,\n to,\n text,\n rules,\n plugin,\n })\n })\n }\n\n return tr.selectionSet || tr.docChanged ? null : prev\n },\n },\n\n props: {\n handleTextInput(view, from, to, text) {\n return run({\n editor,\n from,\n to,\n text,\n rules,\n plugin,\n })\n },\n\n handleDOMEvents: {\n compositionend: view => {\n setTimeout(() => {\n const { $cursor } = view.state.selection as TextSelection\n\n if ($cursor) {\n run({\n editor,\n from: $cursor.pos,\n to: $cursor.pos,\n text: '',\n rules,\n plugin,\n })\n }\n })\n\n return false\n },\n },\n\n // add support for input rules to trigger on enter\n // this is useful for example for code blocks\n handleKeyDown(view, event) {\n if (event.key !== 'Enter') {\n return false\n }\n\n const { $cursor } = view.state.selection as TextSelection\n\n if ($cursor) {\n return run({\n editor,\n from: $cursor.pos,\n to: $cursor.pos,\n text: '\\n',\n rules,\n plugin,\n })\n }\n\n return false\n },\n },\n\n // @ts-ignore\n isInputRules: true,\n }) as Plugin\n\n return plugin\n}\n","// see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts\n\nfunction getType(value: any): string {\n return Object.prototype.toString.call(value).slice(8, -1)\n}\n\nexport function isPlainObject(value: any): value is Record<string, any> {\n if (getType(value) !== 'Object') {\n return false\n }\n\n return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype\n}\n","import { isPlainObject } from './isPlainObject.js'\n\nexport function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {\n const output = { ...target }\n\n if (isPlainObject(target) && isPlainObject(source)) {\n Object.keys(source).forEach(key => {\n if (isPlainObject(source[key]) && isPlainObject(target[key])) {\n output[key] = mergeDeep(target[key], source[key])\n } else {\n output[key] = source[key]\n }\n })\n }\n\n return output\n}\n","import type { Plugin } from '@tiptap/pm/state'\n\nimport type { Editor } from './Editor.js'\nimport { getExtensionField } from './helpers/getExtensionField.js'\nimport type { ExtensionConfig, MarkConfig, NodeConfig } from './index.js'\nimport type { InputRule } from './InputRule.js'\nimport type { Mark } from './Mark.js'\nimport type { Node } from './Node.js'\nimport type { PasteRule } from './PasteRule.js'\nimport type {\n AnyConfig,\n DispatchTransactionProps,\n EditorEvents,\n Extensions,\n GlobalAttributes,\n JSONContent,\n KeyboardShortcutCommand,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownRendererHelpers,\n MarkdownToken,\n MarkdownTokenizer,\n ParentConfig,\n RawCommands,\n RenderContext,\n} from './types.js'\nimport { callOrReturn } from './utilities/callOrReturn.js'\nimport { mergeDeep } from './utilities/mergeDeep.js'\n\nexport interface ExtendableConfig<\n Options = any,\n Storage = any,\n Config extends\n | ExtensionConfig<Options, Storage>\n | NodeConfig<Options, Storage>\n | MarkConfig<Options, Storage>\n | ExtendableConfig<Options, Storage> = ExtendableConfig<Options, Storage, any, any>,\n PMType = any,\n> {\n /**\n * The extension name - this must be unique.\n * It will be used to identify the extension.\n *\n * @example 'myExtension'\n */\n name: string\n\n /**\n * The priority of your extension. The higher, the earlier it will be called\n * and will take precedence over other extensions with a lower priority.\n * @default 100\n * @example 101\n */\n priority?: number\n\n /**\n * This method will add options to this extension\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#settings\n * @example\n * addOptions() {\n * return {\n * myOption: 'foo',\n * myOtherOption: 10,\n * }\n */\n addOptions?: (this: { name: string; parent: ParentConfig<Config>['addOptions'] }) => Options\n\n /**\n * The default storage this extension can save data to.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#storage\n * @example\n * defaultStorage: {\n * prefetchedUsers: [],\n * loading: false,\n * }\n */\n addStorage?: (this: { name: string; options: Options; parent: ParentConfig<Config>['addStorage'] }) => Storage\n\n /**\n * This function adds globalAttributes to specific nodes.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#global-attributes\n * @example\n * addGlobalAttributes() {\n * return [\n * {\n // Extend the following extensions\n * types: [\n * 'heading',\n * 'paragraph',\n * ],\n * // … with those attributes\n * attributes: {\n * textAlign: {\n * default: 'left',\n * renderHTML: attributes => ({\n * style: `text-align: ${attributes.textAlign}`,\n * }),\n * parseHTML: element => element.style.textAlign || 'left',\n * },\n * },\n * },\n * ]\n * }\n */\n addGlobalAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n extensions: (Node | Mark)[]\n parent: ParentConfig<Config>['addGlobalAttributes']\n }) => GlobalAttributes\n\n /**\n * This function adds commands to the editor\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#commands\n * @example\n * addCommands() {\n * return {\n * myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),\n * }\n * }\n */\n addCommands?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addCommands']\n }) => Partial<RawCommands>\n\n /**\n * This function registers keyboard shortcuts.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#keyboard-shortcuts\n * @example\n * addKeyboardShortcuts() {\n * return {\n * 'Mod-l': () => this.editor.commands.toggleBulletList(),\n * }\n * },\n */\n addKeyboardShortcuts?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addKeyboardShortcuts']\n }) => {\n [key: string]: KeyboardShortcutCommand\n }\n\n /**\n * This function adds input rules to the editor.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#input-rules\n * @example\n * addInputRules() {\n * return [\n * markInputRule({\n * find: inputRegex,\n * type: this.type,\n * }),\n * ]\n * },\n */\n addInputRules?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addInputRules']\n }) => InputRule[]\n\n /**\n * This function adds paste rules to the editor.\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#paste-rules\n * @example\n * addPasteRules() {\n * return [\n * markPasteRule({\n * find: pasteRegex,\n * type: this.type,\n * }),\n * ]\n * },\n */\n addPasteRules?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addPasteRules']\n }) => PasteRule[]\n\n /**\n * This function adds Prosemirror plugins to the editor\n * @see https://tiptap.dev/docs/editor/guide/custom-extensions#prosemirror-plugins\n * @example\n * addProseMirrorPlugins() {\n * return [\n * customPlugin(),\n * ]\n * }\n */\n addProseMirrorPlugins?: (this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['addProseMirrorPlugins']\n }) => Plugin[]\n\n /**\n * This function adds additional extensions to the editor. This is useful for\n * building extension kits.\n * @example\n * addExtensions() {\n * return [\n * BulletList,\n * OrderedList,\n * ListItem\n * ]\n * }\n */\n addExtensions?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['addExtensions']\n }) => Extensions\n\n /**\n * The markdown token name\n *\n * This is the name of the token that this extension uses to parse and render markdown and comes from the Marked Lexer.\n *\n * @see https://github.com/markedjs/marked/blob/master/src/Tokens.ts\n *\n */\n markdownTokenName?: string\n\n /**\n * The parse function used by the markdown parser to convert markdown tokens to ProseMirror nodes.\n */\n parseMarkdown?: (token: MarkdownToken, helpers: MarkdownParseHelpers) => MarkdownParseResult\n\n /**\n * The serializer function used by the markdown serializer to convert ProseMirror nodes to markdown tokens.\n */\n renderMarkdown?: (node: JSONContent, helpers: MarkdownRendererHelpers, ctx: RenderContext) => string\n\n /**\n * The markdown tokenizer responsible for turning a markdown string into tokens\n *\n * Custom tokenizers are only needed when you want to parse non-standard markdown token.\n */\n markdownTokenizer?: MarkdownTokenizer\n\n /**\n * Optional markdown options for indentation\n */\n markdownOptions?: {\n /**\n * Defines if this markdown element should indent it's child elements\n */\n indentsContent?: boolean\n }\n\n /**\n * This function extends the schema of the node.\n * @example\n * extendNodeSchema() {\n * return {\n * group: 'inline',\n * selectable: false,\n * }\n * }\n */\n extendNodeSchema?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['extendNodeSchema']\n },\n extension: Node,\n ) => Record<string, any>)\n | null\n\n /**\n * This function extends the schema of the mark.\n * @example\n * extendMarkSchema() {\n * return {\n * group: 'inline',\n * selectable: false,\n * }\n * }\n */\n extendMarkSchema?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<Config>['extendMarkSchema']\n },\n extension: Mark,\n ) => Record<string, any>)\n | null\n\n /**\n * The editor is not ready yet.\n */\n onBeforeCreate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onBeforeCreate']\n },\n event: EditorEvents['beforeCreate'],\n ) => void)\n | null\n\n /**\n * The editor is ready.\n */\n onCreate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onCreate']\n },\n event: EditorEvents['create'],\n ) => void)\n | null\n\n /**\n * The content has changed.\n */\n onUpdate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onUpdate']\n },\n event: EditorEvents['update'],\n ) => void)\n | null\n\n /**\n * The selection has changed.\n */\n onSelectionUpdate?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onSelectionUpdate']\n },\n event: EditorEvents['selectionUpdate'],\n ) => void)\n | null\n\n /**\n * The editor state has changed.\n */\n onTransaction?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onTransaction']\n },\n event: EditorEvents['transaction'],\n ) => void)\n | null\n\n /**\n * The editor is focused.\n */\n onFocus?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onFocus']\n },\n event: EditorEvents['focus'],\n ) => void)\n | null\n\n /**\n * The editor isn’t focused anymore.\n */\n onBlur?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onBlur']\n },\n event: EditorEvents['blur'],\n ) => void)\n | null\n\n /**\n * The editor is destroyed.\n */\n onDestroy?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['onDestroy']\n },\n event: EditorEvents['destroy'],\n ) => void)\n | null\n\n /**\n * This hook allows you to intercept and modify transactions before they are dispatched.\n *\n * Example\n * ```ts\n * dispatchTransaction({ transaction, next }) {\n * console.log('Dispatching transaction:', transaction)\n * next(transaction)\n * }\n * ```\n *\n * @param props - The dispatch transaction props\n */\n dispatchTransaction?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: PMType\n parent: ParentConfig<Config>['dispatchTransaction']\n },\n props: DispatchTransactionProps,\n ) => void)\n | null\n}\n\nexport class Extendable<\n Options = any,\n Storage = any,\n Config = ExtensionConfig<Options, Storage> | NodeConfig<Options, Storage> | MarkConfig<Options, Storage>,\n> {\n type = 'extendable'\n parent: Extendable | null = null\n\n child: Extendable | null = null\n\n name = ''\n\n config: Config = {\n name: this.name,\n } as Config\n\n constructor(config: Partial<Config> = {}) {\n this.config = {\n ...this.config,\n ...config,\n }\n\n this.name = (this.config as any).name\n }\n\n get options(): Options {\n return {\n ...(callOrReturn(\n getExtensionField<AnyConfig['addOptions']>(this as any, 'addOptions', {\n name: this.name,\n }),\n ) || {}),\n }\n }\n\n get storage(): Readonly<Storage> {\n return {\n ...(callOrReturn(\n getExtensionField<AnyConfig['addStorage']>(this as any, 'addStorage', {\n name: this.name,\n options: this.options,\n }),\n ) || {}),\n }\n }\n\n configure(options: Partial<Options> = {}) {\n const extension = this.extend<Options, Storage, Config>({\n ...this.config,\n addOptions: () => {\n return mergeDeep(this.options as Record<string, any>, options) as Options\n },\n })\n\n extension.name = this.name\n extension.parent = this.parent\n\n return extension\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig =\n | ExtensionConfig<ExtendedOptions, ExtendedStorage>\n | NodeConfig<ExtendedOptions, ExtendedStorage>\n | MarkConfig<ExtendedOptions, ExtendedStorage>,\n >(extendedConfig: Partial<ExtendedConfig> = {}): Extendable<ExtendedOptions, ExtendedStorage> {\n const extension = new (this.constructor as any)({ ...this.config, ...extendedConfig })\n\n extension.parent = this\n this.child = extension\n extension.name = 'name' in extendedConfig ? extendedConfig.name : extension.parent.name\n\n return extension\n }\n}\n","import type { DOMOutputSpec, Mark as ProseMirrorMark, MarkSpec, MarkType } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { ExtendableConfig } from './Extendable.js'\nimport { Extendable } from './Extendable.js'\nimport type { Attributes, MarkViewRenderer, ParentConfig } from './types.js'\n\nexport interface MarkConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, MarkConfig<Options, Storage>, MarkType> {\n /**\n * Mark View\n */\n addMarkView?:\n | ((this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: MarkType\n parent: ParentConfig<MarkConfig<Options, Storage>>['addMarkView']\n }) => MarkViewRenderer)\n | null\n\n /**\n * Keep mark after split node\n */\n keepOnSplit?: boolean | (() => boolean)\n\n /**\n * Inclusive\n */\n inclusive?:\n | MarkSpec['inclusive']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['inclusive']\n editor?: Editor\n }) => MarkSpec['inclusive'])\n\n /**\n * Excludes\n */\n excludes?:\n | MarkSpec['excludes']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['excludes']\n editor?: Editor\n }) => MarkSpec['excludes'])\n\n /**\n * Marks this Mark as exitable\n */\n exitable?: boolean | (() => boolean)\n\n /**\n * Group\n */\n group?:\n | MarkSpec['group']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['group']\n editor?: Editor\n }) => MarkSpec['group'])\n\n /**\n * Spanning\n */\n spanning?:\n | MarkSpec['spanning']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['spanning']\n editor?: Editor\n }) => MarkSpec['spanning'])\n\n /**\n * Code\n */\n code?:\n | boolean\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['code']\n editor?: Editor\n }) => boolean)\n\n /**\n * Parse HTML\n */\n parseHTML?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['parseHTML']\n editor?: Editor\n }) => MarkSpec['parseDOM']\n\n /**\n * Render HTML\n */\n renderHTML?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['renderHTML']\n editor?: Editor\n },\n props: {\n mark: ProseMirrorMark\n HTMLAttributes: Record<string, any>\n },\n ) => DOMOutputSpec)\n | null\n\n /**\n * Attributes\n */\n addAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<MarkConfig<Options, Storage>>['addAttributes']\n editor?: Editor\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n }) => Attributes | {}\n}\n\n/**\n * The Mark class is used to create custom mark extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {\n type = 'mark'\n\n /**\n * Create a new Mark instance\n * @param config - Mark configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>) = {}) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Mark<O, S>(resolvedConfig)\n }\n\n static handleExit({ editor, mark }: { editor: Editor; mark: Mark }) {\n const { tr } = editor.state\n const currentPos = editor.state.selection.$from\n const isAtEnd = currentPos.pos === currentPos.end()\n\n if (isAtEnd) {\n const currentMarks = currentPos.marks()\n const isInMark = !!currentMarks.find(m => m?.type.name === mark.name)\n\n if (!isInMark) {\n return false\n }\n\n const removeMark = currentMarks.find(m => m?.type.name === mark.name)\n\n if (removeMark) {\n tr.removeStoredMark(removeMark)\n }\n tr.insertText(' ', currentPos.pos)\n\n editor.view.dispatch(tr)\n\n return true\n }\n\n return false\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Mark<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig extends MarkConfig<ExtendedOptions, ExtendedStorage> = MarkConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: MarkType\n }>),\n ): Mark<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Mark<ExtendedOptions, ExtendedStorage>\n }\n}\n","import type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\nimport { Plugin } from '@tiptap/pm/state'\n\nimport { CommandManager } from './CommandManager.js'\nimport type { Editor } from './Editor.js'\nimport { createChainableState } from './helpers/createChainableState.js'\nimport { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'\nimport type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'\nimport { isNumber } from './utilities/isNumber.js'\nimport { isRegExp } from './utilities/isRegExp.js'\n\nexport type PasteRuleMatch = {\n index: number\n text: string\n replaceWith?: string\n match?: RegExpMatchArray\n data?: Record<string, any>\n}\n\nexport type PasteRuleFinder =\n | RegExp\n | ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)\n\n/**\n * Paste rules are used to react to pasted content.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport class PasteRule {\n find: PasteRuleFinder\n\n handler: (props: {\n state: EditorState\n range: Range\n match: ExtendedRegExpMatchArray\n commands: SingleCommands\n chain: () => ChainedCommands\n can: () => CanCommands\n pasteEvent: ClipboardEvent | null\n dropEvent: DragEvent | null\n }) => void | null\n\n constructor(config: {\n find: PasteRuleFinder\n handler: (props: {\n can: () => CanCommands\n chain: () => ChainedCommands\n commands: SingleCommands\n dropEvent: DragEvent | null\n match: ExtendedRegExpMatchArray\n pasteEvent: ClipboardEvent | null\n range: Range\n state: EditorState\n }) => void | null\n }) {\n this.find = config.find\n this.handler = config.handler\n }\n}\n\nconst pasteRuleMatcherHandler = (\n text: string,\n find: PasteRuleFinder,\n event?: ClipboardEvent | null,\n): ExtendedRegExpMatchArray[] => {\n if (isRegExp(find)) {\n return [...text.matchAll(find)]\n }\n\n const matches = find(text, event)\n\n if (!matches) {\n return []\n }\n\n return matches.map(pasteRuleMatch => {\n const result: ExtendedRegExpMatchArray = [pasteRuleMatch.text]\n\n result.index = pasteRuleMatch.index\n result.input = text\n result.data = pasteRuleMatch.data\n\n if (pasteRuleMatch.replaceWith) {\n if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) {\n console.warn('[tiptap warn]: \"pasteRuleMatch.replaceWith\" must be part of \"pasteRuleMatch.text\".')\n }\n\n result.push(pasteRuleMatch.replaceWith)\n }\n\n return result\n })\n}\n\nfunction run(config: {\n editor: Editor\n state: EditorState\n from: number\n to: number\n rule: PasteRule\n pasteEvent: ClipboardEvent | null\n dropEvent: DragEvent | null\n}): boolean {\n const { editor, state, from, to, rule, pasteEvent, dropEvent } = config\n\n const { commands, chain, can } = new CommandManager({\n editor,\n state,\n })\n\n const handlers: (void | null)[] = []\n\n state.doc.nodesBetween(from, to, (node, pos) => {\n // Skip code blocks and non-textual nodes.\n // Be defensive: `node` may be a Fragment without a `type`. Only text,\n // inline, or textblock nodes are processed by paste rules.\n if (node.type?.spec?.code || !(node.isText || node.isTextblock || node.isInline)) {\n return\n }\n\n // For textblock and inline/text nodes, compute the range relative to the node.\n // Prefer `node.nodeSize` when available (some Node shapes expose this),\n // otherwise fall back to `node.content?.size`. Default to 0 if neither exists.\n const contentSize = node.content?.size ?? node.nodeSize ?? 0\n const resolvedFrom = Math.max(from, pos)\n const resolvedTo = Math.min(to, pos + contentSize)\n\n // If the resolved range is empty or invalid for this node, skip it. This\n // avoids calling `textBetween` with start > end which can cause internal\n // Fragment/Node traversal to access undefined `nodeSize` values.\n if (resolvedFrom >= resolvedTo) {\n return\n }\n\n const textToMatch = node.isText\n ? node.text || ''\n : node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\\ufffc')\n\n const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent)\n\n matches.forEach(match => {\n if (match.index === undefined) {\n return\n }\n\n const start = resolvedFrom + match.index + 1\n const end = start + match[0].length\n const range = {\n from: state.tr.mapping.map(start),\n to: state.tr.mapping.map(end),\n }\n\n const handler = rule.handler({\n state,\n range,\n match,\n commands,\n chain,\n can,\n pasteEvent,\n dropEvent,\n })\n\n handlers.push(handler)\n })\n })\n\n const success = handlers.every(handler => handler !== null)\n\n return success\n}\n\n// When dragging across editors, must get another editor instance to delete selection content.\nlet tiptapDragFromOtherEditor: Editor | null = null\n\nconst createClipboardPasteEvent = (text: string) => {\n const event = new ClipboardEvent('paste', {\n clipboardData: new DataTransfer(),\n })\n\n event.clipboardData?.setData('text/html', text)\n\n return event\n}\n\n/**\n * Create an paste rules plugin. When enabled, it will cause pasted\n * text that matches any of the given rules to trigger the rule’s\n * action.\n */\nexport function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }): Plugin[] {\n const { editor, rules } = props\n let dragSourceElement: Element | null = null\n let isPastedFromProseMirror = false\n let isDroppedFromProseMirror = false\n let pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null\n let dropEvent: DragEvent | null\n\n try {\n dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null\n } catch {\n dropEvent = null\n }\n\n const processEvent = ({\n state,\n from,\n to,\n rule,\n pasteEvt,\n }: {\n state: EditorState\n from: number\n to: { b: number }\n rule: PasteRule\n pasteEvt: ClipboardEvent | null\n }) => {\n const tr = state.tr\n const chainableState = createChainableState({\n state,\n transaction: tr,\n })\n\n const handler = run({\n editor,\n state: chainableState,\n from: Math.max(from - 1, 0),\n to: to.b - 1,\n rule,\n pasteEvent: pasteEvt,\n dropEvent,\n })\n\n if (!handler || !tr.steps.length) {\n return\n }\n\n try {\n dropEvent = typeof DragEvent !== 'undefined' ? new DragEvent('drop') : null\n } catch {\n dropEvent = null\n }\n pasteEvent = typeof ClipboardEvent !== 'undefined' ? new ClipboardEvent('paste') : null\n\n return tr\n }\n\n const plugins = rules.map(rule => {\n return new Plugin({\n // we register a global drag handler to track the current drag source element\n view(view) {\n const handleDragstart = (event: DragEvent) => {\n dragSourceElement = view.dom.parentElement?.contains(event.target as Element) ? view.dom.parentElement : null\n\n if (dragSourceElement) {\n tiptapDragFromOtherEditor = editor\n }\n }\n\n const handleDragend = () => {\n if (tiptapDragFromOtherEditor) {\n tiptapDragFromOtherEditor = null\n }\n }\n\n window.addEventListener('dragstart', handleDragstart)\n window.addEventListener('dragend', handleDragend)\n\n return {\n destroy() {\n window.removeEventListener('dragstart', handleDragstart)\n window.removeEventListener('dragend', handleDragend)\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n drop: (view, event: Event) => {\n isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement\n dropEvent = event as DragEvent\n\n if (!isDroppedFromProseMirror) {\n const dragFromOtherEditor = tiptapDragFromOtherEditor\n\n if (dragFromOtherEditor?.isEditable) {\n // setTimeout to avoid the wrong content after drop, timeout arg can't be empty or 0\n setTimeout(() => {\n const selection = dragFromOtherEditor.state.selection\n\n if (selection) {\n dragFromOtherEditor.commands.deleteRange({ from: selection.from, to: selection.to })\n }\n }, 10)\n }\n }\n return false\n },\n\n paste: (_view, event: Event) => {\n const html = (event as ClipboardEvent).clipboardData?.getData('text/html')\n\n pasteEvent = event as ClipboardEvent\n\n isPastedFromProseMirror = !!html?.includes('data-pm-slice')\n\n return false\n },\n },\n },\n\n appendTransaction: (transactions, oldState, state) => {\n const transaction = transactions[0]\n const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror\n const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror\n\n // if PasteRule is triggered by insertContent()\n const simulatedPasteMeta = transaction.getMeta('applyPasteRules') as\n | undefined\n | { from: number; text: string | ProseMirrorNode | Fragment }\n const isSimulatedPaste = !!simulatedPasteMeta\n\n if (!isPaste && !isDrop && !isSimulatedPaste) {\n return\n }\n\n // Handle simulated paste\n if (isSimulatedPaste) {\n let { text } = simulatedPasteMeta\n\n if (typeof text === 'string') {\n text = text as string\n } else {\n text = getHTMLFromFragment(Fragment.from(text), state.schema)\n }\n\n const { from } = simulatedPasteMeta\n const to = from + text.length\n\n const pasteEvt = createClipboardPasteEvent(text)\n\n return processEvent({\n rule,\n state,\n from,\n to: { b: to },\n pasteEvt,\n })\n }\n\n // handle actual paste/drop\n const from = oldState.doc.content.findDiffStart(state.doc.content)\n const to = oldState.doc.content.findDiffEnd(state.doc.content)\n\n // stop if there is no changed range\n if (!isNumber(from) || !to || from === to.b) {\n return\n }\n\n return processEvent({\n rule,\n state,\n from,\n to,\n pasteEvt: pasteEvent,\n })\n },\n })\n })\n\n return plugins\n}\n","export function isNumber(value: any): value is number {\n return typeof value === 'number'\n}\n","export { ClipboardTextSerializer } from './clipboardTextSerializer.js'\nexport { Commands } from './commands.js'\nexport { Delete } from './delete.js'\nexport { Drop } from './drop.js'\nexport { Editable } from './editable.js'\nexport { FocusEvents, focusEventsPluginKey } from './focusEvents.js'\nexport { Keymap } from './keymap.js'\nexport { Paste } from './paste.js'\nexport { Tabindex } from './tabindex.js'\nexport { TextDirection } from './textDirection.js'\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\nimport { getTextBetween } from '../helpers/getTextBetween.js'\nimport { getTextSerializersFromSchema } from '../helpers/getTextSerializersFromSchema.js'\n\nexport type ClipboardTextSerializerOptions = {\n blockSeparator?: string\n}\n\nexport const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerOptions>({\n name: 'clipboardTextSerializer',\n\n addOptions() {\n return {\n blockSeparator: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('clipboardTextSerializer'),\n props: {\n clipboardTextSerializer: () => {\n const { editor } = this\n const { state, schema } = editor\n const { doc, selection } = state\n const { ranges } = selection\n const from = Math.min(...ranges.map(range => range.$from.pos))\n const to = Math.max(...ranges.map(range => range.$to.pos))\n const textSerializers = getTextSerializersFromSchema(schema)\n const range = { from, to }\n\n return getTextBetween(doc, range, {\n ...(this.options.blockSeparator !== undefined ? { blockSeparator: this.options.blockSeparator } : {}),\n textSerializers,\n })\n },\n },\n }),\n ]\n },\n})\n","import type { Editor } from './Editor.js'\nimport { type ExtendableConfig, Extendable } from './Extendable.js'\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface ExtensionConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, ExtensionConfig<Options, Storage>, null> {}\n\n/**\n * The Extension class is the base class for all extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Extension<Options = any, Storage = any> extends Extendable<\n Options,\n Storage,\n ExtensionConfig<Options, Storage>\n> {\n type = 'extension'\n\n /**\n * Create a new Extension instance\n * @param config - Extension configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(\n config: Partial<ExtensionConfig<O, S>> | (() => Partial<ExtensionConfig<O, S>>) = {},\n ) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Extension<O, S>(resolvedConfig)\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Extension<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: null\n }>),\n ): Extension<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Extension<ExtendedOptions, ExtendedStorage>\n }\n}\n","import * as commands from '../commands/index.js'\nimport { Extension } from '../Extension.js'\n\nexport * from '../commands/index.js'\n\nexport const Commands = Extension.create({\n name: 'commands',\n\n addCommands() {\n return {\n ...commands,\n }\n },\n})\n","import { RemoveMarkStep } from '@tiptap/pm/transform'\n\nimport { Extension } from '../Extension.js'\nimport { combineTransactionSteps, getChangedRanges } from '../helpers/index.js'\n\n/**\n * This extension allows you to be notified when the user deletes content you are interested in.\n */\nexport const Delete = Extension.create({\n name: 'delete',\n\n onUpdate({ transaction, appendedTransactions }) {\n const callback = () => {\n if (\n this.editor.options.coreExtensionOptions?.delete?.filterTransaction?.(transaction) ??\n transaction.getMeta('y-sync$')\n ) {\n return\n }\n const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions])\n const changes = getChangedRanges(nextTransaction)\n\n changes.forEach(change => {\n if (\n nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter &&\n nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore\n ) {\n nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from) => {\n const to = from + node.nodeSize - 2\n const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to\n\n this.editor.emit('delete', {\n type: 'node',\n node,\n from,\n to,\n newFrom: nextTransaction.mapping.map(from),\n newTo: nextTransaction.mapping.map(to),\n deletedRange: change.oldRange,\n newRange: change.newRange,\n partial: !isFullyWithinRange,\n editor: this.editor,\n transaction,\n combinedTransform: nextTransaction,\n })\n })\n }\n })\n\n const mapping = nextTransaction.mapping\n nextTransaction.steps.forEach((step, index) => {\n if (step instanceof RemoveMarkStep) {\n const newStart = mapping.slice(index).map(step.from, -1)\n const newEnd = mapping.slice(index).map(step.to)\n const oldStart = mapping.invert().map(newStart, -1)\n const oldEnd = mapping.invert().map(newEnd)\n\n const foundBeforeMark = nextTransaction.doc.nodeAt(newStart - 1)?.marks.some(mark => mark.eq(step.mark))\n const foundAfterMark = nextTransaction.doc.nodeAt(newEnd)?.marks.some(mark => mark.eq(step.mark))\n\n this.editor.emit('delete', {\n type: 'mark',\n mark: step.mark,\n from: step.from,\n to: step.to,\n deletedRange: {\n from: oldStart,\n to: oldEnd,\n },\n newRange: {\n from: newStart,\n to: newEnd,\n },\n partial: Boolean(foundAfterMark || foundBeforeMark),\n editor: this.editor,\n transaction,\n combinedTransform: nextTransaction,\n })\n }\n })\n }\n\n if (this.editor.options.coreExtensionOptions?.delete?.async ?? true) {\n setTimeout(callback, 0)\n } else {\n callback()\n }\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Drop = Extension.create({\n name: 'drop',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tiptapDrop'),\n\n props: {\n handleDrop: (_, e, slice, moved) => {\n this.editor.emit('drop', {\n editor: this.editor,\n event: e,\n slice,\n moved,\n })\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Editable = Extension.create({\n name: 'editable',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('editable'),\n props: {\n editable: () => this.editor.options.editable,\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const focusEventsPluginKey = new PluginKey('focusEvents')\n\nexport const FocusEvents = Extension.create({\n name: 'focusEvents',\n\n addProseMirrorPlugins() {\n const { editor } = this\n\n return [\n new Plugin({\n key: focusEventsPluginKey,\n props: {\n handleDOMEvents: {\n focus: (view, event: Event) => {\n editor.isFocused = true\n\n const transaction = editor.state.tr.setMeta('focus', { event }).setMeta('addToHistory', false)\n\n view.dispatch(transaction)\n\n return false\n },\n blur: (view, event: Event) => {\n editor.isFocused = false\n\n const transaction = editor.state.tr.setMeta('blur', { event }).setMeta('addToHistory', false)\n\n view.dispatch(transaction)\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey, Selection } from '@tiptap/pm/state'\n\nimport { CommandManager } from '../CommandManager.js'\nimport { Extension } from '../Extension.js'\nimport { createChainableState } from '../helpers/createChainableState.js'\nimport { isNodeEmpty } from '../helpers/isNodeEmpty.js'\nimport { isiOS } from '../utilities/isiOS.js'\nimport { isMacOS } from '../utilities/isMacOS.js'\n\nexport const Keymap = Extension.create({\n name: 'keymap',\n\n addKeyboardShortcuts() {\n const handleBackspace = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.undoInputRule(),\n\n // maybe convert first text block node to default node\n () =>\n commands.command(({ tr }) => {\n const { selection, doc } = tr\n const { empty, $anchor } = selection\n const { pos, parent } = $anchor\n const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor\n const parentIsIsolating = $parentPos.parent.type.spec.isolating\n\n const parentPos = $anchor.pos - $anchor.parentOffset\n\n const isAtStart =\n parentIsIsolating && $parentPos.parent.childCount === 1\n ? parentPos === $anchor.pos\n : Selection.atStart(doc).from === pos\n\n if (\n !empty ||\n !parent.type.isTextblock ||\n parent.textContent.length ||\n !isAtStart ||\n (isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended\n ) {\n return false\n }\n\n return commands.clearNodes()\n }),\n\n () => commands.deleteSelection(),\n () => commands.joinBackward(),\n () => commands.selectNodeBackward(),\n ])\n\n const handleDelete = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.deleteSelection(),\n () => commands.deleteCurrentNode(),\n () => commands.joinForward(),\n () => commands.selectNodeForward(),\n ])\n\n const handleEnter = () =>\n this.editor.commands.first(({ commands }) => [\n () => commands.newlineInCode(),\n () => commands.createParagraphNear(),\n () => commands.liftEmptyBlock(),\n () => commands.splitBlock(),\n ])\n\n const baseKeymap = {\n Enter: handleEnter,\n 'Mod-Enter': () => this.editor.commands.exitCode(),\n Backspace: handleBackspace,\n 'Mod-Backspace': handleBackspace,\n 'Shift-Backspace': handleBackspace,\n Delete: handleDelete,\n 'Mod-Delete': handleDelete,\n 'Mod-a': () => this.editor.commands.selectAll(),\n }\n\n const pcKeymap = {\n ...baseKeymap,\n }\n\n const macKeymap = {\n ...baseKeymap,\n 'Ctrl-h': handleBackspace,\n 'Alt-Backspace': handleBackspace,\n 'Ctrl-d': handleDelete,\n 'Ctrl-Alt-Backspace': handleDelete,\n 'Alt-Delete': handleDelete,\n 'Alt-d': handleDelete,\n 'Ctrl-a': () => this.editor.commands.selectTextblockStart(),\n 'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),\n }\n\n if (isiOS() || isMacOS()) {\n return macKeymap\n }\n\n return pcKeymap\n },\n\n addProseMirrorPlugins() {\n return [\n // With this plugin we check if the whole document was selected and deleted.\n // In this case we will additionally call `clearNodes()` to convert e.g. a heading\n // to a paragraph if necessary.\n // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well\n // with many other commands.\n new Plugin({\n key: new PluginKey('clearDocument'),\n appendTransaction: (transactions, oldState, newState) => {\n if (transactions.some(tr => tr.getMeta('composition'))) {\n return\n }\n\n const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)\n\n const ignoreTr = transactions.some(transaction => transaction.getMeta('preventClearDocument'))\n\n if (!docChanges || ignoreTr) {\n return\n }\n\n const { empty, from, to } = oldState.selection\n const allFrom = Selection.atStart(oldState.doc).from\n const allEnd = Selection.atEnd(oldState.doc).to\n const allWasSelected = from === allFrom && to === allEnd\n\n if (empty || !allWasSelected) {\n return\n }\n\n const isEmpty = isNodeEmpty(newState.doc)\n\n if (!isEmpty) {\n return\n }\n\n const tr = newState.tr\n const state = createChainableState({\n state: newState,\n transaction: tr,\n })\n const { commands } = new CommandManager({\n editor: this.editor,\n state,\n })\n\n commands.clearNodes()\n\n if (!tr.steps.length) {\n return\n }\n\n return tr\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Paste = Extension.create({\n name: 'paste',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tiptapPaste'),\n\n props: {\n handlePaste: (_view, e, slice) => {\n this.editor.emit('paste', {\n editor: this.editor,\n event: e,\n slice,\n })\n },\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\n\nexport const Tabindex = Extension.create({\n name: 'tabindex',\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('tabindex'),\n props: {\n attributes: (): { [name: string]: string } => (this.editor.isEditable ? { tabindex: '0' } : {}),\n },\n }),\n ]\n },\n})\n","import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { Extension } from '../Extension.js'\nimport { splitExtensions } from '../helpers/splitExtensions.js'\n\nexport interface TextDirectionOptions {\n direction: 'ltr' | 'rtl' | 'auto' | undefined\n}\n\n/**\n * The TextDirection extension adds support for setting text direction (LTR/RTL/auto)\n * on all nodes in the editor.\n *\n * This extension adds a global `dir` attribute to all node types, which can be used\n * to control bidirectional text rendering. The direction can be set globally via\n * editor options or per-node using commands.\n */\nexport const TextDirection = Extension.create<TextDirectionOptions>({\n name: 'textDirection',\n\n addOptions() {\n return {\n direction: undefined,\n }\n },\n\n addGlobalAttributes() {\n // Only add the dir attribute to nodes if text direction is configured\n // This prevents null/undefined values from appearing in JSON exports\n if (!this.options.direction) {\n return []\n }\n\n const { nodeExtensions } = splitExtensions(this.extensions)\n\n return [\n {\n types: nodeExtensions.filter(extension => extension.name !== 'text').map(extension => extension.name),\n attributes: {\n dir: {\n default: this.options.direction,\n parseHTML: element => {\n const dir = element.getAttribute('dir')\n\n if (dir && (dir === 'ltr' || dir === 'rtl' || dir === 'auto')) {\n return dir\n }\n\n return this.options.direction\n },\n renderHTML: attributes => {\n if (!attributes.dir) {\n return {}\n }\n\n return {\n dir: attributes.dir,\n }\n },\n },\n },\n },\n ]\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('textDirection'),\n props: {\n attributes: (): { [name: string]: string } => {\n const direction = this.options.direction\n\n if (!direction) {\n return {}\n }\n\n return {\n dir: direction,\n }\n },\n },\n }),\n ]\n },\n})\n","import type { Fragment, Node, ResolvedPos } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { Content, Range } from './types.js'\n\nexport class NodePos {\n private resolvedPos: ResolvedPos\n\n private isBlock: boolean\n\n private editor: Editor\n\n private get name(): string {\n return this.node.type.name\n }\n\n constructor(pos: ResolvedPos, editor: Editor, isBlock = false, node: Node | null = null) {\n this.isBlock = isBlock\n this.resolvedPos = pos\n this.editor = editor\n this.currentNode = node\n }\n\n private currentNode: Node | null = null\n\n get node(): Node {\n return this.currentNode || this.resolvedPos.node()\n }\n\n get element(): HTMLElement {\n return this.editor.view.domAtPos(this.pos).node as HTMLElement\n }\n\n public actualDepth: number | null = null\n\n get depth(): number {\n return this.actualDepth ?? this.resolvedPos.depth\n }\n\n get pos(): number {\n return this.resolvedPos.pos\n }\n\n get content(): Fragment {\n return this.node.content\n }\n\n set content(content: Content) {\n let from = this.from\n let to = this.to\n\n if (this.isBlock) {\n if (this.content.size === 0) {\n console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`)\n return\n }\n\n from = this.from + 1\n to = this.to - 1\n }\n\n this.editor.commands.insertContentAt({ from, to }, content)\n }\n\n get attributes(): { [key: string]: any } {\n return this.node.attrs\n }\n\n get textContent(): string {\n return this.node.textContent\n }\n\n get size(): number {\n return this.node.nodeSize\n }\n\n get from(): number {\n if (this.isBlock) {\n return this.pos\n }\n\n return this.resolvedPos.start(this.resolvedPos.depth)\n }\n\n get range(): Range {\n return {\n from: this.from,\n to: this.to,\n }\n }\n\n get to(): number {\n if (this.isBlock) {\n return this.pos + this.size\n }\n\n return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1)\n }\n\n get parent(): NodePos | null {\n if (this.depth === 0) {\n return null\n }\n\n const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1)\n const $pos = this.resolvedPos.doc.resolve(parentPos)\n\n return new NodePos($pos, this.editor)\n }\n\n get before(): NodePos | null {\n let $pos = this.resolvedPos.doc.resolve(this.from - (this.isBlock ? 1 : 2))\n\n if ($pos.depth !== this.depth) {\n $pos = this.resolvedPos.doc.resolve(this.from - 3)\n }\n\n return new NodePos($pos, this.editor)\n }\n\n get after(): NodePos | null {\n let $pos = this.resolvedPos.doc.resolve(this.to + (this.isBlock ? 2 : 1))\n\n if ($pos.depth !== this.depth) {\n $pos = this.resolvedPos.doc.resolve(this.to + 3)\n }\n\n return new NodePos($pos, this.editor)\n }\n\n get children(): NodePos[] {\n const children: NodePos[] = []\n\n this.node.content.forEach((node, offset) => {\n const isBlock = node.isBlock && !node.isTextblock\n const isNonTextAtom = node.isAtom && !node.isText\n\n const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)\n\n // Check if targetPos is within valid document range\n if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {\n return\n }\n\n const $pos = this.resolvedPos.doc.resolve(targetPos)\n\n if (!isBlock && $pos.depth <= this.depth) {\n return\n }\n\n const childNodePos = new NodePos($pos, this.editor, isBlock, isBlock ? node : null)\n\n if (isBlock) {\n childNodePos.actualDepth = this.depth + 1\n }\n\n children.push(new NodePos($pos, this.editor, isBlock, isBlock ? node : null))\n })\n\n return children\n }\n\n get firstChild(): NodePos | null {\n return this.children[0] || null\n }\n\n get lastChild(): NodePos | null {\n const children = this.children\n\n return children[children.length - 1] || null\n }\n\n closest(selector: string, attributes: { [key: string]: any } = {}): NodePos | null {\n let node: NodePos | null = null\n let currentNode = this.parent\n\n while (currentNode && !node) {\n if (currentNode.node.type.name === selector) {\n if (Object.keys(attributes).length > 0) {\n const nodeAttributes = currentNode.node.attrs\n const attrKeys = Object.keys(attributes)\n\n for (let index = 0; index < attrKeys.length; index += 1) {\n const key = attrKeys[index]\n\n if (nodeAttributes[key] !== attributes[key]) {\n break\n }\n }\n } else {\n node = currentNode\n }\n }\n\n currentNode = currentNode.parent\n }\n\n return node\n }\n\n querySelector(selector: string, attributes: { [key: string]: any } = {}): NodePos | null {\n return this.querySelectorAll(selector, attributes, true)[0] || null\n }\n\n querySelectorAll(selector: string, attributes: { [key: string]: any } = {}, firstItemOnly = false): NodePos[] {\n let nodes: NodePos[] = []\n\n if (!this.children || this.children.length === 0) {\n return nodes\n }\n const attrKeys = Object.keys(attributes)\n\n /**\n * Finds all children recursively that match the selector and attributes\n * If firstItemOnly is true, it will return the first item found\n */\n this.children.forEach(childPos => {\n // If we already found a node and we only want the first item, we dont need to keep going\n if (firstItemOnly && nodes.length > 0) {\n return\n }\n\n if (childPos.node.type.name === selector) {\n const doesAllAttributesMatch = attrKeys.every(key => attributes[key] === childPos.node.attrs[key])\n\n if (doesAllAttributesMatch) {\n nodes.push(childPos)\n }\n }\n\n // If we already found a node and we only want the first item, we can stop here and skip the recursion\n if (firstItemOnly && nodes.length > 0) {\n return\n }\n\n nodes = nodes.concat(childPos.querySelectorAll(selector, attributes, firstItemOnly))\n })\n\n return nodes\n }\n\n setAttribute(attributes: { [key: string]: any }) {\n const { tr } = this.editor.state\n\n tr.setNodeMarkup(this.from, undefined, {\n ...this.node.attrs,\n ...attributes,\n })\n\n this.editor.view.dispatch(tr)\n }\n}\n","export const style = `.ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n font-feature-settings: \"liga\" 0; /* the above doesn't seem to work in Edge */\n}\n\n.ProseMirror [contenteditable=\"false\"] {\n white-space: normal;\n}\n\n.ProseMirror [contenteditable=\"false\"] [contenteditable=\"true\"] {\n white-space: pre-wrap;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\nimg.ProseMirror-separator {\n display: inline !important;\n border: none !important;\n margin: 0 !important;\n width: 0 !important;\n height: 0 !important;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n margin: 0;\n}\n\n.ProseMirror-gapcursor:after {\n content: \"\";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}`\n","export function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement {\n const tiptapStyleTag = <HTMLStyleElement>(\n document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`)\n )\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarksBetween } from '../helpers/getMarksBetween.js'\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that adds a mark when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function markInputRule(config: {\n find: InputRuleFinder\n type: MarkType\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const { tr } = state\n const captureGroup = match[match.length - 1]\n const fullMatch = match[0]\n\n if (captureGroup) {\n const startSpaces = fullMatch.search(/\\S/)\n const textStart = range.from + fullMatch.indexOf(captureGroup)\n const textEnd = textStart + captureGroup.length\n\n const excludedMarks = getMarksBetween(range.from, range.to, state.doc)\n .filter(item => {\n // @ts-ignore\n const excluded = item.mark.type.excluded as MarkType[]\n\n return excluded.find(type => type === config.type && type !== item.mark.type)\n })\n .filter(item => item.to > textStart)\n\n if (excludedMarks.length) {\n return null\n }\n\n if (textEnd < range.to) {\n tr.delete(textEnd, range.to)\n }\n\n if (textStart > range.from) {\n tr.delete(range.from + startSpaces, textStart)\n }\n\n const markEnd = range.from + startSpaces + captureGroup.length\n\n tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}))\n\n tr.removeStoredMark(config.type)\n }\n },\n undoable: config.undoable,\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that adds a node when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function nodeInputRule(config: {\n /**\n * The regex to match.\n */\n find: InputRuleFinder\n\n /**\n * The node type to add.\n */\n type: NodeType\n\n /**\n * Whether the input rule should be undoable\n * when the user presses backspace.\n */\n undoable?: boolean\n\n /**\n * A function that returns the attributes for the node\n * can also be an object of attributes\n */\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n const { tr } = state\n const start = range.from\n let end = range.to\n\n const newNode = config.type.create(attributes)\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n let matchStart = start + offset\n\n if (matchStart > end) {\n matchStart = end\n } else {\n end = matchStart + match[1].length\n }\n\n // insert last typed character\n const lastChar = match[0][match[0].length - 1]\n\n tr.insertText(lastChar, start + match[0].length - 1)\n\n // insert node from input rule\n tr.replaceWith(matchStart, end, newNode)\n } else if (match[0]) {\n const insertionStart = config.type.isInline ? start : start - 1\n\n tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end))\n }\n\n tr.scrollIntoView()\n },\n undoable: config.undoable,\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule that changes the type of a textblock when the\n * matched text is typed into it. When using a regular expresion you’ll\n * probably want the regexp to start with `^`, so that the pattern can\n * only occur at the start of a textblock.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function textblockTypeInputRule(config: {\n find: InputRuleFinder\n type: NodeType\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n const $start = state.doc.resolve(range.from)\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n\n if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), config.type)) {\n return null\n }\n\n state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes)\n },\n undoable: config.undoable,\n })\n}\n","import type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\n\n/**\n * Build an input rule that replaces text when the\n * matched text is typed into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function textInputRule(config: { find: InputRuleFinder; replace: string; undoable?: boolean }) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n let insert = config.replace\n let start = range.from\n const end = range.to\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n\n insert += match[0].slice(offset + match[1].length)\n start += offset\n\n const cutOff = start - end\n\n if (cutOff > 0) {\n insert = match[0].slice(offset - cutOff, offset) + insert\n start = end\n }\n }\n\n state.tr.insertText(insert, start, end)\n },\n undoable: config.undoable,\n })\n}\n","import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'\nimport { canJoin, findWrapping } from '@tiptap/pm/transform'\n\nimport type { Editor } from '../Editor.js'\nimport type { InputRuleFinder } from '../InputRule.js'\nimport { InputRule } from '../InputRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an input rule for automatically wrapping a textblock when a\n * given string is typed. When using a regular expresion you’ll\n * probably want the regexp to start with `^`, so that the pattern can\n * only occur at the start of a textblock.\n *\n * `type` is the type of node to wrap in.\n *\n * By default, if there’s a node with the same type above the newly\n * wrapped node, the rule will try to join those\n * two nodes. You can pass a join predicate, which takes a regular\n * expression match and the node before the wrapped node, and can\n * return a boolean to indicate whether a join should happen.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules\n */\nexport function wrappingInputRule(config: {\n find: InputRuleFinder\n type: NodeType\n keepMarks?: boolean\n keepAttributes?: boolean\n editor?: Editor\n undoable?: boolean\n getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null\n joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean\n}) {\n return new InputRule({\n find: config.find,\n handler: ({ state, range, match, chain }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match) || {}\n const tr = state.tr.delete(range.from, range.to)\n const $start = tr.doc.resolve(range.from)\n const blockRange = $start.blockRange()\n const wrapping = blockRange && findWrapping(blockRange, config.type, attributes)\n\n if (!wrapping) {\n return null\n }\n\n tr.wrap(blockRange, wrapping)\n\n if (config.keepMarks && config.editor) {\n const { selection, storedMarks } = state\n const { splittableMarks } = config.editor.extensionManager\n const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())\n\n if (marks) {\n const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))\n\n tr.ensureMarks(filteredMarks)\n }\n }\n if (config.keepAttributes) {\n /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */\n const nodeType =\n config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList'\n\n chain().updateAttributes(nodeType, attributes).run()\n }\n\n const before = tr.doc.resolve(range.from - 1).nodeBefore\n\n if (\n before &&\n before.type === config.type &&\n canJoin(tr.doc, range.from - 1) &&\n (!config.joinPredicate || config.joinPredicate(match, before))\n ) {\n tr.join(range.from - 1)\n }\n },\n undoable: config.undoable,\n })\n}\n","export type Attributes = Record<string, any>\n\nexport type DOMOutputSpecElement = 0 | Attributes | DOMOutputSpecArray\n/**\n * Better describes the output of a `renderHTML` function in prosemirror\n * @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec\n */\nexport type DOMOutputSpecArray =\n | [string]\n | [string, Attributes]\n | [string, 0]\n | [string, Attributes, 0]\n | [string, Attributes, DOMOutputSpecArray | 0]\n | [string, DOMOutputSpecArray]\n\n// JSX types for Tiptap's JSX runtime\n// These types only apply when using @jsxImportSource @tiptap/core\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace JSX {\n export type Element = DOMOutputSpecArray\n export interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n }\n export interface ElementChildrenAttribute {\n children: unknown\n }\n}\n\nexport type JSXRenderer = (\n tag: 'slot' | string | ((props?: Attributes) => DOMOutputSpecArray | DOMOutputSpecElement),\n props?: Attributes,\n ...children: JSXRenderer[]\n) => DOMOutputSpecArray | DOMOutputSpecElement\n\nexport function Fragment(props: { children: JSXRenderer[] }) {\n return props.children\n}\n\nexport const h: JSXRenderer = (tag, attributes) => {\n // Treat the slot tag as the Prosemirror hole to render content into\n if (tag === 'slot') {\n return 0\n }\n\n // If the tag is a function, call it with the props\n if (tag instanceof Function) {\n return tag(attributes)\n }\n\n const { children, ...rest } = attributes ?? {}\n\n if (tag === 'svg') {\n throw new Error('SVG elements are not supported in the JSX syntax, use the array syntax instead')\n }\n\n // Otherwise, return the tag, attributes, and children\n return [tag, rest, children]\n}\n\n// See\n// https://esbuild.github.io/api/#jsx-import-source\n// https://www.typescriptlang.org/tsconfig/#jsxImportSource\n\nexport { h as createElement, h as jsx, h as jsxDEV, h as jsxs }\n","import type { Node as PMNode } from '@tiptap/pm/model'\nimport type { Decoration, DecorationSource, NodeView } from '@tiptap/pm/view'\n\nimport type { Editor } from '../Editor.js'\n\nconst isTouchEvent = (e: MouseEvent | TouchEvent): e is TouchEvent => {\n return 'touches' in e\n}\n\n/**\n * Directions where resize handles can be placed\n *\n * @example\n * - `'top'` - Top edge handle\n * - `'bottom-right'` - Bottom-right corner handle\n */\nexport type ResizableNodeViewDirection =\n | 'top'\n | 'right'\n | 'bottom'\n | 'left'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-left'\n\n/**\n * Dimensions for the resizable node in pixels\n */\nexport type ResizableNodeDimensions = {\n /** Width in pixels */\n width: number\n /** Height in pixels */\n height: number\n}\n\n/**\n * Configuration options for creating a ResizableNodeView\n *\n * @example\n * ```ts\n * new ResizableNodeView({\n * element: imgElement,\n * node,\n * getPos,\n * onResize: (width, height) => {\n * imgElement.style.width = `${width}px`\n * imgElement.style.height = `${height}px`\n * },\n * onCommit: (width, height) => {\n * editor.commands.updateAttributes('image', { width, height })\n * },\n * onUpdate: (node) => true,\n * options: {\n * directions: ['bottom-right', 'bottom-left'],\n * min: { width: 100, height: 100 },\n * preserveAspectRatio: true\n * }\n * })\n * ```\n */\nexport type ResizableNodeViewOptions = {\n /**\n * The DOM element to make resizable (e.g., an img, video, or iframe element)\n */\n element: HTMLElement\n\n /**\n * The DOM element that will hold the editable content element\n */\n contentElement?: HTMLElement\n\n /**\n * The ProseMirror node instance\n */\n node: PMNode\n\n /**\n * The Tiptap editor instance\n */\n editor: Editor\n\n /**\n * Function that returns the current position of the node in the document\n */\n getPos: () => number | undefined\n\n /**\n * Callback fired continuously during resize with current dimensions.\n * Use this to update the element's visual size in real-time.\n *\n * @param width - Current width in pixels\n * @param height - Current height in pixels\n *\n * @example\n * ```ts\n * onResize: (width, height) => {\n * element.style.width = `${width}px`\n * element.style.height = `${height}px`\n * }\n * ```\n */\n onResize?: (width: number, height: number) => void\n\n /**\n * Callback fired once when resize completes with final dimensions.\n * Use this to persist the new size to the node's attributes.\n *\n * @param width - Final width in pixels\n * @param height - Final height in pixels\n *\n * @example\n * ```ts\n * onCommit: (width, height) => {\n * const pos = getPos()\n * if (pos !== undefined) {\n * editor.commands.updateAttributes('image', { width, height })\n * }\n * }\n * ```\n */\n onCommit: (width: number, height: number) => void\n\n /**\n * Callback for handling node updates.\n * Return `true` to accept the update, `false` to reject it.\n *\n * @example\n * ```ts\n * onUpdate: (node, decorations, innerDecorations) => {\n * if (node.type !== this.node.type) return false\n * return true\n * }\n * ```\n */\n onUpdate: NodeView['update']\n\n /**\n * Optional configuration for resize behavior and styling\n */\n options?: {\n /**\n * Which resize handles to display.\n * @default ['bottom-left', 'bottom-right', 'top-left', 'top-right']\n *\n * @example\n * ```ts\n * // Only show corner handles\n * directions: ['top-left', 'top-right', 'bottom-left', 'bottom-right']\n *\n * // Only show right edge handle\n * directions: ['right']\n * ```\n */\n directions?: ResizableNodeViewDirection[]\n\n /**\n * Minimum dimensions in pixels\n * @default { width: 8, height: 8 }\n *\n * @example\n * ```ts\n * min: { width: 100, height: 50 }\n * ```\n */\n min?: Partial<ResizableNodeDimensions>\n\n /**\n * Maximum dimensions in pixels\n * @default undefined (no maximum)\n *\n * @example\n * ```ts\n * max: { width: 1000, height: 800 }\n * ```\n */\n max?: Partial<ResizableNodeDimensions>\n\n /**\n * Always preserve aspect ratio when resizing.\n * When `false`, aspect ratio is preserved only when Shift key is pressed.\n * @default false\n *\n * @example\n * ```ts\n * preserveAspectRatio: true // Always lock aspect ratio\n * ```\n */\n preserveAspectRatio?: boolean\n\n /**\n * Custom CSS class names for styling\n *\n * @example\n * ```ts\n * className: {\n * container: 'resize-container',\n * wrapper: 'resize-wrapper',\n * handle: 'resize-handle',\n * resizing: 'is-resizing'\n * }\n * ```\n */\n className?: {\n /** Class for the outer container element */\n container?: string\n /** Class for the wrapper element that contains the resizable element */\n wrapper?: string\n /** Class applied to all resize handles */\n handle?: string\n /** Class added to container while actively resizing */\n resizing?: string\n }\n\n /**\n * Optional callback for creating custom resize handle elements.\n *\n * This function allows developers to define their own handle element\n * (e.g., custom icons, classes, or styles) for a given resize direction.\n * It is called internally for each handle direction.\n *\n * @param direction - The direction of the handle being created (e.g., 'top', 'bottom-right').\n * @returns The custom handle HTMLElement.\n *\n * @example\n * ```ts\n * createCustomHandle: (direction) => {\n * const handle = document.createElement('div')\n * handle.dataset.resizeHandle = direction\n * handle.style.position = 'absolute'\n * handle.className = 'tiptap-custom-handle'\n *\n * const isTop = direction.includes('top')\n * const isBottom = direction.includes('bottom')\n * const isLeft = direction.includes('left')\n * const isRight = direction.includes('right')\n *\n * if (isTop) handle.style.top = '0'\n * if (isBottom) handle.style.bottom = '0'\n * if (isLeft) handle.style.left = '0'\n * if (isRight) handle.style.right = '0'\n *\n * // Edge handles span the full width or height\n * if (direction === 'top' || direction === 'bottom') {\n * handle.style.left = '0'\n * handle.style.right = '0'\n * }\n *\n * if (direction === 'left' || direction === 'right') {\n * handle.style.top = '0'\n * handle.style.bottom = '0'\n * }\n *\n * return handle\n * }\n * ```\n */\n createCustomHandle?: (direction: ResizableNodeViewDirection) => HTMLElement\n }\n}\n\n/**\n * A NodeView implementation that adds resize handles to any DOM element.\n *\n * This class creates a resizable node view for Tiptap/ProseMirror editors.\n * It wraps your element with resize handles and manages the resize interaction,\n * including aspect ratio preservation, min/max constraints, and keyboard modifiers.\n *\n * @example\n * ```ts\n * // Basic usage in a Tiptap extension\n * addNodeView() {\n * return ({ node, getPos }) => {\n * const img = document.createElement('img')\n * img.src = node.attrs.src\n *\n * return new ResizableNodeView({\n * element: img,\n * node,\n * getPos,\n * onResize: (width, height) => {\n * img.style.width = `${width}px`\n * img.style.height = `${height}px`\n * },\n * onCommit: (width, height) => {\n * this.editor.commands.updateAttributes('image', { width, height })\n * },\n * onUpdate: () => true,\n * options: {\n * min: { width: 100, height: 100 },\n * preserveAspectRatio: true\n * }\n * })\n * }\n * }\n * ```\n */\nexport class ResizableNodeView {\n /** The ProseMirror node instance */\n node: PMNode\n\n /** The Tiptap editor instance */\n editor: Editor\n\n /** The DOM element being made resizable */\n element: HTMLElement\n\n /** The editable DOM element inside the DOM */\n contentElement?: HTMLElement\n\n /** The outer container element (returned as NodeView.dom) */\n container: HTMLElement\n\n /** The wrapper element that contains the element and handles */\n wrapper: HTMLElement\n\n /** Function to get the current node position */\n getPos: () => number | undefined\n\n /** Callback fired during resize */\n onResize?: (width: number, height: number) => void\n\n /** Callback fired when resize completes */\n onCommit: (width: number, height: number) => void\n\n /** Callback for node updates */\n onUpdate?: NodeView['update']\n\n /** Active resize handle directions */\n directions: ResizableNodeViewDirection[] = ['bottom-left', 'bottom-right', 'top-left', 'top-right']\n\n /** Minimum allowed dimensions */\n minSize: ResizableNodeDimensions = {\n height: 8,\n width: 8,\n }\n\n /** Maximum allowed dimensions (optional) */\n maxSize?: Partial<ResizableNodeDimensions>\n\n /** Whether to always preserve aspect ratio */\n preserveAspectRatio: boolean = false\n\n /** CSS class names for elements */\n classNames = {\n container: '',\n wrapper: '',\n handle: '',\n resizing: '',\n }\n\n /** Optional callback for creating custom resize handles */\n createCustomHandle?: (direction: ResizableNodeViewDirection) => HTMLElement\n\n /** Initial width of the element (for aspect ratio calculation) */\n private initialWidth: number = 0\n\n /** Initial height of the element (for aspect ratio calculation) */\n private initialHeight: number = 0\n\n /** Calculated aspect ratio (width / height) */\n private aspectRatio: number = 1\n\n /** Whether a resize operation is currently active */\n private isResizing: boolean = false\n\n /** The handle currently being dragged */\n private activeHandle: ResizableNodeViewDirection | null = null\n\n /** Starting mouse X position when resize began */\n private startX: number = 0\n\n /** Starting mouse Y position when resize began */\n private startY: number = 0\n\n /** Element width when resize began */\n private startWidth: number = 0\n\n /** Element height when resize began */\n private startHeight: number = 0\n\n /** Whether Shift key is currently pressed (for temporary aspect ratio lock) */\n private isShiftKeyPressed: boolean = false\n\n /** Last known editable state of the editor */\n private lastEditableState: boolean | undefined = undefined\n\n /** Map of handle elements by direction */\n private handleMap = new Map<ResizableNodeViewDirection, HTMLElement>()\n\n /**\n * Creates a new ResizableNodeView instance.\n *\n * The constructor sets up the resize handles, applies initial sizing from\n * node attributes, and configures all resize behavior options.\n *\n * @param options - Configuration options for the resizable node view\n */\n constructor(options: ResizableNodeViewOptions) {\n this.node = options.node\n this.editor = options.editor\n this.element = options.element\n this.contentElement = options.contentElement\n\n this.getPos = options.getPos\n\n this.onResize = options.onResize\n this.onCommit = options.onCommit\n this.onUpdate = options.onUpdate\n\n if (options.options?.min) {\n this.minSize = {\n ...this.minSize,\n ...options.options.min,\n }\n }\n\n if (options.options?.max) {\n this.maxSize = options.options.max\n }\n\n if (options?.options?.directions) {\n this.directions = options.options.directions\n }\n\n if (options.options?.preserveAspectRatio) {\n this.preserveAspectRatio = options.options.preserveAspectRatio\n }\n\n if (options.options?.className) {\n this.classNames = {\n container: options.options.className.container || '',\n wrapper: options.options.className.wrapper || '',\n handle: options.options.className.handle || '',\n resizing: options.options.className.resizing || '',\n }\n }\n\n if (options.options?.createCustomHandle) {\n this.createCustomHandle = options.options.createCustomHandle\n }\n\n this.wrapper = this.createWrapper()\n this.container = this.createContainer()\n\n this.applyInitialSize()\n this.attachHandles()\n\n this.editor.on('update', this.handleEditorUpdate.bind(this))\n }\n\n /**\n * Returns the top-level DOM node that should be placed in the editor.\n *\n * This is required by the ProseMirror NodeView interface. The container\n * includes the wrapper, handles, and the actual content element.\n *\n * @returns The container element to be inserted into the editor\n */\n get dom() {\n return this.container\n }\n\n get contentDOM() {\n return this.contentElement\n }\n\n private handleEditorUpdate() {\n const isEditable = this.editor.isEditable\n\n // Only if state actually changed\n if (isEditable === this.lastEditableState) {\n return\n }\n\n this.lastEditableState = isEditable\n\n if (!isEditable) {\n this.removeHandles()\n } else if (isEditable && this.handleMap.size === 0) {\n this.attachHandles()\n }\n }\n\n /**\n * Called when the node's content or attributes change.\n *\n * Updates the internal node reference. If a custom `onUpdate` callback\n * was provided, it will be called to handle additional update logic.\n *\n * @param node - The new/updated node\n * @param decorations - Node decorations\n * @param innerDecorations - Inner decorations\n * @returns `false` if the node type has changed (requires full rebuild), otherwise the result of `onUpdate` or `true`\n */\n update(node: PMNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n\n if (this.onUpdate) {\n return this.onUpdate(node, decorations, innerDecorations)\n }\n\n return true\n }\n\n /**\n * Cleanup method called when the node view is being removed.\n *\n * Removes all event listeners to prevent memory leaks. This is required\n * by the ProseMirror NodeView interface. If a resize is active when\n * destroy is called, it will be properly cancelled.\n */\n destroy() {\n if (this.isResizing) {\n this.container.dataset.resizeState = 'false'\n\n if (this.classNames.resizing) {\n this.container.classList.remove(this.classNames.resizing)\n }\n\n document.removeEventListener('mousemove', this.handleMouseMove)\n document.removeEventListener('mouseup', this.handleMouseUp)\n document.removeEventListener('keydown', this.handleKeyDown)\n document.removeEventListener('keyup', this.handleKeyUp)\n this.isResizing = false\n this.activeHandle = null\n }\n\n this.editor.off('update', this.handleEditorUpdate.bind(this))\n\n this.container.remove()\n }\n\n /**\n * Creates the outer container element.\n *\n * The container is the top-level element returned by the NodeView and\n * wraps the entire resizable node. It's set up with flexbox to handle\n * alignment and includes data attributes for styling and identification.\n *\n * @returns The container element\n */\n createContainer() {\n const element = document.createElement('div')\n element.dataset.resizeContainer = ''\n element.dataset.node = this.node.type.name\n element.style.display = 'flex'\n\n if (this.classNames.container) {\n element.className = this.classNames.container\n }\n\n element.appendChild(this.wrapper)\n\n return element\n }\n\n /**\n * Creates the wrapper element that contains the content and handles.\n *\n * The wrapper uses relative positioning so that resize handles can be\n * positioned absolutely within it. This is the direct parent of the\n * content element being made resizable.\n *\n * @returns The wrapper element\n */\n createWrapper() {\n const element = document.createElement('div')\n element.style.position = 'relative'\n element.style.display = 'block'\n element.dataset.resizeWrapper = ''\n\n if (this.classNames.wrapper) {\n element.className = this.classNames.wrapper\n }\n\n element.appendChild(this.element)\n\n return element\n }\n\n /**\n * Creates a resize handle element for a specific direction.\n *\n * Each handle is absolutely positioned and includes a data attribute\n * identifying its direction for styling purposes.\n *\n * @param direction - The resize direction for this handle\n * @returns The handle element\n */\n private createHandle(direction: ResizableNodeViewDirection): HTMLElement {\n const handle = document.createElement('div')\n handle.dataset.resizeHandle = direction\n handle.style.position = 'absolute'\n\n if (this.classNames.handle) {\n handle.className = this.classNames.handle\n }\n\n return handle\n }\n\n /**\n * Positions a handle element according to its direction.\n *\n * Corner handles (e.g., 'top-left') are positioned at the intersection\n * of two edges. Edge handles (e.g., 'top') span the full width or height.\n *\n * @param handle - The handle element to position\n * @param direction - The direction determining the position\n */\n private positionHandle(handle: HTMLElement, direction: ResizableNodeViewDirection): void {\n const isTop = direction.includes('top')\n const isBottom = direction.includes('bottom')\n const isLeft = direction.includes('left')\n const isRight = direction.includes('right')\n\n if (isTop) {\n handle.style.top = '0'\n }\n\n if (isBottom) {\n handle.style.bottom = '0'\n }\n\n if (isLeft) {\n handle.style.left = '0'\n }\n\n if (isRight) {\n handle.style.right = '0'\n }\n\n // Edge handles span the full width or height\n if (direction === 'top' || direction === 'bottom') {\n handle.style.left = '0'\n handle.style.right = '0'\n }\n\n if (direction === 'left' || direction === 'right') {\n handle.style.top = '0'\n handle.style.bottom = '0'\n }\n }\n\n /**\n * Creates and attaches all resize handles to the wrapper.\n *\n * Iterates through the configured directions, creates a handle for each,\n * positions it, attaches the mousedown listener, and appends it to the DOM.\n */\n private attachHandles(): void {\n this.directions.forEach(direction => {\n let handle: HTMLElement\n\n if (this.createCustomHandle) {\n handle = this.createCustomHandle(direction)\n } else {\n handle = this.createHandle(direction)\n }\n\n if (!(handle instanceof HTMLElement)) {\n console.warn(\n `[ResizableNodeView] createCustomHandle(\"${direction}\") did not return an HTMLElement. Falling back to default handle.`,\n )\n handle = this.createHandle(direction)\n }\n\n if (!this.createCustomHandle) {\n this.positionHandle(handle, direction)\n }\n\n handle.addEventListener('mousedown', event => this.handleResizeStart(event, direction))\n handle.addEventListener('touchstart', event => this.handleResizeStart(event as unknown as MouseEvent, direction))\n\n this.handleMap.set(direction, handle)\n\n this.wrapper.appendChild(handle)\n })\n }\n\n /**\n * Removes all resize handles from the wrapper.\n *\n * Cleans up the handle map and removes each handle element from the DOM.\n */\n private removeHandles(): void {\n this.handleMap.forEach(el => el.remove())\n this.handleMap.clear()\n }\n\n /**\n * Applies initial sizing from node attributes to the element.\n *\n * If width/height attributes exist on the node, they're applied to the element.\n * Otherwise, the element's natural/current dimensions are measured. The aspect\n * ratio is calculated for later use in aspect-ratio-preserving resizes.\n */\n private applyInitialSize(): void {\n const width = this.node.attrs.width as number | undefined\n const height = this.node.attrs.height as number | undefined\n\n if (width) {\n this.element.style.width = `${width}px`\n this.initialWidth = width\n } else {\n this.initialWidth = this.element.offsetWidth\n }\n\n if (height) {\n this.element.style.height = `${height}px`\n this.initialHeight = height\n } else {\n this.initialHeight = this.element.offsetHeight\n }\n\n // Calculate aspect ratio for use during resizing\n if (this.initialWidth > 0 && this.initialHeight > 0) {\n this.aspectRatio = this.initialWidth / this.initialHeight\n }\n }\n\n /**\n * Initiates a resize operation when a handle is clicked.\n *\n * Captures the starting mouse position and element dimensions, sets up\n * the resize state, adds the resizing class and state attribute, and\n * attaches document-level listeners for mouse movement and keyboard input.\n *\n * @param event - The mouse down event\n * @param direction - The direction of the handle being dragged\n */\n private handleResizeStart(event: MouseEvent | TouchEvent, direction: ResizableNodeViewDirection): void {\n event.preventDefault()\n event.stopPropagation()\n\n // Capture initial state\n this.isResizing = true\n this.activeHandle = direction\n\n if (isTouchEvent(event)) {\n this.startX = event.touches[0].clientX\n this.startY = event.touches[0].clientY\n } else {\n this.startX = event.clientX\n this.startY = event.clientY\n }\n\n this.startWidth = this.element.offsetWidth\n this.startHeight = this.element.offsetHeight\n\n // Recalculate aspect ratio at resize start for accuracy\n if (this.startWidth > 0 && this.startHeight > 0) {\n this.aspectRatio = this.startWidth / this.startHeight\n }\n\n const pos = this.getPos()\n if (pos !== undefined) {\n // TODO: Select the node in the editor\n }\n\n // Update UI state\n this.container.dataset.resizeState = 'true'\n\n if (this.classNames.resizing) {\n this.container.classList.add(this.classNames.resizing)\n }\n\n // Attach document-level listeners for resize\n document.addEventListener('mousemove', this.handleMouseMove)\n document.addEventListener('touchmove', this.handleTouchMove)\n document.addEventListener('mouseup', this.handleMouseUp)\n document.addEventListener('keydown', this.handleKeyDown)\n document.addEventListener('keyup', this.handleKeyUp)\n }\n\n /**\n * Handles mouse movement during an active resize.\n *\n * Calculates the delta from the starting position, computes new dimensions\n * based on the active handle direction, applies constraints and aspect ratio,\n * then updates the element's style and calls the onResize callback.\n *\n * @param event - The mouse move event\n */\n private handleMouseMove = (event: MouseEvent): void => {\n if (!this.isResizing || !this.activeHandle) {\n return\n }\n\n const deltaX = event.clientX - this.startX\n const deltaY = event.clientY - this.startY\n\n this.handleResize(deltaX, deltaY)\n }\n\n private handleTouchMove = (event: TouchEvent): void => {\n if (!this.isResizing || !this.activeHandle) {\n return\n }\n\n const touch = event.touches[0]\n if (!touch) {\n return\n }\n\n const deltaX = touch.clientX - this.startX\n const deltaY = touch.clientY - this.startY\n\n this.handleResize(deltaX, deltaY)\n }\n\n private handleResize(deltaX: number, deltaY: number) {\n if (!this.activeHandle) {\n return\n }\n\n const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed\n const { width, height } = this.calculateNewDimensions(this.activeHandle, deltaX, deltaY)\n const constrained = this.applyConstraints(width, height, shouldPreserveAspectRatio)\n\n this.element.style.width = `${constrained.width}px`\n this.element.style.height = `${constrained.height}px`\n\n if (this.onResize) {\n this.onResize(constrained.width, constrained.height)\n }\n }\n\n /**\n * Completes the resize operation when the mouse button is released.\n *\n * Captures final dimensions, calls the onCommit callback to persist changes,\n * removes the resizing state and class, and cleans up document-level listeners.\n */\n private handleMouseUp = (): void => {\n if (!this.isResizing) {\n return\n }\n\n const finalWidth = this.element.offsetWidth\n const finalHeight = this.element.offsetHeight\n\n this.onCommit(finalWidth, finalHeight)\n\n this.isResizing = false\n this.activeHandle = null\n\n // Remove UI state\n this.container.dataset.resizeState = 'false'\n\n if (this.classNames.resizing) {\n this.container.classList.remove(this.classNames.resizing)\n }\n\n // Clean up document-level listeners\n document.removeEventListener('mousemove', this.handleMouseMove)\n document.removeEventListener('mouseup', this.handleMouseUp)\n document.removeEventListener('keydown', this.handleKeyDown)\n document.removeEventListener('keyup', this.handleKeyUp)\n }\n\n /**\n * Tracks Shift key state to enable temporary aspect ratio locking.\n *\n * When Shift is pressed during resize, aspect ratio is preserved even if\n * preserveAspectRatio is false.\n *\n * @param event - The keyboard event\n */\n private handleKeyDown = (event: KeyboardEvent): void => {\n if (event.key === 'Shift') {\n this.isShiftKeyPressed = true\n }\n }\n\n /**\n * Tracks Shift key release to disable temporary aspect ratio locking.\n *\n * @param event - The keyboard event\n */\n private handleKeyUp = (event: KeyboardEvent): void => {\n if (event.key === 'Shift') {\n this.isShiftKeyPressed = false\n }\n }\n\n /**\n * Calculates new dimensions based on mouse delta and resize direction.\n *\n * Takes the starting dimensions and applies the mouse movement delta\n * according to the handle direction. For corner handles, both dimensions\n * are affected. For edge handles, only one dimension changes. If aspect\n * ratio should be preserved, delegates to applyAspectRatio.\n *\n * @param direction - The active resize handle direction\n * @param deltaX - Horizontal mouse movement since resize start\n * @param deltaY - Vertical mouse movement since resize start\n * @returns The calculated width and height\n */\n private calculateNewDimensions(\n direction: ResizableNodeViewDirection,\n deltaX: number,\n deltaY: number,\n ): ResizableNodeDimensions {\n let newWidth = this.startWidth\n let newHeight = this.startHeight\n\n const isRight = direction.includes('right')\n const isLeft = direction.includes('left')\n const isBottom = direction.includes('bottom')\n const isTop = direction.includes('top')\n\n // Apply horizontal delta\n if (isRight) {\n newWidth = this.startWidth + deltaX\n } else if (isLeft) {\n newWidth = this.startWidth - deltaX\n }\n\n // Apply vertical delta\n if (isBottom) {\n newHeight = this.startHeight + deltaY\n } else if (isTop) {\n newHeight = this.startHeight - deltaY\n }\n\n // For pure horizontal/vertical handles, only one dimension changes\n if (direction === 'right' || direction === 'left') {\n newWidth = this.startWidth + (isRight ? deltaX : -deltaX)\n }\n\n if (direction === 'top' || direction === 'bottom') {\n newHeight = this.startHeight + (isBottom ? deltaY : -deltaY)\n }\n\n const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed\n\n if (shouldPreserveAspectRatio) {\n return this.applyAspectRatio(newWidth, newHeight, direction)\n }\n\n return { width: newWidth, height: newHeight }\n }\n\n /**\n * Applies min/max constraints to dimensions.\n *\n * When aspect ratio is NOT preserved, constraints are applied independently\n * to width and height. When aspect ratio IS preserved, constraints are\n * applied while maintaining the aspect ratio—if one dimension hits a limit,\n * the other is recalculated proportionally.\n *\n * This ensures that aspect ratio is never broken when constrained.\n *\n * @param width - The unconstrained width\n * @param height - The unconstrained height\n * @param preserveAspectRatio - Whether to maintain aspect ratio while constraining\n * @returns The constrained dimensions\n */\n private applyConstraints(width: number, height: number, preserveAspectRatio: boolean): ResizableNodeDimensions {\n if (!preserveAspectRatio) {\n // Independent constraints for each dimension\n let constrainedWidth = Math.max(this.minSize.width, width)\n let constrainedHeight = Math.max(this.minSize.height, height)\n\n if (this.maxSize?.width) {\n constrainedWidth = Math.min(this.maxSize.width, constrainedWidth)\n }\n\n if (this.maxSize?.height) {\n constrainedHeight = Math.min(this.maxSize.height, constrainedHeight)\n }\n\n return { width: constrainedWidth, height: constrainedHeight }\n }\n\n // Aspect-ratio-aware constraints: adjust both dimensions proportionally\n let constrainedWidth = width\n let constrainedHeight = height\n\n // Check minimum constraints\n if (constrainedWidth < this.minSize.width) {\n constrainedWidth = this.minSize.width\n constrainedHeight = constrainedWidth / this.aspectRatio\n }\n\n if (constrainedHeight < this.minSize.height) {\n constrainedHeight = this.minSize.height\n constrainedWidth = constrainedHeight * this.aspectRatio\n }\n\n // Check maximum constraints\n if (this.maxSize?.width && constrainedWidth > this.maxSize.width) {\n constrainedWidth = this.maxSize.width\n constrainedHeight = constrainedWidth / this.aspectRatio\n }\n\n if (this.maxSize?.height && constrainedHeight > this.maxSize.height) {\n constrainedHeight = this.maxSize.height\n constrainedWidth = constrainedHeight * this.aspectRatio\n }\n\n return { width: constrainedWidth, height: constrainedHeight }\n }\n\n /**\n * Adjusts dimensions to maintain the original aspect ratio.\n *\n * For horizontal handles (left/right), uses width as the primary dimension\n * and calculates height from it. For vertical handles (top/bottom), uses\n * height as primary and calculates width. For corner handles, uses width\n * as the primary dimension.\n *\n * @param width - The new width\n * @param height - The new height\n * @param direction - The active resize direction\n * @returns Dimensions adjusted to preserve aspect ratio\n */\n private applyAspectRatio(\n width: number,\n height: number,\n direction: ResizableNodeViewDirection,\n ): ResizableNodeDimensions {\n const isHorizontal = direction === 'left' || direction === 'right'\n const isVertical = direction === 'top' || direction === 'bottom'\n\n if (isHorizontal) {\n // For horizontal resize, width is primary\n return {\n width,\n height: width / this.aspectRatio,\n }\n }\n\n if (isVertical) {\n // For vertical resize, height is primary\n return {\n width: height * this.aspectRatio,\n height,\n }\n }\n\n // For corner resize, width is primary\n return {\n width,\n height: width / this.aspectRatio,\n }\n }\n}\n\n/**\n * Alias for ResizableNodeView to maintain consistent naming.\n * @deprecated Use ResizableNodeView instead - will be removed in future versions.\n */\nexport const ResizableNodeview = ResizableNodeView\n","import type { NodeType } from '@tiptap/pm/model'\nimport { type EditorState, NodeSelection } from '@tiptap/pm/state'\n\nexport function canInsertNode(state: EditorState, nodeType: NodeType): boolean {\n const { selection } = state\n const { $from } = selection\n\n // Special handling for NodeSelection\n if (selection instanceof NodeSelection) {\n const index = $from.index()\n const parent = $from.parent\n\n // Can we replace the selected node with the horizontal rule?\n return parent.canReplaceWith(index, index + 1, nodeType)\n }\n\n // Default: check if we can insert at the current position\n let depth = $from.depth\n\n while (depth >= 0) {\n const index = $from.index(depth)\n const parent = $from.node(depth)\n const match = parent.contentMatchAt(index)\n if (match.matchType(nodeType)) {\n return true\n }\n depth -= 1\n }\n return false\n}\n","// source: https://stackoverflow.com/a/6969486\nexport function escapeForRegEx(string: string): string {\n return string.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&')\n}\n","export function isString(value: any): value is string {\n return typeof value === 'string'\n}\n","/**\n * @fileoverview Markdown utilities for creating standardized markdown specs.\n *\n * This module provides utilities for creating complete markdown specifications\n * for different types of nodes using unified syntax patterns.\n */\n\nexport * from './attributeUtils.js'\nexport * from './createAtomBlockMarkdownSpec.js'\nexport * from './createBlockMarkdownSpec.js'\nexport * from './createInlineMarkdownSpec.js'\nexport * from './parseIndentedBlocks.js'\nexport * from './renderNestedMarkdownContent.js'\n","/**\n * @fileoverview Utility functions for parsing and serializing markdown attributes.\n *\n * These utilities handle the common patterns for parsing attribute strings\n * in various markdown syntaxes like Pandoc attributes.\n */\n\n/**\n * Parses a Pandoc-style attribute string into an object.\n *\n * Supports the following patterns:\n * - Classes: `.className` → `{ class: 'className' }`\n * - IDs: `#myId` → `{ id: 'myId' }`\n * - Key-value pairs: `key=\"value\"` → `{ key: 'value' }`\n * - Boolean attributes: `disabled` → `{ disabled: true }`\n *\n * @param attrString - The attribute string to parse\n * @returns Parsed attributes object\n *\n * @example\n * ```ts\n * parseAttributes('.btn #submit disabled type=\"button\"')\n * // → { class: 'btn', id: 'submit', disabled: true, type: 'button' }\n * ```\n */\nexport function parseAttributes(attrString: string): Record<string, any> {\n if (!attrString?.trim()) {\n return {}\n }\n\n const attributes: Record<string, any> = {}\n\n // First, extract and remove quoted strings to avoid parsing content inside them\n const quotedStrings: string[] = []\n const tempString = attrString.replace(/[\"']([^\"']*)[\"']/g, match => {\n quotedStrings.push(match)\n return `__QUOTED_${quotedStrings.length - 1}__`\n })\n\n // Parse classes (.className) - only outside of quoted strings\n const classMatches = tempString.match(/(?:^|\\s)\\.([a-zA-Z][\\w-]*)/g)\n if (classMatches) {\n const classes = classMatches.map(match => match.trim().slice(1)) // Remove the dot\n attributes.class = classes.join(' ')\n }\n\n // Parse IDs (#myId) - only outside of quoted strings\n const idMatch = tempString.match(/(?:^|\\s)#([a-zA-Z][\\w-]*)/)\n if (idMatch) {\n attributes.id = idMatch[1]\n }\n\n // Parse key-value pairs (key=\"value\" or key='value') - restore quoted strings\n const kvRegex = /([a-zA-Z][\\w-]*)\\s*=\\s*(__QUOTED_\\d+__)/g\n const kvMatches = Array.from(tempString.matchAll(kvRegex))\n kvMatches.forEach(([, key, quotedRef]) => {\n const quotedIndex = parseInt(quotedRef.match(/__QUOTED_(\\d+)__/)?.[1] || '0', 10)\n const quotedValue = quotedStrings[quotedIndex]\n if (quotedValue) {\n // Remove the outer quotes\n attributes[key] = quotedValue.slice(1, -1)\n }\n })\n\n // Parse boolean attributes (standalone words that aren't classes/IDs)\n const cleanString = tempString\n .replace(/(?:^|\\s)\\.([a-zA-Z][\\w-]*)/g, '') // Remove classes\n .replace(/(?:^|\\s)#([a-zA-Z][\\w-]*)/g, '') // Remove IDs\n .replace(/([a-zA-Z][\\w-]*)\\s*=\\s*__QUOTED_\\d+__/g, '') // Remove key-value pairs\n .trim()\n\n if (cleanString) {\n const booleanAttrs = cleanString.split(/\\s+/).filter(Boolean)\n booleanAttrs.forEach(attr => {\n if (attr.match(/^[a-zA-Z][\\w-]*$/)) {\n attributes[attr] = true\n }\n })\n }\n\n return attributes\n}\n\n/**\n * Serializes an attributes object back to a Pandoc-style attribute string.\n *\n * @param attributes - The attributes object to serialize\n * @returns Serialized attribute string\n *\n * @example\n * ```ts\n * serializeAttributes({ class: 'btn primary', id: 'submit', disabled: true, type: 'button' })\n * // → '.btn.primary #submit disabled type=\"button\"'\n * ```\n */\nexport function serializeAttributes(attributes: Record<string, any>): string {\n if (!attributes || Object.keys(attributes).length === 0) {\n return ''\n }\n\n const parts: string[] = []\n\n // Handle classes\n if (attributes.class) {\n const classes = String(attributes.class).split(/\\s+/).filter(Boolean)\n classes.forEach(cls => parts.push(`.${cls}`))\n }\n\n // Handle ID\n if (attributes.id) {\n parts.push(`#${attributes.id}`)\n }\n\n // Handle other attributes\n Object.entries(attributes).forEach(([key, value]) => {\n if (key === 'class' || key === 'id') {\n return // Already handled\n }\n\n if (value === true) {\n // Boolean attribute\n parts.push(key)\n } else if (value !== false && value != null) {\n // Key-value attribute\n parts.push(`${key}=\"${String(value)}\"`)\n }\n })\n\n return parts.join(' ')\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\nimport {\n parseAttributes as defaultParseAttributes,\n serializeAttributes as defaultSerializeAttributes,\n} from './attributeUtils.js'\n\nexport interface AtomBlockMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The markdown syntax name (defaults to nodeName if not provided) */\n name?: string\n /** Function to parse attributes from token attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes back to string for rendering */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Required attributes that must be present for successful parsing */\n requiredAttributes?: string[]\n /** Attributes that are allowed to be rendered back to markdown (whitelist) */\n allowedAttributes?: string[]\n}\n\n/**\n * Creates a complete markdown spec for atomic block nodes using Pandoc syntax.\n *\n * The generated spec handles:\n * - Parsing self-closing blocks with `:::blockName {attributes}`\n * - Extracting and parsing attributes\n * - Validating required attributes\n * - Rendering blocks back to markdown\n *\n * @param options - Configuration for the atomic block markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * const youtubeSpec = createAtomBlockMarkdownSpec({\n * nodeName: 'youtube',\n * requiredAttributes: ['src'],\n * defaultAttributes: { start: 0 },\n * allowedAttributes: ['src', 'start', 'width', 'height'] // Only these get rendered to markdown\n * })\n *\n * // Usage in extension:\n * export const Youtube = Node.create({\n * // ... other config\n * markdown: youtubeSpec\n * })\n * ```\n */\nexport function createAtomBlockMarkdownSpec(options: AtomBlockMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent) => string\n} {\n const {\n nodeName,\n name: markdownName,\n parseAttributes = defaultParseAttributes,\n serializeAttributes = defaultSerializeAttributes,\n defaultAttributes = {},\n requiredAttributes = [],\n allowedAttributes,\n } = options\n\n // Use markdownName for syntax, fallback to nodeName\n const blockName = markdownName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(key => {\n if (key in attrs) {\n filtered[key] = attrs[key]\n }\n })\n return filtered\n }\n\n return {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => {\n const attrs = { ...defaultAttributes, ...token.attributes }\n return h.createNode(nodeName, attrs, [])\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'block' as const,\n start(src: string) {\n const regex = new RegExp(`^:::${blockName}(?:\\\\s|$)`, 'm')\n const index = src.match(regex)?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, _lexer) {\n // Use non-global regex to match from the start of the string\n // Include optional newline to ensure we consume the entire line\n const regex = new RegExp(`^:::${blockName}(?:\\\\s+\\\\{([^}]*)\\\\})?\\\\s*:::(?:\\\\n|$)`)\n const match = src.match(regex)\n\n if (!match) {\n return undefined\n }\n\n // Parse attributes if present\n const attrString = match[1] || ''\n const attributes = parseAttributes(attrString)\n\n // Validate required attributes\n const missingRequired = requiredAttributes.find(required => !(required in attributes))\n if (missingRequired) {\n return undefined\n }\n\n return {\n type: nodeName,\n raw: match[0],\n attributes,\n }\n },\n },\n\n renderMarkdown: node => {\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` {${attrs}}` : ''\n\n return `:::${blockName}${attrString} :::`\n },\n }\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownRendererHelpers,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\nimport {\n parseAttributes as defaultParseAttributes,\n serializeAttributes as defaultSerializeAttributes,\n} from './attributeUtils.js'\n\nexport interface BlockMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The markdown syntax name (defaults to nodeName if not provided) */\n name?: string\n /** Function to extract content from the node for serialization */\n getContent?: (token: MarkdownToken) => string\n /** Function to parse attributes from the attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes to string */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Content type: 'block' allows paragraphs/lists/etc, 'inline' only allows bold/italic/links/etc */\n content?: 'block' | 'inline'\n /** Allowlist of attributes to include in markdown (if not provided, all attributes are included) */\n allowedAttributes?: string[]\n}\n\n/**\n * Creates a complete markdown spec for block-level nodes using Pandoc syntax.\n *\n * The generated spec handles:\n * - Parsing blocks with `:::blockName {attributes}` syntax\n * - Extracting and parsing attributes\n * - Rendering blocks back to markdown with proper formatting\n * - Nested content support\n *\n * @param options - Configuration for the block markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * const calloutSpec = createBlockMarkdownSpec({\n * nodeName: 'callout',\n * defaultAttributes: { type: 'info' },\n * allowedAttributes: ['type', 'title'] // Only these get rendered to markdown\n * })\n *\n * // Usage in extension:\n * export const Callout = Node.create({\n * // ... other config\n * markdown: calloutSpec\n * })\n * ```\n */\nexport function createBlockMarkdownSpec(options: BlockMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent, h: MarkdownRendererHelpers) => string\n} {\n const {\n nodeName,\n name: markdownName,\n getContent,\n parseAttributes = defaultParseAttributes,\n serializeAttributes = defaultSerializeAttributes,\n defaultAttributes = {},\n content = 'block',\n allowedAttributes,\n } = options\n\n // Use markdownName for syntax, fallback to nodeName\n const blockName = markdownName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(key => {\n if (key in attrs) {\n filtered[key] = attrs[key]\n }\n })\n return filtered\n }\n\n return {\n parseMarkdown: (token, h) => {\n let nodeContent: JSONContent[]\n\n if (getContent) {\n const contentResult = getContent(token)\n // If getContent returns a string, wrap it in a text node\n nodeContent = typeof contentResult === 'string' ? [{ type: 'text', text: contentResult }] : contentResult\n } else if (content === 'block') {\n nodeContent = h.parseChildren(token.tokens || [])\n } else {\n nodeContent = h.parseInline(token.tokens || [])\n }\n\n const attrs = { ...defaultAttributes, ...token.attributes }\n\n return h.createNode(nodeName, attrs, nodeContent)\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'block' as const,\n start(src) {\n const regex = new RegExp(`^:::${blockName}`, 'm')\n const index = src.match(regex)?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, lexer) {\n // Match the opening tag with optional attributes\n const openingRegex = new RegExp(`^:::${blockName}(?:\\\\s+\\\\{([^}]*)\\\\})?\\\\s*\\\\n`)\n const openingMatch = src.match(openingRegex)\n\n if (!openingMatch) {\n return undefined\n }\n\n const [openingTag, attrString = ''] = openingMatch\n const attributes = parseAttributes(attrString)\n\n // Find the matching closing tag by tracking nesting level\n let level = 1\n const position = openingTag.length\n let matchedContent = ''\n\n // Pattern to match any block opening (:::word) or closing (:::)\n const blockPattern = /^:::([\\w-]*)(\\s.*)?/gm\n const remaining = src.slice(position)\n\n blockPattern.lastIndex = 0\n\n // run until no more matches are found\n for (;;) {\n const match = blockPattern.exec(remaining)\n if (match === null) {\n break\n }\n const matchPos = match.index\n const blockType = match[1] // Empty string for closing tag, block name for opening\n\n if (match[2]?.endsWith(':::')) {\n // this is an atom ::: node, we skip it\n continue\n }\n\n if (blockType) {\n // Opening tag found - increase level\n level += 1\n } else {\n // Closing tag found - decrease level\n level -= 1\n\n if (level === 0) {\n // Found our matching closing tag\n // Don't trim yet - keep newlines for tokenizer regex matching\n const rawContent = remaining.slice(0, matchPos)\n matchedContent = rawContent.trim()\n const fullMatch = src.slice(0, position + matchPos + match[0].length)\n\n // Tokenize the content\n let contentTokens: MarkdownToken[] = []\n if (matchedContent) {\n if (content === 'block') {\n // Use rawContent for tokenization to preserve line boundaries for regex matching\n contentTokens = lexer.blockTokens(rawContent)\n\n // Parse inline tokens for any token that has text content but no tokens\n contentTokens.forEach(token => {\n if (token.text && (!token.tokens || token.tokens.length === 0)) {\n token.tokens = lexer.inlineTokens(token.text)\n }\n })\n\n // Clean up empty trailing paragraphs\n while (contentTokens.length > 0) {\n const lastToken = contentTokens[contentTokens.length - 1]\n if (lastToken.type === 'paragraph' && (!lastToken.text || lastToken.text.trim() === '')) {\n contentTokens.pop()\n } else {\n break\n }\n }\n } else {\n contentTokens = lexer.inlineTokens(matchedContent)\n }\n }\n\n return {\n type: nodeName,\n raw: fullMatch,\n attributes,\n content: matchedContent,\n tokens: contentTokens,\n }\n }\n }\n }\n\n // No matching closing tag found\n return undefined\n },\n },\n\n renderMarkdown: (node, h) => {\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` {${attrs}}` : ''\n const renderedContent = h.renderChildren(node.content || [], '\\n\\n')\n\n return `:::${blockName}${attrString}\\n\\n${renderedContent}\\n\\n:::`\n },\n }\n}\n","import type {\n JSONContent,\n MarkdownParseHelpers,\n MarkdownParseResult,\n MarkdownToken,\n MarkdownTokenizer,\n} from '../../types.js'\n\n/**\n * Parse shortcode attributes like 'id=\"madonna\" handle=\"john\" name=\"John Doe\"'\n * Requires all values to be quoted with either single or double quotes\n */\nfunction parseShortcodeAttributes(attrString: string): Record<string, any> {\n if (!attrString.trim()) {\n return {}\n }\n\n const attributes: Record<string, any> = {}\n // Match key=value pairs, only accepting quoted values\n const regex = /(\\w+)=(?:\"([^\"]*)\"|'([^']*)')/g\n let match = regex.exec(attrString)\n\n while (match !== null) {\n const [, key, doubleQuoted, singleQuoted] = match\n attributes[key] = doubleQuoted || singleQuoted\n match = regex.exec(attrString)\n }\n\n return attributes\n}\n\n/**\n * Serialize attributes back to shortcode format\n * Always quotes all values with double quotes\n */\nfunction serializeShortcodeAttributes(attrs: Record<string, any>): string {\n return Object.entries(attrs)\n .filter(([, value]) => value !== undefined && value !== null)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ')\n}\n\n/**\n * Configuration for an allowed attribute in markdown serialization.\n * Can be a simple string (attribute name) or an object with additional options.\n */\nexport type AllowedAttribute =\n | string\n | {\n /** The attribute name */\n name: string\n /**\n * If provided, the attribute will be skipped during serialization when its value\n * equals this default value. This keeps markdown output clean by omitting\n * attributes that have their default values.\n */\n skipIfDefault?: any\n }\n\nexport interface InlineMarkdownSpecOptions {\n /** The Tiptap node name this spec is for */\n nodeName: string\n /** The shortcode name (defaults to nodeName if not provided) */\n name?: string\n /** Function to extract content from the node for serialization */\n getContent?: (node: any) => string\n /** Function to parse attributes from the attribute string */\n parseAttributes?: (attrString: string) => Record<string, any>\n /** Function to serialize attributes to string */\n serializeAttributes?: (attrs: Record<string, any>) => string\n /** Default attributes to apply when parsing */\n defaultAttributes?: Record<string, any>\n /** Whether this is a self-closing shortcode (no content, like [emoji name=party]) */\n selfClosing?: boolean\n /**\n * Allowlist of attributes to include in markdown serialization.\n * If not provided, all attributes are included.\n *\n * Each item can be either:\n * - A string: the attribute name (always included if present)\n * - An object: `{ name: string, skipIfDefault?: any }` for conditional inclusion\n *\n * @example\n * // Simple string attributes (backward compatible)\n * allowedAttributes: ['id', 'label']\n *\n * // Mixed with conditional attributes\n * allowedAttributes: [\n * 'id',\n * 'label',\n * { name: 'mentionSuggestionChar', skipIfDefault: '@' }\n * ]\n */\n allowedAttributes?: AllowedAttribute[]\n}\n\n/**\n * Creates a complete markdown spec for inline nodes using attribute syntax.\n *\n * The generated spec handles:\n * - Parsing shortcode syntax with `[nodeName attributes]content[/nodeName]` format\n * - Self-closing shortcodes like `[emoji name=party_popper]`\n * - Extracting and parsing attributes from the opening tag\n * - Rendering inline elements back to shortcode markdown\n * - Supporting both content-based and self-closing inline elements\n *\n * @param options - Configuration for the inline markdown spec\n * @returns Complete markdown specification object\n *\n * @example\n * ```ts\n * // Self-closing mention: [mention id=\"madonna\" label=\"Madonna\"]\n * const mentionSpec = createInlineMarkdownSpec({\n * nodeName: 'mention',\n * selfClosing: true,\n * defaultAttributes: { type: 'user' },\n * allowedAttributes: ['id', 'label'] // Only these get rendered to markdown\n * })\n *\n * // Self-closing emoji: [emoji name=\"party_popper\"]\n * const emojiSpec = createInlineMarkdownSpec({\n * nodeName: 'emoji',\n * selfClosing: true,\n * allowedAttributes: ['name']\n * })\n *\n * // With content: [highlight color=\"yellow\"]text[/highlight]\n * const highlightSpec = createInlineMarkdownSpec({\n * nodeName: 'highlight',\n * selfClosing: false,\n * allowedAttributes: ['color', 'style']\n * })\n *\n * // Usage in extension:\n * export const Mention = Node.create({\n * name: 'mention', // Must match nodeName\n * // ... other config\n * markdown: mentionSpec\n * })\n * ```\n */\nexport function createInlineMarkdownSpec(options: InlineMarkdownSpecOptions): {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => MarkdownParseResult\n markdownTokenizer: MarkdownTokenizer\n renderMarkdown: (node: JSONContent) => string\n} {\n const {\n nodeName,\n name: shortcodeName,\n getContent,\n parseAttributes = parseShortcodeAttributes,\n serializeAttributes = serializeShortcodeAttributes,\n defaultAttributes = {},\n selfClosing = false,\n allowedAttributes,\n } = options\n\n // Use shortcodeName for markdown syntax, fallback to nodeName\n const shortcode = shortcodeName || nodeName\n\n // Helper function to filter attributes based on allowlist\n const filterAttributes = (attrs: Record<string, any>) => {\n if (!allowedAttributes) {\n return attrs\n }\n\n const filtered: Record<string, any> = {}\n allowedAttributes.forEach(attr => {\n // Handle both string and object formats for backward compatibility\n const attrName = typeof attr === 'string' ? attr : attr.name\n const skipIfDefault = typeof attr === 'string' ? undefined : attr.skipIfDefault\n\n if (attrName in attrs) {\n const value = attrs[attrName]\n\n // Skip if value equals the default (when skipIfDefault is specified)\n if (skipIfDefault !== undefined && value === skipIfDefault) {\n return\n }\n\n filtered[attrName] = value\n }\n })\n return filtered\n }\n\n // Escape special regex characters in shortcode name\n const escapedShortcode = shortcode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return {\n parseMarkdown: (token: MarkdownToken, h: MarkdownParseHelpers) => {\n const attrs = { ...defaultAttributes, ...token.attributes }\n\n if (selfClosing) {\n // Self-closing nodes like mentions are atomic - no content\n return h.createNode(nodeName, attrs)\n }\n\n // Nodes with content\n const content = getContent ? getContent(token) : token.content || ''\n if (content) {\n // For inline content, create text nodes using the proper helper\n return h.createNode(nodeName, attrs, [h.createTextNode(content)])\n }\n return h.createNode(nodeName, attrs, [])\n },\n\n markdownTokenizer: {\n name: nodeName,\n level: 'inline' as const,\n start(src: string) {\n // Create a non-global version for finding the start position\n const startPattern = selfClosing\n ? new RegExp(`\\\\[${escapedShortcode}\\\\s*[^\\\\]]*\\\\]`)\n : new RegExp(`\\\\[${escapedShortcode}\\\\s*[^\\\\]]*\\\\][\\\\s\\\\S]*?\\\\[\\\\/${escapedShortcode}\\\\]`)\n\n const match = src.match(startPattern)\n const index = match?.index\n return index !== undefined ? index : -1\n },\n tokenize(src, _tokens, _lexer) {\n // Use non-global regex to match from the start of the string\n const tokenPattern = selfClosing\n ? new RegExp(`^\\\\[${escapedShortcode}\\\\s*([^\\\\]]*)\\\\]`)\n : new RegExp(`^\\\\[${escapedShortcode}\\\\s*([^\\\\]]*)\\\\]([\\\\s\\\\S]*?)\\\\[\\\\/${escapedShortcode}\\\\]`)\n\n const match = src.match(tokenPattern)\n\n if (!match) {\n return undefined\n }\n\n let content = ''\n let attrString = ''\n\n if (selfClosing) {\n // Self-closing: [shortcode attr=\"value\"]\n const [, attrs] = match\n attrString = attrs\n } else {\n // With content: [shortcode attr=\"value\"]content[/shortcode]\n const [, attrs, contentMatch] = match\n attrString = attrs\n content = contentMatch || ''\n }\n\n // Parse attributes from the attribute string\n const attributes = parseAttributes(attrString.trim())\n\n return {\n type: nodeName,\n raw: match[0],\n content: content.trim(),\n attributes,\n }\n },\n },\n\n renderMarkdown: (node: JSONContent) => {\n let content = ''\n if (getContent) {\n content = getContent(node)\n } else if (node.content && node.content.length > 0) {\n // Extract text from content array for inline nodes\n content = node.content\n .filter((child: any) => child.type === 'text')\n .map((child: any) => child.text)\n .join('')\n }\n\n const filteredAttrs = filterAttributes(node.attrs || {})\n const attrs = serializeAttributes(filteredAttrs)\n const attrString = attrs ? ` ${attrs}` : ''\n\n if (selfClosing) {\n return `[${shortcode}${attrString}]`\n }\n\n return `[${shortcode}${attrString}]${content}[/${shortcode}]`\n },\n }\n}\n","/**\n * @fileoverview Utility for parsing indented markdown blocks with hierarchical nesting.\n *\n * This utility handles the complex logic of parsing markdown blocks that can contain\n * nested content based on indentation levels, maintaining proper hierarchical structure\n * for lists, task lists, and other indented block types.\n */\n\nexport interface ParsedBlock {\n type: string\n raw: string\n mainContent: string\n indentLevel: number\n nestedContent?: string\n nestedTokens?: any[]\n [key: string]: any\n}\n\nexport interface BlockParserConfig {\n /** Regex pattern to match block items */\n itemPattern: RegExp\n /** Function to extract data from regex match */\n extractItemData: (match: RegExpMatchArray) => {\n mainContent: string\n indentLevel: number\n [key: string]: any\n }\n /** Function to create the final token */\n createToken: (data: any, nestedTokens?: any[]) => ParsedBlock\n /** Base indentation to remove from nested content (default: 2 spaces) */\n baseIndentSize?: number\n /**\n * Custom parser for nested content. If provided, this will be called instead\n * of the default lexer.blockTokens() for parsing nested content.\n * This allows recursive parsing of the same block type.\n */\n customNestedParser?: (dedentedContent: string) => any[] | undefined\n}\n\n/**\n * Parses markdown text into hierarchical indented blocks with proper nesting.\n *\n * This utility handles:\n * - Line-by-line parsing with pattern matching\n * - Hierarchical nesting based on indentation levels\n * - Nested content collection and parsing\n * - Empty line handling\n * - Content dedenting for nested blocks\n *\n * The key difference from flat parsing is that this maintains the hierarchical\n * structure where nested items become `nestedTokens` of their parent items,\n * rather than being flattened into a single array.\n *\n * @param src - The markdown source text to parse\n * @param config - Configuration object defining how to parse and create tokens\n * @param lexer - Markdown lexer for parsing nested content\n * @returns Parsed result with hierarchical items, or undefined if no matches\n *\n * @example\n * ```ts\n * const result = parseIndentedBlocks(src, {\n * itemPattern: /^(\\s*)([-+*])\\s+\\[([ xX])\\]\\s+(.*)$/,\n * extractItemData: (match) => ({\n * indentLevel: match[1].length,\n * mainContent: match[4],\n * checked: match[3].toLowerCase() === 'x'\n * }),\n * createToken: (data, nestedTokens) => ({\n * type: 'taskItem',\n * checked: data.checked,\n * text: data.mainContent,\n * nestedTokens\n * })\n * }, lexer)\n * ```\n */\nexport function parseIndentedBlocks(\n src: string,\n config: BlockParserConfig,\n lexer: {\n inlineTokens: (src: string) => any[]\n blockTokens: (src: string) => any[]\n },\n):\n | {\n items: ParsedBlock[]\n raw: string\n }\n | undefined {\n const lines = src.split('\\n')\n const items: ParsedBlock[] = []\n let totalRaw = ''\n let i = 0\n const baseIndentSize = config.baseIndentSize || 2\n\n while (i < lines.length) {\n const currentLine = lines[i]\n const itemMatch = currentLine.match(config.itemPattern)\n\n if (!itemMatch) {\n // Not a matching item - stop if we have items, otherwise this isn't our block type\n if (items.length > 0) {\n break\n } else if (currentLine.trim() === '') {\n i += 1\n totalRaw = `${totalRaw}${currentLine}\\n`\n continue\n } else {\n return undefined\n }\n }\n\n const itemData = config.extractItemData(itemMatch)\n const { indentLevel, mainContent } = itemData\n totalRaw = `${totalRaw}${currentLine}\\n`\n\n // Collect content for this item (including nested items)\n const itemContent = [mainContent] // Start with the main text\n i += 1\n\n // Look ahead for nested content (indented more than current item)\n while (i < lines.length) {\n const nextLine = lines[i]\n\n if (nextLine.trim() === '') {\n // Empty line - might be end of nested content\n const nextNonEmptyIndex = lines.slice(i + 1).findIndex(l => l.trim() !== '')\n if (nextNonEmptyIndex === -1) {\n // No more content\n break\n }\n\n const nextNonEmpty = lines[i + 1 + nextNonEmptyIndex]\n const nextIndent = nextNonEmpty.match(/^(\\s*)/)?.[1]?.length || 0\n\n if (nextIndent > indentLevel) {\n // Nested content continues after empty line\n itemContent.push(nextLine)\n totalRaw = `${totalRaw}${nextLine}\\n`\n i += 1\n continue\n } else {\n // End of nested content\n break\n }\n }\n\n const nextIndent = nextLine.match(/^(\\s*)/)?.[1]?.length || 0\n\n if (nextIndent > indentLevel) {\n // This is nested content for the current item\n itemContent.push(nextLine)\n totalRaw = `${totalRaw}${nextLine}\\n`\n i += 1\n } else {\n // Same or less indentation - this belongs to parent level\n break\n }\n }\n\n // Parse nested content if present\n let nestedTokens: any[] | undefined\n const nestedContent = itemContent.slice(1)\n\n if (nestedContent.length > 0) {\n // Remove the base indentation from nested content\n const dedentedNested = nestedContent\n .map(nestedLine => nestedLine.slice(indentLevel + baseIndentSize)) // Remove base indent + 2 spaces\n .join('\\n')\n\n if (dedentedNested.trim()) {\n // Use custom nested parser if provided, otherwise fall back to default\n if (config.customNestedParser) {\n nestedTokens = config.customNestedParser(dedentedNested)\n } else {\n nestedTokens = lexer.blockTokens(dedentedNested)\n }\n }\n }\n\n // Create the token using the provided factory function\n const token = config.createToken(itemData, nestedTokens)\n items.push(token)\n }\n\n if (items.length === 0) {\n return undefined\n }\n\n return {\n items,\n raw: totalRaw,\n }\n}\n","import type { JSONContent } from '@tiptap/core'\n\n/**\n * @fileoverview Utility functions for rendering nested content in markdown.\n *\n * This module provides reusable utilities for extensions that need to render\n * content with a prefix on the main line and properly indented nested content.\n */\n\n/**\n * Utility function for rendering content with a main line prefix and nested indented content.\n *\n * This function handles the common pattern of rendering content with:\n * 1. A main line with a prefix (like \"- \" for lists, \"> \" for blockquotes, etc.)\n * 2. Nested content that gets indented properly\n *\n * @param node - The ProseMirror node representing the content\n * @param h - The markdown renderer helper\n * @param prefixOrGenerator - Either a string prefix or a function that generates the prefix from context\n * @param ctx - Optional context object (used when prefixOrGenerator is a function)\n * @returns The rendered markdown string\n *\n * @example\n * ```ts\n * // For a bullet list item with static prefix\n * return renderNestedMarkdownContent(node, h, '- ')\n *\n * // For a task item with static prefix\n * const prefix = `- [${node.attrs?.checked ? 'x' : ' '}] `\n * return renderNestedMarkdownContent(node, h, prefix)\n *\n * // For a blockquote with static prefix\n * return renderNestedMarkdownContent(node, h, '> ')\n *\n * // For content with dynamic prefix based on context\n * return renderNestedMarkdownContent(node, h, ctx => {\n * if (ctx.parentType === 'orderedList') {\n * return `${ctx.index + 1}. `\n * }\n * return '- '\n * }, ctx)\n *\n * // Custom extension example\n * const CustomContainer = Node.create({\n * name: 'customContainer',\n * // ... other config\n * markdown: {\n * render: (node, h) => {\n * const type = node.attrs?.type || 'info'\n * return renderNestedMarkdownContent(node, h, `[${type}] `)\n * }\n * }\n * })\n * ```\n */\nexport function renderNestedMarkdownContent(\n node: JSONContent,\n h: {\n renderChildren: (nodes: JSONContent[]) => string\n indent: (text: string) => string\n },\n prefixOrGenerator: string | ((ctx: any) => string),\n ctx?: any,\n): string {\n if (!node || !Array.isArray(node.content)) {\n return ''\n }\n\n // Determine the prefix based on the input\n const prefix = typeof prefixOrGenerator === 'function' ? prefixOrGenerator(ctx) : prefixOrGenerator\n\n const [content, ...children] = node.content\n\n // Render the main content (typically a paragraph)\n const mainContent = h.renderChildren([content])\n const output = [`${prefix}${mainContent}`]\n\n // Handle nested children with proper indentation\n if (children && children.length > 0) {\n children.forEach(child => {\n const childContent = h.renderChildren([child])\n if (childContent) {\n // Split the child content by lines and indent each line\n const indentedChild = childContent\n .split('\\n')\n .map(line => (line ? h.indent(line) : ''))\n .join('\\n')\n output.push(indentedChild)\n }\n })\n }\n\n return output.join('\\n')\n}\n","import type { Mark } from '@tiptap/pm/model'\nimport type { ViewMutationRecord } from '@tiptap/pm/view'\n\nimport type { Editor } from './Editor.js'\nimport type { MarkViewProps, MarkViewRendererOptions } from './types.js'\nimport { isAndroid, isiOS } from './utilities/index.js'\n\nexport function updateMarkViewAttributes(checkMark: Mark, editor: Editor, attrs: Record<string, any> = {}): void {\n const { state } = editor\n const { doc, tr } = state\n const thisMark = checkMark\n\n doc.descendants((node, pos) => {\n const from = tr.mapping.map(pos)\n const to = tr.mapping.map(pos) + node.nodeSize\n let foundMark: Mark | null = null\n\n // find the mark on the current node\n node.marks.forEach(mark => {\n if (mark !== thisMark) {\n return false\n }\n\n foundMark = mark\n })\n\n if (!foundMark) {\n return\n }\n\n // check if we need to update given the attributes\n let needsUpdate = false\n Object.keys(attrs).forEach(k => {\n if (attrs[k] !== foundMark!.attrs[k]) {\n needsUpdate = true\n }\n })\n\n if (needsUpdate) {\n const updatedMark = checkMark.type.create({\n ...checkMark.attrs,\n ...attrs,\n })\n\n tr.removeMark(from, to, checkMark.type)\n tr.addMark(from, to, updatedMark)\n }\n })\n\n if (tr.docChanged) {\n editor.view.dispatch(tr)\n }\n}\n\nexport class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {\n component: Component\n editor: Editor\n options: Options\n mark: MarkViewProps['mark']\n HTMLAttributes: MarkViewProps['HTMLAttributes']\n\n constructor(component: Component, props: MarkViewProps, options?: Partial<Options>) {\n this.component = component\n this.editor = props.editor\n this.options = { ...options } as Options\n this.mark = props.mark\n this.HTMLAttributes = props.HTMLAttributes\n }\n\n get dom(): HTMLElement {\n return this.editor.view.dom\n }\n\n get contentDOM(): HTMLElement | null {\n return null\n }\n\n /**\n * Update the attributes of the mark in the document.\n * @param attrs The attributes to update.\n */\n updateAttributes(attrs: Record<string, any>, checkMark?: Mark): void {\n updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs)\n }\n\n ignoreMutation(mutation: ViewMutationRecord): boolean {\n if (!this.dom || !this.contentDOM) {\n return true\n }\n\n if (typeof this.options.ignoreMutation === 'function') {\n return this.options.ignoreMutation({ mutation })\n }\n\n if (mutation.type === 'selection') {\n return false\n }\n\n if (\n this.dom.contains(mutation.target) &&\n mutation.type === 'childList' &&\n (isiOS() || isAndroid()) &&\n this.editor.isFocused\n ) {\n const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]\n\n if (changedNodes.every(node => node.isContentEditable)) {\n return false\n }\n }\n\n if (this.contentDOM === mutation.target && mutation.type === 'attributes') {\n return true\n }\n\n if (this.contentDOM.contains(mutation.target)) {\n return false\n }\n\n return true\n }\n}\n","import type { DOMOutputSpec, Node as ProseMirrorNode, NodeSpec, NodeType } from '@tiptap/pm/model'\n\nimport type { Editor } from './Editor.js'\nimport type { ExtendableConfig } from './Extendable.js'\nimport { Extendable } from './Extendable.js'\nimport type { Attributes, NodeViewRenderer, ParentConfig } from './types.js'\n\nexport interface NodeConfig<Options = any, Storage = any>\n extends ExtendableConfig<Options, Storage, NodeConfig<Options, Storage>, NodeType> {\n /**\n * Node View\n */\n addNodeView?:\n | ((this: {\n name: string\n options: Options\n storage: Storage\n editor: Editor\n type: NodeType\n parent: ParentConfig<NodeConfig<Options, Storage>>['addNodeView']\n }) => NodeViewRenderer | null)\n | null\n\n /**\n * Defines if this node should be a top level node (doc)\n * @default false\n * @example true\n */\n topNode?: boolean\n\n /**\n * The content expression for this node, as described in the [schema\n * guide](/docs/guide/#schema.content_expressions). When not given,\n * the node does not allow any content.\n *\n * You can read more about it on the Prosemirror documentation here\n * @see https://prosemirror.net/docs/guide/#schema.content_expressions\n * @default undefined\n * @example content: 'block+'\n * @example content: 'headline paragraph block*'\n */\n content?:\n | NodeSpec['content']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['content']\n editor?: Editor\n }) => NodeSpec['content'])\n\n /**\n * The marks that are allowed inside of this node. May be a\n * space-separated string referring to mark names or groups, `\"_\"`\n * to explicitly allow all marks, or `\"\"` to disallow marks. When\n * not given, nodes with inline content default to allowing all\n * marks, other nodes default to not allowing marks.\n *\n * @example marks: 'strong em'\n */\n marks?:\n | NodeSpec['marks']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['marks']\n editor?: Editor\n }) => NodeSpec['marks'])\n\n /**\n * The group or space-separated groups to which this node belongs,\n * which can be referred to in the content expressions for the\n * schema.\n *\n * By default Tiptap uses the groups 'block' and 'inline' for nodes. You\n * can also use custom groups if you want to group specific nodes together\n * and handle them in your schema.\n * @example group: 'block'\n * @example group: 'inline'\n * @example group: 'customBlock' // this uses a custom group\n */\n group?:\n | NodeSpec['group']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['group']\n editor?: Editor\n }) => NodeSpec['group'])\n\n /**\n * Should be set to true for inline nodes. (Implied for text nodes.)\n */\n inline?:\n | NodeSpec['inline']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['inline']\n editor?: Editor\n }) => NodeSpec['inline'])\n\n /**\n * Can be set to true to indicate that, though this isn't a [leaf\n * node](https://prosemirror.net/docs/ref/#model.NodeType.isLeaf), it doesn't have directly editable\n * content and should be treated as a single unit in the view.\n *\n * @example atom: true\n */\n atom?:\n | NodeSpec['atom']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['atom']\n editor?: Editor\n }) => NodeSpec['atom'])\n\n /**\n * Controls whether nodes of this type can be selected as a [node\n * selection](https://prosemirror.net/docs/ref/#state.NodeSelection). Defaults to true for non-text\n * nodes.\n *\n * @default true\n * @example selectable: false\n */\n selectable?:\n | NodeSpec['selectable']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['selectable']\n editor?: Editor\n }) => NodeSpec['selectable'])\n\n /**\n * Determines whether nodes of this type can be dragged without\n * being selected. Defaults to false.\n *\n * @default: false\n * @example: draggable: true\n */\n draggable?:\n | NodeSpec['draggable']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['draggable']\n editor?: Editor\n }) => NodeSpec['draggable'])\n\n /**\n * Can be used to indicate that this node contains code, which\n * causes some commands to behave differently.\n */\n code?:\n | NodeSpec['code']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['code']\n editor?: Editor\n }) => NodeSpec['code'])\n\n /**\n * Controls way whitespace in this a node is parsed. The default is\n * `\"normal\"`, which causes the [DOM parser](https://prosemirror.net/docs/ref/#model.DOMParser) to\n * collapse whitespace in normal mode, and normalize it (replacing\n * newlines and such with spaces) otherwise. `\"pre\"` causes the\n * parser to preserve spaces inside the node. When this option isn't\n * given, but [`code`](https://prosemirror.net/docs/ref/#model.NodeSpec.code) is true, `whitespace`\n * will default to `\"pre\"`. Note that this option doesn't influence\n * the way the node is rendered—that should be handled by `toDOM`\n * and/or styling.\n */\n whitespace?:\n | NodeSpec['whitespace']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['whitespace']\n editor?: Editor\n }) => NodeSpec['whitespace'])\n\n /**\n * Allows a **single** node to be set as linebreak equivalent (e.g. hardBreak).\n * When converting between block types that have whitespace set to \"pre\"\n * and don't support the linebreak node (e.g. codeBlock) and other block types\n * that do support the linebreak node (e.g. paragraphs) - this node will be used\n * as the linebreak instead of stripping the newline.\n *\n * See [linebreakReplacement](https://prosemirror.net/docs/ref/#model.NodeSpec.linebreakReplacement).\n */\n linebreakReplacement?:\n | NodeSpec['linebreakReplacement']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['linebreakReplacement']\n editor?: Editor\n }) => NodeSpec['linebreakReplacement'])\n\n /**\n * When enabled, enables both\n * [`definingAsContext`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext) and\n * [`definingForContent`](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).\n *\n * @default false\n * @example isolating: true\n */\n defining?:\n | NodeSpec['defining']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['defining']\n editor?: Editor\n }) => NodeSpec['defining'])\n\n /**\n * When enabled (default is false), the sides of nodes of this type\n * count as boundaries that regular editing operations, like\n * backspacing or lifting, won't cross. An example of a node that\n * should probably have this enabled is a table cell.\n */\n isolating?:\n | NodeSpec['isolating']\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['isolating']\n editor?: Editor\n }) => NodeSpec['isolating'])\n\n /**\n * Associates DOM parser information with this node, which can be\n * used by [`DOMParser.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMParser^fromSchema) to\n * automatically derive a parser. The `node` field in the rules is\n * implied (the name of this node will be filled in automatically).\n * If you supply your own parser, you do not need to also specify\n * parsing rules in your schema.\n *\n * @example parseHTML: [{ tag: 'div', attrs: { 'data-id': 'my-block' } }]\n */\n parseHTML?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['parseHTML']\n editor?: Editor\n }) => NodeSpec['parseDOM']\n\n /**\n * A description of a DOM structure. Can be either a string, which is\n * interpreted as a text node, a DOM node, which is interpreted as\n * itself, a `{dom, contentDOM}` object, or an array.\n *\n * An array describes a DOM element. The first value in the array\n * should be a string—the name of the DOM element, optionally prefixed\n * by a namespace URL and a space. If the second element is plain\n * object, it is interpreted as a set of attributes for the element.\n * Any elements after that (including the 2nd if it's not an attribute\n * object) are interpreted as children of the DOM elements, and must\n * either be valid `DOMOutputSpec` values, or the number zero.\n *\n * The number zero (pronounced “hole”) is used to indicate the place\n * where a node's child nodes should be inserted. If it occurs in an\n * output spec, it should be the only child element in its parent\n * node.\n *\n * @example toDOM: ['div[data-id=\"my-block\"]', { class: 'my-block' }, 0]\n */\n renderHTML?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML']\n editor?: Editor\n },\n props: {\n node: ProseMirrorNode\n HTMLAttributes: Record<string, any>\n },\n ) => DOMOutputSpec)\n | null\n\n /**\n * renders the node as text\n * @example renderText: () => 'foo\n */\n renderText?:\n | ((\n this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['renderText']\n editor?: Editor\n },\n props: {\n node: ProseMirrorNode\n pos: number\n parent: ProseMirrorNode\n index: number\n },\n ) => string)\n | null\n\n /**\n * Add attributes to the node\n * @example addAttributes: () => ({ class: 'foo' })\n */\n addAttributes?: (this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options, Storage>>['addAttributes']\n editor?: Editor\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n }) => Attributes | {}\n}\n\n/**\n * The Node class is used to create custom node extensions.\n * @see https://tiptap.dev/api/extensions#create-a-new-extension\n */\nexport class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {\n type = 'node'\n\n /**\n * Create a new Node instance\n * @param config - Node configuration object or a function that returns a configuration object\n */\n static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>) = {}) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config\n return new Node<O, S>(resolvedConfig)\n }\n\n configure(options?: Partial<Options>) {\n return super.configure(options) as Node<Options, Storage>\n }\n\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig extends NodeConfig<ExtendedOptions, ExtendedStorage> = NodeConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string\n options: ExtendedOptions\n storage: ExtendedStorage\n editor: Editor\n type: NodeType\n }>),\n ): Node<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig\n return super.extend(resolvedConfig) as Node<ExtendedOptions, ExtendedStorage>\n }\n}\n","import { NodeSelection } from '@tiptap/pm/state'\nimport type { NodeView as ProseMirrorNodeView, ViewMutationRecord } from '@tiptap/pm/view'\n\nimport type { Editor as CoreEditor } from './Editor.js'\nimport type { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } from './types.js'\nimport { isAndroid } from './utilities/isAndroid.js'\nimport { isiOS } from './utilities/isiOS.js'\n\n/**\n * Node views are used to customize the rendered DOM structure of a node.\n * @see https://tiptap.dev/guide/node-views\n */\nexport class NodeView<\n Component,\n NodeEditor extends CoreEditor = CoreEditor,\n Options extends NodeViewRendererOptions = NodeViewRendererOptions,\n> implements ProseMirrorNodeView\n{\n component: Component\n\n editor: NodeEditor\n\n options: Options\n\n extension: NodeViewRendererProps['extension']\n\n node: NodeViewRendererProps['node']\n\n decorations: NodeViewRendererProps['decorations']\n\n innerDecorations: NodeViewRendererProps['innerDecorations']\n\n view: NodeViewRendererProps['view']\n\n getPos: NodeViewRendererProps['getPos']\n\n HTMLAttributes: NodeViewRendererProps['HTMLAttributes']\n\n isDragging = false\n\n constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>) {\n this.component = component\n this.editor = props.editor as NodeEditor\n this.options = {\n stopEvent: null,\n ignoreMutation: null,\n ...options,\n } as Options\n this.extension = props.extension\n this.node = props.node\n this.decorations = props.decorations as DecorationWithType[]\n this.innerDecorations = props.innerDecorations\n this.view = props.view\n this.HTMLAttributes = props.HTMLAttributes\n this.getPos = props.getPos\n this.mount()\n }\n\n mount() {\n // eslint-disable-next-line\n return\n }\n\n get dom(): HTMLElement {\n return this.editor.view.dom as HTMLElement\n }\n\n get contentDOM(): HTMLElement | null {\n return null\n }\n\n onDragStart(event: DragEvent) {\n const { view } = this.editor\n const target = event.target as HTMLElement\n\n // get the drag handle element\n // `closest` is not available for text nodes so we may have to use its parent\n const dragHandle =\n target.nodeType === 3 ? target.parentElement?.closest('[data-drag-handle]') : target.closest('[data-drag-handle]')\n\n if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {\n return\n }\n\n let x = 0\n let y = 0\n\n // calculate offset for drag element if we use a different drag handle element\n if (this.dom !== dragHandle) {\n const domBox = this.dom.getBoundingClientRect()\n const handleBox = dragHandle.getBoundingClientRect()\n\n // In React, we have to go through nativeEvent to reach offsetX/offsetY.\n const offsetX = event.offsetX ?? (event as any).nativeEvent?.offsetX\n const offsetY = event.offsetY ?? (event as any).nativeEvent?.offsetY\n\n x = handleBox.x - domBox.x + offsetX\n y = handleBox.y - domBox.y + offsetY\n }\n\n const clonedNode = this.dom.cloneNode(true) as HTMLElement\n\n // Preserve the visual size of the original when using the clone as\n // the drag image.\n try {\n const domBox = this.dom.getBoundingClientRect()\n clonedNode.style.width = `${Math.round(domBox.width)}px`\n clonedNode.style.height = `${Math.round(domBox.height)}px`\n clonedNode.style.boxSizing = 'border-box'\n // Ensure the clone doesn't capture pointer events while offscreen\n clonedNode.style.pointerEvents = 'none'\n } catch {\n // ignore measurement errors (e.g. if element not in DOM)\n }\n\n // Some browsers (notably Safari) require the element passed to\n // setDragImage to be present in the DOM. Using a detached node can\n // cause the drag to immediately end.\n let dragImageWrapper: HTMLElement | null = null\n\n try {\n dragImageWrapper = document.createElement('div')\n dragImageWrapper.style.position = 'absolute'\n dragImageWrapper.style.top = '-9999px'\n dragImageWrapper.style.left = '-9999px'\n dragImageWrapper.style.pointerEvents = 'none'\n dragImageWrapper.appendChild(clonedNode)\n document.body.appendChild(dragImageWrapper)\n\n event.dataTransfer?.setDragImage(clonedNode, x, y)\n } finally {\n // Remove the wrapper on the next tick so the browser can use the\n // element as the drag image. A 0ms timeout is enough in practice.\n if (dragImageWrapper) {\n setTimeout(() => {\n try {\n dragImageWrapper?.remove()\n } catch {\n // ignore removal errors\n }\n }, 0)\n }\n }\n\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n // we need to tell ProseMirror that we want to move the whole node\n // so we create a NodeSelection\n const selection = NodeSelection.create(view.state.doc, pos)\n const transaction = view.state.tr.setSelection(selection)\n\n view.dispatch(transaction)\n }\n\n stopEvent(event: Event) {\n if (!this.dom) {\n return false\n }\n\n if (typeof this.options.stopEvent === 'function') {\n return this.options.stopEvent({ event })\n }\n\n const target = event.target as HTMLElement\n const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target)\n\n // any event from child nodes should be handled by ProseMirror\n if (!isInElement) {\n return false\n }\n\n const isDragEvent = event.type.startsWith('drag')\n const isDropEvent = event.type === 'drop'\n const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName) || target.isContentEditable\n\n // any input event within node views should be ignored by ProseMirror\n if (isInput && !isDropEvent && !isDragEvent) {\n return true\n }\n\n const { isEditable } = this.editor\n const { isDragging } = this\n const isDraggable = !!this.node.type.spec.draggable\n const isSelectable = NodeSelection.isSelectable(this.node)\n const isCopyEvent = event.type === 'copy'\n const isPasteEvent = event.type === 'paste'\n const isCutEvent = event.type === 'cut'\n const isClickEvent = event.type === 'mousedown'\n\n // ProseMirror tries to drag selectable nodes\n // even if `draggable` is set to `false`\n // this fix prevents that\n if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) {\n event.preventDefault()\n }\n\n if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) {\n event.preventDefault()\n return false\n }\n\n // we have to store that dragging started\n if (isDraggable && isEditable && !isDragging && isClickEvent) {\n const dragHandle = target.closest('[data-drag-handle]')\n const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle))\n\n if (isValidDragHandle) {\n this.isDragging = true\n\n document.addEventListener(\n 'dragend',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n\n document.addEventListener(\n 'drop',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n\n document.addEventListener(\n 'mouseup',\n () => {\n this.isDragging = false\n },\n { once: true },\n )\n }\n }\n\n // these events are handled by prosemirror\n if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || (isClickEvent && isSelectable)) {\n return false\n }\n\n return true\n }\n\n /**\n * Called when a DOM [mutation](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) or a selection change happens within the view.\n * @return `false` if the editor should re-read the selection or re-parse the range around the mutation\n * @return `true` if it can safely be ignored.\n */\n ignoreMutation(mutation: ViewMutationRecord) {\n if (!this.dom || !this.contentDOM) {\n return true\n }\n\n if (typeof this.options.ignoreMutation === 'function') {\n return this.options.ignoreMutation({ mutation })\n }\n\n // a leaf/atom node is like a black box for ProseMirror\n // and should be fully handled by the node view\n if (this.node.isLeaf || this.node.isAtom) {\n return true\n }\n\n // ProseMirror should handle any selections\n if (mutation.type === 'selection') {\n return false\n }\n\n // try to prevent a bug on iOS and Android that will break node views on enter\n // this is because ProseMirror can’t preventDispatch on enter\n // this will lead to a re-render of the node view on enter\n // see: https://github.com/ueberdosis/tiptap/issues/1214\n // see: https://github.com/ueberdosis/tiptap/issues/2534\n if (\n this.dom.contains(mutation.target) &&\n mutation.type === 'childList' &&\n (isiOS() || isAndroid()) &&\n this.editor.isFocused\n ) {\n const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]\n\n // we’ll check if every changed node is contentEditable\n // to make sure it’s probably mutated by ProseMirror\n if (changedNodes.every(node => node.isContentEditable)) {\n return false\n }\n }\n\n // we will allow mutation contentDOM with attributes\n // so we can for example adding classes within our node view\n if (this.contentDOM === mutation.target && mutation.type === 'attributes') {\n return true\n }\n\n // ProseMirror should handle any changes within contentDOM\n if (this.contentDOM.contains(mutation.target)) {\n return false\n }\n\n return true\n }\n\n /**\n * Update the attributes of the prosemirror node.\n */\n updateAttributes(attributes: Record<string, any>): void {\n this.editor.commands.command(({ tr }) => {\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return false\n }\n\n tr.setNodeMarkup(pos, undefined, {\n ...this.node.attrs,\n ...attributes,\n })\n\n return true\n })\n }\n\n /**\n * Delete the node.\n */\n deleteNode(): void {\n const from = this.getPos()\n\n if (typeof from !== 'number') {\n return\n }\n const to = from + this.node.nodeSize\n\n this.editor.commands.deleteRange({ from, to })\n }\n}\n","import type { MarkType } from '@tiptap/pm/model'\n\nimport { getMarksBetween } from '../helpers/getMarksBetween.js'\nimport type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\nimport type { ExtendedRegExpMatchArray } from '../types.js'\nimport { callOrReturn } from '../utilities/callOrReturn.js'\n\n/**\n * Build an paste rule that adds a mark when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport function markPasteRule(config: {\n find: PasteRuleFinder\n type: MarkType\n getAttributes?:\n | Record<string, any>\n | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)\n | false\n | null\n}) {\n return new PasteRule({\n find: config.find,\n handler: ({ state, range, match, pasteEvent }) => {\n const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const { tr } = state\n const captureGroup = match[match.length - 1]\n const fullMatch = match[0]\n let markEnd = range.to\n\n if (captureGroup) {\n const startSpaces = fullMatch.search(/\\S/)\n const textStart = range.from + fullMatch.indexOf(captureGroup)\n const textEnd = textStart + captureGroup.length\n\n const excludedMarks = getMarksBetween(range.from, range.to, state.doc)\n .filter(item => {\n // @ts-ignore\n const excluded = item.mark.type.excluded as MarkType[]\n\n return excluded.find(type => type === config.type && type !== item.mark.type)\n })\n .filter(item => item.to > textStart)\n\n if (excludedMarks.length) {\n return null\n }\n\n if (textEnd < range.to) {\n tr.delete(textEnd, range.to)\n }\n\n if (textStart > range.from) {\n tr.delete(range.from + startSpaces, textStart)\n }\n\n markEnd = range.from + startSpaces + captureGroup.length\n\n tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}))\n\n tr.removeStoredMark(config.type)\n }\n },\n })\n}\n","import type { NodeType } from '@tiptap/pm/model'\n\nimport type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\nimport type { ExtendedRegExpMatchArray, JSONContent } from '../types.js'\nimport { callOrReturn } from '../utilities/index.js'\n\n/**\n * Build an paste rule that adds a node when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/api/paste-rules\n */\nexport function nodePasteRule(config: {\n find: PasteRuleFinder\n type: NodeType\n getAttributes?:\n | Record<string, any>\n | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)\n | false\n | null\n getContent?: JSONContent[] | ((attrs: Record<string, any>) => JSONContent[]) | false | null\n}) {\n return new PasteRule({\n find: config.find,\n handler({ match, chain, range, pasteEvent }) {\n const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)\n const content = callOrReturn(config.getContent, undefined, attributes)\n\n if (attributes === false || attributes === null) {\n return null\n }\n\n const node = { type: config.type.name, attrs: attributes } as JSONContent\n\n if (content) {\n node.content = content\n }\n\n if (match.input) {\n chain().deleteRange(range).insertContentAt(range.from, node)\n }\n },\n })\n}\n","import type { PasteRuleFinder } from '../PasteRule.js'\nimport { PasteRule } from '../PasteRule.js'\n\n/**\n * Build an paste rule that replaces text when the\n * matched text is pasted into it.\n * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules\n */\nexport function textPasteRule(config: { find: PasteRuleFinder; replace: string }) {\n return new PasteRule({\n find: config.find,\n handler: ({ state, range, match }) => {\n let insert = config.replace\n let start = range.from\n const end = range.to\n\n if (match[1]) {\n const offset = match[0].lastIndexOf(match[1])\n\n insert += match[0].slice(offset + match[1].length)\n start += offset\n\n const cutOff = start - end\n\n if (cutOff > 0) {\n insert = match[0].slice(offset - cutOff, offset) + insert\n start = end\n }\n }\n\n state.tr.insertText(insert, start, end)\n },\n })\n}\n","import type { Transaction } from '@tiptap/pm/state'\n\nexport interface TrackerResult {\n position: number\n deleted: boolean\n}\n\nexport class Tracker {\n transaction: Transaction\n\n currentStep: number\n\n constructor(transaction: Transaction) {\n this.transaction = transaction\n this.currentStep = this.transaction.steps.length\n }\n\n map(position: number): TrackerResult {\n let deleted = false\n\n const mappedPosition = this.transaction.steps.slice(this.currentStep).reduce((newPosition, step) => {\n const mapResult = step.getMap().mapResult(newPosition)\n\n if (mapResult.deleted) {\n deleted = true\n }\n\n return mapResult.pos\n }, position)\n\n return {\n position: mappedPosition,\n deleted,\n }\n }\n}\n","import { Mark, mergeAttributes } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/core'\nimport type { CommentWithUser } from './comments'\n\nexport interface CommentMarkOptions {\n onCommentClick?: (commentId: string) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n comment: {\n setComment: (commentId: string) => ReturnType\n unsetComment: (commentId: string) => ReturnType\n }\n }\n}\n\nexport const CommentMark = Mark.create<CommentMarkOptions>({\n name: 'comment',\n\n addOptions() {\n return {\n onCommentClick: undefined,\n }\n },\n\n addAttributes() {\n return {\n commentId: {\n default: null,\n parseHTML: (element) => element.getAttribute('data-comment-id'),\n renderHTML: (attributes) => ({\n 'data-comment-id': attributes.commentId,\n }),\n },\n }\n },\n\n parseHTML() {\n return [{ tag: 'mark[data-comment-id]' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'mark',\n mergeAttributes(HTMLAttributes, {\n class:\n 'bg-yellow-200/50 dark:bg-yellow-500/30 dark:text-foreground cursor-pointer hover:bg-yellow-300/60 dark:hover:bg-yellow-500/40 transition-colors rounded-sm',\n }),\n 0,\n ]\n },\n\n addCommands() {\n return {\n setComment:\n (commentId: string) =>\n ({ commands }) => {\n return commands.setMark(this.name, { commentId })\n },\n unsetComment:\n (commentId: string) =>\n ({ tr, state }) => {\n const { doc } = state\n let found = false\n\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === this.name && mark.attrs.commentId === commentId) {\n tr.removeMark(pos, pos + node.nodeSize, mark.type)\n found = true\n }\n })\n })\n\n return found\n },\n }\n },\n\n addProseMirrorPlugins() {\n const { onCommentClick } = this.options\n\n return [\n new Plugin({\n key: new PluginKey('commentClick'),\n props: {\n handleClick(view, pos) {\n if (!onCommentClick) return false\n\n const { state } = view\n const $pos = state.doc.resolve(pos)\n const marks = $pos.marks()\n\n const commentMark = marks.find((mark) => mark.type.name === 'comment')\n if (commentMark && commentMark.attrs.commentId) {\n // Blur the editor to prevent keyboard popup on mobile\n ;(view.dom as HTMLElement).blur()\n onCommentClick(commentMark.attrs.commentId)\n return true\n }\n\n return false\n },\n },\n }),\n ]\n },\n})\n\n/**\n * Apply comment mark to the current selection\n */\nexport function addCommentMark(\n editor: Editor,\n commentId: string,\n from: number,\n to: number\n): void {\n // Guard against editor not being ready\n if (!editor.view || editor.isDestroyed) {\n console.warn('Cannot add comment mark: editor not ready')\n return\n }\n \n editor\n .chain()\n .setTextSelection({ from, to })\n .setComment(commentId)\n .run()\n}\n\n/**\n * Remove comment mark from the document\n */\nexport function removeCommentMark(editor: Editor, commentId: string): void {\n if (!editor.view || editor.isDestroyed) return\n editor.chain().unsetComment(commentId).run()\n}\n\n/**\n * Re-apply comment marks based on quoted text matching.\n * Called when loading a post with existing comments.\n */\nexport function applyCommentMarks(\n editor: Editor,\n comments: CommentWithUser[]\n): void {\n if (!editor.view || editor.isDestroyed) return\n \n const { doc } = editor.state\n const textContent = doc.textContent\n\n comments.forEach((comment) => {\n if (!comment.quotedText || comment.parentId || comment.resolved) return // Skip replies\n\n const index = textContent.indexOf(comment.quotedText)\n if (index === -1) return // Text not found\n\n // Find the actual position in the document\n let currentPos = 0\n let startPos: number | null = null\n let endPos: number | null = null\n\n doc.descendants((node, pos) => {\n if (startPos !== null && endPos !== null) return false\n\n if (node.isText && node.text) {\n const nodeStart = currentPos\n const nodeEnd = currentPos + node.text.length\n\n if (startPos === null && nodeEnd > index) {\n // Start is in this node\n const offsetInNode = index - nodeStart\n startPos = pos + offsetInNode\n }\n\n if (startPos !== null && endPos === null) {\n const targetEnd = index + comment.quotedText.length\n if (nodeEnd >= targetEnd) {\n // End is in this node\n const offsetInNode = targetEnd - nodeStart\n endPos = pos + offsetInNode\n }\n }\n\n currentPos = nodeEnd\n }\n\n return true\n })\n\n if (startPos !== null && endPos !== null) {\n editor\n .chain()\n .setTextSelection({ from: startPos, to: endPos })\n .setComment(comment.id)\n .setTextSelection(endPos) // Deselect\n .run()\n }\n })\n}\n\n/**\n * Scroll to a comment mark in the editor\n */\nexport function scrollToComment(editor: Editor, commentId: string): void {\n if (!editor.view || editor.isDestroyed) return\n \n const { doc } = editor.state\n\n doc.descendants((node, pos) => {\n const commentMark = node.marks.find(\n (mark) => mark.type.name === 'comment' && mark.attrs.commentId === commentId\n )\n\n if (commentMark) {\n editor.chain().setTextSelection(pos).run()\n\n // Scroll to the selection\n const view = editor.view\n const coords = view.coordsAtPos(pos)\n const editorRect = view.dom.getBoundingClientRect()\n\n if (coords.top < editorRect.top || coords.bottom > editorRect.bottom) {\n view.dom.scrollIntoView({ behavior: 'smooth', block: 'center' })\n }\n\n return false // Stop iteration\n }\n\n return true\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAQa,2BAwDA,uBAmCA,0BAgCA,6BAyDA,uBAmBA,oBA+CA,wBA0CA,8BA+CA;AAvVb;AAAA;AAAA;AAQO,IAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDlC,IAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmC9B,IAAM,2BAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCjC,IAAM,8BAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AC;AAED,QAAI,aAAa,QAAQ,WAAW,MAAM;AACxC,aACG,MAAM,EACN,iBAAiB,EAAE,MAAM,UAAU,IAAI,OAAO,CAAC,EAC/C,WAAW,QAAQ,EAAE,EACrB,iBAAiB,MAAM,EACvB,IAAI;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAKO,SAAS,gBAAgB,QAAgB,WAAyB;AACvE,MAAI,CAAC,OAAO,QAAQ,OAAO,YAAa;AAExC,QAAM,EAAE,IAAI,IAAI,OAAO;AAEvB,MAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,UAAM,cAAc,KAAK,MAAM;AAAA,MAC7B,CAAC,SAAS,KAAK,KAAK,SAAS,aAAa,KAAK,MAAM,cAAc;AAAA,IACrE;AAEA,QAAI,aAAa;AACf,aAAO,MAAM,EAAE,iBAAiB,GAAG,EAAE,IAAI;AAGzC,YAAM,OAAO,OAAO;AACpB,YAAM,SAAS,KAAK,YAAY,GAAG;AACnC,YAAM,aAAa,KAAK,IAAI,sBAAsB;AAElD,UAAI,OAAO,MAAM,WAAW,OAAO,OAAO,SAAS,WAAW,QAAQ;AACpE,aAAK,IAAI,eAAe,EAAE,UAAU,UAAU,OAAO,SAAS,CAAC;AAAA,MACjE;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AACH;","names":["OpenAI","Anthropic","response","content","extractUrls","jsonResponse","jsonResponse","jsonResponse","jsonResponse","wordCount","expandPlanStream","generateStream","generate","chatStream","buildRewritePrompt","createStream","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","jsonResponse","Parser","TurndownService","sanitizeHtml","generateUniqueSlug","import_commands","import_state","import_model","import_transform","import_schema_list","command","run","__export","originalCreateParagraphNear","originalDeleteSelection","originalExitCode","mark","TextSelection","ProseMirrorNode","parser","Selection","Fragment","isTextSelection","originalJoinUp","originalJoinDown","originalJoinBackward","originalJoinForward","joinPoint","originalCommand","isActive","originalLift","originalLiftEmptyBlock","originalLiftListItem","originalNewlineInCode","originalSelectNodeBackward","originalSelectNodeForward","originalSelectParentNode","originalSelectTextblockEnd","originalSelectTextblockStart","document","style","Schema","range","NodeSelection","TextSelection","originalSinkListItem","first","Fragment","newNextTypeAttributes","nextType","canSplit","isActive","originalWrapIn","originalWrapInList","Fragment","run","Plugin","Fragment","from","to","__export","range","_a","_b","_c","PluginKey","Selection","tr","__export","parseAttributes","serializeAttributes","h","nextIndent","import_state"]}