@dxos/plugin-script 0.7.4 → 0.7.5-main.9d26e3a
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-PMTZROAZ.mjs → AutomationPanel-RFQAQ7NF.mjs} +2 -9
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs.map +7 -0
- package/dist/lib/browser/{ScriptContainer-RYZFYCNK.mjs → ScriptContainer-GDVBWFI7.mjs} +16 -26
- package/dist/lib/browser/ScriptContainer-GDVBWFI7.mjs.map +7 -0
- package/dist/lib/browser/chunk-RQA3EB5K.mjs +26 -0
- package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +57 -131
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types.mjs +8 -0
- package/dist/lib/node/{AutomationPanel-AAGQREH7.cjs → AutomationPanel-5CJEF4MI.cjs} +12 -13
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs.map +7 -0
- package/dist/lib/node/{ScriptContainer-FZ44UIRC.cjs → ScriptContainer-YWXXNLG6.cjs} +27 -28
- package/dist/lib/node/ScriptContainer-YWXXNLG6.cjs.map +7 -0
- package/dist/lib/node/chunk-PK3OQP5L.cjs +45 -0
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +7 -0
- package/dist/lib/node/index.cjs +61 -132
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{types/index.cjs → types.cjs} +5 -9
- package/dist/lib/node/types.cjs.map +7 -0
- package/dist/lib/node-esm/{AutomationPanel-ETQEDY5I.mjs → AutomationPanel-7Y6REBNJ.mjs} +2 -9
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs.map +7 -0
- package/dist/lib/node-esm/{ScriptContainer-3PKDW34A.mjs → ScriptContainer-BG2PHKEH.mjs} +16 -26
- package/dist/lib/node-esm/ScriptContainer-BG2PHKEH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +27 -0
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +57 -131
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types.mjs +9 -0
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +2 -2
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +0 -43
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +22 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +39 -47
- package/src/ScriptPlugin.tsx +43 -95
- package/src/components/AutomationPanel/AutomationPanel.tsx +2 -4
- package/src/components/FrameContainer/FrameContainer.tsx +1 -1
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +6 -3
- package/src/components/ScriptBlock/ScriptBlock.tsx +2 -2
- package/src/components/ScriptEditor.tsx +20 -18
- package/src/components/ScriptSettingsPanel.tsx +1 -2
- package/src/components/Toolbar/Toolbar.tsx +1 -1
- package/src/translations.ts +0 -4
- package/src/types.ts +38 -0
- package/dist/lib/browser/AutomationPanel-PMTZROAZ.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-RYZFYCNK.mjs.map +0 -7
- package/dist/lib/browser/chunk-QFZUFT5G.mjs +0 -48
- package/dist/lib/browser/chunk-QFZUFT5G.mjs.map +0 -7
- package/dist/lib/browser/chunk-U3OP64V4.mjs +0 -123
- package/dist/lib/browser/chunk-U3OP64V4.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -19
- package/dist/lib/browser/types/index.mjs +0 -12
- package/dist/lib/node/AutomationPanel-AAGQREH7.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-FZ44UIRC.cjs.map +0 -7
- package/dist/lib/node/chunk-CS25QNKZ.cjs +0 -151
- package/dist/lib/node/chunk-CS25QNKZ.cjs.map +0 -7
- package/dist/lib/node/chunk-DQYAU2CJ.cjs +0 -67
- package/dist/lib/node/chunk-DQYAU2CJ.cjs.map +0 -7
- package/dist/lib/node/edge/index.cjs +0 -41
- package/dist/lib/node/edge/index.cjs.map +0 -7
- package/dist/lib/node/types/index.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-ETQEDY5I.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-3PKDW34A.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-36DLLQ6E.mjs +0 -125
- package/dist/lib/node-esm/chunk-36DLLQ6E.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GMVPKT6A.mjs +0 -49
- package/dist/lib/node-esm/chunk-GMVPKT6A.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -20
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -13
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/edge/functions.d.ts +0 -25
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -3
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -71
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -8
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/edge/functions.ts +0 -116
- package/src/edge/index.ts +0 -7
- package/src/types/index.ts +0 -6
- package/src/types/schema.ts +0 -44
- package/src/types/types.ts +0 -29
- /package/dist/lib/browser/{edge/index.mjs.map → types.mjs.map} +0 -0
- /package/dist/lib/{browser/types/index.mjs.map → node-esm/types.mjs.map} +0 -0
package/src/ScriptPlugin.tsx
CHANGED
|
@@ -6,13 +6,10 @@
|
|
|
6
6
|
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { type ActionGroup, createExtension, isActionGroup } from '@dxos/plugin-graph';
|
|
9
|
+
import { createIntent, createResolver, createSurface, type PluginDefinition } from '@dxos/app-framework';
|
|
10
|
+
import { FunctionType, ScriptType } from '@dxos/functions';
|
|
11
|
+
import { create, makeRef, RefArray } from '@dxos/live-object';
|
|
13
12
|
import { TextType } from '@dxos/plugin-markdown/types';
|
|
14
|
-
import { SpaceAction } from '@dxos/plugin-space';
|
|
15
|
-
import { loadObjectReferences } from '@dxos/react-client/echo';
|
|
16
13
|
|
|
17
14
|
import { initializeBundler } from './bundler';
|
|
18
15
|
import { Compiler } from './compiler';
|
|
@@ -20,7 +17,7 @@ import { AutomationPanel, ScriptContainer, ScriptSettings, ScriptSettingsPanel }
|
|
|
20
17
|
import meta, { SCRIPT_PLUGIN } from './meta';
|
|
21
18
|
import { templates } from './templates';
|
|
22
19
|
import translations from './translations';
|
|
23
|
-
import {
|
|
20
|
+
import { ScriptAction, type ScriptPluginProvides } from './types';
|
|
24
21
|
|
|
25
22
|
export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
|
|
26
23
|
const compiler = new Compiler();
|
|
@@ -48,11 +45,11 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
|
|
|
48
45
|
metadata: {
|
|
49
46
|
records: {
|
|
50
47
|
[ScriptType.typename]: {
|
|
51
|
-
createObject: ScriptAction.
|
|
48
|
+
createObject: (props: { name?: string }) => createIntent(ScriptAction.Create, props),
|
|
52
49
|
placeholder: ['object title placeholder', { ns: SCRIPT_PLUGIN }],
|
|
53
50
|
icon: 'ph--code--regular',
|
|
54
51
|
// TODO(wittjosiah): Move out of metadata.
|
|
55
|
-
loadReferences: (script: ScriptType) =>
|
|
52
|
+
loadReferences: async (script: ScriptType) => await RefArray.loadAll([script.source]),
|
|
56
53
|
},
|
|
57
54
|
},
|
|
58
55
|
},
|
|
@@ -61,97 +58,48 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
|
|
|
61
58
|
schema: [ScriptType],
|
|
62
59
|
system: [FunctionType],
|
|
63
60
|
},
|
|
64
|
-
graph: {
|
|
65
|
-
builder: (plugins) => {
|
|
66
|
-
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
67
|
-
const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
|
|
68
|
-
if (!client || !dispatch) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return createExtension({
|
|
73
|
-
id: ScriptAction.CREATE,
|
|
74
|
-
filter: (node): node is ActionGroup => isActionGroup(node) && node.id.startsWith(SpaceAction.ADD_OBJECT),
|
|
75
|
-
actions: ({ node }) => {
|
|
76
|
-
const id = node.id.split('/').at(-1);
|
|
77
|
-
const [spaceId, objectId] = id?.split(':') ?? [];
|
|
78
|
-
const space = client.spaces.get().find((space) => space.id === spaceId);
|
|
79
|
-
const object = objectId && space?.db.getObjectById(objectId);
|
|
80
|
-
const target = objectId ? object : space;
|
|
81
|
-
if (!target) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return [
|
|
86
|
-
{
|
|
87
|
-
id: `${SCRIPT_PLUGIN}/create/${node.id}`,
|
|
88
|
-
data: async () => {
|
|
89
|
-
await dispatch([
|
|
90
|
-
{ plugin: SCRIPT_PLUGIN, action: ScriptAction.CREATE },
|
|
91
|
-
{ action: SpaceAction.ADD_OBJECT, data: { target } },
|
|
92
|
-
{ action: NavigationAction.OPEN },
|
|
93
|
-
]);
|
|
94
|
-
},
|
|
95
|
-
properties: {
|
|
96
|
-
label: ['create object label', { ns: SCRIPT_PLUGIN }],
|
|
97
|
-
icon: 'ph--code--regular',
|
|
98
|
-
testId: 'scriptPlugin.createObject',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
];
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
61
|
surface: {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return null;
|
|
139
|
-
},
|
|
62
|
+
definitions: () => [
|
|
63
|
+
createSurface({
|
|
64
|
+
id: `${SCRIPT_PLUGIN}/settings`,
|
|
65
|
+
role: 'settings',
|
|
66
|
+
filter: (data): data is any => data.subject === SCRIPT_PLUGIN,
|
|
67
|
+
component: () => <ScriptSettings settings={{}} />,
|
|
68
|
+
}),
|
|
69
|
+
createSurface({
|
|
70
|
+
id: `${SCRIPT_PLUGIN}/article`,
|
|
71
|
+
role: 'article',
|
|
72
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
73
|
+
component: ({ data }) => <ScriptContainer script={data.subject} env={compiler.environment} />,
|
|
74
|
+
}),
|
|
75
|
+
createSurface({
|
|
76
|
+
id: `${SCRIPT_PLUGIN}/automation`,
|
|
77
|
+
role: 'complementary--automation',
|
|
78
|
+
disposition: 'hoist',
|
|
79
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
80
|
+
component: ({ data }) => <AutomationPanel subject={data.subject} />,
|
|
81
|
+
}),
|
|
82
|
+
createSurface({
|
|
83
|
+
id: `${SCRIPT_PLUGIN}/settings-panel`,
|
|
84
|
+
role: 'complementary--settings',
|
|
85
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
86
|
+
component: ({ data }) => <ScriptSettingsPanel script={data.subject} />,
|
|
87
|
+
}),
|
|
88
|
+
],
|
|
140
89
|
},
|
|
141
90
|
intent: {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
91
|
+
resolvers: () =>
|
|
92
|
+
createResolver(ScriptAction.Create, ({ name }) => ({
|
|
93
|
+
data: {
|
|
94
|
+
object: create(ScriptType, {
|
|
95
|
+
source: makeRef(
|
|
96
|
+
create(TextType, {
|
|
148
97
|
content: templates[0].source,
|
|
149
98
|
}),
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
},
|
|
99
|
+
),
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
})),
|
|
155
103
|
},
|
|
156
104
|
},
|
|
157
105
|
};
|
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type ReactiveEchoObject } from '@dxos/client/echo';
|
|
8
7
|
import { failUndefined } from '@dxos/debug';
|
|
8
|
+
import { FunctionType, ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
9
9
|
import { useClient } from '@dxos/react-client';
|
|
10
|
-
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
10
|
+
import { Filter, getMeta, getSpace, type ReactiveEchoObject, useQuery } from '@dxos/react-client/echo';
|
|
11
11
|
import { Select, useTranslation } from '@dxos/react-ui';
|
|
12
12
|
|
|
13
|
-
import { getInvocationUrl, getUserFunctionUrlInMetadata } from '../../edge';
|
|
14
13
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
15
|
-
import { FunctionType, ScriptType } from '../../types';
|
|
16
14
|
import { DebugPanel } from '../DebugPanel';
|
|
17
15
|
|
|
18
16
|
export interface AutomationPanelProps {
|
|
@@ -59,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
|
|
|
59
59
|
className={mx(
|
|
60
60
|
baseSurface,
|
|
61
61
|
'flex absolute right-2 bottom-2 w-[400px] h-[200px] ring rounded',
|
|
62
|
-
'z-
|
|
62
|
+
'z-20 overflow-x-hidden overflow-y-auto',
|
|
63
63
|
)}
|
|
64
64
|
>
|
|
65
65
|
<pre className='text-xs whitespace-break-spaces break-all p-2'>
|
|
@@ -7,13 +7,13 @@ import '@dxos-theme';
|
|
|
7
7
|
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React, { useMemo } from 'react';
|
|
9
9
|
|
|
10
|
+
import { ScriptType } from '@dxos/functions';
|
|
10
11
|
import { TextType } from '@dxos/plugin-markdown/types';
|
|
11
|
-
import { create, createObject } from '@dxos/react-client/echo';
|
|
12
|
+
import { create, createObject, makeRef } from '@dxos/react-client/echo';
|
|
12
13
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
14
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
14
15
|
|
|
15
16
|
import { ScriptBlock } from './ScriptBlock';
|
|
16
|
-
import { ScriptType } from '../../types';
|
|
17
17
|
// @ts-ignore
|
|
18
18
|
import mainUrl from '../FrameContainer/frame?url';
|
|
19
19
|
|
|
@@ -33,7 +33,10 @@ const code = [
|
|
|
33
33
|
|
|
34
34
|
const DefaultStory = () => {
|
|
35
35
|
// TODO(burdon): Review what's the right way to create automerge-backed objects.
|
|
36
|
-
const object = useMemo(
|
|
36
|
+
const object = useMemo(
|
|
37
|
+
() => createObject(create(ScriptType, { source: makeRef(create(TextType, { content: code })) })),
|
|
38
|
+
[],
|
|
39
|
+
);
|
|
37
40
|
|
|
38
41
|
// TODO(dmaretskyi): Not sure how to provide `containerUrl` here since the html now lives in composer-app.
|
|
39
42
|
// TODO(burdon): Normalize html/frame.tsx with composer-app to test locally.
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
8
|
|
|
9
|
+
import { type ScriptType } from '@dxos/functions';
|
|
9
10
|
import { createDocAccessor, DocAccessor } from '@dxos/react-client/echo';
|
|
10
11
|
import { Toolbar, Button, Icon } from '@dxos/react-ui';
|
|
11
12
|
|
|
12
13
|
import { Bundler, type BundlerResult, initializeBundler } from '../../bundler';
|
|
13
|
-
import { type ScriptType } from '../../types';
|
|
14
14
|
import { FrameContainer } from '../FrameContainer';
|
|
15
15
|
import { ScriptEditor } from '../ScriptEditor';
|
|
16
16
|
|
|
@@ -37,7 +37,7 @@ export type ScriptBlockProps = {
|
|
|
37
37
|
*/
|
|
38
38
|
// TODO(burdon): Cache compiled results in context.
|
|
39
39
|
export const ScriptBlock = ({ script, hideSelector, containerUrl }: ScriptBlockProps) => {
|
|
40
|
-
const source = useMemo(() => script.source && createDocAccessor(script.source
|
|
40
|
+
const source = useMemo(() => script.source && createDocAccessor(script.source.target!, ['content']), [script.source]);
|
|
41
41
|
const [result, setResult] = useState<BundlerResult>();
|
|
42
42
|
const bundler = useMemo(
|
|
43
43
|
() => new Bundler({ platform: 'browser', sandboxedModules: PROVIDED_MODULES, remoteModules: {} }),
|
|
@@ -7,9 +7,19 @@ import prettierPluginEstree from 'prettier/plugins/estree';
|
|
|
7
7
|
import prettierPluginTypescript from 'prettier/plugins/typescript';
|
|
8
8
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
9
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';
|
|
10
20
|
import { log } from '@dxos/log';
|
|
11
21
|
import { useClient } from '@dxos/react-client';
|
|
12
|
-
import { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
22
|
+
import { create, createDocAccessor, Filter, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
|
|
13
23
|
import { useIdentity } from '@dxos/react-client/halo';
|
|
14
24
|
import { useTranslation, type ThemedClassName } from '@dxos/react-ui';
|
|
15
25
|
import { createDataExtensions, listener } from '@dxos/react-ui-editor';
|
|
@@ -19,17 +29,8 @@ import { DebugPanel } from './DebugPanel';
|
|
|
19
29
|
import { type TemplateSelectProps, Toolbar, type ViewType } from './Toolbar';
|
|
20
30
|
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
21
31
|
import { Bundler } from '../bundler';
|
|
22
|
-
import {
|
|
23
|
-
getInvocationUrl,
|
|
24
|
-
getUserFunctionUrlInMetadata,
|
|
25
|
-
setUserFunctionUrlInMetadata,
|
|
26
|
-
uploadWorkerFunction,
|
|
27
|
-
FUNCTIONS_PRESET_META_KEY,
|
|
28
|
-
incrementSemverPatch,
|
|
29
|
-
} from '../edge';
|
|
30
32
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
31
33
|
import { templates } from '../templates';
|
|
32
|
-
import { FunctionType, type ScriptType } from '../types';
|
|
33
34
|
|
|
34
35
|
export type ScriptEditorProps = ThemedClassName<{
|
|
35
36
|
script: ScriptType;
|
|
@@ -47,19 +48,19 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
47
48
|
() => [
|
|
48
49
|
listener({
|
|
49
50
|
onChange: (text) => {
|
|
50
|
-
if (script.source && script.source
|
|
51
|
+
if (script.source.target && script.source.target.content !== text) {
|
|
51
52
|
script.changed = true;
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
}),
|
|
55
56
|
createDataExtensions({
|
|
56
57
|
id: script.id,
|
|
57
|
-
text: script.source && createDocAccessor(script.source, ['content']),
|
|
58
|
+
text: script.source.target && createDocAccessor(script.source.target, ['content']),
|
|
58
59
|
space,
|
|
59
60
|
identity,
|
|
60
61
|
}),
|
|
61
62
|
],
|
|
62
|
-
[script, script.source, space, identity],
|
|
63
|
+
[script, script.source.target, space, identity],
|
|
63
64
|
);
|
|
64
65
|
|
|
65
66
|
const [view, setView] = useState<ViewType>('editor');
|
|
@@ -72,7 +73,7 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
try {
|
|
75
|
-
script.source.content = await format(script.source.content, {
|
|
76
|
+
script.source.target!.content = await format(script.source.target!.content, {
|
|
76
77
|
parser: 'typescript',
|
|
77
78
|
plugins: [prettierPluginEstree, prettierPluginTypescript],
|
|
78
79
|
semi: true,
|
|
@@ -88,7 +89,7 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
88
89
|
const template = templates.find((template) => template.id === id);
|
|
89
90
|
if (template) {
|
|
90
91
|
script.name = template.name;
|
|
91
|
-
script.source!.content = template.source;
|
|
92
|
+
script.source!.target!.content = template.source;
|
|
92
93
|
const metaKeys = getMeta(script).keys;
|
|
93
94
|
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
94
95
|
if (oldPresetIndex >= 0) {
|
|
@@ -111,7 +112,7 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
111
112
|
const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
|
|
112
113
|
|
|
113
114
|
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
114
|
-
const buildResult = await bundler.bundle(script.source.content);
|
|
115
|
+
const buildResult = await bundler.bundle(script.source.target!.content);
|
|
115
116
|
if (buildResult.error || !buildResult.bundle) {
|
|
116
117
|
throw buildResult.error;
|
|
117
118
|
}
|
|
@@ -132,7 +133,8 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
132
133
|
fn.version = version;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
const deployedFunction =
|
|
136
|
+
const deployedFunction =
|
|
137
|
+
fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
|
|
136
138
|
|
|
137
139
|
script.changed = false;
|
|
138
140
|
|
|
@@ -179,7 +181,7 @@ export const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) =>
|
|
|
179
181
|
<TypescriptEditor
|
|
180
182
|
id={script.id}
|
|
181
183
|
env={env}
|
|
182
|
-
initialValue={script.source?.content}
|
|
184
|
+
initialValue={script.source?.target?.content}
|
|
183
185
|
extensions={extensions}
|
|
184
186
|
className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'
|
|
185
187
|
/>
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type ChangeEvent, useCallback } from 'react';
|
|
6
6
|
|
|
7
|
+
import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
7
8
|
import { useClient } from '@dxos/react-client';
|
|
8
9
|
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
9
10
|
import { Button, Icon, Input, useControlledValue, useTranslation } from '@dxos/react-ui';
|
|
10
11
|
|
|
11
|
-
import { getInvocationUrl, getUserFunctionUrlInMetadata } from '../edge';
|
|
12
12
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
13
|
-
import { FunctionType, type ScriptType } from '../types';
|
|
14
13
|
|
|
15
14
|
export type ScriptSettingsPanelProps = {
|
|
16
15
|
script: ScriptType;
|
|
@@ -64,7 +64,7 @@ export const Toolbar = ({
|
|
|
64
64
|
|
|
65
65
|
// TODO(burdon): Factor out common toolbar components with sheet/editor?
|
|
66
66
|
return (
|
|
67
|
-
<ElevationProvider elevation='
|
|
67
|
+
<ElevationProvider elevation='positioned'>
|
|
68
68
|
<NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>
|
|
69
69
|
{templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}
|
|
70
70
|
{onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}
|
package/src/translations.ts
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { SCRIPT_PLUGIN } from './meta';
|
|
6
|
-
import { ScriptType } from './types';
|
|
7
6
|
|
|
8
7
|
export default [
|
|
9
8
|
{
|
|
10
9
|
'en-US': {
|
|
11
|
-
[ScriptType.typename]: {
|
|
12
|
-
'typename label': 'Script',
|
|
13
|
-
},
|
|
14
10
|
[SCRIPT_PLUGIN]: {
|
|
15
11
|
'plugin name': 'Scripts',
|
|
16
12
|
'object title placeholder': 'New script',
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
IntentResolverProvides,
|
|
7
|
+
MetadataRecordsProvides,
|
|
8
|
+
SettingsProvides,
|
|
9
|
+
SurfaceProvides,
|
|
10
|
+
TranslationsProvides,
|
|
11
|
+
} from '@dxos/app-framework';
|
|
12
|
+
import { S } from '@dxos/echo-schema';
|
|
13
|
+
import { ScriptType } from '@dxos/functions';
|
|
14
|
+
import { type SchemaProvides } from '@dxos/plugin-space';
|
|
15
|
+
|
|
16
|
+
import { SCRIPT_PLUGIN } from './meta';
|
|
17
|
+
|
|
18
|
+
export namespace ScriptAction {
|
|
19
|
+
const SCRIPT_ACTION = `${SCRIPT_PLUGIN}/action`;
|
|
20
|
+
|
|
21
|
+
export class Create extends S.TaggedClass<Create>()(`${SCRIPT_ACTION}/create`, {
|
|
22
|
+
input: S.Struct({
|
|
23
|
+
name: S.optional(S.String),
|
|
24
|
+
}),
|
|
25
|
+
output: S.Struct({
|
|
26
|
+
object: ScriptType,
|
|
27
|
+
}),
|
|
28
|
+
}) {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ScriptSettingsProps = {};
|
|
32
|
+
|
|
33
|
+
export type ScriptPluginProvides = IntentResolverProvides &
|
|
34
|
+
MetadataRecordsProvides &
|
|
35
|
+
SchemaProvides &
|
|
36
|
+
SettingsProvides<ScriptSettingsProps> &
|
|
37
|
+
SurfaceProvides &
|
|
38
|
+
TranslationsProvides;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/AutomationPanel/AutomationPanel.tsx", "../../../src/components/AutomationPanel/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useMemo, useState } from 'react';\n\nimport { type ReactiveEchoObject } from '@dxos/client/echo';\nimport { failUndefined } from '@dxos/debug';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Select, useTranslation } from '@dxos/react-ui';\n\nimport { getInvocationUrl, getUserFunctionUrlInMetadata } from '../../edge';\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { FunctionType, ScriptType } from '../../types';\nimport { DebugPanel } from '../DebugPanel';\n\nexport interface AutomationPanelProps {\n subject: ReactiveEchoObject<any>;\n}\n\nexport const AutomationPanel = ({ subject }: AutomationPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const space = getSpace(subject);\n\n // TODO(dmaretskyi): Parametric query.\n const functions = useQuery(\n space ?? undefined,\n subject instanceof ScriptType\n ? Filter.schema(FunctionType, { source: subject })\n : Filter.schema(FunctionType, (fn) => fn.binding != null),\n {},\n [subject],\n );\n\n const [selectedFunction, setSelectedFunction] = useState<FunctionType | null>(null);\n const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;\n\n return (\n <div className='h-full flex flex-col'>\n {!(subject instanceof ScriptType) && (\n <BindingSelect\n selectedFunction={selectedFunction}\n setSelectedFunction={setSelectedFunction}\n functions={functions}\n />\n )}\n {chatFunction && <ChatPanel fn={chatFunction} subject={subject} />}\n {subject instanceof ScriptType && functions.length === 0 && <div className='p-1'>{t('not deployed')}</div>}\n </div>\n );\n};\n\nexport interface ChatPanelProps {\n fn: FunctionType;\n subject: ReactiveEchoObject<any>;\n}\n\nconst ChatPanel = ({ fn, subject }: ChatPanelProps) => {\n const client = useClient();\n const space = getSpace(fn);\n const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n subjectId: subject?.id,\n });\n }, [existingFunctionUrl, space, subject]);\n\n return <DebugPanel functionUrl={functionUrl} classNames='flex-1' />;\n};\n\nexport interface BindingSelectProps {\n selectedFunction: FunctionType | null;\n setSelectedFunction: (fn: FunctionType) => void;\n functions: FunctionType[];\n}\n\nconst BindingSelect = ({ selectedFunction, setSelectedFunction, functions }: BindingSelectProps) => {\n return (\n <Select.Root\n value={selectedFunction?.id}\n onValueChange={(id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())}\n >\n <Select.TriggerButton placeholder='Select value' />\n <Select.Portal>\n <Select.Content>\n <Select.ScrollUpButton />\n <Select.Viewport>\n {functions.map(({ id, binding }) => (\n <Select.Option key={id} value={id}>\n {binding}\n </Select.Option>\n ))}\n </Select.Viewport>\n <Select.ScrollDownButton />\n <Select.Arrow />\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AutomationPanel } from './AutomationPanel';\n\nexport * from './AutomationPanel';\n\nexport default AutomationPanel;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;AAIA,OAAOA,SAASC,SAASC,gBAAgB;AAGzC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,SAASC,UAAUC,gBAAgB;AACpD,SAASC,QAAQC,sBAAsB;AAWhC,IAAMC,kBAAkB,CAAC,EAAEC,QAAO,MAAwB;AAC/D,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAMC,QAAQC,SAASL,OAAAA;AAGvB,QAAMM,YAAYC,SAChBH,SAASI,QACTR,mBAAmBS,aACfC,OAAOC,OAAOC,cAAc;IAAEC,QAAQb;EAAQ,CAAA,IAC9CU,OAAOC,OAAOC,cAAc,CAACE,OAAOA,GAAGC,WAAW,IAAA,GACtD,CAAC,GACD;IAACf;GAAQ;AAGX,QAAM,CAACgB,kBAAkBC,mBAAAA,IAAuBC,SAA8B,IAAA;AAC9E,QAAMC,eAAenB,mBAAmBS,aAAaH,UAAU,CAAA,IAAKU;AAEpE,SACE,sBAAA,cAACI,OAAAA;IAAIC,WAAU;KACZ,EAAErB,mBAAmBS,eACpB,sBAAA,cAACa,eAAAA;IACCN;IACAC;IACAX;MAGHa,gBAAgB,sBAAA,cAACI,WAAAA;IAAUT,IAAIK;IAAcnB;MAC7CA,mBAAmBS,cAAcH,UAAUkB,WAAW,KAAK,sBAAA,cAACJ,OAAAA;IAAIC,WAAU;KAAOpB,EAAE,cAAA,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|
-
"names": ["React", "useMemo", "useState", "failUndefined", "useClient", "Filter", "getMeta", "getSpace", "useQuery", "Select", "useTranslation", "AutomationPanel", "subject", "t", "useTranslation", "SCRIPT_PLUGIN", "space", "getSpace", "functions", "useQuery", "undefined", "ScriptType", "Filter", "schema", "FunctionType", "source", "fn", "binding", "selectedFunction", "setSelectedFunction", "useState", "chatFunction", "div", "className", "BindingSelect", "ChatPanel", "length", "client", "useClient", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "functionUrl", "useMemo", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "id", "subjectId", "DebugPanel", "classNames", "Select", "Root", "value", "onValueChange", "find", "failUndefined", "TriggerButton", "placeholder", "Portal", "Content", "ScrollUpButton", "Viewport", "map", "Option", "key", "ScrollDownButton", "Arrow", "AutomationPanel"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptEditor.tsx", "../../../src/components/Toolbar/Toolbar.tsx", "../../../src/components/TypescriptEditor/TypescriptEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { useAttendableAttributes } from '@dxos/react-ui-attention';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';\n\nconst ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {\n const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));\n return (\n <div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>\n <ScriptEditor {...props} script={script} />\n </div>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { format } from 'prettier';\nimport prettierPluginEstree from 'prettier/plugins/estree';\nimport prettierPluginTypescript from 'prettier/plugins/typescript';\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { useTranslation, type ThemedClassName } from '@dxos/react-ui';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { DebugPanel } from './DebugPanel';\nimport { type TemplateSelectProps, Toolbar, type ViewType } from './Toolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { Bundler } from '../bundler';\nimport {\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n FUNCTIONS_PRESET_META_KEY,\n incrementSemverPatch,\n} from '../edge';\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { templates } from '../templates';\nimport { FunctionType, type ScriptType } from '../types';\n\nexport type ScriptEditorProps = ThemedClassName<{\n script: ScriptType;\n}> &\n Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source && script.source?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source && createDocAccessor(script.source, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source, space, identity],\n );\n\n const [view, setView] = useState<ViewType>('editor');\n const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const [error, setError] = useState<string>();\n\n const handleFormat = useCallback(async () => {\n if (!script.source) {\n return;\n }\n\n try {\n script.source.content = await format(script.source.content, {\n parser: 'typescript',\n plugins: [prettierPluginEstree, prettierPluginTypescript],\n semi: true,\n singleQuote: true,\n });\n } catch (err: any) {\n // TODO(wittjosiah): Show error in UI.\n log.catch(err);\n }\n }, [script.source]);\n\n const handleTemplateChange: TemplateSelectProps['onTemplateSelect'] = (id) => {\n const template = templates.find((template) => template.id === id);\n if (template) {\n script.name = template.name;\n script.source!.content = template.source;\n const metaKeys = getMeta(script).keys;\n const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });\n }\n }\n };\n\n const handleDeploy = useCallback(async () => {\n if (!script.source || !identity || !space) {\n return;\n }\n\n setError(undefined);\n\n try {\n const existingFunctionId = existingFunctionUrl?.split('/').at(-1);\n\n const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });\n const buildResult = await bundler.bundle(script.source.content);\n if (buildResult.error || !buildResult.bundle) {\n throw buildResult.error;\n }\n\n const { functionId, version, meta } = await uploadWorkerFunction({\n client,\n spaceId: space.id,\n version: fn ? incrementSemverPatch(fn.version) : '0.0.1',\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (functionId === undefined || version === undefined) {\n throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);\n }\n\n log.info('function uploaded', { functionId, version });\n if (fn) {\n fn.version = version;\n }\n\n const deployedFunction = fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: script }));\n\n script.changed = false;\n\n if (meta.inputSchema) {\n deployedFunction.inputSchema = meta.inputSchema;\n } else {\n log.verbose('no input schema in function metadata', { functionId });\n }\n\n setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);\n\n setView('split');\n } catch (err: any) {\n log.catch(err);\n setError(t('upload failed label'));\n }\n }, [fn, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);\n\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n }, [existingFunctionUrl, space]);\n\n return (\n <div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>\n <Toolbar\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n functionUrl={functionUrl}\n error={error}\n view={view}\n templates={templates}\n onDeploy={handleDeploy}\n onFormat={handleFormat}\n onViewChange={setView}\n onTemplateSelect={handleTemplateChange}\n />\n\n {view !== 'preview' && (\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.content}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'\n />\n )}\n\n {view !== 'editor' && <DebugPanel functionUrl={functionUrl} />}\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport {\n ElevationProvider,\n Icon,\n Select,\n type ThemedClassName,\n ToggleGroup,\n ToggleGroupItem,\n type ToolbarButtonProps,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type Template } from '../../templates';\n\nexport type ToolbarProps = ThemedClassName<\n {\n deployed?: boolean;\n error?: string;\n functionUrl?: string;\n onDeploy?: () => Promise<void>;\n onFormat?: () => Promise<void>;\n } & TemplateSelectProps &\n ViewSelectorProps\n>;\n\nexport const Toolbar = ({\n classNames,\n deployed,\n error,\n functionUrl,\n view,\n templates,\n onDeploy,\n onFormat,\n onViewChange,\n onTemplateSelect,\n}: ToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const [pending, setPending] = useState(false);\n\n const handleCopyLink = async () => {\n if (!functionUrl) {\n return;\n }\n\n await navigator.clipboard.writeText(functionUrl);\n };\n\n const handleDeploy = async () => {\n if (!pending) {\n setPending(true);\n await onDeploy?.();\n setPending(false);\n }\n };\n\n // TODO(burdon): Factor out common toolbar components with sheet/editor?\n return (\n <ElevationProvider elevation='chrome'>\n <NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>\n {templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}\n {onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}\n\n <div role='separator' className='grow' />\n\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Icon icon='ph--warning-circle--regular' size={4} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {error}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n\n {functionUrl && deployed && (\n <ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />\n )}\n\n {onDeploy && (\n <ToolbarIconButton\n icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}\n classNames={[pending && 'animate-spin']}\n text={pending ? t('pending label') : t('deploy label')}\n onClick={handleDeploy}\n />\n )}\n\n <ViewSelector view={view} onViewChange={onViewChange} />\n </NaturalToolbar.Root>\n </ElevationProvider>\n );\n};\n\nconst ToolbarIconButton = ({\n icon,\n text,\n classNames,\n disabled,\n onClick,\n}: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {\n return (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>\n <Icon icon={icon} size={4} classNames={classNames} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {text}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n );\n};\n\nexport type ViewType = 'editor' | 'split' | 'preview';\n\nexport type TemplateSelectProps = {\n templates?: Template[];\n onTemplateSelect?: (id: string) => void;\n};\n\nexport const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {\n return (\n <Select.Root value={''} onValueChange={onTemplateSelect}>\n <Select.TriggerButton />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n <Select.Option value={''}>Template</Select.Option>\n {templates.map(({ id, name }) => (\n <Select.Option key={id} value={id}>\n {name}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nexport type ViewSelectorProps = {\n view?: ViewType;\n onViewChange?: (view: ViewType) => void;\n};\n\nexport const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {\n return (\n <ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>\n <ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--code--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--square-split-vertical--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--eye--regular' size={4} />\n </ToggleGroupItem>\n </ToggleGroup>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorFullWidth,\n editorGutter,\n editorMonospace,\n InputModeExtensions,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n env?: VirtualTypeScriptEnvironment;\n} & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n env,\n className,\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 extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n scrollPastEnd: true,\n }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: {\n content: { className: editorFullWidth },\n },\n }),\n editorGutter,\n // TODO(burdon): Factor out.\n [\n editorMonospace,\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : [] }),\n env ? [tsFacet.of({ env, path: `/src/${id}.ts` }), tsSync(), tsLinter(), tsHover()] : [],\n InputModeExtensions.vscode,\n ],\n ].filter(nonNullable),\n selection,\n scrollTo,\n }),\n [id, extensions, themeMode, selection, scrollTo],\n );\n\n return <div ref={parentRef} className={className} {...focusAttributes} />;\n};\n\nexport default TypescriptEditor;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,wBAAwB;AACjC,SAASC,+BAA+B;AACxC,SAASC,MAAAA,WAAU;;;ACJnB,SAASC,cAAc;AACvB,OAAOC,0BAA0B;AACjC,OAAOC,8BAA8B;AACrC,OAAOC,UAASC,aAAaC,SAASC,YAAAA,iBAAgB;AAEtD,SAASC,WAAW;AACpB,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,mBAAmBC,QAAQC,SAASC,UAAUC,gBAAgB;AAC/E,SAASC,mBAAmB;AAC5B,SAASC,kBAAAA,uBAA4C;AACrD,SAASC,sBAAsBC,gBAAgB;AAC/C,SAASC,UAAU;;;ACXnB,OAAOC,SAASC,gBAAgB;AAEhC,SACEC,mBACAC,MACAC,QAEAC,aACAC,iBAEAC,WAAWC,gBACXC,SACAC,sBACK;A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AAA,KAAwB,CAAC9B,OAAOuB;IAClDiE;IACAvD;IACAN;IACAsB;IACAuD,UAAU3C;IACV4C,UAAUtE;IACVuE,cAAc9E;IACd+E,kBAAkB5D;MAGnBpB,SAAS,aACR,gBAAAqE,OAAA,cAACY,kBAAAA;IACCnF,IAAIzB,OAAOyB;IACXxB;IACA4G,cAAc7G,OAAOgB,QAAQM;IAC7BL;IACAkF,WAAU;MAIbxE,SAAS,YAAY,gBAAAqE,OAAA,cAACc,YAAAA;IAAWtB;;AAGxC;;;ADlLA,IAAMuB,kBAAkB,CAAC,EAAEC,QAAQ,GAAGC,MAAAA,MAA0B;AAC9D,QAAMC,kBAAkBC,wBAAwBC,iBAAiBJ,MAAAA,CAAAA;AACjE,SACE,gBAAAK,OAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAWC,IAAG,0DAAA;IAA8D,GAAGP;KAC9F,gBAAAG,OAAA,cAACK,cAAAA;IAAc,GAAGT;IAAOD;;AAG/B;AAEA,IAAA,0BAAeD;",
|
|
6
|
-
"names": ["React", "fullyQualifiedId", "useAttendableAttributes", "mx", "format", "prettierPluginEstree", "prettierPluginTypescript", "React", "useCallback", "useMemo", "useState", "log", "useClient", "create", "createDocAccessor", "Filter", "getMeta", "getSpace", "useQuery", "useIdentity", "useTranslation", "createDataExtensions", "listener", "mx", "React", "useState", "ElevationProvider", "Icon", "Select", "ToggleGroup", "ToggleGroupItem", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "Toolbar", "classNames", "deployed", "error", "functionUrl", "view", "templates", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "ElevationProvider", "elevation", "NaturalToolbar", "Root", "style", "contain", "TemplateSelect", "ToolbarIconButton", "icon", "text", "onClick", "div", "role", "className", "Tooltip", "Trigger", "Icon", "size", "Portal", "Content", "Arrow", "ViewSelector", "disabled", "asChild", "Button", "variant", "Select", "value", "onValueChange", "TriggerButton", "Viewport", "Option", "map", "id", "name", "key", "ToggleGroup", "type", "ToggleGroupItem", "javascript", "tsSync", "tsFacet", "tsLinter", "tsAutocomplete", "tsHover", "React", "useThemeContext", "autocomplete", "createBasicExtensions", "createThemeExtensions", "editorFullWidth", "editorGutter", "editorMonospace", "InputModeExtensions", "useTextEditor", "nonNullable", "TypescriptEditor", "id", "env", "className", "initialValue", "extensions", "scrollTo", "selection", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "scrollPastEnd", "createThemeExtensions", "syntaxHighlighting", "slots", "content", "editorFullWidth", "editorGutter", "editorMonospace", "javascript", "typescript", "autocomplete", "override", "tsAutocomplete", "tsFacet", "of", "path", "tsSync", "tsLinter", "tsHover", "InputModeExtensions", "vscode", "filter", "nonNullable", "React", "div", "ref", "ScriptEditor", "classNames", "script", "env", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "identity", "useIdentity", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "extensions", "useMemo", "listener", "onChange", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "view", "setView", "useState", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "error", "setError", "handleFormat", "useCallback", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "handleTemplateChange", "template", "templates", "find", "name", "metaKeys", "keys", "oldPresetIndex", "findIndex", "key", "FUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "handleDeploy", "undefined", "existingFunctionId", "split", "at", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "functionId", "version", "meta", "uploadWorkerFunction", "spaceId", "incrementSemverPatch", "Error", "info", "deployedFunction", "db", "add", "create", "inputSchema", "verbose", "setUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "React", "div", "role", "className", "mx", "Toolbar", "deployed", "Boolean", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "TypescriptEditor", "initialValue", "DebugPanel", "ScriptContainer", "script", "props", "attendableAttrs", "useAttendableAttributes", "fullyQualifiedId", "React", "div", "role", "className", "mx", "ScriptEditor"]
|
|
7
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SCRIPT_PLUGIN
|
|
3
|
-
} from "./chunk-C7VBULMK.mjs";
|
|
4
|
-
|
|
5
|
-
// packages/plugins/experimental/plugin-script/src/types/schema.ts
|
|
6
|
-
import { JsonSchemaType, ref, S, TypedObject } from "@dxos/echo-schema";
|
|
7
|
-
import { TextType } from "@dxos/plugin-markdown/types";
|
|
8
|
-
var ScriptType = class extends TypedObject({
|
|
9
|
-
typename: "dxos.org/type/Script",
|
|
10
|
-
version: "0.1.0"
|
|
11
|
-
})({
|
|
12
|
-
// TODO(burdon): Change to URI?
|
|
13
|
-
name: S.optional(S.String),
|
|
14
|
-
description: S.optional(S.String),
|
|
15
|
-
// TODO(burdon): Change to hash of deployed content.
|
|
16
|
-
// Whether source has changed since last deploy.
|
|
17
|
-
changed: S.optional(S.Boolean),
|
|
18
|
-
source: ref(TextType)
|
|
19
|
-
}) {
|
|
20
|
-
};
|
|
21
|
-
var FunctionType = class extends TypedObject({
|
|
22
|
-
typename: "dxos.org/type/Function",
|
|
23
|
-
version: "0.1.0"
|
|
24
|
-
})({
|
|
25
|
-
// TODO(burdon): Rename to id/uri?
|
|
26
|
-
name: S.NonEmptyString,
|
|
27
|
-
version: S.String,
|
|
28
|
-
// Reference to a source script if it exists within ECHO.
|
|
29
|
-
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
30
|
-
source: S.optional(ref(ScriptType)),
|
|
31
|
-
inputSchema: S.optional(JsonSchemaType),
|
|
32
|
-
// Local binding to a function name.
|
|
33
|
-
binding: S.optional(S.String)
|
|
34
|
-
}) {
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// packages/plugins/experimental/plugin-script/src/types/types.ts
|
|
38
|
-
var ScriptAction;
|
|
39
|
-
(function(ScriptAction2) {
|
|
40
|
-
ScriptAction2[ScriptAction2["CREATE"] = `${SCRIPT_PLUGIN}/create`] = "CREATE";
|
|
41
|
-
})(ScriptAction || (ScriptAction = {}));
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
ScriptType,
|
|
45
|
-
FunctionType,
|
|
46
|
-
ScriptAction
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=chunk-QFZUFT5G.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/plugin-markdown/types';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { type SchemaProvides } from '@dxos/plugin-space';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport enum ScriptAction {\n CREATE = `${SCRIPT_PLUGIN}/create`,\n}\n\nexport type ScriptSettingsProps = {};\n\nexport type ScriptPluginProvides = GraphBuilderProvides &\n IntentResolverProvides &\n MetadataRecordsProvides &\n SchemaProvides &\n SettingsProvides<ScriptSettingsProps> &\n SurfaceProvides &\n TranslationsProvides;\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,cAA2Bb,YAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEU;EACRZ,SAASE,EAAEE;;;EAIXI,QAAQN,EAAEC,SAASM,IAAIZ,UAAAA,CAAAA;EAEvBgB,aAAaX,EAAEC,SAASW,cAAAA;;EAGxBC,SAASb,EAAEC,SAASD,EAAEE,MAAM;AAC9B,CAAA,EAAA;AAAI;;;;UC3BQY,eAAAA;0CACD,GAAGC,aAAAA,SAAsB,IAAA;GADxBD,iBAAAA,eAAAA,CAAAA,EAAAA;",
|
|
6
|
-
"names": ["JsonSchemaType", "ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "binding", "ScriptAction", "SCRIPT_PLUGIN"]
|
|
7
|
-
}
|