prosemirror-suggestcat-plugin 0.0.12 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,8 @@
9
9
  ![feature-gif](https://suggestcat.com/suggestcat.gif)
10
10
 
11
11
  - Adds AI features to your ProseMirror editor
12
- - Coming soon: text completion, rewriting with a given style, YJS support and more!
12
+ - YJS support
13
+ - Text completion, rewriting content to make it shorter or longer.
13
14
 
14
15
  ## How to use?
15
16
 
@@ -20,20 +21,20 @@
20
21
 
21
22
  ```typescript
22
23
  import {
23
- grammarSuggestPlugin,
24
- defaultOptions,
24
+ grammarSuggestPlugin,
25
+ defaultOptions,
25
26
  } from "prosemirror-suggestcat-plugin";
26
27
 
27
28
  const view = new EditorView(document.querySelector("#editor"), {
28
- state: EditorState.create({
29
- doc: schema.nodeFromJSON(initialDoc),
30
- plugins: [
31
- ...exampleSetup({schema}),
32
- grammarSuggestPlugin(PROSEMIRROR_SUGGESTCAT_PLUGIN_API_KEY, {
33
- ...defaultOptions,
34
- }),
35
- ],
36
- }),
29
+ state: EditorState.create({
30
+ doc: schema.nodeFromJSON(initialDoc),
31
+ plugins: [
32
+ ...exampleSetup({ schema }),
33
+ grammarSuggestPlugin(PROSEMIRROR_SUGGESTCAT_PLUGIN_API_KEY, {
34
+ ...defaultOptions,
35
+ }),
36
+ ],
37
+ }),
37
38
  });
38
39
  ```
39
40
 
@@ -43,14 +44,14 @@ const view = new EditorView(document.querySelector("#editor"), {
43
44
 
44
45
  ```typescript
45
46
  export type GrammarSuggestPluginOptions = {
46
- debounceMs: number;
47
- createUpdatePopup: (
48
- view: EditorView,
49
- decoration: Decoration,
50
- pos: number,
51
- applySuggestion: (view: EditorView, decoration: Decoration) => void,
52
- discardSuggestion: (view: EditorView, decoration: Decoration) => void,
53
- ) => HTMLElement;
47
+ debounceMs: number;
48
+ createUpdatePopup: (
49
+ view: EditorView,
50
+ decoration: Decoration,
51
+ pos: number,
52
+ applySuggestion: (view: EditorView, decoration: Decoration) => void,
53
+ discardSuggestion: (view: EditorView, decoration: Decoration) => void,
54
+ ) => HTMLElement;
54
55
  };
55
56
  ```
56
57
 
@@ -58,8 +59,8 @@ export type GrammarSuggestPluginOptions = {
58
59
 
59
60
  ```typescript
60
61
  export const defaultOptions: GrammarSuggestPluginOptions = {
61
- debounceMs: 2000,
62
- createUpdatePopup,
62
+ debounceMs: 2000,
63
+ createUpdatePopup,
63
64
  };
64
65
  ```
65
66
 
@@ -89,10 +90,146 @@ import "prosemirror-suggestcat-plugin/dist/styles/styles.css";
89
90
 
90
91
  ```css
91
92
  .grammarSuggestion {
92
- background-color: green;
93
+ background-color: green;
93
94
  }
94
95
 
95
96
  .grammarSuggestion .removalSuggestion {
96
- background-color: red;
97
+ background-color: red;
97
98
  }
98
99
  ```
100
+
101
+ ### AI feature to complete text, or make it longer/shorter
102
+
103
+ - you can use another plugin from this package called `completePlugin`
104
+ - with prosemirror meta calls you can transform your existing content, or generate more content based on your existing content
105
+
106
+ #### Usage
107
+
108
+ - import the `completePlugin` and provide your API key, and optional options
109
+
110
+ ```ts
111
+ import {
112
+ completePluginKey,
113
+ completePlugin,
114
+ defaultCompleteOptions,
115
+ completePluginKey,
116
+ } from "prosemirror-suggestcat-plugin";
117
+
118
+ const v = new EditorView(document.querySelector("#editor"), {
119
+ state: EditorState.create({
120
+ doc: schema.nodeFromJSON(initialDoc),
121
+ plugins: [
122
+ ...exampleSetup({ schema }),
123
+ completePlugin(<YOUR_API_KEY>, defaultCompleteOptions),
124
+ ],
125
+ }),
126
+ });
127
+ ```
128
+
129
+ - `DefaultCompleteOptions`:
130
+ - `maxSelection` defaults to 1000 - can controll how long text will be sent to AI to transform it
131
+
132
+ ```ts
133
+ export interface DefaultCompleteOptions {
134
+ maxSelection: number;
135
+ }
136
+ ```
137
+
138
+ #### How it works?
139
+
140
+ - the plugin's initial state is `{status: "idle"}`
141
+ - send the plugin a task using `setMeta` using the `completePluginKey` plugin key
142
+
143
+ ```ts
144
+ view.dispatch(
145
+ view.state.tr.setMeta(completePluginKey, {
146
+ type: "Complete",
147
+ status: "new",
148
+ }),
149
+ );
150
+ ```
151
+
152
+ - pluginState will change to `{type: "Complete", status: "streaming", result: "some string being streamed...", }`
153
+
154
+ - when the AI finishes the pluginState's status changes to `{status: "finished"}`
155
+ - at this point you can either accept or reject the completion
156
+
157
+ ```ts
158
+ view.dispatch(
159
+ view.state.tr.setMeta(completePluginKey, {
160
+ type: "Complete",
161
+ status: "accpeted",
162
+ }),
163
+ );
164
+ ```
165
+
166
+ - after accepting it, your completion will be placed at the end of your document and the pluginState changes to `{status: "idle"}`waiting for a new task
167
+ - only one task can be ran at once
168
+ - only pluginState with `{status: "idle"}` can handle a new task
169
+ - if pluginState has an error like `{status: "error", error: "selection is too big"}` you can clear the error dispatching an `accepted` meta like above
170
+ - the plugin takes care of replacing existing text, or appending the completion result to the end of your document
171
+ - `MakeLonger/MakeShorter` - requires a selection, which content to make shorter or longer
172
+
173
+ ```ts
174
+ export enum TaskType {
175
+ complete = "Complete",
176
+ makeLonger = "MakeLonger",
177
+ makeShorter = "MakeShorter",
178
+ }
179
+
180
+ export enum Status {
181
+ idle = "idle",
182
+ new = "new",
183
+ streaming = "streaming",
184
+ finished = "finished",
185
+ accepted = "accepted",
186
+ rejected = "rejected",
187
+ done = "done",
188
+ error = "error",
189
+ }
190
+
191
+ export interface CompletePluginState {
192
+ type?: TaskType;
193
+ status?: Status;
194
+ result?: string;
195
+ selection?: TextSelection;
196
+ error?: string;
197
+ }
198
+
199
+ export interface TaskMeta {
200
+ type: TaskType;
201
+ status: Status.new | Status.accepted | Status.rejected;
202
+ }
203
+ ```
204
+
205
+ - Example for completion
206
+
207
+ ```ts
208
+ const getStuff = useCallback(() => {
209
+ if (!view) {
210
+ return;
211
+ }
212
+
213
+ view.dispatch(
214
+ view.state.tr.setMeta(completePluginKey, {
215
+ type: "Complete",
216
+ status: "new",
217
+ }),
218
+ );
219
+ }, [view]);
220
+
221
+ const completeStuff = useCallback(() => {
222
+ if (!view) {
223
+ return;
224
+ }
225
+ const state = completePluginKey.getState(view.state);
226
+
227
+ if (state?.status === "finished")
228
+ view.dispatch(
229
+ view.state.tr.setMeta(completePluginKey, {
230
+ type: "Complete",
231
+ status: "accepted",
232
+ }),
233
+ );
234
+ }, [view]);
235
+ ```
@@ -0,0 +1,3 @@
1
+ import { Plugin } from "prosemirror-state";
2
+ import { CompletePluginState } from "./types";
3
+ export declare const completePlugin: (apiKey: string, options?: import("./types").DefaultCompleteOptions) => Plugin<CompletePluginState>;
@@ -1,2 +1,3 @@
1
- import { GrammarSuggestPluginOptions } from "./types";
1
+ import { DefaultCompleteOptions, GrammarSuggestPluginOptions } from "./types";
2
2
  export declare const defaultOptions: GrammarSuggestPluginOptions;
3
+ export declare const defaultCompleteOptions: DefaultCompleteOptions;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  export { grammarSuggestPlugin } from "./plugin";
2
- export { defaultOptions } from "./defaults";
2
+ export { defaultOptions, defaultCompleteOptions } from "./defaults";
3
+ export { completePluginKey } from "./utils";
4
+ export { completePlugin } from "./completePlugin";
5
+ export { OpenAiPromptsWithParam, OpenAiPromptsWithoutParam, Status, MoodParamType, TranslationTargetLanguage, } from "./types";
6
+ export type { DefaultCompleteOptions, TaskMeta, CompletePluginState, MoodParams, TranslationParams, } from "./types";
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- import{PluginKey as t,Plugin as e}from"prosemirror-state";import{Decoration as n,DecorationSet as o}from"prosemirror-view";import r from"fast-diff";import i from"lodash.debounce";import{StepMap as s,Mapping as a}from"prosemirror-transform";const c=new t("grammarSuggestPlugin"),l=t=>{let e="";return t.descendants(((t,n)=>{t.isText&&(e+=`${t.text}\n`)})),e},p=(t,e)=>{if(t===e)return{start:t.length,end:t.length,oldStart:t.length,oldEnd:t.length,oldText:"",newText:""};const n=r(t,e),o=n[0],i=o[0]===r.EQUAL?o[1].length-1:0,s=((t,e)=>{if(e[e.length-1][0]!==r.EQUAL)return t.length;const n=e.slice(0,e.length-1);let o=0;for(const t of n){const[e,n]=t;e===r.EQUAL&&(o+=n.length),e===r.DELETE&&(o+=n.length)}return o})(t,n),a=t.lastIndexOf("\n",i),c=t.indexOf("\n",s),l=-1===a?0:a+1,p=-1===c?t.length:c,g=t.slice(l,p),d=e.slice(l,e.length-(t.length-p));return{start:l,end:l+d.length,oldStart:l,oldEnd:p,oldText:g,newText:d}};var g,d;function u(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))}!function(t){t.suggestionUpdate="suggestionUpdate",t.acceptSuggestion="acceptSuggestion",t.openSuggestion="openSuggestion",t.closeSuggestion="closeSuggestion",t.discardSuggestion="discardSuggestion"}(g||(g={})),function(t){t.grammarSuggestPopup="grammar-suggest-popup"}(d||(d={}));const m=[{docPos:1,textPos:0}],f=t=>{let e="";const n=[];return t.descendants(((t,o)=>{t.isText&&(n.push({docPos:o,textPos:e.length}),e+=`${t.text}\n`)})),{text:e,mapping:n.length?n:m}},h=(t,e)=>{for(let n=0;n<e.length;n++)if(t>=e[n].textPos&&(void 0===e[n+1]||t<e[n+1].textPos))return e[n].docPos+(t-e[n].textPos);throw new Error("textPositionToDocumentPosition: textPos not found in mapping")},x=(t,e)=>u(void 0,void 0,void 0,(function*(){const n=[...e.split("\n")];return fetch("https://prosemirror-ai-plugin.web.app/api/suggestion",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:n}})}).then((t=>t.ok?t.json():Promise.reject(t))).then((t=>t&&t.some((t=>(t=>{try{JSON.parse(t)}catch(t){return!1}return!0})(t)))?{result:t.map((t=>JSON.parse(t).result)).join("\n"),fixed:!0}:{fixed:!1,result:e})).catch((t=>(t.text().then((e=>{console.error({status:t.status,text:e})})),{fixed:!1,result:e})))})),S=t=>t.replacement===t.original,v=t=>t.reduce(((t,e)=>{const n=t[t.length-1],o=t.slice(0,t.length-1);if(!n)return[e];return[...o,...((t,e)=>{if(t.to!==e.from)throw new Error(`Replace pairs must be adjacent\n\n, ${JSON.stringify({leftReplace:t,rightReplace:e})}`);if(t.replacement.endsWith("\n"))return[t,e];if(S(t)&&S(e))return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}];if(S(t)){if(e.replacement.startsWith(" ")&&""===e.original||e.original.startsWith(" ")&&""===e.replacement)return[t,e];const n=t.original.split(" "),o=n.pop()||"",r=n.join(" ")+(n.length?" ":"");return[...r.length?[{from:t.from,to:t.from+r.length,original:r,replacement:r}]:[],{from:t.from+r.length,to:e.to,original:o+e.original,replacement:o+e.replacement}]}if(S(e)){if(t.replacement.endsWith(" ")&&""===t.original||t.original.endsWith(" ")&&""===t.replacement)return[t,e];const n=e.original.split(" "),o=n.shift()||"",r=(n.length?" ":"")+n.join(" ");return" "===r?[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]:[{from:t.from,to:t.to+o.length,original:t.original+o,replacement:t.replacement+o},...r.length?[{from:t.to+o.length,to:e.to,original:r,replacement:r}]:[]]}return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]})(n,e)]}),[]),w=(t,e)=>{const n=(t=>{let e=0;return t.map((([t,n])=>{switch(t){case r.EQUAL:const t=n.lastIndexOf("\n"),o={from:e,to:e+n.length,original:n,replacement:n};if(-1!==t&&"\n"!==n){const o=[{from:e,to:e+t+1,original:n.slice(0,t+1),replacement:n.slice(0,t+1)},{from:e+t+1,to:e+n.length,original:n.slice(t+1),replacement:n.slice(t+1)}];return e+=n.length,o}return e+=n.length,[o];case r.DELETE:const i={from:e,to:e+n.length,original:n,replacement:""};return e+=n.length,[i];case r.INSERT:return[{from:e,to:e,original:"",replacement:n}]}})).flat()})(r(t,e));return v(v(n))},y=(t,e)=>{var n;const o=null===(n=c.getState(t.state))||void 0===n?void 0:n.decorations.find(0,t.state.doc.nodeSize,(t=>t.id===e.spec.id))[0];if(!o)return;const{text:r}=o.spec,{from:i,to:s}=o,a={type:g.acceptSuggestion,id:e.spec.id},l=t.state.tr.insertText(r,i,s).setMeta(c,a);t.dispatch(l)},T=(t,e)=>{const{spec:n}=e,o={type:g.discardSuggestion,id:n.id},r=t.state.tr.setMeta(c,o);t.dispatch(r)},b=(t,e)=>{const n=c.getState(t.state);if(!n)return!1;const{decorations:o}=n,r=o.find(e,e)[0];if(!r){const e={type:g.closeSuggestion};return t.dispatch(t.state.tr.setMeta(c,e)),!1}const i=n.popupDecoration.find()[0];if((null==i?void 0:i.spec.id)===r.spec.id)return!1;const s={type:g.openSuggestion,decoration:r};return t.dispatch(t.state.tr.setMeta(c,s)),!1},j={debounceMs:2e3,createUpdatePopup:(t,e,n,o,r)=>{const i=document.createElement("div");i.className="grammar-suggest-tooltip";const{spec:s}=e,a=t.dom.getBoundingClientRect();i.id=d.grammarSuggestPopup;const c=t.coordsAtPos(n);i.style.left=c.left-a.left+"px",i.style.top=c.bottom-a.top+5+"px";const l=document.createElement("div");l.className="grammar-suggest-tooltip-apply",l.innerText=s.text||s.originalText,s.text||(l.style.textDecoration="line-through",l.style.color="red"),l.onclick=()=>{o(t,e)},i.appendChild(l);const p=document.createElement("div");return p.innerHTML="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path d='M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z'></path></svg>",p.className="grammar-suggest-tooltip-discard",p.onclick=()=>{r(t,e)},i.appendChild(p),i},withYjs:!1},O=(t,r=j)=>{let d=!1;return new e({key:c,state:{init:()=>({lastText:"",decorations:o.empty,popupDecoration:o.empty}),apply(t,e,i,d){const u=t.getMeta(c);return(null==u?void 0:u.type)===g.suggestionUpdate?((t,e,o)=>{const{changedRegion:r,fix:i,mapping:s,text:a}=e,c=w(r.newText,i.result).filter((t=>!S(t))).filter((t=>t.original!==`${t.replacement}\n`)).map((({from:t,to:e,original:o,replacement:i})=>{const a=h(r.start+t,s),c=h(r.start+(i.endsWith("\n")?e-1:e),s),l={text:i.endsWith("\n")?i.slice(0,-1):i,originalText:o,id:{}};return n.inline(a,c,{class:"grammarSuggestion "+(""===i?"removalSuggestion":"")},l)}));return Object.assign(Object.assign({},t),{decorations:t.decorations.add(o.doc,c),lastText:a})})(e,u,t):(null==u?void 0:u.type)===g.acceptSuggestion?((t,e,n)=>{const r=t.decorations.remove(t.decorations.find(0,n.doc.nodeSize,(t=>t.id===e.id)));return Object.assign(Object.assign({},t),{lastText:l(n.doc),decorations:r.map(n.mapping,n.doc),popupDecoration:o.empty})})(e,u,t):(null==u?void 0:u.type)===g.openSuggestion?((t,e,r,i)=>{const{decoration:s}=e,a={id:s.spec.id};return Object.assign(Object.assign({},t),{popupDecoration:o.create(r.doc,[n.widget(s.from,((t,e)=>{const n=e();return n?i.createUpdatePopup(t,s,n,y,T):document.createElement("div")}),Object.assign(Object.assign({},a),{stopEvent:()=>!0}))])})})(e,u,t,r):(null==u?void 0:u.type)===g.closeSuggestion?Object.assign(Object.assign({},e),{popupDecoration:o.empty}):(null==u?void 0:u.type)===g.discardSuggestion?((t,e,n)=>Object.assign(Object.assign({},t),{decorations:t.decorations.remove(t.decorations.find(0,n.doc.nodeSize,(t=>t.id===e.id))),popupDecoration:o.empty}))(e,u,t):t.docChanged?((t,e,n,o)=>{const r=f(n.doc).text,{text:i,mapping:c}=f(e.doc);if(i===r)return t;let l=e.mapping;if(o){const t=e.doc.content.findDiffStart(n.doc.content),o=n.doc.content.findDiffEnd(e.doc.content),r=new s(o&&t?[t,o.a-t,o.b-t]:[0,0,0]);l=new a([r])}const g=p(r,i),d=t.decorations.map(l,e.doc),u=h(g.start,c),m=h(g.end,c),x=t.popupDecoration.map(l,e.doc);return Object.assign(Object.assign({},t),{decorations:d.remove(d.find(u,m)),popupDecoration:x.remove(x.find(u,m))})})(e,t,i,r.withYjs):e}},props:{handleClick:b,decorations:t=>{const e=c.getState(t);return e?e.decorations.add(t.doc,e.popupDecoration.find()):null}},view(){const e=((t,e)=>i((t=>{var n;const o=f(t.state.doc),r=(null===(n=c.getState(t.state))||void 0===n?void 0:n.lastText)||"",i=p(r,o.text);x(e,i.newText).then((e=>{if(l(t.state.doc)!==o.text)return;const n={type:g.suggestionUpdate,fix:e,changedRegion:i,mapping:o.mapping,text:o.text};t.dispatch(t.state.tr.setMeta(c,n))})).catch((t=>{console.error("Grammar suggest API error",t)}))}),t.debounceMs))(r,t);return{update(t,n){const o=c.getState(t.state);t.state.doc.textBetween(0,t.state.doc.nodeSize-2,"/n")===n.doc.textBetween(0,n.doc.nodeSize-2,"/n")&&d||!o||o.lastText===l(t.state.doc)||(d=!0,e(t))}}}})};export{j as defaultOptions,O as grammarSuggestPlugin};
1
+ import{PluginKey as e,Plugin as t}from"prosemirror-state";import{Decoration as n,DecorationSet as o}from"prosemirror-view";import r from"fast-diff";import s from"lodash.debounce";import{StepMap as i,Mapping as a}from"prosemirror-transform";import{Fragment as c,Slice as l}from"prosemirror-model";var d,p,g,u,m,f,h;!function(e){e.suggestionUpdate="suggestionUpdate",e.acceptSuggestion="acceptSuggestion",e.openSuggestion="openSuggestion",e.closeSuggestion="closeSuggestion",e.discardSuggestion="discardSuggestion"}(d||(d={})),function(e){e.grammarSuggestPopup="grammar-suggest-popup"}(p||(p={})),function(e){e.Casual="Casual",e.Confident="Confident",e.Straightforward="Straightforward",e.Friendly="Friendly"}(g||(g={})),function(e){e.English="English",e.Spanish="Spanish",e.French="French",e.German="German",e.Italian="Italian",e.Portuguese="Portuguese",e.Dutch="Dutch",e.Russian="Russian",e.Chinese="Chinese",e.Korean="Korean",e.Japanese="Japanese"}(u||(u={})),function(e){e.Complete="Complete",e.Improve="Improve",e.MakeLonger="MakeLonger",e.MakeShorter="MakeShorter",e.Simplify="Simplify",e.Explain="Explain",e.ActionItems="ActionItems"}(m||(m={})),function(e){e.ChangeTone="ChangeTone",e.Translate="Translate"}(f||(f={})),function(e){e.idle="idle",e.new="new",e.streaming="streaming",e.finished="finished",e.accepted="accepted",e.rejected="rejected",e.done="done",e.error="error"}(h||(h={}));const x=new e("completePlugin"),v=new e("grammarSuggestPlugin"),y=e=>{let t="";return e.descendants(((e,n)=>{e.isText&&(t+=`${e.text}\n`)})),t},S=(e,t)=>{if(e===t)return{start:e.length,end:e.length,oldStart:e.length,oldEnd:e.length,oldText:"",newText:""};const n=r(e,t),o=n[0],s=o[0]===r.EQUAL?o[1].length-1:0,i=((e,t)=>{if(t[t.length-1][0]!==r.EQUAL)return e.length;const n=t.slice(0,t.length-1);let o=0;for(const e of n){const[t,n]=e;t===r.EQUAL&&(o+=n.length),t===r.DELETE&&(o+=n.length)}return o})(e,n),a=e.lastIndexOf("\n",s),c=e.indexOf("\n",i),l=-1===a?0:a+1,d=-1===c?e.length:c,p=e.slice(l,d),g=t.slice(l,t.length-(e.length-d));return{start:l,end:l+g.length,oldStart:l,oldEnd:d,oldText:p,newText:g}};function w(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}const j=[{docPos:1,textPos:0}],b=e=>{let t="";const n=[];return e.descendants(((e,o)=>{e.isText&&(n.push({docPos:o,textPos:t.length}),t+=`${e.text}\n`)})),{text:t,mapping:n.length?n:j}},T=(e,t)=>{for(let n=0;n<t.length;n++)if(e>=t[n].textPos&&(void 0===t[n+1]||e<t[n+1].textPos))return t[n].docPos+(e-t[n].textPos);throw new Error("textPositionToDocumentPosition: textPos not found in mapping")},C=(e,t)=>w(void 0,void 0,void 0,(function*(){const n=[...t.split("\n")];return fetch("https://prosemirror-ai-plugin.web.app/api/suggestion",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:n}})}).then((e=>e.ok?e.json():Promise.reject(e))).then((e=>e&&e.some((e=>(e=>{try{JSON.parse(e)}catch(e){return!1}return!0})(e)))?{result:e.map((e=>JSON.parse(e).result)).join("\n"),fixed:!0}:{fixed:!1,result:t})).catch((e=>(e.text().then((t=>{console.error({status:e.status,text:t})})),{fixed:!1,result:t})))})),O=e=>e.replacement===e.original,E=e=>e.reduce(((e,t)=>{const n=e[e.length-1],o=e.slice(0,e.length-1);if(!n)return[t];return[...o,...((e,t)=>{if(e.to!==t.from)throw new Error(`Replace pairs must be adjacent\n\n, ${JSON.stringify({leftReplace:e,rightReplace:t})}`);if(e.replacement.endsWith("\n"))return[e,t];if(O(e)&&O(t))return[{from:e.from,to:t.to,original:e.original+t.original,replacement:e.replacement+t.replacement}];if(O(e)){if(t.replacement.startsWith(" ")&&""===t.original||t.original.startsWith(" ")&&""===t.replacement)return[e,t];const n=e.original.split(" "),o=n.pop()||"",r=n.join(" ")+(n.length?" ":"");return[...r.length?[{from:e.from,to:e.from+r.length,original:r,replacement:r}]:[],{from:e.from+r.length,to:t.to,original:o+t.original,replacement:o+t.replacement}]}if(O(t)){if(e.replacement.endsWith(" ")&&""===e.original||e.original.endsWith(" ")&&""===e.replacement)return[e,t];const n=t.original.split(" "),o=n.shift()||"",r=(n.length?" ":"")+n.join(" ");return" "===r?[{from:e.from,to:t.to,original:e.original+t.original,replacement:e.replacement+t.replacement}]:[{from:e.from,to:e.to+o.length,original:e.original+o,replacement:e.replacement+o},...r.length?[{from:e.to+o.length,to:t.to,original:r,replacement:r}]:[]]}return[{from:e.from,to:t.to,original:e.original+t.original,replacement:e.replacement+t.replacement}]})(n,t)]}),[]),M=(e,t)=>{const n=(e=>{let t=0;return e.map((([e,n])=>{switch(e){case r.EQUAL:const e=n.lastIndexOf("\n"),o={from:t,to:t+n.length,original:n,replacement:n};if(-1!==e&&"\n"!==n){const o=[{from:t,to:t+e+1,original:n.slice(0,e+1),replacement:n.slice(0,e+1)},{from:t+e+1,to:t+n.length,original:n.slice(e+1),replacement:n.slice(e+1)}];return t+=n.length,o}return t+=n.length,[o];case r.DELETE:const s={from:t,to:t+n.length,original:n,replacement:""};return t+=n.length,[s];case r.INSERT:return[{from:t,to:t,original:"",replacement:n}]}})).flat()})(r(e,t));return E(E(n))},P=(e,t)=>{var n;const o=null===(n=v.getState(e.state))||void 0===n?void 0:n.decorations.find(0,e.state.doc.nodeSize,(e=>e.id===t.spec.id))[0];if(!o)return;const{text:r}=o.spec,{from:s,to:i}=o,a={type:d.acceptSuggestion,id:t.spec.id},c=e.state.tr.insertText(r,s,i).setMeta(v,a);e.dispatch(c)},L=(e,t)=>{const{spec:n}=t,o={type:d.discardSuggestion,id:n.id},r=e.state.tr.setMeta(v,o);e.dispatch(r)},k=(e,t)=>{const n=v.getState(e.state);if(!n)return!1;const{decorations:o}=n,r=o.find(t,t)[0];if(!r){const t={type:d.closeSuggestion};return e.dispatch(e.state.tr.setMeta(v,t)),!1}const s=n.popupDecoration.find()[0];if((null==s?void 0:s.spec.id)===r.spec.id)return!1;const i={type:d.openSuggestion,decoration:r};return e.dispatch(e.state.tr.setMeta(v,i)),!1},D={debounceMs:2e3,createUpdatePopup:(e,t,n,o,r)=>{const s=document.createElement("div");s.className="grammar-suggest-tooltip";const{spec:i}=t,a=e.dom.getBoundingClientRect();s.id=p.grammarSuggestPopup;const c=e.coordsAtPos(n);s.style.left=c.left-a.left+"px",s.style.top=c.bottom-a.top+5+"px";const l=document.createElement("div");l.className="grammar-suggest-tooltip-apply",l.innerText=i.text||i.originalText,i.text||(l.style.textDecoration="line-through",l.style.color="red"),l.onclick=()=>{o(e,t)},s.appendChild(l);const d=document.createElement("div");return d.innerHTML="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path d='M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z'></path></svg>",d.className="grammar-suggest-tooltip-discard",d.onclick=()=>{r(e,t)},s.appendChild(d),s},withYjs:!1},A={maxSelection:1e3},I=(e,r=D)=>{let c=!1;return new t({key:v,state:{init:()=>({lastText:"",decorations:o.empty,popupDecoration:o.empty}),apply(e,t,s,c){const l=e.getMeta(v);return(null==l?void 0:l.type)===d.suggestionUpdate?((e,t,o)=>{const{changedRegion:r,fix:s,mapping:i,text:a}=t,c=M(r.newText,s.result).filter((e=>!O(e))).filter((e=>e.original!==`${e.replacement}\n`)).map((({from:e,to:t,original:o,replacement:s})=>{const a=T(r.start+e,i),c=T(r.start+(s.endsWith("\n")?t-1:t),i),l={text:s.endsWith("\n")?s.slice(0,-1):s,originalText:o,id:{}};return n.inline(a,c,{class:"grammarSuggestion "+(""===s?"removalSuggestion":"")},l)}));return Object.assign(Object.assign({},e),{decorations:e.decorations.add(o.doc,c),lastText:a})})(t,l,e):(null==l?void 0:l.type)===d.acceptSuggestion?((e,t,n)=>{const r=e.decorations.remove(e.decorations.find(0,n.doc.nodeSize,(e=>e.id===t.id)));return Object.assign(Object.assign({},e),{lastText:y(n.doc),decorations:r.map(n.mapping,n.doc),popupDecoration:o.empty})})(t,l,e):(null==l?void 0:l.type)===d.openSuggestion?((e,t,r,s)=>{const{decoration:i}=t,a={id:i.spec.id};return Object.assign(Object.assign({},e),{popupDecoration:o.create(r.doc,[n.widget(i.from,((e,t)=>{const n=t();return n?s.createUpdatePopup(e,i,n,P,L):document.createElement("div")}),Object.assign(Object.assign({},a),{stopEvent:()=>!0}))])})})(t,l,e,r):(null==l?void 0:l.type)===d.closeSuggestion?Object.assign(Object.assign({},t),{popupDecoration:o.empty}):(null==l?void 0:l.type)===d.discardSuggestion?((e,t,n)=>Object.assign(Object.assign({},e),{decorations:e.decorations.remove(e.decorations.find(0,n.doc.nodeSize,(e=>e.id===t.id))),popupDecoration:o.empty}))(t,l,e):e.docChanged?((e,t,n,o)=>{const r=b(n.doc).text,{text:s,mapping:c}=b(t.doc);if(s===r)return e;let l=t.mapping;if(o){const e=t.doc.content.findDiffStart(n.doc.content),o=n.doc.content.findDiffEnd(t.doc.content),r=new i(o&&e?[e,o.a-e,o.b-e]:[0,0,0]);l=new a([r])}const d=S(r,s),p=e.decorations.map(l,t.doc),g=T(d.start,c),u=T(d.end,c),m=e.popupDecoration.map(l,t.doc);return Object.assign(Object.assign({},e),{decorations:p.remove(p.find(g,u)),popupDecoration:m.remove(m.find(g,u))})})(t,e,s,r.withYjs):t}},props:{handleClick:k,decorations:e=>{const t=v.getState(e);if(!t)return null;const n=x.getState(e);return(null==n?void 0:n.status)!==h.idle?t.decorations:t.decorations.add(e.doc,t.popupDecoration.find())}},view(){const t=((e,t)=>s((e=>{var n;const o=b(e.state.doc),r=(null===(n=v.getState(e.state))||void 0===n?void 0:n.lastText)||"",s=S(r,o.text);C(t,s.newText).then((t=>{if(y(e.state.doc)!==o.text)return;const n={type:d.suggestionUpdate,fix:t,changedRegion:s,mapping:o.mapping,text:o.text};e.dispatch(e.state.tr.setMeta(v,n))})).catch((e=>{console.error("Grammar suggest API error",e)}))}),e.debounceMs))(r,e);return{update(e,n){const o=v.getState(e.state);e.state.doc.textBetween(0,e.state.doc.nodeSize-2,"/n")===n.doc.textBetween(0,n.doc.nodeSize-2,"/n")&&c||!o||o.lastText===y(e.state.doc)||(c=!0,t(e))}}}})},R=(e,t,n,o,r,s,i)=>w(void 0,void 0,void 0,(function*(){var e;let n="";try{const a=null===(e=(yield fetch("https://suggestion-gw5lxik4dq-uc.a.run.app",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:"Bearer -qKivjCv6MfQSmgF438PjEY7RnLfqoVe"},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:[t],task:r,params:i}})})).body)||void 0===e?void 0:e.getReader(),c=({done:e,value:t})=>w(void 0,void 0,void 0,(function*(){if(e)return;const i=(new TextDecoder).decode(t);try{n+=i,console.log({res:n,chunk:i}),o.dispatch(o.state.tr.setMeta(x,Object.assign({type:r,status:h.streaming,result:n},s&&{selection:s})))}catch(e){console.error("Could not parse stream message",i,e)}return null==a?void 0:a.read().then(c)}));yield null==a?void 0:a.read().then(c),o.dispatch(o.state.tr.setMeta(x,Object.assign({type:r,status:h.finished,result:n},s&&{selection:s})))}catch(e){console.error("Error:",e)}})),N=(e,n=A)=>new t({key:x,state:{init:()=>({status:h.idle}),apply(e,t,n,o){const r=e.getMeta(x);return t.status===h.done||t.status===h.rejected?{status:h.idle}:r&&(e=>Object.values(f).includes(e.type)||Object.values(m).includes(e.type))(r)?t.type&&r.type!==t.type?t:Object.assign(Object.assign({},t),r):t}},view:()=>({update(e,t){const o=x.getState(e.state);let r=e.state.tr;if((null==o?void 0:o.status)===h.new)switch(o.type){case m.Complete:((e,t,n)=>{w(void 0,void 0,void 0,(function*(){const{doc:e}=t.state,n=[];e.descendants((e=>{"paragraph"===e.type.name&&n.push(e.textContent)}));let o="";o=n.length>=2?n.slice(-2).join(" "):n.join(" "),R(0,o,0,t,m.Complete)}))})(0,e),console.log("complete");break;case m.MakeLonger:case m.MakeShorter:case m.Improve:case m.Simplify:case m.Explain:case m.ActionItems:case f.Translate:case f.ChangeTone:((e,t,n,o,r,s)=>{const i=n.state.selection;if(!i)return console.log("No selection"),void n.dispatch(n.state.tr.setMeta(x,{task:e,status:h.done}));const a=n.state.doc.textBetween(i.from,i.to);if(console.log({selectedText:a}),a.length>r)return void n.dispatch(n.state.tr.setMeta(x,{type:e,status:h.error,error:"Selection is too big"}));const c=n.state.doc.textBetween(i.from,i.to,"\n");R(0,c,0,n,e,i,s)})(o.type,0,e,0,n.maxSelection,o.params),console.log("improve selected text")}if((null==o?void 0:o.status)===h.accepted){if(o.error)return r.setMeta(x,{type:o.type,status:h.done}),void e.dispatch(r);switch(o.type){case m.Complete:r=r.insertText(o.result||"",e.state.doc.nodeSize-2),r.setMeta(x,{type:m.Complete,status:h.done}),e.dispatch(r),e.focus(),console.log("complete accepted V1");break;case m.MakeLonger:case m.MakeShorter:case m.Improve:case m.Simplify:case m.Explain:case m.ActionItems:if(o.selection&&o.result){const t=c.fromArray(Array.from(o.result).map((t=>e.state.schema.text(t))));r.selection.replace(r,new l(t,0,0))}r.setMeta(x,{type:o.type,status:h.done}),e.dispatch(r),e.focus(),console.log("makeShorterLonger acceptedV1")}}}})});export{g as MoodParamType,f as OpenAiPromptsWithParam,m as OpenAiPromptsWithoutParam,h as Status,u as TranslationTargetLanguage,N as completePlugin,x as completePluginKey,A as defaultCompleteOptions,D as defaultOptions,I as grammarSuggestPlugin};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("prosemirror-state"),e=require("prosemirror-view"),n=require("fast-diff"),o=require("lodash.debounce"),r=require("prosemirror-transform");const i=new t.PluginKey("grammarSuggestPlugin"),s=t=>{let e="";return t.descendants(((t,n)=>{t.isText&&(e+=`${t.text}\n`)})),e},a=(t,e)=>{if(t===e)return{start:t.length,end:t.length,oldStart:t.length,oldEnd:t.length,oldText:"",newText:""};const o=n(t,e),r=o[0],i=r[0]===n.EQUAL?r[1].length-1:0,s=((t,e)=>{if(e[e.length-1][0]!==n.EQUAL)return t.length;const o=e.slice(0,e.length-1);let r=0;for(const t of o){const[e,o]=t;e===n.EQUAL&&(r+=o.length),e===n.DELETE&&(r+=o.length)}return r})(t,o),a=t.lastIndexOf("\n",i),c=t.indexOf("\n",s),l=-1===a?0:a+1,g=-1===c?t.length:c,p=t.slice(l,g),d=e.slice(l,e.length-(t.length-g));return{start:l,end:l+d.length,oldStart:l,oldEnd:g,oldText:p,newText:d}};var c,l;function g(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))}!function(t){t.suggestionUpdate="suggestionUpdate",t.acceptSuggestion="acceptSuggestion",t.openSuggestion="openSuggestion",t.closeSuggestion="closeSuggestion",t.discardSuggestion="discardSuggestion"}(c||(c={})),function(t){t.grammarSuggestPopup="grammar-suggest-popup"}(l||(l={}));const p=[{docPos:1,textPos:0}],d=t=>{let e="";const n=[];return t.descendants(((t,o)=>{t.isText&&(n.push({docPos:o,textPos:e.length}),e+=`${t.text}\n`)})),{text:e,mapping:n.length?n:p}},u=(t,e)=>{for(let n=0;n<e.length;n++)if(t>=e[n].textPos&&(void 0===e[n+1]||t<e[n+1].textPos))return e[n].docPos+(t-e[n].textPos);throw new Error("textPositionToDocumentPosition: textPos not found in mapping")},m=(t,e)=>g(void 0,void 0,void 0,(function*(){const n=[...e.split("\n")];return fetch("https://prosemirror-ai-plugin.web.app/api/suggestion",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:n}})}).then((t=>t.ok?t.json():Promise.reject(t))).then((t=>t&&t.some((t=>(t=>{try{JSON.parse(t)}catch(t){return!1}return!0})(t)))?{result:t.map((t=>JSON.parse(t).result)).join("\n"),fixed:!0}:{fixed:!1,result:e})).catch((t=>(t.text().then((e=>{console.error({status:t.status,text:e})})),{fixed:!1,result:e})))})),f=t=>t.replacement===t.original,h=t=>t.reduce(((t,e)=>{const n=t[t.length-1],o=t.slice(0,t.length-1);if(!n)return[e];return[...o,...((t,e)=>{if(t.to!==e.from)throw new Error(`Replace pairs must be adjacent\n\n, ${JSON.stringify({leftReplace:t,rightReplace:e})}`);if(t.replacement.endsWith("\n"))return[t,e];if(f(t)&&f(e))return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}];if(f(t)){if(e.replacement.startsWith(" ")&&""===e.original||e.original.startsWith(" ")&&""===e.replacement)return[t,e];const n=t.original.split(" "),o=n.pop()||"",r=n.join(" ")+(n.length?" ":"");return[...r.length?[{from:t.from,to:t.from+r.length,original:r,replacement:r}]:[],{from:t.from+r.length,to:e.to,original:o+e.original,replacement:o+e.replacement}]}if(f(e)){if(t.replacement.endsWith(" ")&&""===t.original||t.original.endsWith(" ")&&""===t.replacement)return[t,e];const n=e.original.split(" "),o=n.shift()||"",r=(n.length?" ":"")+n.join(" ");return" "===r?[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]:[{from:t.from,to:t.to+o.length,original:t.original+o,replacement:t.replacement+o},...r.length?[{from:t.to+o.length,to:e.to,original:r,replacement:r}]:[]]}return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]})(n,e)]}),[]),x=(t,e)=>{const o=(t=>{let e=0;return t.map((([t,o])=>{switch(t){case n.EQUAL:const t=o.lastIndexOf("\n"),r={from:e,to:e+o.length,original:o,replacement:o};if(-1!==t&&"\n"!==o){const n=[{from:e,to:e+t+1,original:o.slice(0,t+1),replacement:o.slice(0,t+1)},{from:e+t+1,to:e+o.length,original:o.slice(t+1),replacement:o.slice(t+1)}];return e+=o.length,n}return e+=o.length,[r];case n.DELETE:const i={from:e,to:e+o.length,original:o,replacement:""};return e+=o.length,[i];case n.INSERT:return[{from:e,to:e,original:"",replacement:o}]}})).flat()})(n(t,e));return h(h(o))},S=(t,e)=>{var n;const o=null===(n=i.getState(t.state))||void 0===n?void 0:n.decorations.find(0,t.state.doc.nodeSize,(t=>t.id===e.spec.id))[0];if(!o)return;const{text:r}=o.spec,{from:s,to:a}=o,l={type:c.acceptSuggestion,id:e.spec.id},g=t.state.tr.insertText(r,s,a).setMeta(i,l);t.dispatch(g)},v=(t,e)=>{const{spec:n}=e,o={type:c.discardSuggestion,id:n.id},r=t.state.tr.setMeta(i,o);t.dispatch(r)},w=(t,e)=>{const n=i.getState(t.state);if(!n)return!1;const{decorations:o}=n,r=o.find(e,e)[0];if(!r){const e={type:c.closeSuggestion};return t.dispatch(t.state.tr.setMeta(i,e)),!1}const s=n.popupDecoration.find()[0];if((null==s?void 0:s.spec.id)===r.spec.id)return!1;const a={type:c.openSuggestion,decoration:r};return t.dispatch(t.state.tr.setMeta(i,a)),!1},y={debounceMs:2e3,createUpdatePopup:(t,e,n,o,r)=>{const i=document.createElement("div");i.className="grammar-suggest-tooltip";const{spec:s}=e,a=t.dom.getBoundingClientRect();i.id=l.grammarSuggestPopup;const c=t.coordsAtPos(n);i.style.left=c.left-a.left+"px",i.style.top=c.bottom-a.top+5+"px";const g=document.createElement("div");g.className="grammar-suggest-tooltip-apply",g.innerText=s.text||s.originalText,s.text||(g.style.textDecoration="line-through",g.style.color="red"),g.onclick=()=>{o(t,e)},i.appendChild(g);const p=document.createElement("div");return p.innerHTML="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path d='M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z'></path></svg>",p.className="grammar-suggest-tooltip-discard",p.onclick=()=>{r(t,e)},i.appendChild(p),i},withYjs:!1};exports.defaultOptions=y,exports.grammarSuggestPlugin=(n,l=y)=>{let g=!1;return new t.Plugin({key:i,state:{init:()=>({lastText:"",decorations:e.DecorationSet.empty,popupDecoration:e.DecorationSet.empty}),apply(t,n,o,g){const p=t.getMeta(i);return(null==p?void 0:p.type)===c.suggestionUpdate?((t,n,o)=>{const{changedRegion:r,fix:i,mapping:s,text:a}=n,c=x(r.newText,i.result).filter((t=>!f(t))).filter((t=>t.original!==`${t.replacement}\n`)).map((({from:t,to:n,original:o,replacement:i})=>{const a=u(r.start+t,s),c=u(r.start+(i.endsWith("\n")?n-1:n),s),l={text:i.endsWith("\n")?i.slice(0,-1):i,originalText:o,id:{}};return e.Decoration.inline(a,c,{class:"grammarSuggestion "+(""===i?"removalSuggestion":"")},l)}));return Object.assign(Object.assign({},t),{decorations:t.decorations.add(o.doc,c),lastText:a})})(n,p,t):(null==p?void 0:p.type)===c.acceptSuggestion?((t,n,o)=>{const r=t.decorations.remove(t.decorations.find(0,o.doc.nodeSize,(t=>t.id===n.id)));return Object.assign(Object.assign({},t),{lastText:s(o.doc),decorations:r.map(o.mapping,o.doc),popupDecoration:e.DecorationSet.empty})})(n,p,t):(null==p?void 0:p.type)===c.openSuggestion?((t,n,o,r)=>{const{decoration:i}=n,s={id:i.spec.id};return Object.assign(Object.assign({},t),{popupDecoration:e.DecorationSet.create(o.doc,[e.Decoration.widget(i.from,((t,e)=>{const n=e();return n?r.createUpdatePopup(t,i,n,S,v):document.createElement("div")}),Object.assign(Object.assign({},s),{stopEvent:()=>!0}))])})})(n,p,t,l):(null==p?void 0:p.type)===c.closeSuggestion?Object.assign(Object.assign({},n),{popupDecoration:e.DecorationSet.empty}):(null==p?void 0:p.type)===c.discardSuggestion?((t,n,o)=>Object.assign(Object.assign({},t),{decorations:t.decorations.remove(t.decorations.find(0,o.doc.nodeSize,(t=>t.id===n.id))),popupDecoration:e.DecorationSet.empty}))(n,p,t):t.docChanged?((t,e,n,o)=>{const i=d(n.doc).text,{text:s,mapping:c}=d(e.doc);if(s===i)return t;let l=e.mapping;if(o){const t=e.doc.content.findDiffStart(n.doc.content),o=n.doc.content.findDiffEnd(e.doc.content),i=o&&t?new r.StepMap([t,o.a-t,o.b-t]):new r.StepMap([0,0,0]);l=new r.Mapping([i])}const g=a(i,s),p=t.decorations.map(l,e.doc),m=u(g.start,c),f=u(g.end,c),h=t.popupDecoration.map(l,e.doc);return Object.assign(Object.assign({},t),{decorations:p.remove(p.find(m,f)),popupDecoration:h.remove(h.find(m,f))})})(n,t,o,l.withYjs):n}},props:{handleClick:w,decorations:t=>{const e=i.getState(t);return e?e.decorations.add(t.doc,e.popupDecoration.find()):null}},view(){const t=((t,e)=>o((t=>{var n;const o=d(t.state.doc),r=(null===(n=i.getState(t.state))||void 0===n?void 0:n.lastText)||"",l=a(r,o.text);m(e,l.newText).then((e=>{if(s(t.state.doc)!==o.text)return;const n={type:c.suggestionUpdate,fix:e,changedRegion:l,mapping:o.mapping,text:o.text};t.dispatch(t.state.tr.setMeta(i,n))})).catch((t=>{console.error("Grammar suggest API error",t)}))}),t.debounceMs))(l,n);return{update(e,n){const o=i.getState(e.state);e.state.doc.textBetween(0,e.state.doc.nodeSize-2,"/n")===n.doc.textBetween(0,n.doc.nodeSize-2,"/n")&&g||!o||o.lastText===s(e.state.doc)||(g=!0,t(e))}}}})};
1
+ "use strict";var t,e,o,n,r,s,a,i=require("prosemirror-state"),c=require("prosemirror-view"),p=require("fast-diff"),l=require("lodash.debounce"),d=require("prosemirror-transform"),u=require("prosemirror-model");!function(t){t.suggestionUpdate="suggestionUpdate",t.acceptSuggestion="acceptSuggestion",t.openSuggestion="openSuggestion",t.closeSuggestion="closeSuggestion",t.discardSuggestion="discardSuggestion"}(t||(t={})),function(t){t.grammarSuggestPopup="grammar-suggest-popup"}(e||(e={})),exports.MoodParamType=void 0,(o=exports.MoodParamType||(exports.MoodParamType={})).Casual="Casual",o.Confident="Confident",o.Straightforward="Straightforward",o.Friendly="Friendly",exports.TranslationTargetLanguage=void 0,(n=exports.TranslationTargetLanguage||(exports.TranslationTargetLanguage={})).English="English",n.Spanish="Spanish",n.French="French",n.German="German",n.Italian="Italian",n.Portuguese="Portuguese",n.Dutch="Dutch",n.Russian="Russian",n.Chinese="Chinese",n.Korean="Korean",n.Japanese="Japanese",exports.OpenAiPromptsWithoutParam=void 0,(r=exports.OpenAiPromptsWithoutParam||(exports.OpenAiPromptsWithoutParam={})).Complete="Complete",r.Improve="Improve",r.MakeLonger="MakeLonger",r.MakeShorter="MakeShorter",r.Simplify="Simplify",r.Explain="Explain",r.ActionItems="ActionItems",exports.OpenAiPromptsWithParam=void 0,(s=exports.OpenAiPromptsWithParam||(exports.OpenAiPromptsWithParam={})).ChangeTone="ChangeTone",s.Translate="Translate",exports.Status=void 0,(a=exports.Status||(exports.Status={})).idle="idle",a.new="new",a.streaming="streaming",a.finished="finished",a.accepted="accepted",a.rejected="rejected",a.done="done",a.error="error";const g=new i.PluginKey("completePlugin"),m=new i.PluginKey("grammarSuggestPlugin"),h=t=>{let e="";return t.descendants(((t,o)=>{t.isText&&(e+=`${t.text}\n`)})),e},f=(t,e)=>{if(t===e)return{start:t.length,end:t.length,oldStart:t.length,oldEnd:t.length,oldText:"",newText:""};const o=p(t,e),n=o[0],r=n[0]===p.EQUAL?n[1].length-1:0,s=((t,e)=>{if(e[e.length-1][0]!==p.EQUAL)return t.length;const o=e.slice(0,e.length-1);let n=0;for(const t of o){const[e,o]=t;e===p.EQUAL&&(n+=o.length),e===p.DELETE&&(n+=o.length)}return n})(t,o),a=t.lastIndexOf("\n",r),i=t.indexOf("\n",s),c=-1===a?0:a+1,l=-1===i?t.length:i,d=t.slice(c,l),u=e.slice(c,e.length-(t.length-l));return{start:c,end:c+u.length,oldStart:c,oldEnd:l,oldText:d,newText:u}};function x(t,e,o,n){return new(o||(o=Promise))((function(r,s){function a(t){try{c(n.next(t))}catch(t){s(t)}}function i(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,i)}c((n=n.apply(t,e||[])).next())}))}const P=[{docPos:1,textPos:0}],S=t=>{let e="";const o=[];return t.descendants(((t,n)=>{t.isText&&(o.push({docPos:n,textPos:e.length}),e+=`${t.text}\n`)})),{text:e,mapping:o.length?o:P}},v=(t,e)=>{for(let o=0;o<e.length;o++)if(t>=e[o].textPos&&(void 0===e[o+1]||t<e[o+1].textPos))return e[o].docPos+(t-e[o].textPos);throw new Error("textPositionToDocumentPosition: textPos not found in mapping")},y=(t,e)=>x(void 0,void 0,void 0,(function*(){const o=[...e.split("\n")];return fetch("https://prosemirror-ai-plugin.web.app/api/suggestion",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:o}})}).then((t=>t.ok?t.json():Promise.reject(t))).then((t=>t&&t.some((t=>(t=>{try{JSON.parse(t)}catch(t){return!1}return!0})(t)))?{result:t.map((t=>JSON.parse(t).result)).join("\n"),fixed:!0}:{fixed:!1,result:e})).catch((t=>(t.text().then((e=>{console.error({status:t.status,text:e})})),{fixed:!1,result:e})))})),O=t=>t.replacement===t.original,w=t=>t.reduce(((t,e)=>{const o=t[t.length-1],n=t.slice(0,t.length-1);if(!o)return[e];return[...n,...((t,e)=>{if(t.to!==e.from)throw new Error(`Replace pairs must be adjacent\n\n, ${JSON.stringify({leftReplace:t,rightReplace:e})}`);if(t.replacement.endsWith("\n"))return[t,e];if(O(t)&&O(e))return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}];if(O(t)){if(e.replacement.startsWith(" ")&&""===e.original||e.original.startsWith(" ")&&""===e.replacement)return[t,e];const o=t.original.split(" "),n=o.pop()||"",r=o.join(" ")+(o.length?" ":"");return[...r.length?[{from:t.from,to:t.from+r.length,original:r,replacement:r}]:[],{from:t.from+r.length,to:e.to,original:n+e.original,replacement:n+e.replacement}]}if(O(e)){if(t.replacement.endsWith(" ")&&""===t.original||t.original.endsWith(" ")&&""===t.replacement)return[t,e];const o=e.original.split(" "),n=o.shift()||"",r=(o.length?" ":"")+o.join(" ");return" "===r?[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]:[{from:t.from,to:t.to+n.length,original:t.original+n,replacement:t.replacement+n},...r.length?[{from:t.to+n.length,to:e.to,original:r,replacement:r}]:[]]}return[{from:t.from,to:e.to,original:t.original+e.original,replacement:t.replacement+e.replacement}]})(o,e)]}),[]),T=(t,e)=>{const o=(t=>{let e=0;return t.map((([t,o])=>{switch(t){case p.EQUAL:const t=o.lastIndexOf("\n"),n={from:e,to:e+o.length,original:o,replacement:o};if(-1!==t&&"\n"!==o){const n=[{from:e,to:e+t+1,original:o.slice(0,t+1),replacement:o.slice(0,t+1)},{from:e+t+1,to:e+o.length,original:o.slice(t+1),replacement:o.slice(t+1)}];return e+=o.length,n}return e+=o.length,[n];case p.DELETE:const r={from:e,to:e+o.length,original:o,replacement:""};return e+=o.length,[r];case p.INSERT:return[{from:e,to:e,original:"",replacement:o}]}})).flat()})(p(t,e));return w(w(o))},A=(e,o)=>{var n;const r=null===(n=m.getState(e.state))||void 0===n?void 0:n.decorations.find(0,e.state.doc.nodeSize,(t=>t.id===o.spec.id))[0];if(!r)return;const{text:s}=r.spec,{from:a,to:i}=r,c={type:t.acceptSuggestion,id:o.spec.id},p=e.state.tr.insertText(s,a,i).setMeta(m,c);e.dispatch(p)},j=(e,o)=>{const{spec:n}=o,r={type:t.discardSuggestion,id:n.id},s=e.state.tr.setMeta(m,r);e.dispatch(s)},b=(e,o)=>{const n=m.getState(e.state);if(!n)return!1;const{decorations:r}=n,s=r.find(o,o)[0];if(!s){const o={type:t.closeSuggestion};return e.dispatch(e.state.tr.setMeta(m,o)),!1}const a=n.popupDecoration.find()[0];if((null==a?void 0:a.spec.id)===s.spec.id)return!1;const i={type:t.openSuggestion,decoration:s};return e.dispatch(e.state.tr.setMeta(m,i)),!1},M={debounceMs:2e3,createUpdatePopup:(t,o,n,r,s)=>{const a=document.createElement("div");a.className="grammar-suggest-tooltip";const{spec:i}=o,c=t.dom.getBoundingClientRect();a.id=e.grammarSuggestPopup;const p=t.coordsAtPos(n);a.style.left=p.left-c.left+"px",a.style.top=p.bottom-c.top+5+"px";const l=document.createElement("div");l.className="grammar-suggest-tooltip-apply",l.innerText=i.text||i.originalText,i.text||(l.style.textDecoration="line-through",l.style.color="red"),l.onclick=()=>{r(t,o)},a.appendChild(l);const d=document.createElement("div");return d.innerHTML="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path d='M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z'></path></svg>",d.className="grammar-suggest-tooltip-discard",d.onclick=()=>{s(t,o)},a.appendChild(d),a},withYjs:!1},C={maxSelection:1e3},W=(t,e,o,n,r,s,a)=>x(void 0,void 0,void 0,(function*(){var t;let o="";try{const i=null===(t=(yield fetch("https://suggestion-gw5lxik4dq-uc.a.run.app",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json",Authorization:"Bearer -qKivjCv6MfQSmgF438PjEY7RnLfqoVe"},body:JSON.stringify({model:"gpt-3.5-turbo",modelParams:{input:[e],task:r,params:a}})})).body)||void 0===t?void 0:t.getReader(),c=({done:t,value:e})=>x(void 0,void 0,void 0,(function*(){if(t)return;const a=(new TextDecoder).decode(e);try{o+=a,console.log({res:o,chunk:a}),n.dispatch(n.state.tr.setMeta(g,Object.assign({type:r,status:exports.Status.streaming,result:o},s&&{selection:s})))}catch(t){console.error("Could not parse stream message",a,t)}return null==i?void 0:i.read().then(c)}));yield null==i?void 0:i.read().then(c),n.dispatch(n.state.tr.setMeta(g,Object.assign({type:r,status:exports.Status.finished,result:o},s&&{selection:s})))}catch(t){console.error("Error:",t)}}));exports.completePlugin=(t,e=C)=>new i.Plugin({key:g,state:{init:()=>({status:exports.Status.idle}),apply(t,e,o,n){const r=t.getMeta(g);return e.status===exports.Status.done||e.status===exports.Status.rejected?{status:exports.Status.idle}:r&&(t=>Object.values(exports.OpenAiPromptsWithParam).includes(t.type)||Object.values(exports.OpenAiPromptsWithoutParam).includes(t.type))(r)?e.type&&r.type!==e.type?e:Object.assign(Object.assign({},e),r):e}},view:()=>({update(t,o){const n=g.getState(t.state);let r=t.state.tr;if((null==n?void 0:n.status)===exports.Status.new)switch(n.type){case exports.OpenAiPromptsWithoutParam.Complete:((t,e,o)=>{x(void 0,void 0,void 0,(function*(){const{doc:t}=e.state,o=[];t.descendants((t=>{"paragraph"===t.type.name&&o.push(t.textContent)}));let n="";n=o.length>=2?o.slice(-2).join(" "):o.join(" "),W(0,n,0,e,exports.OpenAiPromptsWithoutParam.Complete)}))})(0,t),console.log("complete");break;case exports.OpenAiPromptsWithoutParam.MakeLonger:case exports.OpenAiPromptsWithoutParam.MakeShorter:case exports.OpenAiPromptsWithoutParam.Improve:case exports.OpenAiPromptsWithoutParam.Simplify:case exports.OpenAiPromptsWithoutParam.Explain:case exports.OpenAiPromptsWithoutParam.ActionItems:case exports.OpenAiPromptsWithParam.Translate:case exports.OpenAiPromptsWithParam.ChangeTone:((t,e,o,n,r,s)=>{const a=o.state.selection;if(!a)return console.log("No selection"),void o.dispatch(o.state.tr.setMeta(g,{task:t,status:exports.Status.done}));const i=o.state.doc.textBetween(a.from,a.to);if(console.log({selectedText:i}),i.length>r)return void o.dispatch(o.state.tr.setMeta(g,{type:t,status:exports.Status.error,error:"Selection is too big"}));const c=o.state.doc.textBetween(a.from,a.to,"\n");W(0,c,0,o,t,a,s)})(n.type,0,t,0,e.maxSelection,n.params),console.log("improve selected text")}if((null==n?void 0:n.status)===exports.Status.accepted){if(n.error)return r.setMeta(g,{type:n.type,status:exports.Status.done}),void t.dispatch(r);switch(n.type){case exports.OpenAiPromptsWithoutParam.Complete:r=r.insertText(n.result||"",t.state.doc.nodeSize-2),r.setMeta(g,{type:exports.OpenAiPromptsWithoutParam.Complete,status:exports.Status.done}),t.dispatch(r),t.focus(),console.log("complete accepted V1");break;case exports.OpenAiPromptsWithoutParam.MakeLonger:case exports.OpenAiPromptsWithoutParam.MakeShorter:case exports.OpenAiPromptsWithoutParam.Improve:case exports.OpenAiPromptsWithoutParam.Simplify:case exports.OpenAiPromptsWithoutParam.Explain:case exports.OpenAiPromptsWithoutParam.ActionItems:if(n.selection&&n.result){const e=u.Fragment.fromArray(Array.from(n.result).map((e=>t.state.schema.text(e))));r.selection.replace(r,new u.Slice(e,0,0))}r.setMeta(g,{type:n.type,status:exports.Status.done}),t.dispatch(r),t.focus(),console.log("makeShorterLonger acceptedV1")}}}})}),exports.completePluginKey=g,exports.defaultCompleteOptions=C,exports.defaultOptions=M,exports.grammarSuggestPlugin=(e,o=M)=>{let n=!1;return new i.Plugin({key:m,state:{init:()=>({lastText:"",decorations:c.DecorationSet.empty,popupDecoration:c.DecorationSet.empty}),apply(e,n,r,s){const a=e.getMeta(m);return(null==a?void 0:a.type)===t.suggestionUpdate?((t,e,o)=>{const{changedRegion:n,fix:r,mapping:s,text:a}=e,i=T(n.newText,r.result).filter((t=>!O(t))).filter((t=>t.original!==`${t.replacement}\n`)).map((({from:t,to:e,original:o,replacement:r})=>{const a=v(n.start+t,s),i=v(n.start+(r.endsWith("\n")?e-1:e),s),p={text:r.endsWith("\n")?r.slice(0,-1):r,originalText:o,id:{}};return c.Decoration.inline(a,i,{class:"grammarSuggestion "+(""===r?"removalSuggestion":"")},p)}));return Object.assign(Object.assign({},t),{decorations:t.decorations.add(o.doc,i),lastText:a})})(n,a,e):(null==a?void 0:a.type)===t.acceptSuggestion?((t,e,o)=>{const n=t.decorations.remove(t.decorations.find(0,o.doc.nodeSize,(t=>t.id===e.id)));return Object.assign(Object.assign({},t),{lastText:h(o.doc),decorations:n.map(o.mapping,o.doc),popupDecoration:c.DecorationSet.empty})})(n,a,e):(null==a?void 0:a.type)===t.openSuggestion?((t,e,o,n)=>{const{decoration:r}=e,s={id:r.spec.id};return Object.assign(Object.assign({},t),{popupDecoration:c.DecorationSet.create(o.doc,[c.Decoration.widget(r.from,((t,e)=>{const o=e();return o?n.createUpdatePopup(t,r,o,A,j):document.createElement("div")}),Object.assign(Object.assign({},s),{stopEvent:()=>!0}))])})})(n,a,e,o):(null==a?void 0:a.type)===t.closeSuggestion?Object.assign(Object.assign({},n),{popupDecoration:c.DecorationSet.empty}):(null==a?void 0:a.type)===t.discardSuggestion?((t,e,o)=>Object.assign(Object.assign({},t),{decorations:t.decorations.remove(t.decorations.find(0,o.doc.nodeSize,(t=>t.id===e.id))),popupDecoration:c.DecorationSet.empty}))(n,a,e):e.docChanged?((t,e,o,n)=>{const r=S(o.doc).text,{text:s,mapping:a}=S(e.doc);if(s===r)return t;let i=e.mapping;if(n){const t=e.doc.content.findDiffStart(o.doc.content),n=o.doc.content.findDiffEnd(e.doc.content),r=n&&t?new d.StepMap([t,n.a-t,n.b-t]):new d.StepMap([0,0,0]);i=new d.Mapping([r])}const c=f(r,s),p=t.decorations.map(i,e.doc),l=v(c.start,a),u=v(c.end,a),g=t.popupDecoration.map(i,e.doc);return Object.assign(Object.assign({},t),{decorations:p.remove(p.find(l,u)),popupDecoration:g.remove(g.find(l,u))})})(n,e,r,o.withYjs):n}},props:{handleClick:b,decorations:t=>{const e=m.getState(t);if(!e)return null;const o=g.getState(t);return(null==o?void 0:o.status)!==exports.Status.idle?e.decorations:e.decorations.add(t.doc,e.popupDecoration.find())}},view(){const r=((e,o)=>l((e=>{var n;const r=S(e.state.doc),s=(null===(n=m.getState(e.state))||void 0===n?void 0:n.lastText)||"",a=f(s,r.text);y(o,a.newText).then((o=>{if(h(e.state.doc)!==r.text)return;const n={type:t.suggestionUpdate,fix:o,changedRegion:a,mapping:r.mapping,text:r.text};e.dispatch(e.state.tr.setMeta(m,n))})).catch((t=>{console.error("Grammar suggest API error",t)}))}),e.debounceMs))(o,e);return{update(t,e){const o=m.getState(t.state);t.state.doc.textBetween(0,t.state.doc.nodeSize-2,"/n")===e.doc.textBetween(0,e.doc.nodeSize-2,"/n")&&n||!o||o.lastText===h(t.state.doc)||(n=!0,r(t))}}}})};
@@ -0,0 +1,4 @@
1
+ import { EditorView } from "prosemirror-view";
2
+ import { CompletePluginState, MoodParams, TaskType, TranslationParams } from "./types";
3
+ export declare const completeRequest: (pluginState: CompletePluginState, view: EditorView, apiKey: string) => Promise<void>;
4
+ export declare const makeShorterLonger: (task: TaskType, pluginState: CompletePluginState, view: EditorView, apiKey: string, maxSelection: number, params?: MoodParams | TranslationParams) => void;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
2
+ import { TextSelection } from "prosemirror-state";
2
3
  export type TextMappingItem = {
3
4
  docPos: number;
4
5
  textPos: number;
@@ -74,3 +75,67 @@ export type PopupDecorationSpec = {
74
75
  export declare enum GrammarSuggestElementClass {
75
76
  grammarSuggestPopup = "grammar-suggest-popup"
76
77
  }
78
+ export declare enum MoodParamType {
79
+ Casual = "Casual",
80
+ Confident = "Confident",
81
+ Straightforward = "Straightforward",
82
+ Friendly = "Friendly"
83
+ }
84
+ export declare enum TranslationTargetLanguage {
85
+ English = "English",
86
+ Spanish = "Spanish",
87
+ French = "French",
88
+ German = "German",
89
+ Italian = "Italian",
90
+ Portuguese = "Portuguese",
91
+ Dutch = "Dutch",
92
+ Russian = "Russian",
93
+ Chinese = "Chinese",
94
+ Korean = "Korean",
95
+ Japanese = "Japanese"
96
+ }
97
+ export type TranslationParams = {
98
+ targetLanguage: TranslationTargetLanguage;
99
+ };
100
+ export type MoodParams = {
101
+ mood: MoodParamType;
102
+ };
103
+ export declare enum OpenAiPromptsWithoutParam {
104
+ Complete = "Complete",
105
+ Improve = "Improve",
106
+ MakeLonger = "MakeLonger",
107
+ MakeShorter = "MakeShorter",
108
+ Simplify = "Simplify",
109
+ Explain = "Explain",
110
+ ActionItems = "ActionItems"
111
+ }
112
+ export declare enum OpenAiPromptsWithParam {
113
+ ChangeTone = "ChangeTone",
114
+ Translate = "Translate"
115
+ }
116
+ export type TaskType = OpenAiPromptsWithoutParam | OpenAiPromptsWithParam;
117
+ export declare enum Status {
118
+ idle = "idle",
119
+ new = "new",
120
+ streaming = "streaming",
121
+ finished = "finished",
122
+ accepted = "accepted",
123
+ rejected = "rejected",
124
+ done = "done",
125
+ error = "error"
126
+ }
127
+ export interface CompletePluginState {
128
+ type?: TaskType;
129
+ params?: MoodParams | TranslationParams | undefined;
130
+ status?: Status;
131
+ result?: string;
132
+ selection?: TextSelection;
133
+ error?: string;
134
+ }
135
+ export interface TaskMeta {
136
+ type: TaskType;
137
+ status: Status.new | Status.accepted | Status.rejected;
138
+ }
139
+ export interface DefaultCompleteOptions {
140
+ maxSelection: number;
141
+ }
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { PluginKey } from "prosemirror-state";
2
2
  import { Node } from "prosemirror-model";
3
- import { ChangedRegion, GrammarSuggestPluginState } from "./types";
3
+ import { ChangedRegion, CompletePluginState, GrammarSuggestPluginState, TaskMeta } from "./types";
4
+ export declare const completePluginKey: PluginKey<CompletePluginState>;
5
+ export declare const isCompleteMeta: (meta: any) => meta is TaskMeta;
4
6
  export declare const grammarSuggestPluginKey: PluginKey<GrammarSuggestPluginState>;
5
7
  export declare const getTextWithNewlines: (node: Node) => string;
6
8
  export declare const getChangedRegions: (oldText: string, newText: string) => ChangedRegion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-suggestcat-plugin",
3
- "version": "0.0.12",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",