@dxos/plugin-script 0.6.13-staging.1e988a3 → 0.6.14-main.1366248
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/README.md +1 -1
- package/dist/lib/browser/AutomationPanel-XLL2ZXGS.mjs +78 -0
- package/dist/lib/browser/AutomationPanel-XLL2ZXGS.mjs.map +7 -0
- package/dist/lib/browser/ScriptContainer-YXH4MFEO.mjs +415 -0
- package/dist/lib/browser/ScriptContainer-YXH4MFEO.mjs.map +7 -0
- package/dist/lib/browser/chunk-C7VBULMK.mjs +18 -0
- package/dist/lib/browser/chunk-C7VBULMK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RHEZ5LUU.mjs → chunk-G6H56WFS.mjs} +51 -2
- package/dist/lib/browser/{chunk-RHEZ5LUU.mjs.map → chunk-G6H56WFS.mjs.map} +4 -4
- package/dist/lib/browser/{chunk-DL5XQRQM.mjs → chunk-KHNN3F7J.mjs} +18 -6
- package/dist/lib/browser/chunk-KHNN3F7J.mjs.map +7 -0
- package/dist/lib/browser/chunk-NCZUJKJE.mjs +236 -0
- package/dist/lib/browser/chunk-NCZUJKJE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-USXWNH3S.mjs} +2 -2
- package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-USXWNH3S.mjs.map} +2 -2
- package/dist/lib/browser/edge/index.mjs +5 -1
- package/dist/lib/browser/index.mjs +185 -62
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/AutomationPanel-OSPAFWZU.cjs +100 -0
- package/dist/lib/node/AutomationPanel-OSPAFWZU.cjs.map +7 -0
- package/dist/lib/node/ScriptContainer-FWHFEIHK.cjs +417 -0
- package/dist/lib/node/ScriptContainer-FWHFEIHK.cjs.map +7 -0
- package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-6LYX73ZT.cjs} +19 -8
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +7 -0
- package/dist/lib/node/{chunk-4GTXIELQ.cjs → chunk-ACLCRWDB.cjs} +44 -6
- package/dist/lib/node/chunk-ACLCRWDB.cjs.map +7 -0
- package/dist/lib/node/chunk-BJ4WIWCP.cjs +265 -0
- package/dist/lib/node/chunk-BJ4WIWCP.cjs.map +7 -0
- package/dist/lib/node/{chunk-5RBVXKXT.cjs → chunk-CPNHUAFN.cjs} +6 -6
- package/dist/lib/node/{chunk-5RBVXKXT.cjs.map → chunk-CPNHUAFN.cjs.map} +2 -2
- package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-FY5KKL5N.cjs} +22 -8
- package/dist/lib/node/chunk-FY5KKL5N.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +12 -8
- package/dist/lib/node/edge/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +196 -81
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +5 -5
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/AutomationPanel-KJNL6ARP.mjs +79 -0
- package/dist/lib/node-esm/AutomationPanel-KJNL6ARP.mjs.map +7 -0
- package/dist/lib/node-esm/ScriptContainer-6U5WJFRB.mjs +416 -0
- package/dist/lib/node-esm/ScriptContainer-6U5WJFRB.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2NPZGQGA.mjs +47 -0
- package/dist/lib/node-esm/chunk-2NPZGQGA.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DXWSRDEN.mjs +237 -0
- package/dist/lib/node-esm/chunk-DXWSRDEN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs +280 -0
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QMTTZYLF.mjs +255 -0
- package/dist/lib/node-esm/chunk-QMTTZYLF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs +20 -0
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +24 -0
- package/dist/lib/node-esm/index.mjs +415 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +10 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +13 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +17 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/index.d.ts +4 -0
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +7 -0
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/index.d.ts +2 -0
- package/dist/types/src/components/DebugPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -0
- package/dist/types/src/components/FrameContainer/frame.d.ts.map +1 -0
- package/dist/types/src/components/FrameContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -3
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +3 -8
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +5 -0
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -0
- package/dist/types/src/components/ScriptEditor.d.ts +4 -5
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +6 -0
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -0
- package/dist/types/src/components/ScriptSettings/index.d.ts +2 -0
- package/dist/types/src/components/ScriptSettings/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +7 -0
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +23 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +14 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/{TypescriptEditor.d.ts → TypescriptEditor/TypescriptEditor.d.ts} +1 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +6 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/index.d.ts +2 -0
- package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +4 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +7 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +5 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chat.d.ts +6 -0
- package/dist/types/src/templates/chat.d.ts.map +1 -0
- package/dist/types/src/templates/chess.d.ts +6 -0
- package/dist/types/src/templates/chess.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts +6 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -0
- package/dist/types/src/templates/email.d.ts +6 -0
- package/dist/types/src/templates/email.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +6 -0
- package/dist/types/src/templates/forex.d.ts.map +1 -0
- package/dist/types/src/templates.d.ts +8 -0
- package/dist/types/src/templates.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +7 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/script.d.ts +4 -4
- package/dist/types/src/types/types.d.ts +4 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +59 -64
- package/src/ScriptPlugin.tsx +47 -41
- package/src/bundler/bundler.test.ts +12 -2
- package/src/components/AutomationPanel/AutomationPanel.tsx +101 -0
- package/src/components/AutomationPanel/index.ts +9 -0
- package/src/components/{DebugPanel.tsx → DebugPanel/DebugPanel.tsx} +74 -96
- package/src/components/DebugPanel/index.ts +5 -0
- package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.tsx +1 -1
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +15 -14
- package/src/components/ScriptBlock/ScriptBlock.tsx +23 -51
- package/src/components/ScriptContainer.tsx +22 -0
- package/src/components/ScriptEditor.tsx +51 -62
- package/src/components/ScriptSettings/ScriptSettings.tsx +47 -0
- package/src/components/ScriptSettings/index.ts +5 -0
- package/src/components/ScriptSettingsPanel.tsx +105 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +30 -0
- package/src/components/Toolbar/Toolbar.tsx +177 -0
- package/src/components/{ScriptBlock/Splitter → Toolbar}/index.ts +1 -1
- package/src/components/{TypescriptEditor.stories.tsx → TypescriptEditor/TypescriptEditor.stories.tsx} +17 -35
- package/src/components/{TypescriptEditor.tsx → TypescriptEditor/TypescriptEditor.tsx} +1 -3
- package/src/components/TypescriptEditor/index.ts +5 -0
- package/src/components/index.ts +6 -3
- package/src/edge/functions.ts +19 -0
- package/src/meta.ts +16 -0
- package/src/templates/chat.ts +102 -0
- package/src/templates/chess.ts +41 -0
- package/src/templates/echo.ts +15 -0
- package/src/templates/email.ts +38 -0
- package/src/templates/forex.ts +21 -0
- package/src/templates.ts +54 -0
- package/src/translations.ts +7 -0
- package/src/types/types.ts +9 -5
- package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs +0 -513
- package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +0 -7
- package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +0 -9
- package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +0 -7
- package/dist/lib/browser/chunk-JBACGDOJ.mjs +0 -21
- package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-MRGOT5RF.mjs +0 -78
- package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +0 -7
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +0 -526
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +0 -7
- package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +0 -7
- package/dist/lib/node/chunk-4GTXIELQ.cjs.map +0 -7
- package/dist/lib/node/chunk-4VMNBXWU.cjs +0 -54
- package/dist/lib/node/chunk-4VMNBXWU.cjs.map +0 -7
- package/dist/lib/node/chunk-IMLDKD5Y.cjs +0 -111
- package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +0 -7
- package/dist/lib/node/chunk-PFH3ROEH.cjs.map +0 -7
- package/dist/types/src/components/DebugPanel.d.ts +0 -9
- package/dist/types/src/components/DebugPanel.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +0 -15
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +0 -13
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar.d.ts +0 -13
- package/dist/types/src/components/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar.stories.d.ts +0 -14
- package/dist/types/src/components/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor.stories.d.ts +0 -10
- package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +0 -1
- package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +0 -37
- package/src/components/ScriptBlock/Splitter/Splitter.tsx +0 -52
- package/src/components/Toolbar.stories.tsx +0 -17
- package/src/components/Toolbar.tsx +0 -147
- package/src/meta.tsx +0 -19
- /package/dist/lib/{browser/TypescriptEditor-GPE72Y6I.mjs.map → node-esm/edge/index.mjs.map} +0 -0
- /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.d.ts +0 -0
- /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.d.ts +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.html +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.tsx +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.ts +0 -0
|
@@ -5,20 +5,11 @@
|
|
|
5
5
|
import React, { useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { log } from '@dxos/log';
|
|
8
|
-
import {
|
|
9
|
-
Avatar,
|
|
10
|
-
DensityProvider,
|
|
11
|
-
Icon,
|
|
12
|
-
Input,
|
|
13
|
-
type ThemedClassName,
|
|
14
|
-
Toolbar,
|
|
15
|
-
useControlledValue,
|
|
16
|
-
useTranslation,
|
|
17
|
-
} from '@dxos/react-ui';
|
|
8
|
+
import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
18
9
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
19
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
20
11
|
|
|
21
|
-
import { SCRIPT_PLUGIN } from '
|
|
12
|
+
import { SCRIPT_PLUGIN } from '../../meta';
|
|
22
13
|
|
|
23
14
|
type State = 'pending' | 'responding';
|
|
24
15
|
|
|
@@ -29,25 +20,17 @@ type Message = { type: 'request' | 'response'; text?: string; data?: any; error?
|
|
|
29
20
|
|
|
30
21
|
export type DebugPanelProps = ThemedClassName<{
|
|
31
22
|
functionUrl?: string;
|
|
32
|
-
binding?: string;
|
|
33
|
-
onBindingChange?: (binding: string) => void;
|
|
34
23
|
}>;
|
|
35
24
|
|
|
36
|
-
export const DebugPanel = ({ classNames, functionUrl
|
|
25
|
+
export const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {
|
|
37
26
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
38
27
|
|
|
39
|
-
const bindingInputRef = useRef<HTMLInputElement>(null);
|
|
40
|
-
const [binding, setBinding] = useControlledValue(_binding ?? '');
|
|
41
|
-
const handleBlur = () => {
|
|
42
|
-
onBindingChange?.(binding);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
28
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
46
29
|
const [input, setInput] = useState('');
|
|
47
30
|
const [result, setResult] = useState('');
|
|
48
31
|
const [state, setState] = useState<State | null>(null);
|
|
49
32
|
|
|
50
|
-
// TODO(burdon): Persistent history (non-space ECHO data?)
|
|
33
|
+
// TODO(burdon): Persistent history -- at least for session (non-space ECHO data?)
|
|
51
34
|
const [history, setHistory] = useState<Message[]>([]);
|
|
52
35
|
|
|
53
36
|
const scrollerRef = useRef<HTMLDivElement>(null);
|
|
@@ -175,95 +158,90 @@ export const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindi
|
|
|
175
158
|
};
|
|
176
159
|
|
|
177
160
|
return (
|
|
178
|
-
<
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
<
|
|
182
|
-
<MessageThread state={state} result={result} history={history} />
|
|
183
|
-
</div>
|
|
184
|
-
|
|
185
|
-
<Toolbar.Root classNames='p-2'>
|
|
186
|
-
<Input.Root>
|
|
187
|
-
<Input.TextInput
|
|
188
|
-
ref={inputRef}
|
|
189
|
-
autoFocus
|
|
190
|
-
placeholder={t('function request placeholder')}
|
|
191
|
-
value={input}
|
|
192
|
-
onChange={(ev) => setInput(ev.target.value)}
|
|
193
|
-
onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
|
|
194
|
-
/>
|
|
195
|
-
</Input.Root>
|
|
196
|
-
<Input.Root>
|
|
197
|
-
<Input.TextInput
|
|
198
|
-
ref={bindingInputRef}
|
|
199
|
-
classNames='!w-[10rem]'
|
|
200
|
-
placeholder={t('binding placeholder')}
|
|
201
|
-
value={binding}
|
|
202
|
-
onChange={(ev) => setBinding(ev.target.value.toUpperCase())}
|
|
203
|
-
onBlur={handleBlur}
|
|
204
|
-
/>
|
|
205
|
-
</Input.Root>
|
|
206
|
-
<Toolbar.Button onClick={() => handleRequest(input)}>
|
|
207
|
-
<Icon icon='ph--play--regular' size={4} />
|
|
208
|
-
</Toolbar.Button>
|
|
209
|
-
<Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>
|
|
210
|
-
<Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />
|
|
211
|
-
</Toolbar.Button>
|
|
212
|
-
</Toolbar.Root>
|
|
161
|
+
<div className={mx('flex flex-col h-full overflow-hidden', classNames)}>
|
|
162
|
+
{/* TODO(burdon): Replace with Thread? */}
|
|
163
|
+
<div ref={scrollerRef} className='flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto'>
|
|
164
|
+
<MessageThread state={state} result={result} history={history} />
|
|
213
165
|
</div>
|
|
214
|
-
</DensityProvider>
|
|
215
|
-
);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const RobotAvatar = () => (
|
|
219
|
-
<Avatar.Root size={6} variant='circle'>
|
|
220
|
-
<Avatar.Frame>
|
|
221
|
-
<Avatar.Icon icon='ph--robot--regular' />
|
|
222
|
-
</Avatar.Frame>
|
|
223
|
-
</Avatar.Root>
|
|
224
|
-
);
|
|
225
166
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
167
|
+
<Toolbar.Root classNames='p-2'>
|
|
168
|
+
<Input.Root>
|
|
169
|
+
<Input.TextInput
|
|
170
|
+
ref={inputRef}
|
|
171
|
+
autoFocus
|
|
172
|
+
placeholder={t('function request placeholder')}
|
|
173
|
+
value={input}
|
|
174
|
+
onChange={(ev) => setInput(ev.target.value)}
|
|
175
|
+
onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
|
|
176
|
+
/>
|
|
177
|
+
</Input.Root>
|
|
178
|
+
<Toolbar.Button onClick={() => handleRequest(input)}>
|
|
179
|
+
<Icon icon='ph--play--regular' size={4} />
|
|
180
|
+
</Toolbar.Button>
|
|
181
|
+
<Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>
|
|
182
|
+
<Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />
|
|
183
|
+
</Toolbar.Button>
|
|
184
|
+
</Toolbar.Root>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
239
187
|
};
|
|
240
188
|
|
|
241
189
|
// TODO(burdon): Replace with thread?
|
|
242
190
|
// TODO(burdon): Button to delete individual messages.
|
|
243
|
-
// TODO(burdon): Button to re-run question.
|
|
191
|
+
// TODO(burdon): Button to edit/re-run question.
|
|
244
192
|
const MessageThread = ({ state, result, history }: { state: State | null; result: string; history: Message[] }) => {
|
|
245
193
|
return (
|
|
246
194
|
<>
|
|
247
195
|
{history.map((message, i) => (
|
|
248
|
-
<div key={i} className='grid grid-cols-[
|
|
249
|
-
<div>{message.type === 'response' && <RobotAvatar />}</div>
|
|
250
|
-
<div className=
|
|
251
|
-
<MessageItem
|
|
252
|
-
classNames={[message.type === 'request' && 'p-1 px-2 rounded-lg bg-hoverSurface']}
|
|
253
|
-
message={message}
|
|
254
|
-
/>
|
|
196
|
+
<div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>
|
|
197
|
+
<div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>
|
|
198
|
+
<div className='overflow-auto'>
|
|
199
|
+
<MessageItem message={message} />
|
|
255
200
|
</div>
|
|
256
201
|
</div>
|
|
257
202
|
))}
|
|
258
|
-
|
|
259
|
-
<div>
|
|
260
|
-
|
|
261
|
-
(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
203
|
+
{result?.length > 0 && (
|
|
204
|
+
<div className='grid grid-cols-[2rem_1fr_2rem]'>
|
|
205
|
+
<div className='p-1'>
|
|
206
|
+
{(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin' />) || (
|
|
207
|
+
<Icon icon='ph--robot--regular' size={6} classNames='animate-[pulse_1s_ease-in-out_infinite]' />
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
<div className='overflow-auto'>
|
|
211
|
+
<MessageItem message={{ type: 'response', text: result }} />
|
|
212
|
+
</div>
|
|
265
213
|
</div>
|
|
266
|
-
|
|
214
|
+
)}
|
|
267
215
|
</>
|
|
268
216
|
);
|
|
269
217
|
};
|
|
218
|
+
|
|
219
|
+
const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {
|
|
220
|
+
const { type, text, data, error } = message;
|
|
221
|
+
const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
|
|
222
|
+
return (
|
|
223
|
+
<div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
|
|
224
|
+
{error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}
|
|
225
|
+
|
|
226
|
+
{text !== undefined && (
|
|
227
|
+
<div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
|
|
228
|
+
{text || '\u00D8'}
|
|
229
|
+
</div>
|
|
230
|
+
)}
|
|
231
|
+
|
|
232
|
+
{data && (
|
|
233
|
+
<SyntaxHighlighter language='json' className={mx(wrapper, 'px-8 py-2 text-xs')}>
|
|
234
|
+
{JSON.stringify(data, null, 2)}
|
|
235
|
+
</SyntaxHighlighter>
|
|
236
|
+
)}
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const RobotAvatar = () => (
|
|
242
|
+
<Avatar.Root size={6} variant='circle'>
|
|
243
|
+
<Avatar.Frame>
|
|
244
|
+
<Avatar.Icon icon='ph--robot--regular' />
|
|
245
|
+
</Avatar.Frame>
|
|
246
|
+
</Avatar.Root>
|
|
247
|
+
);
|
|
@@ -11,7 +11,7 @@ import { baseSurface, mx } from '@dxos/react-ui-theme';
|
|
|
11
11
|
import { createProtoRpcPeer } from '@dxos/rpc';
|
|
12
12
|
import { createIFramePort } from '@dxos/rpc-tunnel';
|
|
13
13
|
|
|
14
|
-
import { type BundlerResult } from '
|
|
14
|
+
import { type BundlerResult } from '../../bundler';
|
|
15
15
|
|
|
16
16
|
export type FrameContainerProps = {
|
|
17
17
|
containerUrl: string;
|
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
6
8
|
import React, { useEffect, useMemo } from 'react';
|
|
7
9
|
|
|
8
10
|
import { createSpaceObjectGenerator, TestSchemaType } from '@dxos/echo-generator';
|
|
9
11
|
import { TextType } from '@dxos/plugin-markdown/types';
|
|
10
12
|
import { useClient } from '@dxos/react-client';
|
|
11
|
-
import { create,
|
|
13
|
+
import { create, createObject, useSpaces } from '@dxos/react-client/echo';
|
|
12
14
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
15
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
14
16
|
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
import mainUrl from './FrameContainer/frame?url';
|
|
17
17
|
import { ScriptBlock } from './ScriptBlock';
|
|
18
18
|
import { ScriptType } from '../../types';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import mainUrl from '../FrameContainer/frame?url';
|
|
19
21
|
|
|
20
22
|
const code = [
|
|
21
23
|
"import { Filter, useQuery, useSpaces} from '@dxos/react-client/echo';",
|
|
@@ -29,7 +31,7 @@ const code = [
|
|
|
29
31
|
'}',
|
|
30
32
|
].join('\n');
|
|
31
33
|
|
|
32
|
-
const
|
|
34
|
+
const DefaultStory = () => {
|
|
33
35
|
const client = useClient();
|
|
34
36
|
const spaces = useSpaces();
|
|
35
37
|
console.log(spaces.length);
|
|
@@ -44,28 +46,27 @@ const Story = () => {
|
|
|
44
46
|
[TestSchemaType.organization]: 20,
|
|
45
47
|
[TestSchemaType.contact]: 50,
|
|
46
48
|
})
|
|
47
|
-
.catch();
|
|
49
|
+
.catch(() => {});
|
|
48
50
|
} catch (err) {
|
|
49
51
|
console.log(err);
|
|
50
52
|
}
|
|
51
53
|
}, [client]);
|
|
52
54
|
|
|
53
55
|
// TODO(burdon): Review what's the right way to create automerge-backed objects.
|
|
54
|
-
const object = useMemo(
|
|
55
|
-
() => createEchoObject(create(ScriptType, { source: create(TextType, { content: code }) })),
|
|
56
|
-
[],
|
|
57
|
-
);
|
|
56
|
+
const object = useMemo(() => createObject(create(ScriptType, { source: create(TextType, { content: code }) })), []);
|
|
58
57
|
|
|
59
58
|
// TODO(dmaretskyi): Not sure how to provide `containerUrl` here since the html now lives in composer-app.
|
|
60
59
|
// TODO(burdon): Normalize html/frame.tsx with composer-app to test locally.
|
|
61
60
|
return <ScriptBlock script={object} containerUrl={mainUrl} />;
|
|
62
61
|
};
|
|
63
62
|
|
|
64
|
-
export
|
|
65
|
-
|
|
63
|
+
export const Default = {};
|
|
64
|
+
|
|
65
|
+
const meta: Meta = {
|
|
66
|
+
title: 'plugins/plugin-script/ScriptBlock',
|
|
66
67
|
component: ScriptBlock,
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
render: DefaultStory,
|
|
69
|
+
decorators: [withClientProvider({ createSpace: true }), withTheme, withLayout({ fullscreen: true, tooltips: true })],
|
|
69
70
|
};
|
|
70
71
|
|
|
71
|
-
export
|
|
72
|
+
export default meta;
|
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Check, Play, Warning } from '@phosphor-icons/react';
|
|
6
5
|
// @ts-ignore
|
|
7
6
|
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
8
7
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
8
|
|
|
10
9
|
import { createDocAccessor, DocAccessor } from '@dxos/react-client/echo';
|
|
11
|
-
import {
|
|
12
|
-
import { mx
|
|
10
|
+
import { Toolbar, Button, Icon } from '@dxos/react-ui';
|
|
11
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
13
12
|
|
|
14
|
-
import { FrameContainer } from './FrameContainer';
|
|
15
|
-
import { Splitter, SplitterSelector, type View } from './Splitter';
|
|
16
13
|
import { Bundler, type BundlerResult, initializeBundler } from '../../bundler';
|
|
17
14
|
import { type ScriptType } from '../../types';
|
|
15
|
+
import { FrameContainer } from '../FrameContainer';
|
|
18
16
|
import { ScriptEditor } from '../ScriptEditor';
|
|
19
17
|
|
|
20
18
|
// Keep in sync with packages/apps/composer-app/script-frame/main.tsx .
|
|
@@ -29,7 +27,6 @@ const PROVIDED_MODULES = [
|
|
|
29
27
|
|
|
30
28
|
export type ScriptBlockProps = {
|
|
31
29
|
script: ScriptType;
|
|
32
|
-
view?: View;
|
|
33
30
|
hideSelector?: boolean;
|
|
34
31
|
classes?: {
|
|
35
32
|
root?: string;
|
|
@@ -44,17 +41,8 @@ export type ScriptBlockProps = {
|
|
|
44
41
|
* @deprecated
|
|
45
42
|
*/
|
|
46
43
|
// TODO(burdon): Cache compiled results in context.
|
|
47
|
-
export const ScriptBlock = ({
|
|
48
|
-
script,
|
|
49
|
-
view: controlledView,
|
|
50
|
-
hideSelector,
|
|
51
|
-
classes,
|
|
52
|
-
containerUrl,
|
|
53
|
-
}: ScriptBlockProps) => {
|
|
44
|
+
export const ScriptBlock = ({ script, hideSelector, classes, containerUrl }: ScriptBlockProps) => {
|
|
54
45
|
const source = useMemo(() => script.source && createDocAccessor(script.source, ['content']), [script.source]);
|
|
55
|
-
const [view, setView] = useState<View>(controlledView ?? 'editor');
|
|
56
|
-
useEffect(() => handleSetView(controlledView ?? 'editor'), [controlledView]);
|
|
57
|
-
|
|
58
46
|
const [result, setResult] = useState<BundlerResult>();
|
|
59
47
|
const bundler = useMemo(
|
|
60
48
|
() => new Bundler({ platform: 'browser', sandboxedModules: PROVIDED_MODULES, remoteModules: {} }),
|
|
@@ -78,16 +66,6 @@ export const ScriptBlock = ({
|
|
|
78
66
|
return () => clearTimeout(t);
|
|
79
67
|
}, [source]);
|
|
80
68
|
|
|
81
|
-
const handleSetView = useCallback(
|
|
82
|
-
(view: View) => {
|
|
83
|
-
setView(view);
|
|
84
|
-
if (!result && view !== 'editor') {
|
|
85
|
-
void handleExec(false);
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
[result],
|
|
89
|
-
);
|
|
90
|
-
|
|
91
69
|
const handleExec = useCallback(
|
|
92
70
|
async (auto = true) => {
|
|
93
71
|
if (!source) {
|
|
@@ -95,41 +73,35 @@ export const ScriptBlock = ({
|
|
|
95
73
|
}
|
|
96
74
|
const result = await bundler.bundle(DocAccessor.getValue(source));
|
|
97
75
|
setResult(result);
|
|
98
|
-
if (auto && view === 'editor') {
|
|
99
|
-
setView('preview');
|
|
100
|
-
}
|
|
101
76
|
},
|
|
102
|
-
[source
|
|
77
|
+
[source],
|
|
103
78
|
);
|
|
104
79
|
|
|
105
80
|
return (
|
|
106
81
|
<div className={mx('flex flex-col grow overflow-hidden', classes?.root)}>
|
|
107
82
|
{!hideSelector && (
|
|
108
|
-
<
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
<div
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
)}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
</Button>
|
|
125
|
-
</Toolbar.Root>
|
|
126
|
-
</DensityProvider>
|
|
83
|
+
<Toolbar.Root classNames={mx('mb-2', classes?.toolbar)}>
|
|
84
|
+
<div className='grow' />
|
|
85
|
+
{result?.bundle && !result?.error && (
|
|
86
|
+
<div title={String(result.error)}>
|
|
87
|
+
<Icon icon='ph--check--regular' size={5} classNames='text-green-500' />
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
{result?.error && (
|
|
91
|
+
<div title={String(result.error)}>
|
|
92
|
+
<Icon icon='ph--warning--regular' size={5} classNames='text-orange-500' />
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
<Button variant='ghost' onClick={() => handleExec()}>
|
|
96
|
+
<Icon icon='ph--play--regular' size={5} />
|
|
97
|
+
</Button>
|
|
98
|
+
</Toolbar.Root>
|
|
127
99
|
)}
|
|
128
100
|
|
|
129
|
-
<
|
|
101
|
+
<div className='flex'>
|
|
130
102
|
<ScriptEditor script={script} />
|
|
131
103
|
{result && <FrameContainer key={script.id} result={result} containerUrl={containerUrl} />}
|
|
132
|
-
</
|
|
104
|
+
</div>
|
|
133
105
|
</div>
|
|
134
106
|
);
|
|
135
107
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
8
|
+
import { useAttendableAttributes } from '@dxos/react-ui-attention';
|
|
9
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
+
|
|
11
|
+
import { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';
|
|
12
|
+
|
|
13
|
+
const ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {
|
|
14
|
+
const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));
|
|
15
|
+
return (
|
|
16
|
+
<div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>
|
|
17
|
+
<ScriptEditor {...props} script={script} />
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default ScriptContainer;
|
|
@@ -10,45 +10,39 @@ import React, { useCallback, useMemo, useState } from 'react';
|
|
|
10
10
|
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { useClient } from '@dxos/react-client';
|
|
13
|
-
import {
|
|
14
|
-
create,
|
|
15
|
-
createDocAccessor,
|
|
16
|
-
Filter,
|
|
17
|
-
fullyQualifiedId,
|
|
18
|
-
getMeta,
|
|
19
|
-
getSpace,
|
|
20
|
-
useQuery,
|
|
21
|
-
} from '@dxos/react-client/echo';
|
|
13
|
+
import { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
22
14
|
import { useIdentity } from '@dxos/react-client/halo';
|
|
23
|
-
import { useTranslation } from '@dxos/react-ui';
|
|
24
|
-
import { useHasAttention } from '@dxos/react-ui-attention';
|
|
15
|
+
import { useTranslation, type ThemedClassName } from '@dxos/react-ui';
|
|
25
16
|
import { createDataExtensions, listener } from '@dxos/react-ui-editor';
|
|
26
17
|
import { mx } from '@dxos/react-ui-theme';
|
|
27
18
|
|
|
28
19
|
import { DebugPanel } from './DebugPanel';
|
|
29
|
-
import { Toolbar } from './Toolbar';
|
|
20
|
+
import { type TemplateSelectProps, Toolbar, type ViewType } from './Toolbar';
|
|
30
21
|
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
31
22
|
import { Bundler } from '../bundler';
|
|
32
23
|
import {
|
|
24
|
+
getInvocationUrl,
|
|
33
25
|
getUserFunctionUrlInMetadata,
|
|
34
26
|
publicKeyToDid,
|
|
35
27
|
setUserFunctionUrlInMetadata,
|
|
36
28
|
uploadWorkerFunction,
|
|
29
|
+
USERFUNCTIONS_PRESET_META_KEY,
|
|
37
30
|
} from '../edge';
|
|
38
31
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
32
|
+
import { templates } from '../templates';
|
|
39
33
|
import { FunctionType, type ScriptType } from '../types';
|
|
40
34
|
|
|
41
|
-
export type ScriptEditorProps = {
|
|
35
|
+
export type ScriptEditorProps = ThemedClassName<{
|
|
42
36
|
script: ScriptType;
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
}> &
|
|
38
|
+
Pick<TypescriptEditorProps, 'env'>;
|
|
45
39
|
|
|
46
|
-
export const ScriptEditor = ({
|
|
40
|
+
export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) => {
|
|
47
41
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
48
|
-
const hasAttention = useHasAttention(fullyQualifiedId(script));
|
|
49
42
|
const client = useClient();
|
|
50
43
|
const identity = useIdentity();
|
|
51
44
|
const space = getSpace(script);
|
|
45
|
+
// TODO(dmaretskyi): Parametric query.
|
|
52
46
|
const [fn] = useQuery(
|
|
53
47
|
space,
|
|
54
48
|
Filter.schema(FunctionType, (fn) => fn.source === script),
|
|
@@ -73,18 +67,11 @@ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
|
|
|
73
67
|
[script, script.source, space, identity],
|
|
74
68
|
);
|
|
75
69
|
|
|
76
|
-
const [
|
|
70
|
+
const [view, setView] = useState<ViewType>('editor');
|
|
77
71
|
const initialValue = useMemo(() => script.source?.content, [script.source]);
|
|
78
72
|
const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
79
73
|
const [error, setError] = useState<string>();
|
|
80
74
|
|
|
81
|
-
const handleBindingChange = useCallback(
|
|
82
|
-
(binding: string) => {
|
|
83
|
-
fn.binding = binding;
|
|
84
|
-
},
|
|
85
|
-
[fn],
|
|
86
|
-
);
|
|
87
|
-
|
|
88
75
|
const handleFormat = useCallback(async () => {
|
|
89
76
|
if (!script.source) {
|
|
90
77
|
return;
|
|
@@ -103,6 +90,22 @@ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
|
|
|
103
90
|
}
|
|
104
91
|
}, [script.source]);
|
|
105
92
|
|
|
93
|
+
const handleTemplateChange: TemplateSelectProps['onTemplateSelect'] = (id) => {
|
|
94
|
+
const template = templates.find((template) => template.id === id);
|
|
95
|
+
if (template) {
|
|
96
|
+
script.name = template.name;
|
|
97
|
+
script.source!.content = template.source;
|
|
98
|
+
const metaKeys = getMeta(script).keys;
|
|
99
|
+
const oldPresetIndex = metaKeys.findIndex((key) => key.source === USERFUNCTIONS_PRESET_META_KEY);
|
|
100
|
+
if (oldPresetIndex >= 0) {
|
|
101
|
+
metaKeys.splice(oldPresetIndex, 1);
|
|
102
|
+
}
|
|
103
|
+
if (template.presetId) {
|
|
104
|
+
metaKeys.push({ source: USERFUNCTIONS_PRESET_META_KEY, id: template.presetId });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
106
109
|
const handleDeploy = useCallback(async () => {
|
|
107
110
|
if (!script.source || !identity || !space) {
|
|
108
111
|
return;
|
|
@@ -114,11 +117,7 @@ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
|
|
|
114
117
|
const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
|
|
115
118
|
const ownerDid = (existingFunctionUrl?.split('/').at(-2) as DID) ?? publicKeyToDid(identity.identityKey);
|
|
116
119
|
|
|
117
|
-
const bundler = new Bundler({
|
|
118
|
-
platform: 'browser',
|
|
119
|
-
sandboxedModules: [],
|
|
120
|
-
remoteModules: {},
|
|
121
|
-
});
|
|
120
|
+
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
122
121
|
const buildResult = await bundler.bundle(script.source.content);
|
|
123
122
|
if (buildResult.error || !buildResult.bundle) {
|
|
124
123
|
throw buildResult.error;
|
|
@@ -134,15 +133,18 @@ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
|
|
|
134
133
|
if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {
|
|
135
134
|
throw new Error(errorMessage);
|
|
136
135
|
}
|
|
136
|
+
|
|
137
137
|
log.info('function uploaded', { functionId, functionVersionNumber });
|
|
138
138
|
if (fn) {
|
|
139
139
|
fn.version = functionVersionNumber;
|
|
140
140
|
}
|
|
141
|
+
|
|
141
142
|
const deployedFunction =
|
|
142
143
|
fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));
|
|
143
144
|
const meta = getMeta(deployedFunction);
|
|
144
|
-
setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
|
|
145
145
|
script.changed = false;
|
|
146
|
+
setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
|
|
147
|
+
setView('split');
|
|
146
148
|
} catch (err: any) {
|
|
147
149
|
log.catch(err);
|
|
148
150
|
setError(t('upload failed label'));
|
|
@@ -154,49 +156,36 @@ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
|
|
|
154
156
|
return;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const relativeUrl = existingFunctionUrl.replace(/^\//, '');
|
|
161
|
-
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
162
|
-
space && url.searchParams.set('spaceId', space.id);
|
|
163
|
-
url.protocol = 'https';
|
|
164
|
-
return url.toString();
|
|
159
|
+
return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
160
|
+
spaceId: space?.id,
|
|
161
|
+
});
|
|
165
162
|
}, [existingFunctionUrl, space]);
|
|
166
163
|
|
|
167
164
|
return (
|
|
168
|
-
<div
|
|
169
|
-
role='none'
|
|
170
|
-
className={mx(
|
|
171
|
-
'flex flex-col is-full bs-full overflow-hidden',
|
|
172
|
-
role === 'article' && 'row-span-2',
|
|
173
|
-
hasAttention && 'attention-surface',
|
|
174
|
-
)}
|
|
175
|
-
>
|
|
176
|
-
<TypescriptEditor
|
|
177
|
-
id={script.id}
|
|
178
|
-
env={env}
|
|
179
|
-
initialValue={initialValue}
|
|
180
|
-
extensions={extensions}
|
|
181
|
-
className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'
|
|
182
|
-
/>
|
|
183
|
-
|
|
165
|
+
<div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>
|
|
184
166
|
<Toolbar
|
|
185
|
-
classNames='border-t border-separator'
|
|
186
167
|
deployed={Boolean(existingFunctionUrl) && !script.changed}
|
|
187
168
|
functionUrl={functionUrl}
|
|
188
169
|
error={error}
|
|
189
|
-
|
|
170
|
+
view={view}
|
|
171
|
+
templates={templates}
|
|
190
172
|
onDeploy={handleDeploy}
|
|
191
173
|
onFormat={handleFormat}
|
|
192
|
-
|
|
174
|
+
onViewChange={setView}
|
|
175
|
+
onTemplateSelect={handleTemplateChange}
|
|
193
176
|
/>
|
|
194
177
|
|
|
195
|
-
{
|
|
196
|
-
<
|
|
178
|
+
{view !== 'preview' && (
|
|
179
|
+
<TypescriptEditor
|
|
180
|
+
id={script.id}
|
|
181
|
+
env={env}
|
|
182
|
+
initialValue={initialValue}
|
|
183
|
+
extensions={extensions}
|
|
184
|
+
className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'
|
|
185
|
+
/>
|
|
197
186
|
)}
|
|
187
|
+
|
|
188
|
+
{view !== 'editor' && <DebugPanel functionUrl={functionUrl} />}
|
|
198
189
|
</div>
|
|
199
190
|
);
|
|
200
191
|
};
|
|
201
|
-
|
|
202
|
-
export default ScriptEditor;
|