@dxos/plugin-script 0.7.5-main.499c70c → 0.7.5-main.6a330ac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs +258 -0
- package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs +251 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs +15 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs.map +7 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs +475 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs.map +7 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs +40 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs +234 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs.map +7 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs +82 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +146 -289
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs +45 -0
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs +81 -0
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs.map +7 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs +24 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +6 -4
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs +274 -0
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs +267 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs.map +7 -0
- package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-5UH3F7TA.cjs} +11 -8
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → chunk-ALY3N6PW.cjs} +12 -8
- package/dist/lib/node/chunk-ALY3N6PW.cjs.map +7 -0
- package/dist/lib/node/{chunk-PK3OQP5L.cjs → chunk-DJGLGRQV.cjs} +26 -11
- package/dist/lib/node/chunk-DJGLGRQV.cjs.map +7 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
- package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs +261 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs.map +7 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs +498 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs.map +7 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs +104 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +138 -278
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs +59 -0
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-EGSE3FMN.cjs +96 -0
- package/dist/lib/node/react-surface-EGSE3FMN.cjs.map +7 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs +38 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs.map +7 -0
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs +259 -0
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs +252 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs +16 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs +476 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-P2V2Y5LV.mjs} +7 -4
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs +235 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs +41 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs +71 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs.map +7 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs +83 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +146 -289
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs +82 -0
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs.map +7 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs +25 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +6 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -3
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compiler.d.ts +4 -0
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings.d.ts +4 -0
- package/dist/types/src/capabilities/settings.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +10 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -0
- package/dist/types/src/components/{Toolbar/Toolbar.stories.d.ts → ScriptToolbar/ScriptToolbar.stories.d.ts} +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts +2 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/deploy.d.ts +48 -0
- package/dist/types/src/hooks/deploy.d.ts.map +1 -0
- package/dist/types/src/hooks/format.d.ts +25 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/template.d.ts +31 -0
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts +14 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts +10 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/hooks/view.d.ts +33 -0
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts +1 -4
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts +3 -0
- package/dist/types/src/templates/discord.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts +2 -1
- package/dist/types/src/templates/email.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +3 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -4
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/{templates.d.ts → templates/index.d.ts} +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +100 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +14 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -46
- package/src/ScriptPlugin.tsx +80 -91
- package/src/capabilities/artifact-definition.ts +224 -0
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/compiler.ts +33 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +46 -0
- package/src/capabilities/react-surface.tsx +60 -0
- package/src/capabilities/settings.ts +14 -0
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +69 -9
- package/src/components/ScriptSettings/ScriptSettings.tsx +28 -4
- package/src/components/ScriptSettingsPanel.tsx +139 -51
- package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +53 -0
- package/src/{bundler → components/ScriptToolbar}/index.ts +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +75 -10
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/hooks/deploy.ts +169 -0
- package/src/hooks/format.ts +47 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/template.ts +64 -0
- package/src/hooks/useToolbarAction.ts +54 -0
- package/src/hooks/useToolbarState.ts +16 -0
- package/src/hooks/view.ts +55 -0
- package/src/index.ts +2 -7
- package/src/meta.ts +4 -2
- package/src/templates/chat.ts +4 -4
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/echo.ts +5 -1
- package/src/templates/email.ts +26 -23
- package/src/templates/forex-effect.ts +41 -0
- package/src/templates/forex.ts +23 -16
- package/src/{templates.ts → templates/index.ts} +20 -5
- package/src/translations.ts +26 -0
- package/src/types.ts +19 -18
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs +0 -78
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs +0 -415
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs.map +0 -7
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs +0 -286
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-C7VBULMK.mjs +0 -18
- package/dist/lib/browser/chunk-C7VBULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-K7KY6YMG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQA3EB5K.mjs +0 -26
- package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs +0 -104
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs +0 -426
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs.map +0 -7
- package/dist/lib/node/chunk-4INUJLXL.cjs.map +0 -7
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +0 -7
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +0 -7
- package/dist/lib/node/chunk-WPP65EYS.cjs +0 -298
- package/dist/lib/node/chunk-WPP65EYS.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs +0 -79
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs +0 -416
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs +0 -288
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +0 -27
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OFYGBUNI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -39
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +0 -17
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/index.d.ts +0 -4
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +0 -12
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +0 -6
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptEditor.d.ts +0 -9
- package/dist/types/src/components/ScriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/templates.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -54
- package/src/bundler/bundler.ts +0 -250
- package/src/components/AutomationPanel/AutomationPanel.tsx +0 -104
- package/src/components/AutomationPanel/index.ts +0 -9
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +0 -55
- package/src/components/ScriptBlock/ScriptBlock.tsx +0 -102
- package/src/components/ScriptBlock/index.ts +0 -5
- package/src/components/ScriptEditor.tsx +0 -193
- package/src/components/Toolbar/Toolbar.tsx +0 -177
- package/src/components/Toolbar/index.ts +0 -5
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../../../src/components/Toolbar/Toolbar.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAIL,KAAK,eAAe,EAOrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,eAAe,CACxC;IACE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,GAAG,mBAAmB,GACrB,iBAAiB,CACpB,CAAC;AAEF,eAAO,MAAM,OAAO,uHAWjB,YAAY,sBA4Dd,CAAC;AA0BF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,gBAAgB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,cAAc,oCAA0C,mBAAmB,sBAkBvF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,YAAY,2BAA4B,iBAAiB,sBAcrE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Toolbar/Toolbar.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAO7C,eAAO,MAAM,OAAO;;;;;;;;CAQnB,CAAC;AAEF,QAAA,MAAM,IAAI,EAAE,IAIX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Toolbar/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/templates.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,QAAQ,EA6B/B,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2022 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
|
-
import { beforeAll, describe, expect, test } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { isNode } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
import { Bundler, initializeBundler } from './bundler';
|
|
12
|
-
|
|
13
|
-
describe('Bundler', () => {
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
if (!isNode()) {
|
|
16
|
-
await initializeBundler({ wasmUrl });
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Basic', async () => {
|
|
21
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
22
|
-
const result = await bundler.bundle('const x = 100'); // TODO(burdon): Test import.
|
|
23
|
-
expect(result.bundle).to.exist;
|
|
24
|
-
expect(result.error).to.not.exist;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('Import', async () => {
|
|
28
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
29
|
-
const result = await bundler.bundle(`
|
|
30
|
-
import { Filter } from './runtime.js';
|
|
31
|
-
|
|
32
|
-
const query = Filter.typename('dxos.org/type/Example');
|
|
33
|
-
`);
|
|
34
|
-
expect(result.bundle).to.exist;
|
|
35
|
-
expect(result.error).to.not.exist;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('HTTPS Import', async () => {
|
|
39
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
40
|
-
const result = await bundler.bundle(`
|
|
41
|
-
import { Octokit } from 'https://esm.sh/octokit';
|
|
42
|
-
const octokit = new Octokit();
|
|
43
|
-
`);
|
|
44
|
-
expect(result.bundle).to.exist;
|
|
45
|
-
expect(result.error).to.not.exist;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('Error', async () => {
|
|
49
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
50
|
-
const result = await bundler.bundle("import missing from './module'; missing();");
|
|
51
|
-
expect(result.bundle).to.not.exist;
|
|
52
|
-
expect(result.error).to.exist;
|
|
53
|
-
});
|
|
54
|
-
});
|
package/src/bundler/bundler.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type BuildOptions } from 'esbuild';
|
|
6
|
-
import { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';
|
|
7
|
-
|
|
8
|
-
import { subtleCrypto } from '@dxos/crypto';
|
|
9
|
-
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
|
|
12
|
-
export type Import = {
|
|
13
|
-
moduleUrl: string;
|
|
14
|
-
defaultImport: boolean;
|
|
15
|
-
namedImports: string[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type BundlerResult = {
|
|
19
|
-
timestamp: number;
|
|
20
|
-
sourceHash: Buffer;
|
|
21
|
-
imports?: Import[];
|
|
22
|
-
bundle?: string;
|
|
23
|
-
error?: any;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type BundlerOptions = {
|
|
27
|
-
platform: BuildOptions['platform'];
|
|
28
|
-
sandboxedModules: string[];
|
|
29
|
-
remoteModules: Record<string, string>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
let initialized: Promise<void>;
|
|
33
|
-
export const initializeBundler = async (options: { wasmUrl: string }) => {
|
|
34
|
-
await (initialized ??= initialize({
|
|
35
|
-
wasmURL: options.wasmUrl,
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* ESBuild bundler.
|
|
41
|
-
*/
|
|
42
|
-
export class Bundler {
|
|
43
|
-
constructor(private readonly _options: BundlerOptions) {}
|
|
44
|
-
|
|
45
|
-
async bundle(source: string): Promise<BundlerResult> {
|
|
46
|
-
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
47
|
-
|
|
48
|
-
const createResult = async (result?: Partial<BundlerResult>) => {
|
|
49
|
-
return {
|
|
50
|
-
timestamp: Date.now(),
|
|
51
|
-
sourceHash: Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))),
|
|
52
|
-
...result,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
if (this._options.platform === 'browser') {
|
|
57
|
-
invariant(initialized, 'Compiler not initialized.');
|
|
58
|
-
await initialized;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const imports = analyzeSourceFileImports(source);
|
|
62
|
-
|
|
63
|
-
// https://esbuild.github.io/api/#build
|
|
64
|
-
try {
|
|
65
|
-
const result = await build({
|
|
66
|
-
platform: options.platform,
|
|
67
|
-
conditions: ['workerd', 'browser'],
|
|
68
|
-
metafile: true,
|
|
69
|
-
write: false,
|
|
70
|
-
entryPoints: ['memory:main.tsx'],
|
|
71
|
-
bundle: true,
|
|
72
|
-
format: 'esm',
|
|
73
|
-
plugins: [
|
|
74
|
-
{
|
|
75
|
-
name: 'memory',
|
|
76
|
-
setup: (build) => {
|
|
77
|
-
build.onResolve({ filter: /^\.\/runtime\.js$/ }, ({ path }) => {
|
|
78
|
-
return { path, external: true };
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {
|
|
82
|
-
return { path: './runtime.js', external: true };
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
build.onResolve({ filter: /^memory:/ }, ({ path }) => {
|
|
86
|
-
return { path: path.split(':')[1], namespace: 'memory' };
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {
|
|
90
|
-
if (path === 'main.tsx') {
|
|
91
|
-
return {
|
|
92
|
-
contents: source,
|
|
93
|
-
loader: 'tsx',
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
for (const module of providedModules) {
|
|
99
|
-
build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {
|
|
100
|
-
return { path, namespace: 'injected-module' };
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {
|
|
105
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
106
|
-
return {
|
|
107
|
-
contents: `
|
|
108
|
-
const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
109
|
-
export { ${namedImports.join(',')} };
|
|
110
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
111
|
-
`,
|
|
112
|
-
loader: 'tsx',
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
httpPlugin,
|
|
118
|
-
],
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
log('compile complete', result.metafile);
|
|
122
|
-
|
|
123
|
-
return await createResult({
|
|
124
|
-
imports: this.analyzeImports(result),
|
|
125
|
-
bundle: result.outputFiles![0].text,
|
|
126
|
-
});
|
|
127
|
-
} catch (err) {
|
|
128
|
-
return await createResult({ error: err });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
133
|
-
analyzeImports(result: BuildResult): Import[] {
|
|
134
|
-
invariant(result.outputFiles);
|
|
135
|
-
|
|
136
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
137
|
-
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
138
|
-
return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {
|
|
139
|
-
const namedImports: string[] = [];
|
|
140
|
-
|
|
141
|
-
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
142
|
-
if (parsedImport?.[2]) {
|
|
143
|
-
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
144
|
-
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
145
|
-
if (namedImportsMatch) {
|
|
146
|
-
namedImportsMatch[1].split(',').forEach((importName) => {
|
|
147
|
-
namedImports.push(importName.trim());
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
moduleUrl: entry.path,
|
|
154
|
-
defaultImport: !!parsedImport?.[1],
|
|
155
|
-
namedImports,
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
analyzeSourceFileImports(code: string) {
|
|
161
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
162
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
163
|
-
return parsedImports.map((capture) => {
|
|
164
|
-
return {
|
|
165
|
-
defaultImportName: capture[1],
|
|
166
|
-
namedImports: capture[2]?.split(',').map((importName) => importName.trim()),
|
|
167
|
-
wildcardImportName: capture[3],
|
|
168
|
-
moduleIdentifier: capture[4],
|
|
169
|
-
quotes: capture[5],
|
|
170
|
-
};
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// https://regex101.com/r/FEN5ks/1
|
|
176
|
-
// https://stackoverflow.com/a/73265022
|
|
177
|
-
// $1 = default import name (can be non-existent)
|
|
178
|
-
// $2 = destructured exports (can be non-existent)
|
|
179
|
-
// $3 = wildcard import name (can be non-existent)
|
|
180
|
-
// $4 = module identifier
|
|
181
|
-
// $5 = quotes used (either ' or ")
|
|
182
|
-
const IMPORT_REGEX =
|
|
183
|
-
/import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
184
|
-
|
|
185
|
-
const NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
186
|
-
|
|
187
|
-
const allMatches = (regex: RegExp, str: string) => {
|
|
188
|
-
regex.lastIndex = 0;
|
|
189
|
-
|
|
190
|
-
let match;
|
|
191
|
-
const matches = [];
|
|
192
|
-
while ((match = regex.exec(str))) {
|
|
193
|
-
matches.push(match);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return matches;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
type ParsedImport = {
|
|
200
|
-
defaultImportName?: string;
|
|
201
|
-
namedImports: string[];
|
|
202
|
-
wildcardImportName?: string;
|
|
203
|
-
moduleIdentifier: string;
|
|
204
|
-
quotes: string;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const analyzeSourceFileImports = (code: string): ParsedImport[] => {
|
|
208
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
209
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
210
|
-
return parsedImports.map((capture) => {
|
|
211
|
-
return {
|
|
212
|
-
defaultImportName: capture[1],
|
|
213
|
-
namedImports: capture[2]
|
|
214
|
-
?.trim()
|
|
215
|
-
.slice(1, -1)
|
|
216
|
-
.split(',')
|
|
217
|
-
.map((importName) => importName.trim()),
|
|
218
|
-
wildcardImportName: capture[3],
|
|
219
|
-
moduleIdentifier: capture[4],
|
|
220
|
-
quotes: capture[5],
|
|
221
|
-
};
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const httpPlugin: Plugin = {
|
|
226
|
-
name: 'http',
|
|
227
|
-
setup: (build) => {
|
|
228
|
-
// Intercept import paths starting with "http:" and "https:" so esbuild doesn't attempt to map them to a file system location.
|
|
229
|
-
// Tag them with the "http-url" namespace to associate them with this plugin.
|
|
230
|
-
build.onResolve({ filter: /^https?:\/\// }, (args) => ({
|
|
231
|
-
path: args.path,
|
|
232
|
-
namespace: 'http-url',
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
// We also want to intercept all import paths inside downloaded files and resolve them against the original URL.
|
|
236
|
-
// All of these files will be in the "http-url" namespace.
|
|
237
|
-
// Make sure to keep the newly resolved URL in the "http-url" namespace so imports inside it will also be resolved as URLs recursively.
|
|
238
|
-
build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({
|
|
239
|
-
path: new URL(args.path, args.importer).toString(),
|
|
240
|
-
namespace: 'http-url',
|
|
241
|
-
}));
|
|
242
|
-
|
|
243
|
-
// When a URL is loaded, we want to actually download the content from the internet.
|
|
244
|
-
// This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.
|
|
245
|
-
build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {
|
|
246
|
-
const response = await fetch(args.path);
|
|
247
|
-
return { contents: await response.text(), loader: 'jsx' };
|
|
248
|
-
});
|
|
249
|
-
},
|
|
250
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { failUndefined } from '@dxos/debug';
|
|
8
|
-
import { FunctionType, ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
9
|
-
import { useClient } from '@dxos/react-client';
|
|
10
|
-
import { Filter, getMeta, getSpace, type ReactiveEchoObject, useQuery } from '@dxos/react-client/echo';
|
|
11
|
-
import { Select, useTranslation } from '@dxos/react-ui';
|
|
12
|
-
|
|
13
|
-
import { SCRIPT_PLUGIN } from '../../meta';
|
|
14
|
-
import { DebugPanel } from '../DebugPanel';
|
|
15
|
-
|
|
16
|
-
export interface AutomationPanelProps {
|
|
17
|
-
subject: ReactiveEchoObject<any>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const AutomationPanel = ({ subject }: AutomationPanelProps) => {
|
|
21
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
22
|
-
const space = getSpace(subject);
|
|
23
|
-
|
|
24
|
-
// TODO(dmaretskyi): Parametric query.
|
|
25
|
-
const functions = useQuery(
|
|
26
|
-
space ?? undefined,
|
|
27
|
-
subject instanceof ScriptType
|
|
28
|
-
? Filter.schema(FunctionType, { source: subject })
|
|
29
|
-
: Filter.schema(FunctionType, (fn) => fn.binding != null),
|
|
30
|
-
{},
|
|
31
|
-
[subject],
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const [selectedFunction, setSelectedFunction] = useState<FunctionType | null>(null);
|
|
35
|
-
const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className='h-full flex flex-col'>
|
|
39
|
-
{!(subject instanceof ScriptType) && (
|
|
40
|
-
<BindingSelect
|
|
41
|
-
selectedFunction={selectedFunction}
|
|
42
|
-
setSelectedFunction={setSelectedFunction}
|
|
43
|
-
functions={functions}
|
|
44
|
-
/>
|
|
45
|
-
)}
|
|
46
|
-
{chatFunction && <ChatPanel fn={chatFunction} subject={subject} />}
|
|
47
|
-
{subject instanceof ScriptType && functions.length === 0 && <div className='p-1'>{t('not deployed')}</div>}
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export interface ChatPanelProps {
|
|
53
|
-
fn: FunctionType;
|
|
54
|
-
subject: ReactiveEchoObject<any>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ChatPanel = ({ fn, subject }: ChatPanelProps) => {
|
|
58
|
-
const client = useClient();
|
|
59
|
-
const space = getSpace(fn);
|
|
60
|
-
const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
61
|
-
const functionUrl = useMemo(() => {
|
|
62
|
-
if (!existingFunctionUrl) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
67
|
-
spaceId: space?.id,
|
|
68
|
-
subjectId: subject?.id,
|
|
69
|
-
});
|
|
70
|
-
}, [existingFunctionUrl, space, subject]);
|
|
71
|
-
|
|
72
|
-
return <DebugPanel functionUrl={functionUrl} classNames='flex-1' />;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export interface BindingSelectProps {
|
|
76
|
-
selectedFunction: FunctionType | null;
|
|
77
|
-
setSelectedFunction: (fn: FunctionType) => void;
|
|
78
|
-
functions: FunctionType[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const BindingSelect = ({ selectedFunction, setSelectedFunction, functions }: BindingSelectProps) => {
|
|
82
|
-
return (
|
|
83
|
-
<Select.Root
|
|
84
|
-
value={selectedFunction?.id}
|
|
85
|
-
onValueChange={(id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())}
|
|
86
|
-
>
|
|
87
|
-
<Select.TriggerButton placeholder='Select value' />
|
|
88
|
-
<Select.Portal>
|
|
89
|
-
<Select.Content>
|
|
90
|
-
<Select.ScrollUpButton />
|
|
91
|
-
<Select.Viewport>
|
|
92
|
-
{functions.map(({ id, binding }) => (
|
|
93
|
-
<Select.Option key={id} value={id}>
|
|
94
|
-
{binding}
|
|
95
|
-
</Select.Option>
|
|
96
|
-
))}
|
|
97
|
-
</Select.Viewport>
|
|
98
|
-
<Select.ScrollDownButton />
|
|
99
|
-
<Select.Arrow />
|
|
100
|
-
</Select.Content>
|
|
101
|
-
</Select.Portal>
|
|
102
|
-
</Select.Root>
|
|
103
|
-
);
|
|
104
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
|
-
import { type Meta } from '@storybook/react';
|
|
8
|
-
import React, { useMemo } from 'react';
|
|
9
|
-
|
|
10
|
-
import { ScriptType } from '@dxos/functions';
|
|
11
|
-
import { TextType } from '@dxos/plugin-markdown/types';
|
|
12
|
-
import { create, createObject, makeRef } from '@dxos/react-client/echo';
|
|
13
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
14
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
15
|
-
|
|
16
|
-
import { ScriptBlock } from './ScriptBlock';
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import mainUrl from '../FrameContainer/frame?url';
|
|
19
|
-
|
|
20
|
-
const typename = 'example.com/type/contact';
|
|
21
|
-
|
|
22
|
-
const code = [
|
|
23
|
-
"import { Filter, useQuery, useSpaces} from '@dxos/react-client/echo';",
|
|
24
|
-
"import { Chart, Explorer, Globe } from '@dxos/plugin-explorer';",
|
|
25
|
-
'',
|
|
26
|
-
'export default () => {',
|
|
27
|
-
' const spaces = useSpaces();',
|
|
28
|
-
' const space = spaces[1]',
|
|
29
|
-
` const objects = useQuery(space, Filter.typename('${typename}'));`,
|
|
30
|
-
' return <Chart items={objects} accessor={object => ({ x: object.lat, y: object.lng })} />',
|
|
31
|
-
'}',
|
|
32
|
-
].join('\n');
|
|
33
|
-
|
|
34
|
-
const DefaultStory = () => {
|
|
35
|
-
// TODO(burdon): Review what's the right way to create automerge-backed objects.
|
|
36
|
-
const object = useMemo(
|
|
37
|
-
() => createObject(create(ScriptType, { source: makeRef(create(TextType, { content: code })) })),
|
|
38
|
-
[],
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// TODO(dmaretskyi): Not sure how to provide `containerUrl` here since the html now lives in composer-app.
|
|
42
|
-
// TODO(burdon): Normalize html/frame.tsx with composer-app to test locally.
|
|
43
|
-
return <ScriptBlock script={object} containerUrl={mainUrl} />;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const Default = {};
|
|
47
|
-
|
|
48
|
-
const meta: Meta = {
|
|
49
|
-
title: 'plugins/plugin-script/ScriptBlock',
|
|
50
|
-
component: ScriptBlock,
|
|
51
|
-
render: DefaultStory,
|
|
52
|
-
decorators: [withClientProvider({ createSpace: true }), withTheme, withLayout({ fullscreen: true, tooltips: true })],
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export default meta;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { type ScriptType } from '@dxos/functions';
|
|
10
|
-
import { createDocAccessor, DocAccessor } from '@dxos/react-client/echo';
|
|
11
|
-
import { Toolbar, Button, Icon } from '@dxos/react-ui';
|
|
12
|
-
|
|
13
|
-
import { Bundler, type BundlerResult, initializeBundler } from '../../bundler';
|
|
14
|
-
import { FrameContainer } from '../FrameContainer';
|
|
15
|
-
import { ScriptEditor } from '../ScriptEditor';
|
|
16
|
-
|
|
17
|
-
// Keep in sync with packages/apps/composer-app/script-frame/main.tsx .
|
|
18
|
-
const PROVIDED_MODULES = [
|
|
19
|
-
'react',
|
|
20
|
-
'react-dom/client',
|
|
21
|
-
'@dxos/client',
|
|
22
|
-
'@dxos/react-client',
|
|
23
|
-
'@dxos/react-client/echo',
|
|
24
|
-
'@dxos/plugin-explorer',
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export type ScriptBlockProps = {
|
|
28
|
-
script: ScriptType;
|
|
29
|
-
hideSelector?: boolean;
|
|
30
|
-
|
|
31
|
-
// Url to the page used to host the script in the iframe.
|
|
32
|
-
containerUrl: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @deprecated
|
|
37
|
-
*/
|
|
38
|
-
// TODO(burdon): Cache compiled results in context.
|
|
39
|
-
export const ScriptBlock = ({ script, hideSelector, containerUrl }: ScriptBlockProps) => {
|
|
40
|
-
const source = useMemo(() => script.source && createDocAccessor(script.source.target!, ['content']), [script.source]);
|
|
41
|
-
const [result, setResult] = useState<BundlerResult>();
|
|
42
|
-
const bundler = useMemo(
|
|
43
|
-
() => new Bundler({ platform: 'browser', sandboxedModules: PROVIDED_MODULES, remoteModules: {} }),
|
|
44
|
-
[],
|
|
45
|
-
);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
// TODO(burdon): Create useCompiler hook (with initialization).
|
|
48
|
-
void initializeBundler({ wasmUrl });
|
|
49
|
-
}, []);
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
// TODO(burdon): Throttle and listen for update.
|
|
52
|
-
const t = setTimeout(async () => {
|
|
53
|
-
if (!source) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const result = await bundler.bundle(DocAccessor.getValue(source));
|
|
58
|
-
setResult(result);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return () => clearTimeout(t);
|
|
62
|
-
}, [source]);
|
|
63
|
-
|
|
64
|
-
const handleExec = useCallback(
|
|
65
|
-
async (auto = true) => {
|
|
66
|
-
if (!source) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const result = await bundler.bundle(DocAccessor.getValue(source));
|
|
70
|
-
setResult(result);
|
|
71
|
-
},
|
|
72
|
-
[source],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<div className='flex flex-col grow overflow-hidden'>
|
|
77
|
-
{!hideSelector && (
|
|
78
|
-
<Toolbar.Root>
|
|
79
|
-
<div className='grow' />
|
|
80
|
-
{result?.bundle && !result?.error && (
|
|
81
|
-
<div title={String(result.error)}>
|
|
82
|
-
<Icon icon='ph--check--regular' size={5} classNames='text-green-500' />
|
|
83
|
-
</div>
|
|
84
|
-
)}
|
|
85
|
-
{result?.error && (
|
|
86
|
-
<div title={String(result.error)}>
|
|
87
|
-
<Icon icon='ph--warning--regular' size={5} classNames='text-orange-500' />
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
<Button variant='ghost' onClick={() => handleExec()}>
|
|
91
|
-
<Icon icon='ph--play--regular' size={5} />
|
|
92
|
-
</Button>
|
|
93
|
-
</Toolbar.Root>
|
|
94
|
-
)}
|
|
95
|
-
|
|
96
|
-
<div className='flex'>
|
|
97
|
-
<ScriptEditor script={script} />
|
|
98
|
-
{result && <FrameContainer key={script.id} result={result} containerUrl={containerUrl} />}
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
};
|