@dxos/plugin-script 0.6.9 → 0.6.10-main.48c066e

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.
Files changed (93) hide show
  1. package/dist/lib/browser/{ScriptEditor-7XICKICQ.mjs → ScriptEditor-TBM5XWUC.mjs} +73 -11
  2. package/dist/lib/browser/ScriptEditor-TBM5XWUC.mjs.map +7 -0
  3. package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs → TypescriptEditor-XTGRVCMY.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-D4O723CR.mjs → chunk-DX5CSOBP.mjs} +22 -5
  5. package/dist/lib/browser/chunk-DX5CSOBP.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-SK3L274X.mjs → chunk-K26D5UCK.mjs} +13 -7
  7. package/dist/lib/browser/{chunk-SK3L274X.mjs.map → chunk-K26D5UCK.mjs.map} +3 -3
  8. package/dist/lib/browser/chunk-RHEZ5LUU.mjs +229 -0
  9. package/dist/lib/browser/chunk-RHEZ5LUU.mjs.map +7 -0
  10. package/dist/lib/browser/edge/index.mjs +1 -1
  11. package/dist/lib/browser/index.mjs +79 -187
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/node/{ScriptEditor-M7KZ2CRS.cjs → ScriptEditor-VWT74T2V.cjs} +78 -18
  15. package/dist/lib/node/ScriptEditor-VWT74T2V.cjs.map +7 -0
  16. package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs → TypescriptEditor-CRONCQSI.cjs} +7 -7
  17. package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs.map → TypescriptEditor-CRONCQSI.cjs.map} +2 -2
  18. package/dist/lib/node/chunk-4GTXIELQ.cjs +252 -0
  19. package/dist/lib/node/chunk-4GTXIELQ.cjs.map +7 -0
  20. package/dist/lib/node/{chunk-ITLHJMWP.cjs → chunk-RXI576K3.cjs} +24 -7
  21. package/dist/lib/node/chunk-RXI576K3.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-X6A3D4PD.cjs → chunk-VXR2JE2I.cjs} +16 -10
  23. package/dist/lib/node/{chunk-X6A3D4PD.cjs.map → chunk-VXR2JE2I.cjs.map} +3 -3
  24. package/dist/lib/node/edge/index.cjs +8 -8
  25. package/dist/lib/node/edge/index.cjs.map +1 -1
  26. package/dist/lib/node/index.cjs +76 -186
  27. package/dist/lib/node/index.cjs.map +4 -4
  28. package/dist/lib/node/meta.json +1 -1
  29. package/dist/types/src/ScriptPlugin.d.ts +1 -4
  30. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  31. package/dist/types/src/bundler/bundler.d.ts +39 -0
  32. package/dist/types/src/bundler/bundler.d.ts.map +1 -0
  33. package/dist/types/src/bundler/bundler.test.d.ts +2 -0
  34. package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
  35. package/dist/types/src/bundler/index.d.ts +2 -0
  36. package/dist/types/src/bundler/index.d.ts.map +1 -0
  37. package/dist/types/src/compiler/compiler.browser.test.d.ts +2 -0
  38. package/dist/types/src/compiler/compiler.browser.test.d.ts.map +1 -0
  39. package/dist/types/src/compiler/compiler.d.ts +9 -34
  40. package/dist/types/src/compiler/compiler.d.ts.map +1 -1
  41. package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts +2 -2
  42. package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +1 -1
  43. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
  44. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +1 -1
  45. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
  46. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +1 -1
  47. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +1 -1
  48. package/dist/types/src/components/ScriptEditor.d.ts +3 -2
  49. package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
  50. package/dist/types/src/components/Toolbar.d.ts +2 -1
  51. package/dist/types/src/components/Toolbar.d.ts.map +1 -1
  52. package/dist/types/src/components/Toolbar.stories.d.ts +2 -2
  53. package/dist/types/src/components/Toolbar.stories.d.ts.map +1 -1
  54. package/dist/types/src/components/TypescriptEditor.d.ts +3 -1
  55. package/dist/types/src/components/TypescriptEditor.d.ts.map +1 -1
  56. package/dist/types/src/components/TypescriptEditor.stories.d.ts +2 -2
  57. package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/index.d.ts +2 -2
  59. package/dist/types/src/components/index.d.ts.map +1 -1
  60. package/dist/types/src/edge/functions.d.ts.map +1 -1
  61. package/dist/types/src/index.d.ts +1 -0
  62. package/dist/types/src/index.d.ts.map +1 -1
  63. package/dist/types/src/translations.d.ts +1 -0
  64. package/dist/types/src/translations.d.ts.map +1 -1
  65. package/dist/types/src/types/script.d.ts +4 -4
  66. package/package.json +38 -33
  67. package/src/ScriptPlugin.tsx +23 -5
  68. package/src/bundler/bundler.test.ts +44 -0
  69. package/src/bundler/bundler.ts +246 -0
  70. package/src/bundler/index.ts +5 -0
  71. package/src/compiler/compiler.browser.test.ts +18 -0
  72. package/src/compiler/compiler.ts +31 -190
  73. package/src/compiler/index.ts +1 -1
  74. package/src/components/ScriptBlock/FrameContainer/FrameContainer.tsx +2 -2
  75. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +1 -1
  76. package/src/components/ScriptBlock/ScriptBlock.tsx +10 -7
  77. package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +1 -1
  78. package/src/components/ScriptEditor.tsx +51 -5
  79. package/src/components/Toolbar.stories.tsx +1 -1
  80. package/src/components/Toolbar.tsx +28 -1
  81. package/src/components/TypescriptEditor.stories.tsx +1 -1
  82. package/src/components/TypescriptEditor.tsx +18 -4
  83. package/src/edge/functions.ts +8 -2
  84. package/src/index.ts +1 -0
  85. package/src/translations.ts +1 -0
  86. package/dist/lib/browser/ScriptEditor-7XICKICQ.mjs.map +0 -7
  87. package/dist/lib/browser/chunk-D4O723CR.mjs.map +0 -7
  88. package/dist/lib/node/ScriptEditor-M7KZ2CRS.cjs.map +0 -7
  89. package/dist/lib/node/chunk-ITLHJMWP.cjs.map +0 -7
  90. package/dist/types/src/compiler/compiler.test.d.ts +0 -2
  91. package/dist/types/src/compiler/compiler.test.d.ts.map +0 -1
  92. package/src/compiler/compiler.test.ts +0 -17
  93. /package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs.map → TypescriptEditor-XTGRVCMY.mjs.map} +0 -0
@@ -3,6 +3,9 @@
3
3
  //
4
4
 
5
5
  import { type DID } from 'iso-did/types';
6
+ import { format } from 'prettier';
7
+ import prettierPluginEstree from 'prettier/plugins/estree';
8
+ import prettierPluginTypescript from 'prettier/plugins/typescript';
6
9
  import React, { useCallback, useMemo, useState } from 'react';
7
10
 
8
11
  import { log } from '@dxos/log';
@@ -14,7 +17,8 @@ import { createDataExtensions, listener } from '@dxos/react-ui-editor';
14
17
  import { mx } from '@dxos/react-ui-theme';
15
18
 
16
19
  import { Toolbar } from './Toolbar';
17
- import { TypescriptEditor } from './TypescriptEditor';
20
+ import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
21
+ import { Bundler } from '../bundler';
18
22
  import {
19
23
  getUserFunctionUrlInMetadata,
20
24
  publicKeyToDid,
@@ -27,9 +31,9 @@ import { FunctionType, type ScriptType } from '../types';
27
31
  export type ScriptEditorProps = {
28
32
  script: ScriptType;
29
33
  role?: string;
30
- };
34
+ } & Pick<TypescriptEditorProps, 'env'>;
31
35
 
32
- export const ScriptEditor = ({ script, role }: ScriptEditorProps) => {
36
+ export const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {
33
37
  const { t } = useTranslation(SCRIPT_PLUGIN);
34
38
  const client = useClient();
35
39
  const identity = useIdentity();
@@ -67,6 +71,25 @@ export const ScriptEditor = ({ script, role }: ScriptEditorProps) => {
67
71
  [fn],
68
72
  );
69
73
 
74
+ const handleFormat = useCallback(async () => {
75
+ if (!script.source) {
76
+ return;
77
+ }
78
+
79
+ try {
80
+ const formatted = await format(script.source.content, {
81
+ parser: 'typescript',
82
+ plugins: [prettierPluginEstree, prettierPluginTypescript],
83
+ semi: true,
84
+ singleQuote: true,
85
+ });
86
+ script.source.content = formatted;
87
+ } catch (err: any) {
88
+ // TODO(wittjosiah): Show error in UI.
89
+ log.catch(err);
90
+ }
91
+ }, [script.source]);
92
+
70
93
  const handleDeploy = useCallback(async () => {
71
94
  if (!script.source || !identity || !space) {
72
95
  return;
@@ -78,12 +101,22 @@ export const ScriptEditor = ({ script, role }: ScriptEditorProps) => {
78
101
  const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
79
102
  const ownerDid = (existingFunctionUrl?.split('/').at(-2) as DID) ?? publicKeyToDid(identity.identityKey);
80
103
 
104
+ const bundler = new Bundler({
105
+ platform: 'browser',
106
+ sandboxedModules: [],
107
+ remoteModules: {},
108
+ });
109
+ const buildResult = await bundler.bundle(script.source.content);
110
+ if (buildResult.error || !buildResult.bundle) {
111
+ throw buildResult.error;
112
+ }
113
+
81
114
  const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({
82
115
  clientConfig: client.config,
83
116
  halo: client.halo,
84
117
  ownerDid,
85
118
  functionId: existingFunctionId,
86
- source: script.source.content,
119
+ source: buildResult.bundle,
87
120
  });
88
121
  if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {
89
122
  throw new Error(errorMessage);
@@ -103,6 +136,17 @@ export const ScriptEditor = ({ script, role }: ScriptEditorProps) => {
103
136
  }
104
137
  }, [fn, existingFunctionUrl, script, script.name, script.source]);
105
138
 
139
+ const functionUrl = useMemo(() => {
140
+ if (!existingFunctionUrl) {
141
+ return;
142
+ }
143
+
144
+ const url = new URL(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url);
145
+ space && url.searchParams.set('spaceId', space.id);
146
+ url.protocol = 'https';
147
+ return url.toString();
148
+ }, [existingFunctionUrl, space]);
149
+
106
150
  return (
107
151
  <div
108
152
  role='none'
@@ -111,13 +155,15 @@ export const ScriptEditor = ({ script, role }: ScriptEditorProps) => {
111
155
  <Toolbar
112
156
  binding={fn?.binding ?? ''}
113
157
  onBindingChange={handleBindingChange}
158
+ onFormat={handleFormat}
114
159
  deployed={Boolean(existingFunctionUrl) && !script.changed}
115
160
  onDeploy={handleDeploy}
116
- functionUrl={existingFunctionUrl}
161
+ functionUrl={functionUrl}
117
162
  error={error}
118
163
  />
119
164
  <TypescriptEditor
120
165
  id={script.id}
166
+ env={env}
121
167
  initialValue={initialValue}
122
168
  extensions={extensions}
123
169
  className='flex is-full bs-full overflow-hidden'
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxosTheme';
5
+ import '@dxos-theme';
6
6
 
7
7
  // import React from 'react';
8
8
 
@@ -2,7 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Check, Checks, CircleNotch, Link, PencilSimple, UploadSimple, WarningCircle, X } from '@phosphor-icons/react';
5
+ import {
6
+ Check,
7
+ Checks,
8
+ CircleNotch,
9
+ Link,
10
+ MagicWand,
11
+ PencilSimple,
12
+ UploadSimple,
13
+ WarningCircle,
14
+ X,
15
+ } from '@phosphor-icons/react';
6
16
  import React, { useEffect, useRef, useState } from 'react';
7
17
 
8
18
  import {
@@ -21,6 +31,7 @@ import { SCRIPT_PLUGIN } from '../meta';
21
31
  export type ToolbarProps = {
22
32
  binding: string;
23
33
  onBindingChange: (binding: string) => void;
34
+ onFormat?: () => Promise<void>;
24
35
  deployed?: boolean;
25
36
  onDeploy?: () => Promise<void>;
26
37
  functionUrl?: string;
@@ -30,6 +41,7 @@ export type ToolbarProps = {
30
41
  export const Toolbar = ({
31
42
  binding: _binding,
32
43
  onBindingChange,
44
+ onFormat,
33
45
  deployed,
34
46
  onDeploy,
35
47
  functionUrl,
@@ -82,6 +94,21 @@ export const Toolbar = ({
82
94
  classNames='p-1 is-full shrink-0 overflow-x-auto overflow-y-hidden'
83
95
  style={{ contain: 'layout' }}
84
96
  >
97
+ {onFormat && (
98
+ <Tooltip.Root>
99
+ <Tooltip.Trigger asChild>
100
+ <NaturalToolbar.Button variant='ghost' onClick={onFormat}>
101
+ <MagicWand className={getSize(4)} />
102
+ </NaturalToolbar.Button>
103
+ </Tooltip.Trigger>
104
+ <Tooltip.Portal>
105
+ <Tooltip.Content>
106
+ <Tooltip.Arrow />
107
+ {t('format label')}
108
+ </Tooltip.Content>
109
+ </Tooltip.Portal>
110
+ </Tooltip.Root>
111
+ )}
85
112
  {/* TODO(wittjosiah): Binding input shouldn't be in the toolbar. */}
86
113
  <Input.Root>
87
114
  <Input.Label>{t('binding label')}</Input.Label>
@@ -13,7 +13,7 @@
13
13
  // - virtual document image rendering
14
14
  // - mobile rendering error
15
15
 
16
- import '@dxosTheme';
16
+ import '@dxos-theme';
17
17
 
18
18
  import React, { useMemo } from 'react';
19
19
 
@@ -5,6 +5,8 @@
5
5
  import { javascript } from '@codemirror/lang-javascript';
6
6
  import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
7
7
  import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
8
+ import { type VirtualTypeScriptEnvironment } from '@typescript/vfs';
9
+ import { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from '@valtown/codemirror-ts';
8
10
  import React from 'react';
9
11
 
10
12
  import { useThemeContext } from '@dxos/react-ui';
@@ -12,9 +14,10 @@ import {
12
14
  autocomplete,
13
15
  createBasicExtensions,
14
16
  createThemeExtensions,
15
- editorContent,
17
+ editorFullWidth,
16
18
  editorGutter,
17
19
  editorMonospace,
20
+ InputModeExtensions,
18
21
  useTextEditor,
19
22
  type UseTextEditorProps,
20
23
  } from '@dxos/react-ui-editor';
@@ -22,6 +25,7 @@ import { nonNullable } from '@dxos/util';
22
25
 
23
26
  export type TypescriptEditorProps = {
24
27
  id: string;
28
+ env?: VirtualTypeScriptEnvironment;
25
29
  className?: string;
26
30
  scrollPastEnd?: boolean;
27
31
  } & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;
@@ -29,6 +33,7 @@ export type TypescriptEditorProps = {
29
33
  export const TypescriptEditor = ({
30
34
  id,
31
35
  extensions,
36
+ env,
32
37
  initialValue,
33
38
  scrollTo,
34
39
  selection,
@@ -43,19 +48,28 @@ export const TypescriptEditor = ({
43
48
  extensions: [
44
49
  extensions,
45
50
  // TODO(wittjosiah): Highlight active line doesn't work.
46
- createBasicExtensions({ highlightActiveLine: true, indentWithTab: true, lineNumbers: true, scrollPastEnd }),
51
+ createBasicExtensions({
52
+ highlightActiveLine: true,
53
+ indentWithTab: true,
54
+ lineNumbers: true,
55
+ lineWrapping: false,
56
+ scrollPastEnd,
57
+ }),
47
58
  // TODO(wittjosiah): Factor out syntax highlighting to theme extensions.
48
59
  themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
49
60
  createThemeExtensions({
50
61
  themeMode,
51
62
  slots: {
52
- content: { className: editorContent },
63
+ content: { className: editorFullWidth },
53
64
  },
54
65
  }),
55
66
  editorGutter,
56
67
  editorMonospace,
57
68
  javascript({ typescript: true }),
58
- autocomplete(),
69
+ // https://github.com/val-town/codemirror-ts
70
+ env ? [tsFacet.of({ env, path: `/src/${id}.ts` }), tsSync(), tsLinter(), tsHover()] : [],
71
+ autocomplete({ override: env ? [tsAutocomplete()] : [] }),
72
+ InputModeExtensions.vscode,
59
73
  ].filter(nonNullable),
60
74
  selection,
61
75
  scrollTo,
@@ -37,10 +37,16 @@ export type UploadWorkerProps = {
37
37
  credentialLoadTimeout?: number; // ms to wait for credentials to load
38
38
  };
39
39
 
40
- const defaultUserFunctionsBaseUrl = 'https://functions-staging.dxos.workers.dev'; // 'http://localhost:8600';
40
+ const defaultUserFunctionsBaseUrl = 'https://edge-main.dxos.workers.dev/functions'; // 'http://localhost:8600';
41
41
 
42
42
  const getBaseUrl = (config: Config) => {
43
- return config.get('runtime.app.env.DX_USERFUNCTIONS_BASE_URL') || defaultUserFunctionsBaseUrl;
43
+ if (config.values.runtime?.services?.edge?.url) {
44
+ const url = new URL('/functions', config.values.runtime?.services?.edge?.url);
45
+ url.protocol = 'https';
46
+ return url.toString();
47
+ } else {
48
+ return defaultUserFunctionsBaseUrl;
49
+ }
44
50
  };
45
51
 
46
52
  export const uploadWorkerFunction = async ({
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import { ScriptPlugin } from './ScriptPlugin';
6
6
 
7
7
  export default ScriptPlugin;
8
8
 
9
+ export * from './bundler';
9
10
  export * from './compiler';
10
11
  export * from './components';
11
12
  export * from './types';
@@ -19,6 +19,7 @@ export default [
19
19
  'deployed label': 'Current version of the script is deployed',
20
20
  'upload failed label': 'Upload failed',
21
21
  'copy link label': 'Copy function link',
22
+ 'format label': 'Format',
22
23
  },
23
24
  },
24
25
  },
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ScriptEditor.tsx", "../../../src/components/Toolbar.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\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 } from '@dxos/react-ui';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { Toolbar } from './Toolbar';\nimport { TypescriptEditor } from './TypescriptEditor';\nimport {\n getUserFunctionUrlInMetadata,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n} from '../edge';\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { FunctionType, type ScriptType } from '../types';\n\nexport type ScriptEditorProps = {\n script: ScriptType;\n role?: string;\n};\n\nexport const ScriptEditor = ({ script, role }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(\n space,\n Filter.schema(FunctionType, (fn) => fn.source === script),\n );\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source && script.source?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source && createDocAccessor(script.source, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source, space, identity],\n );\n 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 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 { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({\n clientConfig: client.config,\n halo: client.halo,\n ownerDid,\n functionId: existingFunctionId,\n source: script.source.content,\n });\n if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {\n throw new Error(errorMessage);\n }\n log.info('function uploaded', { functionId, functionVersionNumber });\n if (fn) {\n fn.version = functionVersionNumber;\n }\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));\n const meta = getMeta(deployedFunction);\n setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);\n script.changed = false;\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 return (\n <div\n role='none'\n className={mx(role === 'article' && 'row-span-2', 'flex flex-col is-full bs-full overflow-hidden')}\n >\n <Toolbar\n binding={fn?.binding ?? ''}\n onBindingChange={handleBindingChange}\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n onDeploy={handleDeploy}\n functionUrl={existingFunctionUrl}\n error={error}\n />\n <TypescriptEditor\n id={script.id}\n initialValue={initialValue}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden'\n />\n </div>\n );\n};\n\nexport default ScriptEditor;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Check, Checks, CircleNotch, Link, PencilSimple, UploadSimple, WarningCircle, X } from '@phosphor-icons/react';\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport {\n Button,\n DensityProvider,\n ElevationProvider,\n Input,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\nimport { getSize, mx } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type ToolbarProps = {\n binding: string;\n onBindingChange: (binding: string) => void;\n deployed?: boolean;\n onDeploy?: () => Promise<void>;\n functionUrl?: string;\n error?: string;\n};\n\nexport const Toolbar = ({\n binding: _binding,\n onBindingChange,\n deployed,\n onDeploy,\n functionUrl,\n error,\n}: ToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const [pending, setPending] = useState(false);\n const [editing, setEditing] = useState(false);\n const [binding, setBinding] = useState(_binding);\n const inputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!editing && _binding !== binding) {\n setBinding(_binding);\n }\n }, [_binding]);\n\n const handleEdit = () => {\n setEditing(true);\n inputRef.current?.focus();\n };\n\n const handleSave = () => {\n setEditing(false);\n onBindingChange(binding);\n };\n\n const handleCancel = () => {\n setEditing(false);\n };\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 setPending(true);\n await onDeploy?.();\n setPending(false);\n };\n\n return (\n <DensityProvider density='fine'>\n <ElevationProvider elevation='chrome'>\n <NaturalToolbar.Root\n classNames='p-1 is-full shrink-0 overflow-x-auto overflow-y-hidden'\n style={{ contain: 'layout' }}\n >\n {/* TODO(wittjosiah): Binding input shouldn't be in the toolbar. */}\n <Input.Root>\n <Input.Label>{t('binding label')}</Input.Label>\n <Input.TextInput\n ref={inputRef}\n classNames='!is-auto'\n disabled={!editing}\n value={binding}\n onChange={(event) => setBinding(event.target.value.toUpperCase())}\n />\n {editing ? (\n <>\n <Button variant='ghost' onClick={handleCancel}>\n <X className={getSize(4)} />\n </Button>\n <Button variant='ghost' onClick={handleSave}>\n <Check className={getSize(4)} />\n </Button>\n </>\n ) : (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <Button variant='ghost' onClick={handleEdit}>\n <PencilSimple className={getSize(4)} />\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('edit binding label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n </Input.Root>\n <div role='separator' className='grow' />\n {/* TODO(wittjosiah): Better treatment for status indicators in toolbar? */}\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <WarningCircle className={getSize(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 ) : deployed ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Checks className={getSize(4)} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('deployed label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n {functionUrl && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleCopyLink}>\n <Link className={getSize(4)} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('copy link label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleDeploy} disabled={pending}>\n {pending ? (\n <CircleNotch className={mx('spinner', getSize(4))} />\n ) : (\n <UploadSimple className={getSize(4)} />\n )}\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {pending ? t('pending label') : t('deploy label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n </NaturalToolbar.Root>\n </ElevationProvider>\n </DensityProvider>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAKA,OAAOA,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,uBAAsB;AAC/B,SAASC,sBAAsBC,gBAAgB;AAC/C,SAASC,MAAAA,WAAU;;;ACTnB,SAASC,OAAOC,QAAQC,aAAaC,MAAMC,cAAcC,cAAcC,eAAeC,SAAS;AAC/F,OAAOC,SAASC,WAAWC,QAAQC,gBAAgB;AAEnD,SACEC,QACAC,iBACAC,mBACAC,OACAC,WAAWC,gBACXC,SACAC,sBACK;AACP,SAASC,SAASC,UAAU;AAarB,IAAMC,UAAU,CAAC,EACtBC,SAASC,UACTC,iBACAC,UACAC,UACAC,aACAC,MAAK,MACQ;AACb,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAS,KAAA;AACvC,QAAM,CAACC,SAASC,UAAAA,IAAcF,SAAS,KAAA;AACvC,QAAM,CAACZ,SAASe,UAAAA,IA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AAMD,KAAAA,QAAAA;;;;;;AACV/B,eAAS9B,EAAE,qBAAA,CAAA;IACb;EACF,GAAG;IAACS;IAAIiB;IAAqB5B;IAAQA,OAAOiE;IAAMjE,OAAOgB;GAAO;AAEhE,SACE,gBAAAkD,OAAA,cAACC,OAAAA;IACClE,MAAK;IACLmE,WAAWC,IAAGpE,SAAS,aAAa,cAAc,+CAAA;KAElD,gBAAAiE,OAAA,cAACI,SAAAA;IACClC,SAASzB,IAAIyB,WAAW;IACxBmC,iBAAiBrC;IACjBsC,UAAUC,QAAQ7C,mBAAAA,KAAwB,CAAC5B,OAAOuB;IAClDmD,UAAUrC;IACVsC,aAAa/C;IACbG;MAEF,gBAAAmC,OAAA,cAACU,kBAAAA;IACCnD,IAAIzB,OAAOyB;IACXE;IACAV;IACAmD,WAAU;;AAIlB;AAEA,IAAA,uBAAerE;",
6
- "names": ["React", "useCallback", "useMemo", "useState", "log", "useClient", "create", "createDocAccessor", "Filter", "getMeta", "getSpace", "useQuery", "useIdentity", "useTranslation", "createDataExtensions", "listener", "mx", "Check", "Checks", "CircleNotch", "Link", "PencilSimple", "UploadSimple", "WarningCircle", "X", "React", "useEffect", "useRef", "useState", "Button", "DensityProvider", "ElevationProvider", "Input", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "getSize", "mx", "Toolbar", "binding", "_binding", "onBindingChange", "deployed", "onDeploy", "functionUrl", "error", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "editing", "setEditing", "setBinding", "inputRef", "useRef", "useEffect", "handleEdit", "current", "focus", "handleSave", "handleCancel", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "DensityProvider", "density", "ElevationProvider", "elevation", "NaturalToolbar", "Root", "classNames", "style", "contain", "Input", "Label", "TextInput", "ref", "disabled", "value", "onChange", "event", "target", "toUpperCase", "Button", "variant", "onClick", "X", "className", "getSize", "Check", "Tooltip", "Trigger", "asChild", "PencilSimple", "Portal", "Content", "Arrow", "div", "role", "WarningCircle", "Checks", "Link", "CircleNotch", "mx", "UploadSimple", "ScriptEditor", "script", "role", "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", "initialValue", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "error", "setError", "useState", "handleBindingChange", "useCallback", "binding", "handleDeploy", "undefined", "existingFunctionId", "split", "at", "ownerDid", "publicKeyToDid", "identityKey", "result", "functionId", "functionVersionNumber", "errorMessage", "uploadWorkerFunction", "clientConfig", "config", "halo", "Error", "log", "info", "version", "deployedFunction", "db", "add", "create", "meta", "setUserFunctionUrlInMetadata", "err", "catch", "name", "React", "div", "className", "mx", "Toolbar", "onBindingChange", "deployed", "Boolean", "onDeploy", "functionUrl", "TypescriptEditor"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/TypescriptEditor.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';\nimport { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorContent,\n editorGutter,\n editorMonospace,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n className?: string;\n scrollPastEnd?: boolean;\n} & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n extensions,\n initialValue,\n scrollTo,\n selection,\n className,\n scrollPastEnd,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n // TODO(wittjosiah): Highlight active line doesn't work.\n createBasicExtensions({ highlightActiveLine: true, indentWithTab: true, lineNumbers: true, scrollPastEnd }),\n // TODO(wittjosiah): Factor out syntax highlighting to theme extensions.\n themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),\n createThemeExtensions({\n themeMode,\n slots: {\n content: { className: editorContent },\n },\n }),\n editorGutter,\n editorMonospace,\n javascript({ typescript: true }),\n autocomplete(),\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,SAASA,kBAAkB;AAC3B,SAASC,uBAAuBC,0BAA0B;AAC1D,SAASC,6BAA6B;AACtC,OAAOC,WAAW;AAElB,SAASC,uBAAuB;AAChC,SACEC,cACAC,uBACAC,uBACAC,eACAC,cACAC,iBACAC,qBAEK;AACP,SAASC,mBAAmB;AAQrB,IAAMC,mBAAmB,CAAC,EAC/BC,IACAC,YACAC,cACAC,UACAC,WACAC,WACAC,cAAa,MACS;AACtB,QAAM,EAAEC,UAAS,IAAKC,gBAAAA;AACtB,QAAM,EAAEC,WAAWC,gBAAe,IAAKC,cACrC,OAAO;IACLX;IACAE;IACAD,YAAY;MACVA;;MAEAW,sBAAsB;QAAEC,qBAAqB;QAAMC,eAAe;QAAMC,aAAa;QAAMT;MAAc,CAAA;;MAEzGC,cAAc,SAASS,mBAAmBC,qBAAAA,IAAyBD,mBAAmBE,qBAAAA;MACtFC,sBAAsB;QACpBZ;QACAa,OAAO;UACLC,SAAS;YAAEhB,WAAWiB;UAAc;QACtC;MACF,CAAA;MACAC;MACAC;MACAC,WAAW;QAAEC,YAAY;MAAK,CAAA;MAC9BC,aAAAA;MACAC,OAAOC,WAAAA;IACTzB;IACAD;EACF,IACA;IAACH;IAAIE;IAAcD;IAAYM;IAAWH;IAAWD;GAAS;AAGhE,SAAO,sBAAA,cAAC2B,OAAAA;IAAIC,KAAKtB;IAAWJ;IAAuB,GAAGK;;AACxD;AAEA,IAAA,2BAAeX;",
6
- "names": ["javascript", "defaultHighlightStyle", "syntaxHighlighting", "oneDarkHighlightStyle", "React", "useThemeContext", "autocomplete", "createBasicExtensions", "createThemeExtensions", "editorContent", "editorGutter", "editorMonospace", "useTextEditor", "nonNullable", "TypescriptEditor", "id", "extensions", "initialValue", "scrollTo", "selection", "className", "scrollPastEnd", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "syntaxHighlighting", "oneDarkHighlightStyle", "defaultHighlightStyle", "createThemeExtensions", "slots", "content", "editorContent", "editorGutter", "editorMonospace", "javascript", "typescript", "autocomplete", "filter", "nonNullable", "div", "ref"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ScriptEditor.tsx", "../../../src/components/Toolbar.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\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 } from '@dxos/react-ui';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { Toolbar } from './Toolbar';\nimport { TypescriptEditor } from './TypescriptEditor';\nimport {\n getUserFunctionUrlInMetadata,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n} from '../edge';\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { FunctionType, type ScriptType } from '../types';\n\nexport type ScriptEditorProps = {\n script: ScriptType;\n role?: string;\n};\n\nexport const ScriptEditor = ({ script, role }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(\n space,\n Filter.schema(FunctionType, (fn) => fn.source === script),\n );\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source && script.source?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source && createDocAccessor(script.source, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source, space, identity],\n );\n 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 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 { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({\n clientConfig: client.config,\n halo: client.halo,\n ownerDid,\n functionId: existingFunctionId,\n source: script.source.content,\n });\n if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {\n throw new Error(errorMessage);\n }\n log.info('function uploaded', { functionId, functionVersionNumber });\n if (fn) {\n fn.version = functionVersionNumber;\n }\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));\n const meta = getMeta(deployedFunction);\n setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);\n script.changed = false;\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 return (\n <div\n role='none'\n className={mx(role === 'article' && 'row-span-2', 'flex flex-col is-full bs-full overflow-hidden')}\n >\n <Toolbar\n binding={fn?.binding ?? ''}\n onBindingChange={handleBindingChange}\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n onDeploy={handleDeploy}\n functionUrl={existingFunctionUrl}\n error={error}\n />\n <TypescriptEditor\n id={script.id}\n initialValue={initialValue}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden'\n />\n </div>\n );\n};\n\nexport default ScriptEditor;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Check, Checks, CircleNotch, Link, PencilSimple, UploadSimple, WarningCircle, X } from '@phosphor-icons/react';\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport {\n Button,\n DensityProvider,\n ElevationProvider,\n Input,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\nimport { getSize, mx } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type ToolbarProps = {\n binding: string;\n onBindingChange: (binding: string) => void;\n deployed?: boolean;\n onDeploy?: () => Promise<void>;\n functionUrl?: string;\n error?: string;\n};\n\nexport const Toolbar = ({\n binding: _binding,\n onBindingChange,\n deployed,\n onDeploy,\n functionUrl,\n error,\n}: ToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const [pending, setPending] = useState(false);\n const [editing, setEditing] = useState(false);\n const [binding, setBinding] = useState(_binding);\n const inputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!editing && _binding !== binding) {\n setBinding(_binding);\n }\n }, [_binding]);\n\n const handleEdit = () => {\n setEditing(true);\n inputRef.current?.focus();\n };\n\n const handleSave = () => {\n setEditing(false);\n onBindingChange(binding);\n };\n\n const handleCancel = () => {\n setEditing(false);\n };\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 setPending(true);\n await onDeploy?.();\n setPending(false);\n };\n\n return (\n <DensityProvider density='fine'>\n <ElevationProvider elevation='chrome'>\n <NaturalToolbar.Root\n classNames='p-1 is-full shrink-0 overflow-x-auto overflow-y-hidden'\n style={{ contain: 'layout' }}\n >\n {/* TODO(wittjosiah): Binding input shouldn't be in the toolbar. */}\n <Input.Root>\n <Input.Label>{t('binding label')}</Input.Label>\n <Input.TextInput\n ref={inputRef}\n classNames='!is-auto'\n disabled={!editing}\n value={binding}\n onChange={(event) => setBinding(event.target.value.toUpperCase())}\n />\n {editing ? (\n <>\n <Button variant='ghost' onClick={handleCancel}>\n <X className={getSize(4)} />\n </Button>\n <Button variant='ghost' onClick={handleSave}>\n <Check className={getSize(4)} />\n </Button>\n </>\n ) : (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <Button variant='ghost' onClick={handleEdit}>\n <PencilSimple className={getSize(4)} />\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('edit binding label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n </Input.Root>\n <div role='separator' className='grow' />\n {/* TODO(wittjosiah): Better treatment for status indicators in toolbar? */}\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <WarningCircle className={getSize(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 ) : deployed ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Checks className={getSize(4)} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('deployed label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n {functionUrl && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleCopyLink}>\n <Link className={getSize(4)} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('copy link label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleDeploy} disabled={pending}>\n {pending ? (\n <CircleNotch className={mx('spinner', getSize(4))} />\n ) : (\n <UploadSimple className={getSize(4)} />\n )}\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {pending ? t('pending label') : t('deploy label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n </NaturalToolbar.Root>\n </ElevationProvider>\n </DensityProvider>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,mBAAsD;AAEtD,iBAAoB;AACpB,0BAA0B;AAC1B,kBAA+E;AAC/E,kBAA4B;AAC5B,sBAA+B;AAC/B,6BAA+C;AAC/C,4BAAmB;ACTnB,IAAAA,gBAA+F;AAC/F,IAAAA,gBAAmD;AAEnD,IAAAC,mBAQO;AACP,IAAAC,yBAA4B;AAarB,IAAMC,UAAU,CAAC,EACtBC,SAASC,UACTC,iBACAC,UACAC,UACAC,aACAC,MAAK,MACQ;AACb,QAAM,EAAEC,EAAC,QAAKC,iCAAeC,mCAAAA;AAC7B,QAAM,CAACC,SAASC,UAAAA,QAAcC,wBAAS,KAAA;AACvC,QAAM,CAACC,SAASC,UAAAA,QAAcF,wBAAS,KAAA;AACvC,QAAM,CAACZ,SAASe,UAAAA,QAAcH,wBAASX,QAAAA;AACvC,QAAMe,eAAWC,sBAAyB,IAAA;AAE1CC,+BAAU,MAAA;AACR,QAAI,CAACL,WAAWZ,aAAaD,SAAS;AACpCe,iBAAWd,QAAAA;IACb;EACF,GAAG;IAACA;GAAS;AAEb,QAAMkB,aAAa,MAAA;AACjBL,eAAW,IAAA;AAC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;;;;;AAClE,UAAI/B,IAAI;AACNA,WAAGwC,UAAUT;MACf;AACA,YAAMU,mBACJzC,MAAMF,MAAM4C,GAAGC,QAAIC,oBAAOxC,oCAAc;QAAEoC,SAAST;QAAuB1B,QAAQZ;MAAO,CAAA,CAAA;AAC3F,YAAMoD,WAAO3B,qBAAQuB,gBAAAA;AACrBK,8DAA6BD,MAAM,IAAInB,QAAAA,IAAYI,UAAAA,EAAY;AAC/DrC,aAAOkB,UAAU;IACnB,SAASoC,KAAU;AACjBT,qBAAIU,MAAMD,KAAAA,QAAAA;;;;;;AACV5B,eAAS3F,EAAE,qBAAA,CAAA;IACb;EACF,GAAG;IAACwE;IAAIgB;IAAqBvB;IAAQA,OAAOwD;IAAMxD,OAAOY;GAAO;AAEhE,SACEvD,6BAAAA,QAAA,cAACkC,OAAAA;IACCC,MAAK;IACLX,eAAWgB,sBAAAA,IAAGL,SAAS,aAAa,cAAc,+CAAA;KAElDnC,6BAAAA,QAAA,cAAC9B,SAAAA;IACCC,SAAS+E,IAAI/E,WAAW;IACxBE,iBAAiBiG;IACjBhG,UAAU8H,QAAQlC,mBAAAA,KAAwB,CAACvB,OAAOkB;IAClDtF,UAAUwB;IACVvB,aAAa0F;IACbzF;MAEFuB,6BAAAA,QAAA,cAACqG,wCAAAA;IACCtC,IAAIpB,OAAOoB;IACXE;IACAT;IACAhC,WAAU;;AAIlB;AAEA,IAAA,uBAAekB;",
6
- "names": ["import_react", "import_react_ui", "import_react_ui_theme", "Toolbar", "binding", "_binding", "onBindingChange", "deployed", "onDeploy", "functionUrl", "error", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "editing", "setEditing", "setBinding", "inputRef", "useRef", "useEffect", "handleEdit", "current", "focus", "handleSave", "handleCancel", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "React", "DensityProvider", "density", "ElevationProvider", "elevation", "NaturalToolbar", "Root", "classNames", "style", "contain", "Input", "Label", "TextInput", "ref", "disabled", "value", "onChange", "event", "target", "toUpperCase", "Button", "variant", "onClick", "X", "className", "getSize", "Check", "Tooltip", "Trigger", "asChild", "PencilSimple", "Portal", "Content", "Arrow", "div", "role", "WarningCircle", "Checks", "Link", "CircleNotch", "mx", "UploadSimple", "ScriptEditor", "script", "client", "useClient", "identity", "useIdentity", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "extensions", "useMemo", "listener", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "initialValue", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "setError", "handleBindingChange", "useCallback", "undefined", "existingFunctionId", "split", "at", "ownerDid", "publicKeyToDid", "identityKey", "result", "functionId", "functionVersionNumber", "errorMessage", "uploadWorkerFunction", "clientConfig", "config", "halo", "Error", "log", "info", "version", "deployedFunction", "db", "add", "create", "meta", "setUserFunctionUrlInMetadata", "err", "catch", "name", "Boolean", "TypescriptEditor"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/TypescriptEditor.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';\nimport { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorContent,\n editorGutter,\n editorMonospace,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n className?: string;\n scrollPastEnd?: boolean;\n} & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n extensions,\n initialValue,\n scrollTo,\n selection,\n className,\n scrollPastEnd,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n // TODO(wittjosiah): Highlight active line doesn't work.\n createBasicExtensions({ highlightActiveLine: true, indentWithTab: true, lineNumbers: true, scrollPastEnd }),\n // TODO(wittjosiah): Factor out syntax highlighting to theme extensions.\n themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),\n createThemeExtensions({\n themeMode,\n slots: {\n content: { className: editorContent },\n },\n }),\n editorGutter,\n editorMonospace,\n javascript({ typescript: true }),\n autocomplete(),\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,6BAA2B;AAC3B,sBAA0D;AAC1D,4BAAsC;AACtC,mBAAkB;AAElB,sBAAgC;AAChC,6BASO;AACP,kBAA4B;AAQrB,IAAMA,mBAAmB,CAAC,EAC/BC,IACAC,YACAC,cACAC,UACAC,WACAC,WACAC,cAAa,MACS;AACtB,QAAM,EAAEC,UAAS,QAAKC,iCAAAA;AACtB,QAAM,EAAEC,WAAWC,gBAAe,QAAKC,sCACrC,OAAO;IACLX;IACAE;IACAD,YAAY;MACVA;;UAEAW,8CAAsB;QAAEC,qBAAqB;QAAMC,eAAe;QAAMC,aAAa;QAAMT;MAAc,CAAA;;MAEzGC,cAAc,aAASS,oCAAmBC,2CAAAA,QAAyBD,oCAAmBE,qCAAAA;UACtFC,8CAAsB;QACpBZ;QACAa,OAAO;UACLC,SAAS;YAAEhB,WAAWiB;UAAc;QACtC;MACF,CAAA;MACAC;MACAC;UACAC,mCAAW;QAAEC,YAAY;MAAK,CAAA;UAC9BC,qCAAAA;MACAC,OAAOC,uBAAAA;IACTzB;IACAD;EACF,IACA;IAACH;IAAIE;IAAcD;IAAYM;IAAWH;IAAWD;GAAS;AAGhE,SAAO,6BAAA2B,QAAA,cAACC,OAAAA;IAAIC,KAAKvB;IAAWJ;IAAuB,GAAGK;;AACxD;AAEA,IAAA,2BAAeX;",
6
- "names": ["TypescriptEditor", "id", "extensions", "initialValue", "scrollTo", "selection", "className", "scrollPastEnd", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "syntaxHighlighting", "oneDarkHighlightStyle", "defaultHighlightStyle", "createThemeExtensions", "slots", "content", "editorContent", "editorGutter", "editorMonospace", "javascript", "typescript", "autocomplete", "filter", "nonNullable", "React", "div", "ref"]
7
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=compiler.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compiler.test.d.ts","sourceRoot":"","sources":["../../../../src/compiler/compiler.test.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import { expect } from 'chai';
6
-
7
- import { describe, test } from '@dxos/test';
8
-
9
- import { Compiler } from './compiler';
10
-
11
- describe('Compiler', () => {
12
- test('Basic', async () => {
13
- const compiler = new Compiler({ platform: 'node', providedModules: [] });
14
- const result = await compiler.compile('const x = 100'); // TODO(burdon): Test import.
15
- expect(result).to.exist;
16
- });
17
- });