@dxos/plugin-script 0.7.5-main.9d26e3a → 0.7.5-main.b19bfc8
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/{AutomationPanel-RFQAQ7NF.mjs → AutomationPanel-6HFRNRWV.mjs} +3 -3
- package/dist/lib/browser/ScriptContainer-U3BFT76B.mjs +713 -0
- package/dist/lib/browser/ScriptContainer-U3BFT76B.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs +243 -0
- package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs.map +7 -0
- package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs +15 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs.map +7 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/chunk-HJNS3BBK.mjs +236 -0
- package/dist/lib/browser/chunk-HJNS3BBK.mjs.map +7 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs +40 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs +82 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +129 -288
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs +45 -0
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-DIXYM2HA.mjs +65 -0
- package/dist/lib/browser/react-surface-DIXYM2HA.mjs.map +7 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs +24 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +6 -4
- package/dist/lib/node/{AutomationPanel-5CJEF4MI.cjs → AutomationPanel-RBQ4DODN.cjs} +8 -8
- package/dist/lib/node/ScriptContainer-PSLB34RX.cjs +719 -0
- package/dist/lib/node/ScriptContainer-PSLB34RX.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-7AANUS3X.cjs +262 -0
- package/dist/lib/node/artifact-definition-7AANUS3X.cjs.map +7 -0
- package/dist/lib/node/chunk-2UNNYU2C.cjs +264 -0
- package/dist/lib/node/chunk-2UNNYU2C.cjs.map +7 -0
- package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-5UH3F7TA.cjs} +11 -8
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → chunk-ALY3N6PW.cjs} +12 -8
- package/dist/lib/node/chunk-ALY3N6PW.cjs.map +7 -0
- package/dist/lib/node/{chunk-PK3OQP5L.cjs → chunk-DJGLGRQV.cjs} +26 -11
- package/dist/lib/node/chunk-DJGLGRQV.cjs.map +7 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
- package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs +104 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +122 -277
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs +59 -0
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-JOMWTFI2.cjs +84 -0
- package/dist/lib/node/react-surface-JOMWTFI2.cjs.map +7 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs +38 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs.map +7 -0
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/{AutomationPanel-7Y6REBNJ.mjs → AutomationPanel-WTVVVMRH.mjs} +3 -3
- package/dist/lib/node-esm/ScriptContainer-E4J6XXE6.mjs +714 -0
- package/dist/lib/node-esm/ScriptContainer-E4J6XXE6.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs +245 -0
- package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-4OCRARHP.mjs +237 -0
- package/dist/lib/node-esm/chunk-4OCRARHP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs +16 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-P2V2Y5LV.mjs} +7 -4
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs +41 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs +71 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs.map +7 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs +83 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +129 -288
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-OLH7N3DK.mjs +66 -0
- package/dist/lib/node-esm/react-surface-OLH7N3DK.mjs.map +7 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs +25 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +6 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -3
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compiler.d.ts +4 -0
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings.d.ts +4 -0
- package/dist/types/src/capabilities/settings.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +1 -2
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +10 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -0
- package/dist/types/src/components/{Toolbar/Toolbar.stories.d.ts → ScriptToolbar/ScriptToolbar.stories.d.ts} +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts +2 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/deploy.d.ts +48 -0
- package/dist/types/src/hooks/deploy.d.ts.map +1 -0
- package/dist/types/src/hooks/format.d.ts +25 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/template.d.ts +31 -0
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts +14 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts +10 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/hooks/view.d.ts +33 -0
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts +1 -4
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts +3 -0
- package/dist/types/src/templates/discord.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts +2 -1
- package/dist/types/src/templates/email.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +3 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -4
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/{templates.d.ts → templates/index.d.ts} +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +97 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +14 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -46
- package/src/ScriptPlugin.tsx +70 -90
- package/src/capabilities/artifact-definition.ts +219 -0
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/compiler.ts +33 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +46 -0
- package/src/capabilities/react-surface.tsx +54 -0
- package/src/capabilities/settings.ts +14 -0
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +69 -9
- package/src/components/ScriptSettings/ScriptSettings.tsx +28 -4
- package/src/components/ScriptSettingsPanel.tsx +139 -51
- package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +53 -0
- package/src/{bundler → components/ScriptToolbar}/index.ts +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +75 -10
- package/src/events.ts +11 -0
- package/src/hooks/deploy.ts +169 -0
- package/src/hooks/format.ts +47 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/template.ts +64 -0
- package/src/hooks/useToolbarAction.ts +54 -0
- package/src/hooks/useToolbarState.ts +16 -0
- package/src/hooks/view.ts +52 -0
- package/src/index.ts +2 -7
- package/src/meta.ts +4 -2
- package/src/templates/chat.ts +4 -4
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/echo.ts +5 -1
- package/src/templates/email.ts +26 -23
- package/src/templates/forex-effect.ts +41 -0
- package/src/templates/forex.ts +23 -16
- package/src/{templates.ts → templates/index.ts} +20 -5
- package/src/translations.ts +23 -0
- package/src/types.ts +19 -18
- package/dist/lib/browser/ScriptContainer-GDVBWFI7.mjs +0 -415
- package/dist/lib/browser/ScriptContainer-GDVBWFI7.mjs.map +0 -7
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs +0 -286
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-C7VBULMK.mjs +0 -18
- package/dist/lib/browser/chunk-C7VBULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-K7KY6YMG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQA3EB5K.mjs +0 -26
- package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-YWXXNLG6.cjs +0 -426
- package/dist/lib/node/ScriptContainer-YWXXNLG6.cjs.map +0 -7
- package/dist/lib/node/chunk-4INUJLXL.cjs.map +0 -7
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +0 -7
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +0 -7
- package/dist/lib/node/chunk-WPP65EYS.cjs +0 -298
- package/dist/lib/node/chunk-WPP65EYS.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-BG2PHKEH.mjs +0 -416
- package/dist/lib/node-esm/ScriptContainer-BG2PHKEH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs +0 -288
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +0 -27
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OFYGBUNI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -39
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +0 -12
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +0 -6
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptEditor.d.ts +0 -9
- package/dist/types/src/components/ScriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/templates.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -54
- package/src/bundler/bundler.ts +0 -250
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +0 -55
- package/src/components/ScriptBlock/ScriptBlock.tsx +0 -102
- package/src/components/ScriptBlock/index.ts +0 -5
- package/src/components/ScriptEditor.tsx +0 -193
- package/src/components/Toolbar/Toolbar.tsx +0 -177
- package/src/components/Toolbar/index.ts +0 -5
- /package/dist/lib/browser/{AutomationPanel-RFQAQ7NF.mjs.map → AutomationPanel-6HFRNRWV.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-5CJEF4MI.cjs.map → AutomationPanel-RBQ4DODN.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-7Y6REBNJ.mjs.map → AutomationPanel-WTVVVMRH.mjs.map} +0 -0
|
@@ -3,27 +3,37 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { javascript } from '@codemirror/lang-javascript';
|
|
6
|
+
import { defaultHighlightStyle } from '@codemirror/language';
|
|
7
|
+
import { Prec } from '@codemirror/state';
|
|
8
|
+
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
9
|
+
import { keymap } from '@codemirror/view';
|
|
10
|
+
import { tags } from '@lezer/highlight';
|
|
6
11
|
import { type VirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
7
|
-
import {
|
|
12
|
+
import { continueKeymap } from '@valtown/codemirror-continue';
|
|
13
|
+
import { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover, type HoverInfo } from '@valtown/codemirror-ts';
|
|
8
14
|
import React from 'react';
|
|
9
15
|
|
|
10
|
-
import { useThemeContext } from '@dxos/react-ui';
|
|
16
|
+
import { type ThemeMode, useThemeContext } from '@dxos/react-ui';
|
|
11
17
|
import {
|
|
12
18
|
autocomplete,
|
|
13
19
|
createBasicExtensions,
|
|
14
20
|
createThemeExtensions,
|
|
15
21
|
editorFullWidth,
|
|
16
|
-
|
|
22
|
+
type EditorInputMode,
|
|
17
23
|
editorMonospace,
|
|
24
|
+
EditorView,
|
|
25
|
+
folding,
|
|
18
26
|
InputModeExtensions,
|
|
19
27
|
useTextEditor,
|
|
20
28
|
type UseTextEditorProps,
|
|
21
29
|
} from '@dxos/react-ui-editor';
|
|
22
|
-
import {
|
|
30
|
+
import { isNonNullable } from '@dxos/util';
|
|
23
31
|
|
|
24
32
|
export type TypescriptEditorProps = {
|
|
25
33
|
id: string;
|
|
34
|
+
inputMode?: EditorInputMode;
|
|
26
35
|
env?: VirtualTypeScriptEnvironment;
|
|
36
|
+
toolbar?: boolean;
|
|
27
37
|
} & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;
|
|
28
38
|
|
|
29
39
|
export const TypescriptEditor = ({
|
|
@@ -34,6 +44,8 @@ export const TypescriptEditor = ({
|
|
|
34
44
|
extensions,
|
|
35
45
|
scrollTo,
|
|
36
46
|
selection,
|
|
47
|
+
toolbar,
|
|
48
|
+
inputMode = 'vscode',
|
|
37
49
|
}: TypescriptEditorProps) => {
|
|
38
50
|
const { themeMode } = useThemeContext();
|
|
39
51
|
const { parentRef, focusAttributes } = useTextEditor(
|
|
@@ -56,24 +68,77 @@ export const TypescriptEditor = ({
|
|
|
56
68
|
content: { className: editorFullWidth },
|
|
57
69
|
},
|
|
58
70
|
}),
|
|
59
|
-
|
|
71
|
+
// NOTE: Not using default editor gutter because folding for code works best right beside text.
|
|
72
|
+
EditorView.theme({
|
|
73
|
+
'.cm-gutters': {
|
|
74
|
+
// Match margin from content.
|
|
75
|
+
marginTop: '16px',
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
InputModeExtensions[inputMode],
|
|
79
|
+
folding(),
|
|
80
|
+
// Continues block comments when you hit Enter.
|
|
81
|
+
Prec.high(keymap.of(continueKeymap)),
|
|
60
82
|
// TODO(burdon): Factor out.
|
|
61
83
|
[
|
|
62
84
|
editorMonospace,
|
|
63
85
|
javascript({ typescript: true }),
|
|
64
86
|
// https://github.com/val-town/codemirror-ts
|
|
65
87
|
autocomplete({ override: env ? [tsAutocomplete()] : [] }),
|
|
66
|
-
env
|
|
67
|
-
|
|
88
|
+
env
|
|
89
|
+
? [
|
|
90
|
+
tsFacet.of({ env, path: `/src/${id}.ts` }),
|
|
91
|
+
tsSync(),
|
|
92
|
+
tsLinter(),
|
|
93
|
+
tsHover({ renderTooltip: createTooltipRenderer(themeMode) }),
|
|
94
|
+
]
|
|
95
|
+
: [],
|
|
68
96
|
],
|
|
69
|
-
].filter(
|
|
97
|
+
].filter(isNonNullable),
|
|
70
98
|
selection,
|
|
71
99
|
scrollTo,
|
|
72
100
|
}),
|
|
73
|
-
[id, extensions, themeMode, selection, scrollTo],
|
|
101
|
+
[id, extensions, themeMode, inputMode, selection, scrollTo],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div ref={parentRef} data-toolbar={toolbar ? 'enabled' : 'disabled'} className={className} {...focusAttributes} />
|
|
74
106
|
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const createTooltipRenderer = (themeMode: ThemeMode) => {
|
|
110
|
+
const theme = themeMode === 'dark' ? oneDarkHighlightStyle : defaultHighlightStyle;
|
|
111
|
+
|
|
112
|
+
const classFromKind = (_kind: string) => {
|
|
113
|
+
// E.g., localName, methodName, parameterName, etc.
|
|
114
|
+
const kind = _kind.endsWith('Name') ? 'name' : _kind;
|
|
115
|
+
const validTag = kind in tags;
|
|
116
|
+
if (!validTag) {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tag = tags[kind as keyof typeof tags];
|
|
121
|
+
if (typeof tag === 'function') {
|
|
122
|
+
return '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return theme.style([tag]) ?? '';
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return (info: HoverInfo) => {
|
|
129
|
+
const div = document.createElement('div');
|
|
130
|
+
div.className = 'p-1 rounded border border-separator bg-baseSurface xs:max-w-80 max-w-lg';
|
|
131
|
+
|
|
132
|
+
if (info.quickInfo?.displayParts) {
|
|
133
|
+
for (const part of info.quickInfo.displayParts) {
|
|
134
|
+
const span = div.appendChild(document.createElement('span'));
|
|
135
|
+
span.className = classFromKind(part.kind);
|
|
136
|
+
span.innerText = part.text;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
75
139
|
|
|
76
|
-
|
|
140
|
+
return { dom: div };
|
|
141
|
+
};
|
|
77
142
|
};
|
|
78
143
|
|
|
79
144
|
export default TypescriptEditor;
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { defineEvent } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { SCRIPT_PLUGIN } from './meta';
|
|
8
|
+
|
|
9
|
+
export namespace ScriptEvents {
|
|
10
|
+
export const SetupCompiler = defineEvent(`${SCRIPT_PLUGIN}/event/setup-compiler`);
|
|
11
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
FunctionType,
|
|
9
|
+
type ScriptType,
|
|
10
|
+
getInvocationUrl,
|
|
11
|
+
getUserFunctionUrlInMetadata,
|
|
12
|
+
incrementSemverPatch,
|
|
13
|
+
setUserFunctionUrlInMetadata,
|
|
14
|
+
uploadWorkerFunction,
|
|
15
|
+
} from '@dxos/functions';
|
|
16
|
+
import { Bundler } from '@dxos/functions/bundler';
|
|
17
|
+
import { log } from '@dxos/log';
|
|
18
|
+
import { useClient } from '@dxos/react-client';
|
|
19
|
+
import { Filter, create, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
|
|
20
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
21
|
+
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
22
|
+
|
|
23
|
+
import { type ViewState } from './view';
|
|
24
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
25
|
+
|
|
26
|
+
export type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };
|
|
27
|
+
|
|
28
|
+
export type DeployState = ViewState & {
|
|
29
|
+
deploying: boolean;
|
|
30
|
+
deployed: boolean;
|
|
31
|
+
functionUrl: string;
|
|
32
|
+
error: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const createDeploy = (state: Partial<DeployState>) => {
|
|
36
|
+
const errorItem = createMenuAction('error', {
|
|
37
|
+
label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],
|
|
38
|
+
icon: 'ph--warning-circle--regular',
|
|
39
|
+
hidden: !state.error,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const deployAction = createMenuAction<DeployActionProperties>('deploy', {
|
|
43
|
+
type: 'deploy',
|
|
44
|
+
label: [state.deploying ? 'pending label' : 'deploy label', { ns: SCRIPT_PLUGIN }],
|
|
45
|
+
icon: state.deploying ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular',
|
|
46
|
+
disabled: state.deploying,
|
|
47
|
+
classNames: state.deploying ? '[&_svg]:animate-spin' : '',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const copyAction = createMenuAction<DeployActionProperties>('copy', {
|
|
51
|
+
type: 'copy',
|
|
52
|
+
label: ['copy link label', { ns: SCRIPT_PLUGIN }],
|
|
53
|
+
icon: 'ph--link--regular',
|
|
54
|
+
disabled: !state.functionUrl,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
nodes: [errorItem, deployAction, copyAction],
|
|
59
|
+
edges: [
|
|
60
|
+
{ source: 'root', target: 'error' },
|
|
61
|
+
{ source: 'root', target: 'deploy' },
|
|
62
|
+
{ source: 'root', target: 'copy' },
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const useDeployDeps = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
68
|
+
const space = getSpace(script);
|
|
69
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));
|
|
70
|
+
const client = useClient();
|
|
71
|
+
const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);
|
|
72
|
+
return { space, fn, client, existingFunctionUrl };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
76
|
+
const { space, client, existingFunctionUrl } = useDeployDeps({ state, script });
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!existingFunctionUrl) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
state.functionUrl = getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
83
|
+
spaceId: space?.id,
|
|
84
|
+
});
|
|
85
|
+
}, [existingFunctionUrl, space]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
state.deployed = Boolean(existingFunctionUrl) && !script.changed;
|
|
89
|
+
}, [script.changed, existingFunctionUrl]);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const useDeployHandler = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
93
|
+
const { space, fn, client, existingFunctionUrl } = useDeployDeps({ state, script });
|
|
94
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
95
|
+
|
|
96
|
+
return useCallback(async () => {
|
|
97
|
+
if (!script.source || !space) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
state.error = undefined;
|
|
102
|
+
state.deploying = true;
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
|
|
106
|
+
|
|
107
|
+
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
108
|
+
const buildResult = await bundler.bundle({ source: script.source.target!.content });
|
|
109
|
+
if (buildResult.error || !buildResult.bundle) {
|
|
110
|
+
throw buildResult.error;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
114
|
+
client,
|
|
115
|
+
spaceId: space.id,
|
|
116
|
+
version: fn ? incrementSemverPatch(fn.version) : '0.0.1',
|
|
117
|
+
functionId: existingFunctionId,
|
|
118
|
+
source: buildResult.bundle,
|
|
119
|
+
});
|
|
120
|
+
if (functionId === undefined || version === undefined) {
|
|
121
|
+
throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
log.info('function uploaded', { functionId, version });
|
|
125
|
+
if (fn) {
|
|
126
|
+
fn.version = version;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const deployedFunction =
|
|
130
|
+
fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
|
|
131
|
+
|
|
132
|
+
script.changed = false;
|
|
133
|
+
if (script.description !== undefined && script.description.trim() !== '') {
|
|
134
|
+
deployedFunction.description = script.description;
|
|
135
|
+
} else if (meta.description) {
|
|
136
|
+
deployedFunction.description = meta.description;
|
|
137
|
+
} else {
|
|
138
|
+
log.verbose('no description in function metadata', { functionId });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (meta.inputSchema) {
|
|
142
|
+
deployedFunction.inputSchema = meta.inputSchema;
|
|
143
|
+
} else {
|
|
144
|
+
log.verbose('no input schema in function metadata', { functionId });
|
|
145
|
+
}
|
|
146
|
+
if (meta.outputSchema) {
|
|
147
|
+
deployedFunction.outputSchema = meta.outputSchema;
|
|
148
|
+
} else {
|
|
149
|
+
log.verbose('no output schema in function metadata', { functionId });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
|
|
153
|
+
|
|
154
|
+
state.view = 'split';
|
|
155
|
+
} catch (err: any) {
|
|
156
|
+
log.catch(err);
|
|
157
|
+
state.error = t('upload failed label');
|
|
158
|
+
}
|
|
159
|
+
state.deploying = false;
|
|
160
|
+
}, [fn, client, t, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const useCopyHandler = ({ state }: { state: Partial<DeployState> }) =>
|
|
164
|
+
useCallback(async () => {
|
|
165
|
+
if (!state.functionUrl) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
await navigator.clipboard.writeText(state.functionUrl);
|
|
169
|
+
}, [state.functionUrl]);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { format } from 'prettier';
|
|
6
|
+
import prettierPluginEstree from 'prettier/plugins/estree';
|
|
7
|
+
import prettierPluginTypescript from 'prettier/plugins/typescript';
|
|
8
|
+
import { useCallback } from 'react';
|
|
9
|
+
|
|
10
|
+
import { type ScriptType } from '@dxos/functions';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
13
|
+
|
|
14
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
15
|
+
|
|
16
|
+
export type FormatActionProperties = { type: 'format' };
|
|
17
|
+
|
|
18
|
+
export const createFormat = () => {
|
|
19
|
+
const formatAction = createMenuAction('format', {
|
|
20
|
+
label: ['format label', { ns: SCRIPT_PLUGIN }],
|
|
21
|
+
icon: 'ph--magic-wand--regular',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
nodes: [formatAction],
|
|
26
|
+
edges: [{ source: 'root', target: 'format' }],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const useFormatHandler = ({ script }: { script: ScriptType }) =>
|
|
31
|
+
useCallback(async () => {
|
|
32
|
+
if (!script.source) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
script.source.target!.content = await format(script.source.target!.content, {
|
|
38
|
+
parser: 'typescript',
|
|
39
|
+
plugins: [prettierPluginEstree, prettierPluginTypescript],
|
|
40
|
+
semi: true,
|
|
41
|
+
singleQuote: true,
|
|
42
|
+
});
|
|
43
|
+
} catch (err: any) {
|
|
44
|
+
// TODO(wittjosiah): Show error in UI.
|
|
45
|
+
log.catch(err);
|
|
46
|
+
}
|
|
47
|
+
}, [script.source]);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
|
|
8
|
+
import { getMeta } from '@dxos/live-object';
|
|
9
|
+
import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
|
|
10
|
+
|
|
11
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
12
|
+
import { templates } from '../templates';
|
|
13
|
+
|
|
14
|
+
export type TemplateActionProperties = { type: 'template'; value: string };
|
|
15
|
+
|
|
16
|
+
const createTemplateSelectGroup = () => {
|
|
17
|
+
return createMenuItemGroup('template-select', {
|
|
18
|
+
label: ['template select group label', { ns: SCRIPT_PLUGIN }],
|
|
19
|
+
variant: 'dropdownMenu',
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const createTemplateSelectActions = () => {
|
|
24
|
+
return templates.map((template) => {
|
|
25
|
+
return createMenuAction<TemplateActionProperties>(`template--${template.id}`, {
|
|
26
|
+
label: template.name,
|
|
27
|
+
value: template.id,
|
|
28
|
+
type: 'template',
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createTemplateSelect = () => {
|
|
34
|
+
const templateSelectGroup = createTemplateSelectGroup();
|
|
35
|
+
const templateSelectActions = createTemplateSelectActions();
|
|
36
|
+
return {
|
|
37
|
+
nodes: [templateSelectGroup, ...templateSelectActions],
|
|
38
|
+
edges: [
|
|
39
|
+
{ source: 'root', target: 'template-select' },
|
|
40
|
+
...templateSelectActions.map((action) => ({ source: 'template-select', target: action.id })),
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const useTemplateSelectHandler = ({ script }: { script: ScriptType }) => {
|
|
46
|
+
return useCallback(
|
|
47
|
+
(templateId: string) => {
|
|
48
|
+
const template = templates.find((template) => template.id === templateId);
|
|
49
|
+
if (template) {
|
|
50
|
+
script.name = template.name;
|
|
51
|
+
script.source!.target!.content = template.source;
|
|
52
|
+
const metaKeys = getMeta(script).keys;
|
|
53
|
+
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
54
|
+
if (oldPresetIndex >= 0) {
|
|
55
|
+
metaKeys.splice(oldPresetIndex, 1);
|
|
56
|
+
}
|
|
57
|
+
if (template.presetId) {
|
|
58
|
+
metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
[script],
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type ScriptType } from '@dxos/functions';
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
import { type MenuAction, type MenuActionHandler } from '@dxos/react-ui-menu';
|
|
10
|
+
|
|
11
|
+
import { type DeployActionProperties, useDeployHandler, useCopyHandler } from './deploy';
|
|
12
|
+
import { type FormatActionProperties, useFormatHandler } from './format';
|
|
13
|
+
import { type TemplateActionProperties, useTemplateSelectHandler } from './template';
|
|
14
|
+
import { type ScriptToolbarState } from './useToolbarState';
|
|
15
|
+
import { type ViewActionProperties } from './view';
|
|
16
|
+
|
|
17
|
+
export type ScriptToolbarActionProperties =
|
|
18
|
+
| TemplateActionProperties
|
|
19
|
+
| ViewActionProperties
|
|
20
|
+
| FormatActionProperties
|
|
21
|
+
| DeployActionProperties;
|
|
22
|
+
|
|
23
|
+
export type ScriptToolbarAction = MenuAction<ScriptToolbarActionProperties>;
|
|
24
|
+
|
|
25
|
+
export const useToolbarAction = (props: { state: ScriptToolbarState; script: ScriptType }) => {
|
|
26
|
+
const handleTemplateSelect = useTemplateSelectHandler(props);
|
|
27
|
+
const handleFormat = useFormatHandler(props);
|
|
28
|
+
const handleDeploy = useDeployHandler(props);
|
|
29
|
+
const handleCopy = useCopyHandler(props);
|
|
30
|
+
return useCallback(
|
|
31
|
+
((action: ScriptToolbarAction) => {
|
|
32
|
+
switch (action.properties.type) {
|
|
33
|
+
case 'template':
|
|
34
|
+
handleTemplateSelect(action.properties.value);
|
|
35
|
+
break;
|
|
36
|
+
case 'view':
|
|
37
|
+
props.state.view = action.properties.value;
|
|
38
|
+
break;
|
|
39
|
+
case 'format':
|
|
40
|
+
void handleFormat();
|
|
41
|
+
break;
|
|
42
|
+
case 'deploy':
|
|
43
|
+
void handleDeploy();
|
|
44
|
+
break;
|
|
45
|
+
case 'copy':
|
|
46
|
+
void handleCopy();
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
log.error('Unknown action type', action);
|
|
50
|
+
}
|
|
51
|
+
}) as MenuActionHandler,
|
|
52
|
+
[handleTemplateSelect, handleFormat, handleDeploy, handleCopy],
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { create } from '@dxos/live-object';
|
|
8
|
+
|
|
9
|
+
import { type DeployState } from './deploy';
|
|
10
|
+
import { type ViewState } from './view';
|
|
11
|
+
|
|
12
|
+
export type ScriptToolbarState = Partial<DeployState & ViewState>;
|
|
13
|
+
|
|
14
|
+
export const useToolbarState = (initialState: ScriptToolbarState = {}) => {
|
|
15
|
+
return useMemo(() => create<ScriptToolbarState>(initialState), []);
|
|
16
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
6
|
+
|
|
7
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
8
|
+
|
|
9
|
+
export type ViewType = 'editor' | 'split' | 'debug';
|
|
10
|
+
|
|
11
|
+
export type ViewState = { view: ViewType };
|
|
12
|
+
|
|
13
|
+
export type ViewActionProperties = { type: 'view'; value: ViewType };
|
|
14
|
+
|
|
15
|
+
const views: Record<ViewType, string> = {
|
|
16
|
+
editor: 'ph--code--regular',
|
|
17
|
+
split: 'ph--square-split-vertical--regular',
|
|
18
|
+
debug: 'ph--bug--regular',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const createViewGroupItem = (state: Partial<ViewState>) => {
|
|
22
|
+
return createMenuItemGroup('view', {
|
|
23
|
+
label: ['view group label', { ns: SCRIPT_PLUGIN }],
|
|
24
|
+
variant: 'dropdownMenu',
|
|
25
|
+
applyActive: true,
|
|
26
|
+
value: state.view,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const createViewActions = (state: Partial<ViewState>) => {
|
|
31
|
+
return Object.entries(views).map(([viewType, icon]) => {
|
|
32
|
+
return createMenuAction<ViewActionProperties>(`view--${viewType}`, {
|
|
33
|
+
type: 'view',
|
|
34
|
+
value: viewType as ViewType,
|
|
35
|
+
label: [`view ${viewType} label`, { ns: SCRIPT_PLUGIN }],
|
|
36
|
+
icon,
|
|
37
|
+
checked: state.view === viewType,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const createView = (state: Partial<ViewState>) => {
|
|
43
|
+
const viewGroupItem = createViewGroupItem(state);
|
|
44
|
+
const viewActions = createViewActions(state);
|
|
45
|
+
return {
|
|
46
|
+
nodes: [viewGroupItem, ...viewActions],
|
|
47
|
+
edges: [
|
|
48
|
+
{ source: 'root', target: 'view' },
|
|
49
|
+
...viewActions.map((action) => ({ source: 'view', target: action.id })),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default ScriptPlugin;
|
|
8
|
-
|
|
9
|
-
export * from './bundler';
|
|
10
|
-
export * from './compiler';
|
|
5
|
+
export { ScriptCapabilities } from './capabilities';
|
|
11
6
|
export * from './components';
|
|
12
|
-
export * from './
|
|
7
|
+
export * from './meta';
|
|
13
8
|
|
|
14
9
|
export * from './ScriptPlugin';
|
package/src/meta.ts
CHANGED
|
@@ -6,11 +6,13 @@ import { type PluginMeta } from '@dxos/app-framework';
|
|
|
6
6
|
|
|
7
7
|
export const SCRIPT_PLUGIN = 'dxos.org/plugin/script';
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export const meta = {
|
|
10
10
|
id: SCRIPT_PLUGIN,
|
|
11
11
|
name: 'Scripts',
|
|
12
|
-
description:
|
|
12
|
+
description:
|
|
13
|
+
'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',
|
|
13
14
|
icon: 'ph--code--regular',
|
|
14
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',
|
|
15
16
|
tags: ['experimental'],
|
|
17
|
+
screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
|
|
16
18
|
} satisfies PluginMeta;
|
package/src/templates/chat.ts
CHANGED
|
@@ -57,11 +57,11 @@ export default async ({
|
|
|
57
57
|
let prompt = promptObject.template;
|
|
58
58
|
for (const input of promptObject.inputs) {
|
|
59
59
|
let value: string | null = null;
|
|
60
|
-
if (input.type ===
|
|
60
|
+
if (input.type === TemplateInputType.VALUE) {
|
|
61
61
|
value = String(input.value);
|
|
62
|
-
} else if (input.type ===
|
|
62
|
+
} else if (input.type === TemplateInputType.RETRIEVER) {
|
|
63
63
|
value = await getContext({ space });
|
|
64
|
-
} else if (input.type ===
|
|
64
|
+
} else if (input.type === TemplateInputType.PASS_THROUGH) {
|
|
65
65
|
value = message.text;
|
|
66
66
|
}
|
|
67
67
|
if (value) {
|
|
@@ -90,7 +90,7 @@ const getContext = async ({ space }: any) => {
|
|
|
90
90
|
return context;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
enum
|
|
93
|
+
enum TemplateInputType {
|
|
94
94
|
VALUE = 0,
|
|
95
95
|
PASS_THROUGH = 1,
|
|
96
96
|
RETRIEVER = 2,
|