@assistant-ui/vue 0.0.0 → 0.0.1
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/LICENSE +21 -0
- package/README.md +90 -2
- package/dist/AuiIf.d.ts +27 -0
- package/dist/AuiIf.d.ts.map +1 -0
- package/dist/AuiIf.js +30 -0
- package/dist/AuiIf.js.map +1 -0
- package/dist/AuiProvider.d.ts +41 -0
- package/dist/AuiProvider.d.ts.map +1 -0
- package/dist/AuiProvider.js +61 -0
- package/dist/AuiProvider.js.map +1 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +17 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/primitives/AttachmentByIndexProvider.d.ts +30 -0
- package/dist/primitives/AttachmentByIndexProvider.d.ts.map +1 -0
- package/dist/primitives/AttachmentByIndexProvider.js +63 -0
- package/dist/primitives/AttachmentByIndexProvider.js.map +1 -0
- package/dist/primitives/ChainOfThoughtPrimitiveAccordionTrigger.d.ts +11 -0
- package/dist/primitives/ChainOfThoughtPrimitiveAccordionTrigger.d.ts.map +1 -0
- package/dist/primitives/ChainOfThoughtPrimitiveAccordionTrigger.js +31 -0
- package/dist/primitives/ChainOfThoughtPrimitiveAccordionTrigger.js.map +1 -0
- package/dist/primitives/ChainOfThoughtPrimitiveParts.d.ts +19 -0
- package/dist/primitives/ChainOfThoughtPrimitiveParts.d.ts.map +1 -0
- package/dist/primitives/ChainOfThoughtPrimitiveParts.js +85 -0
- package/dist/primitives/ChainOfThoughtPrimitiveParts.js.map +1 -0
- package/dist/primitives/ComposerPrimitiveCancel.d.ts +12 -0
- package/dist/primitives/ComposerPrimitiveCancel.d.ts.map +1 -0
- package/dist/primitives/ComposerPrimitiveCancel.js +33 -0
- package/dist/primitives/ComposerPrimitiveCancel.js.map +1 -0
- package/dist/primitives/ComposerPrimitiveInput.d.ts +26 -0
- package/dist/primitives/ComposerPrimitiveInput.d.ts.map +1 -0
- package/dist/primitives/ComposerPrimitiveInput.js +57 -0
- package/dist/primitives/ComposerPrimitiveInput.js.map +1 -0
- package/dist/primitives/ComposerPrimitiveSend.d.ts +13 -0
- package/dist/primitives/ComposerPrimitiveSend.d.ts.map +1 -0
- package/dist/primitives/ComposerPrimitiveSend.js +31 -0
- package/dist/primitives/ComposerPrimitiveSend.js.map +1 -0
- package/dist/primitives/MessageByIdProvider.d.ts +23 -0
- package/dist/primitives/MessageByIdProvider.d.ts.map +1 -0
- package/dist/primitives/MessageByIdProvider.js +70 -0
- package/dist/primitives/MessageByIdProvider.js.map +1 -0
- package/dist/primitives/MessagePrimitiveParts.d.ts +50 -0
- package/dist/primitives/MessagePrimitiveParts.d.ts.map +1 -0
- package/dist/primitives/MessagePrimitiveParts.js +93 -0
- package/dist/primitives/MessagePrimitiveParts.js.map +1 -0
- package/dist/primitives/PartByIndexProvider.d.ts +21 -0
- package/dist/primitives/PartByIndexProvider.d.ts.map +1 -0
- package/dist/primitives/PartByIndexProvider.js +50 -0
- package/dist/primitives/PartByIndexProvider.js.map +1 -0
- package/dist/primitives/ThreadListItemPrimitiveRoot.d.ts +7 -0
- package/dist/primitives/ThreadListItemPrimitiveRoot.d.ts.map +1 -0
- package/dist/primitives/ThreadListItemPrimitiveRoot.js +36 -0
- package/dist/primitives/ThreadListItemPrimitiveRoot.js.map +1 -0
- package/dist/primitives/ThreadListItemPrimitiveTrigger.d.ts +14 -0
- package/dist/primitives/ThreadListItemPrimitiveTrigger.d.ts.map +1 -0
- package/dist/primitives/ThreadListItemPrimitiveTrigger.js +58 -0
- package/dist/primitives/ThreadListItemPrimitiveTrigger.js.map +1 -0
- package/dist/primitives/ThreadListPrimitiveRoot.d.ts +7 -0
- package/dist/primitives/ThreadListPrimitiveRoot.d.ts.map +1 -0
- package/dist/primitives/ThreadListPrimitiveRoot.js +16 -0
- package/dist/primitives/ThreadListPrimitiveRoot.js.map +1 -0
- package/dist/primitives/ThreadPrimitiveMessages.d.ts +23 -0
- package/dist/primitives/ThreadPrimitiveMessages.d.ts.map +1 -0
- package/dist/primitives/ThreadPrimitiveMessages.js +37 -0
- package/dist/primitives/ThreadPrimitiveMessages.js.map +1 -0
- package/dist/primitives/ThreadPrimitiveScrollToBottom.d.ts +25 -0
- package/dist/primitives/ThreadPrimitiveScrollToBottom.d.ts.map +1 -0
- package/dist/primitives/ThreadPrimitiveScrollToBottom.js +43 -0
- package/dist/primitives/ThreadPrimitiveScrollToBottom.js.map +1 -0
- package/dist/primitives/ThreadPrimitiveViewport.d.ts +57 -0
- package/dist/primitives/ThreadPrimitiveViewport.d.ts.map +1 -0
- package/dist/primitives/ThreadPrimitiveViewport.js +174 -0
- package/dist/primitives/ThreadPrimitiveViewport.js.map +1 -0
- package/dist/primitives/ThreadPrimitiveViewportFooter.d.ts +13 -0
- package/dist/primitives/ThreadPrimitiveViewportFooter.d.ts.map +1 -0
- package/dist/primitives/ThreadPrimitiveViewportFooter.js +46 -0
- package/dist/primitives/ThreadPrimitiveViewportFooter.js.map +1 -0
- package/dist/primitives/actionBar.d.ts +41 -0
- package/dist/primitives/actionBar.d.ts.map +1 -0
- package/dist/primitives/actionBar.js +110 -0
- package/dist/primitives/actionBar.js.map +1 -0
- package/dist/primitives/attachment.d.ts +27 -0
- package/dist/primitives/attachment.d.ts.map +1 -0
- package/dist/primitives/attachment.js +63 -0
- package/dist/primitives/attachment.js.map +1 -0
- package/dist/primitives/attrDisabled.d.ts +2 -0
- package/dist/primitives/attrDisabled.d.ts.map +1 -0
- package/dist/primitives/attrDisabled.js +6 -0
- package/dist/primitives/attrDisabled.js.map +1 -0
- package/dist/primitives/branchPicker.d.ts +18 -0
- package/dist/primitives/branchPicker.d.ts.map +1 -0
- package/dist/primitives/branchPicker.js +48 -0
- package/dist/primitives/branchPicker.js.map +1 -0
- package/dist/primitives/composerAttachments.d.ts +57 -0
- package/dist/primitives/composerAttachments.d.ts.map +1 -0
- package/dist/primitives/composerAttachments.js +132 -0
- package/dist/primitives/composerAttachments.js.map +1 -0
- package/dist/primitives/error.d.ts +15 -0
- package/dist/primitives/error.d.ts.map +1 -0
- package/dist/primitives/error.js +29 -0
- package/dist/primitives/error.js.map +1 -0
- package/dist/primitives/lastValidCache.d.ts +6 -0
- package/dist/primitives/lastValidCache.d.ts.map +1 -0
- package/dist/primitives/lastValidCache.js +9 -0
- package/dist/primitives/lastValidCache.js.map +1 -0
- package/dist/primitives/message.d.ts +12 -0
- package/dist/primitives/message.d.ts.map +1 -0
- package/dist/primitives/message.js +44 -0
- package/dist/primitives/message.js.map +1 -0
- package/dist/primitives/messageAttachments.d.ts +12 -0
- package/dist/primitives/messageAttachments.d.ts.map +1 -0
- package/dist/primitives/messageAttachments.js +27 -0
- package/dist/primitives/messageAttachments.js.map +1 -0
- package/dist/primitives/stableKeys.d.ts +5 -0
- package/dist/primitives/stableKeys.d.ts.map +1 -0
- package/dist/primitives/stableKeys.js +14 -0
- package/dist/primitives/stableKeys.js.map +1 -0
- package/dist/primitives/suggestions.d.ts +66 -0
- package/dist/primitives/suggestions.d.ts.map +1 -0
- package/dist/primitives/suggestions.js +137 -0
- package/dist/primitives/suggestions.js.map +1 -0
- package/dist/primitives/thread.d.ts +11 -0
- package/dist/primitives/thread.d.ts.map +1 -0
- package/dist/primitives/thread.js +37 -0
- package/dist/primitives/thread.js.map +1 -0
- package/dist/primitives/threadList.d.ts +82 -0
- package/dist/primitives/threadList.d.ts.map +1 -0
- package/dist/primitives/threadList.js +128 -0
- package/dist/primitives/threadList.js.map +1 -0
- package/dist/primitives/threadListFocusGroup.d.ts +14 -0
- package/dist/primitives/threadListFocusGroup.d.ts.map +1 -0
- package/dist/primitives/threadListFocusGroup.js +32 -0
- package/dist/primitives/threadListFocusGroup.js.map +1 -0
- package/dist/primitives/threadListStructural.d.ts +29 -0
- package/dist/primitives/threadListStructural.d.ts.map +1 -0
- package/dist/primitives/threadListStructural.js +55 -0
- package/dist/primitives/threadListStructural.js.map +1 -0
- package/dist/primitives/useComposerSendState.d.ts +6 -0
- package/dist/primitives/useComposerSendState.d.ts.map +1 -0
- package/dist/primitives/useComposerSendState.js +15 -0
- package/dist/primitives/useComposerSendState.js.map +1 -0
- package/dist/primitives/viewportContext.d.ts +12 -0
- package/dist/primitives/viewportContext.d.ts.map +1 -0
- package/dist/primitives/viewportContext.js +6 -0
- package/dist/primitives/viewportContext.js.map +1 -0
- package/dist/useAui.d.ts +15 -0
- package/dist/useAui.d.ts.map +1 -0
- package/dist/useAui.js +21 -0
- package/dist/useAui.js.map +1 -0
- package/dist/useAuiEvent.d.ts +17 -0
- package/dist/useAuiEvent.d.ts.map +1 -0
- package/dist/useAuiEvent.js +52 -0
- package/dist/useAuiEvent.js.map +1 -0
- package/dist/useAuiState.d.ts +23 -0
- package/dist/useAuiState.d.ts.map +1 -0
- package/dist/useAuiState.js +42 -0
- package/dist/useAuiState.js.map +1 -0
- package/dist/useScrollLock.d.ts +3 -0
- package/dist/useScrollLock.d.ts.map +1 -0
- package/dist/useScrollLock.js +53 -0
- package/dist/useScrollLock.js.map +1 -0
- package/package.json +57 -6
- package/src/AuiIf.ts +34 -0
- package/src/AuiProvider.ts +90 -0
- package/src/__tests__/AuiIf.test.ts +54 -0
- package/src/__tests__/AuiProvider.test.ts +266 -0
- package/src/__tests__/byindex-shrink-race.test.ts +411 -0
- package/src/__tests__/dist-graph.test.ts +49 -0
- package/src/__tests__/fixtures.ts +51 -0
- package/src/__tests__/primitives-actionbar.test.ts +469 -0
- package/src/__tests__/primitives-attachment.test.ts +493 -0
- package/src/__tests__/primitives-content.test.ts +749 -0
- package/src/__tests__/primitives-keyed-items.test.ts +270 -0
- package/src/__tests__/primitives-keyed-messages.test.ts +264 -0
- package/src/__tests__/primitives-structural.test.ts +573 -0
- package/src/__tests__/primitives-suggestions.test.ts +374 -0
- package/src/__tests__/primitives-threadlist.test.ts +443 -0
- package/src/__tests__/primitives-tool-ui.test.ts +579 -0
- package/src/__tests__/primitives.test.ts +361 -0
- package/src/__tests__/useAuiEvent.test.ts +159 -0
- package/src/__tests__/useAuiState.test.ts +124 -0
- package/src/context.ts +31 -0
- package/src/index.ts +87 -0
- package/src/primitives/AttachmentByIndexProvider.ts +88 -0
- package/src/primitives/ChainOfThoughtPrimitiveAccordionTrigger.test.ts +105 -0
- package/src/primitives/ChainOfThoughtPrimitiveAccordionTrigger.ts +38 -0
- package/src/primitives/ChainOfThoughtPrimitiveParts.test.ts +254 -0
- package/src/primitives/ChainOfThoughtPrimitiveParts.ts +112 -0
- package/src/primitives/ComposerPrimitiveCancel.ts +41 -0
- package/src/primitives/ComposerPrimitiveInput.ts +64 -0
- package/src/primitives/ComposerPrimitiveSend.ts +39 -0
- package/src/primitives/MessageByIdProvider.ts +89 -0
- package/src/primitives/MessagePrimitiveParts.tool-interaction.test.ts +88 -0
- package/src/primitives/MessagePrimitiveParts.ts +166 -0
- package/src/primitives/PartByIndexProvider.ts +62 -0
- package/src/primitives/ThreadListItemPrimitiveRoot.ts +57 -0
- package/src/primitives/ThreadListItemPrimitiveTrigger.ts +74 -0
- package/src/primitives/ThreadListKeyboardNav.test.ts +298 -0
- package/src/primitives/ThreadListPrimitiveRoot.ts +18 -0
- package/src/primitives/ThreadPrimitiveMessages.ts +40 -0
- package/src/primitives/ThreadPrimitiveScrollToBottom.ts +65 -0
- package/src/primitives/ThreadPrimitiveViewport.ts +233 -0
- package/src/primitives/ThreadPrimitiveViewportFooter.test.ts +305 -0
- package/src/primitives/ThreadPrimitiveViewportFooter.ts +60 -0
- package/src/primitives/actionBar.ts +159 -0
- package/src/primitives/attachment.ts +76 -0
- package/src/primitives/attrDisabled.ts +6 -0
- package/src/primitives/branchPicker.ts +77 -0
- package/src/primitives/composerAttachments.ts +181 -0
- package/src/primitives/error.ts +36 -0
- package/src/primitives/lastValidCache.ts +12 -0
- package/src/primitives/message.ts +54 -0
- package/src/primitives/messageAttachments.ts +32 -0
- package/src/primitives/stableKeys.test.ts +19 -0
- package/src/primitives/stableKeys.ts +21 -0
- package/src/primitives/suggestions.ts +179 -0
- package/src/primitives/thread.ts +46 -0
- package/src/primitives/threadList.ts +163 -0
- package/src/primitives/threadListFocusGroup.ts +56 -0
- package/src/primitives/threadListStructural.ts +86 -0
- package/src/primitives/useComposerSendState.ts +13 -0
- package/src/primitives/viewportContext.ts +16 -0
- package/src/useAui.ts +18 -0
- package/src/useAuiEvent.ts +64 -0
- package/src/useAuiState.ts +55 -0
- package/src/useScrollLock.test.ts +207 -0
- package/src/useScrollLock.ts +79 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { useAuiState } from "../useAuiState.js";
|
|
2
|
+
import { useAui } from "../useAui.js";
|
|
3
|
+
import { getAttachmentKeys, useStableKeys } from "./stableKeys.js";
|
|
4
|
+
import { isAttrDisabled } from "./attrDisabled.js";
|
|
5
|
+
import { AttachmentByIndexProvider } from "./AttachmentByIndexProvider.js";
|
|
6
|
+
import { defineComponent, h, mergeProps, ref, watch } from "vue";
|
|
7
|
+
//#region src/primitives/composerAttachments.ts
|
|
8
|
+
/**
|
|
9
|
+
* Renders the composer's pending attachments in order, each scoped through
|
|
10
|
+
* {@link AttachmentByIndexProvider}; the `default` slot renders each
|
|
11
|
+
* attachment.
|
|
12
|
+
*/
|
|
13
|
+
const ComposerPrimitiveAttachments = defineComponent({
|
|
14
|
+
name: "ComposerPrimitiveAttachments",
|
|
15
|
+
slots: Object,
|
|
16
|
+
setup(_, { slots }) {
|
|
17
|
+
const attachments = useAuiState((s) => s.composer.attachments);
|
|
18
|
+
const attachmentKeys = useStableKeys(() => getAttachmentKeys(attachments.value));
|
|
19
|
+
return () => attachmentKeys.value.map((key, index) => h(AttachmentByIndexProvider, {
|
|
20
|
+
source: "composer",
|
|
21
|
+
index,
|
|
22
|
+
key
|
|
23
|
+
}, { default: () => slots.default?.() }));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* A button that opens a file picker and adds the selected files to the
|
|
28
|
+
* composer. Disabled while the composer is not editable. The picker's accept
|
|
29
|
+
* filter follows the composer's `attachmentAccept`.
|
|
30
|
+
*/
|
|
31
|
+
const ComposerPrimitiveAddAttachment = defineComponent({
|
|
32
|
+
name: "ComposerPrimitiveAddAttachment",
|
|
33
|
+
inheritAttrs: false,
|
|
34
|
+
props: { multiple: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: true
|
|
37
|
+
} },
|
|
38
|
+
slots: Object,
|
|
39
|
+
setup(props, { attrs, slots }) {
|
|
40
|
+
const aui = useAui();
|
|
41
|
+
const disabled = useAuiState((s) => !s.composer.isEditing);
|
|
42
|
+
const onClick = (event) => {
|
|
43
|
+
if (event.defaultPrevented || disabled.value || isAttrDisabled(attrs)) return;
|
|
44
|
+
const input = document.createElement("input");
|
|
45
|
+
input.type = "file";
|
|
46
|
+
input.multiple = props.multiple;
|
|
47
|
+
input.hidden = true;
|
|
48
|
+
const attachmentAccept = aui.composer.getState().attachmentAccept;
|
|
49
|
+
if (attachmentAccept !== "*") input.accept = attachmentAccept;
|
|
50
|
+
document.body.appendChild(input);
|
|
51
|
+
input.onchange = (e) => {
|
|
52
|
+
const fileList = e.target.files;
|
|
53
|
+
if (fileList) for (const file of Array.from(fileList)) aui.composer.addAttachment(file).catch(() => {});
|
|
54
|
+
input.remove();
|
|
55
|
+
};
|
|
56
|
+
input.oncancel = () => input.remove();
|
|
57
|
+
input.click();
|
|
58
|
+
};
|
|
59
|
+
return () => h("button", mergeProps(attrs, {
|
|
60
|
+
type: "button",
|
|
61
|
+
disabled: disabled.value || isAttrDisabled(attrs),
|
|
62
|
+
onClick
|
|
63
|
+
}), slots.default?.());
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* A drop target that adds dropped files to the composer. `data-dragging` is
|
|
68
|
+
* present while a file drag hovers the element. File drags are claimed via
|
|
69
|
+
* `preventDefault` even when the runtime does not support attachments, since
|
|
70
|
+
* an unprevented file drop navigates the tab to the file.
|
|
71
|
+
*/
|
|
72
|
+
const ComposerPrimitiveAttachmentDropzone = defineComponent({
|
|
73
|
+
name: "ComposerPrimitiveAttachmentDropzone",
|
|
74
|
+
inheritAttrs: false,
|
|
75
|
+
props: { disabled: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: false
|
|
78
|
+
} },
|
|
79
|
+
slots: Object,
|
|
80
|
+
setup(props, { attrs, slots }) {
|
|
81
|
+
const aui = useAui();
|
|
82
|
+
const isDragging = ref(false);
|
|
83
|
+
watch(() => props.disabled, (disabled) => {
|
|
84
|
+
if (disabled) isDragging.value = false;
|
|
85
|
+
});
|
|
86
|
+
const isFileDrag = (event) => event.dataTransfer?.types.includes("Files") === true;
|
|
87
|
+
const onDragenterCapture = (event) => {
|
|
88
|
+
if (props.disabled || !isFileDrag(event)) return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
if (!aui.thread.getState().capabilities.attachments) {
|
|
91
|
+
event.dataTransfer.dropEffect = "none";
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
isDragging.value = true;
|
|
95
|
+
};
|
|
96
|
+
const onDragoverCapture = (event) => {
|
|
97
|
+
if (props.disabled || !isFileDrag(event)) return;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
if (!aui.thread.getState().capabilities.attachments) {
|
|
100
|
+
event.dataTransfer.dropEffect = "none";
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!isDragging.value) isDragging.value = true;
|
|
104
|
+
};
|
|
105
|
+
const onDragleaveCapture = (event) => {
|
|
106
|
+
if (props.disabled || !isFileDrag(event)) return;
|
|
107
|
+
const related = event.relatedTarget;
|
|
108
|
+
if (related && event.currentTarget.contains(related)) return;
|
|
109
|
+
isDragging.value = false;
|
|
110
|
+
};
|
|
111
|
+
const onDropCapture = (event) => {
|
|
112
|
+
if (props.disabled) return;
|
|
113
|
+
isDragging.value = false;
|
|
114
|
+
if (!isFileDrag(event)) return;
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
117
|
+
if (!aui.thread.getState().capabilities.attachments || files.length === 0) return;
|
|
118
|
+
for (const file of files) aui.composer.addAttachment(file).catch(() => {});
|
|
119
|
+
};
|
|
120
|
+
return () => h("div", mergeProps(attrs, {
|
|
121
|
+
...!props.disabled && isDragging.value && { "data-dragging": "true" },
|
|
122
|
+
onDragenterCapture,
|
|
123
|
+
onDragoverCapture,
|
|
124
|
+
onDragleaveCapture,
|
|
125
|
+
onDropCapture
|
|
126
|
+
}), slots.default?.());
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
//#endregion
|
|
130
|
+
export { ComposerPrimitiveAddAttachment, ComposerPrimitiveAttachmentDropzone, ComposerPrimitiveAttachments };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=composerAttachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composerAttachments.js","names":[],"sources":["../../src/primitives/composerAttachments.ts"],"sourcesContent":["import {\n defineComponent,\n h,\n mergeProps,\n ref,\n watch,\n type SlotsType,\n type VNodeChild,\n} from \"vue\";\nimport { isAttrDisabled } from \"./attrDisabled\";\nimport { useAui } from \"../useAui\";\nimport { useAuiState } from \"../useAuiState\";\nimport { AttachmentByIndexProvider } from \"./AttachmentByIndexProvider\";\nimport { getAttachmentKeys, useStableKeys } from \"./stableKeys\";\n\n/**\n * Renders the composer's pending attachments in order, each scoped through\n * {@link AttachmentByIndexProvider}; the `default` slot renders each\n * attachment.\n */\nexport const ComposerPrimitiveAttachments = defineComponent({\n name: \"ComposerPrimitiveAttachments\",\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { slots }) {\n const attachments = useAuiState((s) => s.composer.attachments);\n const attachmentKeys = useStableKeys(() =>\n getAttachmentKeys(attachments.value),\n );\n return () =>\n attachmentKeys.value.map((key, index) =>\n h(\n AttachmentByIndexProvider,\n { source: \"composer\", index, key },\n { default: () => slots.default?.() },\n ),\n );\n },\n});\n\n/**\n * A button that opens a file picker and adds the selected files to the\n * composer. Disabled while the composer is not editable. The picker's accept\n * filter follows the composer's `attachmentAccept`.\n */\nexport const ComposerPrimitiveAddAttachment = defineComponent({\n name: \"ComposerPrimitiveAddAttachment\",\n inheritAttrs: false,\n props: {\n multiple: {\n type: Boolean,\n default: true,\n },\n },\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(props, { attrs, slots }) {\n const aui = useAui();\n const disabled = useAuiState((s) => !s.composer.isEditing);\n const onClick = (event: MouseEvent) => {\n if (event.defaultPrevented || disabled.value || isAttrDisabled(attrs))\n return;\n\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.multiple = props.multiple;\n input.hidden = true;\n\n const attachmentAccept = aui.composer.getState().attachmentAccept;\n if (attachmentAccept !== \"*\") {\n input.accept = attachmentAccept;\n }\n\n document.body.appendChild(input);\n\n input.onchange = (e) => {\n const fileList = (e.target as HTMLInputElement).files;\n if (fileList) {\n for (const file of Array.from(fileList)) {\n aui.composer.addAttachment(file).catch(() => {});\n }\n }\n input.remove();\n };\n input.oncancel = () => input.remove();\n\n input.click();\n };\n return () =>\n h(\n \"button\",\n mergeProps(attrs, {\n type: \"button\",\n disabled: disabled.value || isAttrDisabled(attrs),\n onClick,\n }),\n slots.default?.(),\n );\n },\n});\n\n/**\n * A drop target that adds dropped files to the composer. `data-dragging` is\n * present while a file drag hovers the element. File drags are claimed via\n * `preventDefault` even when the runtime does not support attachments, since\n * an unprevented file drop navigates the tab to the file.\n */\nexport const ComposerPrimitiveAttachmentDropzone = defineComponent({\n name: \"ComposerPrimitiveAttachmentDropzone\",\n inheritAttrs: false,\n props: {\n disabled: {\n type: Boolean,\n default: false,\n },\n },\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(props, { attrs, slots }) {\n const aui = useAui();\n const isDragging = ref(false);\n\n watch(\n () => props.disabled,\n (disabled) => {\n if (disabled) isDragging.value = false;\n },\n );\n\n const isFileDrag = (event: DragEvent) =>\n event.dataTransfer?.types.includes(\"Files\") === true;\n\n const onDragenterCapture = (event: DragEvent) => {\n if (props.disabled || !isFileDrag(event)) return;\n event.preventDefault();\n if (!aui.thread.getState().capabilities.attachments) {\n event.dataTransfer!.dropEffect = \"none\";\n return;\n }\n isDragging.value = true;\n };\n const onDragoverCapture = (event: DragEvent) => {\n if (props.disabled || !isFileDrag(event)) return;\n event.preventDefault();\n if (!aui.thread.getState().capabilities.attachments) {\n event.dataTransfer!.dropEffect = \"none\";\n return;\n }\n if (!isDragging.value) isDragging.value = true;\n };\n const onDragleaveCapture = (event: DragEvent) => {\n if (props.disabled || !isFileDrag(event)) return;\n const related = event.relatedTarget as Node | null;\n if (related && (event.currentTarget as Node).contains(related)) return;\n isDragging.value = false;\n };\n const onDropCapture = (event: DragEvent) => {\n if (props.disabled) return;\n isDragging.value = false;\n if (!isFileDrag(event)) return;\n event.preventDefault();\n const files = Array.from(event.dataTransfer?.files ?? []);\n if (!aui.thread.getState().capabilities.attachments || files.length === 0)\n return;\n for (const file of files) {\n aui.composer.addAttachment(file).catch(() => {});\n }\n };\n\n return () =>\n h(\n \"div\",\n mergeProps(attrs, {\n ...(!props.disabled &&\n isDragging.value && { \"data-dragging\": \"true\" }),\n onDragenterCapture,\n onDragoverCapture,\n onDragleaveCapture,\n onDropCapture,\n }),\n slots.default?.(),\n );\n },\n});\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,+BAA+B,gBAAgB;CAC1D,MAAM;CACN,OAAO;CACP,MAAM,GAAG,EAAE,SAAS;EAClB,MAAM,cAAc,aAAa,MAAM,EAAE,SAAS,WAAW;EAC7D,MAAM,iBAAiB,oBACrB,kBAAkB,YAAY,KAAK,CACrC;EACA,aACE,eAAe,MAAM,KAAK,KAAK,UAC7B,EACE,2BACA;GAAE,QAAQ;GAAY;GAAO;EAAI,GACjC,EAAE,eAAe,MAAM,UAAU,EAAE,CACrC,CACF;CACJ;AACF,CAAC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type SlotsType, type VNodeChild } from "vue";
|
|
2
|
+
/** A wrapper element for the current message's error state. */
|
|
3
|
+
export declare const ErrorPrimitiveRoot: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
6
|
+
default?: () => VNodeChild[];
|
|
7
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
/**
|
|
9
|
+
* Renders the current assistant message's error text (raw text, slot
|
|
10
|
+
* override supported); renders nothing while the message has no error.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ErrorPrimitiveMessage: import("vue").DefineComponent<{}, () => string | VNodeChild[] | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
13
|
+
default?: () => VNodeChild[];
|
|
14
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
15
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/primitives/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AAIb,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB;;;cAGU,MAAM,UAAU,EAAE;yEAKzD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB;cAEO,MAAM,UAAU,EAAE;yEAQzD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useAuiState } from "../useAuiState.js";
|
|
2
|
+
import { defineComponent, h, mergeProps } from "vue";
|
|
3
|
+
import { messageErrorText } from "@assistant-ui/core/store/internal";
|
|
4
|
+
//#region src/primitives/error.ts
|
|
5
|
+
/** A wrapper element for the current message's error state. */
|
|
6
|
+
const ErrorPrimitiveRoot = defineComponent({
|
|
7
|
+
name: "ErrorPrimitiveRoot",
|
|
8
|
+
inheritAttrs: false,
|
|
9
|
+
slots: Object,
|
|
10
|
+
setup(_, { attrs, slots }) {
|
|
11
|
+
return () => h("div", mergeProps({ role: "alert" }, attrs), slots.default?.());
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Renders the current assistant message's error text (raw text, slot
|
|
16
|
+
* override supported); renders nothing while the message has no error.
|
|
17
|
+
*/
|
|
18
|
+
const ErrorPrimitiveMessage = defineComponent({
|
|
19
|
+
name: "ErrorPrimitiveMessage",
|
|
20
|
+
slots: Object,
|
|
21
|
+
setup(_, { slots }) {
|
|
22
|
+
const error = useAuiState(messageErrorText);
|
|
23
|
+
return () => error.value === void 0 ? null : slots.default?.() ?? String(error.value);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ErrorPrimitiveMessage, ErrorPrimitiveRoot };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/primitives/error.ts"],"sourcesContent":["import {\n defineComponent,\n h,\n mergeProps,\n type SlotsType,\n type VNodeChild,\n} from \"vue\";\nimport { messageErrorText } from \"@assistant-ui/core/store/internal\";\nimport { useAuiState } from \"../useAuiState\";\n\n/** A wrapper element for the current message's error state. */\nexport const ErrorPrimitiveRoot = defineComponent({\n name: \"ErrorPrimitiveRoot\",\n inheritAttrs: false,\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { attrs, slots }) {\n return () =>\n h(\"div\", mergeProps({ role: \"alert\" }, attrs), slots.default?.());\n },\n});\n\n/**\n * Renders the current assistant message's error text (raw text, slot\n * override supported); renders nothing while the message has no error.\n */\nexport const ErrorPrimitiveMessage = defineComponent({\n name: \"ErrorPrimitiveMessage\",\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { slots }) {\n const error = useAuiState(messageErrorText);\n return () =>\n error.value === undefined\n ? null\n : (slots.default?.() ?? String(error.value));\n },\n});\n"],"mappings":";;;;;AAWA,MAAa,qBAAqB,gBAAgB;CAChD,MAAM;CACN,cAAc;CACd,OAAO;CACP,MAAM,GAAG,EAAE,OAAO,SAAS;EACzB,aACE,EAAE,OAAO,WAAW,EAAE,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,UAAU,CAAC;CACpE;AACF,CAAC;;;;;AAMD,MAAa,wBAAwB,gBAAgB;CACnD,MAAM;CACN,OAAO;CACP,MAAM,GAAG,EAAE,SAAS;EAClB,MAAM,QAAQ,YAAY,gBAAgB;EAC1C,aACE,MAAM,UAAU,KAAA,IACZ,OACC,MAAM,UAAU,KAAK,OAAO,MAAM,KAAK;CAChD;AACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createStaleReporter } from "@assistant-ui/store/client";
|
|
2
|
+
export declare const createLastValidCache: <T>(reportStale: (() => void) | null) => {
|
|
3
|
+
resolve: (valid: boolean, resolveItem: () => T) => T;
|
|
4
|
+
};
|
|
5
|
+
export { createStaleReporter };
|
|
6
|
+
//# sourceMappingURL=lastValidCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastValidCache.d.ts","sourceRoot":"","sources":["../../src/primitives/lastValidCache.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAIpC,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,aAAa,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;;CACX,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { nextTick } from "vue";
|
|
2
|
+
import { createLastValidCache as createLastValidCache$1, createStaleReporter } from "@assistant-ui/store/client";
|
|
3
|
+
//#region src/primitives/lastValidCache.ts
|
|
4
|
+
const scheduleExpiry = (callback) => void nextTick(callback);
|
|
5
|
+
const createLastValidCache = (reportStale) => createLastValidCache$1(reportStale, scheduleExpiry);
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createLastValidCache, createStaleReporter };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=lastValidCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastValidCache.js","names":["createNeutralLastValidCache"],"sources":["../../src/primitives/lastValidCache.ts"],"sourcesContent":["import { nextTick } from \"vue\";\nimport {\n createLastValidCache as createNeutralLastValidCache,\n createStaleReporter,\n} from \"@assistant-ui/store/client\";\n\nconst scheduleExpiry = (callback: () => void) => void nextTick(callback);\n\nexport const createLastValidCache = <T>(reportStale: (() => void) | null) =>\n createNeutralLastValidCache<T>(reportStale, scheduleExpiry);\n\nexport { createStaleReporter };\n"],"mappings":";;;AAMA,MAAM,kBAAkB,aAAyB,KAAK,SAAS,QAAQ;AAEvE,MAAa,wBAA2B,gBACtCA,uBAA+B,aAAa,cAAc"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SlotsType, type VNodeChild } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper element for one message. Sets `data-message-id` and tracks
|
|
4
|
+
* pointer hover into `s.message.isHovering`, including an element already
|
|
5
|
+
* under the pointer when it mounts.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MessagePrimitiveRoot: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
10
|
+
default?: () => VNodeChild[];
|
|
11
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
12
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/primitives/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AAIb;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;cAGQ,MAAM,UAAU,EAAE;yEAkCzD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useAuiState } from "../useAuiState.js";
|
|
2
|
+
import { useAui } from "../useAui.js";
|
|
3
|
+
import { defineComponent, h, mergeProps, onScopeDispose } from "vue";
|
|
4
|
+
//#region src/primitives/message.ts
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper element for one message. Sets `data-message-id` and tracks
|
|
7
|
+
* pointer hover into `s.message.isHovering`, including an element already
|
|
8
|
+
* under the pointer when it mounts.
|
|
9
|
+
*/
|
|
10
|
+
const MessagePrimitiveRoot = defineComponent({
|
|
11
|
+
name: "MessagePrimitiveRoot",
|
|
12
|
+
inheritAttrs: false,
|
|
13
|
+
slots: Object,
|
|
14
|
+
setup(_, { attrs, slots }) {
|
|
15
|
+
const aui = useAui();
|
|
16
|
+
const messageId = useAuiState((s) => s.message.id);
|
|
17
|
+
const onMouseenter = () => {
|
|
18
|
+
aui.message.setIsHovering(true);
|
|
19
|
+
};
|
|
20
|
+
const onMouseleave = () => {
|
|
21
|
+
aui.message.setIsHovering(false);
|
|
22
|
+
};
|
|
23
|
+
let active = true;
|
|
24
|
+
onScopeDispose(() => {
|
|
25
|
+
active = false;
|
|
26
|
+
onMouseleave();
|
|
27
|
+
});
|
|
28
|
+
const hoverRef = (el) => {
|
|
29
|
+
if (el instanceof HTMLElement && el.matches(":hover")) queueMicrotask(() => {
|
|
30
|
+
if (active) onMouseenter();
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return () => h("div", mergeProps(attrs, {
|
|
34
|
+
ref: hoverRef,
|
|
35
|
+
"data-message-id": messageId.value,
|
|
36
|
+
onMouseenter,
|
|
37
|
+
onMouseleave
|
|
38
|
+
}), slots.default?.());
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//#endregion
|
|
42
|
+
export { MessagePrimitiveRoot };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","names":[],"sources":["../../src/primitives/message.ts"],"sourcesContent":["import {\n defineComponent,\n h,\n mergeProps,\n onScopeDispose,\n type SlotsType,\n type VNodeChild,\n} from \"vue\";\nimport { useAui } from \"../useAui\";\nimport { useAuiState } from \"../useAuiState\";\n\n/**\n * A wrapper element for one message. Sets `data-message-id` and tracks\n * pointer hover into `s.message.isHovering`, including an element already\n * under the pointer when it mounts.\n */\nexport const MessagePrimitiveRoot = defineComponent({\n name: \"MessagePrimitiveRoot\",\n inheritAttrs: false,\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { attrs, slots }) {\n const aui = useAui();\n const messageId = useAuiState((s) => s.message.id);\n const onMouseenter = () => {\n aui.message.setIsHovering(true);\n };\n const onMouseleave = () => {\n aui.message.setIsHovering(false);\n };\n let active = true;\n onScopeDispose(() => {\n active = false;\n onMouseleave();\n });\n const hoverRef = (el: unknown) => {\n if (el instanceof HTMLElement && el.matches(\":hover\")) {\n queueMicrotask(() => {\n if (active) onMouseenter();\n });\n }\n };\n return () =>\n h(\n \"div\",\n mergeProps(attrs, {\n ref: hoverRef,\n \"data-message-id\": messageId.value,\n onMouseenter,\n onMouseleave,\n }),\n slots.default?.(),\n );\n },\n});\n"],"mappings":";;;;;;;;;AAgBA,MAAa,uBAAuB,gBAAgB;CAClD,MAAM;CACN,cAAc;CACd,OAAO;CACP,MAAM,GAAG,EAAE,OAAO,SAAS;EACzB,MAAM,MAAM,OAAO;EACnB,MAAM,YAAY,aAAa,MAAM,EAAE,QAAQ,EAAE;EACjD,MAAM,qBAAqB;GACzB,IAAI,QAAQ,cAAc,IAAI;EAChC;EACA,MAAM,qBAAqB;GACzB,IAAI,QAAQ,cAAc,KAAK;EACjC;EACA,IAAI,SAAS;EACb,qBAAqB;GACnB,SAAS;GACT,aAAa;EACf,CAAC;EACD,MAAM,YAAY,OAAgB;GAChC,IAAI,cAAc,eAAe,GAAG,QAAQ,QAAQ,GAClD,qBAAqB;IACnB,IAAI,QAAQ,aAAa;GAC3B,CAAC;EAEL;EACA,aACE,EACE,OACA,WAAW,OAAO;GAChB,KAAK;GACL,mBAAmB,UAAU;GAC7B;GACA;EACF,CAAC,GACD,MAAM,UAAU,CAClB;CACJ;AACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SlotsType, type VNodeChild } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the current message's attachments in order, each scoped through
|
|
4
|
+
* {@link AttachmentByIndexProvider}; the `default` slot renders each
|
|
5
|
+
* attachment.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MessagePrimitiveAttachments: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}>[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
10
|
+
default?: () => VNodeChild[];
|
|
11
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
12
|
+
//# sourceMappingURL=messageAttachments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageAttachments.d.ts","sourceRoot":"","sources":["../../src/primitives/messageAttachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAK1E;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;cAEC,MAAM,UAAU,EAAE;yEAmBzD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useAuiState } from "../useAuiState.js";
|
|
2
|
+
import { getAttachmentKeys, useStableKeys } from "./stableKeys.js";
|
|
3
|
+
import { AttachmentByIndexProvider } from "./AttachmentByIndexProvider.js";
|
|
4
|
+
import { defineComponent, h } from "vue";
|
|
5
|
+
//#region src/primitives/messageAttachments.ts
|
|
6
|
+
/**
|
|
7
|
+
* Renders the current message's attachments in order, each scoped through
|
|
8
|
+
* {@link AttachmentByIndexProvider}; the `default` slot renders each
|
|
9
|
+
* attachment.
|
|
10
|
+
*/
|
|
11
|
+
const MessagePrimitiveAttachments = defineComponent({
|
|
12
|
+
name: "MessagePrimitiveAttachments",
|
|
13
|
+
slots: Object,
|
|
14
|
+
setup(_, { slots }) {
|
|
15
|
+
const attachments = useAuiState((s) => s.message.role === "user" ? s.message.submission?.attachments ?? s.message.attachments : void 0);
|
|
16
|
+
const attachmentKeys = useStableKeys(() => getAttachmentKeys(attachments.value ?? []));
|
|
17
|
+
return () => attachmentKeys.value.map((key, index) => h(AttachmentByIndexProvider, {
|
|
18
|
+
source: "message",
|
|
19
|
+
index,
|
|
20
|
+
key
|
|
21
|
+
}, { default: () => slots.default?.() }));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
//#endregion
|
|
25
|
+
export { MessagePrimitiveAttachments };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=messageAttachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageAttachments.js","names":[],"sources":["../../src/primitives/messageAttachments.ts"],"sourcesContent":["import { defineComponent, h, type SlotsType, type VNodeChild } from \"vue\";\nimport { useAuiState } from \"../useAuiState\";\nimport { AttachmentByIndexProvider } from \"./AttachmentByIndexProvider\";\nimport { getAttachmentKeys, useStableKeys } from \"./stableKeys\";\n\n/**\n * Renders the current message's attachments in order, each scoped through\n * {@link AttachmentByIndexProvider}; the `default` slot renders each\n * attachment.\n */\nexport const MessagePrimitiveAttachments = defineComponent({\n name: \"MessagePrimitiveAttachments\",\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { slots }) {\n const attachments = useAuiState((s) =>\n s.message.role === \"user\"\n ? (s.message.submission?.attachments ?? s.message.attachments)\n : undefined,\n );\n const attachmentKeys = useStableKeys(() =>\n getAttachmentKeys(attachments.value ?? []),\n );\n return () =>\n attachmentKeys.value.map((key, index) =>\n h(\n AttachmentByIndexProvider,\n { source: \"message\", index, key },\n { default: () => slots.default?.() },\n ),\n );\n },\n});\n"],"mappings":";;;;;;;;;;AAUA,MAAa,8BAA8B,gBAAgB;CACzD,MAAM;CACN,OAAO;CACP,MAAM,GAAG,EAAE,SAAS;EAClB,MAAM,cAAc,aAAa,MAC/B,EAAE,QAAQ,SAAS,SACd,EAAE,QAAQ,YAAY,eAAe,EAAE,QAAQ,cAChD,KAAA,CACN;EACA,MAAM,iBAAiB,oBACrB,kBAAkB,YAAY,SAAS,CAAC,CAAC,CAC3C;EACA,aACE,eAAe,MAAM,KAAK,KAAK,UAC7B,EACE,2BACA;GAAE,QAAQ;GAAW;GAAO;EAAI,GAChC,EAAE,eAAe,MAAM,UAAU,EAAE,CACrC,CACF;CACJ;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stableKeys.d.ts","sourceRoot":"","sources":["../../src/primitives/stableKeys.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,MAAM,EAAE,wCAOjD,CAAC;AAEL,eAAO,MAAM,iBAAiB,GAC5B,aAAa,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,aAQhD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
//#region src/primitives/stableKeys.ts
|
|
3
|
+
const useStableKeys = (getKeys) => computed((previous) => {
|
|
4
|
+
const keys = getKeys();
|
|
5
|
+
return previous?.length === keys.length && previous.every((key, index) => key === keys[index]) ? previous : keys;
|
|
6
|
+
});
|
|
7
|
+
const getAttachmentKeys = (attachments) => {
|
|
8
|
+
const ids = attachments.map((attachment) => attachment.id);
|
|
9
|
+
return ids.map((id, index) => ids.indexOf(id) === ids.lastIndexOf(id) ? `attachment:${id}` : `attachment@${index}`);
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getAttachmentKeys, useStableKeys };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=stableKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stableKeys.js","names":[],"sources":["../../src/primitives/stableKeys.ts"],"sourcesContent":["import { computed } from \"vue\";\n\nexport const useStableKeys = (getKeys: () => string[]) =>\n computed<string[]>((previous) => {\n const keys = getKeys();\n return previous?.length === keys.length &&\n previous.every((key, index) => key === keys[index])\n ? previous\n : keys;\n });\n\nexport const getAttachmentKeys = (\n attachments: readonly { readonly id: string }[],\n) => {\n const ids = attachments.map((attachment) => attachment.id);\n return ids.map((id, index) =>\n ids.indexOf(id) === ids.lastIndexOf(id)\n ? `attachment:${id}`\n : `attachment@${index}`,\n );\n};\n"],"mappings":";;AAEA,MAAa,iBAAiB,YAC5B,UAAoB,aAAa;CAC/B,MAAM,OAAO,QAAQ;CACrB,OAAO,UAAU,WAAW,KAAK,UAC/B,SAAS,OAAO,KAAK,UAAU,QAAQ,KAAK,MAAM,IAChD,WACA;AACN,CAAC;AAEH,MAAa,qBACX,gBACG;CACH,MAAM,MAAM,YAAY,KAAK,eAAe,WAAW,EAAE;CACzD,OAAO,IAAI,KAAK,IAAI,UAClB,IAAI,QAAQ,EAAE,MAAM,IAAI,YAAY,EAAE,IAClC,cAAc,OACd,cAAc,OACpB;AACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type SlotsType, type VNodeChild } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Scopes the subtree to the suggestion at `index`: descendants read it
|
|
4
|
+
* through `s.suggestion`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SuggestionByIndexProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
index: {
|
|
8
|
+
type: NumberConstructor;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
14
|
+
index: {
|
|
15
|
+
type: NumberConstructor;
|
|
16
|
+
required: true;
|
|
17
|
+
};
|
|
18
|
+
}>> & Readonly<{}>, {}, SlotsType<{
|
|
19
|
+
default?: () => VNodeChild[];
|
|
20
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Renders the default slot once per thread suggestion, each instance scoped
|
|
23
|
+
* through {@link SuggestionByIndexProvider}.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ThreadPrimitiveSuggestions: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}>[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
28
|
+
default?: () => VNodeChild[];
|
|
29
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
30
|
+
/**
|
|
31
|
+
* A button that triggers the current suggestion. With `send`, the prompt is
|
|
32
|
+
* appended as a message (queued sends never clear a draft the user is still
|
|
33
|
+
* composing); without it, the prompt replaces the composer text, or is
|
|
34
|
+
* appended to it when `clearComposer` is false.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SuggestionPrimitiveTrigger: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
37
|
+
send: {
|
|
38
|
+
type: BooleanConstructor;
|
|
39
|
+
default: boolean;
|
|
40
|
+
};
|
|
41
|
+
clearComposer: {
|
|
42
|
+
type: BooleanConstructor;
|
|
43
|
+
default: boolean;
|
|
44
|
+
};
|
|
45
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
48
|
+
send: {
|
|
49
|
+
type: BooleanConstructor;
|
|
50
|
+
default: boolean;
|
|
51
|
+
};
|
|
52
|
+
clearComposer: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
default: boolean;
|
|
55
|
+
};
|
|
56
|
+
}>> & Readonly<{}>, {
|
|
57
|
+
send: boolean;
|
|
58
|
+
clearComposer: boolean;
|
|
59
|
+
}, SlotsType<{
|
|
60
|
+
default?: () => VNodeChild[];
|
|
61
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
62
|
+
/** Renders the current suggestion's title as text. */
|
|
63
|
+
export declare const SuggestionPrimitiveTitle: import("vue").DefineComponent<{}, () => string, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
64
|
+
/** Renders the current suggestion's label as text. */
|
|
65
|
+
export declare const SuggestionPrimitiveDescription: import("vue").DefineComponent<{}, () => string, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
66
|
+
//# sourceMappingURL=suggestions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggestions.d.ts","sourceRoot":"","sources":["../../src/primitives/suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AAgBb;;;GAGG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;cAQG,MAAM,UAAU,EAAE;yEAoCzD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;cAEE,MAAM,UAAU,EAAE;yEAezD,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;cAaE,MAAM,UAAU,EAAE;yEA4CzD,CAAC;AAEH,sDAAsD;AACtD,eAAO,MAAM,wBAAwB,yRAMnC,CAAC;AAEH,sDAAsD;AACtD,eAAO,MAAM,8BAA8B,yRAMzC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useAuiState } from "../useAuiState.js";
|
|
2
|
+
import { AuiProvider } from "../AuiProvider.js";
|
|
3
|
+
import { useAui } from "../useAui.js";
|
|
4
|
+
import { createLastValidCache as createLastValidCache$1, createStaleReporter } from "./lastValidCache.js";
|
|
5
|
+
import { useStableKeys } from "./stableKeys.js";
|
|
6
|
+
import { isAttrDisabled } from "./attrDisabled.js";
|
|
7
|
+
import { computed, defineComponent, h, mergeProps, onScopeDispose } from "vue";
|
|
8
|
+
import { AuiConfig, Derived } from "@assistant-ui/store/client";
|
|
9
|
+
import { suggestionSendMode, suggestionTriggerDisabled } from "@assistant-ui/core/store/internal";
|
|
10
|
+
import { getSuggestionKeys } from "@assistant-ui/core/internal";
|
|
11
|
+
import { flushTapSync } from "@assistant-ui/tap";
|
|
12
|
+
//#region src/primitives/suggestions.ts
|
|
13
|
+
/**
|
|
14
|
+
* Scopes the subtree to the suggestion at `index`: descendants read it
|
|
15
|
+
* through `s.suggestion`.
|
|
16
|
+
*/
|
|
17
|
+
const SuggestionByIndexProvider = defineComponent({
|
|
18
|
+
name: "SuggestionByIndexProvider",
|
|
19
|
+
props: { index: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: true
|
|
22
|
+
} },
|
|
23
|
+
slots: Object,
|
|
24
|
+
setup(props, { slots }) {
|
|
25
|
+
const aui = useAui();
|
|
26
|
+
let disposed = false;
|
|
27
|
+
onScopeDispose(() => {
|
|
28
|
+
disposed = true;
|
|
29
|
+
});
|
|
30
|
+
const config = computed(() => {
|
|
31
|
+
const index = props.index;
|
|
32
|
+
const cache = createLastValidCache$1(createStaleReporter({
|
|
33
|
+
name: "SuggestionByIndexProvider",
|
|
34
|
+
index,
|
|
35
|
+
isCurrent: () => !disposed && index === props.index,
|
|
36
|
+
isValid: () => index < aui.suggestions.getState().suggestions.length
|
|
37
|
+
}));
|
|
38
|
+
return AuiConfig({ suggestion: Derived({
|
|
39
|
+
source: "suggestions",
|
|
40
|
+
query: { index },
|
|
41
|
+
get: (aui) => cache.resolve(index < aui.suggestions.getState().suggestions.length, () => aui.suggestions.suggestion({ index }))
|
|
42
|
+
}) });
|
|
43
|
+
});
|
|
44
|
+
return () => h(AuiProvider, {
|
|
45
|
+
config: config.value,
|
|
46
|
+
extends: aui
|
|
47
|
+
}, { default: () => slots.default?.() });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Renders the default slot once per thread suggestion, each instance scoped
|
|
52
|
+
* through {@link SuggestionByIndexProvider}.
|
|
53
|
+
*/
|
|
54
|
+
const ThreadPrimitiveSuggestions = defineComponent({
|
|
55
|
+
name: "ThreadPrimitiveSuggestions",
|
|
56
|
+
slots: Object,
|
|
57
|
+
setup(_, { slots }) {
|
|
58
|
+
const suggestions = useAuiState((s) => s.suggestions.suggestions);
|
|
59
|
+
const suggestionKeys = useStableKeys(() => getSuggestionKeys(suggestions.value));
|
|
60
|
+
return () => suggestionKeys.value.map((key, index) => h(SuggestionByIndexProvider, {
|
|
61
|
+
index,
|
|
62
|
+
key
|
|
63
|
+
}, { default: () => slots.default?.() }));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* A button that triggers the current suggestion. With `send`, the prompt is
|
|
68
|
+
* appended as a message (queued sends never clear a draft the user is still
|
|
69
|
+
* composing); without it, the prompt replaces the composer text, or is
|
|
70
|
+
* appended to it when `clearComposer` is false.
|
|
71
|
+
*/
|
|
72
|
+
const SuggestionPrimitiveTrigger = defineComponent({
|
|
73
|
+
name: "SuggestionPrimitiveTrigger",
|
|
74
|
+
inheritAttrs: false,
|
|
75
|
+
props: {
|
|
76
|
+
send: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: false
|
|
79
|
+
},
|
|
80
|
+
clearComposer: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
default: true
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
slots: Object,
|
|
86
|
+
setup(props, { attrs, slots }) {
|
|
87
|
+
const aui = useAui();
|
|
88
|
+
const prompt = useAuiState((s) => s.suggestion.prompt);
|
|
89
|
+
const disabled = useAuiState((s) => suggestionTriggerDisabled(s, props.send));
|
|
90
|
+
const onClick = (event) => {
|
|
91
|
+
if (event.defaultPrevented || disabled.value || isAttrDisabled(attrs)) return;
|
|
92
|
+
flushTapSync(() => {
|
|
93
|
+
if (props.send) {
|
|
94
|
+
const mode = suggestionSendMode(aui.thread.getState());
|
|
95
|
+
if (mode === "blocked") return;
|
|
96
|
+
aui.thread.append({
|
|
97
|
+
content: [{
|
|
98
|
+
type: "text",
|
|
99
|
+
text: prompt.value
|
|
100
|
+
}],
|
|
101
|
+
runConfig: aui.composer.getState().runConfig
|
|
102
|
+
});
|
|
103
|
+
if (props.clearComposer && mode === "now") aui.composer.setText("");
|
|
104
|
+
} else if (props.clearComposer) aui.composer.setText(prompt.value);
|
|
105
|
+
else {
|
|
106
|
+
const currentText = aui.composer.getState().text;
|
|
107
|
+
aui.composer.setText([currentText, prompt.value].filter((part) => part.trim()).join(" "));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
return () => h("button", mergeProps(attrs, {
|
|
112
|
+
type: "button",
|
|
113
|
+
disabled: disabled.value || isAttrDisabled(attrs),
|
|
114
|
+
onClick
|
|
115
|
+
}), slots.default?.());
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
/** Renders the current suggestion's title as text. */
|
|
119
|
+
const SuggestionPrimitiveTitle = defineComponent({
|
|
120
|
+
name: "SuggestionPrimitiveTitle",
|
|
121
|
+
setup() {
|
|
122
|
+
const title = useAuiState((s) => s.suggestion.title);
|
|
123
|
+
return () => title.value;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
/** Renders the current suggestion's label as text. */
|
|
127
|
+
const SuggestionPrimitiveDescription = defineComponent({
|
|
128
|
+
name: "SuggestionPrimitiveDescription",
|
|
129
|
+
setup() {
|
|
130
|
+
const label = useAuiState((s) => s.suggestion.label);
|
|
131
|
+
return () => label.value;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
//#endregion
|
|
135
|
+
export { SuggestionByIndexProvider, SuggestionPrimitiveDescription, SuggestionPrimitiveTitle, SuggestionPrimitiveTrigger, ThreadPrimitiveSuggestions };
|
|
136
|
+
|
|
137
|
+
//# sourceMappingURL=suggestions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggestions.js","names":["createLastValidCache"],"sources":["../../src/primitives/suggestions.ts"],"sourcesContent":["import {\n computed,\n defineComponent,\n h,\n mergeProps,\n onScopeDispose,\n type SlotsType,\n type VNodeChild,\n} from \"vue\";\nimport { AuiConfig, Derived } from \"@assistant-ui/store/client\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport type { SuggestionMethods } from \"@assistant-ui/core/store\";\nimport { getSuggestionKeys } from \"@assistant-ui/core/internal\";\nimport {\n suggestionSendMode,\n suggestionTriggerDisabled,\n} from \"@assistant-ui/core/store/internal\";\nimport { AuiProvider } from \"../AuiProvider\";\nimport { isAttrDisabled } from \"./attrDisabled\";\nimport { createLastValidCache, createStaleReporter } from \"./lastValidCache\";\nimport { useStableKeys } from \"./stableKeys\";\nimport { useAui } from \"../useAui\";\nimport { useAuiState } from \"../useAuiState\";\n\n/**\n * Scopes the subtree to the suggestion at `index`: descendants read it\n * through `s.suggestion`.\n */\nexport const SuggestionByIndexProvider = defineComponent({\n name: \"SuggestionByIndexProvider\",\n props: {\n index: {\n type: Number,\n required: true,\n },\n },\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(props, { slots }) {\n const aui = useAui();\n let disposed = false;\n onScopeDispose(() => {\n disposed = true;\n });\n const config = computed(() => {\n const index = props.index;\n const cache = createLastValidCache<SuggestionMethods>(\n createStaleReporter({\n name: \"SuggestionByIndexProvider\",\n index,\n isCurrent: () => !disposed && index === props.index,\n isValid: () => index < aui.suggestions.getState().suggestions.length,\n }),\n );\n return AuiConfig({\n suggestion: Derived({\n source: \"suggestions\",\n query: { index },\n get: (aui) =>\n cache.resolve(\n index < aui.suggestions.getState().suggestions.length,\n () => aui.suggestions.suggestion({ index }),\n ),\n }),\n });\n });\n return () =>\n h(\n AuiProvider,\n { config: config.value, extends: aui },\n { default: () => slots.default?.() },\n );\n },\n});\n\n/**\n * Renders the default slot once per thread suggestion, each instance scoped\n * through {@link SuggestionByIndexProvider}.\n */\nexport const ThreadPrimitiveSuggestions = defineComponent({\n name: \"ThreadPrimitiveSuggestions\",\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(_, { slots }) {\n const suggestions = useAuiState((s) => s.suggestions.suggestions);\n const suggestionKeys = useStableKeys(() =>\n getSuggestionKeys(suggestions.value),\n );\n return () =>\n suggestionKeys.value.map((key, index) =>\n h(\n SuggestionByIndexProvider,\n { index, key },\n { default: () => slots.default?.() },\n ),\n );\n },\n});\n\n/**\n * A button that triggers the current suggestion. With `send`, the prompt is\n * appended as a message (queued sends never clear a draft the user is still\n * composing); without it, the prompt replaces the composer text, or is\n * appended to it when `clearComposer` is false.\n */\nexport const SuggestionPrimitiveTrigger = defineComponent({\n name: \"SuggestionPrimitiveTrigger\",\n inheritAttrs: false,\n props: {\n send: {\n type: Boolean,\n default: false,\n },\n clearComposer: {\n type: Boolean,\n default: true,\n },\n },\n slots: Object as SlotsType<{ default?: () => VNodeChild[] }>,\n setup(props, { attrs, slots }) {\n const aui = useAui();\n const prompt = useAuiState((s) => s.suggestion.prompt);\n const disabled = useAuiState((s) =>\n suggestionTriggerDisabled(s, props.send),\n );\n\n const onClick = (event: MouseEvent) => {\n if (event.defaultPrevented || disabled.value || isAttrDisabled(attrs))\n return;\n flushTapSync(() => {\n if (props.send) {\n const mode = suggestionSendMode(aui.thread.getState());\n if (mode === \"blocked\") return;\n aui.thread.append({\n content: [{ type: \"text\", text: prompt.value }],\n runConfig: aui.composer.getState().runConfig,\n });\n if (props.clearComposer && mode === \"now\") {\n aui.composer.setText(\"\");\n }\n } else if (props.clearComposer) {\n aui.composer.setText(prompt.value);\n } else {\n const currentText = aui.composer.getState().text;\n aui.composer.setText(\n [currentText, prompt.value].filter((part) => part.trim()).join(\" \"),\n );\n }\n });\n };\n\n return () =>\n h(\n \"button\",\n mergeProps(attrs, {\n type: \"button\",\n disabled: disabled.value || isAttrDisabled(attrs),\n onClick,\n }),\n slots.default?.(),\n );\n },\n});\n\n/** Renders the current suggestion's title as text. */\nexport const SuggestionPrimitiveTitle = defineComponent({\n name: \"SuggestionPrimitiveTitle\",\n setup() {\n const title = useAuiState((s) => s.suggestion.title);\n return () => title.value;\n },\n});\n\n/** Renders the current suggestion's label as text. */\nexport const SuggestionPrimitiveDescription = defineComponent({\n name: \"SuggestionPrimitiveDescription\",\n setup() {\n const label = useAuiState((s) => s.suggestion.label);\n return () => label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Aa,MAAM,EAAE,WAAW,KAAK;EACnD,aAAa,MAAM;CACrB;AACF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SlotsType, type VNodeChild } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper element for the thread. While mounted, Escape stops an active
|
|
4
|
+
* speech synthesis run.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ThreadPrimitiveRoot: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
9
|
+
default?: () => VNodeChild[];
|
|
10
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
11
|
+
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/primitives/thread.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AAGb;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;cAGS,MAAM,UAAU,EAAE;yEA2BzD,CAAC"}
|