@dxos/plugin-script 0.7.5-main.9d26e3a → 0.7.5-main.e9bb01b
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-KZVZMZE6.mjs} +3 -3
- package/dist/lib/browser/ScriptContainer-AERJBGYK.mjs +685 -0
- package/dist/lib/browser/ScriptContainer-AERJBGYK.mjs.map +7 -0
- package/dist/lib/browser/chunk-ABNZIPST.mjs +15 -0
- package/dist/lib/browser/chunk-ABNZIPST.mjs.map +7 -0
- package/dist/lib/browser/chunk-ESPJMGXJ.mjs +21 -0
- package/dist/lib/browser/chunk-ESPJMGXJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-J7CBIZI2.mjs +224 -0
- package/dist/lib/browser/chunk-J7CBIZI2.mjs.map +7 -0
- package/dist/lib/browser/chunk-NFPF4OIU.mjs +40 -0
- package/dist/lib/browser/chunk-NFPF4OIU.mjs.map +7 -0
- package/dist/lib/browser/chunk-REL2R7SB.mjs +52 -0
- package/dist/lib/browser/chunk-REL2R7SB.mjs.map +7 -0
- package/dist/lib/browser/{chunk-4UTRJLQ3.mjs → chunk-SDHKTS6H.mjs} +2 -51
- package/dist/lib/browser/{chunk-4UTRJLQ3.mjs.map → chunk-SDHKTS6H.mjs.map} +4 -4
- package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-Y4CVWFVS.mjs} +2 -2
- package/dist/lib/browser/compiler-4QD7VFZX.mjs +84 -0
- package/dist/lib/browser/compiler-4QD7VFZX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +112 -288
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-YABC4JRJ.mjs +45 -0
- package/dist/lib/browser/intent-resolver-YABC4JRJ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-FRQIIYKG.mjs +65 -0
- package/dist/lib/browser/react-surface-FRQIIYKG.mjs.map +7 -0
- package/dist/lib/browser/settings-S4MGGM4D.mjs +24 -0
- package/dist/lib/browser/settings-S4MGGM4D.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +6 -4
- package/dist/lib/node/{AutomationPanel-5CJEF4MI.cjs → AutomationPanel-6QSV7ZYK.cjs} +8 -8
- package/dist/lib/node/ScriptContainer-DOAQ6KOE.cjs +689 -0
- package/dist/lib/node/ScriptContainer-DOAQ6KOE.cjs.map +7 -0
- package/dist/lib/node/chunk-63C2KSD6.cjs +252 -0
- package/dist/lib/node/chunk-63C2KSD6.cjs.map +7 -0
- package/dist/lib/node/{chunk-PK3OQP5L.cjs → chunk-6M2VRFBC.cjs} +26 -11
- package/dist/lib/node/chunk-6M2VRFBC.cjs.map +7 -0
- package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-CZVVFUVL.cjs} +6 -6
- package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-HU2JXUXI.cjs} +11 -8
- package/dist/lib/node/chunk-HU2JXUXI.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → chunk-RZHY5LAR.cjs} +12 -8
- package/dist/lib/node/chunk-RZHY5LAR.cjs.map +7 -0
- package/dist/lib/node/{chunk-WPP65EYS.cjs → chunk-T4TXCRN5.cjs} +6 -44
- package/dist/lib/node/chunk-T4TXCRN5.cjs.map +7 -0
- package/dist/lib/node/chunk-TJ4BTPOS.cjs +64 -0
- package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +7 -0
- package/dist/lib/node/compiler-Q3EXWKV5.cjs +104 -0
- package/dist/lib/node/compiler-Q3EXWKV5.cjs.map +7 -0
- package/dist/lib/node/index.cjs +105 -276
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-7HI2CDGB.cjs +59 -0
- package/dist/lib/node/intent-resolver-7HI2CDGB.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-IKONODLG.cjs +84 -0
- package/dist/lib/node/react-surface-IKONODLG.cjs.map +7 -0
- package/dist/lib/node/settings-Q5XIA4LZ.cjs +38 -0
- package/dist/lib/node/settings-Q5XIA4LZ.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-EZQSGJLS.mjs} +3 -3
- package/dist/lib/node-esm/ScriptContainer-HE5QPPFZ.mjs +686 -0
- package/dist/lib/node-esm/ScriptContainer-HE5QPPFZ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-3YOO5E2D.mjs +16 -0
- package/dist/lib/node-esm/chunk-3YOO5E2D.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5D2AXTAW.mjs +41 -0
- package/dist/lib/node-esm/chunk-5D2AXTAW.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-77LRZF2W.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-EOBGHKNT.mjs} +7 -4
- package/dist/lib/node-esm/chunk-EOBGHKNT.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-4SRPREUK.mjs → chunk-G76M6O46.mjs} +2 -51
- package/dist/lib/node-esm/{chunk-4SRPREUK.mjs.map → chunk-G76M6O46.mjs.map} +4 -4
- package/dist/lib/node-esm/chunk-JJZYWSD7.mjs +54 -0
- package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UWHMEJYW.mjs +225 -0
- package/dist/lib/node-esm/chunk-UWHMEJYW.mjs.map +7 -0
- package/dist/lib/node-esm/compiler-KJEIPDZ6.mjs +85 -0
- package/dist/lib/node-esm/compiler-KJEIPDZ6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +112 -288
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-KG7I6JJA.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-KG7I6JJA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-YA7WIRAM.mjs +66 -0
- package/dist/lib/node-esm/react-surface-YA7WIRAM.mjs.map +7 -0
- package/dist/lib/node-esm/settings-NZXHNIQ3.mjs +25 -0
- package/dist/lib/node-esm/settings-NZXHNIQ3.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/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 +6 -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/ScriptContainer.d.ts +10 -2
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +11 -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/deploy.d.ts +48 -0
- package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/format.d.ts +25 -0
- package/dist/types/src/components/ScriptToolbar/format.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/ScriptToolbar/templateSelect.d.ts +31 -0
- package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts +14 -0
- package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/view.d.ts +33 -0
- package/dist/types/src/components/ScriptToolbar/view.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -2
- 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 +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -4
- 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/email.d.ts +2 -1
- package/dist/types/src/templates/email.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 +91 -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 +55 -91
- package/src/bundler/bundler.test.ts +4 -3
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/compiler.ts +33 -0
- package/src/capabilities/index.ts +12 -0
- package/src/capabilities/intent-resolver.ts +46 -0
- package/src/capabilities/react-surface.tsx +53 -0
- package/src/capabilities/settings.ts +14 -0
- package/src/components/ScriptContainer.tsx +64 -9
- package/src/components/ScriptSettings/ScriptSettings.tsx +28 -4
- package/src/components/ScriptSettingsPanel.tsx +124 -50
- package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +51 -0
- package/src/components/ScriptToolbar/deploy.ts +157 -0
- package/src/components/ScriptToolbar/format.ts +47 -0
- package/src/components/{Toolbar → ScriptToolbar}/index.ts +1 -1
- package/src/components/ScriptToolbar/templateSelect.ts +64 -0
- package/src/components/ScriptToolbar/useToolbarAction.ts +54 -0
- package/src/components/ScriptToolbar/useToolbarState.ts +16 -0
- package/src/components/ScriptToolbar/view.ts +52 -0
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +73 -8
- package/src/index.ts +2 -6
- package/src/meta.ts +3 -2
- package/src/templates/email.ts +26 -23
- package/src/{templates.ts → templates/index.ts} +5 -5
- package/src/translations.ts +21 -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-C7VBULMK.mjs +0 -18
- package/dist/lib/browser/chunk-C7VBULMK.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-6LYX73ZT.cjs.map +0 -7
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +0 -7
- 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-H6BBLQ5Q.mjs +0 -27
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.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/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/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/dist/lib/browser/{AutomationPanel-RFQAQ7NF.mjs.map → AutomationPanel-KZVZMZE6.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-K7KY6YMG.mjs.map → chunk-Y4CVWFVS.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-5CJEF4MI.cjs.map → AutomationPanel-6QSV7ZYK.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-4INUJLXL.cjs.map → chunk-CZVVFUVL.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-7Y6REBNJ.mjs.map → AutomationPanel-EZQSGJLS.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs.map → chunk-77LRZF2W.mjs.map} +0 -0
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
|
-
import { type Meta } from '@storybook/react';
|
|
8
|
-
import React, { useMemo } from 'react';
|
|
9
|
-
|
|
10
|
-
import { ScriptType } from '@dxos/functions';
|
|
11
|
-
import { TextType } from '@dxos/plugin-markdown/types';
|
|
12
|
-
import { create, createObject, makeRef } from '@dxos/react-client/echo';
|
|
13
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
14
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
15
|
-
|
|
16
|
-
import { ScriptBlock } from './ScriptBlock';
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import mainUrl from '../FrameContainer/frame?url';
|
|
19
|
-
|
|
20
|
-
const typename = 'example.com/type/contact';
|
|
21
|
-
|
|
22
|
-
const code = [
|
|
23
|
-
"import { Filter, useQuery, useSpaces} from '@dxos/react-client/echo';",
|
|
24
|
-
"import { Chart, Explorer, Globe } from '@dxos/plugin-explorer';",
|
|
25
|
-
'',
|
|
26
|
-
'export default () => {',
|
|
27
|
-
' const spaces = useSpaces();',
|
|
28
|
-
' const space = spaces[1]',
|
|
29
|
-
` const objects = useQuery(space, Filter.typename('${typename}'));`,
|
|
30
|
-
' return <Chart items={objects} accessor={object => ({ x: object.lat, y: object.lng })} />',
|
|
31
|
-
'}',
|
|
32
|
-
].join('\n');
|
|
33
|
-
|
|
34
|
-
const DefaultStory = () => {
|
|
35
|
-
// TODO(burdon): Review what's the right way to create automerge-backed objects.
|
|
36
|
-
const object = useMemo(
|
|
37
|
-
() => createObject(create(ScriptType, { source: makeRef(create(TextType, { content: code })) })),
|
|
38
|
-
[],
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// TODO(dmaretskyi): Not sure how to provide `containerUrl` here since the html now lives in composer-app.
|
|
42
|
-
// TODO(burdon): Normalize html/frame.tsx with composer-app to test locally.
|
|
43
|
-
return <ScriptBlock script={object} containerUrl={mainUrl} />;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const Default = {};
|
|
47
|
-
|
|
48
|
-
const meta: Meta = {
|
|
49
|
-
title: 'plugins/plugin-script/ScriptBlock',
|
|
50
|
-
component: ScriptBlock,
|
|
51
|
-
render: DefaultStory,
|
|
52
|
-
decorators: [withClientProvider({ createSpace: true }), withTheme, withLayout({ fullscreen: true, tooltips: true })],
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export default meta;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { type ScriptType } from '@dxos/functions';
|
|
10
|
-
import { createDocAccessor, DocAccessor } from '@dxos/react-client/echo';
|
|
11
|
-
import { Toolbar, Button, Icon } from '@dxos/react-ui';
|
|
12
|
-
|
|
13
|
-
import { Bundler, type BundlerResult, initializeBundler } from '../../bundler';
|
|
14
|
-
import { FrameContainer } from '../FrameContainer';
|
|
15
|
-
import { ScriptEditor } from '../ScriptEditor';
|
|
16
|
-
|
|
17
|
-
// Keep in sync with packages/apps/composer-app/script-frame/main.tsx .
|
|
18
|
-
const PROVIDED_MODULES = [
|
|
19
|
-
'react',
|
|
20
|
-
'react-dom/client',
|
|
21
|
-
'@dxos/client',
|
|
22
|
-
'@dxos/react-client',
|
|
23
|
-
'@dxos/react-client/echo',
|
|
24
|
-
'@dxos/plugin-explorer',
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export type ScriptBlockProps = {
|
|
28
|
-
script: ScriptType;
|
|
29
|
-
hideSelector?: boolean;
|
|
30
|
-
|
|
31
|
-
// Url to the page used to host the script in the iframe.
|
|
32
|
-
containerUrl: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @deprecated
|
|
37
|
-
*/
|
|
38
|
-
// TODO(burdon): Cache compiled results in context.
|
|
39
|
-
export const ScriptBlock = ({ script, hideSelector, containerUrl }: ScriptBlockProps) => {
|
|
40
|
-
const source = useMemo(() => script.source && createDocAccessor(script.source.target!, ['content']), [script.source]);
|
|
41
|
-
const [result, setResult] = useState<BundlerResult>();
|
|
42
|
-
const bundler = useMemo(
|
|
43
|
-
() => new Bundler({ platform: 'browser', sandboxedModules: PROVIDED_MODULES, remoteModules: {} }),
|
|
44
|
-
[],
|
|
45
|
-
);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
// TODO(burdon): Create useCompiler hook (with initialization).
|
|
48
|
-
void initializeBundler({ wasmUrl });
|
|
49
|
-
}, []);
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
// TODO(burdon): Throttle and listen for update.
|
|
52
|
-
const t = setTimeout(async () => {
|
|
53
|
-
if (!source) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const result = await bundler.bundle(DocAccessor.getValue(source));
|
|
58
|
-
setResult(result);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return () => clearTimeout(t);
|
|
62
|
-
}, [source]);
|
|
63
|
-
|
|
64
|
-
const handleExec = useCallback(
|
|
65
|
-
async (auto = true) => {
|
|
66
|
-
if (!source) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const result = await bundler.bundle(DocAccessor.getValue(source));
|
|
70
|
-
setResult(result);
|
|
71
|
-
},
|
|
72
|
-
[source],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<div className='flex flex-col grow overflow-hidden'>
|
|
77
|
-
{!hideSelector && (
|
|
78
|
-
<Toolbar.Root>
|
|
79
|
-
<div className='grow' />
|
|
80
|
-
{result?.bundle && !result?.error && (
|
|
81
|
-
<div title={String(result.error)}>
|
|
82
|
-
<Icon icon='ph--check--regular' size={5} classNames='text-green-500' />
|
|
83
|
-
</div>
|
|
84
|
-
)}
|
|
85
|
-
{result?.error && (
|
|
86
|
-
<div title={String(result.error)}>
|
|
87
|
-
<Icon icon='ph--warning--regular' size={5} classNames='text-orange-500' />
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
<Button variant='ghost' onClick={() => handleExec()}>
|
|
91
|
-
<Icon icon='ph--play--regular' size={5} />
|
|
92
|
-
</Button>
|
|
93
|
-
</Toolbar.Root>
|
|
94
|
-
)}
|
|
95
|
-
|
|
96
|
-
<div className='flex'>
|
|
97
|
-
<ScriptEditor script={script} />
|
|
98
|
-
{result && <FrameContainer key={script.id} result={result} containerUrl={containerUrl} />}
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 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 React, { useCallback, useMemo, useState } from 'react';
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
FUNCTIONS_PRESET_META_KEY,
|
|
12
|
-
FunctionType,
|
|
13
|
-
type ScriptType,
|
|
14
|
-
getInvocationUrl,
|
|
15
|
-
getUserFunctionUrlInMetadata,
|
|
16
|
-
setUserFunctionUrlInMetadata,
|
|
17
|
-
uploadWorkerFunction,
|
|
18
|
-
incrementSemverPatch,
|
|
19
|
-
} from '@dxos/functions';
|
|
20
|
-
import { log } from '@dxos/log';
|
|
21
|
-
import { useClient } from '@dxos/react-client';
|
|
22
|
-
import { create, createDocAccessor, Filter, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
|
|
23
|
-
import { useIdentity } from '@dxos/react-client/halo';
|
|
24
|
-
import { useTranslation, type ThemedClassName } from '@dxos/react-ui';
|
|
25
|
-
import { createDataExtensions, listener } from '@dxos/react-ui-editor';
|
|
26
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
27
|
-
|
|
28
|
-
import { DebugPanel } from './DebugPanel';
|
|
29
|
-
import { type TemplateSelectProps, Toolbar, type ViewType } from './Toolbar';
|
|
30
|
-
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
31
|
-
import { Bundler } from '../bundler';
|
|
32
|
-
import { SCRIPT_PLUGIN } from '../meta';
|
|
33
|
-
import { templates } from '../templates';
|
|
34
|
-
|
|
35
|
-
export type ScriptEditorProps = ThemedClassName<{
|
|
36
|
-
script: ScriptType;
|
|
37
|
-
}> &
|
|
38
|
-
Pick<TypescriptEditorProps, 'env'>;
|
|
39
|
-
|
|
40
|
-
export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) => {
|
|
41
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
42
|
-
const client = useClient();
|
|
43
|
-
const identity = useIdentity();
|
|
44
|
-
const space = getSpace(script);
|
|
45
|
-
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));
|
|
46
|
-
|
|
47
|
-
const extensions = useMemo(
|
|
48
|
-
() => [
|
|
49
|
-
listener({
|
|
50
|
-
onChange: (text) => {
|
|
51
|
-
if (script.source.target && script.source.target.content !== text) {
|
|
52
|
-
script.changed = true;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
createDataExtensions({
|
|
57
|
-
id: script.id,
|
|
58
|
-
text: script.source.target && createDocAccessor(script.source.target, ['content']),
|
|
59
|
-
space,
|
|
60
|
-
identity,
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
63
|
-
[script, script.source.target, space, identity],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const [view, setView] = useState<ViewType>('editor');
|
|
67
|
-
const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
68
|
-
const [error, setError] = useState<string>();
|
|
69
|
-
|
|
70
|
-
const handleFormat = useCallback(async () => {
|
|
71
|
-
if (!script.source) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
script.source.target!.content = await format(script.source.target!.content, {
|
|
77
|
-
parser: 'typescript',
|
|
78
|
-
plugins: [prettierPluginEstree, prettierPluginTypescript],
|
|
79
|
-
semi: true,
|
|
80
|
-
singleQuote: true,
|
|
81
|
-
});
|
|
82
|
-
} catch (err: any) {
|
|
83
|
-
// TODO(wittjosiah): Show error in UI.
|
|
84
|
-
log.catch(err);
|
|
85
|
-
}
|
|
86
|
-
}, [script.source]);
|
|
87
|
-
|
|
88
|
-
const handleTemplateChange: TemplateSelectProps['onTemplateSelect'] = (id) => {
|
|
89
|
-
const template = templates.find((template) => template.id === id);
|
|
90
|
-
if (template) {
|
|
91
|
-
script.name = template.name;
|
|
92
|
-
script.source!.target!.content = template.source;
|
|
93
|
-
const metaKeys = getMeta(script).keys;
|
|
94
|
-
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
95
|
-
if (oldPresetIndex >= 0) {
|
|
96
|
-
metaKeys.splice(oldPresetIndex, 1);
|
|
97
|
-
}
|
|
98
|
-
if (template.presetId) {
|
|
99
|
-
metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const handleDeploy = useCallback(async () => {
|
|
105
|
-
if (!script.source || !identity || !space) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
setError(undefined);
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
|
|
113
|
-
|
|
114
|
-
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
115
|
-
const buildResult = await bundler.bundle(script.source.target!.content);
|
|
116
|
-
if (buildResult.error || !buildResult.bundle) {
|
|
117
|
-
throw buildResult.error;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
121
|
-
client,
|
|
122
|
-
spaceId: space.id,
|
|
123
|
-
version: fn ? incrementSemverPatch(fn.version) : '0.0.1',
|
|
124
|
-
functionId: existingFunctionId,
|
|
125
|
-
source: buildResult.bundle,
|
|
126
|
-
});
|
|
127
|
-
if (functionId === undefined || version === undefined) {
|
|
128
|
-
throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
log.info('function uploaded', { functionId, version });
|
|
132
|
-
if (fn) {
|
|
133
|
-
fn.version = version;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const deployedFunction =
|
|
137
|
-
fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
|
|
138
|
-
|
|
139
|
-
script.changed = false;
|
|
140
|
-
|
|
141
|
-
if (meta.inputSchema) {
|
|
142
|
-
deployedFunction.inputSchema = meta.inputSchema;
|
|
143
|
-
} else {
|
|
144
|
-
log.verbose('no input schema in function metadata', { functionId });
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
|
|
148
|
-
|
|
149
|
-
setView('split');
|
|
150
|
-
} catch (err: any) {
|
|
151
|
-
log.catch(err);
|
|
152
|
-
setError(t('upload failed label'));
|
|
153
|
-
}
|
|
154
|
-
}, [fn, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);
|
|
155
|
-
|
|
156
|
-
const functionUrl = useMemo(() => {
|
|
157
|
-
if (!existingFunctionUrl) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
162
|
-
spaceId: space?.id,
|
|
163
|
-
});
|
|
164
|
-
}, [existingFunctionUrl, space]);
|
|
165
|
-
|
|
166
|
-
return (
|
|
167
|
-
<div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>
|
|
168
|
-
<Toolbar
|
|
169
|
-
deployed={Boolean(existingFunctionUrl) && !script.changed}
|
|
170
|
-
functionUrl={functionUrl}
|
|
171
|
-
error={error}
|
|
172
|
-
view={view}
|
|
173
|
-
templates={templates}
|
|
174
|
-
onDeploy={handleDeploy}
|
|
175
|
-
onFormat={handleFormat}
|
|
176
|
-
onViewChange={setView}
|
|
177
|
-
onTemplateSelect={handleTemplateChange}
|
|
178
|
-
/>
|
|
179
|
-
|
|
180
|
-
{view !== 'preview' && (
|
|
181
|
-
<TypescriptEditor
|
|
182
|
-
id={script.id}
|
|
183
|
-
env={env}
|
|
184
|
-
initialValue={script.source?.target?.content}
|
|
185
|
-
extensions={extensions}
|
|
186
|
-
className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'
|
|
187
|
-
/>
|
|
188
|
-
)}
|
|
189
|
-
|
|
190
|
-
{view !== 'editor' && <DebugPanel functionUrl={functionUrl} />}
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
ElevationProvider,
|
|
9
|
-
Icon,
|
|
10
|
-
Select,
|
|
11
|
-
type ThemedClassName,
|
|
12
|
-
ToggleGroup,
|
|
13
|
-
ToggleGroupItem,
|
|
14
|
-
type ToolbarButtonProps,
|
|
15
|
-
Toolbar as NaturalToolbar,
|
|
16
|
-
Tooltip,
|
|
17
|
-
useTranslation,
|
|
18
|
-
} from '@dxos/react-ui';
|
|
19
|
-
|
|
20
|
-
import { SCRIPT_PLUGIN } from '../../meta';
|
|
21
|
-
import { type Template } from '../../templates';
|
|
22
|
-
|
|
23
|
-
export type ToolbarProps = ThemedClassName<
|
|
24
|
-
{
|
|
25
|
-
deployed?: boolean;
|
|
26
|
-
error?: string;
|
|
27
|
-
functionUrl?: string;
|
|
28
|
-
onDeploy?: () => Promise<void>;
|
|
29
|
-
onFormat?: () => Promise<void>;
|
|
30
|
-
} & TemplateSelectProps &
|
|
31
|
-
ViewSelectorProps
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export const Toolbar = ({
|
|
35
|
-
classNames,
|
|
36
|
-
deployed,
|
|
37
|
-
error,
|
|
38
|
-
functionUrl,
|
|
39
|
-
view,
|
|
40
|
-
templates,
|
|
41
|
-
onDeploy,
|
|
42
|
-
onFormat,
|
|
43
|
-
onViewChange,
|
|
44
|
-
onTemplateSelect,
|
|
45
|
-
}: ToolbarProps) => {
|
|
46
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
47
|
-
const [pending, setPending] = useState(false);
|
|
48
|
-
|
|
49
|
-
const handleCopyLink = async () => {
|
|
50
|
-
if (!functionUrl) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await navigator.clipboard.writeText(functionUrl);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleDeploy = async () => {
|
|
58
|
-
if (!pending) {
|
|
59
|
-
setPending(true);
|
|
60
|
-
await onDeploy?.();
|
|
61
|
-
setPending(false);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// TODO(burdon): Factor out common toolbar components with sheet/editor?
|
|
66
|
-
return (
|
|
67
|
-
<ElevationProvider elevation='positioned'>
|
|
68
|
-
<NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>
|
|
69
|
-
{templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}
|
|
70
|
-
{onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}
|
|
71
|
-
|
|
72
|
-
<div role='separator' className='grow' />
|
|
73
|
-
|
|
74
|
-
{error ? (
|
|
75
|
-
<Tooltip.Root>
|
|
76
|
-
<Tooltip.Trigger>
|
|
77
|
-
<Icon icon='ph--warning-circle--regular' size={4} />
|
|
78
|
-
</Tooltip.Trigger>
|
|
79
|
-
<Tooltip.Portal>
|
|
80
|
-
<Tooltip.Content>
|
|
81
|
-
<Tooltip.Arrow />
|
|
82
|
-
{error}
|
|
83
|
-
</Tooltip.Content>
|
|
84
|
-
</Tooltip.Portal>
|
|
85
|
-
</Tooltip.Root>
|
|
86
|
-
) : null}
|
|
87
|
-
|
|
88
|
-
{functionUrl && deployed && (
|
|
89
|
-
<ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />
|
|
90
|
-
)}
|
|
91
|
-
|
|
92
|
-
{onDeploy && (
|
|
93
|
-
<ToolbarIconButton
|
|
94
|
-
icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}
|
|
95
|
-
classNames={[pending && 'animate-spin']}
|
|
96
|
-
text={pending ? t('pending label') : t('deploy label')}
|
|
97
|
-
onClick={handleDeploy}
|
|
98
|
-
/>
|
|
99
|
-
)}
|
|
100
|
-
|
|
101
|
-
<ViewSelector view={view} onViewChange={onViewChange} />
|
|
102
|
-
</NaturalToolbar.Root>
|
|
103
|
-
</ElevationProvider>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const ToolbarIconButton = ({
|
|
108
|
-
icon,
|
|
109
|
-
text,
|
|
110
|
-
classNames,
|
|
111
|
-
disabled,
|
|
112
|
-
onClick,
|
|
113
|
-
}: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {
|
|
114
|
-
return (
|
|
115
|
-
<Tooltip.Root>
|
|
116
|
-
<Tooltip.Trigger asChild>
|
|
117
|
-
<NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>
|
|
118
|
-
<Icon icon={icon} size={4} classNames={classNames} />
|
|
119
|
-
</NaturalToolbar.Button>
|
|
120
|
-
</Tooltip.Trigger>
|
|
121
|
-
<Tooltip.Portal>
|
|
122
|
-
<Tooltip.Content>
|
|
123
|
-
<Tooltip.Arrow />
|
|
124
|
-
{text}
|
|
125
|
-
</Tooltip.Content>
|
|
126
|
-
</Tooltip.Portal>
|
|
127
|
-
</Tooltip.Root>
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export type ViewType = 'editor' | 'split' | 'preview';
|
|
132
|
-
|
|
133
|
-
export type TemplateSelectProps = {
|
|
134
|
-
templates?: Template[];
|
|
135
|
-
onTemplateSelect?: (id: string) => void;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {
|
|
139
|
-
return (
|
|
140
|
-
<Select.Root value={''} onValueChange={onTemplateSelect}>
|
|
141
|
-
<Select.TriggerButton />
|
|
142
|
-
<Select.Portal>
|
|
143
|
-
<Select.Content>
|
|
144
|
-
<Select.Viewport>
|
|
145
|
-
<Select.Option value={''}>Template</Select.Option>
|
|
146
|
-
{templates.map(({ id, name }) => (
|
|
147
|
-
<Select.Option key={id} value={id}>
|
|
148
|
-
{name}
|
|
149
|
-
</Select.Option>
|
|
150
|
-
))}
|
|
151
|
-
</Select.Viewport>
|
|
152
|
-
</Select.Content>
|
|
153
|
-
</Select.Portal>
|
|
154
|
-
</Select.Root>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export type ViewSelectorProps = {
|
|
159
|
-
view?: ViewType;
|
|
160
|
-
onViewChange?: (view: ViewType) => void;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {
|
|
164
|
-
return (
|
|
165
|
-
<ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>
|
|
166
|
-
<ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>
|
|
167
|
-
<Icon icon='ph--code--regular' size={4} />
|
|
168
|
-
</ToggleGroupItem>
|
|
169
|
-
<ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>
|
|
170
|
-
<Icon icon='ph--square-split-vertical--regular' size={4} />
|
|
171
|
-
</ToggleGroupItem>
|
|
172
|
-
<ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>
|
|
173
|
-
<Icon icon='ph--eye--regular' size={4} />
|
|
174
|
-
</ToggleGroupItem>
|
|
175
|
-
</ToggleGroup>
|
|
176
|
-
);
|
|
177
|
-
};
|
/package/dist/lib/browser/{AutomationPanel-RFQAQ7NF.mjs.map → AutomationPanel-KZVZMZE6.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/lib/node/{AutomationPanel-5CJEF4MI.cjs.map → AutomationPanel-6QSV7ZYK.cjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/lib/node-esm/{AutomationPanel-7Y6REBNJ.mjs.map → AutomationPanel-EZQSGJLS.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|