@dxos/react-ui-chat 0.8.4-main.b97322e → 0.8.4-main.f5c0578
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/lib/browser/index.mjs +12 -8
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +12 -8
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +1 -0
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/autocomplete.d.ts +2 -1
- package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -24
- package/src/components/ChatDialog/ChatDialog.stories.tsx +4 -3
- package/src/components/ChatDialog/ChatDialog.tsx +2 -2
- package/src/components/ChatEditor/ChatEditor.stories.tsx +3 -2
- package/src/components/ChatEditor/ChatEditor.tsx +4 -2
- package/src/components/ChatEditor/autocomplete.ts +8 -6
- package/src/components/ChatEditor/references.ts +1 -1
|
@@ -3,7 +3,7 @@ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
|
3
3
|
import { createContext } from "@radix-ui/react-context";
|
|
4
4
|
import React, { useEffect, useState } from "react";
|
|
5
5
|
import { Dialog, Icon, IconButton, useControlledState } from "@dxos/react-ui";
|
|
6
|
-
import {
|
|
6
|
+
import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
7
7
|
import { mx } from "@dxos/react-ui-theme";
|
|
8
8
|
var preventDefault = (event) => event.preventDefault();
|
|
9
9
|
var Endcap = ({ children }) => {
|
|
@@ -141,10 +141,10 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
141
141
|
]
|
|
142
142
|
});
|
|
143
143
|
const decorationField = ViewPlugin.fromClass(class ReferenceView {
|
|
144
|
+
// TODO(burdon): Why?
|
|
145
|
+
_mutex = new Mutex();
|
|
146
|
+
decorations = Decoration.set([]);
|
|
144
147
|
constructor(view) {
|
|
145
|
-
// TODO(burdon): Why?
|
|
146
|
-
this._mutex = new Mutex();
|
|
147
|
-
this.decorations = Decoration.set([]);
|
|
148
148
|
queueMicrotask(async () => {
|
|
149
149
|
const guard = await this._mutex.acquire();
|
|
150
150
|
try {
|
|
@@ -230,6 +230,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
230
230
|
];
|
|
231
231
|
};
|
|
232
232
|
var ReferenceWidget = class extends WidgetType {
|
|
233
|
+
data;
|
|
233
234
|
constructor(data) {
|
|
234
235
|
super(), this.data = data;
|
|
235
236
|
}
|
|
@@ -257,11 +258,12 @@ import { isNonNullable } from "@dxos/util";
|
|
|
257
258
|
|
|
258
259
|
// src/components/ChatEditor/autocomplete.ts
|
|
259
260
|
import { Prec } from "@codemirror/state";
|
|
260
|
-
import {
|
|
261
|
-
var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
261
|
+
import { Decoration as Decoration2, EditorView as EditorView2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2, keymap as keymap2 } from "@codemirror/view";
|
|
262
|
+
var autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }) => {
|
|
262
263
|
const suggest = ViewPlugin2.fromClass(class {
|
|
264
|
+
_decorations;
|
|
265
|
+
_currentSuggestion = null;
|
|
263
266
|
constructor(view) {
|
|
264
|
-
this._currentSuggestion = null;
|
|
265
267
|
this._decorations = this.computeDecorations(view);
|
|
266
268
|
}
|
|
267
269
|
update(update) {
|
|
@@ -343,7 +345,7 @@ var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
|
343
345
|
preventDefault: true,
|
|
344
346
|
run: (view) => {
|
|
345
347
|
const text = view.state.doc.toString().trim();
|
|
346
|
-
if (text.length > 0
|
|
348
|
+
if (onSubmit && (fireIfEmpty || text.length > 0)) {
|
|
347
349
|
const reset = onSubmit(text);
|
|
348
350
|
if (reset) {
|
|
349
351
|
view.dispatch({
|
|
@@ -394,6 +396,7 @@ var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
|
394
396
|
];
|
|
395
397
|
};
|
|
396
398
|
var InlineSuggestionWidget = class extends WidgetType2 {
|
|
399
|
+
suffix;
|
|
397
400
|
constructor(suffix) {
|
|
398
401
|
super(), this.suffix = suffix;
|
|
399
402
|
}
|
|
@@ -446,6 +449,7 @@ var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, extensions, reference
|
|
|
446
449
|
focus: () => {
|
|
447
450
|
view?.focus();
|
|
448
451
|
},
|
|
452
|
+
getText: () => view?.state.doc.toString() ?? "",
|
|
449
453
|
setText: (text) => {
|
|
450
454
|
view?.dispatch({
|
|
451
455
|
changes: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ChatDialog/ChatDialog.tsx", "../../../src/components/ChatEditor/references.ts", "../../../src/components/ChatEditor/ChatEditor.tsx", "../../../src/components/ChatEditor/autocomplete.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, useControlledState, type ThemedClassName } from '@dxos/react-ui';\nimport { resizeAttributes, ResizeHandle, type Size, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: _open = false,\n expanded: _expanded = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(_expanded, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // The dialog has no vertical padding and has box-content so that when closed it collapses to the size of the header and prompt bar.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',\n 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);\n\n return (\n <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = 'ChatDialog.Header';\n\n//\n// Content\n//\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',\n 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = 'ChatDialog.Content';\n\n//\n// Footer\n//\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = 'ChatDialog.Footer';\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { autocompletion, completionKeymap, type CompletionResult } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string;\n label: string;\n};\n\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n */\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: (plugin) => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = `@ ${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n\n override eq(other: ReferenceWidget): boolean {\n return other.data.uri === this.data.uri;\n }\n\n override ignoreEvent(): boolean {\n return true;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport {\n type BasicExtensionsOptions,\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nimport { autocomplete, type AutocompleteOptions } from './autocomplete';\nimport { references as referencesExtension, type ReferencesOptions } from './references';\n\n// TODO(burdon): Handle object references.\n\nexport interface ChatEditorController {\n focus(): void;\n setText(text: string): void;\n}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & AutocompleteOptions &\n Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>\n>;\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n (\n { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },\n forwardRef,\n ) => {\n const { themeMode } = useThemeContext();\n const { parentRef, view } = useTextEditor(\n {\n debug: true,\n autoFocus,\n extensions: [\n createThemeExtensions({ themeMode }),\n autocomplete({ onSubmit, onSuggest, onCancel }),\n references ? referencesExtension({ provider: references.provider }) : [],\n createBasicExtensions({\n bracketMatching: false,\n lineWrapping,\n placeholder,\n }),\n extensions,\n ].filter(isNonNullable),\n },\n [themeMode, extensions, onSubmit, onSuggest],\n );\n\n // Expose editor view.\n useImperativeHandle(forwardRef, () => {\n return {\n focus: () => {\n view?.focus();\n },\n setText: (text: string) => {\n view?.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: text,\n },\n selection: {\n anchor: text.length,\n head: text.length,\n },\n });\n },\n };\n }, [view, onSubmit]);\n\n return <div ref={parentRef} className={mx('is-full', classNames)} />;\n },\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Prec, type Extension } from '@codemirror/state';\nimport {\n EditorView,\n Decoration,\n ViewPlugin,\n keymap,\n type DecorationSet,\n type ViewUpdate,\n WidgetType,\n} from '@codemirror/view';\n\nexport type AutocompleteOptions = {\n /**\n * Callback triggered when Enter is pressed.\n * @param text The current text in the editor\n * @returns true if the editor should reset the document.\n */\n onSubmit?: (text: string) => boolean | void;\n\n /**\n * Function that returns a list of suggestions based on the current text.\n * @param text The current text before the cursor\n * @returns Array of suggestion strings\n */\n onSuggest?: (text: string) => string[];\n\n /**\n * ESC pressed.\n */\n onCancel?: () => void;\n};\n\n/**\n * Creates an autocomplete extension that shows inline suggestions.\n * Pressing Tab will complete the suggestion.\n */\n// TODO(burdon): Move to react-ui-editor.\nexport const autocomplete = ({ onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {\n const suggest = ViewPlugin.fromClass(\n class {\n _decorations: DecorationSet;\n _currentSuggestion: string | null = null;\n\n constructor(view: EditorView) {\n this._decorations = this.computeDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.selectionSet) {\n this._decorations = this.computeDecorations(update.view);\n }\n }\n\n private computeDecorations(view: EditorView): DecorationSet {\n const text = view.state.doc.toString();\n const suggestions = onSuggest?.(text) ?? [];\n if (!suggestions.length) {\n this._currentSuggestion = null;\n return Decoration.none;\n }\n\n // Get the first suggestion.\n this._currentSuggestion = suggestions[0];\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return Decoration.none;\n }\n\n // Always show ghost text at the end of the document.\n return Decoration.set([\n Decoration.widget({\n widget: new InlineSuggestionWidget(suffix),\n side: 1,\n }).range(view.state.doc.length),\n ]);\n }\n\n completeSuggestion(view: EditorView): boolean {\n if (!this._currentSuggestion) {\n return false;\n }\n\n const text = view.state.doc.toString();\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return false;\n }\n\n view.dispatch({\n changes: {\n from: view.state.doc.length,\n insert: suffix,\n },\n selection: {\n anchor: view.state.doc.length + suffix.length,\n },\n });\n\n return true;\n }\n },\n {\n decorations: (v) => v._decorations,\n },\n );\n\n return [\n suggest,\n EditorView.theme({\n '.cm-inline-suggestion': {\n opacity: 0.4,\n },\n }),\n\n Prec.highest(\n keymap.of([\n {\n key: 'Tab',\n preventDefault: true,\n run: (view) => {\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'ArrowRight',\n preventDefault: true,\n run: (view) => {\n // Only complete if cursor is at the end\n if (view.state.selection.main.head !== view.state.doc.length) {\n return false;\n }\n\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'Enter',\n preventDefault: true,\n run: (view) => {\n const text = view.state.doc.toString().trim();\n if (text.length > 0 && onSubmit) {\n const reset = onSubmit(text);\n\n // Clear the document after calling onEnter.\n if (reset) {\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n }\n }\n\n return true;\n },\n },\n {\n key: 'Shift-Enter',\n preventDefault: true,\n run: (view) => {\n view.dispatch({\n changes: {\n from: view.state.selection.main.head,\n insert: '\\n',\n },\n selection: {\n anchor: view.state.selection.main.head + 1,\n head: view.state.selection.main.head + 1,\n },\n });\n return true;\n },\n },\n {\n key: 'Escape',\n preventDefault: true,\n run: (view) => {\n // Clear the entire document.\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n onCancel?.();\n return true;\n },\n },\n ]),\n ),\n ];\n};\n\nclass InlineSuggestionWidget extends WidgetType {\n constructor(private suffix: string) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = this.suffix;\n span.className = 'cm-inline-suggestion';\n return span;\n }\n\n override eq(other: InlineSuggestionWidget): boolean {\n return other.suffix === this.suffix;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,SAAqEC,WAAWC,gBAAgB;AAEvG,SAASC,QAAQC,MAAMC,
|
|
6
|
-
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';\nimport { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: _open = false,\n expanded: _expanded = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(_expanded, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // The dialog has no vertical padding and has box-content so that when closed it collapses to the size of the header and prompt bar.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',\n 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);\n\n return (\n <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = 'ChatDialog.Header';\n\n//\n// Content\n//\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',\n 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = 'ChatDialog.Content';\n\n//\n// Footer\n//\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = 'ChatDialog.Footer';\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type CompletionResult, autocompletion, completionKeymap } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string;\n label: string;\n};\n\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n */\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: (plugin) => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = `@ ${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n\n override eq(other: ReferenceWidget): boolean {\n return other.data.uri === this.data.uri;\n }\n\n override ignoreEvent(): boolean {\n return true;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport {\n type BasicExtensionsOptions,\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type AutocompleteOptions, autocomplete } from './autocomplete';\nimport { type ReferencesOptions, references as referencesExtension } from './references';\n\n// TODO(burdon): Handle object references.\n\nexport interface ChatEditorController {\n focus(): void;\n getText(): string;\n setText(text: string): void;\n}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & AutocompleteOptions &\n Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>\n>;\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n (\n { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },\n forwardRef,\n ) => {\n const { themeMode } = useThemeContext();\n const { parentRef, view } = useTextEditor(\n {\n debug: true,\n autoFocus,\n extensions: [\n createThemeExtensions({ themeMode }),\n autocomplete({ onSubmit, onSuggest, onCancel }),\n references ? referencesExtension({ provider: references.provider }) : [],\n createBasicExtensions({\n bracketMatching: false,\n lineWrapping,\n placeholder,\n }),\n extensions,\n ].filter(isNonNullable),\n },\n [themeMode, extensions, onSubmit, onSuggest],\n );\n\n // Expose editor view.\n useImperativeHandle(forwardRef, () => {\n return {\n focus: () => {\n view?.focus();\n },\n getText: () => view?.state.doc.toString() ?? '',\n setText: (text: string) => {\n view?.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: text,\n },\n selection: {\n anchor: text.length,\n head: text.length,\n },\n });\n },\n };\n }, [view, onSubmit]);\n\n return <div ref={parentRef} className={mx('is-full', classNames)} />;\n },\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension, Prec } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nexport type AutocompleteOptions = {\n fireIfEmpty?: boolean;\n\n /**\n * Callback triggered when Enter is pressed.\n * @param text The current text in the editor\n * @returns true if the editor should reset the document.\n */\n onSubmit?: (text: string) => boolean | void;\n\n /**\n * Function that returns a list of suggestions based on the current text.\n * @param text The current text before the cursor\n * @returns Array of suggestion strings\n */\n onSuggest?: (text: string) => string[];\n\n /**\n * ESC pressed.\n */\n onCancel?: () => void;\n};\n\n/**\n * Creates an autocomplete extension that shows inline suggestions.\n * Pressing Tab will complete the suggestion.\n */\n// TODO(burdon): Move to react-ui-editor.\nexport const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {\n const suggest = ViewPlugin.fromClass(\n class {\n _decorations: DecorationSet;\n _currentSuggestion: string | null = null;\n\n constructor(view: EditorView) {\n this._decorations = this.computeDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.selectionSet) {\n this._decorations = this.computeDecorations(update.view);\n }\n }\n\n private computeDecorations(view: EditorView): DecorationSet {\n const text = view.state.doc.toString();\n const suggestions = onSuggest?.(text) ?? [];\n if (!suggestions.length) {\n this._currentSuggestion = null;\n return Decoration.none;\n }\n\n // Get the first suggestion.\n this._currentSuggestion = suggestions[0];\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return Decoration.none;\n }\n\n // Always show ghost text at the end of the document.\n return Decoration.set([\n Decoration.widget({\n widget: new InlineSuggestionWidget(suffix),\n side: 1,\n }).range(view.state.doc.length),\n ]);\n }\n\n completeSuggestion(view: EditorView): boolean {\n if (!this._currentSuggestion) {\n return false;\n }\n\n const text = view.state.doc.toString();\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return false;\n }\n\n view.dispatch({\n changes: {\n from: view.state.doc.length,\n insert: suffix,\n },\n selection: {\n anchor: view.state.doc.length + suffix.length,\n },\n });\n\n return true;\n }\n },\n {\n decorations: (v) => v._decorations,\n },\n );\n\n return [\n suggest,\n EditorView.theme({\n '.cm-inline-suggestion': {\n opacity: 0.4,\n },\n }),\n\n Prec.highest(\n keymap.of([\n {\n key: 'Tab',\n preventDefault: true,\n run: (view) => {\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'ArrowRight',\n preventDefault: true,\n run: (view) => {\n // Only complete if cursor is at the end\n if (view.state.selection.main.head !== view.state.doc.length) {\n return false;\n }\n\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'Enter',\n preventDefault: true,\n run: (view) => {\n const text = view.state.doc.toString().trim();\n if (onSubmit && (fireIfEmpty || text.length > 0)) {\n const reset = onSubmit(text);\n\n // Clear the document after calling onEnter.\n if (reset) {\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n }\n }\n\n return true;\n },\n },\n {\n key: 'Shift-Enter',\n preventDefault: true,\n run: (view) => {\n view.dispatch({\n changes: {\n from: view.state.selection.main.head,\n insert: '\\n',\n },\n selection: {\n anchor: view.state.selection.main.head + 1,\n head: view.state.selection.main.head + 1,\n },\n });\n return true;\n },\n },\n {\n key: 'Escape',\n preventDefault: true,\n run: (view) => {\n // Clear the entire document.\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n onCancel?.();\n return true;\n },\n },\n ]),\n ),\n ];\n};\n\nclass InlineSuggestionWidget extends WidgetType {\n constructor(private suffix: string) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = this.suffix;\n span.className = 'cm-inline-suggestion';\n return span;\n }\n\n override eq(other: InlineSuggestionWidget): boolean {\n return other.suffix === this.suffix;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,SAAqEC,WAAWC,gBAAgB;AAEvG,SAASC,QAAQC,MAAMC,YAAkCC,0BAA0B;AACnF,SAASC,cAAyBC,kBAAkBC,iBAAiB;AACrE,SAASC,UAAU;AAEnB,IAAMC,iBAAiB,CAACC,UAAiBA,MAAMD,eAAc;AAG7D,IAAME,SAAS,CAAC,EAAEC,SAAQ,MAAqB;;;AAC7C,WACE,sBAAA,cAACC,OAAAA;MAAIC,WAAU;OAAkFF,QAAAA;;;;AAErG;AAeA,IAAM,CAACG,2BAA2BC,oBAAAA,IAAwBC,cAAsC,YAAA;AAchG,IAAMC,iBAAiB,CAAC,EACtBN,UACAO,MAAMC,QAAQ,OACdC,UAAUC,YAAY,OACtBC,cACAC,kBACAC,SAAQ,MACY;;;AACpB,UAAM,CAACC,MAAMC,OAAAA,IAAWC,SAAe,aAAA;AACvC,UAAM,CAACT,MAAMU,OAAAA,IAAWC,mBAA4BV,OAAOG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c,MAAMC,IAAIC,SAAAA,KAAc;QAC7CC,SAAS,CAACC,SAAAA;AACRlB,gBAAMmB,SAAS;YACbC,SAAS;cACPC,MAAM;cACNC,IAAItB,KAAKc,MAAMC,IAAIQ;cACnBC,QAAQN;YACV;YACAO,WAAW;cACTC,QAAQR,KAAKK;cACbI,MAAMT,KAAKK;YACb;UACF,CAAA;QACF;MACF;IACF,GAAG;MAACvB;MAAMN;KAAS;AAEnB,WAAO,gBAAAkC,OAAA,cAACC,OAAAA;MAAIC,KAAK/B;MAAWgC,WAAWC,IAAG,WAAW5C,UAAAA;;;;;AACvD,CAAA;",
|
|
6
|
+
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "ResizeHandle", "resizeAttributes", "sizeStyle", "mx", "preventDefault", "event", "Endcap", "children", "div", "className", "ChatDialogContextProvider", "useChatDialogContext", "createContext", "ChatDialogRoot", "open", "_open", "expanded", "_expanded", "onOpenChange", "onExpandedChange", "onEscape", "size", "setSize", "useState", "setOpen", "useControlledState", "setExpanded", "Dialog", "Root", "modal", "role", "data-block-align", "Content", "inOverlayLayout", "classNames", "onEscapeKeyDown", "onInteractOutside", "displayName", "ChatDialogHeader", "title", "mx", "Close", "Icon", "icon", "Title", "onClick", "IconButton", "variant", "iconOnly", "label", "ChatDialogContent", "useEffect", "style", "sizeStyle", "maxBlockSize", "resizeAttributes", "ResizeHandle", "side", "iconPosition", "defaultSize", "fallbackSize", "minSize", "onSizeChange", "ChatDialogFooter", "ChatDialog", "Header", "Footer", "autocompletion", "completionKeymap", "RangeSet", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "keymap", "Mutex", "invariant", "references", "provider", "triggerCharacter", "debug", "length", "decorationField", "fromClass", "ReferenceView", "_mutex", "decorations", "set", "view", "queueMicrotask", "guard", "acquire", "_computeDecorations", "release", "update", "docChanged", "text", "state", "doc", "toString", "matchAll", "RegExp", "match", "reference", "uri", "slice", "data", "resolveReference", "push", "replace", "widget", "ReferenceWidget", "range", "index", "v", "provide", "plugin", "atomicRanges", "of", "empty", "theme", "borderRadius", "borderWidth", "marginRight", "marginLeft", "tooltipClass", "activateOnTyping", "aboveCursor", "closeOnBlur", "override", "context", "matchBefore", "to", "from", "query", "getReferences", "filter", "options", "map", "label", "apply", "toDOM", "span", "document", "createElement", "textContent", "className", "eq", "other", "ignoreEvent", "React", "forwardRef", "useImperativeHandle", "useThemeContext", "createBasicExtensions", "createThemeExtensions", "useTextEditor", "mx", "isNonNullable", "Prec", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "keymap", "autocomplete", "fireIfEmpty", "onSubmit", "onSuggest", "onCancel", "suggest", "ViewPlugin", "fromClass", "_decorations", "_currentSuggestion", "view", "computeDecorations", "update", "docChanged", "selectionSet", "text", "state", "doc", "toString", "suggestions", "length", "Decoration", "none", "suffix", "slice", "set", "widget", "InlineSuggestionWidget", "side", "range", "completeSuggestion", "dispatch", "changes", "from", "insert", "selection", "anchor", "decorations", "v", "EditorView", "theme", "opacity", "Prec", "highest", "keymap", "of", "key", "preventDefault", "run", "plugin", "main", "head", "trim", "reset", "to", "WidgetType", "toDOM", "span", "document", "createElement", "textContent", "className", "eq", "other", "ChatEditor", "forwardRef", "classNames", "extensions", "references", "autoFocus", "lineWrapping", "placeholder", "onSubmit", "onSuggest", "onCancel", "themeMode", "useThemeContext", "parentRef", "view", "useTextEditor", "debug", "createThemeExtensions", "autocomplete", "referencesExtension", "provider", "createBasicExtensions", "bracketMatching", "filter", "isNonNullable", "useImperativeHandle", "focus", "getText", "state", "doc", "toString", "setText", "text", "dispatch", "changes", "from", "to", "length", "insert", "selection", "anchor", "head", "React", "div", "ref", "className", "mx"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":17734,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatDialog/index.ts":{"bytes":480,"imports":[{"path":"src/components/ChatDialog/ChatDialog.tsx","kind":"import-statement","original":"./ChatDialog"}],"format":"esm"},"src/components/ChatEditor/references.ts":{"bytes":15921,"imports":[{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/autocomplete.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":17734,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatDialog/index.ts":{"bytes":480,"imports":[{"path":"src/components/ChatDialog/ChatDialog.tsx","kind":"import-statement","original":"./ChatDialog"}],"format":"esm"},"src/components/ChatEditor/references.ts":{"bytes":15921,"imports":[{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/autocomplete.ts":{"bytes":19079,"imports":[{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/ChatEditor.tsx":{"bytes":8783,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/components/ChatEditor/autocomplete.ts","kind":"import-statement","original":"./autocomplete"},{"path":"src/components/ChatEditor/references.ts","kind":"import-statement","original":"./references"}],"format":"esm"},"src/components/ChatEditor/index.ts":{"bytes":574,"imports":[{"path":"src/components/ChatEditor/references.ts","kind":"import-statement","original":"./references"},{"path":"src/components/ChatEditor/ChatEditor.tsx","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/components/index.ts":{"bytes":563,"imports":[{"path":"src/components/ChatDialog/index.ts","kind":"import-statement","original":"./ChatDialog"},{"path":"src/components/ChatEditor/index.ts","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/index.ts":{"bytes":458,"imports":[{"path":"src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":31251},"dist/lib/browser/index.mjs":{"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true}],"exports":["ChatDialog","ChatEditor","references"],"entryPoint":"src/index.ts","inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytesInOutput":4866},"src/components/ChatDialog/index.ts":{"bytesInOutput":0},"src/components/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/references.ts":{"bytesInOutput":3691},"src/components/ChatEditor/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/ChatEditor.tsx":{"bytesInOutput":1997},"src/components/ChatEditor/autocomplete.ts":{"bytesInOutput":4120},"src/index.ts":{"bytesInOutput":0}},"bytes":14986}}}
|
|
@@ -5,7 +5,7 @@ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
|
5
5
|
import { createContext } from "@radix-ui/react-context";
|
|
6
6
|
import React, { useEffect, useState } from "react";
|
|
7
7
|
import { Dialog, Icon, IconButton, useControlledState } from "@dxos/react-ui";
|
|
8
|
-
import {
|
|
8
|
+
import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
9
9
|
import { mx } from "@dxos/react-ui-theme";
|
|
10
10
|
var preventDefault = (event) => event.preventDefault();
|
|
11
11
|
var Endcap = ({ children }) => {
|
|
@@ -143,10 +143,10 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
143
143
|
]
|
|
144
144
|
});
|
|
145
145
|
const decorationField = ViewPlugin.fromClass(class ReferenceView {
|
|
146
|
+
// TODO(burdon): Why?
|
|
147
|
+
_mutex = new Mutex();
|
|
148
|
+
decorations = Decoration.set([]);
|
|
146
149
|
constructor(view) {
|
|
147
|
-
// TODO(burdon): Why?
|
|
148
|
-
this._mutex = new Mutex();
|
|
149
|
-
this.decorations = Decoration.set([]);
|
|
150
150
|
queueMicrotask(async () => {
|
|
151
151
|
const guard = await this._mutex.acquire();
|
|
152
152
|
try {
|
|
@@ -232,6 +232,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
232
232
|
];
|
|
233
233
|
};
|
|
234
234
|
var ReferenceWidget = class extends WidgetType {
|
|
235
|
+
data;
|
|
235
236
|
constructor(data) {
|
|
236
237
|
super(), this.data = data;
|
|
237
238
|
}
|
|
@@ -259,11 +260,12 @@ import { isNonNullable } from "@dxos/util";
|
|
|
259
260
|
|
|
260
261
|
// src/components/ChatEditor/autocomplete.ts
|
|
261
262
|
import { Prec } from "@codemirror/state";
|
|
262
|
-
import {
|
|
263
|
-
var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
263
|
+
import { Decoration as Decoration2, EditorView as EditorView2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2, keymap as keymap2 } from "@codemirror/view";
|
|
264
|
+
var autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }) => {
|
|
264
265
|
const suggest = ViewPlugin2.fromClass(class {
|
|
266
|
+
_decorations;
|
|
267
|
+
_currentSuggestion = null;
|
|
265
268
|
constructor(view) {
|
|
266
|
-
this._currentSuggestion = null;
|
|
267
269
|
this._decorations = this.computeDecorations(view);
|
|
268
270
|
}
|
|
269
271
|
update(update) {
|
|
@@ -345,7 +347,7 @@ var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
|
345
347
|
preventDefault: true,
|
|
346
348
|
run: (view) => {
|
|
347
349
|
const text = view.state.doc.toString().trim();
|
|
348
|
-
if (text.length > 0
|
|
350
|
+
if (onSubmit && (fireIfEmpty || text.length > 0)) {
|
|
349
351
|
const reset = onSubmit(text);
|
|
350
352
|
if (reset) {
|
|
351
353
|
view.dispatch({
|
|
@@ -396,6 +398,7 @@ var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
|
396
398
|
];
|
|
397
399
|
};
|
|
398
400
|
var InlineSuggestionWidget = class extends WidgetType2 {
|
|
401
|
+
suffix;
|
|
399
402
|
constructor(suffix) {
|
|
400
403
|
super(), this.suffix = suffix;
|
|
401
404
|
}
|
|
@@ -448,6 +451,7 @@ var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, extensions, reference
|
|
|
448
451
|
focus: () => {
|
|
449
452
|
view?.focus();
|
|
450
453
|
},
|
|
454
|
+
getText: () => view?.state.doc.toString() ?? "",
|
|
451
455
|
setText: (text) => {
|
|
452
456
|
view?.dispatch({
|
|
453
457
|
changes: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ChatDialog/ChatDialog.tsx", "../../../src/components/ChatEditor/references.ts", "../../../src/components/ChatEditor/ChatEditor.tsx", "../../../src/components/ChatEditor/autocomplete.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, useControlledState, type ThemedClassName } from '@dxos/react-ui';\nimport { resizeAttributes, ResizeHandle, type Size, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: _open = false,\n expanded: _expanded = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(_expanded, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // The dialog has no vertical padding and has box-content so that when closed it collapses to the size of the header and prompt bar.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',\n 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);\n\n return (\n <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = 'ChatDialog.Header';\n\n//\n// Content\n//\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',\n 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = 'ChatDialog.Content';\n\n//\n// Footer\n//\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = 'ChatDialog.Footer';\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { autocompletion, completionKeymap, type CompletionResult } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string;\n label: string;\n};\n\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n */\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: (plugin) => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = `@ ${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n\n override eq(other: ReferenceWidget): boolean {\n return other.data.uri === this.data.uri;\n }\n\n override ignoreEvent(): boolean {\n return true;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport {\n type BasicExtensionsOptions,\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nimport { autocomplete, type AutocompleteOptions } from './autocomplete';\nimport { references as referencesExtension, type ReferencesOptions } from './references';\n\n// TODO(burdon): Handle object references.\n\nexport interface ChatEditorController {\n focus(): void;\n setText(text: string): void;\n}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & AutocompleteOptions &\n Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>\n>;\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n (\n { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },\n forwardRef,\n ) => {\n const { themeMode } = useThemeContext();\n const { parentRef, view } = useTextEditor(\n {\n debug: true,\n autoFocus,\n extensions: [\n createThemeExtensions({ themeMode }),\n autocomplete({ onSubmit, onSuggest, onCancel }),\n references ? referencesExtension({ provider: references.provider }) : [],\n createBasicExtensions({\n bracketMatching: false,\n lineWrapping,\n placeholder,\n }),\n extensions,\n ].filter(isNonNullable),\n },\n [themeMode, extensions, onSubmit, onSuggest],\n );\n\n // Expose editor view.\n useImperativeHandle(forwardRef, () => {\n return {\n focus: () => {\n view?.focus();\n },\n setText: (text: string) => {\n view?.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: text,\n },\n selection: {\n anchor: text.length,\n head: text.length,\n },\n });\n },\n };\n }, [view, onSubmit]);\n\n return <div ref={parentRef} className={mx('is-full', classNames)} />;\n },\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Prec, type Extension } from '@codemirror/state';\nimport {\n EditorView,\n Decoration,\n ViewPlugin,\n keymap,\n type DecorationSet,\n type ViewUpdate,\n WidgetType,\n} from '@codemirror/view';\n\nexport type AutocompleteOptions = {\n /**\n * Callback triggered when Enter is pressed.\n * @param text The current text in the editor\n * @returns true if the editor should reset the document.\n */\n onSubmit?: (text: string) => boolean | void;\n\n /**\n * Function that returns a list of suggestions based on the current text.\n * @param text The current text before the cursor\n * @returns Array of suggestion strings\n */\n onSuggest?: (text: string) => string[];\n\n /**\n * ESC pressed.\n */\n onCancel?: () => void;\n};\n\n/**\n * Creates an autocomplete extension that shows inline suggestions.\n * Pressing Tab will complete the suggestion.\n */\n// TODO(burdon): Move to react-ui-editor.\nexport const autocomplete = ({ onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {\n const suggest = ViewPlugin.fromClass(\n class {\n _decorations: DecorationSet;\n _currentSuggestion: string | null = null;\n\n constructor(view: EditorView) {\n this._decorations = this.computeDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.selectionSet) {\n this._decorations = this.computeDecorations(update.view);\n }\n }\n\n private computeDecorations(view: EditorView): DecorationSet {\n const text = view.state.doc.toString();\n const suggestions = onSuggest?.(text) ?? [];\n if (!suggestions.length) {\n this._currentSuggestion = null;\n return Decoration.none;\n }\n\n // Get the first suggestion.\n this._currentSuggestion = suggestions[0];\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return Decoration.none;\n }\n\n // Always show ghost text at the end of the document.\n return Decoration.set([\n Decoration.widget({\n widget: new InlineSuggestionWidget(suffix),\n side: 1,\n }).range(view.state.doc.length),\n ]);\n }\n\n completeSuggestion(view: EditorView): boolean {\n if (!this._currentSuggestion) {\n return false;\n }\n\n const text = view.state.doc.toString();\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return false;\n }\n\n view.dispatch({\n changes: {\n from: view.state.doc.length,\n insert: suffix,\n },\n selection: {\n anchor: view.state.doc.length + suffix.length,\n },\n });\n\n return true;\n }\n },\n {\n decorations: (v) => v._decorations,\n },\n );\n\n return [\n suggest,\n EditorView.theme({\n '.cm-inline-suggestion': {\n opacity: 0.4,\n },\n }),\n\n Prec.highest(\n keymap.of([\n {\n key: 'Tab',\n preventDefault: true,\n run: (view) => {\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'ArrowRight',\n preventDefault: true,\n run: (view) => {\n // Only complete if cursor is at the end\n if (view.state.selection.main.head !== view.state.doc.length) {\n return false;\n }\n\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'Enter',\n preventDefault: true,\n run: (view) => {\n const text = view.state.doc.toString().trim();\n if (text.length > 0 && onSubmit) {\n const reset = onSubmit(text);\n\n // Clear the document after calling onEnter.\n if (reset) {\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n }\n }\n\n return true;\n },\n },\n {\n key: 'Shift-Enter',\n preventDefault: true,\n run: (view) => {\n view.dispatch({\n changes: {\n from: view.state.selection.main.head,\n insert: '\\n',\n },\n selection: {\n anchor: view.state.selection.main.head + 1,\n head: view.state.selection.main.head + 1,\n },\n });\n return true;\n },\n },\n {\n key: 'Escape',\n preventDefault: true,\n run: (view) => {\n // Clear the entire document.\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n onCancel?.();\n return true;\n },\n },\n ]),\n ),\n ];\n};\n\nclass InlineSuggestionWidget extends WidgetType {\n constructor(private suffix: string) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = this.suffix;\n span.className = 'cm-inline-suggestion';\n return span;\n }\n\n override eq(other: InlineSuggestionWidget): boolean {\n return other.suffix === this.suffix;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,SAAqEC,WAAWC,gBAAgB;AAEvG,SAASC,QAAQC,MAAMC,
|
|
6
|
-
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';\nimport { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: _open = false,\n expanded: _expanded = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(_expanded, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // The dialog has no vertical padding and has box-content so that when closed it collapses to the size of the header and prompt bar.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',\n 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);\n\n return (\n <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = 'ChatDialog.Header';\n\n//\n// Content\n//\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',\n 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = 'ChatDialog.Content';\n\n//\n// Footer\n//\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = 'ChatDialog.Footer';\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type CompletionResult, autocompletion, completionKeymap } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string;\n label: string;\n};\n\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n */\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: (plugin) => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = `@ ${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n\n override eq(other: ReferenceWidget): boolean {\n return other.data.uri === this.data.uri;\n }\n\n override ignoreEvent(): boolean {\n return true;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport {\n type BasicExtensionsOptions,\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type AutocompleteOptions, autocomplete } from './autocomplete';\nimport { type ReferencesOptions, references as referencesExtension } from './references';\n\n// TODO(burdon): Handle object references.\n\nexport interface ChatEditorController {\n focus(): void;\n getText(): string;\n setText(text: string): void;\n}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & AutocompleteOptions &\n Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>\n>;\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n (\n { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },\n forwardRef,\n ) => {\n const { themeMode } = useThemeContext();\n const { parentRef, view } = useTextEditor(\n {\n debug: true,\n autoFocus,\n extensions: [\n createThemeExtensions({ themeMode }),\n autocomplete({ onSubmit, onSuggest, onCancel }),\n references ? referencesExtension({ provider: references.provider }) : [],\n createBasicExtensions({\n bracketMatching: false,\n lineWrapping,\n placeholder,\n }),\n extensions,\n ].filter(isNonNullable),\n },\n [themeMode, extensions, onSubmit, onSuggest],\n );\n\n // Expose editor view.\n useImperativeHandle(forwardRef, () => {\n return {\n focus: () => {\n view?.focus();\n },\n getText: () => view?.state.doc.toString() ?? '',\n setText: (text: string) => {\n view?.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: text,\n },\n selection: {\n anchor: text.length,\n head: text.length,\n },\n });\n },\n };\n }, [view, onSubmit]);\n\n return <div ref={parentRef} className={mx('is-full', classNames)} />;\n },\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension, Prec } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nexport type AutocompleteOptions = {\n fireIfEmpty?: boolean;\n\n /**\n * Callback triggered when Enter is pressed.\n * @param text The current text in the editor\n * @returns true if the editor should reset the document.\n */\n onSubmit?: (text: string) => boolean | void;\n\n /**\n * Function that returns a list of suggestions based on the current text.\n * @param text The current text before the cursor\n * @returns Array of suggestion strings\n */\n onSuggest?: (text: string) => string[];\n\n /**\n * ESC pressed.\n */\n onCancel?: () => void;\n};\n\n/**\n * Creates an autocomplete extension that shows inline suggestions.\n * Pressing Tab will complete the suggestion.\n */\n// TODO(burdon): Move to react-ui-editor.\nexport const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {\n const suggest = ViewPlugin.fromClass(\n class {\n _decorations: DecorationSet;\n _currentSuggestion: string | null = null;\n\n constructor(view: EditorView) {\n this._decorations = this.computeDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.selectionSet) {\n this._decorations = this.computeDecorations(update.view);\n }\n }\n\n private computeDecorations(view: EditorView): DecorationSet {\n const text = view.state.doc.toString();\n const suggestions = onSuggest?.(text) ?? [];\n if (!suggestions.length) {\n this._currentSuggestion = null;\n return Decoration.none;\n }\n\n // Get the first suggestion.\n this._currentSuggestion = suggestions[0];\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return Decoration.none;\n }\n\n // Always show ghost text at the end of the document.\n return Decoration.set([\n Decoration.widget({\n widget: new InlineSuggestionWidget(suffix),\n side: 1,\n }).range(view.state.doc.length),\n ]);\n }\n\n completeSuggestion(view: EditorView): boolean {\n if (!this._currentSuggestion) {\n return false;\n }\n\n const text = view.state.doc.toString();\n const suffix = this._currentSuggestion.slice(text.length);\n if (!suffix) {\n return false;\n }\n\n view.dispatch({\n changes: {\n from: view.state.doc.length,\n insert: suffix,\n },\n selection: {\n anchor: view.state.doc.length + suffix.length,\n },\n });\n\n return true;\n }\n },\n {\n decorations: (v) => v._decorations,\n },\n );\n\n return [\n suggest,\n EditorView.theme({\n '.cm-inline-suggestion': {\n opacity: 0.4,\n },\n }),\n\n Prec.highest(\n keymap.of([\n {\n key: 'Tab',\n preventDefault: true,\n run: (view) => {\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'ArrowRight',\n preventDefault: true,\n run: (view) => {\n // Only complete if cursor is at the end\n if (view.state.selection.main.head !== view.state.doc.length) {\n return false;\n }\n\n const plugin = view.plugin(suggest);\n return plugin?.completeSuggestion(view) ?? false;\n },\n },\n {\n key: 'Enter',\n preventDefault: true,\n run: (view) => {\n const text = view.state.doc.toString().trim();\n if (onSubmit && (fireIfEmpty || text.length > 0)) {\n const reset = onSubmit(text);\n\n // Clear the document after calling onEnter.\n if (reset) {\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n }\n }\n\n return true;\n },\n },\n {\n key: 'Shift-Enter',\n preventDefault: true,\n run: (view) => {\n view.dispatch({\n changes: {\n from: view.state.selection.main.head,\n insert: '\\n',\n },\n selection: {\n anchor: view.state.selection.main.head + 1,\n head: view.state.selection.main.head + 1,\n },\n });\n return true;\n },\n },\n {\n key: 'Escape',\n preventDefault: true,\n run: (view) => {\n // Clear the entire document.\n view.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: '',\n },\n });\n onCancel?.();\n return true;\n },\n },\n ]),\n ),\n ];\n};\n\nclass InlineSuggestionWidget extends WidgetType {\n constructor(private suffix: string) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = this.suffix;\n span.className = 'cm-inline-suggestion';\n return span;\n }\n\n override eq(other: InlineSuggestionWidget): boolean {\n return other.suffix === this.suffix;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,SAAqEC,WAAWC,gBAAgB;AAEvG,SAASC,QAAQC,MAAMC,YAAkCC,0BAA0B;AACnF,SAASC,cAAyBC,kBAAkBC,iBAAiB;AACrE,SAASC,UAAU;AAEnB,IAAMC,iBAAiB,CAACC,UAAiBA,MAAMD,eAAc;AAG7D,IAAME,SAAS,CAAC,EAAEC,SAAQ,MAAqB;;;AAC7C,WACE,sBAAA,cAACC,OAAAA;MAAIC,WAAU;OAAkFF,QAAAA;;;;AAErG;AAeA,IAAM,CAACG,2BAA2BC,oBAAAA,IAAwBC,cAAsC,YAAA;AAchG,IAAMC,iBAAiB,CAAC,EACtBN,UACAO,MAAMC,QAAQ,OACdC,UAAUC,YAAY,OACtBC,cACAC,kBACAC,SAAQ,MACY;;;AACpB,UAAM,CAACC,MAAMC,OAAAA,IAAWC,SAAe,aAAA;AACvC,UAAM,CAACT,MAAMU,OAAAA,IAAWC,mBAA4BV,OAAOG,YAAAA;AAC3D,UAAM,CAACF,UAAUU,WAAAA,IAAeD,mBAA4BR,WAAWE,gBAAAA;AAIvE,WACE,sBAAA,cAACT,2BAAAA;MACCI;MACAU;MACAR;MACAU;MACAL;MACAC;OAEA,sBAAA,cAACK,OAAOC,MAAI;MAACC,OAAO;MAAOf;MAAYI,cAAcM;OACnD,sBAAA,cAAChB,OAAAA;MAAIsB,MAAK;MAAOrB,WAAU;MAAwDsB,oBAAiB;OAClG,sBAAA,cAACJ,OAAOK,SAAO;MACbC,iBAAAA;MACAC,YAAY;QACV;QACA;;MAEFC,iBAAiBf;MACjBgB,mBAAmBhC;OAElBG,QAAAA,CAAAA,CAAAA,CAAAA;;;;AAMb;AAEAM,eAAewB,cAA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AAc,KAAKrC;AACxBkC,SAAKI,YAAY;AACjB,WAAOJ;EACT;EAESK,GAAGC,OAAwC;AAClD,WAAOA,MAAMxC,WAAW,KAAKA;EAC/B;AACF;;;ADrLO,IAAMyC,aAAaC,2BACxB,CACE,EAAEC,YAAYC,YAAYC,YAAAA,aAAYC,WAAWC,eAAe,OAAOC,aAAaC,UAAUC,WAAWC,SAAQ,GACjHT,gBAAAA;;;AAEA,UAAM,EAAEU,UAAS,IAAKC,gBAAAA;AACtB,UAAM,EAAEC,WAAWC,KAAI,IAAKC,cAC1B;MACEC,OAAO;MACPX;MACAF,YAAY;QACVc,sBAAsB;UAAEN;QAAU,CAAA;QAClCO,aAAa;UAAEV;UAAUC;UAAWC;QAAS,CAAA;QAC7CN,cAAae,WAAoB;UAAEC,UAAUhB,YAAWgB;QAAS,CAAA,IAAK,CAAA;QACtEC,sBAAsB;UACpBC,iBAAiB;UACjBhB;UACAC;QACF,CAAA;QACAJ;QACAoB,OAAOC,aAAAA;IACX,GACA;MAACb;MAAWR;MAAYK;MAAUC;KAAU;AAI9CgB,wBAAoBxB,aAAY,MAAA;AAC9B,aAAO;QACLyB,OAAO,MAAA;AACLZ,gBAAMY,MAAAA;QACR;QACAC,SAAS,MAAMb,MAAMc,MAAMC,IAAIC,SAAAA,KAAc;QAC7CC,SAAS,CAACC,SAAAA;AACRlB,gBAAMmB,SAAS;YACbC,SAAS;cACPC,MAAM;cACNC,IAAItB,KAAKc,MAAMC,IAAIQ;cACnBC,QAAQN;YACV;YACAO,WAAW;cACTC,QAAQR,KAAKK;cACbI,MAAMT,KAAKK;YACb;UACF,CAAA;QACF;MACF;IACF,GAAG;MAACvB;MAAMN;KAAS;AAEnB,WAAO,gBAAAkC,OAAA,cAACC,OAAAA;MAAIC,KAAK/B;MAAWgC,WAAWC,IAAG,WAAW5C,UAAAA;;;;;AACvD,CAAA;",
|
|
6
|
+
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "ResizeHandle", "resizeAttributes", "sizeStyle", "mx", "preventDefault", "event", "Endcap", "children", "div", "className", "ChatDialogContextProvider", "useChatDialogContext", "createContext", "ChatDialogRoot", "open", "_open", "expanded", "_expanded", "onOpenChange", "onExpandedChange", "onEscape", "size", "setSize", "useState", "setOpen", "useControlledState", "setExpanded", "Dialog", "Root", "modal", "role", "data-block-align", "Content", "inOverlayLayout", "classNames", "onEscapeKeyDown", "onInteractOutside", "displayName", "ChatDialogHeader", "title", "mx", "Close", "Icon", "icon", "Title", "onClick", "IconButton", "variant", "iconOnly", "label", "ChatDialogContent", "useEffect", "style", "sizeStyle", "maxBlockSize", "resizeAttributes", "ResizeHandle", "side", "iconPosition", "defaultSize", "fallbackSize", "minSize", "onSizeChange", "ChatDialogFooter", "ChatDialog", "Header", "Footer", "autocompletion", "completionKeymap", "RangeSet", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "keymap", "Mutex", "invariant", "references", "provider", "triggerCharacter", "debug", "length", "decorationField", "fromClass", "ReferenceView", "_mutex", "decorations", "set", "view", "queueMicrotask", "guard", "acquire", "_computeDecorations", "release", "update", "docChanged", "text", "state", "doc", "toString", "matchAll", "RegExp", "match", "reference", "uri", "slice", "data", "resolveReference", "push", "replace", "widget", "ReferenceWidget", "range", "index", "v", "provide", "plugin", "atomicRanges", "of", "empty", "theme", "borderRadius", "borderWidth", "marginRight", "marginLeft", "tooltipClass", "activateOnTyping", "aboveCursor", "closeOnBlur", "override", "context", "matchBefore", "to", "from", "query", "getReferences", "filter", "options", "map", "label", "apply", "toDOM", "span", "document", "createElement", "textContent", "className", "eq", "other", "ignoreEvent", "React", "forwardRef", "useImperativeHandle", "useThemeContext", "createBasicExtensions", "createThemeExtensions", "useTextEditor", "mx", "isNonNullable", "Prec", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "keymap", "autocomplete", "fireIfEmpty", "onSubmit", "onSuggest", "onCancel", "suggest", "ViewPlugin", "fromClass", "_decorations", "_currentSuggestion", "view", "computeDecorations", "update", "docChanged", "selectionSet", "text", "state", "doc", "toString", "suggestions", "length", "Decoration", "none", "suffix", "slice", "set", "widget", "InlineSuggestionWidget", "side", "range", "completeSuggestion", "dispatch", "changes", "from", "insert", "selection", "anchor", "decorations", "v", "EditorView", "theme", "opacity", "Prec", "highest", "keymap", "of", "key", "preventDefault", "run", "plugin", "main", "head", "trim", "reset", "to", "WidgetType", "toDOM", "span", "document", "createElement", "textContent", "className", "eq", "other", "ChatEditor", "forwardRef", "classNames", "extensions", "references", "autoFocus", "lineWrapping", "placeholder", "onSubmit", "onSuggest", "onCancel", "themeMode", "useThemeContext", "parentRef", "view", "useTextEditor", "debug", "createThemeExtensions", "autocomplete", "referencesExtension", "provider", "createBasicExtensions", "bracketMatching", "filter", "isNonNullable", "useImperativeHandle", "focus", "getText", "state", "doc", "toString", "setText", "text", "dispatch", "changes", "from", "to", "length", "insert", "selection", "anchor", "head", "React", "div", "ref", "className", "mx"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":17734,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatDialog/index.ts":{"bytes":480,"imports":[{"path":"src/components/ChatDialog/ChatDialog.tsx","kind":"import-statement","original":"./ChatDialog"}],"format":"esm"},"src/components/ChatEditor/references.ts":{"bytes":15921,"imports":[{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/autocomplete.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":17734,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatDialog/index.ts":{"bytes":480,"imports":[{"path":"src/components/ChatDialog/ChatDialog.tsx","kind":"import-statement","original":"./ChatDialog"}],"format":"esm"},"src/components/ChatEditor/references.ts":{"bytes":15921,"imports":[{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/autocomplete.ts":{"bytes":19079,"imports":[{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/ChatEditor.tsx":{"bytes":8783,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/components/ChatEditor/autocomplete.ts","kind":"import-statement","original":"./autocomplete"},{"path":"src/components/ChatEditor/references.ts","kind":"import-statement","original":"./references"}],"format":"esm"},"src/components/ChatEditor/index.ts":{"bytes":574,"imports":[{"path":"src/components/ChatEditor/references.ts","kind":"import-statement","original":"./references"},{"path":"src/components/ChatEditor/ChatEditor.tsx","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/components/index.ts":{"bytes":563,"imports":[{"path":"src/components/ChatDialog/index.ts","kind":"import-statement","original":"./ChatDialog"},{"path":"src/components/ChatEditor/index.ts","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/index.ts":{"bytes":458,"imports":[{"path":"src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":31253},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true}],"exports":["ChatDialog","ChatEditor","references"],"entryPoint":"src/index.ts","inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytesInOutput":4866},"src/components/ChatDialog/index.ts":{"bytesInOutput":0},"src/components/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/references.ts":{"bytesInOutput":3691},"src/components/ChatEditor/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/ChatEditor.tsx":{"bytesInOutput":1997},"src/components/ChatEditor/autocomplete.ts":{"bytesInOutput":4120},"src/index.ts":{"bytesInOutput":0}},"bytes":15079}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatDialog.d.ts","sourceRoot":"","sources":["../../../../../src/components/ChatDialog/ChatDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAiB,KAAK,iBAAiB,EAA4C,MAAM,OAAO,CAAC;AAE/G,OAAO,
|
|
1
|
+
{"version":3,"file":"ChatDialog.d.ts","sourceRoot":"","sources":["../../../../../src/components/ChatDialog/ChatDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAiB,KAAK,iBAAiB,EAA4C,MAAM,OAAO,CAAC;AAE/G,OAAO,EAA4B,KAAK,eAAe,EAAsB,MAAM,gBAAgB,CAAC;AAgCpG,KAAK,mBAAmB,GAAG,iBAAiB,CAAC;IAC3C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,CAAC,CAAC;AAkDH,KAAK,qBAAqB,GAAG,eAAe,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAsCH,KAAK,sBAAsB,GAAG,eAAe,CAAC,iBAAiB,CAAC,CAAC;AAwCjE,KAAK,qBAAqB,GAAG,eAAe,CAAC,iBAAiB,CAAC,CAAC;AAYhE,eAAO,MAAM,UAAU;;oGArIpB,mBAAmB;;;;gCA6C2B,qBAAqB;;;;mCAsCjB,sBAAsB;;;;mCAwCvB,qBAAqB;;;CAexE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@dxos-theme';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
3
3
|
import { ChatDialog } from './ChatDialog';
|
|
4
4
|
declare const meta: Meta<typeof ChatDialog.Root>;
|
|
5
5
|
export default meta;
|