@dxos/plugin-script 0.8.4-main.2e9d522 → 0.8.4-main.5ea62a8
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/{DeploymentDialog-M4QIHTDR.mjs → DeploymentDialog-QZSTVNIS.mjs} +3 -3
- package/dist/lib/browser/{ScriptContainer-Z6SIGRRC.mjs → ScriptContainer-JUPCBUCP.mjs} +10 -9
- package/dist/lib/browser/ScriptContainer-JUPCBUCP.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-HLQ7K3BT.mjs → app-graph-builder-IABOSTBK.mjs} +2 -2
- package/dist/lib/{node-esm/app-graph-builder-7EYIHWH4.mjs.map → browser/app-graph-builder-IABOSTBK.mjs.map} +3 -3
- package/dist/lib/browser/blueprint-definition-AR7ITBCD.mjs +28 -0
- package/dist/lib/browser/blueprint-definition-AR7ITBCD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-3U6DTUH3.mjs → chunk-6CAH7VIE.mjs} +14 -14
- package/dist/lib/browser/chunk-6CAH7VIE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FMDXKOP7.mjs → chunk-NXKU3BNX.mjs} +33 -44
- package/dist/lib/browser/chunk-NXKU3BNX.mjs.map +7 -0
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs +88 -0
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FIM2MVNJ.mjs → chunk-TH7GXPE3.mjs} +41 -40
- package/dist/lib/browser/chunk-TH7GXPE3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-P4HQKUCP.mjs → chunk-YCZPTTFO.mjs} +3 -3
- package/dist/lib/browser/chunk-YCZPTTFO.mjs.map +7 -0
- package/dist/lib/browser/{compiler-CXCUA4UQ.mjs → compiler-2HJH34GM.mjs} +20 -4
- package/dist/lib/browser/compiler-2HJH34GM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +14 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-7B77IG3N.mjs → intent-resolver-YMK5SXVC.mjs} +8 -10
- package/dist/lib/browser/intent-resolver-YMK5SXVC.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FYYXZA7C.mjs → react-surface-FEM5WWFH.mjs} +6 -6
- package/dist/lib/browser/react-surface-FEM5WWFH.mjs.map +7 -0
- package/dist/lib/browser/templates/index.mjs +1 -1
- package/dist/lib/node-esm/{DeploymentDialog-3KPRWFE7.mjs → DeploymentDialog-G6EHEPXN.mjs} +3 -3
- package/dist/lib/node-esm/{ScriptContainer-KPU75HHI.mjs → ScriptContainer-UXZUDQF6.mjs} +10 -9
- package/dist/lib/node-esm/ScriptContainer-UXZUDQF6.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-7EYIHWH4.mjs → app-graph-builder-CQTTAYHP.mjs} +2 -2
- package/dist/lib/{browser/app-graph-builder-HLQ7K3BT.mjs.map → node-esm/app-graph-builder-CQTTAYHP.mjs.map} +3 -3
- package/dist/lib/node-esm/blueprint-definition-TJY4TX6S.mjs +30 -0
- package/dist/lib/node-esm/blueprint-definition-TJY4TX6S.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-RT43MACC.mjs → chunk-2GBESIHU.mjs} +14 -14
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-7NMI4CEU.mjs → chunk-6M2R2FQF.mjs} +41 -40
- package/dist/lib/node-esm/chunk-6M2R2FQF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs +90 -0
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-XJPK3IYI.mjs → chunk-M642JUOZ.mjs} +33 -44
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-QKK3NDHW.mjs → chunk-ZA36GO4T.mjs} +3 -3
- package/dist/lib/node-esm/chunk-ZA36GO4T.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-EPFKQXPE.mjs → compiler-7SP27RA6.mjs} +20 -4
- package/dist/lib/node-esm/compiler-7SP27RA6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +14 -13
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-FRZGS4TB.mjs → intent-resolver-SKRDYQCZ.mjs} +8 -10
- package/dist/lib/node-esm/intent-resolver-SKRDYQCZ.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-V32NWHKN.mjs → react-surface-AOKMDJR4.mjs} +6 -6
- package/dist/lib/node-esm/react-surface-AOKMDJR4.mjs.map +7 -0
- package/dist/lib/node-esm/templates/index.mjs +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/compiler.d.ts +1 -1
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +6 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/settings.d.ts +1 -1
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +139 -12
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/index.d.ts +1 -1
- package/dist/types/src/components/DeploymentDialog/index.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +7 -10
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +10 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +6 -5
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/deploy.d.ts +3 -3
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -54
- package/src/ScriptPlugin.tsx +4 -4
- package/src/capabilities/app-graph-builder.ts +2 -2
- package/src/capabilities/artifact-definition.ts +7 -11
- package/src/capabilities/blueprint-definition.ts +30 -0
- package/src/capabilities/compiler.ts +2 -1
- package/src/capabilities/index.ts +1 -1
- package/src/capabilities/intent-resolver.ts +2 -5
- package/src/capabilities/react-surface.tsx +3 -2
- package/src/compiler/compiler.ts +1 -1
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +28 -16
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +5 -5
- package/src/components/DeploymentDialog/index.ts +1 -1
- package/src/components/FrameContainer/FrameContainer.tsx +3 -2
- package/src/components/ScriptContainer.tsx +3 -2
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +19 -14
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +14 -4
- package/src/components/Settings/ScriptObjectSettings.tsx +19 -23
- package/src/components/Settings/ScriptPluginSettings.tsx +33 -28
- package/src/components/TestPanel/TestContainer.tsx +2 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +9 -16
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +3 -2
- package/src/hooks/deploy.ts +11 -11
- package/src/hooks/template.ts +1 -1
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +1 -0
- package/src/templates/chess.ts +1 -1
- package/src/templates/data-generator.ts +7 -3
- package/src/templates/discord.ts +4 -4
- package/src/templates/forex-effect.ts +3 -3
- package/src/templates/forex.ts +1 -1
- package/src/templates/gmail.ts +13 -54
- package/src/translations.ts +1 -0
- package/src/util/deploy.ts +20 -33
- package/src/util/functions.ts +4 -4
- package/dist/lib/browser/ScriptContainer-Z6SIGRRC.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-24Q3IHOU.mjs +0 -249
- package/dist/lib/browser/artifact-definition-24Q3IHOU.mjs.map +0 -7
- package/dist/lib/browser/chunk-3U6DTUH3.mjs.map +0 -7
- package/dist/lib/browser/chunk-FIM2MVNJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-FMDXKOP7.mjs.map +0 -7
- package/dist/lib/browser/chunk-P4HQKUCP.mjs.map +0 -7
- package/dist/lib/browser/chunk-R4R7VOFY.mjs +0 -88
- package/dist/lib/browser/chunk-R4R7VOFY.mjs.map +0 -7
- package/dist/lib/browser/compiler-CXCUA4UQ.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-7B77IG3N.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FYYXZA7C.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-KPU75HHI.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-WAJFALUI.mjs +0 -250
- package/dist/lib/node-esm/artifact-definition-WAJFALUI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-7NMI4CEU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs +0 -90
- package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QKK3NDHW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RT43MACC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XJPK3IYI.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-EPFKQXPE.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-FRZGS4TB.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-V32NWHKN.mjs.map +0 -7
- /package/dist/lib/browser/{DeploymentDialog-M4QIHTDR.mjs.map → DeploymentDialog-QZSTVNIS.mjs.map} +0 -0
- /package/dist/lib/node-esm/{DeploymentDialog-3KPRWFE7.mjs.map → DeploymentDialog-G6EHEPXN.mjs.map} +0 -0
|
@@ -8,7 +8,7 @@ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
|
8
8
|
import { useClient } from '@dxos/react-client';
|
|
9
9
|
import { Button, Select, useTranslation } from '@dxos/react-ui';
|
|
10
10
|
import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
|
|
11
|
-
import {
|
|
11
|
+
import { ControlGroup, ControlItemInput, ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
12
12
|
|
|
13
13
|
import { meta } from '../../meta';
|
|
14
14
|
import { type ScriptSettingsProps } from '../../types';
|
|
@@ -39,33 +39,38 @@ export const ScriptPluginSettings = ({ settings }: { settings: ScriptSettingsPro
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
return (
|
|
42
|
-
<
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
<ControlPage>
|
|
43
|
+
<ControlSection title={t('settings title', { ns: meta.id })}>
|
|
44
|
+
<ControlGroup>
|
|
45
|
+
{/* TODO(wittjosiah): Hide outside of dev environments. */}
|
|
46
|
+
<ControlItemInput title={t('authenticate action label')}>
|
|
47
|
+
<Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
|
|
48
|
+
</ControlItemInput>
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
<ControlItemInput title={t('editor input mode label')}>
|
|
51
|
+
<Select.Root
|
|
52
|
+
value={settings.editorInputMode ?? 'default'}
|
|
53
|
+
onValueChange={(value) => {
|
|
54
|
+
settings.editorInputMode = value as EditorInputMode;
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<Select.TriggerButton placeholder={t('select editor input mode placeholder')} />
|
|
58
|
+
<Select.Portal>
|
|
59
|
+
<Select.Content>
|
|
60
|
+
<Select.Viewport>
|
|
61
|
+
{EditorInputModes.map((mode) => (
|
|
62
|
+
<Select.Option key={mode} value={mode}>
|
|
63
|
+
{t(`settings editor input mode ${mode} label`)}
|
|
64
|
+
</Select.Option>
|
|
65
|
+
))}
|
|
66
|
+
</Select.Viewport>
|
|
67
|
+
<Select.Arrow />
|
|
68
|
+
</Select.Content>
|
|
69
|
+
</Select.Portal>
|
|
70
|
+
</Select.Root>
|
|
71
|
+
</ControlItemInput>
|
|
72
|
+
</ControlGroup>
|
|
73
|
+
</ControlSection>
|
|
74
|
+
</ControlPage>
|
|
70
75
|
);
|
|
71
76
|
};
|
|
@@ -7,9 +7,10 @@ import React from 'react';
|
|
|
7
7
|
import { type ScriptType } from '@dxos/functions';
|
|
8
8
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
9
|
|
|
10
|
-
import { TestPanel } from './TestPanel';
|
|
11
10
|
import { useDeployState, useToolbarState } from '../../hooks';
|
|
12
11
|
|
|
12
|
+
import { TestPanel } from './TestPanel';
|
|
13
|
+
|
|
13
14
|
export type TestContainerProps = {
|
|
14
15
|
role: string;
|
|
15
16
|
script: ScriptType;
|
|
@@ -4,25 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type Meta } from '@storybook/react-vite';
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
8
|
import React, { useMemo } from 'react';
|
|
9
9
|
|
|
10
10
|
import { createDocAccessor, createObject } from '@dxos/react-client/echo';
|
|
11
11
|
import { createDataExtensions } from '@dxos/react-ui-editor';
|
|
12
12
|
import { withTheme } from '@dxos/storybook-utils';
|
|
13
13
|
|
|
14
|
-
import { TypescriptEditor } from './TypescriptEditor';
|
|
15
14
|
import { templates } from '../../templates';
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
// - language support for S
|
|
19
|
-
// - hierarchical editor (DND)
|
|
20
|
-
// - virtual document image rendering
|
|
21
|
-
// - mobile rendering error
|
|
22
|
-
|
|
23
|
-
// TODO(burdon): JSX.
|
|
24
|
-
// TODO(burdon): Effect schema.
|
|
25
|
-
// TODO(burdon): react-buddy for storybook?
|
|
16
|
+
import { TypescriptEditor } from './TypescriptEditor';
|
|
26
17
|
|
|
27
18
|
const DefaultStory = () => {
|
|
28
19
|
const object = useMemo(() => createObject({ content: templates[0].source }), []);
|
|
@@ -32,13 +23,15 @@ const DefaultStory = () => {
|
|
|
32
23
|
return <TypescriptEditor id='test' initialValue={initialValue} extensions={extensions} />;
|
|
33
24
|
};
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const meta: Meta = {
|
|
26
|
+
const meta = {
|
|
38
27
|
title: 'plugins/plugin-script/TypescriptEditor',
|
|
39
|
-
component: TypescriptEditor,
|
|
28
|
+
component: TypescriptEditor as any,
|
|
40
29
|
render: DefaultStory,
|
|
41
30
|
decorators: [withTheme],
|
|
42
|
-
}
|
|
31
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
43
32
|
|
|
44
33
|
export default meta;
|
|
34
|
+
|
|
35
|
+
type Story = StoryObj<typeof meta>;
|
|
36
|
+
|
|
37
|
+
export const Default: Story = {};
|
|
@@ -11,10 +11,10 @@ import { keymap } from '@codemirror/view';
|
|
|
11
11
|
import { tags } from '@lezer/highlight';
|
|
12
12
|
import { type VirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
13
13
|
import { continueKeymap } from '@valtown/codemirror-continue';
|
|
14
|
-
import {
|
|
14
|
+
import { type HoverInfo, tsAutocomplete, tsFacet, tsHover, tsLinter, tsSync } from '@valtown/codemirror-ts';
|
|
15
15
|
import React from 'react';
|
|
16
16
|
|
|
17
|
-
import { type
|
|
17
|
+
import { type ThemeMode, type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
18
18
|
import {
|
|
19
19
|
type EditorInputMode,
|
|
20
20
|
InputModeExtensions,
|
|
@@ -64,6 +64,7 @@ export const TypescriptEditor = ({
|
|
|
64
64
|
lineWrapping: false,
|
|
65
65
|
monospace: true,
|
|
66
66
|
scrollPastEnd: true,
|
|
67
|
+
search: true,
|
|
67
68
|
}),
|
|
68
69
|
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
69
70
|
InputModeExtensions[inputMode],
|
package/src/hooks/deploy.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { FunctionType, type ScriptType,
|
|
7
|
+
import { FunctionType, type ScriptType, getUserFunctionIdInMetadata } from '@dxos/functions';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
9
|
import { type Client, useClient } from '@dxos/react-client';
|
|
10
|
-
import {
|
|
10
|
+
import { Query, Ref, type Space, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
11
11
|
import { type TFunction } from '@dxos/react-ui';
|
|
12
12
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
13
13
|
import { errorMessageColors } from '@dxos/react-ui-theme';
|
|
@@ -29,12 +29,12 @@ export type CreateDeployOptions = {
|
|
|
29
29
|
script: ScriptType;
|
|
30
30
|
fn: FunctionType;
|
|
31
31
|
space?: Space;
|
|
32
|
-
|
|
32
|
+
existingFunctionId?: string;
|
|
33
33
|
client: Client;
|
|
34
34
|
t: TFunction;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const createDeploy = ({ state, script, space, fn, client,
|
|
37
|
+
export const createDeploy = ({ state, script, space, fn, client, existingFunctionId, t }: CreateDeployOptions) => {
|
|
38
38
|
// TODO(wittjosiah): Should this be an action?
|
|
39
39
|
const errorItem = createMenuAction('error', () => {}, {
|
|
40
40
|
label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],
|
|
@@ -53,7 +53,7 @@ export const createDeploy = ({ state, script, space, fn, client, existingFunctio
|
|
|
53
53
|
state.error = undefined;
|
|
54
54
|
state.deploying = true;
|
|
55
55
|
|
|
56
|
-
const result = await deployScript({ script, client, space, fn,
|
|
56
|
+
const result = await deployScript({ script, client, space, fn, existingFunctionId });
|
|
57
57
|
|
|
58
58
|
if (!result.success) {
|
|
59
59
|
log.catch(result.error);
|
|
@@ -98,9 +98,9 @@ export const createDeploy = ({ state, script, space, fn, client, existingFunctio
|
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
101
|
-
const { space, client, fn,
|
|
101
|
+
const { space, client, fn, existingFunctionId } = useDeployDeps({ script });
|
|
102
102
|
useEffect(() => {
|
|
103
|
-
if (!
|
|
103
|
+
if (!existingFunctionId) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -109,17 +109,17 @@ export const useDeployState = ({ state, script }: { state: Partial<DeployState>;
|
|
|
109
109
|
fn,
|
|
110
110
|
edgeUrl: client.config.values.runtime?.services?.edge?.url ?? '',
|
|
111
111
|
});
|
|
112
|
-
}, [
|
|
112
|
+
}, [existingFunctionId, space, fn, script, client.config.values.runtime?.services?.edge?.url]);
|
|
113
113
|
|
|
114
114
|
useEffect(() => {
|
|
115
115
|
state.deployed = isScriptDeployed({ script, fn });
|
|
116
|
-
}, [script.changed,
|
|
116
|
+
}, [script.changed, existingFunctionId, fn, script]);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
export const useDeployDeps = ({ script }: { script: ScriptType }) => {
|
|
120
120
|
const space = getSpace(script);
|
|
121
121
|
const [fn] = useQuery(space, Query.type(FunctionType, { source: Ref.make(script) }));
|
|
122
122
|
const client = useClient();
|
|
123
|
-
const
|
|
124
|
-
return { space, fn, client,
|
|
123
|
+
const existingFunctionId = useMemo(() => fn && getUserFunctionIdInMetadata(getMeta(fn)), [fn]);
|
|
124
|
+
return { space, fn, client, existingFunctionId };
|
|
125
125
|
};
|
package/src/hooks/template.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Obj } from '@dxos/echo';
|
|
6
6
|
import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
|
|
7
|
-
import {
|
|
7
|
+
import { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
8
8
|
|
|
9
9
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
10
10
|
import { templates } from '../templates';
|
|
@@ -55,5 +55,6 @@ export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scri
|
|
|
55
55
|
setStatus(hasErrors ? 'error' : 'success');
|
|
56
56
|
}, [space, dispatch, client, scriptTemplates]);
|
|
57
57
|
|
|
58
|
+
// TODO(burdon): Return onCreateAndDeployScripts.
|
|
58
59
|
return { handleCreateAndDeployScripts, status, error };
|
|
59
60
|
};
|
package/src/templates/chess.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { Expando, S, create, defineFunction } from 'dxos:functions';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';
|
|
9
9
|
|
|
@@ -12,11 +12,15 @@ export default defineFunction({
|
|
|
12
12
|
documentAmount: S.optional(S.Number),
|
|
13
13
|
textSize: S.optional(S.Number),
|
|
14
14
|
mutationAmount: S.optional(S.Number),
|
|
15
|
+
waitAfterCreation: S.optional(S.Number),
|
|
15
16
|
}),
|
|
16
17
|
|
|
17
18
|
outputSchema: S.Struct({}),
|
|
18
19
|
|
|
19
|
-
handler: async ({
|
|
20
|
+
handler: async ({
|
|
21
|
+
data: { documentAmount = 1, textSize = 10, mutationAmount = 0, waitAfterCreation = 10_000 },
|
|
22
|
+
context: { space },
|
|
23
|
+
}: any) => {
|
|
20
24
|
await space.db.graph.schemaRegistry.addSchema([Expando]);
|
|
21
25
|
const result: Record<string, any> = {};
|
|
22
26
|
const objects: Expando[] = [];
|
|
@@ -42,7 +46,7 @@ export default defineFunction({
|
|
|
42
46
|
|
|
43
47
|
// Flush and wait for data to propagate.
|
|
44
48
|
await space.db.flush();
|
|
45
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, waitAfterCreation));
|
|
46
50
|
return { createdObjects: objects.length };
|
|
47
51
|
},
|
|
48
52
|
});
|
package/src/templates/discord.ts
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { DXN, EchoObject, Filter, ObjectId, S, create, defineFunction } from 'dxos:functions';
|
|
7
7
|
// @ts-ignore
|
|
8
|
-
import { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.
|
|
8
|
+
import { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
9
9
|
import {
|
|
10
10
|
DiscordConfig,
|
|
11
11
|
DiscordREST,
|
|
12
12
|
DiscordRESTMemoryLive,
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.
|
|
14
|
+
} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.17.0&bundle=false';
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
import {
|
|
16
|
+
import { Config, Effect, Redacted, Ref } from 'https://esm.sh/effect@3.17.0?bundle=false';
|
|
17
17
|
|
|
18
18
|
const MessageSchema = S.Struct({
|
|
19
19
|
id: ObjectId,
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import { S, defineFunction } from 'dxos:functions';
|
|
7
7
|
import {
|
|
8
|
+
FetchHttpClient,
|
|
8
9
|
HttpClient,
|
|
9
10
|
HttpClientRequest,
|
|
10
|
-
FetchHttpClient,
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
} from 'https://esm.sh/@effect/platform@0.
|
|
12
|
+
} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
import { Effect, Schedule } from 'https://esm.sh/effect@3.
|
|
14
|
+
import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
|
|
15
15
|
|
|
16
16
|
export default defineFunction({
|
|
17
17
|
description: 'Returns the exchange rate between two currencies.',
|
package/src/templates/forex.ts
CHANGED
package/src/templates/gmail.ts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { EchoObject, Filter, ObjectId, S, create, defineFunction } from 'dxos:functions';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import {
|
|
9
|
+
FetchHttpClient,
|
|
9
10
|
HttpClient,
|
|
10
11
|
HttpClientRequest,
|
|
11
|
-
FetchHttpClient,
|
|
12
12
|
// @ts-ignore
|
|
13
|
-
} from 'https://esm.sh/@effect/platform@0.
|
|
13
|
+
} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
import { format, subDays } from 'https://esm.sh/date-fns@3.3.1?bundle=false';
|
|
16
16
|
// @ts-ignore
|
|
17
|
-
import {
|
|
17
|
+
import { Chunk, Effect, Ref, Schedule, Stream, pipe } from 'https://esm.sh/effect@3.17.0?bundle=false';
|
|
18
18
|
|
|
19
19
|
export default defineFunction({
|
|
20
20
|
inputSchema: S.Struct({
|
|
@@ -98,7 +98,7 @@ export default defineFunction({
|
|
|
98
98
|
sender,
|
|
99
99
|
blocks: [
|
|
100
100
|
{
|
|
101
|
-
|
|
101
|
+
_tag: 'text',
|
|
102
102
|
text: Buffer.from(content, 'base64').toString('utf-8'),
|
|
103
103
|
},
|
|
104
104
|
],
|
|
@@ -174,57 +174,16 @@ const ActorSchema = S.Struct({
|
|
|
174
174
|
role: S.optional(ActorRole),
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
const
|
|
177
|
+
const Base = S.Struct({
|
|
178
178
|
pending: S.optional(S.Boolean),
|
|
179
179
|
});
|
|
180
|
-
type
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
S.
|
|
184
|
-
|
|
185
|
-
disposition: S.optional(S.String),
|
|
186
|
-
text: S.String,
|
|
187
|
-
}),
|
|
188
|
-
).pipe(S.mutable);
|
|
189
|
-
type TextContentBlock = S.Schema.Type<typeof TextContentBlock>;
|
|
190
|
-
const JsonContentBlock = S.extend(
|
|
191
|
-
AbstractContentBlock,
|
|
192
|
-
S.Struct({
|
|
193
|
-
type: S.Literal('json'),
|
|
194
|
-
disposition: S.optional(S.String),
|
|
195
|
-
data: S.String,
|
|
196
|
-
}),
|
|
197
|
-
).pipe(S.mutable);
|
|
198
|
-
type JsonContentBlock = S.Schema.Type<typeof JsonContentBlock>;
|
|
199
|
-
const Base64ImageSource = S.Struct({
|
|
200
|
-
type: S.Literal('base64'),
|
|
201
|
-
mediaType: S.String,
|
|
202
|
-
data: S.String,
|
|
180
|
+
type Base = S.Schema.Type<typeof Base>;
|
|
181
|
+
const Text = S.TaggedStruct('text', {
|
|
182
|
+
mimeType: S.optional(S.String),
|
|
183
|
+
text: S.String,
|
|
184
|
+
...Base.fields,
|
|
203
185
|
}).pipe(S.mutable);
|
|
204
|
-
|
|
205
|
-
type: S.Literal('http'),
|
|
206
|
-
url: S.String,
|
|
207
|
-
}).pipe(S.mutable);
|
|
208
|
-
const ImageSource = S.Union(Base64ImageSource, HttpImageSource);
|
|
209
|
-
type ImageSource = S.Schema.Type<typeof ImageSource>;
|
|
210
|
-
const ImageContentBlock = S.extend(
|
|
211
|
-
AbstractContentBlock,
|
|
212
|
-
S.Struct({
|
|
213
|
-
type: S.Literal('image'),
|
|
214
|
-
id: S.optional(S.String),
|
|
215
|
-
source: S.optional(ImageSource),
|
|
216
|
-
}),
|
|
217
|
-
).pipe(S.mutable);
|
|
218
|
-
type ImageContentBlock = S.Schema.Type<typeof ImageContentBlock>;
|
|
219
|
-
const ReferenceContentBlock = S.extend(
|
|
220
|
-
AbstractContentBlock,
|
|
221
|
-
S.Struct({
|
|
222
|
-
type: S.Literal('reference'),
|
|
223
|
-
reference: S.Any,
|
|
224
|
-
}),
|
|
225
|
-
).pipe(S.mutable);
|
|
226
|
-
type ReferenceContentBlock = S.Schema.Type<typeof ReferenceContentBlock>;
|
|
227
|
-
const MessageContentBlock = S.Union(TextContentBlock, JsonContentBlock, ImageContentBlock, ReferenceContentBlock);
|
|
186
|
+
interface Text extends S.Schema.Type<typeof Text> {}
|
|
228
187
|
|
|
229
188
|
const MessageType = S.Struct({
|
|
230
189
|
id: ObjectId,
|
|
@@ -234,7 +193,7 @@ const MessageType = S.Struct({
|
|
|
234
193
|
sender: ActorSchema.annotations({
|
|
235
194
|
description: 'Identity of the message sender.',
|
|
236
195
|
}),
|
|
237
|
-
blocks: S.Array(
|
|
196
|
+
blocks: S.Array(Text).annotations({
|
|
238
197
|
description: 'Contents of the message.',
|
|
239
198
|
}),
|
|
240
199
|
properties: S.optional(
|
package/src/translations.ts
CHANGED
package/src/util/deploy.ts
CHANGED
|
@@ -7,9 +7,8 @@ import { Obj, Ref } from '@dxos/echo';
|
|
|
7
7
|
import {
|
|
8
8
|
FunctionType,
|
|
9
9
|
type ScriptType,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
setUserFunctionUrlInMetadata,
|
|
10
|
+
getUserFunctionIdInMetadata,
|
|
11
|
+
setUserFunctionIdInMetadata,
|
|
13
12
|
} from '@dxos/functions';
|
|
14
13
|
import { Bundler } from '@dxos/functions/bundler';
|
|
15
14
|
import { incrementSemverPatch, uploadWorkerFunction } from '@dxos/functions/edge';
|
|
@@ -19,8 +18,8 @@ import { type Space } from '@dxos/react-client/echo';
|
|
|
19
18
|
import { updateFunctionMetadata } from './functions';
|
|
20
19
|
|
|
21
20
|
export const isScriptDeployed = ({ script, fn }: { script: ScriptType; fn: any }): boolean => {
|
|
22
|
-
const
|
|
23
|
-
return Boolean(
|
|
21
|
+
const existingFunctionId = fn && getUserFunctionIdInMetadata(Obj.getMeta(fn));
|
|
22
|
+
return Boolean(existingFunctionId) && !script.changed;
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
type DeployScriptProps = {
|
|
@@ -28,10 +27,10 @@ type DeployScriptProps = {
|
|
|
28
27
|
client: Client;
|
|
29
28
|
space: Space;
|
|
30
29
|
fn?: FunctionType;
|
|
31
|
-
|
|
30
|
+
existingFunctionId?: string;
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
type DeployScriptResult = { success: boolean; error?: Error;
|
|
33
|
+
type DeployScriptResult = { success: boolean; error?: Error; functionId?: string };
|
|
35
34
|
|
|
36
35
|
/**
|
|
37
36
|
* Deploy a script to a space, handling bundling and uploading to the FaaS infrastructure.
|
|
@@ -41,7 +40,7 @@ export const deployScript = async ({
|
|
|
41
40
|
client,
|
|
42
41
|
space,
|
|
43
42
|
fn,
|
|
44
|
-
|
|
43
|
+
existingFunctionId,
|
|
45
44
|
}: DeployScriptProps): Promise<DeployScriptResult> => {
|
|
46
45
|
const validationError = validateDeployInputs(script, space);
|
|
47
46
|
if (validationError) {
|
|
@@ -49,11 +48,10 @@ export const deployScript = async ({
|
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
throw error || new Error('Bundle creation failed');
|
|
51
|
+
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
52
|
+
const buildResult = await bundler.bundle({ source: script.source!.target!.content });
|
|
53
|
+
if ('error' in buildResult) {
|
|
54
|
+
throw buildResult.error || new Error('Bundle creation failed');
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
@@ -61,7 +59,8 @@ export const deployScript = async ({
|
|
|
61
59
|
ownerPublicKey: space.key,
|
|
62
60
|
version: fn ? incrementSemverPatch(fn.version) : '0.0.1',
|
|
63
61
|
functionId: existingFunctionId,
|
|
64
|
-
|
|
62
|
+
entryPoint: buildResult.entryPoint,
|
|
63
|
+
assets: { [buildResult.entryPoint]: buildResult.asset },
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
if (functionId === undefined || version === undefined) {
|
|
@@ -72,10 +71,9 @@ export const deployScript = async ({
|
|
|
72
71
|
script.changed = false;
|
|
73
72
|
updateFunctionMetadata(script, storedFunction, meta, functionId);
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
setUserFunctionUrlInMetadata(Obj.getMeta(storedFunction), functionUrl);
|
|
74
|
+
setUserFunctionIdInMetadata(Obj.getMeta(storedFunction), functionId);
|
|
77
75
|
|
|
78
|
-
return { success: true,
|
|
76
|
+
return { success: true, functionId };
|
|
79
77
|
} catch (err: any) {
|
|
80
78
|
log.catch(err);
|
|
81
79
|
return { success: false, error: err };
|
|
@@ -92,21 +90,6 @@ const validateDeployInputs = (script: ScriptType, space: Space): Error | null =>
|
|
|
92
90
|
return null;
|
|
93
91
|
};
|
|
94
92
|
|
|
95
|
-
const extractFunctionId = (functionUrl?: string): string | undefined => {
|
|
96
|
-
return functionUrl?.split('/').at(-1);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const bundleScript = async (source: string): Promise<{ bundle?: string; error?: Error }> => {
|
|
100
|
-
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
101
|
-
const buildResult = await bundler.bundle({ source });
|
|
102
|
-
|
|
103
|
-
if (buildResult.error || !buildResult.bundle) {
|
|
104
|
-
return { error: buildResult.error || new Error('Bundle creation failed') };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { bundle: buildResult.bundle };
|
|
108
|
-
};
|
|
109
|
-
|
|
110
93
|
const createOrUpdateFunctionInSpace = (
|
|
111
94
|
space: Space,
|
|
112
95
|
fn: FunctionType | undefined,
|
|
@@ -115,9 +98,13 @@ const createOrUpdateFunctionInSpace = (
|
|
|
115
98
|
version: string,
|
|
116
99
|
): FunctionType => {
|
|
117
100
|
if (fn) {
|
|
101
|
+
fn.name = script.name ?? 'New Function';
|
|
118
102
|
fn.version = version;
|
|
119
103
|
return fn;
|
|
120
104
|
} else {
|
|
121
|
-
|
|
105
|
+
const fn = Obj.make(FunctionType, { name: script.name ?? 'New Function', version, source: Ref.make(script) });
|
|
106
|
+
space.db.add(fn);
|
|
107
|
+
setUserFunctionIdInMetadata(Obj.getMeta(fn), functionId);
|
|
108
|
+
return fn;
|
|
122
109
|
}
|
|
123
110
|
};
|
package/src/util/functions.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type ScriptType, getInvocationUrl,
|
|
5
|
+
import { type ScriptType, getInvocationUrl, getUserFunctionIdInMetadata } from '@dxos/functions';
|
|
6
6
|
import { log } from '@dxos/log';
|
|
7
7
|
import { getMeta, getSpace } from '@dxos/react-client/echo';
|
|
8
8
|
|
|
@@ -19,13 +19,13 @@ export const getFunctionUrl = ({
|
|
|
19
19
|
edgeUrl: string;
|
|
20
20
|
}): string | undefined => {
|
|
21
21
|
const space = getSpace(script);
|
|
22
|
-
const
|
|
22
|
+
const existingFunctionId = fn && getUserFunctionIdInMetadata(getMeta(fn));
|
|
23
23
|
|
|
24
|
-
if (!
|
|
24
|
+
if (!existingFunctionId) {
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return getInvocationUrl(
|
|
28
|
+
return getInvocationUrl(existingFunctionId, edgeUrl, {
|
|
29
29
|
spaceId: space?.id,
|
|
30
30
|
});
|
|
31
31
|
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptToolbar/ScriptToolbar.tsx", "../../../src/components/TypescriptEditor/TypescriptEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useMemo } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { createDocAccessor, getSpace } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { createDataExtensions, listener, stackItemContentEditorClassNames } from '@dxos/react-ui-editor';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { ScriptToolbar } from './ScriptToolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { useDeployState, useToolbarState } from '../hooks';\nimport { type ScriptSettingsProps } from '../types';\n\nexport type ScriptEditorProps = {\n role: string;\n script: ScriptType;\n settings?: ScriptSettingsProps;\n} & Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptContainer = ({ role, script, settings = { editorInputMode: 'vscode' }, env }: ScriptEditorProps) => {\n const identity = useIdentity();\n const space = getSpace(script);\n const state = useToolbarState();\n useDeployState({ state, script });\n\n const extensions = useMemo(\n () =>\n script.source.target\n ? [\n listener({\n onChange: (text) => {\n if (script.source.target?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: createDocAccessor(script.source.target, ['content']),\n space,\n identity,\n }),\n ]\n : [],\n [identity, space, script, script.source.target],\n );\n\n return (\n <StackItem.Content toolbar>\n <ScriptToolbar state={state} role={role} script={script} />\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.target?.content}\n extensions={extensions}\n classNames={stackItemContentEditorClassNames(role)}\n inputMode={settings.editorInputMode}\n toolbar\n />\n </StackItem.Content>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Rx } from '@effect-rx/rx-react';\nimport React, { useMemo } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { ElevationProvider, useTranslation, type ThemedClassName } from '@dxos/react-ui';\nimport { createGapSeparator, MenuProvider, rxFromSignal, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';\n\nimport {\n type CreateDeployOptions,\n type ScriptToolbarState,\n createDeploy,\n createFormat,\n createTemplateSelect,\n useDeployDeps,\n} from '../../hooks';\nimport { SCRIPT_PLUGIN } from '../../meta';\n\nconst createToolbar = ({ state, script, ...options }: CreateDeployOptions) =>\n Rx.make((get) =>\n get(\n rxFromSignal(() => {\n const templateSelect = createTemplateSelect(script);\n const format = createFormat(script);\n const gap = createGapSeparator();\n const deploy = createDeploy({ state, script, ...options });\n return {\n nodes: [...templateSelect.nodes, ...format.nodes, ...gap.nodes, ...deploy.nodes],\n edges: [...templateSelect.edges, ...format.edges, ...gap.edges, ...deploy.edges],\n };\n }),\n ),\n );\n\nexport type ScriptToolbarProps = ThemedClassName<{\n role?: string;\n script: ScriptType;\n state: ScriptToolbarState;\n}>;\n\nexport const ScriptToolbar = ({ script, role, state, classNames }: ScriptToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const options = useDeployDeps({ script });\n const toolbarCreator = useMemo(() => createToolbar({ state, script, t, ...options }), [state, script, options, t]);\n const menu = useMenuActions(toolbarCreator);\n\n return (\n <ElevationProvider elevation={role === 'section' ? 'positioned' : 'base'}>\n <MenuProvider {...menu} attendableId={fullyQualifiedId(script)}>\n <ToolbarMenu classNames={classNames} />\n </MenuProvider>\n </ElevationProvider>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle } from '@codemirror/language';\nimport { lintKeymap } from '@codemirror/lint';\nimport { Prec } from '@codemirror/state';\nimport { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';\nimport { keymap } from '@codemirror/view';\nimport { tags } from '@lezer/highlight';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { continueKeymap } from '@valtown/codemirror-continue';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover, type HoverInfo } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { type ThemedClassName, type ThemeMode, useThemeContext } from '@dxos/react-ui';\nimport {\n type EditorInputMode,\n InputModeExtensions,\n type UseTextEditorProps,\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n folding,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = ThemedClassName<\n {\n id: string;\n inputMode?: EditorInputMode;\n toolbar?: boolean;\n env?: VirtualTypeScriptEnvironment;\n } & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>\n>;\n\nexport const TypescriptEditor = ({\n classNames,\n id,\n inputMode = 'vscode',\n toolbar,\n env,\n initialValue,\n extensions,\n scrollTo,\n selection,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n selection,\n scrollTo,\n extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n monospace: true,\n scrollPastEnd: true,\n }),\n createThemeExtensions({ themeMode, syntaxHighlighting: true }),\n InputModeExtensions[inputMode],\n folding(),\n // Continues block comments when pressing Enter.\n Prec.high(keymap.of(continueKeymap)),\n\n // TODO(burdon): Factor out.\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : undefined }),\n keymap.of(lintKeymap),\n env && [\n tsFacet.of({ env, path: `/src/${id}.ts` }),\n tsSync(),\n tsLinter(),\n tsHover({ renderTooltip: createTooltipRenderer(themeMode) }),\n ],\n ].filter(isNonNullable),\n }),\n [id, extensions, themeMode, inputMode, selection, scrollTo],\n );\n\n return (\n <div\n ref={parentRef}\n data-toolbar={toolbar ? 'enabled' : 'disabled'}\n className={mx(classNames)}\n {...focusAttributes}\n />\n );\n};\n\nconst createTooltipRenderer = (themeMode: ThemeMode) => {\n const theme = themeMode === 'dark' ? oneDarkHighlightStyle : defaultHighlightStyle;\n\n const classFromKind = (_kind: string) => {\n // E.g., localName, methodName, parameterName, etc.\n const kind = _kind.endsWith('Name') ? 'name' : _kind;\n const validTag = kind in tags;\n if (!validTag) {\n return '';\n }\n\n const tag = tags[kind as keyof typeof tags];\n if (typeof tag === 'function') {\n return '';\n }\n\n return theme.style([tag]) ?? '';\n };\n\n return (info: HoverInfo) => {\n const div = document.createElement('div');\n div.className = 'p-1 rounded border border-separator bg-baseSurface xs:max-w-80 max-w-lg';\n\n if (info.quickInfo?.displayParts) {\n for (const part of info.quickInfo.displayParts) {\n const span = div.appendChild(document.createElement('span'));\n span.className = classFromKind(part.kind);\n span.innerText = part.text;\n }\n }\n\n return { dom: div };\n };\n};\n\nexport default TypescriptEditor;\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["React", "useMemo", "createDocAccessor", "getSpace", "useIdentity", "createDataExtensions", "listener", "stackItemContentEditorClassNames", "StackItem", "Rx", "React", "useMemo", "fullyQualifiedId", "ElevationProvider", "useTranslation", "createGapSeparator", "MenuProvider", "rxFromSignal", "ToolbarMenu", "useMenuActions", "createToolbar", "state", "script", "options", "Rx", "make", "get", "rxFromSignal", "templateSelect", "createTemplateSelect", "format", "createFormat", "gap", "createGapSeparator", "deploy", "createDeploy", "nodes", "edges", "ScriptToolbar", "role", "classNames", "t", "useTranslation", "SCRIPT_PLUGIN", "useDeployDeps", "toolbarCreator", "useMemo", "menu", "useMenuActions", "ElevationProvider", "elevation", "MenuProvider", "attendableId", "fullyQualifiedId", "ToolbarMenu", "javascript", "defaultHighlightStyle", "lintKeymap", "Prec", "oneDarkHighlightStyle", "keymap", "tags", "continueKeymap", "tsSync", "tsFacet", "tsLinter", "tsAutocomplete", "tsHover", "React", "useThemeContext", "InputModeExtensions", "autocomplete", "createBasicExtensions", "createThemeExtensions", "folding", "useTextEditor", "mx", "isNonNullable", "TypescriptEditor", "classNames", "id", "inputMode", "toolbar", "env", "initialValue", "extensions", "scrollTo", "selection", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "monospace", "scrollPastEnd", "createThemeExtensions", "syntaxHighlighting", "InputModeExtensions", "folding", "Prec", "high", "keymap", "of", "continueKeymap", "javascript", "typescript", "autocomplete", "override", "tsAutocomplete", "undefined", "lintKeymap", "tsFacet", "path", "tsSync", "tsLinter", "tsHover", "renderTooltip", "createTooltipRenderer", "filter", "isNonNullable", "React", "div", "ref", "data-toolbar", "className", "mx", "theme", "oneDarkHighlightStyle", "defaultHighlightStyle", "classFromKind", "_kind", "kind", "endsWith", "validTag", "tags", "tag", "style", "info", "document", "createElement", "quickInfo", "displayParts", "part", "span", "appendChild", "innerText", "text", "dom", "ScriptContainer", "role", "script", "settings", "editorInputMode", "env", "identity", "useIdentity", "space", "getSpace", "state", "useToolbarState", "useDeployState", "extensions", "useMemo", "source", "target", "listener", "onChange", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "React", "StackItem", "Content", "toolbar", "ScriptToolbar", "TypescriptEditor", "initialValue", "classNames", "stackItemContentEditorClassNames", "inputMode"]
|
|
7
|
-
}
|