@blocklet/pages-kit 0.2.319 → 0.2.321

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 (40) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +11 -4
  2. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +4 -0
  3. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +2 -6
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +29 -17
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +36 -17
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +84 -77
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -2
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +7 -5
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +4 -4
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +4 -1
  11. package/lib/cjs/builtin/iconify/react.js +8 -2
  12. package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +62 -0
  13. package/lib/cjs/components/CustomComponentRenderer/index.js +9 -1
  14. package/lib/cjs/components/CustomComponentRenderer/state.js +14 -0
  15. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  16. package/lib/cjs/utils/inject-global-components-dump-json.js +8 -3
  17. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +11 -4
  18. package/lib/esm/builtin/async/ai-runtime/locales/index.js +4 -0
  19. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +2 -6
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +29 -17
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +36 -17
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +84 -78
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -2
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +7 -5
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +4 -4
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +4 -1
  27. package/lib/esm/builtin/iconify/react.js +7 -1
  28. package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +36 -0
  29. package/lib/esm/components/CustomComponentRenderer/index.js +6 -1
  30. package/lib/esm/components/CustomComponentRenderer/state.js +11 -0
  31. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  32. package/lib/esm/utils/inject-global-components-dump-json.js +8 -3
  33. package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +3 -0
  34. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +4 -0
  35. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +1 -5
  36. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.d.ts +1 -0
  37. package/lib/types/builtin/iconify/react.d.ts +2 -1
  38. package/lib/types/components/CustomComponentRenderer/BlockletReactComponentRenderer.d.ts +2 -0
  39. package/lib/types/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +4 -4
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useV0RuntimeContext = exports.V0RuntimeProvider = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const material_1 = require("@mui/material");
5
6
  const react_1 = require("react");
6
7
  const context = (0, react_1.createContext)(undefined);
7
8
  let cancelAutoScrollTimer;
8
9
  function V0RuntimeProvider({ children }) {
9
10
  const [currentMessageTaskId, setCurrentMessageTaskId] = (0, react_1.useState)();
10
11
  const [propertiesValueMap, setPropertiesValueMap] = (0, react_1.useState)({});
12
+ const isMobile = (0, material_1.useMediaQuery)((theme) => theme.breakpoints.down('sm'));
11
13
  const state = (0, react_1.useMemo)(() => ({
12
14
  setCurrentMessageTaskId: (taskId) => {
13
15
  setCurrentMessageTaskId(taskId);
@@ -40,7 +42,8 @@ function V0RuntimeProvider({ children }) {
40
42
  setPropertiesValueMap: (valueMap) => {
41
43
  setPropertiesValueMap(Object.assign(Object.assign({}, propertiesValueMap), valueMap));
42
44
  },
43
- }), [setCurrentMessageTaskId, currentMessageTaskId, propertiesValueMap, setPropertiesValueMap]);
45
+ isMobile,
46
+ }), [setCurrentMessageTaskId, currentMessageTaskId, propertiesValueMap, setPropertiesValueMap, isMobile]);
44
47
  return (0, jsx_runtime_1.jsx)(context.Provider, { value: state, children: children });
45
48
  }
46
49
  exports.V0RuntimeProvider = V0RuntimeProvider;
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Icon = void 0;
4
- var react_1 = require("@iconify/react");
5
- Object.defineProperty(exports, "Icon", { enumerable: true, get: function () { return react_1.Icon; } });
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("@iconify/react");
6
+ const material_1 = require("@mui/material");
7
+ function Icon(props) {
8
+ return (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_1.Icon }, props));
9
+ }
10
+ exports.Icon = Icon;
11
+ exports.default = Icon;
@@ -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
- 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: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }) }));
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
  }
@@ -42,8 +42,12 @@ var __rest = (this && this.__rest) || function (s, e) {
42
42
  }
43
43
  return t;
44
44
  };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
45
48
  Object.defineProperty(exports, "__esModule", { value: true });
46
49
  exports.transpileAndLoadScript = exports.useComponent = exports.customComponentStates = void 0;
50
+ const set_1 = __importDefault(require("lodash/set"));
47
51
  const react_1 = require("react");
48
52
  const zustand_1 = require("zustand");
49
53
  const immer_1 = require("zustand/middleware/immer");
@@ -203,6 +207,16 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
203
207
  if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
204
208
  propertiesFromCode = {};
205
209
  m.PROPERTIES_SCHEMA.forEach((data, index) => {
210
+ var _a, _b, _c;
211
+ // @ts-ignore
212
+ (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.languages) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, (item) => {
213
+ var _a, _b;
214
+ const { code: localKey } = item;
215
+ if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
216
+ // fallback to en
217
+ (0, set_1.default)(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
218
+ }
219
+ });
206
220
  propertiesFromCode[data.id] = {
207
221
  index,
208
222
  data,