prosemirror-suggestcat-plugin 0.1.0 → 0.1.2
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/completePlugin.d.ts +3 -3
- package/dist/completePlugin.d.ts.map +1 -0
- package/dist/completePlugin.js +123 -0
- package/dist/createUpdatePopup.d.ts +2 -2
- package/dist/createUpdatePopup.d.ts.map +1 -0
- package/dist/defaults.d.ts +3 -3
- package/dist/defaults.d.ts.map +1 -0
- package/dist/eventHandlers.d.ts +9 -9
- package/dist/eventHandlers.d.ts.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +1 -1
- package/dist/index.js +1 -1
- package/dist/makeRequest.d.ts +3 -4
- package/dist/makeRequest.d.ts.map +1 -0
- package/dist/makeRequest.js +95 -0
- package/dist/makeTaksRequest.d.ts +4 -4
- package/dist/makeTaksRequest.d.ts.map +1 -0
- package/dist/mapping.d.ts +7 -7
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.test.d.ts +1 -1
- package/dist/mapping.test.d.ts.map +1 -0
- package/dist/mergeDiffs.d.ts +11 -11
- package/dist/mergeDiffs.d.ts.map +1 -0
- package/dist/mergeDiffs.test.d.ts +1 -1
- package/dist/mergeDiffs.test.d.ts.map +1 -0
- package/dist/plugin.d.ts +3 -3
- package/dist/plugin.d.ts.map +1 -0
- package/dist/types.d.ts +141 -141
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -8
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.test.d.ts +1 -1
- package/dist/utils.test.d.ts.map +1 -0
- package/package.json +21 -19
package/dist/completePlugin.d.ts
CHANGED
|
@@ -1,3 +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
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
import { CompletePluginState } from "./types";
|
|
3
|
+
export declare const completePlugin: (apiKey: string, options?: import("./types").DefaultCompleteOptions) => Plugin<CompletePluginState>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completePlugin.d.ts","sourceRoot":"","sources":["../src/completePlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EACL,mBAAmB,EAIpB,MAAM,SAAS,CAAC;AAajB,eAAO,MAAM,cAAc,WACjB,MAAM,oFAkIZ,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
3
|
+
import { Plugin } from "prosemirror-state";
|
|
4
|
+
import { defaultCompleteOptions } from "./defaults";
|
|
5
|
+
import { completeRequest, makeShorterLonger } from "./makeTaksRequest";
|
|
6
|
+
import { OpenAiPromptsWithoutParam, OpenAiPromptsWithParam, Status, } from "./types";
|
|
7
|
+
import { completePluginKey, isCompleteMeta } from "./utils";
|
|
8
|
+
/*
|
|
9
|
+
* idle - initial state, waiting for task
|
|
10
|
+
* new - make request in view
|
|
11
|
+
* streaming - update state in apply method and wait for finished
|
|
12
|
+
* finished - update state in apply method and wait for accepted or rejected
|
|
13
|
+
* accepted - insert/replace text in view and set status to done, also used for clearing an error
|
|
14
|
+
* rejected - set status to done
|
|
15
|
+
* done - used for clearing pluginState, do not use, it is just for internal state management
|
|
16
|
+
* error - whenever an error occurs, this field gets populated so you can display it for the user, use `accepted`* meta to clear it
|
|
17
|
+
*/
|
|
18
|
+
export const completePlugin = (apiKey, options = defaultCompleteOptions) => new Plugin({
|
|
19
|
+
// props: {
|
|
20
|
+
// handleKeyDown(view, event) {
|
|
21
|
+
// const pluginState = completePluginKey.getState(view.state);
|
|
22
|
+
// return (
|
|
23
|
+
// pluginState?.status !== Status.idle &&
|
|
24
|
+
// (event.key === "Enter" || event.key === "Tab")
|
|
25
|
+
// );
|
|
26
|
+
// },
|
|
27
|
+
// },
|
|
28
|
+
key: completePluginKey,
|
|
29
|
+
state: {
|
|
30
|
+
init() {
|
|
31
|
+
return { status: Status.idle };
|
|
32
|
+
},
|
|
33
|
+
apply(tr, pluginState, prevState, state) {
|
|
34
|
+
const meta = tr.getMeta(completePluginKey);
|
|
35
|
+
if (pluginState.status === Status.done ||
|
|
36
|
+
pluginState.status === Status.rejected) {
|
|
37
|
+
return { status: Status.idle };
|
|
38
|
+
}
|
|
39
|
+
if (meta && isCompleteMeta(meta)) {
|
|
40
|
+
if (pluginState.type && meta.type !== pluginState.type) {
|
|
41
|
+
return pluginState;
|
|
42
|
+
}
|
|
43
|
+
return Object.assign(Object.assign({}, pluginState), meta);
|
|
44
|
+
}
|
|
45
|
+
return pluginState;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
view() {
|
|
49
|
+
return {
|
|
50
|
+
update(view, prevState) {
|
|
51
|
+
const pluginState = completePluginKey.getState(view.state);
|
|
52
|
+
/* eslint-disable prefer-destructuring */
|
|
53
|
+
let tr = view.state.tr;
|
|
54
|
+
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.status) === Status.new) {
|
|
55
|
+
switch (pluginState.type) {
|
|
56
|
+
case OpenAiPromptsWithoutParam.Complete:
|
|
57
|
+
completeRequest(pluginState, view, apiKey);
|
|
58
|
+
console.log("complete");
|
|
59
|
+
break;
|
|
60
|
+
case OpenAiPromptsWithoutParam.MakeLonger:
|
|
61
|
+
case OpenAiPromptsWithoutParam.MakeShorter:
|
|
62
|
+
case OpenAiPromptsWithoutParam.Improve:
|
|
63
|
+
case OpenAiPromptsWithoutParam.Simplify:
|
|
64
|
+
case OpenAiPromptsWithoutParam.Explain:
|
|
65
|
+
case OpenAiPromptsWithoutParam.ActionItems:
|
|
66
|
+
case OpenAiPromptsWithParam.Translate:
|
|
67
|
+
case OpenAiPromptsWithParam.ChangeTone:
|
|
68
|
+
makeShorterLonger(pluginState.type, pluginState, view, apiKey, options.maxSelection, pluginState.params);
|
|
69
|
+
console.log("improve selected text");
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.status) === Status.accepted) {
|
|
76
|
+
if (pluginState.error) {
|
|
77
|
+
tr.setMeta(completePluginKey, {
|
|
78
|
+
type: pluginState.type,
|
|
79
|
+
status: Status.done,
|
|
80
|
+
});
|
|
81
|
+
view.dispatch(tr);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
switch (pluginState.type) {
|
|
85
|
+
case OpenAiPromptsWithoutParam.Complete:
|
|
86
|
+
tr = tr.insertText(pluginState.result || "", view.state.doc.nodeSize - 2);
|
|
87
|
+
tr.setMeta(completePluginKey, {
|
|
88
|
+
type: OpenAiPromptsWithoutParam.Complete,
|
|
89
|
+
status: Status.done,
|
|
90
|
+
});
|
|
91
|
+
view.dispatch(tr);
|
|
92
|
+
view.focus();
|
|
93
|
+
console.log("complete accepted V1");
|
|
94
|
+
break;
|
|
95
|
+
case OpenAiPromptsWithoutParam.MakeLonger:
|
|
96
|
+
case OpenAiPromptsWithoutParam.MakeShorter:
|
|
97
|
+
case OpenAiPromptsWithoutParam.Improve:
|
|
98
|
+
case OpenAiPromptsWithoutParam.Simplify:
|
|
99
|
+
case OpenAiPromptsWithoutParam.Explain:
|
|
100
|
+
case OpenAiPromptsWithoutParam.ActionItems:
|
|
101
|
+
if (pluginState.selection && pluginState.result) {
|
|
102
|
+
const content = pluginState.result;
|
|
103
|
+
const paragraphs = content.split("\n\n");
|
|
104
|
+
const paragraphNodes = paragraphs.map((paragraph) => view.state.schema.node("paragraph", null, view.state.schema.text(paragraph)));
|
|
105
|
+
const fragment = Fragment.fromArray(paragraphNodes);
|
|
106
|
+
tr.selection.replace(tr, new Slice(fragment, 0, 0));
|
|
107
|
+
}
|
|
108
|
+
tr.setMeta(completePluginKey, {
|
|
109
|
+
type: pluginState.type,
|
|
110
|
+
status: Status.done,
|
|
111
|
+
});
|
|
112
|
+
view.dispatch(tr);
|
|
113
|
+
view.focus();
|
|
114
|
+
console.log("makeShorterLonger acceptedV1");
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Decoration, EditorView } from "prosemirror-view";
|
|
2
|
-
export declare const createUpdatePopup: (view: EditorView, decoration: Decoration, pos: number, applySuggestion: (view: EditorView, decoration: Decoration) => void, discardSuggestion: (view: EditorView, decoration: Decoration) => void) => HTMLDivElement;
|
|
1
|
+
import { Decoration, EditorView } from "prosemirror-view";
|
|
2
|
+
export declare const createUpdatePopup: (view: EditorView, decoration: Decoration, pos: number, applySuggestion: (view: EditorView, decoration: Decoration) => void, discardSuggestion: (view: EditorView, decoration: Decoration) => void) => HTMLDivElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUpdatePopup.d.ts","sourceRoot":"","sources":["../src/createUpdatePopup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI1D,eAAO,MAAM,iBAAiB,SACtB,UAAU,cACJ,UAAU,OACjB,MAAM,0BACa,UAAU,cAAc,UAAU,KAAK,IAAI,4BACzC,UAAU,cAAc,UAAU,KAAK,IAAI,mBAkCtE,CAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DefaultCompleteOptions, GrammarSuggestPluginOptions } from "./types";
|
|
2
|
-
export declare const defaultOptions: GrammarSuggestPluginOptions;
|
|
3
|
-
export declare const defaultCompleteOptions: DefaultCompleteOptions;
|
|
1
|
+
import { DefaultCompleteOptions, GrammarSuggestPluginOptions } from "./types";
|
|
2
|
+
export declare const defaultOptions: GrammarSuggestPluginOptions;
|
|
3
|
+
export declare const defaultCompleteOptions: DefaultCompleteOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAG9E,eAAO,MAAM,cAAc,EAAE,2BAI5B,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAEpC,CAAC"}
|
package/dist/eventHandlers.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EditorView } from "prosemirror-view";
|
|
2
|
-
import { EditorState, Transaction } from "prosemirror-state";
|
|
3
|
-
import { AcceptSuggestionMeta, DiscardSuggestionMeta, GrammarSuggestPluginOptions, GrammarSuggestPluginState, OpenSuggestionMeta, UpdateSuggestionMeta } from "./types";
|
|
4
|
-
export declare const handleUpdate: (pluginState: GrammarSuggestPluginState, meta: UpdateSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
5
|
-
export declare const handleAccept: (pluginState: GrammarSuggestPluginState, meta: AcceptSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
6
|
-
export declare const handleDocChange: (pluginState: GrammarSuggestPluginState, tr: Transaction, oldState: EditorState, withYjs: boolean) => GrammarSuggestPluginState;
|
|
7
|
-
export declare const handleOpenSuggestion: (pluginState: GrammarSuggestPluginState, meta: OpenSuggestionMeta, tr: Transaction, options: GrammarSuggestPluginOptions) => GrammarSuggestPluginState;
|
|
8
|
-
export declare const handleClick: (view: EditorView, pos: number) => boolean;
|
|
9
|
-
export declare const handleDiscardSuggestion: (pluginState: GrammarSuggestPluginState, meta: DiscardSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
1
|
+
import { EditorView } from "prosemirror-view";
|
|
2
|
+
import { EditorState, Transaction } from "prosemirror-state";
|
|
3
|
+
import { AcceptSuggestionMeta, DiscardSuggestionMeta, GrammarSuggestPluginOptions, GrammarSuggestPluginState, OpenSuggestionMeta, UpdateSuggestionMeta } from "./types";
|
|
4
|
+
export declare const handleUpdate: (pluginState: GrammarSuggestPluginState, meta: UpdateSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
5
|
+
export declare const handleAccept: (pluginState: GrammarSuggestPluginState, meta: AcceptSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
6
|
+
export declare const handleDocChange: (pluginState: GrammarSuggestPluginState, tr: Transaction, oldState: EditorState, withYjs: boolean) => GrammarSuggestPluginState;
|
|
7
|
+
export declare const handleOpenSuggestion: (pluginState: GrammarSuggestPluginState, meta: OpenSuggestionMeta, tr: Transaction, options: GrammarSuggestPluginOptions) => GrammarSuggestPluginState;
|
|
8
|
+
export declare const handleClick: (view: EditorView, pos: number) => boolean;
|
|
9
|
+
export declare const handleDiscardSuggestion: (pluginState: GrammarSuggestPluginState, meta: DiscardSuggestionMeta, tr: Transaction) => GrammarSuggestPluginState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventHandlers.d.ts","sourceRoot":"","sources":["../src/eventHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG7D,OAAO,EACL,oBAAoB,EAEpB,qBAAqB,EAGrB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAElB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AASjB,eAAO,MAAM,YAAY,gBACV,yBAAyB,QAChC,oBAAoB,MACtB,WAAW,KACd,yBAwCF,CAAC;AAEF,eAAO,MAAM,YAAY,gBACV,yBAAyB,QAChC,oBAAoB,MACtB,WAAW,KACd,yBAcF,CAAC;AAEF,eAAO,MAAM,eAAe,gBACb,yBAAyB,MAClC,WAAW,YACL,WAAW,WACZ,OAAO,KACf,yBAoCF,CAAC;AAiCF,eAAO,MAAM,oBAAoB,gBAClB,yBAAyB,QAChC,kBAAkB,MACpB,WAAW,WACN,2BAA2B,KACnC,yBAuBF,CAAC;AAEF,eAAO,MAAM,WAAW,SAAU,UAAU,OAAO,MAAM,YAsBxD,CAAC;AAEF,eAAO,MAAM,uBAAuB,gBACrB,yBAAyB,QAChC,qBAAqB,MACvB,WAAW,KACd,yBAYF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { grammarSuggestPlugin } from "./plugin";
|
|
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";
|
|
1
|
+
export { grammarSuggestPlugin } from "./plugin";
|
|
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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,MAAM,EACN,aAAa,EACb,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,sBAAsB,EACtB,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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{__awaiter as s}from"tslib";import i from"lodash.debounce";import{StepMap as a,Mapping as c}from"prosemirror-transform";import{Fragment as l,Slice as d}from"prosemirror-model";var p,g,u,m,h,f,x;!function(e){e.suggestionUpdate="suggestionUpdate",e.acceptSuggestion="acceptSuggestion",e.openSuggestion="openSuggestion",e.closeSuggestion="closeSuggestion",e.discardSuggestion="discardSuggestion"}(p||(p={})),function(e){e.grammarSuggestPopup="grammar-suggest-popup"}(g||(g={})),function(e){e.Casual="Casual",e.Confident="Confident",e.Straightforward="Straightforward",e.Friendly="Friendly"}(u||(u={})),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"}(m||(m={})),function(e){e.Complete="Complete",e.Improve="Improve",e.MakeLonger="MakeLonger",e.MakeShorter="MakeShorter",e.Simplify="Simplify",e.Explain="Explain",e.ActionItems="ActionItems"}(h||(h={})),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"}(x||(x={}));const v=new e("completePlugin"),S=new e("grammarSuggestPlugin"),y=e=>{let t="";return e.descendants(((e,n)=>{e.isText&&(t+=`${e.text}\n`)})),t},w=(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}},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)=>s(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=S.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:p.acceptSuggestion,id:t.spec.id},c=e.state.tr.insertText(r,s,i).setMeta(S,a);e.dispatch(c)},L=(e,t)=>{const{spec:n}=t,o={type:p.discardSuggestion,id:n.id},r=e.state.tr.setMeta(S,o);e.dispatch(r)},k=(e,t)=>{const n=S.getState(e.state);if(!n)return!1;const{decorations:o}=n,r=o.find(t,t)[0];if(!r){const t={type:p.closeSuggestion};return e.dispatch(e.state.tr.setMeta(S,t)),!1}const s=n.popupDecoration.find()[0];if((null==s?void 0:s.spec.id)===r.spec.id)return!1;const i={type:p.openSuggestion,decoration:r};return e.dispatch(e.state.tr.setMeta(S,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=g.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},I={maxSelection:1e3},A=(e,r=D)=>{let s=!1;return new t({key:S,state:{init:()=>({lastText:"",decorations:o.empty,popupDecoration:o.empty}),apply(e,t,s,i){const l=e.getMeta(S);return(null==l?void 0:l.type)===p.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)===p.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)===p.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)===p.closeSuggestion?Object.assign(Object.assign({},t),{popupDecoration:o.empty}):(null==l?void 0:l.type)===p.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:i}=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 a(o&&e?[e,o.a-e,o.b-e]:[0,0,0]);l=new c([r])}const d=w(r,s),p=e.decorations.map(l,t.doc),g=T(d.start,i),u=T(d.end,i),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=S.getState(e);if(!t)return null;const n=v.getState(e);return(null==n?void 0:n.status)!==x.idle?t.decorations:t.decorations.add(e.doc,t.popupDecoration.find())}},view(){const t=((e,t)=>i((e=>{var n;const o=b(e.state.doc),r=(null===(n=S.getState(e.state))||void 0===n?void 0:n.lastText)||"",s=w(r,o.text);C(t,s.newText).then((t=>{if(y(e.state.doc)!==o.text)return;const n={type:p.suggestionUpdate,fix:t,changedRegion:s,mapping:o.mapping,text:o.text};e.dispatch(e.state.tr.setMeta(S,n))})).catch((e=>{console.error("Grammar suggest API error",e)}))}),e.debounceMs))(r,e);return{update(e,n){const o=S.getState(e.state);e.state.doc.textBetween(0,e.state.doc.nodeSize-2,"/n")===n.doc.textBetween(0,n.doc.nodeSize-2,"/n")&&s||!o||o.lastText===y(e.state.doc)||(s=!0,t(e))}}}})},R=(e,t,n,o,r,i,a)=>s(void 0,void 0,void 0,(function*(){var e;let n="";try{const c=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:a}})})).body)||void 0===e?void 0:e.getReader(),l=({done:e,value:t})=>s(void 0,void 0,void 0,(function*(){if(e)return;const s=(new TextDecoder).decode(t);try{n+=s,console.log({res:n,chunk:s}),o.dispatch(o.state.tr.setMeta(v,Object.assign({type:r,status:x.streaming,result:n},i&&{selection:i})))}catch(e){console.error("Could not parse stream message",s,e)}return null==c?void 0:c.read().then(l)}));yield null==c?void 0:c.read().then(l),o.dispatch(o.state.tr.setMeta(v,Object.assign({type:r,status:x.finished,result:n},i&&{selection:i})))}catch(e){console.error("Error:",e)}})),N=(e,n=I)=>new t({key:v,state:{init:()=>({status:x.idle}),apply(e,t,n,o){const r=e.getMeta(v);return t.status===x.done||t.status===x.rejected?{status:x.idle}:r&&(e=>Object.values(f).includes(e.type)||Object.values(h).includes(e.type))(r)?t.type&&r.type!==t.type?t:Object.assign(Object.assign({},t),r):t}},view:()=>({update(e,t){const o=v.getState(e.state);let r=e.state.tr;if((null==o?void 0:o.status)===x.new)switch(o.type){case h.Complete:((e,t,n)=>{s(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,h.Complete)}))})(0,e),console.log("complete");break;case h.MakeLonger:case h.MakeShorter:case h.Improve:case h.Simplify:case h.Explain:case h.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(v,{task:e,status:x.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(v,{type:e,status:x.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)===x.accepted){if(o.error)return r.setMeta(v,{type:o.type,status:x.done}),void e.dispatch(r);switch(o.type){case h.Complete:r=r.insertText(o.result||"",e.state.doc.nodeSize-2),r.setMeta(v,{type:h.Complete,status:x.done}),e.dispatch(r),e.focus(),console.log("complete accepted V1");break;case h.MakeLonger:case h.MakeShorter:case h.Improve:case h.Simplify:case h.Explain:case h.ActionItems:if(o.selection&&o.result){const t=o.result.split("\n\n").map((t=>e.state.schema.node("paragraph",null,e.state.schema.text(t)))),n=l.fromArray(t);r.selection.replace(r,new d(n,0,0))}r.setMeta(v,{type:o.type,status:x.done}),e.dispatch(r),e.focus(),console.log("makeShorterLonger acceptedV1")}}}})});export{u as MoodParamType,f as OpenAiPromptsWithParam,h as OpenAiPromptsWithoutParam,x as Status,m as TranslationTargetLanguage,N as completePlugin,v as completePluginKey,I as defaultCompleteOptions,D as defaultOptions,A as grammarSuggestPlugin};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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))}}}})};
|
|
1
|
+
"use strict";var t,e,o,n,r,s,a,i=require("prosemirror-state"),p=require("prosemirror-view"),c=require("fast-diff"),l=require("tslib"),d=require("lodash.debounce"),u=require("prosemirror-transform"),g=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 m=new i.PluginKey("completePlugin"),h=new i.PluginKey("grammarSuggestPlugin"),x=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=c(t,e),n=o[0],r=n[0]===c.EQUAL?n[1].length-1:0,s=((t,e)=>{if(e[e.length-1][0]!==c.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===c.EQUAL&&(n+=o.length),e===c.DELETE&&(n+=o.length)}return n})(t,o),a=t.lastIndexOf("\n",r),i=t.indexOf("\n",s),p=-1===a?0:a+1,l=-1===i?t.length:i,d=t.slice(p,l),u=e.slice(p,e.length-(t.length-l));return{start:p,end:p+u.length,oldStart:p,oldEnd:l,oldText:d,newText:u}},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)=>l.__awaiter(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 c.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 c.DELETE:const r={from:e,to:e+o.length,original:o,replacement:""};return e+=o.length,[r];case c.INSERT:return[{from:e,to:e,original:"",replacement:o}]}})).flat()})(c(t,e));return w(w(o))},A=(e,o)=>{var n;const r=null===(n=h.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,p={type:t.acceptSuggestion,id:o.spec.id},c=e.state.tr.insertText(s,a,i).setMeta(h,p);e.dispatch(c)},j=(e,o)=>{const{spec:n}=o,r={type:t.discardSuggestion,id:n.id},s=e.state.tr.setMeta(h,r);e.dispatch(s)},b=(e,o)=>{const n=h.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(h,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(h,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,p=t.dom.getBoundingClientRect();a.id=e.grammarSuggestPopup;const c=t.coordsAtPos(n);a.style.left=c.left-p.left+"px",a.style.top=c.bottom-p.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)=>l.__awaiter(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(),p=({done:t,value:e})=>l.__awaiter(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(m,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(p)}));yield null==i?void 0:i.read().then(p),n.dispatch(n.state.tr.setMeta(m,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:m,state:{init:()=>({status:exports.Status.idle}),apply(t,e,o,n){const r=t.getMeta(m);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=m.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)=>{l.__awaiter(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(m,{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(m,{type:t,status:exports.Status.error,error:"Selection is too big"}));const p=o.state.doc.textBetween(a.from,a.to,"\n");W(0,p,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(m,{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(m,{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=n.result.split("\n\n").map((e=>t.state.schema.node("paragraph",null,t.state.schema.text(e)))),o=g.Fragment.fromArray(e);r.selection.replace(r,new g.Slice(o,0,0))}r.setMeta(m,{type:n.type,status:exports.Status.done}),t.dispatch(r),t.focus(),console.log("makeShorterLonger acceptedV1")}}}})}),exports.completePluginKey=m,exports.defaultCompleteOptions=C,exports.defaultOptions=M,exports.grammarSuggestPlugin=(e,o=M)=>{let n=!1;return new i.Plugin({key:h,state:{init:()=>({lastText:"",decorations:p.DecorationSet.empty,popupDecoration:p.DecorationSet.empty}),apply(e,n,r,s){const a=e.getMeta(h);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),c={text:r.endsWith("\n")?r.slice(0,-1):r,originalText:o,id:{}};return p.Decoration.inline(a,i,{class:"grammarSuggestion "+(""===r?"removalSuggestion":"")},c)}));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:x(o.doc),decorations:n.map(o.mapping,o.doc),popupDecoration:p.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:p.DecorationSet.create(o.doc,[p.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:p.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:p.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 u.StepMap([t,n.a-t,n.b-t]):new u.StepMap([0,0,0]);i=new u.Mapping([r])}const p=f(r,s),c=t.decorations.map(i,e.doc),l=v(p.start,a),d=v(p.end,a),g=t.popupDecoration.map(i,e.doc);return Object.assign(Object.assign({},t),{decorations:c.remove(c.find(l,d)),popupDecoration:g.remove(g.find(l,d))})})(n,e,r,o.withYjs):n}},props:{handleClick:b,decorations:t=>{const e=h.getState(t);if(!e)return null;const o=m.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)=>d((e=>{var n;const r=S(e.state.doc),s=(null===(n=h.getState(e.state))||void 0===n?void 0:n.lastText)||"",a=f(s,r.text);y(o,a.newText).then((o=>{if(x(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(h,n))})).catch((t=>{console.error("Grammar suggest API error",t)}))}),e.debounceMs))(o,e);return{update(t,e){const o=h.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===x(t.state.doc)||(n=!0,r(t))}}}})};
|
package/dist/makeRequest.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare const createMakeRequest: (options: GrammarSuggestPluginOptions, apiKey: string) => import("lodash").DebouncedFunc<(view: EditorView) => void>;
|
|
1
|
+
import { EditorView } from "prosemirror-view";
|
|
2
|
+
import { GrammarSuggestPluginOptions } from "./types";
|
|
3
|
+
export declare const createMakeRequest: (options: GrammarSuggestPluginOptions, apiKey: string) => (view: EditorView) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRequest.d.ts","sourceRoot":"","sources":["../src/makeRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAM9C,OAAO,EAGL,2BAA2B,EAE5B,MAAM,SAAS,CAAC;AAgEjB,eAAO,MAAM,iBAAiB,YACnB,2BAA2B,UAC5B,MAAM,YACN,UAAU,KAAG,IAiCC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import debounce from "lodash.debounce";
|
|
11
|
+
import { getChangedRegions, getTextWithNewlines, grammarSuggestPluginKey, } from "./utils";
|
|
12
|
+
import { GrammarSuggestMetaType, } from "./types";
|
|
13
|
+
import { docToTextWithMapping } from "./mapping";
|
|
14
|
+
const isJsonString = (str) => {
|
|
15
|
+
try {
|
|
16
|
+
JSON.parse(str);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const myApiRequest = (apiKey, text) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const input = [...text.split("\n")];
|
|
25
|
+
return fetch("https://prosemirror-ai-plugin.web.app/api/suggestion", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
cache: "no-cache",
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
Authorization: `Bearer ${apiKey}`,
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
model: "gpt-3.5-turbo",
|
|
34
|
+
modelParams: {
|
|
35
|
+
input,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
})
|
|
39
|
+
.then((response) => {
|
|
40
|
+
if (response.ok) {
|
|
41
|
+
return response.json();
|
|
42
|
+
}
|
|
43
|
+
return Promise.reject(response);
|
|
44
|
+
})
|
|
45
|
+
.then((jsonData) => {
|
|
46
|
+
if (!jsonData || !jsonData.some((i) => isJsonString(i))) {
|
|
47
|
+
return {
|
|
48
|
+
fixed: false,
|
|
49
|
+
result: text,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
result: jsonData
|
|
54
|
+
.map((data) => JSON.parse(data).result)
|
|
55
|
+
.join("\n"),
|
|
56
|
+
fixed: true,
|
|
57
|
+
};
|
|
58
|
+
})
|
|
59
|
+
.catch((e) => {
|
|
60
|
+
e.text().then((text) => {
|
|
61
|
+
console.error({ status: e.status, text });
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
fixed: false,
|
|
65
|
+
result: text,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
export const createMakeRequest = (options, apiKey) => debounce((view) => {
|
|
70
|
+
var _a;
|
|
71
|
+
// The document changed, start API request
|
|
72
|
+
const versionAtRequestStart = docToTextWithMapping(view.state.doc);
|
|
73
|
+
const oldText = ((_a = grammarSuggestPluginKey.getState(view.state)) === null || _a === void 0 ? void 0 : _a.lastText) || "";
|
|
74
|
+
const changedRegion = getChangedRegions(oldText, versionAtRequestStart.text);
|
|
75
|
+
myApiRequest(apiKey, changedRegion.newText)
|
|
76
|
+
.then((fix) => {
|
|
77
|
+
// Check if the document version has changed while we were waiting
|
|
78
|
+
if (getTextWithNewlines(view.state.doc) !== versionAtRequestStart.text) {
|
|
79
|
+
// The state changed, abort
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// State did not change, update the plugin state
|
|
83
|
+
const meta = {
|
|
84
|
+
type: GrammarSuggestMetaType.suggestionUpdate,
|
|
85
|
+
fix,
|
|
86
|
+
changedRegion,
|
|
87
|
+
mapping: versionAtRequestStart.mapping,
|
|
88
|
+
text: versionAtRequestStart.text,
|
|
89
|
+
};
|
|
90
|
+
view.dispatch(view.state.tr.setMeta(grammarSuggestPluginKey, meta));
|
|
91
|
+
})
|
|
92
|
+
.catch((error) => {
|
|
93
|
+
console.error("Grammar suggest API error", error);
|
|
94
|
+
});
|
|
95
|
+
}, options.debounceMs);
|
|
@@ -1,4 +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;
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeTaksRequest.d.ts","sourceRoot":"","sources":["../src/makeTaksRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EACL,mBAAmB,EACnB,UAAU,EAGV,QAAQ,EACR,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAwEjB,eAAO,MAAM,eAAe,gBACb,mBAAmB,QAC1B,UAAU,UACR,MAAM,kBAmBf,CAAC;AAEF,eAAO,MAAM,iBAAiB,SACtB,QAAQ,eACD,mBAAmB,QAC1B,UAAU,UACR,MAAM,gBACA,MAAM,WACX,UAAU,GAAG,iBAAiB,SA+BxC,CAAC"}
|
package/dist/mapping.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Node } from "prosemirror-model";
|
|
2
|
-
import { TextMappingItem } from "./types";
|
|
3
|
-
export declare const docToTextWithMapping: (doc: Node) => {
|
|
4
|
-
text: string;
|
|
5
|
-
mapping: TextMappingItem[];
|
|
6
|
-
};
|
|
7
|
-
export declare const textPosToDocPos: (textPos: number, mapping: TextMappingItem[]) => number;
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { TextMappingItem } from "./types";
|
|
3
|
+
export declare const docToTextWithMapping: (doc: Node) => {
|
|
4
|
+
text: string;
|
|
5
|
+
mapping: TextMappingItem[];
|
|
6
|
+
};
|
|
7
|
+
export declare const textPosToDocPos: (textPos: number, mapping: TextMappingItem[]) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI1C,eAAO,MAAM,oBAAoB,QAC1B,IAAI;UACA,MAAM;aAAW,eAAe,EAAE;CAU5C,CAAC;AACF,eAAO,MAAM,eAAe,YACjB,MAAM,WACN,eAAe,EAAE,WAa3B,CAAC"}
|
package/dist/mapping.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.test.d.ts","sourceRoot":"","sources":["../src/mapping.test.ts"],"names":[],"mappings":""}
|
package/dist/mergeDiffs.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import diff from "fast-diff";
|
|
2
|
-
export interface Replace {
|
|
3
|
-
from: number;
|
|
4
|
-
to: number;
|
|
5
|
-
original: string;
|
|
6
|
-
replacement: string;
|
|
7
|
-
}
|
|
8
|
-
export declare const isIdentity: (replace: Replace) => boolean;
|
|
9
|
-
export declare const convertDiffToReplaceSet: (diffSet: diff.Diff[]) => Replace[];
|
|
10
|
-
export declare const mergeReplacePair: (leftReplace: Replace, rightReplace: Replace) => Replace[];
|
|
11
|
-
export declare const getDiff: (original: string, fixed: string) => Replace[];
|
|
1
|
+
import diff from "fast-diff";
|
|
2
|
+
export interface Replace {
|
|
3
|
+
from: number;
|
|
4
|
+
to: number;
|
|
5
|
+
original: string;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const isIdentity: (replace: Replace) => boolean;
|
|
9
|
+
export declare const convertDiffToReplaceSet: (diffSet: diff.Diff[]) => Replace[];
|
|
10
|
+
export declare const mergeReplacePair: (leftReplace: Replace, rightReplace: Replace) => Replace[];
|
|
11
|
+
export declare const getDiff: (original: string, fixed: string) => Replace[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeDiffs.d.ts","sourceRoot":"","sources":["../src/mergeDiffs.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,YAAa,OAAO,YACD,CAAC;AAE3C,eAAO,MAAM,uBAAuB,YAAa,KAAK,IAAI,EAAE,KAAG,OAAO,EAyDrE,CAAC;AAEF,eAAO,MAAM,gBAAgB,gBACd,OAAO,gBACN,OAAO,KACpB,OAAO,EA8FT,CAAC;AAYF,eAAO,MAAM,OAAO,aAAc,MAAM,SAAS,MAAM,cAItD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeDiffs.test.d.ts","sourceRoot":"","sources":["../src/mergeDiffs.test.ts"],"names":[],"mappings":""}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Plugin } from "prosemirror-state";
|
|
2
|
-
import { GrammarSuggestPluginOptions, GrammarSuggestPluginState } from "./types";
|
|
3
|
-
export declare const grammarSuggestPlugin: (apiKey: string, options?: GrammarSuggestPluginOptions) => Plugin<GrammarSuggestPluginState>;
|
|
1
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
import { GrammarSuggestPluginOptions, GrammarSuggestPluginState } from "./types";
|
|
3
|
+
export declare const grammarSuggestPlugin: (apiKey: string, options?: GrammarSuggestPluginOptions) => Plugin<GrammarSuggestPluginState>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAO3C,OAAO,EAIL,2BAA2B,EAC3B,yBAAyB,EAE1B,MAAM,SAAS,CAAC;AAajB,eAAO,MAAM,oBAAoB,WACvB,MAAM,YACL,2BAA2B,sCA6ErC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
2
|
-
import { TextSelection } from "prosemirror-state";
|
|
3
|
-
export type TextMappingItem = {
|
|
4
|
-
docPos: number;
|
|
5
|
-
textPos: number;
|
|
6
|
-
};
|
|
7
|
-
export interface ChangedRegion {
|
|
8
|
-
oldStart: number;
|
|
9
|
-
oldEnd: number;
|
|
10
|
-
start: number;
|
|
11
|
-
end: number;
|
|
12
|
-
oldText: string;
|
|
13
|
-
newText: string;
|
|
14
|
-
}
|
|
15
|
-
export type GrammarSuggestPluginState = {
|
|
16
|
-
lastText?: string;
|
|
17
|
-
timer?: number;
|
|
18
|
-
decorations: DecorationSet;
|
|
19
|
-
popupDecoration: DecorationSet;
|
|
20
|
-
currentSuggestionId?: object;
|
|
21
|
-
};
|
|
22
|
-
export type GrammarSuggestPluginOptions = {
|
|
23
|
-
debounceMs: number;
|
|
24
|
-
createUpdatePopup: (view: EditorView, decoration: Decoration, pos: number, applySuggestion: (view: EditorView, decoration: Decoration) => void, discardSuggestion: (view: EditorView, decoration: Decoration) => void) => HTMLElement;
|
|
25
|
-
withYjs: boolean;
|
|
26
|
-
};
|
|
27
|
-
export declare enum GrammarSuggestMetaType {
|
|
28
|
-
suggestionUpdate = "suggestionUpdate",
|
|
29
|
-
acceptSuggestion = "acceptSuggestion",
|
|
30
|
-
openSuggestion = "openSuggestion",
|
|
31
|
-
closeSuggestion = "closeSuggestion",
|
|
32
|
-
discardSuggestion = "discardSuggestion"
|
|
33
|
-
}
|
|
34
|
-
export interface AcceptSuggestionMeta {
|
|
35
|
-
type: GrammarSuggestMetaType.acceptSuggestion;
|
|
36
|
-
id: object;
|
|
37
|
-
}
|
|
38
|
-
export type FixMistakeResultData = {
|
|
39
|
-
result: string;
|
|
40
|
-
fixed: boolean;
|
|
41
|
-
mod?: {
|
|
42
|
-
original: string;
|
|
43
|
-
fixed: string;
|
|
44
|
-
position: number;
|
|
45
|
-
type: string;
|
|
46
|
-
}[];
|
|
47
|
-
};
|
|
48
|
-
export interface UpdateSuggestionMeta {
|
|
49
|
-
type: GrammarSuggestMetaType.suggestionUpdate;
|
|
50
|
-
fix: FixMistakeResultData;
|
|
51
|
-
changedRegion: ChangedRegion;
|
|
52
|
-
mapping: TextMappingItem[];
|
|
53
|
-
text: string;
|
|
54
|
-
}
|
|
55
|
-
export interface OpenSuggestionMeta {
|
|
56
|
-
type: GrammarSuggestMetaType.openSuggestion;
|
|
57
|
-
decoration: Decoration;
|
|
58
|
-
}
|
|
59
|
-
export interface DiscardSuggestionMeta {
|
|
60
|
-
type: GrammarSuggestMetaType.discardSuggestion;
|
|
61
|
-
id: object;
|
|
62
|
-
}
|
|
63
|
-
export interface CloseSuggestionMeta {
|
|
64
|
-
type: GrammarSuggestMetaType.closeSuggestion;
|
|
65
|
-
}
|
|
66
|
-
export type GrammarPluginMeta = UpdateSuggestionMeta | AcceptSuggestionMeta | OpenSuggestionMeta | CloseSuggestionMeta | DiscardSuggestionMeta;
|
|
67
|
-
export type GrammarSuggestDecorationSpec = {
|
|
68
|
-
originalText: string;
|
|
69
|
-
text: string;
|
|
70
|
-
id: object;
|
|
71
|
-
};
|
|
72
|
-
export type PopupDecorationSpec = {
|
|
73
|
-
id: object;
|
|
74
|
-
};
|
|
75
|
-
export declare enum GrammarSuggestElementClass {
|
|
76
|
-
grammarSuggestPopup = "grammar-suggest-popup"
|
|
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
|
-
}
|
|
1
|
+
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
2
|
+
import { TextSelection } from "prosemirror-state";
|
|
3
|
+
export type TextMappingItem = {
|
|
4
|
+
docPos: number;
|
|
5
|
+
textPos: number;
|
|
6
|
+
};
|
|
7
|
+
export interface ChangedRegion {
|
|
8
|
+
oldStart: number;
|
|
9
|
+
oldEnd: number;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
oldText: string;
|
|
13
|
+
newText: string;
|
|
14
|
+
}
|
|
15
|
+
export type GrammarSuggestPluginState = {
|
|
16
|
+
lastText?: string;
|
|
17
|
+
timer?: number;
|
|
18
|
+
decorations: DecorationSet;
|
|
19
|
+
popupDecoration: DecorationSet;
|
|
20
|
+
currentSuggestionId?: object;
|
|
21
|
+
};
|
|
22
|
+
export type GrammarSuggestPluginOptions = {
|
|
23
|
+
debounceMs: number;
|
|
24
|
+
createUpdatePopup: (view: EditorView, decoration: Decoration, pos: number, applySuggestion: (view: EditorView, decoration: Decoration) => void, discardSuggestion: (view: EditorView, decoration: Decoration) => void) => HTMLElement;
|
|
25
|
+
withYjs: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare enum GrammarSuggestMetaType {
|
|
28
|
+
suggestionUpdate = "suggestionUpdate",
|
|
29
|
+
acceptSuggestion = "acceptSuggestion",
|
|
30
|
+
openSuggestion = "openSuggestion",
|
|
31
|
+
closeSuggestion = "closeSuggestion",
|
|
32
|
+
discardSuggestion = "discardSuggestion"
|
|
33
|
+
}
|
|
34
|
+
export interface AcceptSuggestionMeta {
|
|
35
|
+
type: GrammarSuggestMetaType.acceptSuggestion;
|
|
36
|
+
id: object;
|
|
37
|
+
}
|
|
38
|
+
export type FixMistakeResultData = {
|
|
39
|
+
result: string;
|
|
40
|
+
fixed: boolean;
|
|
41
|
+
mod?: {
|
|
42
|
+
original: string;
|
|
43
|
+
fixed: string;
|
|
44
|
+
position: number;
|
|
45
|
+
type: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
export interface UpdateSuggestionMeta {
|
|
49
|
+
type: GrammarSuggestMetaType.suggestionUpdate;
|
|
50
|
+
fix: FixMistakeResultData;
|
|
51
|
+
changedRegion: ChangedRegion;
|
|
52
|
+
mapping: TextMappingItem[];
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
55
|
+
export interface OpenSuggestionMeta {
|
|
56
|
+
type: GrammarSuggestMetaType.openSuggestion;
|
|
57
|
+
decoration: Decoration;
|
|
58
|
+
}
|
|
59
|
+
export interface DiscardSuggestionMeta {
|
|
60
|
+
type: GrammarSuggestMetaType.discardSuggestion;
|
|
61
|
+
id: object;
|
|
62
|
+
}
|
|
63
|
+
export interface CloseSuggestionMeta {
|
|
64
|
+
type: GrammarSuggestMetaType.closeSuggestion;
|
|
65
|
+
}
|
|
66
|
+
export type GrammarPluginMeta = UpdateSuggestionMeta | AcceptSuggestionMeta | OpenSuggestionMeta | CloseSuggestionMeta | DiscardSuggestionMeta;
|
|
67
|
+
export type GrammarSuggestDecorationSpec = {
|
|
68
|
+
originalText: string;
|
|
69
|
+
text: string;
|
|
70
|
+
id: object;
|
|
71
|
+
};
|
|
72
|
+
export type PopupDecorationSpec = {
|
|
73
|
+
id: object;
|
|
74
|
+
};
|
|
75
|
+
export declare enum GrammarSuggestElementClass {
|
|
76
|
+
grammarSuggestPopup = "grammar-suggest-popup"
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,aAAa,CAAC;IAC3B,eAAe,EAAE,aAAa,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,CACjB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,MAAM,EACX,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,KAAK,IAAI,EACnE,iBAAiB,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,KAAK,IAAI,KAClE,WAAW,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,sBAAsB;IAChC,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,iBAAiB,sBAAsB;CACxC;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,sBAAsB,CAAC,gBAAgB,CAAC;IAC9C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,sBAAsB,CAAC,gBAAgB,CAAC;IAC9C,GAAG,EAAE,oBAAoB,CAAC;IAC1B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,sBAAsB,CAAC,cAAc,CAAC;IAC5C,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,sBAAsB,CAAC,iBAAiB,CAAC;IAC/C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,sBAAsB,CAAC,eAAe,CAAC;CAC9C;AAED,MAAM,MAAM,iBAAiB,GACzB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,mBAAmB,GACnB,qBAAqB,CAAC;AAE1B,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,oBAAY,0BAA0B;IACpC,mBAAmB,0BAA0B;CAC9C;AAED,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,eAAe,oBAAoB;IACnC,QAAQ,aAAa;CACtB;AAED,oBAAY,yBAAyB;IACnC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,cAAc,EAAE,yBAAyB,CAAA;CAAE,CAAC;AAC9E,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AACjD,oBAAY,yBAAyB;IACnC,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,sBAAsB;IAChC,UAAU,eAAe;IACzB,SAAS,cAAc;CACxB;AAED,MAAM,MAAM,QAAQ,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;AAE1E,oBAAY,MAAM;IAChB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;CACxD;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PluginKey } from "prosemirror-state";
|
|
2
|
-
import { Node } from "prosemirror-model";
|
|
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;
|
|
6
|
-
export declare const grammarSuggestPluginKey: PluginKey<GrammarSuggestPluginState>;
|
|
7
|
-
export declare const getTextWithNewlines: (node: Node) => string;
|
|
8
|
-
export declare const getChangedRegions: (oldText: string, newText: string) => ChangedRegion;
|
|
1
|
+
import { PluginKey } from "prosemirror-state";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
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;
|
|
6
|
+
export declare const grammarSuggestPluginKey: PluginKey<GrammarSuggestPluginState>;
|
|
7
|
+
export declare const getTextWithNewlines: (node: Node) => string;
|
|
8
|
+
export declare const getChangedRegions: (oldText: string, newText: string) => ChangedRegion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,yBAAyB,EAGzB,QAAQ,EACT,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,iBAAiB,gCAE7B,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,GAAG,qBAKvC,CAAC;AAEF,eAAO,MAAM,uBAAuB,sCAEnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,IAAI,WAQ7C,CAAC;AAuBF,eAAO,MAAM,iBAAiB,YACnB,MAAM,WACN,MAAM,KACd,aAkDF,CAAC"}
|
package/dist/utils.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-suggestcat-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"prebuild": "rimraf dist",
|
|
10
|
-
"build": "rollup -c --bundleConfigAsCjs",
|
|
11
|
-
"dev": "rollup -c -w --bundleConfigAsCjs",
|
|
12
|
-
"format": "eslint src --ext .ts --fix",
|
|
13
|
-
"prepublishOnly": "npm run build && npm run lint",
|
|
14
|
-
"version": "npm run format && git add -A src",
|
|
15
|
-
"postversion": "git push && git push --tags",
|
|
16
|
-
"lint": "tsc --noEmit && eslint src --ext .ts",
|
|
17
|
-
"test": "jest",
|
|
18
|
-
"upgrade-interactive": "npm-check --update",
|
|
19
|
-
"publish:np": "np"
|
|
20
|
-
},
|
|
21
8
|
"repository": {
|
|
22
9
|
"type": "git",
|
|
23
10
|
"url": "git+https://github.com/emergence-engineering/prosemirror-suggestcat-plugin.git"
|
|
@@ -40,11 +27,12 @@
|
|
|
40
27
|
"eslint-plugin-prettier": "^4.2.1",
|
|
41
28
|
"fast-diff": "^1.3.0",
|
|
42
29
|
"lodash.debounce": "^4.0.8",
|
|
43
|
-
"prosemirror-model": "^1.
|
|
44
|
-
"prosemirror-state": "^1.4.
|
|
30
|
+
"prosemirror-model": "^1.19.3",
|
|
31
|
+
"prosemirror-state": "^1.4.3",
|
|
45
32
|
"prosemirror-test-builder": "^1.1.1",
|
|
46
33
|
"prosemirror-transform": "^1.7.3",
|
|
47
|
-
"prosemirror-view": "^1.31.
|
|
34
|
+
"prosemirror-view": "^1.31.4",
|
|
35
|
+
"tslib": "^2.6.1"
|
|
48
36
|
},
|
|
49
37
|
"devDependencies": {
|
|
50
38
|
"@types/jest": "^29.5.1",
|
|
@@ -60,6 +48,20 @@
|
|
|
60
48
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
61
49
|
"rollup-plugin-typescript2": "^0.35.0",
|
|
62
50
|
"ts-jest": "^29.1.0",
|
|
63
|
-
"typescript": "^
|
|
51
|
+
"typescript": "^5.1.6"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"preinstall": "npx only-allow pnpm",
|
|
55
|
+
"prebuild": "rimraf dist",
|
|
56
|
+
"build": "rollup -c --bundleConfigAsCjs",
|
|
57
|
+
"rebuild": "rollup -c --bundleConfigAsCjs",
|
|
58
|
+
"dev": "rollup -c -w --bundleConfigAsCjs",
|
|
59
|
+
"format": "eslint src --ext .ts --fix",
|
|
60
|
+
"version": "pnpm run format && git add -A src",
|
|
61
|
+
"postversion": "git push && git push --tags",
|
|
62
|
+
"lint": "tsc --noEmit && eslint src --ext .ts",
|
|
63
|
+
"test": "jest",
|
|
64
|
+
"upgrade-interactive": "npm-check --update",
|
|
65
|
+
"publish:np": "np"
|
|
64
66
|
}
|
|
65
|
-
}
|
|
67
|
+
}
|