@copilotkit/react-textarea 0.26.0-alpha.2 → 0.26.0-alpha.4
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 +189 -185
- package/CHANGELOG.md +22 -0
- package/dist/chunk-224UKA7C.mjs +33 -0
- package/dist/chunk-224UKA7C.mjs.map +1 -0
- package/dist/chunk-2C7O2EVM.mjs +27 -0
- package/dist/chunk-2C7O2EVM.mjs.map +1 -0
- package/dist/chunk-2QDCE7PD.mjs +29 -0
- package/dist/chunk-2QDCE7PD.mjs.map +1 -0
- package/dist/chunk-3PQ7GSFE.mjs +17 -0
- package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
- package/dist/chunk-47L4PLG4.mjs +45 -0
- package/dist/chunk-47L4PLG4.mjs.map +1 -0
- package/dist/chunk-4NHVQZ67.mjs +107 -0
- package/dist/chunk-4NHVQZ67.mjs.map +1 -0
- package/dist/chunk-5FO6ISW4.mjs +3 -0
- package/dist/chunk-5FO6ISW4.mjs.map +1 -0
- package/dist/chunk-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-72P3KOHZ.mjs +91 -0
- package/dist/chunk-72P3KOHZ.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-7SUZ6CXM.mjs +47 -0
- package/dist/chunk-7SUZ6CXM.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +3 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-DRV2FOHZ.mjs +65 -0
- package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
- package/dist/chunk-ECR45NSD.mjs +101 -0
- package/dist/chunk-ECR45NSD.mjs.map +1 -0
- package/dist/chunk-ELEY7HWW.mjs +202 -0
- package/dist/chunk-ELEY7HWW.mjs.map +1 -0
- package/dist/chunk-EPBVNDKE.mjs +46 -0
- package/dist/chunk-EPBVNDKE.mjs.map +1 -0
- package/dist/chunk-FJNUPSQK.mjs +72 -0
- package/dist/chunk-FJNUPSQK.mjs.map +1 -0
- package/dist/chunk-FP2EKU3L.mjs +28 -0
- package/dist/chunk-FP2EKU3L.mjs.map +1 -0
- package/dist/chunk-FRIYJQCI.mjs +99 -0
- package/dist/chunk-FRIYJQCI.mjs.map +1 -0
- package/dist/chunk-GQN2HYFJ.mjs +22 -0
- package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +3 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +3 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JJLQVT7S.mjs +10 -0
- package/dist/chunk-JJLQVT7S.mjs.map +1 -0
- package/dist/chunk-K5LNB36H.mjs +80 -0
- package/dist/chunk-K5LNB36H.mjs.map +1 -0
- package/dist/chunk-KDVMG3XF.mjs +63 -0
- package/dist/chunk-KDVMG3XF.mjs.map +1 -0
- package/dist/chunk-KFQZHRPJ.mjs +19 -0
- package/dist/chunk-KFQZHRPJ.mjs.map +1 -0
- package/dist/chunk-KNBNKEXR.mjs +27 -0
- package/dist/chunk-KNBNKEXR.mjs.map +1 -0
- package/dist/chunk-KNQIEOFP.mjs +18 -0
- package/dist/chunk-KNQIEOFP.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +3 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-LP2REBM5.mjs +217 -0
- package/dist/chunk-LP2REBM5.mjs.map +1 -0
- package/dist/chunk-M2DR4KVB.mjs +33 -0
- package/dist/chunk-M2DR4KVB.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +3 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-MTDBPK5D.mjs +53 -0
- package/dist/chunk-MTDBPK5D.mjs.map +1 -0
- package/dist/chunk-NRTYAQJE.mjs +46 -0
- package/dist/chunk-NRTYAQJE.mjs.map +1 -0
- package/dist/chunk-NTLVQENP.mjs +19 -0
- package/dist/chunk-NTLVQENP.mjs.map +1 -0
- package/dist/chunk-OHO4G6DR.mjs +19 -0
- package/dist/chunk-OHO4G6DR.mjs.map +1 -0
- package/dist/chunk-P4QVFRLY.mjs +103 -0
- package/dist/chunk-P4QVFRLY.mjs.map +1 -0
- package/dist/chunk-PTZVE6NC.mjs +94 -0
- package/dist/chunk-PTZVE6NC.mjs.map +1 -0
- package/dist/chunk-QDFAIRQF.mjs +45 -0
- package/dist/chunk-QDFAIRQF.mjs.map +1 -0
- package/dist/chunk-RBR32FWA.mjs +74 -0
- package/dist/chunk-RBR32FWA.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-VPEH6V7T.mjs +83 -0
- package/dist/chunk-VPEH6V7T.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +3 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WFTAAA7R.mjs +44 -0
- package/dist/chunk-WFTAAA7R.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +3 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-WTASPE2W.mjs +105 -0
- package/dist/chunk-WTASPE2W.mjs.map +1 -0
- package/dist/chunk-XV7MLLXQ.mjs +18 -0
- package/dist/chunk-XV7MLLXQ.mjs.map +1 -0
- package/dist/chunk-Y473E2ZQ.mjs +112 -0
- package/dist/chunk-Y473E2ZQ.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +35 -1745
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +3 -51
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -49
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +47 -2202
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -17
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -137
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +18 -875
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +12 -558
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +13 -581
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +5 -102
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +14 -581
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.mjs +48 -2203
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +6 -211
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +4 -85
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +7 -53
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +5 -244
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +4 -144
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +4 -60
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +8 -50
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +7 -48
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -158
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -148
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -147
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -193
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.mjs +50 -2206
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +3 -51
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +3 -43
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +3 -102
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +3 -17
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -20
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +3 -47
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +3 -71
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.mjs +1 -0
- package/dist/lib/utils.test.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -265
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -81
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -327
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -75
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -83
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/autosuggestion-state.mjs +2 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -1
- package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +3 -26
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
- package/dist/types/base/custom-editor.mjs +2 -0
- package/dist/types/base/custom-editor.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +4 -17
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +4 -26
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
- package/dist/types/index.mjs +12 -328
- package/dist/types/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/types/autosuggestions-config/insertions-api-config.tsx
|
|
2
|
+
var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
3
|
+
return `You are a versatile writing assistant.
|
|
4
|
+
|
|
5
|
+
The user is writing some text.
|
|
6
|
+
The purpose is: "${textareaPurpose}"
|
|
7
|
+
|
|
8
|
+
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
9
|
+
\`\`\`
|
|
10
|
+
${contextString}
|
|
11
|
+
\`\`\`
|
|
12
|
+
|
|
13
|
+
The user also provides you with a prompt for INSERTIONS into the text they are writing.
|
|
14
|
+
Your job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.
|
|
15
|
+
Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
|
|
16
|
+
|
|
17
|
+
Adjust yourself to the user's style and implied intent.
|
|
18
|
+
|
|
19
|
+
The user will provide the text before and after the cursor, as well as the insertion prompt. You should use this to infer the best relevant insertion.
|
|
20
|
+
<TextAfterCursor>
|
|
21
|
+
<TextBeforeCursor>
|
|
22
|
+
<InsertionPrompt>
|
|
23
|
+
<YourSuggestion>
|
|
24
|
+
`;
|
|
25
|
+
};
|
|
26
|
+
var defaultInsertionsFewShotMessages = [
|
|
27
|
+
{
|
|
28
|
+
role: "user",
|
|
29
|
+
name: "TextAfterCursor",
|
|
30
|
+
content: "While I was there I also picked up some apples, oranges, and bananas."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
role: "user",
|
|
34
|
+
name: "TextBeforeCursor",
|
|
35
|
+
content: "This morning I woke up and went straight to the grocery store."
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
role: "user",
|
|
39
|
+
name: "InsertionPrompt",
|
|
40
|
+
content: "I bought a big watermelon"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
role: "assistant",
|
|
44
|
+
content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
role: "user",
|
|
48
|
+
name: "TextAfterCursor",
|
|
49
|
+
content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
role: "user",
|
|
53
|
+
name: "TextBeforeCursor",
|
|
54
|
+
content: `The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;`
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
role: "user",
|
|
58
|
+
name: "InsertionPrompt",
|
|
59
|
+
content: "add section about the optionholder's pro rata share"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
role: "assistant",
|
|
63
|
+
content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
var defaultInsertionsApiConfig = {
|
|
67
|
+
makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
|
|
68
|
+
fewShotMessages: defaultInsertionsFewShotMessages,
|
|
69
|
+
forwardedParams: void 0
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { defaultInsertionsApiConfig, defaultInsertionsFewShotMessages, defaultInsertionsMakeSystemPrompt };
|
|
73
|
+
//# sourceMappingURL=out.js.map
|
|
74
|
+
//# sourceMappingURL=chunk-RBR32FWA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/autosuggestions-config/insertions-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,oCAAsD,CACjE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA,EAIlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeF;AAEO,IAAM,mCAA4D;AAAA,EACvE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,6BAAkD;AAAA,EAC7D,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user also provides you with a prompt for INSERTIONS into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.\nOnly insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the text before and after the cursor, as well as the insertion prompt. You should use this to infer the best relevant insertion.\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\n<YourSuggestion>\n`;\n};\n\nexport const defaultInsertionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Element } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/editor-to-text.ts
|
|
4
|
+
function nodeChildrenToTextComponents(editor, nodes) {
|
|
5
|
+
const indeciesOfInlineElements = new Set(
|
|
6
|
+
nodes.map((node, index) => {
|
|
7
|
+
if (Element.isElement(node) && editor.isInline(node)) {
|
|
8
|
+
return index;
|
|
9
|
+
}
|
|
10
|
+
return -1;
|
|
11
|
+
}).filter((index) => index !== -1)
|
|
12
|
+
);
|
|
13
|
+
const nonIgnorableItems = nodes.filter((node, index) => {
|
|
14
|
+
const isInline = indeciesOfInlineElements.has(index);
|
|
15
|
+
if (isInline) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
|
|
19
|
+
if (isNeighbourOfInline) {
|
|
20
|
+
return node.text !== "";
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
return nonIgnorableItems.map((node) => {
|
|
25
|
+
if (Element.isElement(node)) {
|
|
26
|
+
switch (node.type) {
|
|
27
|
+
case "paragraph":
|
|
28
|
+
return nodeChildrenToTextComponents(editor, node.children);
|
|
29
|
+
case "suggestion":
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
return [node];
|
|
34
|
+
}
|
|
35
|
+
}).reduce((acc, val) => acc.concat(val), []);
|
|
36
|
+
}
|
|
37
|
+
var editorToText = (editor) => {
|
|
38
|
+
const flattened = nodeChildrenToTextComponents(editor, editor.children);
|
|
39
|
+
const text = flattened.map((textComponent) => textComponent.text).join("\n");
|
|
40
|
+
return text;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { editorToText };
|
|
44
|
+
//# sourceMappingURL=out.js.map
|
|
45
|
+
//# sourceMappingURL=chunk-T6MTDQZ7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/editor-to-text.ts"],"names":[],"mappings":";AAAA,SAAiC,eAAe;AAKhD,SAAS,6BACP,QACA,OACuB;AAEvB,QAAM,2BAA2B,IAAI;AAAA,IACnC,MACG,IAAI,CAAC,MAAM,UAAU;AACpB,UAAI,QAAQ,UAAU,IAAI,KAAK,OAAO,SAAS,IAAI,GAAG;AACpD,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT,CAAC,EACA,OAAO,CAAC,UAAU,UAAU,EAAE;AAAA,EACnC;AAIA,QAAM,oBAAoB,MAAM,OAAO,CAAC,MAAM,UAAU;AACtD,UAAM,WAAW,yBAAyB,IAAI,KAAK;AACnD,QAAI,UAAU;AACZ,aAAO;AAAA,IACT;AAEA,UAAM,sBACJ,yBAAyB,IAAI,QAAQ,CAAC,KAAK,yBAAyB,IAAI,QAAQ,CAAC;AACnF,QAAI,qBAAqB;AACvB,aAAQ,KAAa,SAAS;AAAA,IAChC;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO,kBACJ,IAAI,CAAC,SAAS;AACb,QAAI,QAAQ,UAAU,IAAI,GAAG;AAC3B,cAAQ,KAAK,MAAM;AAAA,QACjB,KAAK;AACH,iBAAO,6BAA6B,QAAQ,KAAK,QAAQ;AAAA,QAC3D,KAAK;AACH,iBAAO,CAAC;AAAA,MACZ;AAAA,IACF,OAAO;AACL,aAAO,CAAC,IAAI;AAAA,IACd;AAAA,EACF,CAAC,EACA,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC;AAC7C;AAEO,IAAM,eAAe,CAAC,WAAqD;AAChF,QAAM,YAAY,6BAA6B,QAAQ,OAAO,QAAQ;AAEtE,QAAM,OAAO,UAAU,IAAI,CAAC,kBAAkB,cAAc,IAAI,EAAE,KAAK,IAAI;AAE3E,SAAO;AACT","sourcesContent":["import { BaseEditor, Descendant, Element } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\nimport { ReactEditor } from \"slate-react\";\nimport { SuggestionAwareText } from \"../types/base/custom-editor\";\n\nfunction nodeChildrenToTextComponents(\n editor: BaseEditor & ReactEditor & HistoryEditor,\n nodes: Descendant[],\n): SuggestionAwareText[] {\n // find inlineable elements\n const indeciesOfInlineElements = new Set(\n nodes\n .map((node, index) => {\n if (Element.isElement(node) && editor.isInline(node)) {\n return index;\n }\n return -1;\n })\n .filter((index) => index !== -1),\n );\n\n // ignorable elements = inline elements,\n // or neighbors of inline elements that are {text: \"\"}\n const nonIgnorableItems = nodes.filter((node, index) => {\n const isInline = indeciesOfInlineElements.has(index);\n if (isInline) {\n return false;\n }\n\n const isNeighbourOfInline =\n indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);\n if (isNeighbourOfInline) {\n return (node as any).text !== \"\";\n }\n\n return true;\n });\n\n return nonIgnorableItems\n .map((node) => {\n if (Element.isElement(node)) {\n switch (node.type) {\n case \"paragraph\":\n return nodeChildrenToTextComponents(editor, node.children);\n case \"suggestion\":\n return [];\n }\n } else {\n return [node];\n }\n })\n .reduce((acc, val) => acc.concat(val), []);\n}\n\nexport const editorToText = (editor: BaseEditor & ReactEditor & HistoryEditor) => {\n const flattened = nodeChildrenToTextComponents(editor, editor.children);\n\n const text = flattened.map((textComponent) => textComponent.text).join(\"\\n\");\n\n return text;\n};\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { replaceEditorText } from './chunk-5UNJXFUO.mjs';
|
|
2
|
+
import { getFullEditorTextWithNewlines } from './chunk-ECR45NSD.mjs';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ReactEditor } from 'slate-react';
|
|
5
|
+
|
|
6
|
+
function usePopulateCopilotTextareaRef(editor, ref) {
|
|
7
|
+
React.useImperativeHandle(
|
|
8
|
+
ref,
|
|
9
|
+
() => {
|
|
10
|
+
class Combined {
|
|
11
|
+
constructor(customMethods2, editorHtmlElement2) {
|
|
12
|
+
this.customMethods = customMethods2;
|
|
13
|
+
this.editorHtmlElement = editorHtmlElement2;
|
|
14
|
+
}
|
|
15
|
+
get(target, propKey) {
|
|
16
|
+
if (this.isKeyOfCustomMethods(propKey)) {
|
|
17
|
+
const value = this.customMethods[propKey];
|
|
18
|
+
if (typeof value === "function") {
|
|
19
|
+
return value.bind(this.customMethods);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
23
|
+
const value = this.editorHtmlElement[propKey];
|
|
24
|
+
if (typeof value === "function") {
|
|
25
|
+
return value.bind(this.editorHtmlElement);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
set(target, propKey, value) {
|
|
31
|
+
if (this.isKeyOfCustomMethods(propKey)) {
|
|
32
|
+
this.customMethods[propKey] = value;
|
|
33
|
+
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
34
|
+
this.editorHtmlElement[propKey] = value;
|
|
35
|
+
} else {
|
|
36
|
+
target[propKey] = value;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
isKeyOfCustomMethods(key) {
|
|
41
|
+
return key in this.customMethods;
|
|
42
|
+
}
|
|
43
|
+
isKeyOfHTMLElement(key) {
|
|
44
|
+
return key in this.editorHtmlElement;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const handler = {
|
|
48
|
+
get(target, propKey) {
|
|
49
|
+
return target.get(target, propKey);
|
|
50
|
+
},
|
|
51
|
+
set(target, propKey, value) {
|
|
52
|
+
return target.set(target, propKey, value);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
class CustomMethods {
|
|
56
|
+
constructor(editor2) {
|
|
57
|
+
this.editor = editor2;
|
|
58
|
+
}
|
|
59
|
+
focus() {
|
|
60
|
+
ReactEditor.focus(this.editor);
|
|
61
|
+
}
|
|
62
|
+
blur() {
|
|
63
|
+
ReactEditor.blur(this.editor);
|
|
64
|
+
}
|
|
65
|
+
get value() {
|
|
66
|
+
return getFullEditorTextWithNewlines(this.editor);
|
|
67
|
+
}
|
|
68
|
+
set value(value) {
|
|
69
|
+
replaceEditorText(this.editor, value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
|
|
73
|
+
const customMethods = new CustomMethods(editor);
|
|
74
|
+
const combined = new Combined(customMethods, editorHtmlElement);
|
|
75
|
+
return new Proxy(combined, handler);
|
|
76
|
+
},
|
|
77
|
+
[editor]
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { usePopulateCopilotTextareaRef };
|
|
82
|
+
//# sourceMappingURL=out.js.map
|
|
83
|
+
//# sourceMappingURL=chunk-VPEH6V7T.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts"],"names":["customMethods","editorHtmlElement","editor"],"mappings":";;;;;;;;AAAA,OAAO,WAAW;AAElB,SAAS,mBAAmB;AAMrB,SAAS,8BACd,QACA,KACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA,MAAM;AACJ,YAAM,SAAS;AAAA,QACb,YAAoBA,gBAAsCC,oBAAgC;AAAtE,+BAAAD;AAAsC,mCAAAC;AAAA,QAAiC;AAAA,QAI3F,IAAI,QAAa,SAAsB;AACrC,cAAI,KAAK,qBAAqB,OAAO,GAAG;AACtC,kBAAM,QAAQ,KAAK,cAAc,OAAO;AACxC,gBAAI,OAAO,UAAU,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK,aAAa;AAAA,YACtC;AACA,mBAAO;AAAA,UACT,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,kBAAM,QAAQ,KAAK,kBAAkB,OAAO;AAC5C,gBAAI,OAAO,UAAU,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK,iBAAiB;AAAA,YAC1C;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,QAEA,IAAI,QAAa,SAAiB,OAAqB;AACrD,cAAI,KAAK,qBAAqB,OAAO,GAAG;AACtC,YAAC,KAAK,cAAsB,OAAO,IAAI;AAAA,UACzC,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,YAAC,KAAK,kBAA0B,OAAO,IAAI;AAAA,UAC7C,OAAO;AAEL,mBAAO,OAAO,IAAI;AAAA,UACpB;AACA,iBAAO;AAAA,QACT;AAAA,QAEQ,qBAAqB,KAAyC;AACpE,iBAAO,OAAO,KAAK;AAAA,QACrB;AAAA,QAEQ,mBAAmB,KAAuC;AAChE,iBAAO,OAAO,KAAK;AAAA,QACrB;AAAA,MACF;AAEA,YAAM,UAAU;AAAA,QACd,IAAI,QAAa,SAAkD;AACjE,iBAAO,OAAO,IAAI,QAAQ,OAAO;AAAA,QACnC;AAAA,QACA,IAAI,QAAa,SAAkD,OAAY;AAC7E,iBAAO,OAAO,IAAI,QAAQ,SAAS,KAAK;AAAA,QAC1C;AAAA,MACF;AAEA,YAAM,cAAc;AAAA,QAClB,YAAoBC,SAAsB;AAAtB,wBAAAA;AAAA,QAAuB;AAAA,QAE3C,QAAQ;AACN,sBAAY,MAAM,KAAK,MAAM;AAAA,QAC/B;AAAA,QAEA,OAAO;AACL,sBAAY,KAAK,KAAK,MAAM;AAAA,QAC9B;AAAA,QAEA,IAAI,QAAQ;AACV,iBAAO,8BAA8B,KAAK,MAAM;AAAA,QAClD;AAAA,QACA,IAAI,MAAM,OAAe;AACvB,4BAAkB,KAAK,QAAQ,KAAK;AAAA,QACtC;AAAA,MACF;AAEA,YAAM,oBAAoB,YAAY,UAAU,QAAQ,MAAM;AAC9D,YAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,YAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,aAAO,IAAI,MAAM,UAAU,OAAO;AAAA,IACpC;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF","sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(\n ref,\n () => {\n class Combined {\n constructor(private customMethods: CustomMethods, private editorHtmlElement: HTMLElement) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n },\n [editor],\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cn } from './chunk-7SUZ6CXM.mjs';
|
|
2
|
+
import { __objRest, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var buttonVariants = cva(
|
|
9
|
+
"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",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
14
|
+
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
15
|
+
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
16
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
17
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
18
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: "h-10 px-4 py-2",
|
|
22
|
+
sm: "h-9 rounded-md px-3",
|
|
23
|
+
lg: "h-11 rounded-md px-8",
|
|
24
|
+
icon: "h-10 w-10"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: "default",
|
|
29
|
+
size: "default"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
var Button = React.forwardRef(
|
|
34
|
+
(_a, ref) => {
|
|
35
|
+
var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
|
|
36
|
+
const Comp = asChild ? Slot : "button";
|
|
37
|
+
return /* @__PURE__ */ jsx(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
Button.displayName = "Button";
|
|
41
|
+
|
|
42
|
+
export { Button, buttonVariants };
|
|
43
|
+
//# sourceMappingURL=out.js.map
|
|
44
|
+
//# sourceMappingURL=chunk-WFTAAA7R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ui/button.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,WAA8B;AAwCjC;AApCN,IAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,aAAa;AAAA,QACb,SAAS;AAAA,QACT,WAAW;AAAA,QACX,OAAO;AAAA,QACP,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAQA,IAAM,SAAe;AAAA,EACnB,CAAC,IAAyD,QAAQ;AAAjE,iBAAE,aAAW,SAAS,MAAM,UAAU,MAvCzC,IAuCG,IAAgD,kBAAhD,IAAgD,CAA9C,aAAW,WAAS,QAAM;AAC3B,UAAM,OAAO,UAAU,OAAO;AAC9B,WACE,oBAAC,uBAAK,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC,GAAG,OAAc,MAAO;AAAA,EAE5F;AACF;AACA,OAAO,cAAc","sourcesContent":["import * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst buttonVariants = cva(\n \"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\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive: \"bg-destructive text-destructive-foreground hover:bg-destructive/90\",\n outline: \"border border-input bg-background hover:bg-accent hover:text-accent-foreground\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n },\n size: {\n default: \"h-10 px-4 py-2\",\n sm: \"h-9 rounded-md px-3\",\n lg: \"h-11 rounded-md px-8\",\n icon: \"h-10 w-10\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n asChild?: boolean;\n}\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />\n );\n },\n);\nButton.displayName = \"Button\";\n\nexport { Button, buttonVariants };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Dialog, DialogContent } from './chunk-PTZVE6NC.mjs';
|
|
2
|
+
import { cn } from './chunk-7SUZ6CXM.mjs';
|
|
3
|
+
import { __objRest, __spreadValues, __spreadProps } from './chunk-MRXNTQOX.mjs';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { Command as Command$1 } from 'cmdk';
|
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var Command = React.forwardRef((_a, ref) => {
|
|
9
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
Command$1,
|
|
12
|
+
__spreadValues({
|
|
13
|
+
ref,
|
|
14
|
+
className: cn(
|
|
15
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
16
|
+
className
|
|
17
|
+
)
|
|
18
|
+
}, props)
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
Command.displayName = Command$1.displayName;
|
|
22
|
+
var CommandDialog = (_a) => {
|
|
23
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
24
|
+
return /* @__PURE__ */ jsx(Dialog, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx(DialogContent, { className: "overflow-hidden p-0 shadow-lg", children: /* @__PURE__ */ jsx(Command, { className: "[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5", children }) }) }));
|
|
25
|
+
};
|
|
26
|
+
var CommandInput = React.forwardRef((_a, ref) => {
|
|
27
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
28
|
+
return /* @__PURE__ */ jsx("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ jsx(
|
|
29
|
+
Command$1.Input,
|
|
30
|
+
__spreadValues({
|
|
31
|
+
ref,
|
|
32
|
+
className: cn(
|
|
33
|
+
"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",
|
|
34
|
+
className
|
|
35
|
+
)
|
|
36
|
+
}, props)
|
|
37
|
+
) });
|
|
38
|
+
});
|
|
39
|
+
CommandInput.displayName = Command$1.Input.displayName;
|
|
40
|
+
var CommandList = React.forwardRef((_a, ref) => {
|
|
41
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
Command$1.List,
|
|
44
|
+
__spreadValues({
|
|
45
|
+
ref,
|
|
46
|
+
className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden pb-2", className)
|
|
47
|
+
}, props)
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
CommandList.displayName = Command$1.List.displayName;
|
|
51
|
+
var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(Command$1.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
|
|
52
|
+
CommandEmpty.displayName = Command$1.Empty.displayName;
|
|
53
|
+
var CommandGroup = React.forwardRef((_a, ref) => {
|
|
54
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
Command$1.Group,
|
|
57
|
+
__spreadValues({
|
|
58
|
+
ref,
|
|
59
|
+
className: cn(
|
|
60
|
+
"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",
|
|
61
|
+
className
|
|
62
|
+
)
|
|
63
|
+
}, props)
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
CommandGroup.displayName = Command$1.Group.displayName;
|
|
67
|
+
var CommandSeparator = React.forwardRef((_a, ref) => {
|
|
68
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
69
|
+
return /* @__PURE__ */ jsx(
|
|
70
|
+
Command$1.Separator,
|
|
71
|
+
__spreadValues({
|
|
72
|
+
ref,
|
|
73
|
+
className: cn("-mx-1 h-px bg-border", className)
|
|
74
|
+
}, props)
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
CommandSeparator.displayName = Command$1.Separator.displayName;
|
|
78
|
+
var CommandItem = React.forwardRef((_a, ref) => {
|
|
79
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
80
|
+
return /* @__PURE__ */ jsx(
|
|
81
|
+
Command$1.Item,
|
|
82
|
+
__spreadValues({
|
|
83
|
+
ref,
|
|
84
|
+
className: cn(
|
|
85
|
+
"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",
|
|
86
|
+
className
|
|
87
|
+
)
|
|
88
|
+
}, props)
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
CommandItem.displayName = Command$1.Item.displayName;
|
|
92
|
+
var CommandShortcut = (_a) => {
|
|
93
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
94
|
+
return /* @__PURE__ */ jsx(
|
|
95
|
+
"span",
|
|
96
|
+
__spreadValues({
|
|
97
|
+
className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
|
|
98
|
+
}, props)
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
CommandShortcut.displayName = "CommandShortcut";
|
|
102
|
+
|
|
103
|
+
export { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut };
|
|
104
|
+
//# sourceMappingURL=out.js.map
|
|
105
|
+
//# sourceMappingURL=chunk-WTASPE2W.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ui/command.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,YAAY,WAAW;AAEvB,SAAS,WAAW,wBAAwB;AAU1C;AAJF,IAAM,UAAgB,iBAGpB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAbL,IAaG,IAAgB,kBAAhB,IAAgB,CAAd;AACH;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,OACI;AAAA,EACN;AAAA,CACD;AACD,QAAQ,cAAc,iBAAiB;AAIvC,IAAM,gBAAgB,CAAC,OAA+C;AAA/C,eAAE,WA3BzB,IA2BuB,IAAe,kBAAf,IAAe,CAAb;AACvB,SACE,oBAAC,yCAAW,QAAX,EACC,8BAAC,iBAAc,WAAU,iCACvB,8BAAC,WAAQ,WAAU,+WAChB,UACH,GACF,IACF;AAEJ;AAEA,IAAM,eAAqB,iBAGzB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YA1CL,IA0CG,IAAgB,kBAAhB,IAAgB,CAAd;AACH,6BAAC,SAAI,WAAU,mCAAkC,sBAAmB,IAElE;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,OACI;AAAA,EACN,GACF;AAAA,CACD;AAED,aAAa,cAAc,iBAAiB,MAAM;AAElD,IAAM,cAAoB,iBAGxB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YA7DL,IA6DG,IAAgB,kBAAhB,IAAgB,CAAd;AACH;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC;AAAA,MACA,WAAW,GAAG,wDAAwD,SAAS;AAAA,OAC3E;AAAA,EACN;AAAA,CACD;AAED,YAAY,cAAc,iBAAiB,KAAK;AAEhD,IAAM,eAAqB,iBAGzB,CAAC,OAAO,QACR,oBAAC,iBAAiB,OAAjB,iBAAuB,KAAU,WAAU,8BAA+B,MAAO,CACnF;AAED,aAAa,cAAc,iBAAiB,MAAM;AAElD,IAAM,eAAqB,iBAGzB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAnFL,IAmFG,IAAgB,kBAAhB,IAAgB,CAAd;AACH;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,OACI;AAAA,EACN;AAAA,CACD;AAED,aAAa,cAAc,iBAAiB,MAAM;AAElD,IAAM,mBAAyB,iBAG7B,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAnGL,IAmGG,IAAgB,kBAAhB,IAAgB,CAAd;AACH;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC;AAAA,MACA,WAAW,GAAG,wBAAwB,SAAS;AAAA,OAC3C;AAAA,EACN;AAAA,CACD;AACD,iBAAiB,cAAc,iBAAiB,UAAU;AAE1D,IAAM,cAAoB,iBAGxB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YA/GL,IA+GG,IAAgB,kBAAhB,IAAgB,CAAd;AACH;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,OACI;AAAA,EACN;AAAA,CACD;AAED,YAAY,cAAc,iBAAiB,KAAK;AAEhD,IAAM,kBAAkB,CAAC,OAAmE;AAAnE,eAAE,YA5H3B,IA4HyB,IAAgB,kBAAhB,IAAgB,CAAd;AACzB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,yDAAyD,SAAS;AAAA,OAC5E;AAAA,EACN;AAEJ;AACA,gBAAgB,cAAc","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DialogProps } from \"@radix-ui/react-dialog\";\nimport { Command as CommandPrimitive } from \"cmdk\";\nimport { Search } from \"lucide-react\";\n\nimport { cn } from \"../../lib/utils\";\nimport { Dialog, DialogContent } from \"./dialog\";\n\nconst Command = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive\n ref={ref}\n className={cn(\n \"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground\",\n className,\n )}\n {...props}\n />\n));\nCommand.displayName = CommandPrimitive.displayName;\n\ninterface CommandDialogProps extends DialogProps {}\n\nconst CommandDialog = ({ children, ...props }: CommandDialogProps) => {\n return (\n <Dialog {...props}>\n <DialogContent className=\"overflow-hidden p-0 shadow-lg\">\n <Command className=\"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5\">\n {children}\n </Command>\n </DialogContent>\n </Dialog>\n );\n};\n\nconst CommandInput = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Input>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>\n>(({ className, ...props }, ref) => (\n <div className=\"flex items-center border-b px-3\" cmdk-input-wrapper=\"\">\n {/* <Search className=\"mr-2 h-4 w-4 shrink-0 opacity-50\" /> */}\n <CommandPrimitive.Input\n ref={ref}\n className={cn(\n \"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\",\n className,\n )}\n {...props}\n />\n </div>\n));\n\nCommandInput.displayName = CommandPrimitive.Input.displayName;\n\nconst CommandList = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.List>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.List\n ref={ref}\n className={cn(\"max-h-[300px] overflow-y-auto overflow-x-hidden pb-2\", className)}\n {...props}\n />\n));\n\nCommandList.displayName = CommandPrimitive.List.displayName;\n\nconst CommandEmpty = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Empty>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>\n>((props, ref) => (\n <CommandPrimitive.Empty ref={ref} className=\"py-6 text-center text-sm\" {...props} />\n));\n\nCommandEmpty.displayName = CommandPrimitive.Empty.displayName;\n\nconst CommandGroup = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Group>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Group\n ref={ref}\n className={cn(\n \"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\",\n className,\n )}\n {...props}\n />\n));\n\nCommandGroup.displayName = CommandPrimitive.Group.displayName;\n\nconst CommandSeparator = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Separator\n ref={ref}\n className={cn(\"-mx-1 h-px bg-border\", className)}\n {...props}\n />\n));\nCommandSeparator.displayName = CommandPrimitive.Separator.displayName;\n\nconst CommandItem = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Item\n ref={ref}\n className={cn(\n \"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\",\n className,\n )}\n {...props}\n />\n));\n\nCommandItem.displayName = CommandPrimitive.Item.displayName;\n\nconst CommandShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span\n className={cn(\"ml-auto text-xs tracking-widest text-muted-foreground\", className)}\n {...props}\n />\n );\n};\nCommandShortcut.displayName = \"CommandShortcut\";\n\nexport {\n Command,\n CommandDialog,\n CommandInput,\n CommandList,\n CommandEmpty,\n CommandGroup,\n CommandItem,\n CommandShortcut,\n CommandSeparator,\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createContext, useState, useContext } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
5
|
+
var HoveringEditorContext = createContext({
|
|
6
|
+
isDisplayed: false,
|
|
7
|
+
setIsDisplayed: () => {
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
var HoveringEditorProvider = ({ children }) => {
|
|
11
|
+
const [isDisplayed, setIsDisplayed] = useState(false);
|
|
12
|
+
return /* @__PURE__ */ jsx(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
|
|
13
|
+
};
|
|
14
|
+
var useHoveringEditorContext = () => useContext(HoveringEditorContext);
|
|
15
|
+
|
|
16
|
+
export { HoveringEditorProvider, useHoveringEditorContext };
|
|
17
|
+
//# sourceMappingURL=out.js.map
|
|
18
|
+
//# sourceMappingURL=chunk-XV7MLLXQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/hovering-editor-provider.tsx"],"names":[],"mappings":";AAAA,SAAgB,eAAe,UAAU,kBAA6B;AAwBlE;AAjBJ,IAAM,wBAAwB,cAA0C;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AACzB,CAAC;AAUM,IAAM,yBAAgE,CAAC,EAAE,SAAS,MAAM;AAC7F,QAAM,CAAC,aAAa,cAAc,IAAI,SAAkB,KAAK;AAE7D,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,aAAa,eAAe,GAClE,UACH;AAEJ;AAEO,IAAM,2BAA2B,MAAM,WAAW,qBAAqB","sourcesContent":["import React, { createContext, useState, useContext, ReactNode } from \"react\";\n\ninterface HoveringEditorContextProps {\n isDisplayed: boolean;\n setIsDisplayed: (value: boolean) => void;\n}\n\nconst HoveringEditorContext = createContext<HoveringEditorContextProps>({\n isDisplayed: false,\n setIsDisplayed: () => {},\n});\n\nexport interface HoveringEditorProviderProps {\n children: ReactNode;\n}\n\n/**\n * A context provider for the hovering editor over the `CopilotTextarea`\n * (used to edit and insert text into the `CopilotTextarea`).\n */\nexport const HoveringEditorProvider: React.FC<HoveringEditorProviderProps> = ({ children }) => {\n const [isDisplayed, setIsDisplayed] = useState<boolean>(false);\n\n return (\n <HoveringEditorContext.Provider value={{ isDisplayed, setIsDisplayed }}>\n {children}\n </HoveringEditorContext.Provider>\n );\n};\n\nexport const useHoveringEditorContext = () => useContext(HoveringEditorContext);\n"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { HoveringInsertionPromptBox } from './chunk-KNBNKEXR.mjs';
|
|
2
|
+
import { useHoveringEditorContext } from './chunk-XV7MLLXQ.mjs';
|
|
3
|
+
import { Portal, Menu } from './chunk-P4QVFRLY.mjs';
|
|
4
|
+
import { getTextAroundSelection, getFullEditorTextWithNewlines } from './chunk-ECR45NSD.mjs';
|
|
5
|
+
import { useRef, useState, useEffect } from 'react';
|
|
6
|
+
import { Transforms } from 'slate';
|
|
7
|
+
import { useSlate, useSlateSelection } from 'slate-react';
|
|
8
|
+
import { jsx } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var HoveringToolbar = (props) => {
|
|
11
|
+
const ref = useRef(null);
|
|
12
|
+
const editor = useSlate();
|
|
13
|
+
const selection = useSlateSelection();
|
|
14
|
+
const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
|
|
15
|
+
const [isClient, setIsClient] = useState(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setIsClient(true);
|
|
18
|
+
}, []);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const el = ref.current;
|
|
21
|
+
const { selection: selection2 } = editor;
|
|
22
|
+
if (!el) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!selection2) {
|
|
26
|
+
el.removeAttribute("style");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const domSelection = window.getSelection();
|
|
30
|
+
if (!domSelection) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const domRange = domSelection.getRangeAt(0);
|
|
34
|
+
const rect = domRange.getBoundingClientRect();
|
|
35
|
+
if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const minGapFromEdge = 60;
|
|
39
|
+
const verticalOffsetFromCorner = 35;
|
|
40
|
+
const horizontalOffsetFromCorner = 15;
|
|
41
|
+
let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
|
|
42
|
+
if (top < minGapFromEdge) {
|
|
43
|
+
top = rect.bottom + window.scrollY + minGapFromEdge;
|
|
44
|
+
} else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
|
|
45
|
+
top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
|
|
46
|
+
}
|
|
47
|
+
let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
|
|
48
|
+
if (left < minGapFromEdge) {
|
|
49
|
+
left = minGapFromEdge;
|
|
50
|
+
} else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
|
|
51
|
+
left = window.innerWidth - el.offsetWidth - minGapFromEdge;
|
|
52
|
+
}
|
|
53
|
+
el.style.opacity = "1";
|
|
54
|
+
el.style.top = `${top}px`;
|
|
55
|
+
el.style.left = `${left}px`;
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const handleClickOutside = (event) => {
|
|
59
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
60
|
+
setIsDisplayed(false);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
64
|
+
return () => {
|
|
65
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
66
|
+
};
|
|
67
|
+
}, [ref, setIsDisplayed]);
|
|
68
|
+
if (!isClient) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(
|
|
72
|
+
Menu,
|
|
73
|
+
{
|
|
74
|
+
ref,
|
|
75
|
+
className: props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
|
|
76
|
+
children: isDisplayed && selection && /* @__PURE__ */ jsx(
|
|
77
|
+
HoveringInsertionPromptBox,
|
|
78
|
+
{
|
|
79
|
+
editorState: editorState(editor),
|
|
80
|
+
apiConfig: props.apiConfig,
|
|
81
|
+
closeWindow: () => {
|
|
82
|
+
setIsDisplayed(false);
|
|
83
|
+
},
|
|
84
|
+
performInsertion: (insertedText) => {
|
|
85
|
+
console.log("inserted text", insertedText);
|
|
86
|
+
Transforms.delete(editor, { at: selection });
|
|
87
|
+
Transforms.insertText(editor, insertedText, {
|
|
88
|
+
at: selection
|
|
89
|
+
});
|
|
90
|
+
setIsDisplayed(false);
|
|
91
|
+
},
|
|
92
|
+
contextCategories: props.contextCategories
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
) });
|
|
97
|
+
};
|
|
98
|
+
function editorState(editor, selection) {
|
|
99
|
+
const textAroundCursor = getTextAroundSelection(editor);
|
|
100
|
+
if (textAroundCursor) {
|
|
101
|
+
return textAroundCursor;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
textBeforeCursor: getFullEditorTextWithNewlines(editor),
|
|
105
|
+
textAfterCursor: "",
|
|
106
|
+
selectedText: ""
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { HoveringToolbar };
|
|
111
|
+
//# sourceMappingURL=out.js.map
|
|
112
|
+
//# sourceMappingURL=chunk-Y473E2ZQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/hovering-toolbar.tsx"],"names":["selection"],"mappings":";;;;;;;;;;;;;;;;AACA,SAAS,WAAoB,QAAQ,gBAAgB;AACrD,SAAiD,kBAAkB;AACnE,SAAS,UAAU,yBAAyB;AAgHlC;AA7FH,IAAM,kBAAuE,CAAC,UAAU;AAC7F,QAAM,MAAM,OAAuB,IAAI;AACvC,QAAM,SAAS,SAAS;AACxB,QAAM,YAAY,kBAAkB;AACpC,QAAM,EAAE,aAAa,eAAe,IAAI,yBAAyB;AAGjE,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,YAAU,MAAM;AACd,gBAAY,IAAI;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM,KAAK,IAAI;AACf,UAAM,EAAE,WAAAA,WAAU,IAAI;AAEtB,QAAI,CAAC,IAAI;AACP;AAAA,IACF;AAEA,QAAI,CAACA,YAAW;AACd,SAAG,gBAAgB,OAAO;AAC1B;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,aAAa;AACzC,QAAI,CAAC,cAAc;AACjB;AAAA,IACF;AAEA,UAAM,WAAW,aAAa,WAAW,CAAC;AAC1C,UAAM,OAAO,SAAS,sBAAsB;AAM5C,QAAI,KAAK,QAAQ,KAAK,KAAK,SAAS,KAAK,KAAK,UAAU,KAAK,KAAK,WAAW,GAAG;AAC9E;AAAA,IACF;AAEA,UAAM,iBAAiB;AACvB,UAAM,2BAA2B;AACjC,UAAM,6BAA6B;AACnC,QAAI,MAAM,KAAK,MAAM,OAAO,UAAU,GAAG,eAAe;AAExD,QAAI,MAAM,gBAAgB;AACxB,YAAM,KAAK,SAAS,OAAO,UAAU;AAAA,IACvC,WAAW,MAAM,GAAG,eAAe,OAAO,cAAc,gBAAgB;AACtE,YAAM,KAAK,MAAM,OAAO,UAAU,GAAG,eAAe;AAAA,IACtD;AAEA,QAAI,OACF,KAAK,OAAO,OAAO,UAAU,GAAG,cAAc,IAAI,KAAK,QAAQ,IAAI;AAErE,QAAI,OAAO,gBAAgB;AACzB,aAAO;AAAA,IACT,WAAW,OAAO,GAAG,cAAc,OAAO,aAAa,gBAAgB;AACrE,aAAO,OAAO,aAAa,GAAG,cAAc;AAAA,IAC9C;AAEA,OAAG,MAAM,UAAU;AACnB,OAAG,MAAM,MAAM,GAAG;AAClB,OAAG,MAAM,OAAO,GAAG;AAAA,EACrB,CAAC;AAED,YAAU,MAAM;AACd,UAAM,qBAAqB,CAAC,UAAsB;AAChD,UAAI,IAAI,WAAW,CAAC,IAAI,QAAQ,SAAS,MAAM,MAAc,GAAG;AAC9D,uBAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAEA,aAAS,iBAAiB,aAAa,kBAAkB;AACzD,WAAO,MAAM;AACX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAC9D;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,CAAC;AAExB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,SACE,oBAAC,UACC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WACE,MAAM,sBACN;AAAA,MAGD,yBAAe,aACd;AAAA,QAAC;AAAA;AAAA,UACC,aAAa,YAAY,QAAQ,SAAS;AAAA,UAC1C,WAAW,MAAM;AAAA,UACjB,aAAa,MAAM;AACjB,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,kBAAkB,CAAC,iBAAiB;AAClC,oBAAQ,IAAI,iBAAiB,YAAY;AAEzC,uBAAW,OAAO,QAAQ,EAAE,IAAI,UAAU,CAAC;AAC3C,uBAAW,WAAW,QAAQ,cAAc;AAAA,cAC1C,IAAI;AAAA,YACN,CAAC;AACD,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EAEJ,GACF;AAEJ;AAEA,SAAS,YAAY,QAAgB,WAAyC;AAC5E,QAAM,mBAAmB,uBAAuB,MAAM;AACtD,MAAI,kBAAkB;AACpB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,kBAAkB,8BAA8B,MAAM;AAAA,IACtD,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AACF","sourcesContent":["import { css } from \"@emotion/css\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { BaseSelection, Editor, Range, Location, Transforms } from \"slate\";\nimport { useSlate, useSlateSelection } from \"slate-react\";\nimport { HoveringInsertionPromptBox } from \"./text-insertion-prompt-box\";\nimport { Button, Icon, Menu, Portal } from \"./hovering-toolbar-components\";\nimport { useHoveringEditorContext } from \"./hovering-editor-provider\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundSelection,\n} from \"../../lib/get-text-around-cursor\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../types/base/autosuggestions-bare-function\";\n\nexport interface HoveringToolbarProps {\n apiConfig: InsertionEditorApiConfig;\n contextCategories: string[];\n hoverMenuClassname: string | undefined;\n}\n\nexport const HoveringToolbar: (props: HoveringToolbarProps) => JSX.Element | null = (props) => {\n const ref = useRef<HTMLDivElement>(null);\n const editor = useSlate();\n const selection = useSlateSelection();\n const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();\n\n // only render on client\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n setIsClient(true);\n }, []);\n\n useEffect(() => {\n const el = ref.current;\n const { selection } = editor;\n\n if (!el) {\n return;\n }\n\n if (!selection) {\n el.removeAttribute(\"style\");\n return;\n }\n\n const domSelection = window.getSelection();\n if (!domSelection) {\n return;\n }\n\n const domRange = domSelection.getRangeAt(0);\n const rect = domRange.getBoundingClientRect();\n\n // We use window = (0,0,0,0) as a signal that the selection is not in the original copilot-textarea,\n // but inside the hovering window.\n //\n // in such case, we simply do nothing.\n if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {\n return;\n }\n\n const minGapFromEdge = 60;\n const verticalOffsetFromCorner = 35;\n const horizontalOffsetFromCorner = 15;\n let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;\n // make sure top is in the viewport and not too close to the edge\n if (top < minGapFromEdge) {\n top = rect.bottom + window.scrollY + minGapFromEdge;\n } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {\n top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;\n }\n\n let left =\n rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;\n // make sure left is in the viewport and not too close to the edge\n if (left < minGapFromEdge) {\n left = minGapFromEdge;\n } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {\n left = window.innerWidth - el.offsetWidth - minGapFromEdge;\n }\n\n el.style.opacity = \"1\";\n el.style.top = `${top}px`;\n el.style.left = `${left}px`;\n });\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n setIsDisplayed(false);\n }\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [ref, setIsDisplayed]);\n\n if (!isClient) {\n return null;\n }\n\n return (\n <Portal>\n <Menu\n ref={ref}\n className={\n props.hoverMenuClassname ||\n \"p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700\"\n }\n >\n {isDisplayed && selection && (\n <HoveringInsertionPromptBox\n editorState={editorState(editor, selection)}\n apiConfig={props.apiConfig}\n closeWindow={() => {\n setIsDisplayed(false);\n }}\n performInsertion={(insertedText) => {\n console.log(\"inserted text\", insertedText);\n // replace the selection with the inserted text\n Transforms.delete(editor, { at: selection });\n Transforms.insertText(editor, insertedText, {\n at: selection,\n });\n setIsDisplayed(false);\n }}\n contextCategories={props.contextCategories}\n />\n )}\n </Menu>\n </Portal>\n );\n};\n\nfunction editorState(editor: Editor, selection: Location): EditingEditorState {\n const textAroundCursor = getTextAroundSelection(editor);\n if (textAroundCursor) {\n return textAroundCursor;\n }\n\n return {\n textBeforeCursor: getFullEditorTextWithNewlines(editor),\n textAfterCursor: \"\",\n selectedText: \"\",\n };\n}\n"]}
|