@blocklet/pages-kit 0.2.319 → 0.2.320

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.
@@ -28,14 +28,10 @@ export default function SimpleOutput() {
28
28
  if (!(outputs === null || outputs === void 0 ? void 0 : outputs.length))
29
29
  return null;
30
30
  return (_jsx(Stack, { gap: 2, children: outputs.map((output) => {
31
- var _a, _b, _c, _d, _e;
31
+ var _a, _b, _c, _d, _e, _f;
32
32
  const value = output.name === RuntimeOutputVariable.text
33
33
  ? (_a = message.result) === null || _a === void 0 ? void 0 : _a.content
34
34
  : (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e[output.name];
35
- return (_jsx(CustomComponentRenderer, { instanceId: output.id, componentId: output.appearance.componentId, properties: output.appearance.componentProperties, props: {
36
- output,
37
- outputValue: value,
38
- writing: output.name === RuntimeOutputVariable.text && message.loading,
39
- } }, output.id));
35
+ return (_jsx(CustomComponentRenderer, { instanceId: output.id, componentId: output.appearance.componentId, properties: output.appearance.componentProperties, props: Object.assign({ output, outputValue: value, writing: output.name === RuntimeOutputVariable.text && message.loading }, (((_f = output === null || output === void 0 ? void 0 : output.appearance) === null || _f === void 0 ? void 0 : _f.componentProps) || {})) }, output.id));
40
36
  }) }));
41
37
  }
@@ -0,0 +1,36 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import React, { useMemo } from 'react';
14
+ import { getComponentMountPoint, joinURL } from '../../builtin/utils';
15
+ export default function BlockletReactComponentRenderer(_a) {
16
+ var props = __rest(_a, []);
17
+ const url = useMemo(() => {
18
+ var _a, _b, _c, _d;
19
+ const did = (_b = (_a = props.properties) === null || _a === void 0 ? void 0 : _a.blockletDid) === null || _b === void 0 ? void 0 : _b.value;
20
+ const path = (_d = (_c = props.properties) === null || _c === void 0 ? void 0 : _c.componentPath) === null || _d === void 0 ? void 0 : _d.value;
21
+ if (!did || !path)
22
+ return null;
23
+ return joinURL(window.location.origin, getComponentMountPoint(did), path);
24
+ }, [props.properties]);
25
+ if (!url) {
26
+ throw new Error('Missing required properties `blockletDid` or `componentPath`');
27
+ }
28
+ const C = loadComponent(url);
29
+ return _jsx(C, Object.assign({}, props.props));
30
+ }
31
+ const COMPONENTS_CACHE = {};
32
+ function loadComponent(url) {
33
+ var _a;
34
+ (_a = COMPONENTS_CACHE[url]) !== null && _a !== void 0 ? _a : (COMPONENTS_CACHE[url] = React.lazy(() => import(url)));
35
+ return COMPONENTS_CACHE[url];
36
+ }
@@ -13,6 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { Alert, Box } from '@mui/material';
14
14
  import { ErrorBoundary } from 'react-error-boundary';
15
15
  import { RenderNestedComponent } from '../../utils/property';
16
+ import BlockletReactComponentRenderer from './BlockletReactComponentRenderer';
16
17
  import { DevProvider, useDev } from './DevProvider';
17
18
  import { useComponent } from './state';
18
19
  export * from './state';
@@ -21,8 +22,12 @@ export default function CustomComponentRenderer(_a) {
21
22
  var _b;
22
23
  var { dev } = _a, props = __rest(_a, ["dev"]);
23
24
  const inheritedDev = useDev();
24
- return (_jsx(ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: _jsx(DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }) }));
25
+ const BuiltinComponent = BuiltinComponents[props.componentId];
26
+ return (_jsx(ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: _jsx(DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: BuiltinComponent ? (_jsx(BuiltinComponent, Object.assign({}, props))) : (_jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId }))) }) }));
25
27
  }
28
+ const BuiltinComponents = {
29
+ 'blocklet-react-component': BlockletReactComponentRenderer,
30
+ };
26
31
  function ErrorView({ error }) {
27
32
  return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
28
33
  }