@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.
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +2 -6
- package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +62 -0
- package/lib/cjs/components/CustomComponentRenderer/index.js +9 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +2 -6
- package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +36 -0
- package/lib/esm/components/CustomComponentRenderer/index.js +6 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +3 -0
- package/lib/types/components/CustomComponentRenderer/BlockletReactComponentRenderer.d.ts +2 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -33,15 +33,11 @@ function SimpleOutput() {
|
|
|
33
33
|
if (!(outputs === null || outputs === void 0 ? void 0 : outputs.length))
|
|
34
34
|
return null;
|
|
35
35
|
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 2, children: outputs.map((output) => {
|
|
36
|
-
var _a, _b, _c, _d, _e;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
37
|
const value = output.name === types_1.RuntimeOutputVariable.text
|
|
38
38
|
? (_a = message.result) === null || _a === void 0 ? void 0 : _a.content
|
|
39
39
|
: (_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];
|
|
40
|
-
return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: output.id, componentId: output.appearance.componentId, properties: output.appearance.componentProperties, props: {
|
|
41
|
-
output,
|
|
42
|
-
outputValue: value,
|
|
43
|
-
writing: output.name === types_1.RuntimeOutputVariable.text && message.loading,
|
|
44
|
-
} }, output.id));
|
|
40
|
+
return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: output.id, componentId: output.appearance.componentId, properties: output.appearance.componentProperties, props: Object.assign({ output, outputValue: value, writing: output.name === types_1.RuntimeOutputVariable.text && message.loading }, (((_f = output === null || output === void 0 ? void 0 : output.appearance) === null || _f === void 0 ? void 0 : _f.componentProps) || {})) }, output.id));
|
|
45
41
|
}) }));
|
|
46
42
|
}
|
|
47
43
|
exports.default = SimpleOutput;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const utils_1 = require("../../builtin/utils");
|
|
40
|
+
function BlockletReactComponentRenderer(_a) {
|
|
41
|
+
var props = __rest(_a, []);
|
|
42
|
+
const url = (0, react_1.useMemo)(() => {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
const did = (_b = (_a = props.properties) === null || _a === void 0 ? void 0 : _a.blockletDid) === null || _b === void 0 ? void 0 : _b.value;
|
|
45
|
+
const path = (_d = (_c = props.properties) === null || _c === void 0 ? void 0 : _c.componentPath) === null || _d === void 0 ? void 0 : _d.value;
|
|
46
|
+
if (!did || !path)
|
|
47
|
+
return null;
|
|
48
|
+
return (0, utils_1.joinURL)(window.location.origin, (0, utils_1.getComponentMountPoint)(did), path);
|
|
49
|
+
}, [props.properties]);
|
|
50
|
+
if (!url) {
|
|
51
|
+
throw new Error('Missing required properties `blockletDid` or `componentPath`');
|
|
52
|
+
}
|
|
53
|
+
const C = loadComponent(url);
|
|
54
|
+
return (0, jsx_runtime_1.jsx)(C, Object.assign({}, props.props));
|
|
55
|
+
}
|
|
56
|
+
exports.default = BlockletReactComponentRenderer;
|
|
57
|
+
const COMPONENTS_CACHE = {};
|
|
58
|
+
function loadComponent(url) {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = COMPONENTS_CACHE[url]) !== null && _a !== void 0 ? _a : (COMPONENTS_CACHE[url] = react_1.default.lazy(() => Promise.resolve(`${url}`).then(s => __importStar(require(s)))));
|
|
61
|
+
return COMPONENTS_CACHE[url];
|
|
62
|
+
}
|
|
@@ -24,11 +24,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
}
|
|
25
25
|
return t;
|
|
26
26
|
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
27
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
31
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
32
|
const material_1 = require("@mui/material");
|
|
30
33
|
const react_error_boundary_1 = require("react-error-boundary");
|
|
31
34
|
const property_1 = require("../../utils/property");
|
|
35
|
+
const BlockletReactComponentRenderer_1 = __importDefault(require("./BlockletReactComponentRenderer"));
|
|
32
36
|
const DevProvider_1 = require("./DevProvider");
|
|
33
37
|
const state_1 = require("./state");
|
|
34
38
|
__exportStar(require("./state"), exports);
|
|
@@ -37,9 +41,13 @@ function CustomComponentRenderer(_a) {
|
|
|
37
41
|
var _b;
|
|
38
42
|
var { dev } = _a, props = __rest(_a, ["dev"]);
|
|
39
43
|
const inheritedDev = (0, DevProvider_1.useDev)();
|
|
40
|
-
|
|
44
|
+
const BuiltinComponent = BuiltinComponents[props.componentId];
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(DevProvider_1.DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: BuiltinComponent ? ((0, jsx_runtime_1.jsx)(BuiltinComponent, Object.assign({}, props))) : ((0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId }))) }) }));
|
|
41
46
|
}
|
|
42
47
|
exports.default = CustomComponentRenderer;
|
|
48
|
+
const BuiltinComponents = {
|
|
49
|
+
'blocklet-react-component': BlockletReactComponentRenderer_1.default,
|
|
50
|
+
};
|
|
43
51
|
function ErrorView({ error }) {
|
|
44
52
|
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }) }));
|
|
45
53
|
}
|