@copilotkit/react-textarea 0.21.0-alpha.1 → 0.21.0-alpha.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/.turbo/turbo-build.log +302 -170
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-34D4UIYX.mjs → chunk-4ENJ4VF6.mjs} +4 -4
- package/dist/{chunk-IPM5WWPW.mjs → chunk-JHLXWI44.mjs} +5 -5
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1772 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +3 -3
- package/dist/components/base-copilot-textarea/render-element.js +75 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +69 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2246 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +5 -5
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +49 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +158 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +915 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +622 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +639 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +140 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +639 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/index.js +2250 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +5 -5
- package/dist/components/manual-ui/chip-with-icon.js +53 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/source-search-box/source-search-box.js +243 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/ui/button.js +118 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.js +142 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/command.js +306 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/dialog.js +199 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/label.js +92 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/separator.js +96 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/textarea.js +91 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +193 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +167 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +227 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.js +39 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/index.js +2256 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -6
- package/dist/lib/debouncer.js +76 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/editor-to-text.js +69 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/get-text-around-cursor.js +131 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/retry.js +43 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +49 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.js +53 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/stream-promise-flatten.js +72 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/utils.js +101 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.test.js +9 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +275 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +109 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/index.js +331 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +103 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.js +99 -0
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +92 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/base/autosuggestion-state.js +19 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.js +19 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.js +38 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.js +19 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/custom-editor.js +19 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.js +45 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/index.js +40 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.js +19 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/index.js +333 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +4 -4
- package/tsup.config.ts +1 -1
- /package/dist/{chunk-34D4UIYX.mjs.map → chunk-4ENJ4VF6.mjs.map} +0 -0
- /package/dist/{chunk-IPM5WWPW.mjs.map → chunk-JHLXWI44.mjs.map} +0 -0
|
@@ -0,0 +1,915 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
51
|
+
mod
|
|
52
|
+
));
|
|
53
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
54
|
+
var __async = (__this, __arguments, generator) => {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
var fulfilled = (value) => {
|
|
57
|
+
try {
|
|
58
|
+
step(generator.next(value));
|
|
59
|
+
} catch (e) {
|
|
60
|
+
reject(e);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var rejected = (value) => {
|
|
64
|
+
try {
|
|
65
|
+
step(generator.throw(value));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
reject(e);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
71
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
76
|
+
var hovering_toolbar_exports = {};
|
|
77
|
+
__export(hovering_toolbar_exports, {
|
|
78
|
+
HoveringToolbar: () => HoveringToolbar
|
|
79
|
+
});
|
|
80
|
+
module.exports = __toCommonJS(hovering_toolbar_exports);
|
|
81
|
+
var import_react6 = require("react");
|
|
82
|
+
var import_slate2 = require("slate");
|
|
83
|
+
var import_slate_react = require("slate-react");
|
|
84
|
+
|
|
85
|
+
// src/hooks/misc/use-autosize-textarea.tsx
|
|
86
|
+
var import_react = require("react");
|
|
87
|
+
var useAutosizeTextArea = (textAreaRef, value) => {
|
|
88
|
+
(0, import_react.useEffect)(() => {
|
|
89
|
+
if (textAreaRef.current !== null) {
|
|
90
|
+
textAreaRef.current.style.height = "0px";
|
|
91
|
+
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
92
|
+
textAreaRef.current.style.height = scrollHeight + "px";
|
|
93
|
+
}
|
|
94
|
+
}, [textAreaRef, value]);
|
|
95
|
+
};
|
|
96
|
+
var use_autosize_textarea_default = useAutosizeTextArea;
|
|
97
|
+
|
|
98
|
+
// src/components/source-search-box/source-search-box.tsx
|
|
99
|
+
var import_react2 = require("react");
|
|
100
|
+
|
|
101
|
+
// src/components/ui/command.tsx
|
|
102
|
+
var React = __toESM(require("react"));
|
|
103
|
+
var import_cmdk = require("cmdk");
|
|
104
|
+
|
|
105
|
+
// src/lib/utils.ts
|
|
106
|
+
var import_clsx = require("clsx");
|
|
107
|
+
var import_nanoid = require("nanoid");
|
|
108
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
109
|
+
function cn(...inputs) {
|
|
110
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
111
|
+
}
|
|
112
|
+
var nanoid = (0, import_nanoid.customAlphabet)(
|
|
113
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
114
|
+
7
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// src/components/ui/command.tsx
|
|
118
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
119
|
+
"use client";
|
|
120
|
+
var Command = React.forwardRef((_a, ref) => {
|
|
121
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
122
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command, __spreadValues({
|
|
123
|
+
ref,
|
|
124
|
+
className: cn(
|
|
125
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
126
|
+
className
|
|
127
|
+
)
|
|
128
|
+
}, props));
|
|
129
|
+
});
|
|
130
|
+
Command.displayName = import_cmdk.Command.displayName;
|
|
131
|
+
var CommandInput = React.forwardRef((_a, ref) => {
|
|
132
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
134
|
+
className: "flex items-center border-b px-3",
|
|
135
|
+
"cmdk-input-wrapper": "",
|
|
136
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Input, __spreadValues({
|
|
137
|
+
ref,
|
|
138
|
+
className: cn(
|
|
139
|
+
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
140
|
+
className
|
|
141
|
+
)
|
|
142
|
+
}, props))
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
CommandInput.displayName = import_cmdk.Command.Input.displayName;
|
|
146
|
+
var CommandList = React.forwardRef((_a, ref) => {
|
|
147
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.List, __spreadValues({
|
|
149
|
+
ref,
|
|
150
|
+
className: cn(
|
|
151
|
+
"max-h-[300px] overflow-y-auto overflow-x-hidden pb-2",
|
|
152
|
+
className
|
|
153
|
+
)
|
|
154
|
+
}, props));
|
|
155
|
+
});
|
|
156
|
+
CommandList.displayName = import_cmdk.Command.List.displayName;
|
|
157
|
+
var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Empty, __spreadValues({
|
|
158
|
+
ref,
|
|
159
|
+
className: "py-6 text-center text-sm"
|
|
160
|
+
}, props)));
|
|
161
|
+
CommandEmpty.displayName = import_cmdk.Command.Empty.displayName;
|
|
162
|
+
var CommandGroup = React.forwardRef((_a, ref) => {
|
|
163
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Group, __spreadValues({
|
|
165
|
+
ref,
|
|
166
|
+
className: cn(
|
|
167
|
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
168
|
+
className
|
|
169
|
+
)
|
|
170
|
+
}, props));
|
|
171
|
+
});
|
|
172
|
+
CommandGroup.displayName = import_cmdk.Command.Group.displayName;
|
|
173
|
+
var CommandSeparator = React.forwardRef((_a, ref) => {
|
|
174
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Separator, __spreadValues({
|
|
176
|
+
ref,
|
|
177
|
+
className: cn("-mx-1 h-px bg-border", className)
|
|
178
|
+
}, props));
|
|
179
|
+
});
|
|
180
|
+
CommandSeparator.displayName = import_cmdk.Command.Separator.displayName;
|
|
181
|
+
var CommandItem = React.forwardRef((_a, ref) => {
|
|
182
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Item, __spreadValues({
|
|
184
|
+
ref,
|
|
185
|
+
className: cn(
|
|
186
|
+
"relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
187
|
+
className
|
|
188
|
+
)
|
|
189
|
+
}, props));
|
|
190
|
+
});
|
|
191
|
+
CommandItem.displayName = import_cmdk.Command.Item.displayName;
|
|
192
|
+
var CommandShortcut = (_a) => {
|
|
193
|
+
var _b = _a, {
|
|
194
|
+
className
|
|
195
|
+
} = _b, props = __objRest(_b, [
|
|
196
|
+
"className"
|
|
197
|
+
]);
|
|
198
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", __spreadValues({
|
|
199
|
+
className: cn(
|
|
200
|
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
201
|
+
className
|
|
202
|
+
)
|
|
203
|
+
}, props));
|
|
204
|
+
};
|
|
205
|
+
CommandShortcut.displayName = "CommandShortcut";
|
|
206
|
+
|
|
207
|
+
// src/components/source-search-box/source-search-box.tsx
|
|
208
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
209
|
+
function SourceSearchBox(props) {
|
|
210
|
+
const [selectedValue, setSelectedValue] = (0, import_react2.useState)("");
|
|
211
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Command, {
|
|
212
|
+
className: "rounded-lg border shadow-md",
|
|
213
|
+
value: selectedValue,
|
|
214
|
+
onValueChange: (value) => {
|
|
215
|
+
setSelectedValue(value);
|
|
216
|
+
},
|
|
217
|
+
filter: (value, search) => {
|
|
218
|
+
if (props.searchTerm === "")
|
|
219
|
+
return 1;
|
|
220
|
+
if (value.startsWith(props.searchTerm))
|
|
221
|
+
return 1;
|
|
222
|
+
return 0;
|
|
223
|
+
},
|
|
224
|
+
children: [
|
|
225
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandInput, {
|
|
226
|
+
value: props.searchTerm,
|
|
227
|
+
className: "rounded-t-lg hidden",
|
|
228
|
+
placeholder: "Search for a command..."
|
|
229
|
+
}),
|
|
230
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(CommandList, {
|
|
231
|
+
children: [
|
|
232
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandEmpty, {
|
|
233
|
+
children: "No results found."
|
|
234
|
+
}),
|
|
235
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandGroup, {
|
|
236
|
+
heading: "Available resources",
|
|
237
|
+
children: props.suggestedFiles.map((filePointer) => {
|
|
238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandItem, {
|
|
239
|
+
value: filePointer.name,
|
|
240
|
+
onSelect: (value) => {
|
|
241
|
+
props.onSelectedFile(filePointer);
|
|
242
|
+
},
|
|
243
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", {
|
|
244
|
+
className: " px-3 flex flex-row gap-1 items-center",
|
|
245
|
+
children: [
|
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Logo, {
|
|
247
|
+
width: "20px",
|
|
248
|
+
height: "20px",
|
|
249
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", {
|
|
250
|
+
src: filePointer.iconImageUri,
|
|
251
|
+
alt: filePointer.sourceApplication,
|
|
252
|
+
className: "w-full h-full"
|
|
253
|
+
})
|
|
254
|
+
}),
|
|
255
|
+
filePointer.name
|
|
256
|
+
]
|
|
257
|
+
})
|
|
258
|
+
}, `word-${filePointer.sourceApplication}.${filePointer.name}`);
|
|
259
|
+
})
|
|
260
|
+
}),
|
|
261
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandSeparator, {})
|
|
262
|
+
]
|
|
263
|
+
})
|
|
264
|
+
]
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function Logo({
|
|
268
|
+
children,
|
|
269
|
+
width,
|
|
270
|
+
height
|
|
271
|
+
}) {
|
|
272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", {
|
|
273
|
+
className: "flex items-center justify-center",
|
|
274
|
+
style: { width, height },
|
|
275
|
+
children
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/components/ui/button.tsx
|
|
280
|
+
var React2 = __toESM(require("react"));
|
|
281
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
282
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
283
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
284
|
+
var buttonVariants = (0, import_class_variance_authority.cva)(
|
|
285
|
+
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
286
|
+
{
|
|
287
|
+
variants: {
|
|
288
|
+
variant: {
|
|
289
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
290
|
+
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
291
|
+
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
292
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
293
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
294
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
295
|
+
},
|
|
296
|
+
size: {
|
|
297
|
+
default: "h-10 px-4 py-2",
|
|
298
|
+
sm: "h-9 rounded-md px-3",
|
|
299
|
+
lg: "h-11 rounded-md px-8",
|
|
300
|
+
icon: "h-10 w-10"
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
defaultVariants: {
|
|
304
|
+
variant: "default",
|
|
305
|
+
size: "default"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
var Button = React2.forwardRef(
|
|
310
|
+
(_a, ref) => {
|
|
311
|
+
var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
|
|
312
|
+
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Comp, __spreadValues({
|
|
314
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
315
|
+
ref
|
|
316
|
+
}, props));
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
Button.displayName = "Button";
|
|
320
|
+
|
|
321
|
+
// src/components/ui/label.tsx
|
|
322
|
+
var React3 = __toESM(require("react"));
|
|
323
|
+
var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
|
|
324
|
+
var import_class_variance_authority2 = require("class-variance-authority");
|
|
325
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
326
|
+
"use client";
|
|
327
|
+
var labelVariants = (0, import_class_variance_authority2.cva)(
|
|
328
|
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
329
|
+
);
|
|
330
|
+
var Label = React3.forwardRef((_a, ref) => {
|
|
331
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LabelPrimitive.Root, __spreadValues({
|
|
333
|
+
ref,
|
|
334
|
+
className: cn(labelVariants(), className)
|
|
335
|
+
}, props));
|
|
336
|
+
});
|
|
337
|
+
Label.displayName = LabelPrimitive.Root.displayName;
|
|
338
|
+
|
|
339
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
340
|
+
var import_react3 = require("react");
|
|
341
|
+
|
|
342
|
+
// src/lib/stream-promise-flatten.ts
|
|
343
|
+
function streamPromiseFlatten(promise) {
|
|
344
|
+
return new ReadableStream({
|
|
345
|
+
start(controller) {
|
|
346
|
+
return __async(this, null, function* () {
|
|
347
|
+
try {
|
|
348
|
+
const stream = yield promise;
|
|
349
|
+
const reader = stream.getReader();
|
|
350
|
+
while (true) {
|
|
351
|
+
const { done, value } = yield reader.read();
|
|
352
|
+
if (done) {
|
|
353
|
+
controller.close();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
controller.enqueue(value);
|
|
357
|
+
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
controller.error(error);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
367
|
+
var import_react_core = require("@copilotkit/react-core");
|
|
368
|
+
|
|
369
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
|
|
370
|
+
var import_Chip = __toESM(require("@mui/material/Chip"));
|
|
371
|
+
var import_Avatar = __toESM(require("@mui/material/Avatar"));
|
|
372
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
373
|
+
var IncludedFilesPreview = ({
|
|
374
|
+
includedFiles,
|
|
375
|
+
setIncludedFiles
|
|
376
|
+
}) => {
|
|
377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
|
|
378
|
+
className: "flex flex-col gap-2 mt-2",
|
|
379
|
+
children: [
|
|
380
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, {
|
|
381
|
+
className: "",
|
|
382
|
+
children: "Included context:"
|
|
383
|
+
}),
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
|
|
385
|
+
className: "flex flex-wrap gap-2",
|
|
386
|
+
children: includedFiles.map((filePointer, index) => {
|
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FileChipPreview, {
|
|
388
|
+
filePointer,
|
|
389
|
+
onDelete: () => {
|
|
390
|
+
setIncludedFiles(
|
|
391
|
+
(prev) => prev.filter((fp) => fp !== filePointer)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}, `file-${filePointer.sourceApplication}.${filePointer.name}`);
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
var FileChipPreview = ({
|
|
401
|
+
filePointer,
|
|
402
|
+
onDelete
|
|
403
|
+
}) => {
|
|
404
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_Chip.default, {
|
|
405
|
+
label: filePointer.name,
|
|
406
|
+
onDelete,
|
|
407
|
+
avatar: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_Avatar.default, {
|
|
408
|
+
sx: { backgroundColor: "transparent" }
|
|
409
|
+
})
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
414
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
415
|
+
var HoveringInsertionPromptBoxCore = ({
|
|
416
|
+
performInsertion,
|
|
417
|
+
state,
|
|
418
|
+
insertionOrEditingFunction,
|
|
419
|
+
contextCategories
|
|
420
|
+
}) => {
|
|
421
|
+
const { getDocumentsContext } = (0, import_react3.useContext)(import_react_core.CopilotContext);
|
|
422
|
+
const [editSuggestion, setEditSuggestion] = (0, import_react3.useState)("");
|
|
423
|
+
const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react3.useState)(false);
|
|
424
|
+
const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react3.useState)("");
|
|
425
|
+
const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react3.useState)(null);
|
|
426
|
+
const adjustmentTextAreaRef = (0, import_react3.useRef)(null);
|
|
427
|
+
const suggestionTextAreaRef = (0, import_react3.useRef)(null);
|
|
428
|
+
const [filePointers, setFilePointers] = (0, import_react3.useState)([]);
|
|
429
|
+
const [suggestedFiles, setSuggestedFiles] = (0, import_react3.useState)([]);
|
|
430
|
+
(0, import_react3.useEffect)(() => {
|
|
431
|
+
setSuggestedFiles(getDocumentsContext(contextCategories));
|
|
432
|
+
}, [contextCategories, getDocumentsContext]);
|
|
433
|
+
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
434
|
+
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
435
|
+
(0, import_react3.useEffect)(() => {
|
|
436
|
+
var _a;
|
|
437
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
438
|
+
}, []);
|
|
439
|
+
(0, import_react3.useEffect)(() => {
|
|
440
|
+
if (!generatingSuggestion) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (generatingSuggestion.locked) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
setEditSuggestion("");
|
|
447
|
+
const reader = generatingSuggestion.getReader();
|
|
448
|
+
const read = () => __async(void 0, null, function* () {
|
|
449
|
+
setSuggestionIsLoading(true);
|
|
450
|
+
while (true) {
|
|
451
|
+
const { done, value } = yield reader.read();
|
|
452
|
+
if (done) {
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
setEditSuggestion((prev) => {
|
|
456
|
+
const newSuggestion = prev + value;
|
|
457
|
+
if (suggestionTextAreaRef.current) {
|
|
458
|
+
suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
|
|
459
|
+
}
|
|
460
|
+
return newSuggestion;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
setSuggestionIsLoading(false);
|
|
464
|
+
});
|
|
465
|
+
read();
|
|
466
|
+
return () => {
|
|
467
|
+
const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
|
|
468
|
+
try {
|
|
469
|
+
yield reader.closed;
|
|
470
|
+
} catch (e) {
|
|
471
|
+
reader.releaseLock();
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
releaseLockIfNotClosed();
|
|
475
|
+
};
|
|
476
|
+
}, [generatingSuggestion]);
|
|
477
|
+
const beginGeneratingAdjustment = (0, import_react3.useCallback)(() => __async(void 0, null, function* () {
|
|
478
|
+
if (!adjustmentPrompt.trim()) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
let modificationState = state.editorState;
|
|
482
|
+
if (editSuggestion !== "") {
|
|
483
|
+
modificationState.selectedText = editSuggestion;
|
|
484
|
+
}
|
|
485
|
+
const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
|
|
486
|
+
modificationState,
|
|
487
|
+
adjustmentPrompt,
|
|
488
|
+
filePointers,
|
|
489
|
+
new AbortController().signal
|
|
490
|
+
);
|
|
491
|
+
const adjustmentSuggestionTextStream = streamPromiseFlatten(
|
|
492
|
+
adjustmentSuggestionTextStreamPromise
|
|
493
|
+
);
|
|
494
|
+
setGeneratingSuggestion(adjustmentSuggestionTextStream);
|
|
495
|
+
}), [
|
|
496
|
+
adjustmentPrompt,
|
|
497
|
+
editSuggestion,
|
|
498
|
+
state.editorState,
|
|
499
|
+
insertionOrEditingFunction,
|
|
500
|
+
filePointers
|
|
501
|
+
]);
|
|
502
|
+
const isLoading = suggestionIsLoading;
|
|
503
|
+
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
504
|
+
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
505
|
+
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
506
|
+
const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, {
|
|
507
|
+
children: [
|
|
508
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Label, {
|
|
509
|
+
className: "",
|
|
510
|
+
children: adjustmentLabel
|
|
511
|
+
}),
|
|
512
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
|
|
513
|
+
className: "relative w-full flex items-center",
|
|
514
|
+
children: [
|
|
515
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("textarea", {
|
|
516
|
+
disabled: suggestionIsLoading,
|
|
517
|
+
ref: adjustmentTextAreaRef,
|
|
518
|
+
value: adjustmentPrompt,
|
|
519
|
+
onChange: (e) => setAdjustmentPrompt(e.target.value),
|
|
520
|
+
onKeyDown: (e) => {
|
|
521
|
+
if (e.key === "Enter" && e.shiftKey) {
|
|
522
|
+
e.preventDefault();
|
|
523
|
+
setAdjustmentPrompt(adjustmentPrompt + "\n");
|
|
524
|
+
} else if (e.key === "Enter") {
|
|
525
|
+
e.preventDefault();
|
|
526
|
+
beginGeneratingAdjustment();
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
placeholder,
|
|
530
|
+
style: { minHeight: "3rem" },
|
|
531
|
+
className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
|
|
532
|
+
rows: 1
|
|
533
|
+
}),
|
|
534
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", {
|
|
535
|
+
onClick: beginGeneratingAdjustment,
|
|
536
|
+
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
537
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("i", {
|
|
538
|
+
className: "material-icons",
|
|
539
|
+
children: "arrow_forward"
|
|
540
|
+
})
|
|
541
|
+
})
|
|
542
|
+
]
|
|
543
|
+
})
|
|
544
|
+
]
|
|
545
|
+
});
|
|
546
|
+
const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, {
|
|
547
|
+
children: [
|
|
548
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
|
|
549
|
+
className: "flex justify-between items-end w-full",
|
|
550
|
+
children: [
|
|
551
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Label, {
|
|
552
|
+
className: "mt-4",
|
|
553
|
+
children: "Suggested:"
|
|
554
|
+
}),
|
|
555
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
|
|
556
|
+
className: "ml-auto",
|
|
557
|
+
children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
|
|
558
|
+
className: "flex justify-center items-center",
|
|
559
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
|
|
560
|
+
className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
|
|
561
|
+
role: "status",
|
|
562
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
|
|
563
|
+
className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]",
|
|
564
|
+
children: "Loading..."
|
|
565
|
+
})
|
|
566
|
+
})
|
|
567
|
+
})
|
|
568
|
+
})
|
|
569
|
+
]
|
|
570
|
+
}),
|
|
571
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("textarea", {
|
|
572
|
+
ref: suggestionTextAreaRef,
|
|
573
|
+
value: editSuggestion,
|
|
574
|
+
disabled: suggestionIsLoading,
|
|
575
|
+
onChange: (e) => setEditSuggestion(e.target.value),
|
|
576
|
+
className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
|
|
577
|
+
style: { overflow: "auto", maxHeight: "10em" }
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
});
|
|
581
|
+
const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
|
|
582
|
+
className: "flex w-full gap-4 justify-start",
|
|
583
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Button, {
|
|
584
|
+
className: " bg-green-700 text-white",
|
|
585
|
+
onClick: () => {
|
|
586
|
+
performInsertion(editSuggestion);
|
|
587
|
+
},
|
|
588
|
+
children: [
|
|
589
|
+
"Insert ",
|
|
590
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("i", {
|
|
591
|
+
className: "material-icons",
|
|
592
|
+
children: "check"
|
|
593
|
+
})
|
|
594
|
+
]
|
|
595
|
+
})
|
|
596
|
+
});
|
|
597
|
+
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
598
|
+
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
599
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
|
|
600
|
+
className: "w-full flex flex-col items-start relative gap-2",
|
|
601
|
+
children: [
|
|
602
|
+
AdjustmentPromptComponent,
|
|
603
|
+
filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(IncludedFilesPreview, {
|
|
604
|
+
includedFiles: filePointers,
|
|
605
|
+
setIncludedFiles: setFilePointers
|
|
606
|
+
}),
|
|
607
|
+
sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SourceSearchBox, {
|
|
608
|
+
searchTerm: sourceSearchWord,
|
|
609
|
+
suggestedFiles,
|
|
610
|
+
onSelectedFile: (filePointer) => {
|
|
611
|
+
var _a;
|
|
612
|
+
setAdjustmentPrompt(
|
|
613
|
+
adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), "")
|
|
614
|
+
);
|
|
615
|
+
setFilePointers((prev) => [...prev, filePointer]);
|
|
616
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
617
|
+
}
|
|
618
|
+
}),
|
|
619
|
+
generatingSuggestion ? SuggestionComponent : null,
|
|
620
|
+
generatingSuggestion ? SubmitComponent : null
|
|
621
|
+
]
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
626
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
627
|
+
var HoveringInsertionPromptBox = (props) => {
|
|
628
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
|
|
629
|
+
className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
|
|
630
|
+
style: { width: "35rem" },
|
|
631
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HoveringInsertionPromptBoxCore, {
|
|
632
|
+
state: {
|
|
633
|
+
editorState: props.editorState
|
|
634
|
+
},
|
|
635
|
+
insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
|
|
636
|
+
performInsertion: props.performInsertion,
|
|
637
|
+
contextCategories: props.contextCategories
|
|
638
|
+
})
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/components/hovering-toolbar/hovering-toolbar-components.tsx
|
|
643
|
+
var import_css = require("@emotion/css");
|
|
644
|
+
var import_react4 = __toESM(require("react"));
|
|
645
|
+
var import_react_dom = __toESM(require("react-dom"));
|
|
646
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
647
|
+
var Button2 = import_react4.default.forwardRef(
|
|
648
|
+
(_a, ref) => {
|
|
649
|
+
var _b = _a, {
|
|
650
|
+
className,
|
|
651
|
+
active,
|
|
652
|
+
reversed
|
|
653
|
+
} = _b, props = __objRest(_b, [
|
|
654
|
+
"className",
|
|
655
|
+
"active",
|
|
656
|
+
"reversed"
|
|
657
|
+
]);
|
|
658
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", __spreadProps(__spreadValues({}, props), {
|
|
659
|
+
ref,
|
|
660
|
+
className: (0, import_css.cx)(
|
|
661
|
+
className,
|
|
662
|
+
import_css.css`
|
|
663
|
+
cursor: pointer;
|
|
664
|
+
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
665
|
+
`
|
|
666
|
+
)
|
|
667
|
+
}));
|
|
668
|
+
}
|
|
669
|
+
);
|
|
670
|
+
var Icon = import_react4.default.forwardRef(
|
|
671
|
+
(_a, ref) => {
|
|
672
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", __spreadProps(__spreadValues({}, props), {
|
|
674
|
+
ref,
|
|
675
|
+
className: (0, import_css.cx)(
|
|
676
|
+
"material-icons",
|
|
677
|
+
className,
|
|
678
|
+
import_css.css`
|
|
679
|
+
font-size: 18px;
|
|
680
|
+
vertical-align: text-bottom;
|
|
681
|
+
`
|
|
682
|
+
)
|
|
683
|
+
}));
|
|
684
|
+
}
|
|
685
|
+
);
|
|
686
|
+
var Menu = import_react4.default.forwardRef(
|
|
687
|
+
(_a, ref) => {
|
|
688
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
689
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", __spreadProps(__spreadValues({}, props), {
|
|
690
|
+
"data-test-id": "menu",
|
|
691
|
+
ref,
|
|
692
|
+
className: (0, import_css.cx)(
|
|
693
|
+
className,
|
|
694
|
+
import_css.css`
|
|
695
|
+
& > * {
|
|
696
|
+
display: inline-block;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
& > * + * {
|
|
700
|
+
margin-left: 15px;
|
|
701
|
+
}
|
|
702
|
+
`
|
|
703
|
+
)
|
|
704
|
+
}));
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
var Portal = ({ children }) => {
|
|
708
|
+
return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
|
|
709
|
+
};
|
|
710
|
+
var Toolbar = import_react4.default.forwardRef(
|
|
711
|
+
(_a, ref) => {
|
|
712
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
713
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Menu, __spreadProps(__spreadValues({}, props), {
|
|
714
|
+
ref,
|
|
715
|
+
className: (0, import_css.cx)(
|
|
716
|
+
className,
|
|
717
|
+
import_css.css`
|
|
718
|
+
position: relative;
|
|
719
|
+
padding: 1px 18px 17px;
|
|
720
|
+
margin: 0 -20px;
|
|
721
|
+
border-bottom: 2px solid #eee;
|
|
722
|
+
margin-bottom: 20px;
|
|
723
|
+
`
|
|
724
|
+
)
|
|
725
|
+
}));
|
|
726
|
+
}
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
730
|
+
var import_react5 = require("react");
|
|
731
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
732
|
+
var HoveringEditorContext = (0, import_react5.createContext)({
|
|
733
|
+
isDisplayed: false,
|
|
734
|
+
setIsDisplayed: () => {
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
var useHoveringEditorContext = () => (0, import_react5.useContext)(HoveringEditorContext);
|
|
738
|
+
|
|
739
|
+
// src/lib/get-text-around-cursor.ts
|
|
740
|
+
var import_slate = require("slate");
|
|
741
|
+
function getTextAroundSelection(editor) {
|
|
742
|
+
const { selection } = editor;
|
|
743
|
+
if (!selection) {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
747
|
+
const beforeRange = {
|
|
748
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
749
|
+
focus: wellOrderedSelection.anchor
|
|
750
|
+
};
|
|
751
|
+
const afterRange = {
|
|
752
|
+
anchor: wellOrderedSelection.focus,
|
|
753
|
+
focus: import_slate.Editor.end(editor, [])
|
|
754
|
+
};
|
|
755
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
756
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
757
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
758
|
+
return {
|
|
759
|
+
selection: wellOrderedSelection,
|
|
760
|
+
textBeforeCursor: before,
|
|
761
|
+
selectedText,
|
|
762
|
+
textAfterCursor: after
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
766
|
+
const fullDocumentRange = {
|
|
767
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
768
|
+
focus: import_slate.Editor.end(editor, [])
|
|
769
|
+
};
|
|
770
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
771
|
+
}
|
|
772
|
+
function extractTextWithNewlines(editor, range) {
|
|
773
|
+
const voids = false;
|
|
774
|
+
const [start, end] = import_slate.Range.edges(range);
|
|
775
|
+
let text = "";
|
|
776
|
+
let lastBlock = null;
|
|
777
|
+
for (const [node, path] of import_slate.Editor.nodes(editor, {
|
|
778
|
+
at: range,
|
|
779
|
+
match: import_slate.Text.isText,
|
|
780
|
+
voids
|
|
781
|
+
})) {
|
|
782
|
+
let t = node.text;
|
|
783
|
+
const [block] = import_slate.Editor.above(editor, {
|
|
784
|
+
at: path,
|
|
785
|
+
match: (n) => import_slate.Element.isElement(n) && n.type === "paragraph"
|
|
786
|
+
}) || [null];
|
|
787
|
+
if (lastBlock !== block && block) {
|
|
788
|
+
if (lastBlock) {
|
|
789
|
+
text += "\n";
|
|
790
|
+
}
|
|
791
|
+
lastBlock = block;
|
|
792
|
+
}
|
|
793
|
+
if (import_slate.Path.equals(path, end.path)) {
|
|
794
|
+
t = t.slice(0, end.offset);
|
|
795
|
+
}
|
|
796
|
+
if (import_slate.Path.equals(path, start.path)) {
|
|
797
|
+
t = t.slice(start.offset);
|
|
798
|
+
}
|
|
799
|
+
text += t;
|
|
800
|
+
}
|
|
801
|
+
return text;
|
|
802
|
+
}
|
|
803
|
+
function wellOrderedRange(range) {
|
|
804
|
+
const { anchor, focus } = range;
|
|
805
|
+
if (import_slate.Point.isBefore(anchor, focus)) {
|
|
806
|
+
return range;
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
anchor: focus,
|
|
810
|
+
focus: anchor
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
815
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
816
|
+
var HoveringToolbar = (props) => {
|
|
817
|
+
const ref = (0, import_react6.useRef)(null);
|
|
818
|
+
const editor = (0, import_slate_react.useSlate)();
|
|
819
|
+
const selection = (0, import_slate_react.useSlateSelection)();
|
|
820
|
+
const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
|
|
821
|
+
const [isClient, setIsClient] = (0, import_react6.useState)(false);
|
|
822
|
+
(0, import_react6.useEffect)(() => {
|
|
823
|
+
setIsClient(true);
|
|
824
|
+
}, []);
|
|
825
|
+
(0, import_react6.useEffect)(() => {
|
|
826
|
+
const el = ref.current;
|
|
827
|
+
const { selection: selection2 } = editor;
|
|
828
|
+
if (!el) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (!selection2) {
|
|
832
|
+
el.removeAttribute("style");
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const domSelection = window.getSelection();
|
|
836
|
+
if (!domSelection) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const domRange = domSelection.getRangeAt(0);
|
|
840
|
+
const rect = domRange.getBoundingClientRect();
|
|
841
|
+
if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const minGapFromEdge = 60;
|
|
845
|
+
const verticalOffsetFromCorner = 35;
|
|
846
|
+
const horizontalOffsetFromCorner = 15;
|
|
847
|
+
let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
|
|
848
|
+
if (top < minGapFromEdge) {
|
|
849
|
+
top = rect.bottom + window.scrollY + minGapFromEdge;
|
|
850
|
+
} else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
|
|
851
|
+
top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
|
|
852
|
+
}
|
|
853
|
+
let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
|
|
854
|
+
if (left < minGapFromEdge) {
|
|
855
|
+
left = minGapFromEdge;
|
|
856
|
+
} else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
|
|
857
|
+
left = window.innerWidth - el.offsetWidth - minGapFromEdge;
|
|
858
|
+
}
|
|
859
|
+
el.style.opacity = "1";
|
|
860
|
+
el.style.top = `${top}px`;
|
|
861
|
+
el.style.left = `${left}px`;
|
|
862
|
+
});
|
|
863
|
+
(0, import_react6.useEffect)(() => {
|
|
864
|
+
const handleClickOutside = (event) => {
|
|
865
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
866
|
+
setIsDisplayed(false);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
870
|
+
return () => {
|
|
871
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
872
|
+
};
|
|
873
|
+
}, [ref, setIsDisplayed]);
|
|
874
|
+
if (!isClient) {
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Portal, {
|
|
878
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Menu, {
|
|
879
|
+
ref,
|
|
880
|
+
className: "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
|
|
881
|
+
children: isDisplayed && selection && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HoveringInsertionPromptBox, {
|
|
882
|
+
editorState: editorState(editor, selection),
|
|
883
|
+
apiConfig: props.apiConfig,
|
|
884
|
+
closeWindow: () => {
|
|
885
|
+
setIsDisplayed(false);
|
|
886
|
+
},
|
|
887
|
+
performInsertion: (insertedText) => {
|
|
888
|
+
console.log("inserted text", insertedText);
|
|
889
|
+
import_slate2.Transforms.delete(editor, { at: selection });
|
|
890
|
+
import_slate2.Transforms.insertText(editor, insertedText, {
|
|
891
|
+
at: selection
|
|
892
|
+
});
|
|
893
|
+
setIsDisplayed(false);
|
|
894
|
+
},
|
|
895
|
+
contextCategories: props.contextCategories
|
|
896
|
+
})
|
|
897
|
+
})
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
function editorState(editor, selection) {
|
|
901
|
+
const textAroundCursor = getTextAroundSelection(editor);
|
|
902
|
+
if (textAroundCursor) {
|
|
903
|
+
return textAroundCursor;
|
|
904
|
+
}
|
|
905
|
+
return {
|
|
906
|
+
textBeforeCursor: getFullEditorTextWithNewlines(editor),
|
|
907
|
+
textAfterCursor: "",
|
|
908
|
+
selectedText: ""
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
912
|
+
0 && (module.exports = {
|
|
913
|
+
HoveringToolbar
|
|
914
|
+
});
|
|
915
|
+
//# sourceMappingURL=hovering-toolbar.js.map
|