react-reason-editor 1.0.114 → 1.0.116
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/Ai-DOAuz6ZE.js +1 -0
- package/dist/Ai-DVWZg0-D.cjs +1 -0
- package/dist/Ai.cjs +1 -1
- package/dist/Ai.js +1 -1
- package/dist/BubbleMenus-D8BicxJF.cjs +1 -0
- package/dist/{BubbleMenus-CFzQBrVG.js → BubbleMenus-DopOZm_P.js} +43 -43
- package/dist/{Drawio-s-Xgqy7a.js → Drawio-LEtUoVAY.js} +7 -7
- package/dist/Drawio.js +1 -1
- package/dist/{Emoji-CTKm00BR.js → Emoji-CIxVw-Kv.js} +2 -2
- package/dist/Emoji.js +1 -1
- package/dist/{ReasonDocs-CsmZMk6W.cjs → ReasonDocs-BCjyspDd.cjs} +1 -1
- package/dist/{ReasonDocs-BXtUm4zk.js → ReasonDocs-eAuJLZVg.js} +17 -17
- package/dist/{RichTextProvider-KRSFedCE.cjs → RichTextProvider-C0V3hhy_.cjs} +1 -1
- package/dist/RichTextProvider-z_4PSTNH.js +5 -0
- package/dist/{bubble-B39N7x_B.js → bubble-DF0FOqik.js} +17 -17
- package/dist/bubble.cjs +1 -1
- package/dist/bubble.js +1 -1
- package/dist/docs-agent/plate/ai-controller.d.ts +82 -0
- package/dist/docs-agent/plate/kits/ai-kit.d.ts +37 -0
- package/dist/docs-agent/plate/ui/ai-menu.d.ts +19 -0
- package/dist/docs-agent/plate/ui/ai-toolbar-button.d.ts +12 -0
- package/dist/docs-agent.cjs +1 -1
- package/dist/docs-agent.d.ts +4 -0
- package/dist/docs-agent.js +18 -18
- package/dist/editor-kit.cjs +1 -1
- package/dist/editor-kit.js +1 -1
- package/dist/editorConfig-CpUHUq44.js +18 -0
- package/dist/editorConfig-DaUET9eN.cjs +1 -0
- package/dist/extensions/Ai/index.d.ts +1 -0
- package/dist/extensions/Ai/lib/rewriteEndpoint.d.ts +17 -0
- package/dist/{html-to-docx.esm-BLUcO7pp-BKB2FJoB.cjs → html-to-docx.esm-BLUcO7pp-sCMiaq9J.cjs} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/reason-docs.cjs +1 -1
- package/dist/reason-docs.js +1 -1
- package/dist/reason-toolbar-skin-BQRPoci6.cjs +1 -0
- package/dist/reason-toolbar-skin-Beh6Q5Ra.js +560 -0
- package/package.json +2 -2
- package/dist/Ai-B_8fziaT.js +0 -1
- package/dist/Ai-BxQjqvdT.cjs +0 -1
- package/dist/BubbleMenus-3RiQc4lw.cjs +0 -1
- package/dist/RichTextProvider-BcsYTR6Z.js +0 -5
- package/dist/editorConfig-9-ZxkRbw.js +0 -18
- package/dist/editorConfig-DF8EAH_P.cjs +0 -1
- package/dist/reason-toolbar-skin-DY4w9SRA.cjs +0 -1
- package/dist/reason-toolbar-skin-DarRq6V-.js +0 -539
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./marked.esm-CvRFZKa2.js";import{Extension as t}from"@tiptap/core";import{Plugin as n,PluginKey as o}from"@tiptap/pm/state";import{ArrowRightLeft as i,Baby as r,Briefcase as a,CheckCheck as s,Coffee as c,Feather as l,FileText as m,Languages as d,ListChecks as u,ListTree as p,Minus as g,PenLine as h,Plus as f,Quote as b,SmilePlus as w,Sparkles as x,WandSparkles as y}from"lucide-react";import{Decoration as v,DecorationSet as k}from"@tiptap/pm/view";var C=[{id:"en",label:"English"},{id:"es",label:"Spanish"},{id:"fr",label:"French"},{id:"de",label:"German"},{id:"pt",label:"Portuguese"},{id:"it",label:"Italian"},{id:"zh",label:"Chinese (Simplified)"},{id:"ja",label:"Japanese"},{id:"ko",label:"Korean"},{id:"hi",label:"Hindi"},{id:"ar",label:"Arabic"},{id:"ru",label:"Russian"}],M=[{id:"improve",label:"Improve writing",description:"Clearer, tighter, same meaning",icon:x,group:"edit",prompt:"Improve the clarity, flow and word choice of the text. Keep the author's meaning, voice, facts and level of formality exactly as they are, and keep roughly the same length."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:s,group:"edit",prompt:"Correct spelling, grammar, punctuation and obvious typos in the text. Change nothing else: keep the original wording, sentence structure, tone and formatting. If the text is already correct, return it unchanged."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:g,group:"edit",prompt:"Rewrite the text roughly half as long. Cut redundancy, filler and hedging, but keep every claim, figure, name and qualifier that carries meaning."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:f,group:"edit",prompt:"Expand the text with useful detail, explanation and structure, staying on the same topic and in the same voice. Do not invent facts, statistics, quotations or sources — expand only on what the text already implies."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:l,group:"edit",prompt:"Rewrite the text in plain, direct language: common words, shorter sentences, active voice. Keep all of the original meaning, including any technical terms that have no plain equivalent."},{id:"rephrase",label:"Rephrase",description:"Same point, fresh wording",icon:i,group:"edit",prompt:"Rewrite the text with different wording and sentence structure while preserving its meaning, tone and approximate length. Avoid reusing the original phrasing."},{id:"professional",label:"Professional tone",description:"Polished and businesslike",icon:a,group:"tone",prompt:"Rewrite the text in a polished, professional tone: precise, courteous, free of slang and exclamation marks. Do not change the meaning or add new claims."},{id:"casual",label:"Casual tone",description:"Relaxed and conversational",icon:c,group:"tone",prompt:"Rewrite the text in a relaxed, conversational tone, as if explaining it to a colleague. Keep it clear and keep the meaning unchanged; do not add jokes or filler."},{id:"confident",label:"More confident",description:"Drop the hedging",icon:h,group:"tone",prompt:'Rewrite the text so it reads more decisively: remove hedges such as "maybe", "I think" and "sort of", and use active voice. Keep any genuine uncertainty that the text explicitly states.'},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:w,group:"tone",prompt:"Add a small number of relevant emoji to the text, at most one per sentence. Do not change any of the wording."},{id:"summarize",label:"Summarize",description:"Condense into a short paragraph",icon:m,group:"transform",prompt:"Summarize the text in one short paragraph that captures its main point and the reasoning behind it. Use only information present in the text."},{id:"key-points",label:"Key takeaways",description:"Turn it into a bullet list",icon:p,group:"transform",prompt:'Rewrite the text as a list of the key takeaways, one per line, each starting with "- ". Keep each line to a single sentence and use only information present in the text.'},{id:"action-items",label:"Extract action items",description:"Who does what, next",icon:u,group:"transform",prompt:'List the concrete action items implied by the text, one per line, each starting with "- " and written as an imperative with the owner named when the text names one. If the text contains no action items, return "- No action items.".'},{id:"explain",label:"Explain this",description:"Plain-English explanation",icon:r,group:"transform",prompt:"Explain what the text means in plain English, in one short paragraph a non-expert can follow. Explain the text; do not rewrite or evaluate it."},{id:"translate",label:"Translate",description:"Into another language",icon:d,group:"transform",options:C,prompt:"Translate the text accurately, preserving tone, formatting, line breaks, names, URLs, code and numbers. Target language:"},{id:"continue",label:"Continue writing",description:"Pick up where the text stops",icon:y,group:"generate",requiresSelection:!1,prompt:"Continue the document from where it stops, in the same voice, tense and formatting. Write one or two paragraphs that follow naturally. Do not repeat what has already been written and do not invent sources or statistics."},{id:"outline",label:"Draft an outline",description:"Headings for this document",icon:p,group:"generate",requiresSelection:!1,prompt:'Draft a working outline for this document, one heading per line, each starting with "- ". Base it on what the document is already about.'},{id:"counterpoint",label:"Counterpoint",description:"The strongest objection",icon:b,group:"transform",prompt:"State the strongest good-faith objection to the argument in the text, in one short paragraph. Name the assumption it challenges. Do not invent evidence, sources or statistics."}],S={edit:"Edit",tone:"Tone",transform:"Transform",generate:"Generate"},T=["edit","tone","transform","generate"],L=[/^#{1,6}\s+/m,/^\s*[-*+]\s+\S/m,/^\s*\d+\.\s+\S/m,/^\s*>\s+\S/m,/^\s*[-*]\s+\[[ xX]\]/m,/^\|.+\|\s*$/m,/^\s*(?:---|\*\*\*)\s*$/m],$=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function A(e){return function(e){return L.some(t=>t.test(e))||$.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}function q(t){return e.parse(t,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function I(e){const t=e.trim();return t?A(t)?{content:q(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}var E=["You are a writing assistant inside a rich-text editor.","Return only the text that should appear in the document — nothing else.","Never add a preamble, sign-off, explanation, or commentary about what you changed.","Never wrap the answer in Markdown code fences or quotation marks unless the original text was itself fenced or quoted.","Preserve the original language of the text unless asked to translate.","Preserve quotations, citations, URLs, code, numbers and proper nouns exactly, unless the instruction is explicitly about changing them.","Never invent facts, statistics, sources, citations or links.","Match the surrounding formatting: plain paragraphs separated by blank lines, and one item per line for lists."].join("\n");function R(e,t){return t?e:e.filter(e=>!(!1!==e.requiresSelection))}function j(e){return T.map(t=>({group:t,commands:e.filter(e=>(e.group??"edit")===t)})).filter(e=>e.commands.length>0)}function P(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}function D(e,t){return t<=0?"":e.length<=t?e:`…${e.slice(e.length-t)}`}function N(e){const t=[`Instruction:\n${e.instruction}`];return e.documentText.trim()&&t.push(`Surrounding document (context only, do not rewrite):\n${e.documentText}`),t.push("replace"===e.mode?`Text to act on:\n${e.selectedText}`:"No text is selected. Write new content for the caret position, using the context above."),t.join("\n\n")}function W(e,t){return new Promise((n,o)=>{const i=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(i),o(new DOMException("Aborted","AbortError"))},{once:!0})})}var B=async(e,t,n)=>{const o=function(e,t,n){const o=`${e} ${t}`.toLowerCase(),i=n.trim();if(!i)return o.includes("outline")?"- Background\n- What changed\n- Why it matters\n- Next steps":`${t.trim()||"New content"}\n\n(Offline demo response — configure Ai.configure({ getCompletion }) to use a real model.)`;if(o.includes("emoji"))return`${i} ✨📝`;if(o.includes("shorter")||o.includes("concise")){const e=i.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return o.includes("longer")||o.includes("expand")?`${i} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:o.includes("key-points")||o.includes("action-items")||o.includes("takeaway")?i.split(/(?<=[.!?])\s+/).map(e=>e.trim()).filter(Boolean).map(e=>`- ${e.replace(/[.!?]$/,"")}`).join("\n"):o.includes("simplify")?i.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):i.charAt(0).toUpperCase()+i.slice(1).replace(/\s{2,}/g," ")}(e.commandId,e.instruction,e.selectedText).split(/(\s+)/).filter(Boolean);let i="";for(const r of o){if(n.aborted)throw new DOMException("Aborted","AbortError");i+=r,t(i),r.trim()&&await W(35,n)}return i},K=/^(?:sure|certainly|of course|absolutely|got it|okay|ok|here(?:'|’)?s|here is|here are|below is|i(?:'|’)?ve|i have)\b[^\n:]{0,120}:[ \t]*\r?\n+/i,O=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,z=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,H=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function U(e,{streaming:t=!1}={}){if(!e)return"";let n=function(e){return e.replace(/\r\n/g,"\n").replace(/[ \t]+$/gm,"").replace(/\n{3,}/g,"\n\n")}(e);return n=function(e){const t=e.replace(K,"");return t!==e?t:e.replace(O,"")}(n),n=function(e){if(!z.test(e))return e;const t=e.replace(z,"").replace(H,"");return/(?:^|\n)[ \t]*(?:```|~~~)/.test(t)?e:t}(n),t||(n=function(e){const t=e.trim();if(t.length<2)return e;for(const[n,o]of[['"','"'],["“","”"],["'","'"],["‘","’"]]){if(!t.startsWith(n)||!t.endsWith(o))continue;const e=t.slice(n.length,t.length-o.length);if(!e.includes(o))return e}return e}(n)),n=n.replace(/^\n+/,""),t?n.replace(/[ \t]+$/," ").replace(/^[ \t]+/,""):n.trim()}var G=new o("ai");function F(e){return G.getState(e)}function J(e){return e.extensionManager.extensions.find(e=>"ai"===e.name)?.options}function X(e){return!!e&&"function"==typeof e.commands.openAiMenu}function Y(e,t){switch(e.status){case"menu":case"loading":case"error":return{from:e.from,to:e.to};case"reviewing":return{from:e.suggestion.from,to:e.suggestion.to};default:return t}}function _(e,t,n){if("loading"===t.status)return k.create(e,[v.widget(t.to,()=>{const e=document.createElement("span");return e.className=n.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:o,to:i,suggestedText:r,mode:a}=t.suggestion,s=[];return"replace"===a&&i>o&&s.push(v.inline(o,i,{class:n.removedClass})),s.push(v.widget(i,()=>{const e=document.createElement("span");return e.className=n.insertedClass,e.textContent=r||"…",e},{side:1})),k.create(e,s)}return k.empty}async function Q(e,t,n,o,i,r){const{view:a}=e,s=e.state.doc,c=i===r?"":s.textBetween(i,r,"\n"),l=function(e,t,n,o){if(o<=0)return"";const i=o+200,r=e.textBetween(Math.max(0,t-i),t,"\n"),a=e.textBetween(n,Math.min(e.content.size,n+i),"\n"),s=D(r,Math.floor(o/2)),c=a.length>o-s.length?`${a.slice(0,o-s.length)}…`:a;return`${s}${s&&c?"\n":""}${c}`.trim()}(s,i,r,t.contextChars),m=c?"replace":"insert";n.abortController?.abort();const d=new AbortController;n.abortController=d;const u=n.requestToken+=1;a.dispatch(a.state.tr.setMeta(G,{type:"set-loading",from:i,to:r,commandId:o.commandId,commandLabel:o.commandLabel,instruction:o.instruction,option:o.option}));const p=(t,a)=>{if(u!==n.requestToken||e.isDestroyed)return;const s=U(t,{streaming:a});e.view.dispatch(e.view.state.tr.setMeta(G,{type:"set-suggestion",commandLabel:o.commandLabel,suggestion:{from:i,to:r,originalText:c,suggestedText:s,mode:m,isStreaming:a}}))};try{const a=await t.getCompletion({instruction:o.instruction,selectedText:c,documentText:l,commandId:o.commandId,commandLabel:o.commandLabel,option:o.option,systemPrompt:t.systemPrompt,mode:m},e=>p(e,!0),d.signal);if(u!==n.requestToken||e.isDestroyed)return;if(!U(a))return void e.view.dispatch(e.view.state.tr.setMeta(G,{type:"set-error",from:i,to:r,commandLabel:o.commandLabel,message:"The model returned an empty response."}));p(a,!1)}catch(g){if(d.signal.aborted||u!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(G,{type:"set-error",from:i,to:r,commandLabel:o.commandLabel,message:g instanceof Error?g.message:"Something went wrong."}))}}var V=t.create({name:"ai",addOptions:()=>({commands:M,getCompletion:B,systemPrompt:E,contextChars:4e3,removedClass:"ai-removed-text",insertedClass:"ai-suggested-text",loadingClass:"ai-loading-indicator"}),addStorage:()=>({requestToken:0,abortController:null}),onDestroy(){this.storage.abortController?.abort()},addKeyboardShortcuts(){return{"Mod-j":()=>this.editor.commands.openAiMenu()}},addCommands(){const e=()=>{this.storage.abortController?.abort(),this.storage.abortController=null,this.storage.requestToken+=1};return{openAiMenu:()=>({state:t,dispatch:n})=>{e();const{from:o,to:i}=t.selection;return n&&n(t.tr.setMeta(G,{type:"open-menu",from:o,to:i})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(G,{type:"close"})),!0),stopAiGeneration:()=>({state:t,dispatch:n})=>{const o=F(t)?.panel;if(!o||"loading"!==o.status&&"reviewing"!==o.status)return!1;if("reviewing"===o.status&&!o.suggestion.isStreaming)return!1;if(e(),!n)return!0;if("reviewing"===o.status)n(t.tr.setMeta(G,{type:"settle"}));else{const{from:e,to:i}=Y(o,t.selection);n(t.tr.setMeta(G,{type:"open-menu",from:e,to:i}))}return!0},runAiCommand:(e,t)=>({state:n,editor:o})=>{const i=this.options.commands.find(t=>t.id===e);if(!i)return!1;const{from:r,to:a}=Y(F(n)?.panel??{status:"closed"},n.selection);return(!1===i.requiresSelection||r!==a)&&(!(i.options?.length&&!t)&&(Q(o,this.options,this.storage,{instruction:P(i,t),commandId:i.id,commandLabel:t?`${i.label} → ${t}`:i.label,option:t},r,a),!0))},submitAiPrompt:e=>({state:t,editor:n})=>{const o=e.trim();if(!o)return!1;const{from:i,to:r}=Y(F(t)?.panel??{status:"closed"},t.selection);return Q(n,this.options,this.storage,{instruction:o,commandId:"custom",commandLabel:"Custom"},i,r),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const n=F(e)?.lastRequest;return!!n&&(Q(t,this.options,this.storage,{instruction:n.instruction,commandId:n.commandId,commandLabel:n.commandLabel,option:n.option},n.from,n.to),!0)},acceptAiSuggestion:()=>({state:t,chain:n})=>{const o=F(t)?.panel;if(!o||"reviewing"!==o.status||o.suggestion.isStreaming)return!1;const{from:i,to:r,suggestedText:a}=o.suggestion,{content:s}=I(a);return!!s&&(e(),n().insertContentAt({from:i,to:r},s,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(G,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(G,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:t,chain:n})=>{const o=F(t)?.panel;if(!o||"reviewing"!==o.status||o.suggestion.isStreaming)return!1;const{to:i,suggestedText:r}=o.suggestion,{content:a}=I(r);if(!a)return!1;const s=t.doc.resolve(Math.min(i,t.doc.content.size)),c=s.depth>0?s.after(s.depth):s.pos;return e(),n().insertContentAt(c,a,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(G,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new n({key:G,state:{init:()=>({panel:{status:"closed"},decorations:k.empty,lastRequest:null}),apply(t,n){let o=n.panel,i=n.lastRequest;t.docChanged&&(o=function(e,t){switch(e.status){case"closed":default:return e;case"menu":case"loading":case"error":return{...e,from:t.map(e.from),to:t.map(e.to)};case"reviewing":return{...e,suggestion:{...e.suggestion,from:t.map(e.suggestion.from),to:t.map(e.suggestion.to)}}}}(o,t.mapping));const r=t.getMeta(G);if(r)switch(r.type){case"open-menu":o={status:"menu",from:r.from,to:r.to};break;case"set-loading":o={status:"loading",from:r.from,to:r.to,commandLabel:r.commandLabel},i={instruction:r.instruction,commandId:r.commandId,commandLabel:r.commandLabel,option:r.option,from:r.from,to:r.to};break;case"set-suggestion":o={status:"reviewing",suggestion:r.suggestion,commandLabel:r.commandLabel};break;case"set-error":o={status:"error",from:r.from,to:r.to,commandLabel:r.commandLabel,message:r.message};break;case"settle":"reviewing"===o.status&&(o={...o,suggestion:{...o.suggestion,isStreaming:!1}});break;case"close":o={status:"closed"}}return{panel:o,decorations:_(t.doc,o,e),lastRequest:i}}},props:{decorations(e){return this.getState(e)?.decorations??k.empty}}})]}});export{C as _,X as a,E as c,D as d,R as f,M as g,S as h,F as i,P as l,A as m,G as n,U as o,j as p,J as r,B as s,V as t,N as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./marked.esm-BDM-vMuY.cjs");let t=require("@tiptap/core"),n=require("@tiptap/pm/state"),o=require("lucide-react"),r=require("@tiptap/pm/view");var i=[{id:"en",label:"English"},{id:"es",label:"Spanish"},{id:"fr",label:"French"},{id:"de",label:"German"},{id:"pt",label:"Portuguese"},{id:"it",label:"Italian"},{id:"zh",label:"Chinese (Simplified)"},{id:"ja",label:"Japanese"},{id:"ko",label:"Korean"},{id:"hi",label:"Hindi"},{id:"ar",label:"Arabic"},{id:"ru",label:"Russian"}],a=[{id:"improve",label:"Improve writing",description:"Clearer, tighter, same meaning",icon:o.Sparkles,group:"edit",prompt:"Improve the clarity, flow and word choice of the text. Keep the author's meaning, voice, facts and level of formality exactly as they are, and keep roughly the same length."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:o.CheckCheck,group:"edit",prompt:"Correct spelling, grammar, punctuation and obvious typos in the text. Change nothing else: keep the original wording, sentence structure, tone and formatting. If the text is already correct, return it unchanged."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:o.Minus,group:"edit",prompt:"Rewrite the text roughly half as long. Cut redundancy, filler and hedging, but keep every claim, figure, name and qualifier that carries meaning."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:o.Plus,group:"edit",prompt:"Expand the text with useful detail, explanation and structure, staying on the same topic and in the same voice. Do not invent facts, statistics, quotations or sources — expand only on what the text already implies."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:o.Feather,group:"edit",prompt:"Rewrite the text in plain, direct language: common words, shorter sentences, active voice. Keep all of the original meaning, including any technical terms that have no plain equivalent."},{id:"rephrase",label:"Rephrase",description:"Same point, fresh wording",icon:o.ArrowRightLeft,group:"edit",prompt:"Rewrite the text with different wording and sentence structure while preserving its meaning, tone and approximate length. Avoid reusing the original phrasing."},{id:"professional",label:"Professional tone",description:"Polished and businesslike",icon:o.Briefcase,group:"tone",prompt:"Rewrite the text in a polished, professional tone: precise, courteous, free of slang and exclamation marks. Do not change the meaning or add new claims."},{id:"casual",label:"Casual tone",description:"Relaxed and conversational",icon:o.Coffee,group:"tone",prompt:"Rewrite the text in a relaxed, conversational tone, as if explaining it to a colleague. Keep it clear and keep the meaning unchanged; do not add jokes or filler."},{id:"confident",label:"More confident",description:"Drop the hedging",icon:o.PenLine,group:"tone",prompt:'Rewrite the text so it reads more decisively: remove hedges such as "maybe", "I think" and "sort of", and use active voice. Keep any genuine uncertainty that the text explicitly states.'},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:o.SmilePlus,group:"tone",prompt:"Add a small number of relevant emoji to the text, at most one per sentence. Do not change any of the wording."},{id:"summarize",label:"Summarize",description:"Condense into a short paragraph",icon:o.FileText,group:"transform",prompt:"Summarize the text in one short paragraph that captures its main point and the reasoning behind it. Use only information present in the text."},{id:"key-points",label:"Key takeaways",description:"Turn it into a bullet list",icon:o.ListTree,group:"transform",prompt:'Rewrite the text as a list of the key takeaways, one per line, each starting with "- ". Keep each line to a single sentence and use only information present in the text.'},{id:"action-items",label:"Extract action items",description:"Who does what, next",icon:o.ListChecks,group:"transform",prompt:'List the concrete action items implied by the text, one per line, each starting with "- " and written as an imperative with the owner named when the text names one. If the text contains no action items, return "- No action items.".'},{id:"explain",label:"Explain this",description:"Plain-English explanation",icon:o.Baby,group:"transform",prompt:"Explain what the text means in plain English, in one short paragraph a non-expert can follow. Explain the text; do not rewrite or evaluate it."},{id:"translate",label:"Translate",description:"Into another language",icon:o.Languages,group:"transform",options:i,prompt:"Translate the text accurately, preserving tone, formatting, line breaks, names, URLs, code and numbers. Target language:"},{id:"continue",label:"Continue writing",description:"Pick up where the text stops",icon:o.WandSparkles,group:"generate",requiresSelection:!1,prompt:"Continue the document from where it stops, in the same voice, tense and formatting. Write one or two paragraphs that follow naturally. Do not repeat what has already been written and do not invent sources or statistics."},{id:"outline",label:"Draft an outline",description:"Headings for this document",icon:o.ListTree,group:"generate",requiresSelection:!1,prompt:'Draft a working outline for this document, one heading per line, each starting with "- ". Base it on what the document is already about.'},{id:"counterpoint",label:"Counterpoint",description:"The strongest objection",icon:o.Quote,group:"transform",prompt:"State the strongest good-faith objection to the argument in the text, in one short paragraph. Name the assumption it challenges. Do not invent evidence, sources or statistics."}],s={edit:"Edit",tone:"Tone",transform:"Transform",generate:"Generate"},c=["edit","tone","transform","generate"],l=[/^#{1,6}\s+/m,/^\s*[-*+]\s+\S/m,/^\s*\d+\.\s+\S/m,/^\s*>\s+\S/m,/^\s*[-*]\s+\[[ xX]\]/m,/^\|.+\|\s*$/m,/^\s*(?:---|\*\*\*)\s*$/m],u=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function d(e){return function(e){return l.some(t=>t.test(e))||u.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}function m(t){return e.f.parse(t,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function p(e){const t=e.trim();return t?d(t)?{content:m(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}var g=["You are a writing assistant inside a rich-text editor.","Return only the text that should appear in the document — nothing else.","Never add a preamble, sign-off, explanation, or commentary about what you changed.","Never wrap the answer in Markdown code fences or quotation marks unless the original text was itself fenced or quoted.","Preserve the original language of the text unless asked to translate.","Preserve quotations, citations, URLs, code, numbers and proper nouns exactly, unless the instruction is explicitly about changing them.","Never invent facts, statistics, sources, citations or links.","Match the surrounding formatting: plain paragraphs separated by blank lines, and one item per line for lists."].join("\n");function h(e,t){return t?e:e.filter(e=>!(!1!==e.requiresSelection))}function f(e){return c.map(t=>({group:t,commands:e.filter(e=>(e.group??"edit")===t)})).filter(e=>e.commands.length>0)}function b(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}function x(e,t){return t<=0?"":e.length<=t?e:`…${e.slice(e.length-t)}`}function y(e){const t=[`Instruction:\n${e.instruction}`];return e.documentText.trim()&&t.push(`Surrounding document (context only, do not rewrite):\n${e.documentText}`),t.push("replace"===e.mode?`Text to act on:\n${e.selectedText}`:"No text is selected. Write new content for the caret position, using the context above."),t.join("\n\n")}function w(e,t){return new Promise((n,o)=>{const r=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(r),o(new DOMException("Aborted","AbortError"))},{once:!0})})}var v=async(e,t,n)=>{const o=function(e,t,n){const o=`${e} ${t}`.toLowerCase(),r=n.trim();if(!r)return o.includes("outline")?"- Background\n- What changed\n- Why it matters\n- Next steps":`${t.trim()||"New content"}\n\n(Offline demo response — configure Ai.configure({ getCompletion }) to use a real model.)`;if(o.includes("emoji"))return`${r} ✨📝`;if(o.includes("shorter")||o.includes("concise")){const e=r.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return o.includes("longer")||o.includes("expand")?`${r} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:o.includes("key-points")||o.includes("action-items")||o.includes("takeaway")?r.split(/(?<=[.!?])\s+/).map(e=>e.trim()).filter(Boolean).map(e=>`- ${e.replace(/[.!?]$/,"")}`).join("\n"):o.includes("simplify")?r.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):r.charAt(0).toUpperCase()+r.slice(1).replace(/\s{2,}/g," ")}(e.commandId,e.instruction,e.selectedText).split(/(\s+)/).filter(Boolean);let r="";for(const i of o){if(n.aborted)throw new DOMException("Aborted","AbortError");r+=i,t(r),i.trim()&&await w(35,n)}return r},k=/^(?:sure|certainly|of course|absolutely|got it|okay|ok|here(?:'|’)?s|here is|here are|below is|i(?:'|’)?ve|i have)\b[^\n:]{0,120}:[ \t]*\r?\n+/i,C=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,S=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,A=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function P(e,{streaming:t=!1}={}){if(!e)return"";let n=function(e){return e.replace(/\r\n/g,"\n").replace(/[ \t]+$/gm,"").replace(/\n{3,}/g,"\n\n")}(e);return n=function(e){const t=e.replace(k,"");return t!==e?t:e.replace(C,"")}(n),n=function(e){if(!S.test(e))return e;const t=e.replace(S,"").replace(A,"");return/(?:^|\n)[ \t]*(?:```|~~~)/.test(t)?e:t}(n),t||(n=function(e){const t=e.trim();if(t.length<2)return e;for(const[n,o]of[['"','"'],["“","”"],["'","'"],["‘","’"]]){if(!t.startsWith(n)||!t.endsWith(o))continue;const e=t.slice(n.length,t.length-o.length);if(!e.includes(o))return e}return e}(n)),n=n.replace(/^\n+/,""),t?n.replace(/[ \t]+$/," ").replace(/^[ \t]+/,""):n.trim()}var M=new n.PluginKey("ai");function L(e){return M.getState(e)}function T(e){return e.extensionManager.extensions.find(e=>"ai"===e.name)?.options}function j(e){return!!e&&"function"==typeof e.commands.openAiMenu}function O(e,t){switch(e.status){case"menu":case"loading":case"error":return{from:e.from,to:e.to};case"reviewing":return{from:e.suggestion.from,to:e.suggestion.to};default:return t}}function D(e,t,n){if("loading"===t.status)return r.DecorationSet.create(e,[r.Decoration.widget(t.to,()=>{const e=document.createElement("span");return e.className=n.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:o,to:i,suggestedText:a,mode:s}=t.suggestion,c=[];return"replace"===s&&i>o&&c.push(r.Decoration.inline(o,i,{class:n.removedClass})),c.push(r.Decoration.widget(i,()=>{const e=document.createElement("span");return e.className=n.insertedClass,e.textContent=a||"…",e},{side:1})),r.DecorationSet.create(e,c)}return r.DecorationSet.empty}async function E(e,t,n,o,r,i){const{view:a}=e,s=e.state.doc,c=r===i?"":s.textBetween(r,i,"\n"),l=function(e,t,n,o){if(o<=0)return"";const r=o+200,i=e.textBetween(Math.max(0,t-r),t,"\n"),a=e.textBetween(n,Math.min(e.content.size,n+r),"\n"),s=x(i,Math.floor(o/2)),c=a.length>o-s.length?`${a.slice(0,o-s.length)}…`:a;return`${s}${s&&c?"\n":""}${c}`.trim()}(s,r,i,t.contextChars),u=c?"replace":"insert";n.abortController?.abort();const d=new AbortController;n.abortController=d;const m=n.requestToken+=1;a.dispatch(a.state.tr.setMeta(M,{type:"set-loading",from:r,to:i,commandId:o.commandId,commandLabel:o.commandLabel,instruction:o.instruction,option:o.option}));const p=(t,a)=>{if(m!==n.requestToken||e.isDestroyed)return;const s=P(t,{streaming:a});e.view.dispatch(e.view.state.tr.setMeta(M,{type:"set-suggestion",commandLabel:o.commandLabel,suggestion:{from:r,to:i,originalText:c,suggestedText:s,mode:u,isStreaming:a}}))};try{const a=await t.getCompletion({instruction:o.instruction,selectedText:c,documentText:l,commandId:o.commandId,commandLabel:o.commandLabel,option:o.option,systemPrompt:t.systemPrompt,mode:u},e=>p(e,!0),d.signal);if(m!==n.requestToken||e.isDestroyed)return;if(!P(a))return void e.view.dispatch(e.view.state.tr.setMeta(M,{type:"set-error",from:r,to:i,commandLabel:o.commandLabel,message:"The model returned an empty response."}));p(a,!1)}catch(g){if(d.signal.aborted||m!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(M,{type:"set-error",from:r,to:i,commandLabel:o.commandLabel,message:g instanceof Error?g.message:"Something went wrong."}))}}var I=t.Extension.create({name:"ai",addOptions:()=>({commands:a,getCompletion:v,systemPrompt:g,contextChars:4e3,removedClass:"ai-removed-text",insertedClass:"ai-suggested-text",loadingClass:"ai-loading-indicator"}),addStorage:()=>({requestToken:0,abortController:null}),onDestroy(){this.storage.abortController?.abort()},addKeyboardShortcuts(){return{"Mod-j":()=>this.editor.commands.openAiMenu()}},addCommands(){const e=()=>{this.storage.abortController?.abort(),this.storage.abortController=null,this.storage.requestToken+=1};return{openAiMenu:()=>({state:t,dispatch:n})=>{e();const{from:o,to:r}=t.selection;return n&&n(t.tr.setMeta(M,{type:"open-menu",from:o,to:r})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(M,{type:"close"})),!0),stopAiGeneration:()=>({state:t,dispatch:n})=>{const o=L(t)?.panel;if(!o||"loading"!==o.status&&"reviewing"!==o.status)return!1;if("reviewing"===o.status&&!o.suggestion.isStreaming)return!1;if(e(),!n)return!0;if("reviewing"===o.status)n(t.tr.setMeta(M,{type:"settle"}));else{const{from:e,to:r}=O(o,t.selection);n(t.tr.setMeta(M,{type:"open-menu",from:e,to:r}))}return!0},runAiCommand:(e,t)=>({state:n,editor:o})=>{const r=this.options.commands.find(t=>t.id===e);if(!r)return!1;const{from:i,to:a}=O(L(n)?.panel??{status:"closed"},n.selection);return(!1===r.requiresSelection||i!==a)&&(!(r.options?.length&&!t)&&(E(o,this.options,this.storage,{instruction:b(r,t),commandId:r.id,commandLabel:t?`${r.label} → ${t}`:r.label,option:t},i,a),!0))},submitAiPrompt:e=>({state:t,editor:n})=>{const o=e.trim();if(!o)return!1;const{from:r,to:i}=O(L(t)?.panel??{status:"closed"},t.selection);return E(n,this.options,this.storage,{instruction:o,commandId:"custom",commandLabel:"Custom"},r,i),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const n=L(e)?.lastRequest;return!!n&&(E(t,this.options,this.storage,{instruction:n.instruction,commandId:n.commandId,commandLabel:n.commandLabel,option:n.option},n.from,n.to),!0)},acceptAiSuggestion:()=>({state:t,chain:n})=>{const o=L(t)?.panel;if(!o||"reviewing"!==o.status||o.suggestion.isStreaming)return!1;const{from:r,to:i,suggestedText:a}=o.suggestion,{content:s}=p(a);return!!s&&(e(),n().insertContentAt({from:r,to:i},s,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(M,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(M,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:t,chain:n})=>{const o=L(t)?.panel;if(!o||"reviewing"!==o.status||o.suggestion.isStreaming)return!1;const{to:r,suggestedText:i}=o.suggestion,{content:a}=p(i);if(!a)return!1;const s=t.doc.resolve(Math.min(r,t.doc.content.size)),c=s.depth>0?s.after(s.depth):s.pos;return e(),n().insertContentAt(c,a,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(M,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new n.Plugin({key:M,state:{init:()=>({panel:{status:"closed"},decorations:r.DecorationSet.empty,lastRequest:null}),apply(t,n){let o=n.panel,r=n.lastRequest;t.docChanged&&(o=function(e,t){switch(e.status){case"closed":default:return e;case"menu":case"loading":case"error":return{...e,from:t.map(e.from),to:t.map(e.to)};case"reviewing":return{...e,suggestion:{...e.suggestion,from:t.map(e.suggestion.from),to:t.map(e.suggestion.to)}}}}(o,t.mapping));const i=t.getMeta(M);if(i)switch(i.type){case"open-menu":o={status:"menu",from:i.from,to:i.to};break;case"set-loading":o={status:"loading",from:i.from,to:i.to,commandLabel:i.commandLabel},r={instruction:i.instruction,commandId:i.commandId,commandLabel:i.commandLabel,option:i.option,from:i.from,to:i.to};break;case"set-suggestion":o={status:"reviewing",suggestion:i.suggestion,commandLabel:i.commandLabel};break;case"set-error":o={status:"error",from:i.from,to:i.to,commandLabel:i.commandLabel,message:i.message};break;case"settle":"reviewing"===o.status&&(o={...o,suggestion:{...o.suggestion,isStreaming:!1}});break;case"close":o={status:"closed"}}return{panel:o,decorations:D(t.doc,o,e),lastRequest:r}}},props:{decorations(e){return this.getState(e)?.decorations??r.DecorationSet.empty}}})]}});Object.defineProperty(exports,"AI_COMMAND_GROUP_LABELS",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"AI_SYSTEM_PROMPT",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"Ai",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"DEFAULT_AI_COMMANDS",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"DEFAULT_AI_LANGUAGES",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"aiPluginKey",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"buildAiInstruction",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"buildAiUserPrompt",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"clampContext",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"commandsForSelection",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"getAiOptions",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"getAiState",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"groupCommands",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"isAiEnabled",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"mockAiCompletion",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"needsRichInsert",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"sanitizeCompletion",{enumerable:!0,get:function(){return P}});
|
package/dist/Ai.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./rolldown-runtime-BeavJI0R.cjs");const e=require("./Ai-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./rolldown-runtime-BeavJI0R.cjs");const e=require("./Ai-DVWZg0-D.cjs");exports.AI_COMMAND_GROUP_LABELS=e.AI_COMMAND_GROUP_LABELS,exports.AI_SYSTEM_PROMPT=e.AI_SYSTEM_PROMPT,exports.Ai=e.Ai,exports.DEFAULT_AI_COMMANDS=e.DEFAULT_AI_COMMANDS,exports.DEFAULT_AI_LANGUAGES=e.DEFAULT_AI_LANGUAGES,exports.aiPluginKey=e.aiPluginKey,exports.getAiOptions=e.getAiOptions,exports.getAiState=e.getAiState,exports.isAiEnabled=e.isAiEnabled;
|
package/dist/Ai.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as a,a as s,c as r,g as i,h as o,i as t,n as m,r as p,t as c}from"./Ai-DOAuz6ZE.js";export{o as AI_COMMAND_GROUP_LABELS,r as AI_SYSTEM_PROMPT,c as Ai,i as DEFAULT_AI_COMMANDS,a as DEFAULT_AI_LANGUAGES,m as aiPluginKey,p as getAiOptions,t as getAiState,s as isAiEnabled};
|