@reforma/components 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Composer/RichField.d.ts +6 -2
- package/dist/Composer/RichField.d.ts.map +1 -1
- package/dist/Composer/RichField.js +107 -37
- package/dist/Composer/RichField.js.map +1 -1
- package/dist/Composer/context.d.ts +6 -2
- package/dist/Composer/context.d.ts.map +1 -1
- package/dist/Composer/context.js +158 -130
- package/dist/Composer/context.js.map +1 -1
- package/dist/Composer/index.d.ts +1 -1
- package/dist/Composer/index.d.ts.map +1 -1
- package/dist/Composer/parts.d.ts +18 -17
- package/dist/Composer/parts.d.ts.map +1 -1
- package/dist/Composer/parts.js +283 -187
- package/dist/Composer/parts.js.map +1 -1
- package/dist/Composer/reforma/Composer.module.css +1 -0
- package/dist/Composer/reforma/Composer.module.css.js +60 -0
- package/dist/Composer/reforma/Composer.module.css.js.map +1 -0
- package/dist/Composer/reforma/index.d.ts +4 -0
- package/dist/Composer/reforma/index.d.ts.map +1 -0
- package/dist/Composer/reforma/index.js +6 -0
- package/dist/Composer/reforma/index.js.map +1 -0
- package/dist/Composer/types.d.ts +6 -0
- package/dist/Composer/types.d.ts.map +1 -1
- package/package.json +3 -1
- package/dist/Composer/Composer.module.css +0 -1
- package/dist/Composer/Composer.module.css.js +0 -26
- package/dist/Composer/Composer.module.css.js.map +0 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
import type { ComposerClassNames } from './types';
|
|
3
|
+
/** TipTap field with caller-owned wrapper and editable-element classes. */
|
|
4
|
+
export declare function ComposerRichField({ className, classNames: slots, style, ...props }: HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
classNames?: Pick<ComposerClassNames, 'textareaWrap' | 'editor'>;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
3
7
|
//# sourceMappingURL=RichField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichField.d.ts","sourceRoot":"","sources":["../../src/Composer/RichField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RichField.d.ts","sourceRoot":"","sources":["../../src/Composer/RichField.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,EAC9B,SAAS,EACT,UAAU,EAAE,KAAK,EACjB,KAAK,EACL,GAAG,KAAK,EACX,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG;IAChC,UAAU,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,QAAQ,CAAC,CAAC;CACpE,+BA4FA"}
|
|
@@ -1,44 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import { cn as s } from "@reforma/lib";
|
|
2
|
+
import E from "@tiptap/extension-bold";
|
|
3
|
+
import S from "@tiptap/extension-code";
|
|
4
|
+
import w from "@tiptap/extension-document";
|
|
5
|
+
import F from "@tiptap/extension-hard-break";
|
|
6
|
+
import H from "@tiptap/extension-history";
|
|
7
|
+
import K from "@tiptap/extension-italic";
|
|
8
|
+
import { ListKit as O } from "@tiptap/extension-list";
|
|
9
|
+
import k from "@tiptap/extension-paragraph";
|
|
10
|
+
import v from "@tiptap/extension-placeholder";
|
|
11
|
+
import I from "@tiptap/extension-text";
|
|
12
|
+
import { useEditor as L, EditorContent as R } from "@tiptap/react";
|
|
13
|
+
import { useLayoutEffect as d, useEffect as j } from "react";
|
|
14
|
+
import { docToPlainText as f, plainTextToDoc as u } from "../RichInput/composerDoc.js";
|
|
15
|
+
import { handleComposerKeyDown as B } from "../RichInput/composerKeymap.js";
|
|
16
|
+
import { useComposer as J } from "./context.js";
|
|
17
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
18
|
+
function at({
|
|
19
|
+
className: x,
|
|
20
|
+
classNames: n,
|
|
21
|
+
style: b,
|
|
22
|
+
...m
|
|
23
|
+
}) {
|
|
8
24
|
const {
|
|
9
|
-
value:
|
|
10
|
-
setPrompt:
|
|
11
|
-
submit:
|
|
12
|
-
placeholder:
|
|
13
|
-
autoFocus:
|
|
14
|
-
submitOnEnter:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
value: r,
|
|
26
|
+
setPrompt: y,
|
|
27
|
+
submit: g,
|
|
28
|
+
placeholder: l,
|
|
29
|
+
autoFocus: C,
|
|
30
|
+
submitOnEnter: N,
|
|
31
|
+
focusRef: a,
|
|
32
|
+
addFiles: D,
|
|
33
|
+
pasteTextAsFile: P,
|
|
34
|
+
classNames: i,
|
|
35
|
+
minHeight: T
|
|
36
|
+
} = J(), p = {
|
|
37
|
+
attributes: {
|
|
38
|
+
class: s(i.editor, n?.editor),
|
|
39
|
+
role: "textbox",
|
|
40
|
+
"aria-multiline": "true",
|
|
41
|
+
"aria-label": m["aria-label"] ?? l,
|
|
42
|
+
"aria-placeholder": l,
|
|
43
|
+
"data-slot": "composer-editor"
|
|
44
|
+
},
|
|
45
|
+
handleKeyDown: (t, o) => B(t, o, {
|
|
46
|
+
submitOnEnter: N,
|
|
47
|
+
hasMenuItems: !1,
|
|
48
|
+
onSubmit: () => g()
|
|
49
|
+
}),
|
|
50
|
+
handlePaste: (t, o) => {
|
|
51
|
+
const c = o.clipboardData?.files;
|
|
52
|
+
return c?.length ? (D([...c]), !0) : P(o.clipboardData?.getData("text/plain") ?? "");
|
|
53
|
+
}
|
|
54
|
+
}, e = L({
|
|
55
|
+
immediatelyRender: !1,
|
|
56
|
+
injectCSS: !1,
|
|
57
|
+
autofocus: C && (typeof document > "u" || !document.activeElement?.matches('input, textarea, [contenteditable="true"]')) ? "end" : !1,
|
|
58
|
+
extensions: [w, k, I, F.extend({
|
|
59
|
+
addKeyboardShortcuts: () => ({})
|
|
60
|
+
}), H, E, K, S, O.configure({
|
|
61
|
+
taskItem: !1,
|
|
62
|
+
taskList: !1
|
|
63
|
+
}), v.configure({
|
|
64
|
+
placeholder: ({
|
|
65
|
+
editor: t
|
|
66
|
+
}) => {
|
|
67
|
+
const o = t.options.editorProps.attributes;
|
|
68
|
+
return (typeof o == "function" ? o(t.state) : o)?.["aria-placeholder"] ?? "";
|
|
69
|
+
}
|
|
70
|
+
})],
|
|
71
|
+
content: u(r.prompt),
|
|
72
|
+
editorProps: p,
|
|
73
|
+
onUpdate: ({
|
|
74
|
+
editor: t
|
|
75
|
+
}) => y(f(t.getJSON()))
|
|
76
|
+
});
|
|
77
|
+
return d(() => {
|
|
78
|
+
e?.setOptions({
|
|
79
|
+
editorProps: p
|
|
80
|
+
});
|
|
81
|
+
}), d(() => {
|
|
82
|
+
if (!e)
|
|
83
|
+
return;
|
|
84
|
+
const t = {
|
|
85
|
+
focus: () => {
|
|
86
|
+
e.chain().focus().run();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return a.current = t, () => {
|
|
90
|
+
a.current === t && (a.current = null);
|
|
91
|
+
};
|
|
92
|
+
}, [e, a]), j(() => {
|
|
93
|
+
!e || f(e.getJSON()) === r.prompt || e.chain().setMeta("addToHistory", !1).setContent(u(r.prompt), {
|
|
94
|
+
emitUpdate: !1
|
|
95
|
+
}).run();
|
|
96
|
+
}, [e, r.prompt]), /* @__PURE__ */ h("div", {
|
|
97
|
+
"data-slot": "composer-field-wrapper",
|
|
98
|
+
className: s(i.textareaWrap, n?.textareaWrap),
|
|
99
|
+
children: /* @__PURE__ */ h(R, {
|
|
100
|
+
...m,
|
|
101
|
+
editor: e,
|
|
102
|
+
"data-slot": "composer-rich-field",
|
|
103
|
+
className: s(i.textarea, x),
|
|
104
|
+
style: {
|
|
105
|
+
"--composer-min-height": `${T}px`,
|
|
106
|
+
...b
|
|
107
|
+
}
|
|
38
108
|
})
|
|
39
109
|
});
|
|
40
110
|
}
|
|
41
111
|
export {
|
|
42
|
-
|
|
112
|
+
at as ComposerRichField
|
|
43
113
|
};
|
|
44
114
|
//# sourceMappingURL=RichField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichField.js","sources":["../../src/Composer/RichField.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"RichField.js","sources":["../../src/Composer/RichField.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from '@reforma/lib';\nimport Bold from '@tiptap/extension-bold';\nimport Code from '@tiptap/extension-code';\nimport Document from '@tiptap/extension-document';\nimport HardBreak from '@tiptap/extension-hard-break';\nimport History from '@tiptap/extension-history';\nimport Italic from '@tiptap/extension-italic';\nimport { ListKit } from '@tiptap/extension-list';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport Text from '@tiptap/extension-text';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport { useEffect, useLayoutEffect } from 'react';\n\nimport { docToPlainText, plainTextToDoc } from '../RichInput/composerDoc';\nimport { handleComposerKeyDown } from '../RichInput/composerKeymap';\nimport { useComposer } from './context';\n\nimport type { EditorOptions } from '@tiptap/core';\nimport type { CSSProperties, HTMLAttributes } from 'react';\nimport type { ComposerClassNames } from './types';\n\n/** TipTap field with caller-owned wrapper and editable-element classes. */\nexport function ComposerRichField({\n className,\n classNames: slots,\n style,\n ...props\n}: HTMLAttributes<HTMLDivElement> & {\n classNames?: Pick<ComposerClassNames, 'textareaWrap' | 'editor'>;\n}) {\n const {\n value, setPrompt, submit, placeholder, autoFocus, submitOnEnter,\n focusRef, addFiles, pasteTextAsFile, classNames, minHeight,\n } = useComposer();\n const editorClassName = cn(classNames.editor, slots?.editor);\n const editorProps: EditorOptions['editorProps'] = {\n attributes: {\n class: editorClassName,\n role: 'textbox',\n 'aria-multiline': 'true',\n 'aria-label': props['aria-label'] ?? placeholder,\n 'aria-placeholder': placeholder,\n 'data-slot': 'composer-editor',\n },\n handleKeyDown: (view, event) => handleComposerKeyDown(view, event, {\n submitOnEnter,\n hasMenuItems: false,\n onSubmit: () => submit(),\n }),\n handlePaste: (_view, event) => {\n const files = event.clipboardData?.files;\n if (files?.length) {\n addFiles([...files]);\n return true;\n }\n return pasteTextAsFile(event.clipboardData?.getData('text/plain') ?? '');\n },\n };\n const editor = useEditor({\n immediatelyRender: false,\n injectCSS: false,\n autofocus: autoFocus && (typeof document === 'undefined' || !document.activeElement?.matches('input, textarea, [contenteditable=\"true\"]')) ? 'end' : false,\n extensions: [\n Document,\n Paragraph,\n Text,\n HardBreak.extend({ addKeyboardShortcuts: () => ({}) }),\n History,\n Bold,\n Italic,\n Code,\n ListKit.configure({ taskItem: false, taskList: false }),\n Placeholder.configure({ placeholder: ({ editor: current }) => {\n const attributes = current.options.editorProps.attributes;\n return (typeof attributes === 'function' ? attributes(current.state) : attributes)?.['aria-placeholder'] ?? '';\n } }),\n ],\n content: plainTextToDoc(value.prompt),\n editorProps,\n onUpdate: ({ editor: current }) => setPrompt(docToPlainText(current.getJSON())),\n });\n\n useLayoutEffect(() => {\n editor?.setOptions({ editorProps });\n });\n\n useLayoutEffect(() => {\n if (!editor) {\n return;\n }\n const handle = { focus: () => {\n editor.chain().focus().run();\n } };\n focusRef.current = handle;\n return () => {\n if (focusRef.current === handle) {\n focusRef.current = null;\n }\n };\n }, [editor, focusRef]);\n\n useEffect(() => {\n if (!editor || docToPlainText(editor.getJSON()) === value.prompt) {\n return;\n }\n // Host resets do not become undo steps; local edits keep their rich document.\n editor.chain().setMeta('addToHistory', false)\n .setContent(plainTextToDoc(value.prompt), { emitUpdate: false }).run();\n }, [editor, value.prompt]);\n\n return (\n <div data-slot=\"composer-field-wrapper\" className={ cn(classNames.textareaWrap, slots?.textareaWrap) }>\n <EditorContent\n { ...props }\n editor={ editor }\n data-slot=\"composer-rich-field\"\n className={ cn(classNames.textarea, className) }\n style={ { '--composer-min-height': `${ minHeight }px`, ...style } as CSSProperties }\n />\n </div>\n );\n}\n"],"names":["ComposerRichField","className","slots","style","props","value","setPrompt","submit","placeholder","autoFocus","submitOnEnter","focusRef","addFiles","pasteTextAsFile","classNames","minHeight","useComposer","editorProps","cn","view","event","handleComposerKeyDown","_view","files","editor","useEditor","Document","Paragraph","Text","HardBreak","History","Bold","Italic","Code","ListKit","Placeholder","current","attributes","plainTextToDoc","docToPlainText","useLayoutEffect","handle","useEffect","EditorContent"],"mappings":";;;;;;;;;;;;;;;;;AAoBO,SAASA,GAAkB;AAAA,EAChC,WAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,OAAAC;AAAA,EACA,GAAGC;AACL,GAAG;AACD,QAAM;AAAA,IACJ,OAAAC;AAAA,IACA,WAAAC;AAAA,IACA,QAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,WAAAC;AAAA,EAAA,IACEC,EAAA,GAEEC,IAAc;AAAA,IAClB,YAAY;AAAA,MACV,OAHoBC,EAAGJ,EAAW,QAAQZ,GAAO,MAAM;AAAA,MAIvD,MAAM;AAAA,MACN,kBAAkB;AAAA,MAClB,cAAcE,EAAM,YAAY,KAAKI;AAAA,MACrC,oBAAoBA;AAAA,MACpB,aAAa;AAAA,IAAA;AAAA,IAEf,eAAe,CAACW,GAAMC,MAAUC,EAAsBF,GAAMC,GAAO;AAAA,M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S;AAAA,MACb,OAAO,MAAM;AACX,QAAAjB,EAAO,MAAA,EAAQ,MAAA,EAAQ,IAAA;AAAA,MACzB;AAAA,IAAA;AAEF,WAAAb,EAAS,UAAU8B,GACZ,MAAM;AACX,MAAI9B,EAAS,YAAY8B,MACvB9B,EAAS,UAAU;AAAA,IAEvB;AAAA,EACF,GAAG,CAACa,GAAQb,CAAQ,CAAC,GACrB+B,EAAU,MAAM;AACd,IAAI,CAAClB,KAAUe,EAAef,EAAO,SAAS,MAAMnB,EAAM,UAI1DmB,EAAO,MAAA,EAAQ,QAAQ,gBAAgB,EAAK,EAAE,WAAWc,EAAejC,EAAM,MAAM,GAAG;AAAA,MACrF,YAAY;AAAA,IAAA,CACb,EAAE,IAAA;AAAA,EACL,GAAG,CAACmB,GAAQnB,EAAM,MAAM,CAAC,qBACA,OAAO;AAAA,IAC9B,aAAa;AAAA,IACb,WAAWa,EAAGJ,EAAW,cAAcZ,GAAO,YAAY;AAAA,IAC1D,4BAA4ByC,GAAe;AAAA,MACzC,GAAGvC;AAAA,MACH,QAAAoB;AAAA,MACA,aAAa;AAAA,MACb,WAAWN,EAAGJ,EAAW,UAAUb,CAAS;AAAA,MAC5C,OAAO;AAAA,QACL,yBAAyB,GAAGc,CAAS;AAAA,QACrC,GAAGZ;AAAA,MAAA;AAAA,IACL,CACD;AAAA,EAAA,CACF;AACH;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type ReactNode, type RefObject } from 'react';
|
|
2
2
|
import { useFileDrag } from '../hooks/useFileDrag';
|
|
3
|
-
import type { ComposerUploadResult, ComposerValue } from './types';
|
|
3
|
+
import type { ComposerClassNames, ComposerNotice, ComposerUploadResult, ComposerValue } from './types';
|
|
4
4
|
export type ComposerFieldHandle = {
|
|
5
5
|
focus: () => void;
|
|
6
6
|
};
|
|
7
7
|
export type ComposerContextValue = {
|
|
8
|
+
classNames: ComposerClassNames;
|
|
8
9
|
value: ComposerValue;
|
|
9
10
|
setPrompt: (prompt: string) => void;
|
|
10
11
|
setPlanMode: (planMode: boolean) => void;
|
|
@@ -28,6 +29,9 @@ export type ComposerContextValue = {
|
|
|
28
29
|
};
|
|
29
30
|
export declare function useComposer(): ComposerContextValue;
|
|
30
31
|
export type ComposerProviderProps = {
|
|
32
|
+
classNames?: ComposerClassNames;
|
|
33
|
+
/** Report validation errors in the host UI. Defaults to an inline alert. */
|
|
34
|
+
onError?: (notice: ComposerNotice) => void;
|
|
31
35
|
value: ComposerValue;
|
|
32
36
|
onChange: (value: ComposerValue) => void;
|
|
33
37
|
onSubmit: () => void;
|
|
@@ -40,5 +44,5 @@ export type ComposerProviderProps = {
|
|
|
40
44
|
rows?: number;
|
|
41
45
|
children: ReactNode;
|
|
42
46
|
};
|
|
43
|
-
export declare function ComposerProvider({ value, onChange, onSubmit, uploadFile, busy, placeholder, autoFocus, submitHotkey, rows, children, }: ComposerProviderProps): import("react").JSX.Element;
|
|
47
|
+
export declare function ComposerProvider({ classNames, onError, value, onChange, onSubmit, uploadFile, busy, placeholder, autoFocus, submitHotkey, rows, children, }: ComposerProviderProps): import("react").JSX.Element;
|
|
44
48
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/Composer/context.tsx"],"names":[],"mappings":"AASA,OAAO,EAQH,KAAK,SAAS,EACd,KAAK,SAAS,EACjB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,KAAK,EAER,oBAAoB,EACpB,aAAa,EAChB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,mBAAmB,GAAG;IAC9B,KAAK,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,WAAW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GACX,EAAE,qBAAqB,+BAoQvB"}
|
package/dist/Composer/context.js
CHANGED
|
@@ -1,70 +1,91 @@
|
|
|
1
|
-
import { coerceUploadMimeType as
|
|
2
|
-
import { revokeObjectURL as
|
|
3
|
-
import {
|
|
4
|
-
import { useFileDrag as
|
|
5
|
-
import {
|
|
6
|
-
import { jsxs as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
1
|
+
import { coerceUploadMimeType as x, MAX_CHAT_ATTACHMENT_BYTES_PER_FILE as S, MAX_CHAT_ATTACHMENT_BYTES_TOTAL as O, COMPOSER_PASTE_AS_FILE_MIN_CHARS as Z } from "@reforma/constants";
|
|
2
|
+
import { revokeObjectURL as C, formatFileSize as P, createObjectURL as ee } from "@reforma/lib";
|
|
3
|
+
import { useState as k, useCallback as y, useRef as f, useLayoutEffect as B, useEffect as te, use as re, createContext as ne } from "react";
|
|
4
|
+
import { useFileDrag as oe } from "../hooks/useFileDrag.js";
|
|
5
|
+
import { Show as se } from "../Show/Show.js";
|
|
6
|
+
import { jsxs as D, jsx as H } from "react/jsx-runtime";
|
|
7
|
+
const L = /* @__PURE__ */ ne(null);
|
|
8
|
+
function fe() {
|
|
9
|
+
const s = re(L);
|
|
10
|
+
if (!s)
|
|
11
11
|
throw new Error("Composer pieces must render inside ComposerProvider");
|
|
12
|
-
return o;
|
|
13
|
-
}
|
|
14
|
-
function Z(o) {
|
|
15
|
-
let s = 0;
|
|
16
|
-
for (const c of o)
|
|
17
|
-
typeof c.size == "number" && Number.isFinite(c.size) && (s += c.size);
|
|
18
12
|
return s;
|
|
19
13
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
14
|
+
function ae(s) {
|
|
15
|
+
let a = 0;
|
|
16
|
+
for (const i of s)
|
|
17
|
+
typeof i.size == "number" && Number.isFinite(i.size) && (a += i.size);
|
|
18
|
+
return a;
|
|
19
|
+
}
|
|
20
|
+
function ie(s) {
|
|
21
|
+
return s.length === 0 ? !0 : s.every((a) => a.uploadStatus === "ready" && !!a.url);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function E(s, a, i) {
|
|
24
24
|
return {
|
|
25
|
-
...
|
|
26
|
-
attachments:
|
|
25
|
+
...s,
|
|
26
|
+
attachments: s.attachments.map((m) => m.clientId === a ? {
|
|
27
27
|
...m,
|
|
28
|
-
...
|
|
28
|
+
...i
|
|
29
29
|
} : m)
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
function he({
|
|
33
|
+
classNames: s = {},
|
|
34
|
+
onError: a,
|
|
35
|
+
value: i,
|
|
36
|
+
onChange: m,
|
|
37
|
+
onSubmit: U,
|
|
38
|
+
uploadFile: _,
|
|
39
|
+
busy: z = !1,
|
|
40
|
+
placeholder: I = "What should it do?",
|
|
41
|
+
autoFocus: N = !0,
|
|
42
|
+
submitHotkey: j = "mod+enter",
|
|
43
|
+
rows: A = 3,
|
|
44
|
+
children: $
|
|
43
45
|
}) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const [v, R] = k(null), h = y((e) => {
|
|
47
|
+
a ? a(e) : R(e);
|
|
48
|
+
}, [a]), w = f(null), F = f(null), c = f(i), M = f(m), d = f(/* @__PURE__ */ new Map()), [X, Y] = k(!1);
|
|
49
|
+
B(() => {
|
|
50
|
+
c.current = i;
|
|
51
|
+
}, [i]), B(() => {
|
|
52
|
+
M.current = m;
|
|
53
|
+
}, [m]);
|
|
54
|
+
const l = y((e) => {
|
|
55
|
+
c.current = e, M.current(e);
|
|
56
|
+
}, []);
|
|
57
|
+
te(() => {
|
|
58
|
+
const e = d.current;
|
|
49
59
|
return () => {
|
|
50
|
-
for (const n of
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
for (const n of c.current.attachments)
|
|
61
|
+
C(n.preview);
|
|
62
|
+
e.clear();
|
|
53
63
|
};
|
|
54
64
|
}, []);
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
const b = !!i.prompt.trim() && ie(i.attachments) && !z, T = y(async (e, n) => {
|
|
66
|
+
let r;
|
|
67
|
+
try {
|
|
68
|
+
r = await _(n);
|
|
69
|
+
} catch (u) {
|
|
70
|
+
r = {
|
|
71
|
+
ok: !1,
|
|
72
|
+
message: u instanceof Error ? u.message : void 0
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (d.current.get(e) !== n)
|
|
76
|
+
return;
|
|
77
|
+
const o = c.current;
|
|
78
|
+
if (!o.attachments.some((u) => u.clientId === e)) {
|
|
79
|
+
d.current.delete(e);
|
|
59
80
|
return;
|
|
60
81
|
}
|
|
61
82
|
if (r.ok) {
|
|
62
|
-
const u =
|
|
63
|
-
|
|
83
|
+
const u = o.attachments.find((p) => p.clientId === e)?.preview;
|
|
84
|
+
C(u), d.current.delete(e), l(E(o, e, {
|
|
64
85
|
id: r.data.id,
|
|
65
86
|
url: r.data.url,
|
|
66
87
|
filename: r.data.name ?? n.name,
|
|
67
|
-
mediaType: r.data.mimeType ??
|
|
88
|
+
mediaType: r.data.mimeType ?? x(n.name, n.type),
|
|
68
89
|
size: r.data.size ?? n.size,
|
|
69
90
|
uploadStatus: "ready",
|
|
70
91
|
uploadError: void 0,
|
|
@@ -72,134 +93,141 @@ function ct({
|
|
|
72
93
|
}));
|
|
73
94
|
return;
|
|
74
95
|
}
|
|
75
|
-
|
|
96
|
+
l(E(o, e, {
|
|
76
97
|
uploadStatus: "error",
|
|
77
98
|
uploadError: r.message ?? "Upload failed"
|
|
78
99
|
}));
|
|
79
|
-
}, [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
}, [l, _]), g = y((e) => {
|
|
101
|
+
R(null);
|
|
102
|
+
const n = [...e], r = [];
|
|
103
|
+
let o = 0;
|
|
104
|
+
const u = ae(c.current.attachments);
|
|
105
|
+
for (const t of n) {
|
|
106
|
+
if (t.size > S) {
|
|
107
|
+
h({
|
|
86
108
|
title: "Attachment too large",
|
|
87
|
-
message: `${
|
|
109
|
+
message: `${t.name} is over the ${P(S, {
|
|
88
110
|
round: "up"
|
|
89
111
|
})} per-file limit.`
|
|
90
112
|
});
|
|
91
113
|
continue;
|
|
92
114
|
}
|
|
93
|
-
if (u +
|
|
94
|
-
|
|
115
|
+
if (u + o + t.size > O) {
|
|
116
|
+
h({
|
|
95
117
|
title: "Attachments too large",
|
|
96
|
-
message: `Adding ${
|
|
118
|
+
message: `Adding ${t.name} would exceed the ${P(O, {
|
|
97
119
|
round: "up"
|
|
98
120
|
})} combined limit.`
|
|
99
121
|
});
|
|
100
122
|
continue;
|
|
101
123
|
}
|
|
102
|
-
r.push(
|
|
124
|
+
r.push(t), o += t.size;
|
|
103
125
|
}
|
|
104
126
|
if (r.length === 0)
|
|
105
127
|
return;
|
|
106
|
-
const
|
|
128
|
+
const p = r.map((t) => ({
|
|
107
129
|
clientId: crypto.randomUUID(),
|
|
108
|
-
filename:
|
|
109
|
-
mediaType:
|
|
110
|
-
size:
|
|
111
|
-
lastModified:
|
|
130
|
+
filename: t.name,
|
|
131
|
+
mediaType: x(t.name, t.type),
|
|
132
|
+
size: t.size,
|
|
133
|
+
lastModified: t.lastModified,
|
|
112
134
|
uploadStatus: "uploading",
|
|
113
|
-
preview:
|
|
135
|
+
preview: ee(t) ?? void 0
|
|
114
136
|
}));
|
|
115
|
-
for (let
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
...
|
|
119
|
-
attachments: [...
|
|
137
|
+
for (let t = 0; t < r.length; t++)
|
|
138
|
+
d.current.set(p[t].clientId, r[t]);
|
|
139
|
+
const Q = {
|
|
140
|
+
...c.current,
|
|
141
|
+
attachments: [...c.current.attachments, ...p]
|
|
120
142
|
};
|
|
121
|
-
|
|
122
|
-
for (let
|
|
123
|
-
|
|
124
|
-
}, [
|
|
125
|
-
onFileDragOver:
|
|
126
|
-
onFilesDropped: (
|
|
127
|
-
}),
|
|
128
|
-
const n =
|
|
129
|
-
|
|
143
|
+
l(Q);
|
|
144
|
+
for (let t = 0; t < r.length; t++)
|
|
145
|
+
T(p[t].clientId, r[t]);
|
|
146
|
+
}, [l, T, h]), V = oe({
|
|
147
|
+
onFileDragOver: Y,
|
|
148
|
+
onFilesDropped: (e) => g(e)
|
|
149
|
+
}), W = (e) => {
|
|
150
|
+
const n = c.current, r = n.attachments.find((o) => o.clientId === e);
|
|
151
|
+
C(r?.preview), d.current.delete(e), l({
|
|
130
152
|
...n,
|
|
131
|
-
attachments: n.attachments.filter((
|
|
153
|
+
attachments: n.attachments.filter((o) => o.clientId !== e)
|
|
132
154
|
});
|
|
133
|
-
},
|
|
134
|
-
const n =
|
|
155
|
+
}, q = (e) => {
|
|
156
|
+
const n = c.current, r = n.attachments.find((u) => u.clientId === e), o = d.current.get(e);
|
|
135
157
|
if (!(!r || r.uploadStatus !== "error")) {
|
|
136
|
-
if (!
|
|
137
|
-
|
|
158
|
+
if (!o) {
|
|
159
|
+
h({
|
|
138
160
|
title: "Could not retry",
|
|
139
161
|
message: "Remove the file and attach it again."
|
|
140
162
|
});
|
|
141
163
|
return;
|
|
142
164
|
}
|
|
143
|
-
|
|
165
|
+
l(E(n, e, {
|
|
144
166
|
uploadStatus: "uploading",
|
|
145
167
|
uploadError: void 0
|
|
146
|
-
})),
|
|
168
|
+
})), T(e, o);
|
|
147
169
|
}
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
},
|
|
151
|
-
if (
|
|
170
|
+
}, G = () => {
|
|
171
|
+
b && U();
|
|
172
|
+
}, J = (e) => {
|
|
173
|
+
if (e.length < Z)
|
|
152
174
|
return !1;
|
|
153
|
-
const n = new File([
|
|
175
|
+
const n = new File([e], "paste.txt", {
|
|
154
176
|
type: "text/plain"
|
|
155
177
|
});
|
|
156
|
-
return n.size >
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
178
|
+
return n.size > S ? !1 : (g([n]), !0);
|
|
179
|
+
}, K = {
|
|
180
|
+
classNames: s,
|
|
181
|
+
value: i,
|
|
182
|
+
setPrompt: (e) => l({
|
|
183
|
+
...c.current,
|
|
184
|
+
prompt: e
|
|
162
185
|
}),
|
|
163
|
-
setPlanMode: (
|
|
164
|
-
...
|
|
165
|
-
planMode:
|
|
186
|
+
setPlanMode: (e) => l({
|
|
187
|
+
...c.current,
|
|
188
|
+
planMode: e
|
|
166
189
|
}),
|
|
167
|
-
addFiles:
|
|
168
|
-
removeAttachment:
|
|
169
|
-
retryAttachment:
|
|
170
|
-
submit:
|
|
171
|
-
canSubmit:
|
|
172
|
-
busy:
|
|
173
|
-
placeholder:
|
|
174
|
-
autoFocus:
|
|
175
|
-
submitOnEnter:
|
|
176
|
-
rows:
|
|
177
|
-
minHeight:
|
|
178
|
-
pasteTextAsFile:
|
|
179
|
-
openFilePicker: () =>
|
|
180
|
-
focus: () =>
|
|
181
|
-
focusRef:
|
|
182
|
-
fileDragOver:
|
|
183
|
-
drag:
|
|
190
|
+
addFiles: g,
|
|
191
|
+
removeAttachment: W,
|
|
192
|
+
retryAttachment: q,
|
|
193
|
+
submit: G,
|
|
194
|
+
canSubmit: b,
|
|
195
|
+
busy: z,
|
|
196
|
+
placeholder: I,
|
|
197
|
+
autoFocus: N,
|
|
198
|
+
submitOnEnter: j === "enter",
|
|
199
|
+
rows: A,
|
|
200
|
+
minHeight: A ? A * 22 : 20,
|
|
201
|
+
pasteTextAsFile: J,
|
|
202
|
+
openFilePicker: () => w.current?.click(),
|
|
203
|
+
focus: () => F.current?.focus(),
|
|
204
|
+
focusRef: F,
|
|
205
|
+
fileDragOver: X,
|
|
206
|
+
drag: V
|
|
184
207
|
};
|
|
185
|
-
return /* @__PURE__ */
|
|
186
|
-
value:
|
|
187
|
-
children: [
|
|
188
|
-
|
|
208
|
+
return /* @__PURE__ */ D(L, {
|
|
209
|
+
value: K,
|
|
210
|
+
children: [$, /* @__PURE__ */ H(se, {
|
|
211
|
+
when: v && !a,
|
|
212
|
+
children: /* @__PURE__ */ D("p", {
|
|
213
|
+
role: "alert",
|
|
214
|
+
className: s.notice,
|
|
215
|
+
children: [v?.title, ": ", v?.message]
|
|
216
|
+
})
|
|
217
|
+
}), /* @__PURE__ */ H("input", {
|
|
218
|
+
ref: w,
|
|
189
219
|
type: "file",
|
|
190
220
|
multiple: !0,
|
|
191
221
|
tabIndex: -1,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
onChange: (t) => {
|
|
196
|
-
t.target.files?.length && p(t.target.files), t.target.value = "";
|
|
222
|
+
hidden: !0,
|
|
223
|
+
onChange: (e) => {
|
|
224
|
+
e.target.files?.length && g(e.target.files), e.target.value = "";
|
|
197
225
|
}
|
|
198
226
|
})]
|
|
199
227
|
});
|
|
200
228
|
}
|
|
201
229
|
export {
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
he as ComposerProvider,
|
|
231
|
+
fe as useComposer
|
|
204
232
|
};
|
|
205
233
|
//# sourceMappingURL=context.js.map
|