react-reason-editor 1.0.77 → 1.0.78
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-CfgczVyp.cjs +1 -0
- package/dist/Ai-DsWeNKXF.js +1 -0
- package/dist/Ai.cjs +1 -1
- package/dist/Ai.js +1 -1
- package/dist/{Attachment-bBEf8uOc.js → Attachment-BmQoshq_.js} +1 -1
- package/dist/Attachment.cjs +1 -1
- package/dist/Attachment.js +1 -1
- package/dist/{Blockquote-Cw5Zty9X.js → Blockquote-cNS4L62L.js} +1 -1
- package/dist/Blockquote.cjs +1 -1
- package/dist/Blockquote.js +1 -1
- package/dist/{Bold-BwuX7fZs.js → Bold-DiKXbC2z.js} +1 -1
- package/dist/Bold.cjs +1 -1
- package/dist/Bold.js +1 -1
- package/dist/BubbleMenus-CIOMgQ-M.js +216 -0
- package/dist/BubbleMenus-vqNuXWlm.cjs +1 -0
- package/dist/BulletList.cjs +1 -1
- package/dist/BulletList.js +1 -1
- package/dist/{Callout-CJofZEpX.js → Callout-BLkbFKjv.js} +1 -1
- package/dist/{Callout-wjo2BYZi.cjs → Callout-CpkjGEBS.cjs} +1 -1
- package/dist/Callout.cjs +1 -1
- package/dist/Callout.js +1 -1
- package/dist/Clear.cjs +1 -1
- package/dist/Clear.js +1 -1
- package/dist/{Code-CtIvf6_L.js → Code-DvYJ892R.js} +1 -1
- package/dist/Code.cjs +1 -1
- package/dist/Code.js +1 -1
- package/dist/{CodeBlock-DoIb7GC2.js → CodeBlock-B3dLyClh.js} +1 -1
- package/dist/CodeBlock.cjs +1 -1
- package/dist/CodeBlock.js +1 -1
- package/dist/CodeView.cjs +1 -1
- package/dist/CodeView.js +1 -1
- package/dist/{Color-DSs2MkQU.js → Color-Cng09GRR.js} +1 -1
- package/dist/{Color-B9PloDr5.cjs → Color-ZjBs7t7J.cjs} +1 -1
- package/dist/Color.cjs +1 -1
- package/dist/Color.js +1 -1
- package/dist/{Column-BXSoMVXw.cjs → Column-BaMOYvoO.cjs} +1 -1
- package/dist/{Column-CrT9596v.js → Column-DO6MfrOQ.js} +1 -1
- package/dist/Column.cjs +1 -1
- package/dist/Column.js +1 -1
- package/dist/{Drawer-CfcCPGCn.cjs → Drawer-CC24iVYp.cjs} +1 -1
- package/dist/{Drawer-DuQ5tw2t.js → Drawer-CL5Rhqw4.js} +1 -1
- package/dist/Drawer.cjs +1 -1
- package/dist/Drawer.js +1 -1
- package/dist/{Drawio-DQEgw3du.cjs → Drawio-CD_Tea_o.cjs} +1 -1
- package/dist/{Drawio-P620K_Ps.js → Drawio-LEtUoVAY.js} +1 -1
- package/dist/Drawio.cjs +1 -1
- package/dist/Drawio.js +1 -1
- package/dist/{Emoji-CYM4tY7s.js → Emoji-DN3yfwz_.js} +1 -1
- package/dist/Emoji.cjs +1 -1
- package/dist/Emoji.js +1 -1
- package/dist/{ExportPdf-BoD_D91q.js → ExportPdf-CrQVmD4l.js} +1 -1
- package/dist/ExportPdf.cjs +1 -1
- package/dist/ExportPdf.js +1 -1
- package/dist/{ExportWord-Bj9q_cyK.js → ExportWord-BM4ogH_i.js} +1 -1
- package/dist/ExportWord.cjs +1 -1
- package/dist/ExportWord.js +1 -1
- package/dist/FontFamily.cjs +1 -1
- package/dist/FontFamily.js +1 -1
- package/dist/FontSize.cjs +1 -1
- package/dist/FontSize.js +1 -1
- package/dist/{Heading-BHOPoy3X.js → Heading-Bcrl3eKU.js} +1 -1
- package/dist/Heading.cjs +1 -1
- package/dist/Heading.js +1 -1
- package/dist/{Highlight-BxKQNHmT.cjs → Highlight-cO9V18Me.cjs} +1 -1
- package/dist/{Highlight-3SpxpGDw.js → Highlight-uXDlNgw3.js} +1 -1
- package/dist/Highlight.cjs +1 -1
- package/dist/Highlight.js +1 -1
- package/dist/{History-CmI6jUTV.js → History-BoHiw0Bn.js} +1 -1
- package/dist/History.cjs +1 -1
- package/dist/History.js +1 -1
- package/dist/{HorizontalRule-BeLfU92F.js → HorizontalRule-C7mAKdzL.js} +1 -1
- package/dist/HorizontalRule.cjs +1 -1
- package/dist/HorizontalRule.js +1 -1
- package/dist/{Iframe-D-WaYtdF.cjs → Iframe-DGL_MOLf.cjs} +1 -1
- package/dist/{Iframe-C0ozlEX4.js → Iframe-D_IjezyZ.js} +1 -1
- package/dist/Iframe.cjs +1 -1
- package/dist/Iframe.js +1 -1
- package/dist/Image.cjs +1 -1
- package/dist/Image.js +1 -1
- package/dist/{ImageCropper-BVl7AuRL.js → ImageCropper-ChOGJuHZ.js} +1 -1
- package/dist/{ImageCropper-DqHxEOtN.cjs → ImageCropper-DDWnFI2-.cjs} +1 -1
- package/dist/{ImageGif-BSVyqEv6.cjs → ImageGif-3dik7FeU.cjs} +1 -1
- package/dist/{ImageGif-BvthT-Lc.js → ImageGif-D_kKkBU5.js} +1 -1
- package/dist/ImageGif.cjs +1 -1
- package/dist/ImageGif.js +1 -1
- package/dist/{ImportWord-C6EnXbyR.js → ImportWord-CtFBb_n4.js} +1 -1
- package/dist/ImportWord.cjs +1 -1
- package/dist/ImportWord.js +1 -1
- package/dist/{Indent-BuzxHbMb.js → Indent-BIk98fDV.js} +1 -1
- package/dist/{Indent-eL-WNEF4.cjs → Indent-BVMl9zKV.cjs} +1 -1
- package/dist/Indent.cjs +1 -1
- package/dist/Indent.js +1 -1
- package/dist/{Italic-D8ZI09FZ.js → Italic-3mlmsxqN.js} +1 -1
- package/dist/Italic.cjs +1 -1
- package/dist/Italic.js +1 -1
- package/dist/{Katex-46mDLDuw.cjs → Katex-C2AcX_Un.cjs} +1 -1
- package/dist/{Katex-B-lo5eMz.js → Katex-DRPWO2AM.js} +1 -1
- package/dist/Katex.cjs +1 -1
- package/dist/Katex.js +1 -1
- package/dist/LineHeight.cjs +1 -1
- package/dist/LineHeight.js +1 -1
- package/dist/{Link-CDtipqwb.js → Link-D5y_0ekP.js} +1 -1
- package/dist/Link.cjs +1 -1
- package/dist/Link.js +1 -1
- package/dist/{LinkEditBlock-D0V9PwbF.cjs → LinkEditBlock-D78J06F7.cjs} +1 -1
- package/dist/MarkdownPaste.cjs +1 -1
- package/dist/MarkdownPaste.js +1 -1
- package/dist/{Mermaid-DDV93CBT.cjs → Mermaid-B6SL3cf5.cjs} +1 -1
- package/dist/{Mermaid-Cb8MiE1N.js → Mermaid-BaTtCsrD.js} +1 -1
- package/dist/Mermaid.cjs +1 -1
- package/dist/Mermaid.js +1 -1
- package/dist/{MoreMark-CJ3nTD1T.js → MoreMark-Bfsa3STU.js} +1 -1
- package/dist/MoreMark.cjs +1 -1
- package/dist/MoreMark.js +1 -1
- package/dist/OrderedList.cjs +1 -1
- package/dist/OrderedList.js +1 -1
- package/dist/{ReasonDocs-BliNN1Tt.cjs → ReasonDocs-Bjefr26w.cjs} +1 -1
- package/dist/{ReasonDocs-4vxZ3zY7.js → ReasonDocs-_hTAa8-q.js} +1 -1
- package/dist/{RichTextProvider-Dl77gVJI.cjs → RichTextProvider-BuTrDlZY.cjs} +1 -1
- package/dist/{RichTextProvider-E6rbc_J2.js → RichTextProvider-D9EtjDKS.js} +1 -1
- package/dist/SearchAndReplace.cjs +1 -1
- package/dist/SearchAndReplace.js +1 -1
- package/dist/{SlashCommand-DtlUkwyM.js → SlashCommand-Cg-Rvv3o.js} +1 -1
- package/dist/SlashCommand.js +1 -1
- package/dist/{Strike-CWYl45VK.js → Strike-CSxbYwpk.js} +1 -1
- package/dist/Strike.cjs +1 -1
- package/dist/Strike.js +1 -1
- package/dist/{Table-DCLsW5DJ.js → Table-CFcOg-4n.js} +1 -1
- package/dist/{Table-C9RAHNEk.cjs → Table-Do_kTawS.cjs} +1 -1
- package/dist/Table.cjs +1 -1
- package/dist/Table.js +1 -1
- package/dist/TaskList.cjs +1 -1
- package/dist/TaskList.js +1 -1
- package/dist/{TextAlign-D4UgbJ7F.cjs → TextAlign-CcsTIs-9.cjs} +1 -1
- package/dist/{TextAlign-9ezg8E99.js → TextAlign-Dun3_Ozv.js} +1 -1
- package/dist/TextAlign.cjs +1 -1
- package/dist/TextAlign.js +1 -1
- package/dist/TextDirection.cjs +1 -1
- package/dist/TextDirection.js +1 -1
- package/dist/{TextUnderline-C5A078R0.js → TextUnderline-Cqm5NQVW.js} +1 -1
- package/dist/TextUnderline.cjs +1 -1
- package/dist/TextUnderline.js +1 -1
- package/dist/{Twitter-D7ulyHFD.cjs → Twitter-B4IYTs3E.cjs} +1 -1
- package/dist/{Twitter-ByGJ4v1K.js → Twitter-CZHAICpz.js} +1 -1
- package/dist/Twitter.cjs +1 -1
- package/dist/Twitter.js +1 -1
- package/dist/{Video-hhw77FP4.js → Video-5nw_Zeob.js} +1 -1
- package/dist/{Video-ConJGjxP.cjs → Video-CtGR5VVD.cjs} +1 -1
- package/dist/Video.cjs +1 -1
- package/dist/Video.js +1 -1
- package/dist/WordCount.cjs +1 -1
- package/dist/WordCount.js +1 -1
- package/dist/bubble-BhkjoWdo.js +79 -0
- package/dist/bubble.cjs +1 -1
- package/dist/bubble.js +1 -1
- package/dist/{cdn-loader-BGIuN138-wkFA6jnE.cjs → cdn-loader-BGIuN138-7PrAg-Ef.cjs} +1 -1
- package/dist/docs-agent.cjs +1 -1
- package/dist/docs-agent.js +1 -1
- package/dist/editor-kit.cjs +1 -1
- package/dist/editor-kit.js +1 -1
- package/dist/editorConfig-BR7z-P0e.js +18 -0
- package/dist/editorConfig-CHBSp2KG.cjs +1 -0
- package/dist/extensions/Ai/Ai.d.ts +22 -5
- package/dist/extensions/Ai/commands.d.ts +6 -1
- package/dist/extensions/Ai/components/AiMenu.d.ts +6 -5
- package/dist/extensions/Ai/components/RichTextAi.d.ts +12 -0
- package/dist/extensions/Ai/index.d.ts +9 -3
- package/dist/extensions/Ai/lib/completionToContent.d.ts +35 -0
- package/dist/extensions/Ai/lib/createStreamingCompletion.d.ts +27 -0
- package/dist/extensions/Ai/lib/prompt.d.ts +38 -0
- package/dist/extensions/Ai/lib/sanitizeCompletion.d.ts +37 -0
- package/dist/extensions/Ai/types.d.ts +47 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/marked.esm-B7mQ2Kzc.cjs +1 -0
- package/dist/marked.esm-CNm6O672.js +1 -0
- package/dist/{react-BQVDEMs2.cjs → react-Bfe0Tko8.cjs} +1 -1
- package/dist/reason-docs.cjs +1 -1
- package/dist/reason-docs.js +1 -1
- package/dist/{reason-toolbar-skin-9xQLtzeK.js → reason-toolbar-skin-BNYK97ET.js} +1 -1
- package/dist/{reason-toolbar-skin-DyYu9ywU.cjs → reason-toolbar-skin-CD4T53He.cjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/useButtonProps-BBiR6DPI.cjs +1 -0
- package/dist/useButtonProps-Codtb0k0.js +1 -0
- package/package.json +1 -1
- package/dist/Ai-BGpnAE8s.js +0 -1
- package/dist/Ai-CORhNCSN.cjs +0 -1
- package/dist/BubbleMenus-QlttKSIN.cjs +0 -1
- package/dist/BubbleMenus-mwxYB3IU.js +0 -195
- package/dist/MarkdownPaste-C5jQ33SR.js +0 -1
- package/dist/bubble-CpeBzXMe.js +0 -78
- package/dist/editorConfig-D-Tlrdwj.js +0 -18
- package/dist/editorConfig-Du7YaEDm.cjs +0 -1
- package/dist/useButtonProps-BFfsKvCi.cjs +0 -1
- package/dist/useButtonProps-BZwO1Of-.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BeavJI0R.cjs"),t=require("./locales-DRkmn37v.cjs"),n=require("./dist-GxnWmQlw.cjs");let r=require("@tiptap/react"),o=require("react"),u=e.__toESM(o,1);function i(e){const{editor:t}=(0,r.useCurrentEditor)(),n=u.useMemo(()=>e||t,[e,t]);return(0,r.useEditorState)({editor:n,selector:e=>e.editor?{editor:e.editor,editorState:e.editor.state,canCommand:e.editor.can}:{editor:null,editorState:void 0,canCommand:void 0}})||{editor:null}}function s(){return i().editor}o=e.__toESM(o);var a=n.y(!1);function c(){return n.b(a)}function f(){return n.S(a)}var d=()=>!1;function l(e=d){const t=c(),[n,r]=(0,u.useState)(()=>{const t=e();return"boolean"==typeof t?!t:t}),o=s();return(0,u.useEffect)(()=>{if(!o||!e)return;const t=()=>{const t=e();r("boolean"==typeof t?!t:t)};return t(),o.on("selectionUpdate",t),o.on("transaction",t),()=>{o.off("selectionUpdate",t),o.off("transaction",t)}},[o,e]),{disabled:(0,u.useMemo)(()=>!t||!o||"boolean"==typeof n&&n,[t,o,n]),dataState:n,editorDisabled:(0,u.useMemo)(()=>!t||!o,[t,o])}}function p(e=d){const t=c(),[n,r]=(0,u.useState)({}),[o,i]=(0,u.useState)(e()),a=s();return(0,u.useEffect)(()=>{if(!a||!e)return;const t=()=>{i(e())};return t(),a.on("selectionUpdate",t),()=>{a.off("selectionUpdate",t)}},[n,a,e]),{disabled:(0,u.useMemo)(()=>!t||!a,[t,a]),dataState:o,editorDisabled:(0,u.useMemo)(()=>!t||!a,[t,a]),update:()=>r({})}}function b(e){const t=s();return(0,u.useMemo)(()=>t?t.extensionManager.extensions.find(t=>t.name===e):null,[t,e])}function m(e,t,n){return e<t?t:e>n?n:e}function x(e,t="px"){if(!e)return e;const n=(e=>"number"==typeof e)(e)?String(e):e,r=Number.parseFloat(n),o=n.match(/[%a-z]+$/i),u=o?o[0]:t;return Number.isNaN(r)?e:r+u}function g(e,t){if(!e)return!1;const{extensions:n=[]}=e?.extensionManager??{};return!!n.find(e=>e.name===t)}function y(e){return e.map(e=>"string"==typeof e?{value:e,name:e}:e)}function j(e){const n=s(),r=b(e),{t:o}=t.useLocale();return(0,u.useMemo)(()=>{if(!n||!r||!o)return null;const{button:e}=r.options;return e&&"function"==typeof e?e({editor:n,extension:r,t:o}):null},[n,r,o])}Object.defineProperty(exports,"clamp",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"ensureNameValueOptions",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"getCssUnitWithDefault",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"hasExtension",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"useActive",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"useButtonProps",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"useEditableEditor",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"useEditorInstance",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"useExtension",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"useStoreEditableEditor",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"useTiptapEditor",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"useToggleActive",{enumerable:!0,get:function(){return p}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as t}from"./locales-rT_qjKW9.js";import{a as n,r as e,t as o}from"./dist-fiA_WbbM.js";import{useCurrentEditor as r,useEditorState as a}from"@tiptap/react";import*as i from"react";import{useEffect as s,useMemo as u,useState as c}from"react";function f(t){const{editor:n}=r(),e=i.useMemo(()=>t||n,[t,n]);return a({editor:e,selector:t=>t.editor?{editor:t.editor,editorState:t.editor.state,canCommand:t.editor.can}:{editor:null,editorState:void 0,canCommand:void 0}})||{editor:null}}function d(){return f().editor}var l=n(!1);function m(){return e(l)}function p(){return o(l)}var b=()=>!1;function x(t=b){const n=m(),[e,o]=c(()=>{const n=t();return"boolean"==typeof n?!n:n}),r=d();return s(()=>{if(!r||!t)return;const n=()=>{const n=t();o("boolean"==typeof n?!n:n)};return n(),r.on("selectionUpdate",n),r.on("transaction",n),()=>{r.off("selectionUpdate",n),r.off("transaction",n)}},[r,t]),{disabled:u(()=>!n||!r||"boolean"==typeof e&&e,[n,r,e]),dataState:e,editorDisabled:u(()=>!n||!r,[n,r])}}function y(t=b){const n=m(),[e,o]=c({}),[r,a]=c(t()),i=d();return s(()=>{if(!i||!t)return;const n=()=>{a(t())};return n(),i.on("selectionUpdate",n),()=>{i.off("selectionUpdate",n)}},[e,i,t]),{disabled:u(()=>!n||!i,[n,i]),dataState:r,editorDisabled:u(()=>!n||!i,[n,i]),update:()=>o({})}}function v(t){const n=d();return u(()=>n?n.extensionManager.extensions.find(n=>n.name===t):null,[n,t])}function S(t,n,e){return t<n?n:t>e?e:t}function g(t,n="px"){if(!t)return t;const e=(t=>"number"==typeof t)(t)?String(t):t,o=Number.parseFloat(e),r=e.match(/[%a-z]+$/i),a=r?r[0]:n;return Number.isNaN(o)?t:o+a}function N(t,n){if(!t)return!1;const{extensions:e=[]}=t?.extensionManager??{};return!!e.find(t=>t.name===n)}function U(t){return t.map(t=>"string"==typeof t?{value:t,name:t}:t)}function M(n){const e=d(),o=v(n),{t:r}=t();return u(()=>{if(!e||!o||!r)return null;const{button:t}=o.options;return t&&"function"==typeof t?t({editor:e,extension:o,t:r}):null},[e,o,r])}export{N as a,y as c,d,f,g as i,m as l,S as n,v as o,U as r,x as s,M as t,p as u};
|
package/package.json
CHANGED
package/dist/Ai-BGpnAE8s.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Extension as e}from"@tiptap/core";import{Plugin as t,PluginKey as o}from"@tiptap/pm/state";import{CheckCheck as s,Feather as n,Minus as r,Plus as i,SmilePlus as a,Sparkles as c}from"lucide-react";import{Decoration as l,DecorationSet as d}from"@tiptap/pm/view";var m=[{id:"improve",label:"Improve writing",description:"Rewrite for clarity and flow",icon:c,prompt:"Improve the writing quality of the selected text while preserving its original meaning and tone."},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:a,prompt:"Add relevant emoji throughout the selected text without changing the wording."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:i,prompt:"Expand the selected text with more detail and supporting context while keeping the same tone."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:r,prompt:"Make the selected text more concise, removing redundancy while preserving all key points."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:s,prompt:"Fix all spelling and grammar mistakes in the selected text without changing its meaning or style."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:n,prompt:"Simplify the language of the selected text so it is easier to understand, using plainer words and shorter sentences."}];function u(e,t){return new Promise((o,s)=>{const n=setTimeout(o,e);t.addEventListener("abort",()=>{clearTimeout(n),s(new DOMException("Aborted","AbortError"))},{once:!0})})}var g=async(e,t,o)=>{const s=function(e,t){const o=e.toLowerCase(),s=t.trim();if(!s)return`${e.trim()||"New content"}.`;if(o.includes("emoji"))return`${s} ✨📝`;if(o.includes("shorter")||o.includes("concise")){const e=s.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return o.includes("longer")||o.includes("expand")?`${s} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:o.includes("simplify")?s.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):s.charAt(0).toUpperCase()+s.slice(1).replace(/\s{2,}/g," ")}(e.instruction,e.selectedText).split(" ");let n="";for(let r=0;r<s.length;r++){if(o.aborted)throw new DOMException("Aborted","AbortError");n+=(0===r?"":" ")+s[r],t(n),await u(35,o)}return n},p=new o("ai");function h(e){return p.getState(e)}function f(e){return e.extensionManager.extensions.find(e=>"ai"===e.name)?.options}function w(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 b(e,t,o){if("loading"===t.status)return d.create(e,[l.widget(t.to,()=>{const e=document.createElement("span");return e.className=o.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:s,to:n,suggestedText:r,mode:i}=t.suggestion,a=[];return"replace"===i&&n>s&&a.push(l.inline(s,n,{class:o.removedClass})),a.push(l.widget(n,()=>{const e=document.createElement("span");return e.className=o.insertedClass,e.textContent=r||"…",e},{side:1})),d.create(e,a)}return d.empty}async function x(e,t,o,s,n,r,i){const{view:a}=e,c=e.state.doc,l=r===i?"":c.textBetween(r,i,"\n"),d=c.textBetween(0,c.content.size,"\n"),m=l?"replace":"insert";o.abortController?.abort();const u=new AbortController;o.abortController=u;const g=o.requestToken+=1;a.dispatch(a.state.tr.setMeta(p,{type:"set-loading",from:r,to:i,commandLabel:n,instruction:s}));const h=(t,s)=>{g!==o.requestToken||e.isDestroyed||e.view.dispatch(e.view.state.tr.setMeta(p,{type:"set-suggestion",commandLabel:n,suggestion:{from:r,to:i,originalText:l,suggestedText:t,mode:m,isStreaming:s}}))};try{h(await t.getCompletion({instruction:s,selectedText:l,documentText:d},e=>h(e,!0),u.signal),!1)}catch(f){if(u.signal.aborted||g!==o.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(p,{type:"set-error",from:r,to:i,commandLabel:n,message:f instanceof Error?f.message:"Something went wrong."}))}}var y=e.create({name:"ai",addOptions:()=>({commands:m,getCompletion:g,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(){return{openAiMenu:()=>({state:e,dispatch:t})=>{const{from:o,to:s}=e.selection;return t&&t(e.tr.setMeta(p,{type:"open-menu",from:o,to:s})),!0},closeAiMenu:()=>({state:e,dispatch:t})=>(this.storage.abortController?.abort(),this.storage.requestToken+=1,t&&t(e.tr.setMeta(p,{type:"close"})),!0),runAiCommand:e=>({state:t,editor:o})=>{const s=this.options.commands.find(t=>t.id===e);if(!s)return!1;const{from:n,to:r}=w(h(t)?.panel??{status:"closed"},t.selection);return x(o,this.options,this.storage,s.prompt,s.label,n,r),!0},submitAiPrompt:e=>({state:t,editor:o})=>{const s=e.trim();if(!s)return!1;const{from:n,to:r}=w(h(t)?.panel??{status:"closed"},t.selection);return x(o,this.options,this.storage,s,"Custom",n,r),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const o=h(e)?.lastRequest;return!!o&&(x(t,this.options,this.storage,o.instruction,o.commandLabel,o.from,o.to),!0)},acceptAiSuggestion:()=>({state:e,dispatch:t,tr:o})=>{const s=h(e)?.panel;if(!s||"reviewing"!==s.status||s.suggestion.isStreaming)return!1;const{from:n,to:r,suggestedText:i}=s.suggestion;return o.insertText(i,n,r),o.setMeta(p,{type:"close"}),t&&t(o),!0},discardAiSuggestion:()=>({state:e,dispatch:t})=>(this.storage.abortController?.abort(),this.storage.requestToken+=1,t&&t(e.tr.setMeta(p,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:e,dispatch:t,tr:o})=>{const s=h(e)?.panel;if(!s||"reviewing"!==s.status||s.suggestion.isStreaming)return!1;const{to:n,suggestedText:r}=s.suggestion,i=o.doc.resolve(Math.min(n,o.doc.content.size)),a=i.end(i.depth),c=e.schema.nodes.paragraph.create(null,r?e.schema.text(r):void 0);return o.insert(a,c),o.setMeta(p,{type:"close"}),t&&t(o),!0}}},addProseMirrorPlugins(){const e=this.options;return[new t({key:p,state:{init:()=>({panel:{status:"closed"},decorations:d.empty,lastRequest:null}),apply(t,o){let s=o.panel,n=o.lastRequest;t.docChanged&&(s=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)}}}}(s,t.mapping));const r=t.getMeta(p);if(r)switch(r.type){case"open-menu":s={status:"menu",from:r.from,to:r.to};break;case"set-loading":s={status:"loading",from:r.from,to:r.to,commandLabel:r.commandLabel},n={instruction:r.instruction,commandLabel:r.commandLabel,from:r.from,to:r.to};break;case"set-suggestion":s={status:"reviewing",suggestion:r.suggestion,commandLabel:r.commandLabel};break;case"set-error":s={status:"error",from:r.from,to:r.to,commandLabel:r.commandLabel,message:r.message};break;case"close":s={status:"closed"}}return{panel:s,decorations:b(t.doc,s,e),lastRequest:n}}},props:{decorations(e){return this.getState(e)?.decorations??d.empty}}})]}});export{m as a,h as i,p as n,f as r,y as t};
|
package/dist/Ai-CORhNCSN.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("./rolldown-runtime-BeavJI0R.cjs");let e=require("@tiptap/core"),t=require("@tiptap/pm/state"),o=require("lucide-react"),n=require("@tiptap/pm/view");var r=[{id:"improve",label:"Improve writing",description:"Rewrite for clarity and flow",icon:o.Sparkles,prompt:"Improve the writing quality of the selected text while preserving its original meaning and tone."},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:o.SmilePlus,prompt:"Add relevant emoji throughout the selected text without changing the wording."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:o.Plus,prompt:"Expand the selected text with more detail and supporting context while keeping the same tone."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:o.Minus,prompt:"Make the selected text more concise, removing redundancy while preserving all key points."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:o.CheckCheck,prompt:"Fix all spelling and grammar mistakes in the selected text without changing its meaning or style."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:o.Feather,prompt:"Simplify the language of the selected text so it is easier to understand, using plainer words and shorter sentences."}];function s(e,t){return new Promise((o,n)=>{const r=setTimeout(o,e);t.addEventListener("abort",()=>{clearTimeout(r),n(new DOMException("Aborted","AbortError"))},{once:!0})})}var i=async(e,t,o)=>{const n=function(e,t){const o=e.toLowerCase(),n=t.trim();if(!n)return`${e.trim()||"New content"}.`;if(o.includes("emoji"))return`${n} ✨📝`;if(o.includes("shorter")||o.includes("concise")){const e=n.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return o.includes("longer")||o.includes("expand")?`${n} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:o.includes("simplify")?n.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):n.charAt(0).toUpperCase()+n.slice(1).replace(/\s{2,}/g," ")}(e.instruction,e.selectedText).split(" ");let r="";for(let i=0;i<n.length;i++){if(o.aborted)throw new DOMException("Aborted","AbortError");r+=(0===i?"":" ")+n[i],t(r),await s(35,o)}return r},a=new t.PluginKey("ai");function c(e){return a.getState(e)}function l(e){return e.extensionManager.extensions.find(e=>"ai"===e.name)?.options}function u(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,o){if("loading"===t.status)return n.DecorationSet.create(e,[n.Decoration.widget(t.to,()=>{const e=document.createElement("span");return e.className=o.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:r,to:s,suggestedText:i,mode:a}=t.suggestion,c=[];return"replace"===a&&s>r&&c.push(n.Decoration.inline(r,s,{class:o.removedClass})),c.push(n.Decoration.widget(s,()=>{const e=document.createElement("span");return e.className=o.insertedClass,e.textContent=i||"…",e},{side:1})),n.DecorationSet.create(e,c)}return n.DecorationSet.empty}async function m(e,t,o,n,r,s,i){const{view:c}=e,l=e.state.doc,u=s===i?"":l.textBetween(s,i,"\n"),d=l.textBetween(0,l.content.size,"\n"),m=u?"replace":"insert";o.abortController?.abort();const g=new AbortController;o.abortController=g;const p=o.requestToken+=1;c.dispatch(c.state.tr.setMeta(a,{type:"set-loading",from:s,to:i,commandLabel:r,instruction:n}));const f=(t,n)=>{p!==o.requestToken||e.isDestroyed||e.view.dispatch(e.view.state.tr.setMeta(a,{type:"set-suggestion",commandLabel:r,suggestion:{from:s,to:i,originalText:u,suggestedText:t,mode:m,isStreaming:n}}))};try{f(await t.getCompletion({instruction:n,selectedText:u,documentText:d},e=>f(e,!0),g.signal),!1)}catch(h){if(g.signal.aborted||p!==o.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(a,{type:"set-error",from:s,to:i,commandLabel:r,message:h instanceof Error?h.message:"Something went wrong."}))}}var g=e.Extension.create({name:"ai",addOptions:()=>({commands:r,getCompletion:i,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(){return{openAiMenu:()=>({state:e,dispatch:t})=>{const{from:o,to:n}=e.selection;return t&&t(e.tr.setMeta(a,{type:"open-menu",from:o,to:n})),!0},closeAiMenu:()=>({state:e,dispatch:t})=>(this.storage.abortController?.abort(),this.storage.requestToken+=1,t&&t(e.tr.setMeta(a,{type:"close"})),!0),runAiCommand:e=>({state:t,editor:o})=>{const n=this.options.commands.find(t=>t.id===e);if(!n)return!1;const{from:r,to:s}=u(c(t)?.panel??{status:"closed"},t.selection);return m(o,this.options,this.storage,n.prompt,n.label,r,s),!0},submitAiPrompt:e=>({state:t,editor:o})=>{const n=e.trim();if(!n)return!1;const{from:r,to:s}=u(c(t)?.panel??{status:"closed"},t.selection);return m(o,this.options,this.storage,n,"Custom",r,s),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const o=c(e)?.lastRequest;return!!o&&(m(t,this.options,this.storage,o.instruction,o.commandLabel,o.from,o.to),!0)},acceptAiSuggestion:()=>({state:e,dispatch:t,tr:o})=>{const n=c(e)?.panel;if(!n||"reviewing"!==n.status||n.suggestion.isStreaming)return!1;const{from:r,to:s,suggestedText:i}=n.suggestion;return o.insertText(i,r,s),o.setMeta(a,{type:"close"}),t&&t(o),!0},discardAiSuggestion:()=>({state:e,dispatch:t})=>(this.storage.abortController?.abort(),this.storage.requestToken+=1,t&&t(e.tr.setMeta(a,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:e,dispatch:t,tr:o})=>{const n=c(e)?.panel;if(!n||"reviewing"!==n.status||n.suggestion.isStreaming)return!1;const{to:r,suggestedText:s}=n.suggestion,i=o.doc.resolve(Math.min(r,o.doc.content.size)),l=i.end(i.depth),u=e.schema.nodes.paragraph.create(null,s?e.schema.text(s):void 0);return o.insert(l,u),o.setMeta(a,{type:"close"}),t&&t(o),!0}}},addProseMirrorPlugins(){const e=this.options;return[new t.Plugin({key:a,state:{init:()=>({panel:{status:"closed"},decorations:n.DecorationSet.empty,lastRequest:null}),apply(t,o){let n=o.panel,r=o.lastRequest;t.docChanged&&(n=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)}}}}(n,t.mapping));const s=t.getMeta(a);if(s)switch(s.type){case"open-menu":n={status:"menu",from:s.from,to:s.to};break;case"set-loading":n={status:"loading",from:s.from,to:s.to,commandLabel:s.commandLabel},r={instruction:s.instruction,commandLabel:s.commandLabel,from:s.from,to:s.to};break;case"set-suggestion":n={status:"reviewing",suggestion:s.suggestion,commandLabel:s.commandLabel};break;case"set-error":n={status:"error",from:s.from,to:s.to,commandLabel:s.commandLabel,message:s.message};break;case"close":n={status:"closed"}}return{panel:n,decorations:d(t.doc,n,e),lastRequest:r}}},props:{decorations(e){return this.getState(e)?.decorations??n.DecorationSet.empty}}})]}});Object.defineProperty(exports,"Ai",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"DEFAULT_AI_COMMANDS",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"aiPluginKey",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"getAiOptions",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"getAiState",{enumerable:!0,get:function(){return c}});
|