@dxos/plugin-script 0.6.14-main.f49f251 → 0.6.14-staging.77003c1
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-MDPZ5WAC.mjs → AutomationPanel-XLL2ZXGS.mjs} +4 -4
- package/dist/lib/browser/{ScriptContainer-B3CPWXRE.mjs → ScriptContainer-YXH4MFEO.mjs} +8 -16
- package/dist/lib/browser/{ScriptContainer-B3CPWXRE.mjs.map → ScriptContainer-YXH4MFEO.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-SGQHRB4P.mjs → chunk-C7VBULMK.mjs} +4 -3
- package/dist/lib/browser/{chunk-SGQHRB4P.mjs.map → chunk-C7VBULMK.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-G66MXS4T.mjs → chunk-NCZUJKJE.mjs} +6 -18
- package/dist/lib/browser/chunk-NCZUJKJE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KXVQPS4Y.mjs → chunk-USXWNH3S.mjs} +2 -2
- package/dist/lib/browser/index.mjs +105 -12
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/{AutomationPanel-SANUE5X4.cjs → AutomationPanel-OSPAFWZU.cjs} +12 -12
- package/dist/lib/node/{ScriptContainer-BV7HMUY5.cjs → ScriptContainer-FWHFEIHK.cjs} +16 -24
- package/dist/lib/node/{ScriptContainer-BV7HMUY5.cjs.map → ScriptContainer-FWHFEIHK.cjs.map} +3 -3
- package/dist/lib/node/{chunk-EJC55SDD.cjs → chunk-6LYX73ZT.cjs} +7 -6
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +7 -0
- package/dist/lib/node/{chunk-JWKMTYYH.cjs → chunk-BJ4WIWCP.cjs} +9 -21
- package/dist/lib/node/chunk-BJ4WIWCP.cjs.map +7 -0
- package/dist/lib/node/{chunk-25PQE7FL.cjs → chunk-CPNHUAFN.cjs} +6 -6
- package/dist/lib/node/index.cjs +117 -28
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +5 -5
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{AutomationPanel-H2IKE53E.mjs → AutomationPanel-KJNL6ARP.mjs} +4 -4
- package/dist/lib/node-esm/{ScriptContainer-HSIOGVP3.mjs → ScriptContainer-6U5WJFRB.mjs} +8 -16
- package/dist/lib/node-esm/{ScriptContainer-HSIOGVP3.mjs.map → ScriptContainer-6U5WJFRB.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-7EDYDVQH.mjs → chunk-2NPZGQGA.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-3QHVR4VV.mjs → chunk-DXWSRDEN.mjs} +6 -18
- package/dist/lib/node-esm/chunk-DXWSRDEN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-GO7HYFM5.mjs → chunk-SLTZMY34.mjs} +4 -3
- package/dist/lib/node-esm/{chunk-GO7HYFM5.mjs.map → chunk-SLTZMY34.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +105 -12
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +1 -1
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -4
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +7 -0
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +5 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/ScriptPlugin.tsx +10 -2
- package/src/components/DebugPanel/DebugPanel.tsx +2 -29
- package/src/components/ScriptEditor.tsx +1 -15
- package/src/components/ScriptSettings/ScriptSettings.tsx +3 -3
- package/src/components/ScriptSettingsPanel.tsx +105 -0
- package/src/components/index.ts +1 -0
- package/src/meta.ts +2 -1
- package/src/translations.ts +5 -0
- package/dist/lib/browser/chunk-G66MXS4T.mjs.map +0 -7
- package/dist/lib/node/chunk-EJC55SDD.cjs.map +0 -7
- package/dist/lib/node/chunk-JWKMTYYH.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-3QHVR4VV.mjs.map +0 -7
- /package/dist/lib/browser/{AutomationPanel-MDPZ5WAC.mjs.map → AutomationPanel-XLL2ZXGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-KXVQPS4Y.mjs.map → chunk-USXWNH3S.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-SANUE5X4.cjs.map → AutomationPanel-OSPAFWZU.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-25PQE7FL.cjs.map → chunk-CPNHUAFN.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-H2IKE53E.mjs.map → AutomationPanel-KJNL6ARP.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-7EDYDVQH.mjs.map → chunk-2NPZGQGA.mjs.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DebugPanel
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NCZUJKJE.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getInvocationUrl,
|
|
6
6
|
getUserFunctionUrlInMetadata
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
FunctionType,
|
|
10
10
|
ScriptType
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-USXWNH3S.mjs";
|
|
12
|
+
import "./chunk-C7VBULMK.mjs";
|
|
13
13
|
|
|
14
14
|
// packages/plugins/experimental/plugin-script/src/components/AutomationPanel/AutomationPanel.tsx
|
|
15
15
|
import React, { useMemo, useState } from "react";
|
|
@@ -75,4 +75,4 @@ export {
|
|
|
75
75
|
AutomationPanel,
|
|
76
76
|
AutomationPanel_default as default
|
|
77
77
|
};
|
|
78
|
-
//# sourceMappingURL=AutomationPanel-
|
|
78
|
+
//# sourceMappingURL=AutomationPanel-XLL2ZXGS.mjs.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-G6H56WFS.mjs";
|
|
5
5
|
import {
|
|
6
6
|
DebugPanel
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NCZUJKJE.mjs";
|
|
8
8
|
import {
|
|
9
9
|
USERFUNCTIONS_PRESET_META_KEY,
|
|
10
10
|
getInvocationUrl,
|
|
@@ -15,10 +15,10 @@ import {
|
|
|
15
15
|
} from "./chunk-KHNN3F7J.mjs";
|
|
16
16
|
import {
|
|
17
17
|
FunctionType
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-USXWNH3S.mjs";
|
|
19
19
|
import {
|
|
20
20
|
SCRIPT_PLUGIN
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-C7VBULMK.mjs";
|
|
22
22
|
|
|
23
23
|
// packages/plugins/experimental/plugin-script/src/components/ScriptContainer.tsx
|
|
24
24
|
import React4 from "react";
|
|
@@ -255,11 +255,6 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
255
255
|
]);
|
|
256
256
|
const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
257
257
|
const [error, setError] = useState2();
|
|
258
|
-
const handleBindingChange = useCallback((binding) => {
|
|
259
|
-
fn.binding = binding;
|
|
260
|
-
}, [
|
|
261
|
-
fn
|
|
262
|
-
]);
|
|
263
258
|
const handleFormat = useCallback(async () => {
|
|
264
259
|
if (!script.source) {
|
|
265
260
|
return;
|
|
@@ -277,7 +272,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
277
272
|
} catch (err) {
|
|
278
273
|
log.catch(err, void 0, {
|
|
279
274
|
F: __dxlog_file,
|
|
280
|
-
L:
|
|
275
|
+
L: 89,
|
|
281
276
|
S: void 0,
|
|
282
277
|
C: (f, a) => f(...a)
|
|
283
278
|
});
|
|
@@ -335,7 +330,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
335
330
|
functionVersionNumber
|
|
336
331
|
}, {
|
|
337
332
|
F: __dxlog_file,
|
|
338
|
-
L:
|
|
333
|
+
L: 137,
|
|
339
334
|
S: void 0,
|
|
340
335
|
C: (f, a) => f(...a)
|
|
341
336
|
});
|
|
@@ -353,7 +348,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
353
348
|
} catch (err) {
|
|
354
349
|
log.catch(err, void 0, {
|
|
355
350
|
F: __dxlog_file,
|
|
356
|
-
L:
|
|
351
|
+
L: 149,
|
|
357
352
|
S: void 0,
|
|
358
353
|
C: (f, a) => f(...a)
|
|
359
354
|
});
|
|
@@ -397,10 +392,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
397
392
|
extensions,
|
|
398
393
|
className: "flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all"
|
|
399
394
|
}), view !== "editor" && /* @__PURE__ */ React3.createElement(DebugPanel, {
|
|
400
|
-
functionUrl
|
|
401
|
-
showBindingConfig: true,
|
|
402
|
-
binding: fn?.binding,
|
|
403
|
-
onBindingChange: handleBindingChange
|
|
395
|
+
functionUrl
|
|
404
396
|
}));
|
|
405
397
|
};
|
|
406
398
|
|
|
@@ -420,4 +412,4 @@ var ScriptContainer_default = ScriptContainer;
|
|
|
420
412
|
export {
|
|
421
413
|
ScriptContainer_default as default
|
|
422
414
|
};
|
|
423
|
-
//# sourceMappingURL=ScriptContainer-
|
|
415
|
+
//# sourceMappingURL=ScriptContainer-YXH4MFEO.mjs.map
|
package/dist/lib/browser/{ScriptContainer-B3CPWXRE.mjs.map → ScriptContainer-YXH4MFEO.mjs.map}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { type DID } from 'iso-did/types';\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 publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n USERFUNCTIONS_PRESET_META_KEY,\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 // TODO(dmaretskyi): Parametric query.\n const [fn] = useQuery(\n space,\n Filter.schema(FunctionType, (fn) => fn.source === script),\n );\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 initialValue = useMemo(() => script.source?.content, [script.source]);\n const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const [error, setError] = useState<string>();\n\n const handleBindingChange = useCallback(\n (binding: string) => {\n fn.binding = binding;\n },\n [fn],\n );\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 === USERFUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: USERFUNCTIONS_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 const ownerDid = (existingFunctionUrl?.split('/').at(-2) as DID) ?? publicKeyToDid(identity.identityKey);\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 { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({\n clientConfig: client.config,\n halo: client.halo,\n ownerDid,\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {\n throw new Error(errorMessage);\n }\n\n log.info('function uploaded', { functionId, functionVersionNumber });\n if (fn) {\n fn.version = functionVersionNumber;\n }\n\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));\n const meta = getMeta(deployedFunction);\n script.changed = false;\n setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);\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]);\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={initialValue}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'\n />\n )}\n\n {view !== 'editor' && (\n <DebugPanel\n functionUrl={functionUrl}\n showBindingConfig\n binding={fn?.binding}\n onBindingChange={handleBindingChange}\n />\n )}\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, initialValue, 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;;;ACHnB,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;;;ACZnB,OAAOC,SAASC,gBAAgB;AAEhC,SACEC,mBACAC,MACAC,QAEAC,aACAC,iBAEAC,WAAWC,gBACXC,SACAC,sBACK;AAgBA,IAAMC,UAAU,CAAC,EACtBC,YACAC,UACAC,OACAC,aACAC,MACAC,WAAAA,YACAC,UACAC,UACAC,cACAC,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D;GAAS;AAGhE,SAAO,gBAAAmC,OAAA,cAACC,OAAAA;IAAIC,KAAKjC;IAAWP;IAAuB,GAAGQ;;AACxD;;;;AFrCO,IAAMiC,eAAe,CAAC,EAAEC,YAAYC,QAAQC,IAAG,MAAqB;AACzE,QAAM,EAAEC,EAAC,IAAKC,gBAAeC,aAAAA;AAC7B,QAAMC,SAASC,UAAAA;AACf,QAAMC,WAAWC,YAAAA;AACjB,QAAMC,QAAQC,SAASV,MAAAA;AAEvB,QAAM,CAACW,EAAAA,IAAMC,SACXH,OACAI,OAAOC,OAAOC,cAAc,CAACJ,QAAOA,IAAGK,WAAWhB,MAAAA,CAAAA;AAGpD,QAAMiB,aAAaC,QACjB,MAAM;IACJC,SAAS;MACPC,UAAU,CAACC,SAAAA;AACT,YAAIrB,OAAOgB,UAAUhB,OAAOgB,QAAQM,YAAYD,MAAM;AACpDrB,iBAAOuB,UAAU;QACnB;MACF;IACF,CAAA;IACAC,qBAAqB;MACnBC,IAAIzB,OAAOyB;MACXJ,MAAMrB,OAAOgB,UAAUU,kBAAkB1B,OAAOgB,QAAQ;QAAC;OAAU;MACnEP;MACAF;IACF,CAAA;KAEF;IAACP;IAAQA,OAAOgB;IAAQP;IAAOF;GAAS;AAG1C,QAAM,CAACoB,MAAMC,OAAAA,IAAWC,UAAmB,QAAA;AAC3C,QAAMC,eAAeZ,QAAQ,MAAMlB,OAAOgB,QAAQM,SAAS;IAACtB,OAAOgB;GAAO;AAC1E,QAAMe,sBAAsBpB,MAAMqB,6BAA6BC,QAAQtB,EAAAA,CAAAA;AACvE,QAAM,CAACuB,OAAOC,QAAAA,IAAYN,UAAAA;AAE1B,QAAMO,
|
|
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", "initialValue", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "error", "setError", "
|
|
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 { type DID } from 'iso-did/types';\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 publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n USERFUNCTIONS_PRESET_META_KEY,\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 // TODO(dmaretskyi): Parametric query.\n const [fn] = useQuery(\n space,\n Filter.schema(FunctionType, (fn) => fn.source === script),\n );\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 initialValue = useMemo(() => script.source?.content, [script.source]);\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 === USERFUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: USERFUNCTIONS_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 const ownerDid = (existingFunctionUrl?.split('/').at(-2) as DID) ?? publicKeyToDid(identity.identityKey);\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 { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({\n clientConfig: client.config,\n halo: client.halo,\n ownerDid,\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {\n throw new Error(errorMessage);\n }\n\n log.info('function uploaded', { functionId, functionVersionNumber });\n if (fn) {\n fn.version = functionVersionNumber;\n }\n\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));\n const meta = getMeta(deployedFunction);\n script.changed = false;\n setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);\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]);\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={initialValue}\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, initialValue, 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;;;ACHnB,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;;;ACZnB,OAAOC,SAASC,gBAAgB;AAEhC,SACEC,mBACAC,MACAC,QAEAC,aACAC,iBAEAC,WAAWC,gBACXC,SACAC,sBACK;AAgBA,IAAMC,UAAU,CAAC,EACtBC,YACAC,UACAC,OACAC,aACAC,MACAC,WAAAA,YACAC,UACAC,UACAC,cACAC,iBAAgB,MACH;AACb,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAS,KAAA;AAEvC,QAAMC,iBAAiB,YAAA;AACrB,QAAI,CAACb,aAAa;AAChB;IACF;AAEA,UAAMc,UAAUC,UAAUC,UAAUhB,WAAAA;EACtC;AAEA,QAAMiB,eAAe,YAAA;AACnB,QAAI,CAACP,SAAS;AACZC,iBAAW,IAAA;AACX,YAAMR,WAAAA;AACNQ,iBAAW,KAAA;IACb;EACF;AAGA,SACE,sBAAA,cAACO,mBAAAA;IAAkBC,WAAU;KAC3B,sBAAA,cAACC,eAAeC,MAAI;IAACxB,YAAY;MAAC;MAAOA;;IAAayB,OAAO;MAAEC,SAAS;IAAS;KAC9ErB,cAAa,sBAAA,cAACsB,gBAAAA;IAAetB,WAAWA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
"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", "initialValue", "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", "USERFUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "handleDeploy", "undefined", "existingFunctionId", "split", "at", "ownerDid", "publicKeyToDid", "identityKey", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "result", "functionId", "functionVersionNumber", "errorMessage", "uploadWorkerFunction", "clientConfig", "config", "halo", "Error", "info", "version", "deployedFunction", "db", "add", "create", "meta", "setUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "values", "runtime", "services", "edge", "url", "spaceId", "React", "div", "role", "className", "mx", "Toolbar", "deployed", "Boolean", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "TypescriptEditor", "DebugPanel", "ScriptContainer", "script", "props", "attendableAttrs", "useAttendableAttributes", "fullyQualifiedId", "React", "div", "role", "className", "mx", "ScriptEditor"]
|
|
7
7
|
}
|
|
@@ -4,14 +4,15 @@ var meta_default = {
|
|
|
4
4
|
id: SCRIPT_PLUGIN,
|
|
5
5
|
name: "Scripts",
|
|
6
6
|
description: "Distributed functions.",
|
|
7
|
+
icon: "ph--code--regular",
|
|
8
|
+
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer",
|
|
7
9
|
tags: [
|
|
8
10
|
"experimental"
|
|
9
|
-
]
|
|
10
|
-
icon: "ph--code--regular"
|
|
11
|
+
]
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
export {
|
|
14
15
|
SCRIPT_PLUGIN,
|
|
15
16
|
meta_default
|
|
16
17
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
18
|
+
//# sourceMappingURL=chunk-C7VBULMK.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const SCRIPT_PLUGIN = 'dxos.org/plugin/script';\n\nexport default {\n id: SCRIPT_PLUGIN,\n name: 'Scripts',\n description: 'Distributed functions.',\n
|
|
5
|
-
"mappings": ";AAMO,IAAMA,gBAAgB;AAE7B,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;EACNC,aAAa;EACbC,MAAM;
|
|
6
|
-
"names": ["SCRIPT_PLUGIN", "id", "name", "description", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const SCRIPT_PLUGIN = 'dxos.org/plugin/script';\n\nexport default {\n id: SCRIPT_PLUGIN,\n name: 'Scripts',\n description: 'Distributed functions.',\n icon: 'ph--code--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',\n tags: ['experimental'],\n} satisfies PluginMeta;\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAMA,gBAAgB;AAE7B,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;EACNC,aAAa;EACbC,MAAM;EACNC,QAAQ;EACRC,MAAM;IAAC;;AACT;",
|
|
6
|
+
"names": ["SCRIPT_PLUGIN", "id", "name", "description", "icon", "source", "tags"]
|
|
7
7
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SCRIPT_PLUGIN
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C7VBULMK.mjs";
|
|
4
4
|
|
|
5
5
|
// packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx
|
|
6
6
|
import React, { useEffect, useRef, useState } from "react";
|
|
7
7
|
import { log } from "@dxos/log";
|
|
8
|
-
import { Avatar, Icon, Input, Toolbar,
|
|
8
|
+
import { Avatar, Icon, Input, Toolbar, useTranslation } from "@dxos/react-ui";
|
|
9
9
|
import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
|
|
10
10
|
import { mx } from "@dxos/react-ui-theme";
|
|
11
11
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx";
|
|
12
|
-
var DebugPanel = ({ classNames, functionUrl
|
|
12
|
+
var DebugPanel = ({ classNames, functionUrl }) => {
|
|
13
13
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
14
|
-
const bindingInputRef = useRef(null);
|
|
15
|
-
const [binding, setBinding] = useControlledValue(_binding ?? "");
|
|
16
|
-
const handleBlur = () => {
|
|
17
|
-
onBindingChange?.(binding);
|
|
18
|
-
};
|
|
19
14
|
const inputRef = useRef(null);
|
|
20
15
|
const [input, setInput] = useState("");
|
|
21
16
|
const [result, setResult] = useState("");
|
|
@@ -130,7 +125,7 @@ var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange,
|
|
|
130
125
|
if (err.name !== "AbortError") {
|
|
131
126
|
log.catch(err, void 0, {
|
|
132
127
|
F: __dxlog_file,
|
|
133
|
-
L:
|
|
128
|
+
L: 146,
|
|
134
129
|
S: void 0,
|
|
135
130
|
C: (f, a) => f(...a)
|
|
136
131
|
});
|
|
@@ -144,7 +139,7 @@ var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange,
|
|
|
144
139
|
});
|
|
145
140
|
log.catch(err, void 0, {
|
|
146
141
|
F: __dxlog_file,
|
|
147
|
-
L:
|
|
142
|
+
L: 153,
|
|
148
143
|
S: void 0,
|
|
149
144
|
C: (f, a) => f(...a)
|
|
150
145
|
});
|
|
@@ -171,13 +166,6 @@ var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange,
|
|
|
171
166
|
value: input,
|
|
172
167
|
onChange: (ev) => setInput(ev.target.value),
|
|
173
168
|
onKeyDown: (ev) => ev.key === "Enter" && handleRequest(input)
|
|
174
|
-
})), showBindingConfig && /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
175
|
-
ref: bindingInputRef,
|
|
176
|
-
classNames: "!w-[10rem]",
|
|
177
|
-
placeholder: t("binding placeholder"),
|
|
178
|
-
value: binding,
|
|
179
|
-
onChange: (ev) => setBinding(ev.target.value.toUpperCase()),
|
|
180
|
-
onBlur: handleBlur
|
|
181
169
|
})), /* @__PURE__ */ React.createElement(Toolbar.Button, {
|
|
182
170
|
onClick: () => handleRequest(input)
|
|
183
171
|
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
@@ -245,4 +233,4 @@ var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
|
|
|
245
233
|
export {
|
|
246
234
|
DebugPanel
|
|
247
235
|
};
|
|
248
|
-
//# sourceMappingURL=chunk-
|
|
236
|
+
//# sourceMappingURL=chunk-NCZUJKJE.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/DebugPanel/DebugPanel.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport { log } from '@dxos/log';\nimport { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';\nimport { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\n\ntype State = 'pending' | 'responding';\n\n/**\n * Request or response.\n */\ntype Message = { type: 'request' | 'response'; text?: string; data?: any; error?: Error };\n\nexport type DebugPanelProps = ThemedClassName<{\n functionUrl?: string;\n}>;\n\nexport const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [input, setInput] = useState('');\n const [result, setResult] = useState('');\n const [state, setState] = useState<State | null>(null);\n\n // TODO(burdon): Persistent history -- at least for session (non-space ECHO data?)\n const [history, setHistory] = useState<Message[]>([]);\n\n const scrollerRef = useRef<HTMLDivElement>(null);\n const handleScroll = () => {\n if (scrollerRef.current) {\n scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;\n }\n };\n\n const controller = useRef<AbortController>();\n useEffect(() => {\n return () => {\n handleStop();\n };\n }, []);\n\n const handleStop = () => {\n controller.current?.abort('stop');\n controller.current = undefined;\n };\n\n const handleClear = () => {\n handleStop();\n setInput('');\n setResult('');\n setHistory([]);\n inputRef.current?.focus();\n };\n\n const handleResponse = ({ text, data, error }: { text?: string; data?: any; error?: Error } = {}) => {\n controller.current = undefined;\n setHistory((history) => [...history, { type: 'response', text, data, error } satisfies Message]);\n setResult('');\n setState(null);\n handleScroll();\n };\n\n const handleRequest = async (input: string) => {\n // Returns a promise that resolves when a value has been received.\n try {\n setState('pending');\n\n let data = null;\n // Detect JSON input.\n if (input.charAt(0) === '{') {\n try {\n const validJsonString = input.replace(/'/g, '\"').replace(/([{,]\\s*)([a-zA-Z0-9_]+)(\\s*:)/g, '$1\"$2\"$3');\n data = JSON.parse(validJsonString);\n input = JSON.stringify(data, null, 2);\n } catch (err) {\n inputRef.current?.focus();\n return;\n }\n }\n\n setInput('');\n setResult('');\n setHistory((history) => [...history, { type: 'request', text: input }]);\n setTimeout(() => {\n handleScroll();\n });\n\n // Throws DOMException when aborted.\n controller.current = new AbortController();\n const response = await fetch(functionUrl!, {\n signal: controller.current.signal,\n method: 'POST',\n body: input,\n headers: {\n 'Content-Type': data ? 'application/json' : 'text/plain',\n },\n });\n\n // Check for error.\n if (!response.ok) {\n const text = await response.text();\n handleResponse({ error: new Error(text || response.statusText || String(response.status)) });\n return;\n }\n\n // Check for JSON.\n const contentType = response.headers.get('content-type');\n if (contentType === 'application/json') {\n const data = await response.json();\n handleResponse({ data });\n return;\n }\n\n // Text (including streaming).\n setState('responding');\n let text = '';\n const reader = response.body!.getReader();\n const pump = async ({ done, value }: ReadableStreamReadResult<Uint8Array>): Promise<void> => {\n text = text + new TextDecoder().decode(value);\n if (!controller.current || done) {\n handleResponse({ text });\n return;\n }\n\n setResult(text);\n setTimeout(() => {\n handleScroll();\n });\n\n return reader.read().then(pump);\n };\n\n void reader\n .read()\n .then(pump)\n .catch((err) => {\n if (err.name !== 'AbortError') {\n log.catch(err);\n }\n });\n } catch (err: any) {\n if (err !== 'stop') {\n const error = err instanceof Error ? err : new Error(err);\n handleResponse({ error });\n log.catch(err);\n } else {\n handleResponse();\n }\n }\n };\n\n return (\n <div className={mx('flex flex-col h-full overflow-hidden', classNames)}>\n {/* TODO(burdon): Replace with Thread? */}\n <div ref={scrollerRef} className='flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto'>\n <MessageThread state={state} result={result} history={history} />\n </div>\n\n <Toolbar.Root classNames='p-2'>\n <Input.Root>\n <Input.TextInput\n ref={inputRef}\n autoFocus\n placeholder={t('function request placeholder')}\n value={input}\n onChange={(ev) => setInput(ev.target.value)}\n onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}\n />\n </Input.Root>\n <Toolbar.Button onClick={() => handleRequest(input)}>\n <Icon icon='ph--play--regular' size={4} />\n </Toolbar.Button>\n <Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>\n <Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />\n </Toolbar.Button>\n </Toolbar.Root>\n </div>\n );\n};\n\n// TODO(burdon): Replace with thread?\n// TODO(burdon): Button to delete individual messages.\n// TODO(burdon): Button to edit/re-run question.\nconst MessageThread = ({ state, result, history }: { state: State | null; result: string; history: Message[] }) => {\n return (\n <>\n {history.map((message, i) => (\n <div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>\n <div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>\n <div className='overflow-auto'>\n <MessageItem message={message} />\n </div>\n </div>\n ))}\n {result?.length > 0 && (\n <div className='grid grid-cols-[2rem_1fr_2rem]'>\n <div className='p-1'>\n {(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin' />) || (\n <Icon icon='ph--robot--regular' size={6} classNames='animate-[pulse_1s_ease-in-out_infinite]' />\n )}\n </div>\n <div className='overflow-auto'>\n <MessageItem message={{ type: 'response', text: result }} />\n </div>\n </div>\n )}\n </>\n );\n};\n\nconst MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {\n const { type, text, data, error } = message;\n const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';\n return (\n <div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>\n {error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}\n\n {text !== undefined && (\n <div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>\n {text || '\\u00D8'}\n </div>\n )}\n\n {data && (\n <SyntaxHighlighter language='json' className={mx(wrapper, 'px-8 py-2 text-xs')}>\n {JSON.stringify(data, null, 2)}\n </SyntaxHighlighter>\n )}\n </div>\n );\n};\n\nconst RobotAvatar = () => (\n <Avatar.Root size={6} variant='circle'>\n <Avatar.Frame>\n <Avatar.Icon icon='ph--robot--regular' />\n </Avatar.Frame>\n </Avatar.Root>\n);\n"],
|
|
5
|
+
"mappings": ";;;;;AAIA,OAAOA,SAASC,WAAWC,QAAQC,gBAAgB;AAEnD,SAASC,WAAW;AACpB,SAASC,QAAQC,MAAMC,OAA6BC,SAASC,sBAAsB;AACnF,SAASC,yBAAyB;AAClC,SAASC,UAAU;;AAeZ,IAAMC,aAAa,CAAC,EAAEC,YAAY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AQ,MAAA,GAIZC,QACC,sBAAA,cAACmE,mBAAAA;IAAkBC,UAAS;IAAO5B,WAAWC,GAAGyB,SAAS,mBAAA;KACvD3D,KAAKE,UAAUT,MAAM,MAAM,CAAA,CAAA,CAAA;AAKtC;AAEA,IAAM+D,cAAc,MAClB,sBAAA,cAACM,OAAOxB,MAAI;EAACc,MAAM;EAAGW,SAAQ;GAC5B,sBAAA,cAACD,OAAOE,OAAK,MACX,sBAAA,cAACF,OAAOZ,MAAI;EAACC,MAAK;;",
|
|
6
|
+
"names": ["React", "useEffect", "useRef", "useState", "log", "Avatar", "Icon", "Input", "Toolbar", "useTranslation", "SyntaxHighlighter", "mx", "DebugPanel", "classNames", "functionUrl", "t", "useTranslation", "SCRIPT_PLUGIN", "inputRef", "useRef", "input", "setInput", "useState", "result", "setResult", "state", "setState", "history", "setHistory", "scrollerRef", "handleScroll", "current", "scrollTop", "scrollHeight", "controller", "useEffect", "handleStop", "abort", "undefined", "handleClear", "focus", "handleResponse", "text", "data", "error", "type", "handleRequest", "charAt", "validJsonString", "replace", "JSON", "parse", "stringify", "err", "setTimeout", "AbortController", "response", "fetch", "signal", "method", "body", "headers", "ok", "Error", "statusText", "String", "status", "contentType", "get", "json", "reader", "getReader", "pump", "done", "value", "TextDecoder", "decode", "read", "then", "catch", "name", "log", "div", "className", "mx", "ref", "MessageThread", "Toolbar", "Root", "Input", "TextInput", "autoFocus", "placeholder", "onChange", "ev", "target", "onKeyDown", "key", "Button", "onClick", "Icon", "icon", "size", "map", "message", "i", "RobotAvatar", "MessageItem", "length", "wrapper", "SyntaxHighlighter", "language", "Avatar", "variant", "Frame"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SCRIPT_PLUGIN
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C7VBULMK.mjs";
|
|
4
4
|
|
|
5
5
|
// packages/plugins/experimental/plugin-script/src/types/script.ts
|
|
6
6
|
import { ref, S, TypedObject } from "@dxos/echo-schema";
|
|
@@ -43,4 +43,4 @@ export {
|
|
|
43
43
|
FunctionType,
|
|
44
44
|
ScriptAction
|
|
45
45
|
};
|
|
46
|
-
//# sourceMappingURL=chunk-
|
|
46
|
+
//# sourceMappingURL=chunk-USXWNH3S.mjs.map
|
|
@@ -3,19 +3,23 @@ import {
|
|
|
3
3
|
initializeBundler,
|
|
4
4
|
templates
|
|
5
5
|
} from "./chunk-G6H56WFS.mjs";
|
|
6
|
+
import {
|
|
7
|
+
getInvocationUrl,
|
|
8
|
+
getUserFunctionUrlInMetadata
|
|
9
|
+
} from "./chunk-KHNN3F7J.mjs";
|
|
6
10
|
import {
|
|
7
11
|
FunctionType,
|
|
8
12
|
ScriptAction,
|
|
9
13
|
ScriptType
|
|
10
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-USXWNH3S.mjs";
|
|
11
15
|
import {
|
|
12
16
|
SCRIPT_PLUGIN,
|
|
13
17
|
meta_default
|
|
14
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-C7VBULMK.mjs";
|
|
15
19
|
|
|
16
20
|
// packages/plugins/experimental/plugin-script/src/ScriptPlugin.tsx
|
|
17
21
|
import wasmUrl from "esbuild-wasm/esbuild.wasm?url";
|
|
18
|
-
import
|
|
22
|
+
import React3 from "react";
|
|
19
23
|
import { NavigationAction, parseIntentPlugin, resolvePlugin } from "@dxos/app-framework";
|
|
20
24
|
import { create } from "@dxos/echo-schema";
|
|
21
25
|
import { parseClientPlugin } from "@dxos/plugin-client";
|
|
@@ -84,7 +88,7 @@ import { lazy } from "react";
|
|
|
84
88
|
import React from "react";
|
|
85
89
|
import { useClient } from "@dxos/react-client";
|
|
86
90
|
import { Button, useTranslation } from "@dxos/react-ui";
|
|
87
|
-
import {
|
|
91
|
+
import { DeprecatedFormInput } from "@dxos/react-ui-data";
|
|
88
92
|
var ScriptSettings = ({ settings }) => {
|
|
89
93
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
90
94
|
const client = useClient();
|
|
@@ -109,16 +113,90 @@ var ScriptSettings = ({ settings }) => {
|
|
|
109
113
|
}
|
|
110
114
|
]);
|
|
111
115
|
};
|
|
112
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
116
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DeprecatedFormInput, {
|
|
113
117
|
label: t("authenticate action label")
|
|
114
118
|
}, /* @__PURE__ */ React.createElement(Button, {
|
|
115
119
|
onClick: handleAuthenticate
|
|
116
120
|
}, t("authenticate button label"))));
|
|
117
121
|
};
|
|
118
122
|
|
|
123
|
+
// packages/plugins/experimental/plugin-script/src/components/ScriptSettingsPanel.tsx
|
|
124
|
+
import React2, { useCallback } from "react";
|
|
125
|
+
import { useClient as useClient2 } from "@dxos/react-client";
|
|
126
|
+
import { Filter, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
|
|
127
|
+
import { Button as Button2, Icon, Input, useControlledValue, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
128
|
+
var ScriptSettingsPanel = ({ script }) => {
|
|
129
|
+
const { t } = useTranslation2(SCRIPT_PLUGIN);
|
|
130
|
+
const client = useClient2();
|
|
131
|
+
const space = getSpace(script);
|
|
132
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, (fn2) => fn2.source === script));
|
|
133
|
+
const handleNameChange = useCallback((event) => {
|
|
134
|
+
script.name = event.target.value;
|
|
135
|
+
}, [
|
|
136
|
+
script
|
|
137
|
+
]);
|
|
138
|
+
const [binding, setBinding] = useControlledValue(fn?.binding ?? "");
|
|
139
|
+
const handleBindingChange = useCallback((event) => {
|
|
140
|
+
setBinding(event.target.value);
|
|
141
|
+
}, [
|
|
142
|
+
setBinding
|
|
143
|
+
]);
|
|
144
|
+
const handleBindingBlur = useCallback(() => {
|
|
145
|
+
fn.binding = binding;
|
|
146
|
+
}, [
|
|
147
|
+
fn,
|
|
148
|
+
binding
|
|
149
|
+
]);
|
|
150
|
+
const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
151
|
+
const functionUrl = functionPath && getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? "", {
|
|
152
|
+
spaceId: space?.id
|
|
153
|
+
});
|
|
154
|
+
const handleCopy = useCallback(() => functionUrl && navigator.clipboard.writeText(functionUrl), [
|
|
155
|
+
functionUrl
|
|
156
|
+
]);
|
|
157
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
158
|
+
role: "form",
|
|
159
|
+
className: "flex flex-col w-full p-2 gap-4"
|
|
160
|
+
}, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement("div", {
|
|
161
|
+
role: "none",
|
|
162
|
+
className: "flex flex-col gap-1"
|
|
163
|
+
}, /* @__PURE__ */ React2.createElement(Input.Label, null, t("name label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
164
|
+
placeholder: t("object title placeholder"),
|
|
165
|
+
value: script.name ?? "",
|
|
166
|
+
onChange: handleNameChange
|
|
167
|
+
}))), fn && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("hr", {
|
|
168
|
+
className: "border-separator"
|
|
169
|
+
}), /* @__PURE__ */ React2.createElement("h2", null, t("remote function settings heading")), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement("div", {
|
|
170
|
+
role: "none",
|
|
171
|
+
className: "flex flex-col gap-1"
|
|
172
|
+
}, /* @__PURE__ */ React2.createElement(Input.Label, null, t("function url label")), /* @__PURE__ */ React2.createElement("div", {
|
|
173
|
+
role: "none",
|
|
174
|
+
className: "flex gap-1"
|
|
175
|
+
}, /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
176
|
+
disabled: true,
|
|
177
|
+
value: functionUrl,
|
|
178
|
+
onChange: (event) => {
|
|
179
|
+
fn.name = event.target.value;
|
|
180
|
+
}
|
|
181
|
+
}), /* @__PURE__ */ React2.createElement(Button2, {
|
|
182
|
+
onClick: handleCopy
|
|
183
|
+
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
184
|
+
icon: "ph--copy--regular",
|
|
185
|
+
size: 4
|
|
186
|
+
}))))), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement("div", {
|
|
187
|
+
role: "none",
|
|
188
|
+
className: "flex flex-col gap-1"
|
|
189
|
+
}, /* @__PURE__ */ React2.createElement(Input.Label, null, t("function binding label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
190
|
+
placeholder: t("function binding placeholder"),
|
|
191
|
+
value: binding,
|
|
192
|
+
onChange: handleBindingChange,
|
|
193
|
+
onBlur: handleBindingBlur
|
|
194
|
+
})))));
|
|
195
|
+
};
|
|
196
|
+
|
|
119
197
|
// packages/plugins/experimental/plugin-script/src/components/index.ts
|
|
120
|
-
var AutomationPanel = lazy(() => import("./AutomationPanel-
|
|
121
|
-
var ScriptContainer = lazy(() => import("./ScriptContainer-
|
|
198
|
+
var AutomationPanel = lazy(() => import("./AutomationPanel-XLL2ZXGS.mjs"));
|
|
199
|
+
var ScriptContainer = lazy(() => import("./ScriptContainer-YXH4MFEO.mjs"));
|
|
122
200
|
|
|
123
201
|
// packages/plugins/experimental/plugin-script/src/translations.ts
|
|
124
202
|
var translations_default = [
|
|
@@ -138,7 +216,12 @@ var translations_default = [
|
|
|
138
216
|
"format label": "Format",
|
|
139
217
|
"toggle details label": "Toggle details panel",
|
|
140
218
|
"authenticate action label": "Authenticate functions service",
|
|
141
|
-
"authenticate button label": "Authenticate"
|
|
219
|
+
"authenticate button label": "Authenticate",
|
|
220
|
+
"name label": "Name",
|
|
221
|
+
"remote function settings heading": "Remote Function",
|
|
222
|
+
"function url label": "Invocation URL",
|
|
223
|
+
"function binding label": "Function binding",
|
|
224
|
+
"function binding placeholder": "BINDING"
|
|
142
225
|
}
|
|
143
226
|
}
|
|
144
227
|
}
|
|
@@ -257,13 +340,13 @@ var ScriptPlugin = () => {
|
|
|
257
340
|
component: ({ data, role }) => {
|
|
258
341
|
switch (role) {
|
|
259
342
|
case "settings": {
|
|
260
|
-
return data.plugin === meta_default.id ? /* @__PURE__ */
|
|
343
|
+
return data.plugin === meta_default.id ? /* @__PURE__ */ React3.createElement(ScriptSettings, {
|
|
261
344
|
settings: {}
|
|
262
345
|
}) : null;
|
|
263
346
|
}
|
|
264
347
|
case "article": {
|
|
265
348
|
if (data.object instanceof ScriptType) {
|
|
266
|
-
return /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ React3.createElement(ScriptContainer, {
|
|
267
350
|
script: data.object,
|
|
268
351
|
env: compiler.environment
|
|
269
352
|
});
|
|
@@ -271,14 +354,23 @@ var ScriptPlugin = () => {
|
|
|
271
354
|
break;
|
|
272
355
|
}
|
|
273
356
|
case "complementary--automation": {
|
|
274
|
-
if (data.
|
|
357
|
+
if (data.subject instanceof ScriptType) {
|
|
275
358
|
return {
|
|
276
|
-
node: /* @__PURE__ */
|
|
359
|
+
node: /* @__PURE__ */ React3.createElement(AutomationPanel, {
|
|
277
360
|
subject: data.subject
|
|
278
361
|
}),
|
|
279
362
|
disposition: "hoist"
|
|
280
363
|
};
|
|
281
364
|
}
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case "complementary--settings": {
|
|
368
|
+
if (data.subject instanceof ScriptType) {
|
|
369
|
+
return /* @__PURE__ */ React3.createElement(ScriptSettingsPanel, {
|
|
370
|
+
script: data.subject
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
break;
|
|
282
374
|
}
|
|
283
375
|
}
|
|
284
376
|
return null;
|
|
@@ -314,6 +406,7 @@ export {
|
|
|
314
406
|
ScriptContainer,
|
|
315
407
|
ScriptPlugin,
|
|
316
408
|
ScriptSettings,
|
|
409
|
+
ScriptSettingsPanel,
|
|
317
410
|
ScriptType,
|
|
318
411
|
src_default as default,
|
|
319
412
|
initializeBundler
|