@dxos/plugin-script 0.7.5-main.499c70c → 0.7.5-main.5ae2ba8
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/ScriptContainer-3RFMYKTV.mjs +258 -0
- package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs +251 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs +15 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs.map +7 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs +475 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs.map +7 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs +40 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs +234 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs.map +7 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs +82 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +146 -289
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs +45 -0
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs +81 -0
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs.map +7 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs +24 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +6 -4
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs +274 -0
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs +267 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs.map +7 -0
- package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-5UH3F7TA.cjs} +11 -8
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → chunk-ALY3N6PW.cjs} +12 -8
- package/dist/lib/node/chunk-ALY3N6PW.cjs.map +7 -0
- package/dist/lib/node/{chunk-PK3OQP5L.cjs → chunk-DJGLGRQV.cjs} +26 -11
- package/dist/lib/node/chunk-DJGLGRQV.cjs.map +7 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
- package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs +261 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs.map +7 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs +498 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs.map +7 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs +104 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +138 -278
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs +59 -0
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-EGSE3FMN.cjs +96 -0
- package/dist/lib/node/react-surface-EGSE3FMN.cjs.map +7 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs +38 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs.map +7 -0
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs +259 -0
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs +252 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs +16 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs +476 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-P2V2Y5LV.mjs} +7 -4
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs +235 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs +41 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs +71 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs.map +7 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs +83 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +146 -289
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs +82 -0
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs.map +7 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs +25 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +6 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -3
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compiler.d.ts +4 -0
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings.d.ts +4 -0
- package/dist/types/src/capabilities/settings.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +10 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -0
- package/dist/types/src/components/{Toolbar/Toolbar.stories.d.ts → ScriptToolbar/ScriptToolbar.stories.d.ts} +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts +2 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/deploy.d.ts +48 -0
- package/dist/types/src/hooks/deploy.d.ts.map +1 -0
- package/dist/types/src/hooks/format.d.ts +25 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/template.d.ts +31 -0
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts +14 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts +10 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/hooks/view.d.ts +33 -0
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts +1 -4
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts +3 -0
- package/dist/types/src/templates/discord.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts +2 -1
- package/dist/types/src/templates/email.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +3 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -4
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/{templates.d.ts → templates/index.d.ts} +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +100 -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 +46 -46
- package/src/ScriptPlugin.tsx +80 -91
- package/src/capabilities/artifact-definition.ts +224 -0
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/compiler.ts +33 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +46 -0
- package/src/capabilities/react-surface.tsx +60 -0
- package/src/capabilities/settings.ts +14 -0
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +69 -9
- package/src/components/ScriptSettings/ScriptSettings.tsx +28 -4
- package/src/components/ScriptSettingsPanel.tsx +139 -51
- package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +53 -0
- package/src/{bundler → components/ScriptToolbar}/index.ts +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +75 -10
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/hooks/deploy.ts +169 -0
- package/src/hooks/format.ts +47 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/template.ts +64 -0
- package/src/hooks/useToolbarAction.ts +54 -0
- package/src/hooks/useToolbarState.ts +16 -0
- package/src/hooks/view.ts +55 -0
- package/src/index.ts +2 -7
- package/src/meta.ts +4 -2
- package/src/templates/chat.ts +4 -4
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/echo.ts +5 -1
- package/src/templates/email.ts +26 -23
- package/src/templates/forex-effect.ts +41 -0
- package/src/templates/forex.ts +23 -16
- package/src/{templates.ts → templates/index.ts} +20 -5
- package/src/translations.ts +26 -0
- package/src/types.ts +19 -18
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs +0 -78
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs +0 -415
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs.map +0 -7
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs +0 -286
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-C7VBULMK.mjs +0 -18
- package/dist/lib/browser/chunk-C7VBULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-K7KY6YMG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQA3EB5K.mjs +0 -26
- package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs +0 -104
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs +0 -426
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs.map +0 -7
- package/dist/lib/node/chunk-4INUJLXL.cjs.map +0 -7
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +0 -7
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +0 -7
- package/dist/lib/node/chunk-WPP65EYS.cjs +0 -298
- package/dist/lib/node/chunk-WPP65EYS.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs +0 -79
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs +0 -416
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs +0 -288
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +0 -27
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OFYGBUNI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -39
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +0 -17
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/index.d.ts +0 -4
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +0 -12
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +0 -6
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptEditor.d.ts +0 -9
- package/dist/types/src/components/ScriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/templates.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -54
- package/src/bundler/bundler.ts +0 -250
- package/src/components/AutomationPanel/AutomationPanel.tsx +0 -104
- package/src/components/AutomationPanel/index.ts +0 -9
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +0 -55
- package/src/components/ScriptBlock/ScriptBlock.tsx +0 -102
- package/src/components/ScriptBlock/index.ts +0 -5
- package/src/components/ScriptEditor.tsx +0 -193
- package/src/components/Toolbar/Toolbar.tsx +0 -177
- package/src/components/Toolbar/index.ts +0 -5
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';
|
|
8
|
+
import { ScriptType } from '@dxos/functions';
|
|
9
|
+
import { SettingsStore } from '@dxos/local-storage';
|
|
10
|
+
import { Clipboard } from '@dxos/react-ui';
|
|
11
|
+
|
|
12
|
+
import { ScriptCapabilities } from './capabilities';
|
|
13
|
+
import { DebugPanel, ScriptSettings, ScriptContainer, ScriptSettingsPanel } from '../components';
|
|
14
|
+
import { useDeployState, useToolbarState } from '../hooks';
|
|
15
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
16
|
+
import { type ScriptSettingsProps } from '../types';
|
|
17
|
+
|
|
18
|
+
export default () =>
|
|
19
|
+
contributes(Capabilities.ReactSurface, [
|
|
20
|
+
createSurface({
|
|
21
|
+
id: `${SCRIPT_PLUGIN}/settings`,
|
|
22
|
+
role: 'article',
|
|
23
|
+
filter: (data): data is { subject: SettingsStore<ScriptSettingsProps> } =>
|
|
24
|
+
data.subject instanceof SettingsStore && data.subject.prefix === SCRIPT_PLUGIN,
|
|
25
|
+
component: ({ data: { subject } }) => <ScriptSettings settings={subject.value} />,
|
|
26
|
+
}),
|
|
27
|
+
createSurface({
|
|
28
|
+
id: `${SCRIPT_PLUGIN}/article`,
|
|
29
|
+
role: 'article',
|
|
30
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
31
|
+
component: ({ data, role }) => {
|
|
32
|
+
const compiler = useCapability(ScriptCapabilities.Compiler);
|
|
33
|
+
// TODO(dmaretskyi): Since settings store is not reactive, this would break on the script plugin being enabled without a page reload.
|
|
34
|
+
const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)?.value;
|
|
35
|
+
return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
createSurface({
|
|
39
|
+
id: `${SCRIPT_PLUGIN}/automation`,
|
|
40
|
+
role: 'complementary--function',
|
|
41
|
+
position: 'hoist',
|
|
42
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
43
|
+
component: ({ data }) => {
|
|
44
|
+
// TODO(wittjosiah): Decouple hooks from toolbar state.
|
|
45
|
+
const state = useToolbarState({ view: 'editor' });
|
|
46
|
+
useDeployState({ state, script: data.subject });
|
|
47
|
+
return <DebugPanel functionUrl={state.functionUrl} />;
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
createSurface({
|
|
51
|
+
id: `${SCRIPT_PLUGIN}/settings-panel`,
|
|
52
|
+
role: 'complementary--settings',
|
|
53
|
+
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
54
|
+
component: ({ data }) => (
|
|
55
|
+
<Clipboard.Provider>
|
|
56
|
+
<ScriptSettingsPanel script={data.subject} />
|
|
57
|
+
</Clipboard.Provider>
|
|
58
|
+
),
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Capabilities, contributes } from '@dxos/app-framework';
|
|
6
|
+
import { create } from '@dxos/live-object';
|
|
7
|
+
|
|
8
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
9
|
+
import { ScriptSettingsSchema } from '../types';
|
|
10
|
+
|
|
11
|
+
export default () => {
|
|
12
|
+
const settings = create(ScriptSettingsSchema, { editorInputMode: 'vscode' });
|
|
13
|
+
return contributes(Capabilities.Settings, { schema: ScriptSettingsSchema, prefix: SCRIPT_PLUGIN, value: settings });
|
|
14
|
+
};
|
|
@@ -12,7 +12,7 @@ describe('Compiler', () => {
|
|
|
12
12
|
await compiler.initialize();
|
|
13
13
|
compiler.setFile('/src/x.ts', 'export const x = 100');
|
|
14
14
|
compiler.setFile('/src/y.ts', 'import { x } from "./x"; export const y = x + 100;');
|
|
15
|
-
const result =
|
|
15
|
+
const result = compiler.compile('/src/y.ts');
|
|
16
16
|
expect(result).to.exist;
|
|
17
17
|
});
|
|
18
18
|
});
|
|
@@ -7,7 +7,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
|
|
7
7
|
import { log } from '@dxos/log';
|
|
8
8
|
import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
10
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
+
import { errorText, mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
12
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
13
13
|
|
|
@@ -232,7 +232,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
|
|
|
232
232
|
const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
|
|
233
233
|
return (
|
|
234
234
|
<div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
|
|
235
|
-
{error && <div className={mx(wrapper, 'whitespace-pre
|
|
235
|
+
{error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
|
|
236
236
|
|
|
237
237
|
{text !== undefined && (
|
|
238
238
|
<div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
|
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
import React, { useEffect, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { clientServiceBundle } from '@dxos/client-protocol';
|
|
8
|
+
import { type BundleResult } from '@dxos/functions/bundler';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
8
10
|
import { log } from '@dxos/log';
|
|
9
11
|
import { useClient } from '@dxos/react-client';
|
|
10
12
|
import { baseSurface, mx } from '@dxos/react-ui-theme';
|
|
11
13
|
import { createProtoRpcPeer } from '@dxos/rpc';
|
|
12
14
|
import { createIFramePort } from '@dxos/rpc-tunnel';
|
|
13
15
|
|
|
14
|
-
import { type BundlerResult } from '../../bundler';
|
|
15
|
-
|
|
16
16
|
export type FrameContainerProps = {
|
|
17
17
|
containerUrl: string;
|
|
18
|
-
result:
|
|
18
|
+
result: BundleResult;
|
|
19
19
|
debug?: boolean;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -46,6 +46,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
|
|
|
46
46
|
}, [iframeRef]);
|
|
47
47
|
|
|
48
48
|
// Encodes compiled code via URL.
|
|
49
|
+
invariant(result.sourceHash, 'Source hash is required.');
|
|
49
50
|
const sourceHash = Buffer.from(result.sourceHash).toString('hex');
|
|
50
51
|
const src = result.bundle && `${containerUrl}?ts=${sourceHash}#code=${encodeURIComponent(result.bundle)}`;
|
|
51
52
|
|
|
@@ -58,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
|
|
|
58
59
|
<div
|
|
59
60
|
className={mx(
|
|
60
61
|
baseSurface,
|
|
61
|
-
'flex absolute right-2 bottom-2 w-[
|
|
62
|
+
'flex absolute right-2 bottom-2 w-[30rem] h-[200px] ring rounded',
|
|
62
63
|
'z-20 overflow-x-hidden overflow-y-auto',
|
|
63
64
|
)}
|
|
64
65
|
>
|
|
@@ -2,20 +2,80 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { type ScriptType } from '@dxos/functions';
|
|
8
|
+
import { createDocAccessor, getSpace } from '@dxos/react-client/echo';
|
|
9
|
+
import { useIdentity } from '@dxos/react-client/halo';
|
|
10
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
11
|
+
import { createDataExtensions, listener, stackItemContentEditorClassNames } from '@dxos/react-ui-editor';
|
|
12
|
+
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
13
|
import { mx } from '@dxos/react-ui-theme';
|
|
10
14
|
|
|
11
|
-
import {
|
|
15
|
+
import { DebugPanel } from './DebugPanel';
|
|
16
|
+
import { ScriptToolbar } from './ScriptToolbar';
|
|
17
|
+
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
18
|
+
import { useDeployState, useToolbarState } from '../hooks';
|
|
19
|
+
import { type ScriptSettingsProps } from '../types';
|
|
20
|
+
|
|
21
|
+
export type ScriptEditorProps = ThemedClassName<{
|
|
22
|
+
script: ScriptType;
|
|
23
|
+
settings?: ScriptSettingsProps;
|
|
24
|
+
role?: string;
|
|
25
|
+
}> &
|
|
26
|
+
Pick<TypescriptEditorProps, 'env'>;
|
|
27
|
+
|
|
28
|
+
export const ScriptContainer = ({
|
|
29
|
+
role,
|
|
30
|
+
classNames,
|
|
31
|
+
script,
|
|
32
|
+
settings = { editorInputMode: 'vscode' },
|
|
33
|
+
env,
|
|
34
|
+
}: ScriptEditorProps) => {
|
|
35
|
+
const identity = useIdentity();
|
|
36
|
+
const space = getSpace(script);
|
|
37
|
+
|
|
38
|
+
const extensions = useMemo(
|
|
39
|
+
() => [
|
|
40
|
+
listener({
|
|
41
|
+
onChange: (text) => {
|
|
42
|
+
if (script.source.target && script.source.target.content !== text) {
|
|
43
|
+
script.changed = true;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
createDataExtensions({
|
|
48
|
+
id: script.id,
|
|
49
|
+
text: script.source.target && createDocAccessor(script.source.target, ['content']),
|
|
50
|
+
space,
|
|
51
|
+
identity,
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
[script, script.source.target, space, identity],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const state = useToolbarState({ view: 'editor' });
|
|
58
|
+
useDeployState({ state, script });
|
|
12
59
|
|
|
13
|
-
const ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {
|
|
14
|
-
const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));
|
|
15
60
|
return (
|
|
16
|
-
<
|
|
17
|
-
<
|
|
18
|
-
|
|
61
|
+
<StackItem.Content toolbar>
|
|
62
|
+
<ScriptToolbar state={state} role={role} script={script} />
|
|
63
|
+
<div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>
|
|
64
|
+
{state.view !== 'debug' && (
|
|
65
|
+
<TypescriptEditor
|
|
66
|
+
id={script.id}
|
|
67
|
+
env={env}
|
|
68
|
+
initialValue={script.source?.target?.content}
|
|
69
|
+
extensions={extensions}
|
|
70
|
+
className={stackItemContentEditorClassNames(role)}
|
|
71
|
+
inputMode={settings.editorInputMode}
|
|
72
|
+
toolbar
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
|
|
76
|
+
{state.view !== 'editor' && <DebugPanel functionUrl={state.functionUrl} />}
|
|
77
|
+
</div>
|
|
78
|
+
</StackItem.Content>
|
|
19
79
|
);
|
|
20
80
|
};
|
|
21
81
|
|
|
@@ -6,8 +6,9 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
8
8
|
import { useClient } from '@dxos/react-client';
|
|
9
|
-
import { Button, useTranslation } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
9
|
+
import { Button, Select, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
|
|
11
|
+
import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
|
|
11
12
|
|
|
12
13
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
13
14
|
import { type ScriptSettingsProps } from '../../types';
|
|
@@ -38,10 +39,33 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
|
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
return (
|
|
41
|
-
|
|
42
|
+
<DeprecatedFormContainer>
|
|
43
|
+
{/* TODO(wittjosiah): Hide outside of dev environments. */}
|
|
42
44
|
<DeprecatedFormInput label={t('authenticate action label')}>
|
|
43
45
|
<Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
|
|
44
46
|
</DeprecatedFormInput>
|
|
45
|
-
|
|
47
|
+
|
|
48
|
+
<DeprecatedFormInput label={t('editor input mode label')}>
|
|
49
|
+
<Select.Root
|
|
50
|
+
value={settings.editorInputMode ?? 'default'}
|
|
51
|
+
onValueChange={(value) => {
|
|
52
|
+
settings.editorInputMode = value as EditorInputMode;
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Select.TriggerButton placeholder={t('select editor input mode placeholder')} />
|
|
56
|
+
<Select.Portal>
|
|
57
|
+
<Select.Content>
|
|
58
|
+
<Select.Viewport>
|
|
59
|
+
{EditorInputModes.map((mode) => (
|
|
60
|
+
<Select.Option key={mode} value={mode}>
|
|
61
|
+
{t(`settings editor input mode ${mode} label`)}
|
|
62
|
+
</Select.Option>
|
|
63
|
+
))}
|
|
64
|
+
</Select.Viewport>
|
|
65
|
+
</Select.Content>
|
|
66
|
+
</Select.Portal>
|
|
67
|
+
</Select.Root>
|
|
68
|
+
</DeprecatedFormInput>
|
|
69
|
+
</DeprecatedFormContainer>
|
|
46
70
|
);
|
|
47
71
|
};
|
|
@@ -2,33 +2,62 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { Octokit } from '@octokit/core';
|
|
6
|
+
import React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';
|
|
6
7
|
|
|
8
|
+
import { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
7
9
|
import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
10
|
+
import { log } from '@dxos/log';
|
|
8
11
|
import { useClient } from '@dxos/react-client';
|
|
9
12
|
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
10
|
-
import { Button,
|
|
13
|
+
import { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { AccessTokenType } from '@dxos/schema';
|
|
11
15
|
|
|
12
16
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
13
17
|
|
|
18
|
+
// TODO(wittjosiah): Factor out.
|
|
19
|
+
// From https://stackoverflow.com/a/67243723/2804332
|
|
20
|
+
const kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
21
|
+
|
|
14
22
|
export type ScriptSettingsPanelProps = {
|
|
15
23
|
script: ScriptType;
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
19
27
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
28
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
20
29
|
const client = useClient();
|
|
21
30
|
const space = getSpace(script);
|
|
22
31
|
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));
|
|
32
|
+
const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));
|
|
33
|
+
const gistKey = getMeta(script).keys.find(({ source }) => source === 'github.com');
|
|
34
|
+
const [gistUrl, setGistUrl] = useState<string | undefined>();
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const token = githubToken?.token;
|
|
38
|
+
const gistId = gistKey?.id;
|
|
39
|
+
if (!token || !gistId) {
|
|
40
|
+
setGistUrl(undefined);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const timeout = setTimeout(async () => {
|
|
45
|
+
try {
|
|
46
|
+
const octokit = new Octokit({ auth: githubToken.token });
|
|
47
|
+
const response = await octokit.request('GET /gists/{gist_id}', {
|
|
48
|
+
gist_id: gistId,
|
|
49
|
+
});
|
|
50
|
+
setGistUrl(response.data.html_url);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
log.catch(err);
|
|
53
|
+
setGistUrl(undefined);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return () => clearTimeout(timeout);
|
|
58
|
+
}, [githubToken, gistKey]);
|
|
30
59
|
|
|
31
|
-
const [binding, setBinding] =
|
|
60
|
+
const [binding, setBinding] = useControlledState(fn?.binding ?? '');
|
|
32
61
|
const handleBindingChange = useCallback(
|
|
33
62
|
(event: ChangeEvent<HTMLInputElement>) => {
|
|
34
63
|
setBinding(event.target.value);
|
|
@@ -46,55 +75,114 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
|
46
75
|
spaceId: space?.id,
|
|
47
76
|
});
|
|
48
77
|
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
const handleOpenTokenManager = useCallback(
|
|
79
|
+
() => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),
|
|
80
|
+
[],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const [publishing, setPublishing] = useState(false);
|
|
84
|
+
const handlePublish = useCallback(async () => {
|
|
85
|
+
setPublishing(true);
|
|
86
|
+
const octokit = new Octokit({ auth: githubToken.token });
|
|
87
|
+
const source = await script.source.load();
|
|
88
|
+
const filename = script.name ? kebabize(script.name) : 'composer-script';
|
|
89
|
+
const files = { [`${filename}.ts`]: { content: source.content } };
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// TODO(wittjosiah): Factor out to intent.
|
|
93
|
+
const meta = getMeta(script);
|
|
94
|
+
const githubKey = meta.keys.find(({ source }) => source === 'github.com');
|
|
95
|
+
const gistId = githubKey?.id;
|
|
96
|
+
if (gistId) {
|
|
97
|
+
await octokit.request('PATCH /gists/{gist_id}', {
|
|
98
|
+
gist_id: gistId,
|
|
99
|
+
files,
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
const response = await octokit.request('POST /gists', {
|
|
103
|
+
public: true,
|
|
104
|
+
files,
|
|
105
|
+
});
|
|
106
|
+
if (response.data.id) {
|
|
107
|
+
meta.keys.push({ source: 'github.com', id: response.data.id });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
setPublishing(false);
|
|
112
|
+
}
|
|
113
|
+
}, [script, githubToken]);
|
|
51
114
|
|
|
52
115
|
return (
|
|
53
|
-
|
|
54
|
-
<
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
116
|
+
<>
|
|
117
|
+
<div role='form' className='flex flex-col w-full p-2 gap-4'>
|
|
118
|
+
<Input.Root>
|
|
119
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
120
|
+
<Input.Label>{t('description label')}</Input.Label>
|
|
121
|
+
<Input.TextInput
|
|
122
|
+
placeholder={t('description placeholder')}
|
|
123
|
+
value={script.description ?? ''}
|
|
124
|
+
onChange={(event) => {
|
|
125
|
+
script.description = event.target.value;
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
</div>
|
|
129
|
+
</Input.Root>
|
|
130
|
+
</div>
|
|
131
|
+
{fn && functionUrl && (
|
|
65
132
|
<>
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
<
|
|
71
|
-
|
|
133
|
+
<Separator />
|
|
134
|
+
<div role='form' className='flex flex-col w-full p-2 gap-4'>
|
|
135
|
+
<h2>{t('remote function settings heading')}</h2>
|
|
136
|
+
<Input.Root>
|
|
137
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
138
|
+
<Input.Label>{t('function url label')}</Input.Label>
|
|
139
|
+
<div role='none' className='flex gap-1'>
|
|
140
|
+
<Input.TextInput
|
|
141
|
+
disabled
|
|
142
|
+
value={functionUrl}
|
|
143
|
+
onChange={(event) => {
|
|
144
|
+
fn.name = event.target.value;
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
<Clipboard.IconButton value={functionUrl} />
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</Input.Root>
|
|
151
|
+
<Input.Root>
|
|
152
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
153
|
+
<Input.Label>{t('function binding label')}</Input.Label>
|
|
72
154
|
<Input.TextInput
|
|
73
|
-
|
|
74
|
-
value={
|
|
75
|
-
onChange={
|
|
76
|
-
|
|
77
|
-
}}
|
|
155
|
+
placeholder={t('function binding placeholder')}
|
|
156
|
+
value={binding}
|
|
157
|
+
onChange={handleBindingChange}
|
|
158
|
+
onBlur={handleBindingBlur}
|
|
78
159
|
/>
|
|
79
|
-
<Button onClick={handleCopy}>
|
|
80
|
-
<Icon icon='ph--copy--regular' size={4} />
|
|
81
|
-
</Button>
|
|
82
160
|
</div>
|
|
83
|
-
</
|
|
84
|
-
</
|
|
85
|
-
<Input.Root>
|
|
86
|
-
<div role='none' className='flex flex-col gap-1'>
|
|
87
|
-
<Input.Label>{t('function binding label')}</Input.Label>
|
|
88
|
-
<Input.TextInput
|
|
89
|
-
placeholder={t('function binding placeholder')}
|
|
90
|
-
value={binding}
|
|
91
|
-
onChange={handleBindingChange}
|
|
92
|
-
onBlur={handleBindingBlur}
|
|
93
|
-
/>
|
|
94
|
-
</div>
|
|
95
|
-
</Input.Root>
|
|
161
|
+
</Input.Root>
|
|
162
|
+
</div>
|
|
96
163
|
</>
|
|
97
164
|
)}
|
|
98
|
-
|
|
165
|
+
<Separator />
|
|
166
|
+
<div className='flex flex-col w-full p-2 gap-4'>
|
|
167
|
+
<div>
|
|
168
|
+
<h2>{t('script publish settings label')}</h2>
|
|
169
|
+
<p className='text-description text-sm'>{t('script publish settings description')}</p>
|
|
170
|
+
</div>
|
|
171
|
+
{!githubToken && (
|
|
172
|
+
<div className='flex flex-col items-center justify-center gap-2'>
|
|
173
|
+
<span>{t('no github token label')}</span>
|
|
174
|
+
<Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
177
|
+
{githubToken && (
|
|
178
|
+
<div className='flex justify-end gap-2'>
|
|
179
|
+
{gistUrl && <Clipboard.IconButton value={gistUrl} />}
|
|
180
|
+
<Button disabled={publishing} onClick={handlePublish}>
|
|
181
|
+
{t(publishing ? 'publishing label' : 'publish label')}
|
|
182
|
+
</Button>
|
|
183
|
+
</div>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
</>
|
|
99
187
|
);
|
|
100
188
|
};
|
package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx}
RENAMED
|
@@ -8,7 +8,7 @@ import { type Meta } from '@storybook/react';
|
|
|
8
8
|
|
|
9
9
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { ScriptToolbar } from './ScriptToolbar';
|
|
12
12
|
import { templates } from '../../templates';
|
|
13
13
|
|
|
14
14
|
export const Default = {
|
|
@@ -23,7 +23,7 @@ export const Default = {
|
|
|
23
23
|
|
|
24
24
|
const meta: Meta = {
|
|
25
25
|
title: 'plugins/plugin-script/Toolbar',
|
|
26
|
-
component:
|
|
26
|
+
component: ScriptToolbar,
|
|
27
27
|
decorators: [withTheme, withLayout({ tooltips: true })],
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type ScriptType } from '@dxos/functions';
|
|
8
|
+
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
9
|
+
import { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';
|
|
11
|
+
import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
type ScriptToolbarState,
|
|
15
|
+
createDeploy,
|
|
16
|
+
createFormat,
|
|
17
|
+
createTemplateSelect,
|
|
18
|
+
createView,
|
|
19
|
+
useToolbarAction,
|
|
20
|
+
} from '../../hooks';
|
|
21
|
+
|
|
22
|
+
export type ScriptToolbarProps = ThemedClassName<{
|
|
23
|
+
role?: string;
|
|
24
|
+
script: ScriptType;
|
|
25
|
+
state: ScriptToolbarState;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
const createToolbar = (state: ScriptToolbarState) => {
|
|
29
|
+
const templateSelect = createTemplateSelect();
|
|
30
|
+
const format = createFormat();
|
|
31
|
+
const gap = createGapSeparator();
|
|
32
|
+
const deploy = createDeploy(state);
|
|
33
|
+
const view = createView(state);
|
|
34
|
+
return {
|
|
35
|
+
nodes: [...templateSelect.nodes, ...format.nodes, ...gap.nodes, ...deploy.nodes, ...view.nodes],
|
|
36
|
+
edges: [...templateSelect.edges, ...format.edges, ...gap.edges, ...deploy.edges, ...view.edges],
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const ScriptToolbar = ({ script, role, state, classNames }: ScriptToolbarProps) => {
|
|
41
|
+
const handleAction = useToolbarAction({ state, script });
|
|
42
|
+
const toolbarCreator = useCallback(() => createToolbar(state), [state]);
|
|
43
|
+
const menu = useMenuActions(toolbarCreator);
|
|
44
|
+
return (
|
|
45
|
+
<div role='none' className={stackItemContentToolbarClassNames(role)}>
|
|
46
|
+
<ElevationProvider elevation={role === 'section' ? 'positioned' : 'base'}>
|
|
47
|
+
<MenuProvider {...menu} onAction={handleAction} attendableId={fullyQualifiedId(script)}>
|
|
48
|
+
<ToolbarMenu classNames={classNames} />
|
|
49
|
+
</MenuProvider>
|
|
50
|
+
</ElevationProvider>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -9,6 +9,7 @@ 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
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
12
13
|
|
|
13
14
|
import { TypescriptEditor } from './TypescriptEditor';
|
|
14
15
|
import { templates } from '../../templates';
|
|
@@ -37,6 +38,7 @@ const meta: Meta = {
|
|
|
37
38
|
title: 'plugins/plugin-script/TypescriptEditor',
|
|
38
39
|
component: TypescriptEditor,
|
|
39
40
|
render: DefaultStory,
|
|
41
|
+
decorators: [withTheme],
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
export default meta;
|