@dxos/react-ui-chat 0.8.4-main.c4373fc → 0.8.4-main.d05539e30a
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 +102 -5
- package/dist/lib/browser/index.mjs +231 -245
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +14 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +231 -245
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +16 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +17 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +2 -3
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +3 -3
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
- package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
- package/dist/types/src/components/ChatStatus/ChatStatus.d.ts +40 -0
- package/dist/types/src/components/ChatStatus/ChatStatus.d.ts.map +1 -0
- package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts +27 -0
- package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts.map +1 -0
- package/dist/types/src/components/ChatStatus/format.d.ts +7 -0
- package/dist/types/src/components/ChatStatus/format.d.ts.map +1 -0
- package/dist/types/src/components/ChatStatus/format.test.d.ts +2 -0
- package/dist/types/src/components/ChatStatus/format.test.d.ts.map +1 -0
- package/dist/types/src/components/ChatStatus/index.d.ts +3 -0
- package/dist/types/src/components/ChatStatus/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +48 -40
- package/src/components/ChatDialog/ChatDialog.stories.tsx +4 -5
- package/src/components/ChatDialog/ChatDialog.tsx +28 -18
- package/src/components/ChatEditor/ChatEditor.stories.tsx +19 -17
- package/src/components/ChatEditor/ChatEditor.tsx +33 -80
- package/src/components/ChatEditor/references.ts +18 -12
- package/src/components/ChatStatus/ChatStatus.stories.tsx +130 -0
- package/src/components/ChatStatus/ChatStatus.tsx +183 -0
- package/src/components/ChatStatus/format.test.ts +48 -0
- package/src/components/ChatStatus/format.ts +27 -0
- package/src/components/ChatStatus/index.ts +6 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +0 -1
- package/src/translations.ts +1 -1
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -1,121 +1,97 @@
|
|
|
1
1
|
// src/components/ChatDialog/ChatDialog.tsx
|
|
2
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
3
2
|
import { createContext } from "@radix-ui/react-context";
|
|
4
3
|
import React, { useEffect, useState } from "react";
|
|
5
4
|
import { Dialog, Icon, IconButton, useControlledState } from "@dxos/react-ui";
|
|
6
5
|
import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
7
|
-
import { mx } from "@dxos/
|
|
6
|
+
import { mx } from "@dxos/ui-theme";
|
|
8
7
|
var preventDefault = (event) => event.preventDefault();
|
|
9
8
|
var Endcap = ({ children }) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
className: "grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center"
|
|
14
|
-
}, children);
|
|
15
|
-
} finally {
|
|
16
|
-
_effect.f();
|
|
17
|
-
}
|
|
9
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
10
|
+
className: "grid w-[var(--dx-rail-action)] h-[var(--dx-rail-action)] items-center justify-center"
|
|
11
|
+
}, children);
|
|
18
12
|
};
|
|
19
13
|
var [ChatDialogContextProvider, useChatDialogContext] = createContext("ChatDialog");
|
|
20
|
-
var ChatDialogRoot = ({ children, open:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
onEscapeKeyDown: onEscape,
|
|
48
|
-
onInteractOutside: preventDefault
|
|
49
|
-
}, children))));
|
|
50
|
-
} finally {
|
|
51
|
-
_effect.f();
|
|
52
|
-
}
|
|
14
|
+
var ChatDialogRoot = ({ children, open: openProp = false, expanded: expandedProp = false, onOpenChange, onExpandedChange, onEscape }) => {
|
|
15
|
+
const [size, setSize] = useState("min-content");
|
|
16
|
+
const [open, setOpen] = useControlledState(openProp, onOpenChange);
|
|
17
|
+
const [expanded, setExpanded] = useControlledState(expandedProp, onExpandedChange);
|
|
18
|
+
return /* @__PURE__ */ React.createElement(ChatDialogContextProvider, {
|
|
19
|
+
open,
|
|
20
|
+
setOpen,
|
|
21
|
+
expanded,
|
|
22
|
+
setExpanded,
|
|
23
|
+
size,
|
|
24
|
+
setSize
|
|
25
|
+
}, /* @__PURE__ */ React.createElement(Dialog.Root, {
|
|
26
|
+
modal: false,
|
|
27
|
+
open,
|
|
28
|
+
onOpenChange: setOpen
|
|
29
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
30
|
+
className: "dx-dialog__overlay bg-transparent pointer-events-none",
|
|
31
|
+
"data-block-align": "end"
|
|
32
|
+
}, /* @__PURE__ */ React.createElement(Dialog.Content, {
|
|
33
|
+
size: "md",
|
|
34
|
+
inOverlayLayout: true,
|
|
35
|
+
classNames: [
|
|
36
|
+
"grid grid-rows-[var(--dx-rail-action)_1fr_min-content] p-0 overflow-hidden box-content pointer-events-auto"
|
|
37
|
+
],
|
|
38
|
+
onEscapeKeyDown: onEscape,
|
|
39
|
+
onInteractOutside: preventDefault
|
|
40
|
+
}, children))));
|
|
53
41
|
};
|
|
54
42
|
ChatDialogRoot.displayName = "ChatDialog.Root";
|
|
43
|
+
var CHAT_DIALOG_HEADER_NAME = "ChatDialog.Header";
|
|
55
44
|
var ChatDialogHeader = ({ classNames, title }) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
73
|
-
})));
|
|
74
|
-
} finally {
|
|
75
|
-
_effect.f();
|
|
76
|
-
}
|
|
45
|
+
const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);
|
|
46
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
47
|
+
className: mx("grid grid-cols-[var(--dx-rail-action)_1fr_min-content] items-center overflow-hidden", classNames)
|
|
48
|
+
}, /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(Dialog.Close, null, /* @__PURE__ */ React.createElement(Icon, {
|
|
49
|
+
icon: "ph--x--regular"
|
|
50
|
+
}))), /* @__PURE__ */ React.createElement(Dialog.Title, {
|
|
51
|
+
classNames: "flex w-full justify-center text-sm text-subdued select-none cursor-pointer",
|
|
52
|
+
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
53
|
+
}, title), /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
|
|
54
|
+
variant: "ghost",
|
|
55
|
+
icon: "ph--caret-up--regular",
|
|
56
|
+
iconOnly: true,
|
|
57
|
+
classNames: mx("p-1! [&>svg]:transition [&>svg]:duration-200", expanded && "[&>svg]:rotate-180"),
|
|
58
|
+
label: expanded ? "Close" : "Open",
|
|
59
|
+
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
60
|
+
})));
|
|
77
61
|
};
|
|
78
|
-
ChatDialogHeader.displayName =
|
|
62
|
+
ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
|
|
63
|
+
var CHAT_DIALOG_CONTENT_NAME = "ChatDialog.Content";
|
|
79
64
|
var ChatDialogContent = ({ children, classNames }) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
])
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
onSizeChange: setSize
|
|
102
|
-
}), children);
|
|
103
|
-
} finally {
|
|
104
|
-
_effect.f();
|
|
105
|
-
}
|
|
65
|
+
const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setSize(expanded ? "min-content" : 0);
|
|
68
|
+
}, [
|
|
69
|
+
expanded
|
|
70
|
+
]);
|
|
71
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
72
|
+
className: mx("border-t border-b border-subdued-separator", 'transition ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200', classNames),
|
|
73
|
+
style: {
|
|
74
|
+
...sizeStyle(size, "vertical", true),
|
|
75
|
+
maxBlockSize: "calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)"
|
|
76
|
+
},
|
|
77
|
+
...resizeAttributes
|
|
78
|
+
}, /* @__PURE__ */ React.createElement(ResizeHandle, {
|
|
79
|
+
side: "block-start",
|
|
80
|
+
iconPosition: "center",
|
|
81
|
+
defaultSize: "min-content",
|
|
82
|
+
fallbackSize: 0,
|
|
83
|
+
minSize: 0,
|
|
84
|
+
onSizeChange: setSize
|
|
85
|
+
}), children);
|
|
106
86
|
};
|
|
107
|
-
ChatDialogContent.displayName =
|
|
87
|
+
ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
|
|
88
|
+
var CHAT_DIALOG_FOOTER_NAME = "ChatDialog.Footer";
|
|
108
89
|
var ChatDialogFooter = ({ children, classNames }) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
className: mx(classNames)
|
|
113
|
-
}, children);
|
|
114
|
-
} finally {
|
|
115
|
-
_effect.f();
|
|
116
|
-
}
|
|
90
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
91
|
+
className: mx(classNames)
|
|
92
|
+
}, children);
|
|
117
93
|
};
|
|
118
|
-
ChatDialogFooter.displayName =
|
|
94
|
+
ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
|
|
119
95
|
var ChatDialog = {
|
|
120
96
|
Root: ChatDialogRoot,
|
|
121
97
|
Header: ChatDialogHeader,
|
|
@@ -129,31 +105,23 @@ import { RangeSet } from "@codemirror/state";
|
|
|
129
105
|
import { Decoration, EditorView, ViewPlugin, WidgetType, keymap } from "@codemirror/view";
|
|
130
106
|
import { Mutex } from "@dxos/async";
|
|
131
107
|
import { invariant } from "@dxos/invariant";
|
|
132
|
-
function _define_property(obj, key, value) {
|
|
133
|
-
if (key in obj) {
|
|
134
|
-
Object.defineProperty(obj, key, {
|
|
135
|
-
value,
|
|
136
|
-
enumerable: true,
|
|
137
|
-
configurable: true,
|
|
138
|
-
writable: true
|
|
139
|
-
});
|
|
140
|
-
} else {
|
|
141
|
-
obj[key] = value;
|
|
142
|
-
}
|
|
143
|
-
return obj;
|
|
144
|
-
}
|
|
145
108
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-chat/src/components/ChatEditor/references.ts";
|
|
146
109
|
var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
147
|
-
invariant(triggerCharacter.length === 1, void 0, {
|
|
148
|
-
F: __dxlog_file,
|
|
149
|
-
L: 50,
|
|
150
|
-
S: void 0,
|
|
151
|
-
A: [
|
|
152
|
-
"triggerCharacter.length === 1",
|
|
153
|
-
""
|
|
154
|
-
]
|
|
155
|
-
});
|
|
110
|
+
invariant(triggerCharacter.length === 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 14, S: void 0, A: ["triggerCharacter.length === 1", ""] });
|
|
156
111
|
const decorationField = ViewPlugin.fromClass(class ReferenceView {
|
|
112
|
+
// TODO(burdon): Why?
|
|
113
|
+
_mutex = new Mutex();
|
|
114
|
+
decorations = Decoration.set([]);
|
|
115
|
+
constructor(view) {
|
|
116
|
+
queueMicrotask(async () => {
|
|
117
|
+
const guard = await this._mutex.acquire();
|
|
118
|
+
try {
|
|
119
|
+
this.decorations = await this._computeDecorations(view);
|
|
120
|
+
} finally {
|
|
121
|
+
guard.release();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
157
125
|
update(update) {
|
|
158
126
|
if (update.docChanged) {
|
|
159
127
|
queueMicrotask(async () => {
|
|
@@ -184,21 +152,9 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
184
152
|
}
|
|
185
153
|
return Decoration.set(decorations);
|
|
186
154
|
}
|
|
187
|
-
constructor(view) {
|
|
188
|
-
_define_property(this, "_mutex", new Mutex());
|
|
189
|
-
_define_property(this, "decorations", Decoration.set([]));
|
|
190
|
-
queueMicrotask(async () => {
|
|
191
|
-
const guard = await this._mutex.acquire();
|
|
192
|
-
try {
|
|
193
|
-
this.decorations = await this._computeDecorations(view);
|
|
194
|
-
} finally {
|
|
195
|
-
guard.release();
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
155
|
}, {
|
|
200
156
|
decorations: (v) => v.decorations,
|
|
201
|
-
provide: (
|
|
157
|
+
provide: () => [
|
|
202
158
|
EditorView.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
|
|
203
159
|
]
|
|
204
160
|
});
|
|
@@ -213,7 +169,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
213
169
|
}
|
|
214
170
|
}),
|
|
215
171
|
autocompletion({
|
|
216
|
-
tooltipClass: () => "shadow rounded",
|
|
172
|
+
tooltipClass: () => "shadow rounded-sm",
|
|
217
173
|
activateOnTyping: true,
|
|
218
174
|
aboveCursor: true,
|
|
219
175
|
closeOnBlur: !debug,
|
|
@@ -242,132 +198,162 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
242
198
|
];
|
|
243
199
|
};
|
|
244
200
|
var ReferenceWidget = class extends WidgetType {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
span.className = "cm-reference-pill";
|
|
249
|
-
return span;
|
|
250
|
-
}
|
|
251
|
-
eq(other) {
|
|
252
|
-
return other.data.uri === this.data.uri;
|
|
201
|
+
data;
|
|
202
|
+
constructor(data) {
|
|
203
|
+
super(), this.data = data;
|
|
253
204
|
}
|
|
254
205
|
ignoreEvent() {
|
|
255
206
|
return true;
|
|
256
207
|
}
|
|
257
|
-
|
|
258
|
-
|
|
208
|
+
eq(other) {
|
|
209
|
+
return this.data.uri === other.data.uri;
|
|
210
|
+
}
|
|
211
|
+
toDOM() {
|
|
212
|
+
const span = document.createElement("span");
|
|
213
|
+
span.textContent = `@${this.data.label}`;
|
|
214
|
+
span.className = "cm-reference-pill";
|
|
215
|
+
return span;
|
|
259
216
|
}
|
|
260
217
|
};
|
|
261
218
|
|
|
262
219
|
// src/components/ChatEditor/ChatEditor.tsx
|
|
263
|
-
import {
|
|
264
|
-
import { keymap as keymap2 } from "@codemirror/view";
|
|
265
|
-
import { useFocusFinders } from "@fluentui/react-tabster";
|
|
266
|
-
import React2, { forwardRef, useImperativeHandle } from "react";
|
|
220
|
+
import React2, { forwardRef, useMemo } from "react";
|
|
267
221
|
import { useThemeContext } from "@dxos/react-ui";
|
|
268
|
-
import {
|
|
269
|
-
import {
|
|
222
|
+
import { Editor } from "@dxos/react-ui-editor";
|
|
223
|
+
import { createBasicExtensions, createThemeExtensions, submit, xmlFormatting } from "@dxos/ui-editor";
|
|
270
224
|
import { isTruthy } from "@dxos/util";
|
|
271
|
-
var
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
bracketMatching: false,
|
|
285
|
-
lineWrapping,
|
|
286
|
-
placeholder
|
|
287
|
-
}),
|
|
288
|
-
autocomplete({
|
|
289
|
-
onSubmit,
|
|
290
|
-
onSuggest,
|
|
291
|
-
onCancel
|
|
292
|
-
}),
|
|
293
|
-
references2 ? references({
|
|
294
|
-
provider: references2.provider
|
|
295
|
-
}) : [],
|
|
296
|
-
// TODO(burdon): Standardize.
|
|
297
|
-
keymap2.of([
|
|
298
|
-
{
|
|
299
|
-
key: "Tab",
|
|
300
|
-
preventDefault: true,
|
|
301
|
-
run: (view2) => {
|
|
302
|
-
findNextFocusable(view2.dom)?.focus();
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
key: "Shift-Tab",
|
|
308
|
-
preventDefault: true,
|
|
309
|
-
run: (view2) => {
|
|
310
|
-
findPrevFocusable(view2.dom)?.focus();
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
]),
|
|
315
|
-
extensions
|
|
316
|
-
].filter(isTruthy)
|
|
317
|
-
}), [
|
|
318
|
-
themeMode,
|
|
319
|
-
extensions,
|
|
320
|
-
onSubmit,
|
|
321
|
-
onSuggest,
|
|
322
|
-
onCancel
|
|
323
|
-
]);
|
|
324
|
-
useImperativeHandle(forwardRef2, () => {
|
|
325
|
-
return {
|
|
326
|
-
focus: () => {
|
|
327
|
-
view?.focus();
|
|
328
|
-
},
|
|
329
|
-
getText: () => view?.state.doc.toString() ?? "",
|
|
330
|
-
setText: (text) => {
|
|
331
|
-
view?.dispatch({
|
|
332
|
-
changes: {
|
|
333
|
-
from: 0,
|
|
334
|
-
to: view.state.doc.length,
|
|
335
|
-
insert: text
|
|
336
|
-
},
|
|
337
|
-
selection: {
|
|
338
|
-
anchor: text.length,
|
|
339
|
-
head: text.length
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}, [
|
|
345
|
-
view,
|
|
225
|
+
var useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }) => {
|
|
226
|
+
const { themeMode } = useThemeContext();
|
|
227
|
+
return useMemo(() => [
|
|
228
|
+
createThemeExtensions({
|
|
229
|
+
themeMode
|
|
230
|
+
}),
|
|
231
|
+
createBasicExtensions({
|
|
232
|
+
bracketMatching: false,
|
|
233
|
+
lineWrapping,
|
|
234
|
+
placeholder
|
|
235
|
+
}),
|
|
236
|
+
xmlFormatting(),
|
|
237
|
+
submit({
|
|
346
238
|
onSubmit
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
239
|
+
}),
|
|
240
|
+
extensions
|
|
241
|
+
].filter(isTruthy), [
|
|
242
|
+
themeMode,
|
|
243
|
+
extensions,
|
|
244
|
+
onSubmit
|
|
245
|
+
]);
|
|
246
|
+
};
|
|
247
|
+
var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef3) => {
|
|
248
|
+
const extensions = useChatExtensions({
|
|
249
|
+
extensions: extensionsProp,
|
|
250
|
+
lineWrapping,
|
|
251
|
+
placeholder,
|
|
252
|
+
onSubmit
|
|
253
|
+
});
|
|
254
|
+
return /* @__PURE__ */ React2.createElement(Editor.Root, {
|
|
255
|
+
ref: forwardRef3
|
|
256
|
+
}, /* @__PURE__ */ React2.createElement(Editor.View, {
|
|
257
|
+
classNames,
|
|
258
|
+
autoFocus,
|
|
259
|
+
extensions
|
|
260
|
+
}));
|
|
355
261
|
});
|
|
356
262
|
|
|
357
|
-
// src/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
263
|
+
// src/components/ChatStatus/ChatStatus.tsx
|
|
264
|
+
import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
265
|
+
import React3, { forwardRef as forwardRef2, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
|
|
266
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
267
|
+
|
|
268
|
+
// src/components/ChatStatus/format.ts
|
|
269
|
+
var SECOND = 1e3;
|
|
270
|
+
var MINUTE = 60 * SECOND;
|
|
271
|
+
var HOUR = 60 * MINUTE;
|
|
272
|
+
var formatElapsed = (ms) => {
|
|
273
|
+
const safe = Math.max(0, ms);
|
|
274
|
+
if (safe < MINUTE) {
|
|
275
|
+
return `${Math.floor(safe / SECOND)}s`;
|
|
276
|
+
}
|
|
277
|
+
if (safe < HOUR) {
|
|
278
|
+
const m2 = Math.floor(safe / MINUTE);
|
|
279
|
+
const s = Math.floor(safe % MINUTE / SECOND);
|
|
280
|
+
return `${m2}m ${s}s`;
|
|
281
|
+
}
|
|
282
|
+
const h = Math.floor(safe / HOUR);
|
|
283
|
+
const m = Math.floor(safe % HOUR / MINUTE);
|
|
284
|
+
return `${h}h ${m}m`;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/components/ChatStatus/ChatStatus.tsx
|
|
288
|
+
var TICK_MS = 1e3;
|
|
289
|
+
var [ChatStatusProvider, useChatStatusContext] = createContext2("ChatStatus");
|
|
290
|
+
var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, defaultRunning = true }, forwardedRef) => {
|
|
291
|
+
const [elapsed, setElapsed] = useState2(0);
|
|
292
|
+
const [running, setRunning] = useState2(defaultRunning);
|
|
293
|
+
useEffect2(() => {
|
|
294
|
+
if (!running) {
|
|
295
|
+
return;
|
|
363
296
|
}
|
|
297
|
+
const startedAt = Date.now() - elapsed * TICK_MS;
|
|
298
|
+
let timeout;
|
|
299
|
+
const tick = () => {
|
|
300
|
+
setElapsed(Math.floor((Date.now() - startedAt) / TICK_MS));
|
|
301
|
+
timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
|
|
302
|
+
};
|
|
303
|
+
timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
|
|
304
|
+
return () => clearTimeout(timeout);
|
|
305
|
+
}, [
|
|
306
|
+
running
|
|
307
|
+
]);
|
|
308
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
309
|
+
start: () => setRunning(true),
|
|
310
|
+
stop: () => setRunning(false)
|
|
311
|
+
}), []);
|
|
312
|
+
return /* @__PURE__ */ React3.createElement(ChatStatusProvider, {
|
|
313
|
+
elapsed,
|
|
314
|
+
running
|
|
315
|
+
}, /* @__PURE__ */ React3.createElement("span", {
|
|
316
|
+
className: mx2("inline-flex items-center gap-2 text-description font-mono tabular-nums", classNames)
|
|
317
|
+
}, children));
|
|
318
|
+
});
|
|
319
|
+
Root.displayName = "ChatChatStatus.Root";
|
|
320
|
+
var Icon2 = ({ classNames, children }) => {
|
|
321
|
+
if (children !== void 0) {
|
|
322
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
|
|
364
323
|
}
|
|
365
|
-
|
|
324
|
+
return /* @__PURE__ */ React3.createElement("span", {
|
|
325
|
+
"aria-hidden": "true",
|
|
326
|
+
className: mx2("inline-block size-2 rounded-full bg-current animate-halo-pulse", classNames)
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
var Stopwatch = ({ classNames, offset = 0 }) => {
|
|
330
|
+
const { elapsed } = useChatStatusContext("ChatChatStatus.Stopwatch");
|
|
331
|
+
return /* @__PURE__ */ React3.createElement("span", {
|
|
332
|
+
"aria-live": "off",
|
|
333
|
+
className: mx2(classNames)
|
|
334
|
+
}, formatElapsed((elapsed + offset) * 1e3));
|
|
335
|
+
};
|
|
336
|
+
var Separator = ({ classNames }) => /* @__PURE__ */ React3.createElement("span", {
|
|
337
|
+
"aria-hidden": "true",
|
|
338
|
+
className: mx2("opacity-50", classNames)
|
|
339
|
+
}, "\xB7");
|
|
340
|
+
var Text = ({ classNames, children }) => /* @__PURE__ */ React3.createElement("span", {
|
|
341
|
+
className: mx2(classNames)
|
|
342
|
+
}, children);
|
|
343
|
+
var ChatStatus = {
|
|
344
|
+
Root,
|
|
345
|
+
Icon: Icon2,
|
|
346
|
+
Stopwatch,
|
|
347
|
+
Separator,
|
|
348
|
+
Text
|
|
349
|
+
};
|
|
366
350
|
export {
|
|
367
351
|
ChatDialog,
|
|
368
352
|
ChatEditor,
|
|
353
|
+
ChatStatus,
|
|
354
|
+
formatElapsed,
|
|
369
355
|
references,
|
|
370
|
-
|
|
371
|
-
|
|
356
|
+
useChatExtensions,
|
|
357
|
+
useChatStatusContext
|
|
372
358
|
};
|
|
373
359
|
//# sourceMappingURL=index.mjs.map
|