@dxos/plugin-script 0.7.4 → 0.7.5-main.9d26e3a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/lib/browser/{AutomationPanel-PMTZROAZ.mjs → AutomationPanel-RFQAQ7NF.mjs} +2 -9
  2. package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs.map +7 -0
  3. package/dist/lib/browser/{ScriptContainer-RYZFYCNK.mjs → ScriptContainer-GDVBWFI7.mjs} +16 -26
  4. package/dist/lib/browser/ScriptContainer-GDVBWFI7.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-RQA3EB5K.mjs +26 -0
  6. package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +57 -131
  8. package/dist/lib/browser/index.mjs.map +3 -3
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/types.mjs +8 -0
  11. package/dist/lib/node/{AutomationPanel-AAGQREH7.cjs → AutomationPanel-5CJEF4MI.cjs} +12 -13
  12. package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs.map +7 -0
  13. package/dist/lib/node/{ScriptContainer-FZ44UIRC.cjs → ScriptContainer-YWXXNLG6.cjs} +27 -28
  14. package/dist/lib/node/ScriptContainer-YWXXNLG6.cjs.map +7 -0
  15. package/dist/lib/node/chunk-PK3OQP5L.cjs +45 -0
  16. package/dist/lib/node/chunk-PK3OQP5L.cjs.map +7 -0
  17. package/dist/lib/node/index.cjs +61 -132
  18. package/dist/lib/node/index.cjs.map +3 -3
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/{types/index.cjs → types.cjs} +5 -9
  21. package/dist/lib/node/types.cjs.map +7 -0
  22. package/dist/lib/node-esm/{AutomationPanel-ETQEDY5I.mjs → AutomationPanel-7Y6REBNJ.mjs} +2 -9
  23. package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs.map +7 -0
  24. package/dist/lib/node-esm/{ScriptContainer-3PKDW34A.mjs → ScriptContainer-BG2PHKEH.mjs} +16 -26
  25. package/dist/lib/node-esm/ScriptContainer-BG2PHKEH.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +27 -0
  27. package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +57 -131
  29. package/dist/lib/node-esm/index.mjs.map +3 -3
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/types.mjs +9 -0
  32. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  33. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +2 -2
  34. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
  35. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -1
  36. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
  37. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
  38. package/dist/types/src/components/ScriptEditor.d.ts +1 -1
  39. package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
  40. package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -1
  41. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
  42. package/dist/types/src/translations.d.ts +0 -43
  43. package/dist/types/src/translations.d.ts.map +1 -1
  44. package/dist/types/src/types.d.ts +22 -0
  45. package/dist/types/src/types.d.ts.map +1 -0
  46. package/dist/types/tsconfig.tsbuildinfo +1 -0
  47. package/package.json +39 -47
  48. package/src/ScriptPlugin.tsx +43 -95
  49. package/src/components/AutomationPanel/AutomationPanel.tsx +2 -4
  50. package/src/components/FrameContainer/FrameContainer.tsx +1 -1
  51. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +6 -3
  52. package/src/components/ScriptBlock/ScriptBlock.tsx +2 -2
  53. package/src/components/ScriptEditor.tsx +20 -18
  54. package/src/components/ScriptSettingsPanel.tsx +1 -2
  55. package/src/components/Toolbar/Toolbar.tsx +1 -1
  56. package/src/translations.ts +0 -4
  57. package/src/types.ts +38 -0
  58. package/dist/lib/browser/AutomationPanel-PMTZROAZ.mjs.map +0 -7
  59. package/dist/lib/browser/ScriptContainer-RYZFYCNK.mjs.map +0 -7
  60. package/dist/lib/browser/chunk-QFZUFT5G.mjs +0 -48
  61. package/dist/lib/browser/chunk-QFZUFT5G.mjs.map +0 -7
  62. package/dist/lib/browser/chunk-U3OP64V4.mjs +0 -123
  63. package/dist/lib/browser/chunk-U3OP64V4.mjs.map +0 -7
  64. package/dist/lib/browser/edge/index.mjs +0 -19
  65. package/dist/lib/browser/types/index.mjs +0 -12
  66. package/dist/lib/node/AutomationPanel-AAGQREH7.cjs.map +0 -7
  67. package/dist/lib/node/ScriptContainer-FZ44UIRC.cjs.map +0 -7
  68. package/dist/lib/node/chunk-CS25QNKZ.cjs +0 -151
  69. package/dist/lib/node/chunk-CS25QNKZ.cjs.map +0 -7
  70. package/dist/lib/node/chunk-DQYAU2CJ.cjs +0 -67
  71. package/dist/lib/node/chunk-DQYAU2CJ.cjs.map +0 -7
  72. package/dist/lib/node/edge/index.cjs +0 -41
  73. package/dist/lib/node/edge/index.cjs.map +0 -7
  74. package/dist/lib/node/types/index.cjs.map +0 -7
  75. package/dist/lib/node-esm/AutomationPanel-ETQEDY5I.mjs.map +0 -7
  76. package/dist/lib/node-esm/ScriptContainer-3PKDW34A.mjs.map +0 -7
  77. package/dist/lib/node-esm/chunk-36DLLQ6E.mjs +0 -125
  78. package/dist/lib/node-esm/chunk-36DLLQ6E.mjs.map +0 -7
  79. package/dist/lib/node-esm/chunk-GMVPKT6A.mjs +0 -49
  80. package/dist/lib/node-esm/chunk-GMVPKT6A.mjs.map +0 -7
  81. package/dist/lib/node-esm/edge/index.mjs +0 -20
  82. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  83. package/dist/lib/node-esm/types/index.mjs +0 -13
  84. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  85. package/dist/types/src/edge/functions.d.ts +0 -25
  86. package/dist/types/src/edge/functions.d.ts.map +0 -1
  87. package/dist/types/src/edge/index.d.ts +0 -2
  88. package/dist/types/src/edge/index.d.ts.map +0 -1
  89. package/dist/types/src/types/index.d.ts +0 -3
  90. package/dist/types/src/types/index.d.ts.map +0 -1
  91. package/dist/types/src/types/schema.d.ts +0 -71
  92. package/dist/types/src/types/schema.d.ts.map +0 -1
  93. package/dist/types/src/types/types.d.ts +0 -8
  94. package/dist/types/src/types/types.d.ts.map +0 -1
  95. package/src/edge/functions.ts +0 -116
  96. package/src/edge/index.ts +0 -7
  97. package/src/types/index.ts +0 -6
  98. package/src/types/schema.ts +0 -44
  99. package/src/types/types.ts +0 -29
  100. /package/dist/lib/browser/{edge/index.mjs.map → types.mjs.map} +0 -0
  101. /package/dist/lib/{browser/types/index.mjs.map → node-esm/types.mjs.map} +0 -0
@@ -26,15 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ScriptContainer_FZ44UIRC_exports = {};
30
- __export(ScriptContainer_FZ44UIRC_exports, {
29
+ var ScriptContainer_YWXXNLG6_exports = {};
30
+ __export(ScriptContainer_YWXXNLG6_exports, {
31
31
  default: () => ScriptContainer_default
32
32
  });
33
- module.exports = __toCommonJS(ScriptContainer_FZ44UIRC_exports);
33
+ module.exports = __toCommonJS(ScriptContainer_YWXXNLG6_exports);
34
34
  var import_chunk_WPP65EYS = require("./chunk-WPP65EYS.cjs");
35
35
  var import_chunk_4INUJLXL = require("./chunk-4INUJLXL.cjs");
36
- var import_chunk_CS25QNKZ = require("./chunk-CS25QNKZ.cjs");
37
- var import_chunk_DQYAU2CJ = require("./chunk-DQYAU2CJ.cjs");
38
36
  var import_chunk_6LYX73ZT = require("./chunk-6LYX73ZT.cjs");
39
37
  var import_react = __toESM(require("react"));
40
38
  var import_echo = require("@dxos/react-client/echo");
@@ -44,6 +42,7 @@ var import_prettier = require("prettier");
44
42
  var import_estree = __toESM(require("prettier/plugins/estree"));
45
43
  var import_typescript = __toESM(require("prettier/plugins/typescript"));
46
44
  var import_react2 = __toESM(require("react"));
45
+ var import_functions = require("@dxos/functions");
47
46
  var import_log = require("@dxos/log");
48
47
  var import_react_client = require("@dxos/react-client");
49
48
  var import_echo2 = require("@dxos/react-client/echo");
@@ -76,7 +75,7 @@ var Toolbar = ({ classNames, deployed, error, functionUrl, view, templates: temp
76
75
  }
77
76
  };
78
77
  return /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.ElevationProvider, {
79
- elevation: "chrome"
78
+ elevation: "positioned"
80
79
  }, /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.Toolbar.Root, {
81
80
  classNames: [
82
81
  "p-1",
@@ -232,20 +231,20 @@ var ScriptEditor = ({ classNames, script, env }) => {
232
231
  const client = (0, import_react_client.useClient)();
233
232
  const identity = (0, import_halo.useIdentity)();
234
233
  const space = (0, import_echo2.getSpace)(script);
235
- const [fn] = (0, import_echo2.useQuery)(space, import_echo2.Filter.schema(import_chunk_DQYAU2CJ.FunctionType, {
234
+ const [fn] = (0, import_echo2.useQuery)(space, import_echo2.Filter.schema(import_functions.FunctionType, {
236
235
  source: script
237
236
  }));
238
237
  const extensions = (0, import_react2.useMemo)(() => [
239
238
  (0, import_react_ui_editor.listener)({
240
239
  onChange: (text) => {
241
- if (script.source && script.source?.content !== text) {
240
+ if (script.source.target && script.source.target.content !== text) {
242
241
  script.changed = true;
243
242
  }
244
243
  }
245
244
  }),
246
245
  (0, import_react_ui_editor.createDataExtensions)({
247
246
  id: script.id,
248
- text: script.source && (0, import_echo2.createDocAccessor)(script.source, [
247
+ text: script.source.target && (0, import_echo2.createDocAccessor)(script.source.target, [
249
248
  "content"
250
249
  ]),
251
250
  space,
@@ -253,19 +252,19 @@ var ScriptEditor = ({ classNames, script, env }) => {
253
252
  })
254
253
  ], [
255
254
  script,
256
- script.source,
255
+ script.source.target,
257
256
  space,
258
257
  identity
259
258
  ]);
260
259
  const [view, setView] = (0, import_react2.useState)("editor");
261
- const existingFunctionUrl = fn && (0, import_chunk_CS25QNKZ.getUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(fn));
260
+ const existingFunctionUrl = fn && (0, import_functions.getUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(fn));
262
261
  const [error, setError] = (0, import_react2.useState)();
263
262
  const handleFormat = (0, import_react2.useCallback)(async () => {
264
263
  if (!script.source) {
265
264
  return;
266
265
  }
267
266
  try {
268
- script.source.content = await (0, import_prettier.format)(script.source.content, {
267
+ script.source.target.content = await (0, import_prettier.format)(script.source.target.content, {
269
268
  parser: "typescript",
270
269
  plugins: [
271
270
  import_estree.default,
@@ -277,7 +276,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
277
276
  } catch (err) {
278
277
  import_log.log.catch(err, void 0, {
279
278
  F: __dxlog_file,
280
- L: 83,
279
+ L: 84,
281
280
  S: void 0,
282
281
  C: (f, a) => f(...a)
283
282
  });
@@ -289,15 +288,15 @@ var ScriptEditor = ({ classNames, script, env }) => {
289
288
  const template = import_chunk_WPP65EYS.templates.find((template2) => template2.id === id);
290
289
  if (template) {
291
290
  script.name = template.name;
292
- script.source.content = template.source;
291
+ script.source.target.content = template.source;
293
292
  const metaKeys = (0, import_echo2.getMeta)(script).keys;
294
- const oldPresetIndex = metaKeys.findIndex((key) => key.source === import_chunk_CS25QNKZ.FUNCTIONS_PRESET_META_KEY);
293
+ const oldPresetIndex = metaKeys.findIndex((key) => key.source === import_functions.FUNCTIONS_PRESET_META_KEY);
295
294
  if (oldPresetIndex >= 0) {
296
295
  metaKeys.splice(oldPresetIndex, 1);
297
296
  }
298
297
  if (template.presetId) {
299
298
  metaKeys.push({
300
- source: import_chunk_CS25QNKZ.FUNCTIONS_PRESET_META_KEY,
299
+ source: import_functions.FUNCTIONS_PRESET_META_KEY,
301
300
  id: template.presetId
302
301
  });
303
302
  }
@@ -315,14 +314,14 @@ var ScriptEditor = ({ classNames, script, env }) => {
315
314
  sandboxedModules: [],
316
315
  remoteModules: {}
317
316
  });
318
- const buildResult = await bundler.bundle(script.source.content);
317
+ const buildResult = await bundler.bundle(script.source.target.content);
319
318
  if (buildResult.error || !buildResult.bundle) {
320
319
  throw buildResult.error;
321
320
  }
322
- const { functionId, version, meta } = await (0, import_chunk_CS25QNKZ.uploadWorkerFunction)({
321
+ const { functionId, version, meta } = await (0, import_functions.uploadWorkerFunction)({
323
322
  client,
324
323
  spaceId: space.id,
325
- version: fn ? (0, import_chunk_CS25QNKZ.incrementSemverPatch)(fn.version) : "0.0.1",
324
+ version: fn ? (0, import_functions.incrementSemverPatch)(fn.version) : "0.0.1",
326
325
  functionId: existingFunctionId,
327
326
  source: buildResult.bundle
328
327
  });
@@ -334,17 +333,17 @@ var ScriptEditor = ({ classNames, script, env }) => {
334
333
  version
335
334
  }, {
336
335
  F: __dxlog_file,
337
- L: 130,
336
+ L: 131,
338
337
  S: void 0,
339
338
  C: (f, a) => f(...a)
340
339
  });
341
340
  if (fn) {
342
341
  fn.version = version;
343
342
  }
344
- const deployedFunction = fn ?? space.db.add((0, import_echo2.create)(import_chunk_DQYAU2CJ.FunctionType, {
343
+ const deployedFunction = fn ?? space.db.add((0, import_echo2.create)(import_functions.FunctionType, {
345
344
  name: functionId,
346
345
  version,
347
- source: script
346
+ source: (0, import_echo2.makeRef)(script)
348
347
  }));
349
348
  script.changed = false;
350
349
  if (meta.inputSchema) {
@@ -354,17 +353,17 @@ var ScriptEditor = ({ classNames, script, env }) => {
354
353
  functionId
355
354
  }, {
356
355
  F: __dxlog_file,
357
- L: 142,
356
+ L: 144,
358
357
  S: void 0,
359
358
  C: (f, a) => f(...a)
360
359
  });
361
360
  }
362
- (0, import_chunk_CS25QNKZ.setUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(deployedFunction), `/${space.id}/${functionId}`);
361
+ (0, import_functions.setUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(deployedFunction), `/${space.id}/${functionId}`);
363
362
  setView("split");
364
363
  } catch (err) {
365
364
  import_log.log.catch(err, void 0, {
366
365
  F: __dxlog_file,
367
- L: 149,
366
+ L: 151,
368
367
  S: void 0,
369
368
  C: (f, a) => f(...a)
370
369
  });
@@ -382,7 +381,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
382
381
  if (!existingFunctionUrl) {
383
382
  return;
384
383
  }
385
- return (0, import_chunk_CS25QNKZ.getInvocationUrl)(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? "", {
384
+ return (0, import_functions.getInvocationUrl)(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? "", {
386
385
  spaceId: space?.id
387
386
  });
388
387
  }, [
@@ -405,7 +404,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
405
404
  }), view !== "preview" && /* @__PURE__ */ import_react2.default.createElement(TypescriptEditor, {
406
405
  id: script.id,
407
406
  env,
408
- initialValue: script.source?.content,
407
+ initialValue: script.source?.target?.content,
409
408
  extensions,
410
409
  className: "flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all"
411
410
  }), view !== "editor" && /* @__PURE__ */ import_react2.default.createElement(import_chunk_4INUJLXL.DebugPanel, {
@@ -424,4 +423,4 @@ var ScriptContainer = ({ script, ...props }) => {
424
423
  }));
425
424
  };
426
425
  var ScriptContainer_default = ScriptContainer;
427
- //# sourceMappingURL=ScriptContainer-FZ44UIRC.cjs.map
426
+ //# sourceMappingURL=ScriptContainer-YWXXNLG6.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptEditor.tsx", "../../../src/components/Toolbar/Toolbar.tsx", "../../../src/components/TypescriptEditor/TypescriptEditor.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { useAttendableAttributes } from '@dxos/react-ui-attention';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';\n\nconst ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {\n const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));\n return (\n <div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>\n <ScriptEditor {...props} script={script} />\n </div>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { format } from 'prettier';\nimport prettierPluginEstree from 'prettier/plugins/estree';\nimport prettierPluginTypescript from 'prettier/plugins/typescript';\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport {\n FUNCTIONS_PRESET_META_KEY,\n FunctionType,\n type ScriptType,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n incrementSemverPatch,\n} from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { create, createDocAccessor, Filter, getMeta, getSpace, makeRef, 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 { SCRIPT_PLUGIN } from '../meta';\nimport { templates } from '../templates';\n\nexport type ScriptEditorProps = ThemedClassName<{\n script: ScriptType;\n}> &\n Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source.target && script.source.target.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source.target && createDocAccessor(script.source.target, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source.target, space, identity],\n );\n\n const [view, setView] = useState<ViewType>('editor');\n const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const [error, setError] = useState<string>();\n\n const handleFormat = useCallback(async () => {\n if (!script.source) {\n return;\n }\n\n try {\n script.source.target!.content = await format(script.source.target!.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!.target!.content = template.source;\n const metaKeys = getMeta(script).keys;\n const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });\n }\n }\n };\n\n const handleDeploy = useCallback(async () => {\n if (!script.source || !identity || !space) {\n return;\n }\n\n setError(undefined);\n\n try {\n const existingFunctionId = existingFunctionUrl?.split('/').at(-1);\n\n const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });\n const buildResult = await bundler.bundle(script.source.target!.content);\n if (buildResult.error || !buildResult.bundle) {\n throw buildResult.error;\n }\n\n const { functionId, version, meta } = await uploadWorkerFunction({\n client,\n spaceId: space.id,\n version: fn ? incrementSemverPatch(fn.version) : '0.0.1',\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (functionId === undefined || version === undefined) {\n throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);\n }\n\n log.info('function uploaded', { functionId, version });\n if (fn) {\n fn.version = version;\n }\n\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));\n\n script.changed = false;\n\n if (meta.inputSchema) {\n deployedFunction.inputSchema = meta.inputSchema;\n } else {\n log.verbose('no input schema in function metadata', { functionId });\n }\n\n setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);\n\n setView('split');\n } catch (err: any) {\n log.catch(err);\n setError(t('upload failed label'));\n }\n }, [fn, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);\n\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n }, [existingFunctionUrl, space]);\n\n return (\n <div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>\n <Toolbar\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n functionUrl={functionUrl}\n error={error}\n view={view}\n templates={templates}\n onDeploy={handleDeploy}\n onFormat={handleFormat}\n onViewChange={setView}\n onTemplateSelect={handleTemplateChange}\n />\n\n {view !== 'preview' && (\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.target?.content}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'\n />\n )}\n\n {view !== 'editor' && <DebugPanel functionUrl={functionUrl} />}\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport {\n ElevationProvider,\n Icon,\n Select,\n type ThemedClassName,\n ToggleGroup,\n ToggleGroupItem,\n type ToolbarButtonProps,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type Template } from '../../templates';\n\nexport type ToolbarProps = ThemedClassName<\n {\n deployed?: boolean;\n error?: string;\n functionUrl?: string;\n onDeploy?: () => Promise<void>;\n onFormat?: () => Promise<void>;\n } & TemplateSelectProps &\n ViewSelectorProps\n>;\n\nexport const Toolbar = ({\n classNames,\n deployed,\n error,\n functionUrl,\n view,\n templates,\n onDeploy,\n onFormat,\n onViewChange,\n onTemplateSelect,\n}: ToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const [pending, setPending] = useState(false);\n\n const handleCopyLink = async () => {\n if (!functionUrl) {\n return;\n }\n\n await navigator.clipboard.writeText(functionUrl);\n };\n\n const handleDeploy = async () => {\n if (!pending) {\n setPending(true);\n await onDeploy?.();\n setPending(false);\n }\n };\n\n // TODO(burdon): Factor out common toolbar components with sheet/editor?\n return (\n <ElevationProvider elevation='positioned'>\n <NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>\n {templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}\n {onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}\n\n <div role='separator' className='grow' />\n\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Icon icon='ph--warning-circle--regular' size={4} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {error}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n\n {functionUrl && deployed && (\n <ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />\n )}\n\n {onDeploy && (\n <ToolbarIconButton\n icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}\n classNames={[pending && 'animate-spin']}\n text={pending ? t('pending label') : t('deploy label')}\n onClick={handleDeploy}\n />\n )}\n\n <ViewSelector view={view} onViewChange={onViewChange} />\n </NaturalToolbar.Root>\n </ElevationProvider>\n );\n};\n\nconst ToolbarIconButton = ({\n icon,\n text,\n classNames,\n disabled,\n onClick,\n}: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {\n return (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>\n <Icon icon={icon} size={4} classNames={classNames} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {text}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n );\n};\n\nexport type ViewType = 'editor' | 'split' | 'preview';\n\nexport type TemplateSelectProps = {\n templates?: Template[];\n onTemplateSelect?: (id: string) => void;\n};\n\nexport const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {\n return (\n <Select.Root value={''} onValueChange={onTemplateSelect}>\n <Select.TriggerButton />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n <Select.Option value={''}>Template</Select.Option>\n {templates.map(({ id, name }) => (\n <Select.Option key={id} value={id}>\n {name}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nexport type ViewSelectorProps = {\n view?: ViewType;\n onViewChange?: (view: ViewType) => void;\n};\n\nexport const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {\n return (\n <ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>\n <ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--code--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--square-split-vertical--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--eye--regular' size={4} />\n </ToggleGroupItem>\n </ToggleGroup>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorFullWidth,\n editorGutter,\n editorMonospace,\n InputModeExtensions,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n env?: VirtualTypeScriptEnvironment;\n} & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n env,\n className,\n initialValue,\n extensions,\n scrollTo,\n selection,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n scrollPastEnd: true,\n }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: {\n content: { className: editorFullWidth },\n },\n }),\n editorGutter,\n // TODO(burdon): Factor out.\n [\n editorMonospace,\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : [] }),\n env ? [tsFacet.of({ env, path: `/src/${id}.ts` }), tsSync(), tsLinter(), tsHover()] : [],\n InputModeExtensions.vscode,\n ],\n ].filter(nonNullable),\n selection,\n scrollTo,\n }),\n [id, extensions, themeMode, selection, scrollTo],\n );\n\n return <div ref={parentRef} className={className} {...focusAttributes} />;\n};\n\nexport default TypescriptEditor;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAkB;AAElB,kBAAiC;AACjC,gCA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qJ,sBAAAA,IAAG,0DAAA;IAA8D,GAAGK;KAC9FxK,6BAAAA,QAAA,cAACgF,cAAAA;IAAc,GAAGuF;IAAOtF;;AAG/B;AAEA,IAAA,0BAAeqF;",
6
+ "names": ["import_react", "import_echo", "import_react_ui_theme", "import_react_ui", "import_react_ui_editor", "Toolbar", "classNames", "deployed", "error", "functionUrl", "view", "templates", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "React", "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", "TypescriptEditor", "env", "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", "ref", "ScriptEditor", "script", "client", "useClient", "identity", "useIdentity", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "useMemo", "listener", "onChange", "target", "changed", "createDataExtensions", "createDocAccessor", "setView", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "setError", "handleFormat", "useCallback", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "handleTemplateChange", "template", "find", "metaKeys", "keys", "oldPresetIndex", "findIndex", "FUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "undefined", "existingFunctionId", "split", "at", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "functionId", "version", "meta", "uploadWorkerFunction", "spaceId", "incrementSemverPatch", "Error", "info", "deployedFunction", "db", "add", "create", "makeRef", "inputSchema", "verbose", "setUserFunctionUrlInMetadata", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "mx", "Boolean", "DebugPanel", "ScriptContainer", "props", "attendableAttrs", "useAttendableAttributes", "fullyQualifiedId"]
7
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_PK3OQP5L_exports = {};
20
+ __export(chunk_PK3OQP5L_exports, {
21
+ ScriptAction: () => ScriptAction
22
+ });
23
+ module.exports = __toCommonJS(chunk_PK3OQP5L_exports);
24
+ var import_chunk_6LYX73ZT = require("./chunk-6LYX73ZT.cjs");
25
+ var import_echo_schema = require("@dxos/echo-schema");
26
+ var import_functions = require("@dxos/functions");
27
+ var ScriptAction;
28
+ (function(ScriptAction2) {
29
+ const SCRIPT_ACTION = `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/action`;
30
+ class Create extends import_echo_schema.S.TaggedClass()(`${SCRIPT_ACTION}/create`, {
31
+ input: import_echo_schema.S.Struct({
32
+ name: import_echo_schema.S.optional(import_echo_schema.S.String)
33
+ }),
34
+ output: import_echo_schema.S.Struct({
35
+ object: import_functions.ScriptType
36
+ })
37
+ }) {
38
+ }
39
+ ScriptAction2.Create = Create;
40
+ })(ScriptAction || (ScriptAction = {}));
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ ScriptAction
44
+ });
45
+ //# sourceMappingURL=chunk-PK3OQP5L.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { S } from '@dxos/echo-schema';\nimport { ScriptType } from '@dxos/functions';\nimport { type SchemaProvides } from '@dxos/plugin-space';\n\nimport { SCRIPT_PLUGIN } from './meta';\n\nexport namespace ScriptAction {\n const SCRIPT_ACTION = `${SCRIPT_PLUGIN}/action`;\n\n export class Create extends S.TaggedClass<Create>()(`${SCRIPT_ACTION}/create`, {\n input: S.Struct({\n name: S.optional(S.String),\n }),\n output: S.Struct({\n object: ScriptType,\n }),\n }) {}\n}\n\nexport type ScriptSettingsProps = {};\n\nexport type ScriptPluginProvides = IntentResolverProvides &\n MetadataRecordsProvides &\n SchemaProvides &\n SettingsProvides<ScriptSettingsProps> &\n SurfaceProvides &\n TranslationsProvides;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAWA,yBAAkB;AAClB,uBAA2B;;UAKVA,eAAAA;AACf,QAAMC,gBAAgB,GAAGC,mCAAAA;EAElB,MAAMC,eAAeC,qBAAEC,YAAW,EAAW,GAAGJ,aAAAA,WAAwB;IAC7EK,OAAOF,qBAAEG,OAAO;MACdC,MAAMJ,qBAAEK,SAASL,qBAAEM,MAAM;IAC3B,CAAA;IACAC,QAAQP,qBAAEG,OAAO;MACfK,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;gBAPSV,SAAAA;AAQf,GAXiBH,iBAAAA,eAAAA,CAAAA,EAAAA;",
6
+ "names": ["ScriptAction", "SCRIPT_ACTION", "SCRIPT_PLUGIN", "Create", "S", "TaggedClass", "input", "Struct", "name", "optional", "String", "output", "object", "ScriptType"]
7
+ }
@@ -31,30 +31,24 @@ __export(node_exports, {
31
31
  AutomationPanel: () => AutomationPanel,
32
32
  Bundler: () => import_chunk_WPP65EYS.Bundler,
33
33
  Compiler: () => Compiler,
34
- FunctionType: () => import_chunk_DQYAU2CJ.FunctionType,
35
- ScriptAction: () => import_chunk_DQYAU2CJ.ScriptAction,
34
+ ScriptAction: () => import_chunk_PK3OQP5L.ScriptAction,
36
35
  ScriptContainer: () => ScriptContainer,
37
36
  ScriptPlugin: () => ScriptPlugin,
38
37
  ScriptSettings: () => ScriptSettings,
39
38
  ScriptSettingsPanel: () => ScriptSettingsPanel,
40
- ScriptType: () => import_chunk_DQYAU2CJ.ScriptType,
41
39
  default: () => src_default,
42
40
  initializeBundler: () => import_chunk_WPP65EYS.initializeBundler
43
41
  });
44
42
  module.exports = __toCommonJS(node_exports);
43
+ var import_chunk_PK3OQP5L = require("./chunk-PK3OQP5L.cjs");
45
44
  var import_chunk_WPP65EYS = require("./chunk-WPP65EYS.cjs");
46
- var import_chunk_CS25QNKZ = require("./chunk-CS25QNKZ.cjs");
47
- var import_chunk_DQYAU2CJ = require("./chunk-DQYAU2CJ.cjs");
48
45
  var import_chunk_6LYX73ZT = require("./chunk-6LYX73ZT.cjs");
49
46
  var import_esbuild = __toESM(require("esbuild-wasm/esbuild.wasm?url"));
50
47
  var import_react = __toESM(require("react"));
51
48
  var import_app_framework = require("@dxos/app-framework");
49
+ var import_functions = require("@dxos/functions");
52
50
  var import_live_object = require("@dxos/live-object");
53
- var import_plugin_client = require("@dxos/plugin-client");
54
- var import_plugin_graph = require("@dxos/plugin-graph");
55
51
  var import_types = require("@dxos/plugin-markdown/types");
56
- var import_plugin_space = require("@dxos/plugin-space");
57
- var import_echo = require("@dxos/react-client/echo");
58
52
  var import_vfs = require("@typescript/vfs");
59
53
  var import_typescript = __toESM(require("typescript"));
60
54
  var import_invariant = require("@dxos/invariant");
@@ -64,8 +58,9 @@ var import_react_client = require("@dxos/react-client");
64
58
  var import_react_ui = require("@dxos/react-ui");
65
59
  var import_react_ui_form = require("@dxos/react-ui-form");
66
60
  var import_react4 = __toESM(require("react"));
61
+ var import_functions2 = require("@dxos/functions");
67
62
  var import_react_client2 = require("@dxos/react-client");
68
- var import_echo2 = require("@dxos/react-client/echo");
63
+ var import_echo = require("@dxos/react-client/echo");
69
64
  var import_react_ui2 = require("@dxos/react-ui");
70
65
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/compiler/compiler.ts";
71
66
  var defaultOptions = {
@@ -148,8 +143,8 @@ var ScriptSettings = ({ settings }) => {
148
143
  var ScriptSettingsPanel = ({ script }) => {
149
144
  const { t } = (0, import_react_ui2.useTranslation)(import_chunk_6LYX73ZT.SCRIPT_PLUGIN);
150
145
  const client = (0, import_react_client2.useClient)();
151
- const space = (0, import_echo2.getSpace)(script);
152
- const [fn] = (0, import_echo2.useQuery)(space, import_echo2.Filter.schema(import_chunk_DQYAU2CJ.FunctionType, {
146
+ const space = (0, import_echo.getSpace)(script);
147
+ const [fn] = (0, import_echo.useQuery)(space, import_echo.Filter.schema(import_functions2.FunctionType, {
153
148
  source: script
154
149
  }));
155
150
  const handleNameChange = (0, import_react4.useCallback)((event) => {
@@ -169,8 +164,8 @@ var ScriptSettingsPanel = ({ script }) => {
169
164
  fn,
170
165
  binding
171
166
  ]);
172
- const functionPath = fn && (0, import_chunk_CS25QNKZ.getUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(fn));
173
- const functionUrl = functionPath && (0, import_chunk_CS25QNKZ.getInvocationUrl)(functionPath, client.config.values.runtime?.services?.edge?.url ?? "", {
167
+ const functionPath = fn && (0, import_functions2.getUserFunctionUrlInMetadata)((0, import_echo.getMeta)(fn));
168
+ const functionUrl = functionPath && (0, import_functions2.getInvocationUrl)(functionPath, client.config.values.runtime?.services?.edge?.url ?? "", {
174
169
  spaceId: space?.id
175
170
  });
176
171
  const handleCopy = (0, import_react4.useCallback)(() => functionUrl && navigator.clipboard.writeText(functionUrl), [
@@ -215,14 +210,11 @@ var ScriptSettingsPanel = ({ script }) => {
215
210
  onBlur: handleBindingBlur
216
211
  })))));
217
212
  };
218
- var AutomationPanel = (0, import_react2.lazy)(() => import("./AutomationPanel-AAGQREH7.cjs"));
219
- var ScriptContainer = (0, import_react2.lazy)(() => import("./ScriptContainer-FZ44UIRC.cjs"));
213
+ var AutomationPanel = (0, import_react2.lazy)(() => import("./AutomationPanel-5CJEF4MI.cjs"));
214
+ var ScriptContainer = (0, import_react2.lazy)(() => import("./ScriptContainer-YWXXNLG6.cjs"));
220
215
  var translations_default = [
221
216
  {
222
217
  "en-US": {
223
- [import_chunk_DQYAU2CJ.ScriptType.typename]: {
224
- "typename label": "Script"
225
- },
226
218
  [import_chunk_6LYX73ZT.SCRIPT_PLUGIN]: {
227
219
  "plugin name": "Scripts",
228
220
  "object title placeholder": "New script",
@@ -267,8 +259,8 @@ var ScriptPlugin = () => {
267
259
  settings: {},
268
260
  metadata: {
269
261
  records: {
270
- [import_chunk_DQYAU2CJ.ScriptType.typename]: {
271
- createObject: import_chunk_DQYAU2CJ.ScriptAction.CREATE,
262
+ [import_functions.ScriptType.typename]: {
263
+ createObject: (props) => (0, import_app_framework.createIntent)(import_chunk_PK3OQP5L.ScriptAction.Create, props),
272
264
  placeholder: [
273
265
  "object title placeholder",
274
266
  {
@@ -277,8 +269,8 @@ var ScriptPlugin = () => {
277
269
  ],
278
270
  icon: "ph--code--regular",
279
271
  // TODO(wittjosiah): Move out of metadata.
280
- loadReferences: (script) => (0, import_echo.loadObjectReferences)(script, (script2) => [
281
- script2.source
272
+ loadReferences: async (script) => await import_live_object.RefArray.loadAll([
273
+ script.source
282
274
  ])
283
275
  }
284
276
  }
@@ -286,121 +278,60 @@ var ScriptPlugin = () => {
286
278
  translations: translations_default,
287
279
  echo: {
288
280
  schema: [
289
- import_chunk_DQYAU2CJ.ScriptType
281
+ import_functions.ScriptType
290
282
  ],
291
283
  system: [
292
- import_chunk_DQYAU2CJ.FunctionType
284
+ import_functions.FunctionType
293
285
  ]
294
286
  },
295
- graph: {
296
- builder: (plugins) => {
297
- const client = (0, import_app_framework.resolvePlugin)(plugins, import_plugin_client.parseClientPlugin)?.provides.client;
298
- const dispatch = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseIntentPlugin)?.provides.intent.dispatch;
299
- if (!client || !dispatch) {
300
- return [];
301
- }
302
- return (0, import_plugin_graph.createExtension)({
303
- id: import_chunk_DQYAU2CJ.ScriptAction.CREATE,
304
- filter: (node) => (0, import_plugin_graph.isActionGroup)(node) && node.id.startsWith(import_plugin_space.SpaceAction.ADD_OBJECT),
305
- actions: ({ node }) => {
306
- const id = node.id.split("/").at(-1);
307
- const [spaceId, objectId] = id?.split(":") ?? [];
308
- const space = client.spaces.get().find((space2) => space2.id === spaceId);
309
- const object = objectId && space?.db.getObjectById(objectId);
310
- const target = objectId ? object : space;
311
- if (!target) {
312
- return;
313
- }
314
- return [
315
- {
316
- id: `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/create/${node.id}`,
317
- data: async () => {
318
- await dispatch([
319
- {
320
- plugin: import_chunk_6LYX73ZT.SCRIPT_PLUGIN,
321
- action: import_chunk_DQYAU2CJ.ScriptAction.CREATE
322
- },
323
- {
324
- action: import_plugin_space.SpaceAction.ADD_OBJECT,
325
- data: {
326
- target
327
- }
328
- },
329
- {
330
- action: import_app_framework.NavigationAction.OPEN
331
- }
332
- ]);
333
- },
334
- properties: {
335
- label: [
336
- "create object label",
337
- {
338
- ns: import_chunk_6LYX73ZT.SCRIPT_PLUGIN
339
- }
340
- ],
341
- icon: "ph--code--regular",
342
- testId: "scriptPlugin.createObject"
343
- }
344
- }
345
- ];
346
- }
347
- });
348
- }
349
- },
350
287
  surface: {
351
- component: ({ data, role }) => {
352
- switch (role) {
353
- case "settings": {
354
- return data.plugin === import_chunk_6LYX73ZT.meta_default.id ? /* @__PURE__ */ import_react.default.createElement(ScriptSettings, {
355
- settings: {}
356
- }) : null;
357
- }
358
- case "article": {
359
- if (data.object instanceof import_chunk_DQYAU2CJ.ScriptType) {
360
- return /* @__PURE__ */ import_react.default.createElement(ScriptContainer, {
361
- script: data.object,
362
- env: compiler.environment
363
- });
364
- }
365
- break;
366
- }
367
- case "complementary--automation": {
368
- if (data.subject instanceof import_chunk_DQYAU2CJ.ScriptType) {
369
- return {
370
- node: /* @__PURE__ */ import_react.default.createElement(AutomationPanel, {
371
- subject: data.subject
372
- }),
373
- disposition: "hoist"
374
- };
375
- }
376
- break;
377
- }
378
- case "complementary--settings": {
379
- if (data.subject instanceof import_chunk_DQYAU2CJ.ScriptType) {
380
- return /* @__PURE__ */ import_react.default.createElement(ScriptSettingsPanel, {
381
- script: data.subject
382
- });
383
- }
384
- break;
385
- }
386
- }
387
- return null;
388
- }
288
+ definitions: () => [
289
+ (0, import_app_framework.createSurface)({
290
+ id: `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/settings`,
291
+ role: "settings",
292
+ filter: (data) => data.subject === import_chunk_6LYX73ZT.SCRIPT_PLUGIN,
293
+ component: () => /* @__PURE__ */ import_react.default.createElement(ScriptSettings, {
294
+ settings: {}
295
+ })
296
+ }),
297
+ (0, import_app_framework.createSurface)({
298
+ id: `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/article`,
299
+ role: "article",
300
+ filter: (data) => data.subject instanceof import_functions.ScriptType,
301
+ component: ({ data }) => /* @__PURE__ */ import_react.default.createElement(ScriptContainer, {
302
+ script: data.subject,
303
+ env: compiler.environment
304
+ })
305
+ }),
306
+ (0, import_app_framework.createSurface)({
307
+ id: `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/automation`,
308
+ role: "complementary--automation",
309
+ disposition: "hoist",
310
+ filter: (data) => data.subject instanceof import_functions.ScriptType,
311
+ component: ({ data }) => /* @__PURE__ */ import_react.default.createElement(AutomationPanel, {
312
+ subject: data.subject
313
+ })
314
+ }),
315
+ (0, import_app_framework.createSurface)({
316
+ id: `${import_chunk_6LYX73ZT.SCRIPT_PLUGIN}/settings-panel`,
317
+ role: "complementary--settings",
318
+ filter: (data) => data.subject instanceof import_functions.ScriptType,
319
+ component: ({ data }) => /* @__PURE__ */ import_react.default.createElement(ScriptSettingsPanel, {
320
+ script: data.subject
321
+ })
322
+ })
323
+ ]
389
324
  },
390
325
  intent: {
391
- resolver: (intent) => {
392
- switch (intent.action) {
393
- case import_chunk_DQYAU2CJ.ScriptAction.CREATE: {
394
- return {
395
- data: (0, import_live_object.create)(import_chunk_DQYAU2CJ.ScriptType, {
396
- source: (0, import_live_object.create)(import_types.TextType, {
397
- content: import_chunk_WPP65EYS.templates[0].source
398
- })
399
- })
400
- };
401
- }
326
+ resolvers: () => (0, import_app_framework.createResolver)(import_chunk_PK3OQP5L.ScriptAction.Create, ({ name }) => ({
327
+ data: {
328
+ object: (0, import_live_object.create)(import_functions.ScriptType, {
329
+ source: (0, import_live_object.makeRef)((0, import_live_object.create)(import_types.TextType, {
330
+ content: import_chunk_WPP65EYS.templates[0].source
331
+ }))
332
+ })
402
333
  }
403
- }
334
+ }))
404
335
  }
405
336
  }
406
337
  };
@@ -411,13 +342,11 @@ var src_default = ScriptPlugin;
411
342
  AutomationPanel,
412
343
  Bundler,
413
344
  Compiler,
414
- FunctionType,
415
345
  ScriptAction,
416
346
  ScriptContainer,
417
347
  ScriptPlugin,
418
348
  ScriptSettings,
419
349
  ScriptSettingsPanel,
420
- ScriptType,
421
350
  initializeBundler
422
351
  });
423
352
  //# sourceMappingURL=index.cjs.map