@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
@@ -14,13 +14,13 @@ export default function UserQuestion({ question }) {
14
14
  display: 'flex',
15
15
  alignItems: 'center',
16
16
  gap: 1,
17
- }, children: [((_a = authSession === null || authSession === void 0 ? void 0 : authSession.user) === null || _a === void 0 ? void 0 : _a.did) && (_jsx(Box, { sx: {
17
+ }, children: [((_a = authSession === null || authSession === void 0 ? void 0 : authSession.user) === null || _a === void 0 ? void 0 : _a.did) && (_jsx(Box, { className: "user", sx: {
18
18
  width: 30,
19
19
  height: 30,
20
- }, children: _jsx(Avatar, { size: 30, did: user === null || user === void 0 ? void 0 : user.did, variant: "circle", shape: "circle", src: user === null || user === void 0 ? void 0 : user.avatar }) })), _jsx(Box, { sx: {
21
- padding: '6px 8px',
20
+ }, children: _jsx(Avatar, { size: 30, did: user === null || user === void 0 ? void 0 : user.did, variant: "circle", shape: "circle", src: user === null || user === void 0 ? void 0 : user.avatar }) })), _jsx(Box, { className: "question", sx: {
21
+ padding: '6px 12px',
22
22
  borderRadius: 1,
23
23
  // borderTopLeftRadius: 0,
24
24
  backgroundColor: 'grey.200',
25
- }, children: _jsx(ClickToCopy, { locale: locale, unstyled: true, children: _jsx(Typography, { sx: Object.assign({ fontWeight: 500, fontSize: 13, maxWidth: 300, color: 'textColor' }, getLineClamp(1)), children: question }) }) })] }));
25
+ }, children: _jsx(ClickToCopy, { locale: locale, unstyled: true, children: _jsx(Typography, { sx: Object.assign({ fontWeight: 500, fontSize: 13, maxWidth: 300, color: 'textColor', textAlign: 'left' }, getLineClamp(1)), children: question }) }) })] }));
26
26
  }
@@ -1,10 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMediaQuery } from '@mui/material';
2
3
  import { createContext, useContext, useMemo, useState } from 'react';
3
4
  const context = createContext(undefined);
4
5
  let cancelAutoScrollTimer;
5
6
  export function V0RuntimeProvider({ children }) {
6
7
  const [currentMessageTaskId, setCurrentMessageTaskId] = useState();
7
8
  const [propertiesValueMap, setPropertiesValueMap] = useState({});
9
+ const isMobile = useMediaQuery((theme) => theme.breakpoints.down('sm'));
8
10
  const state = useMemo(() => ({
9
11
  setCurrentMessageTaskId: (taskId) => {
10
12
  setCurrentMessageTaskId(taskId);
@@ -37,7 +39,8 @@ export function V0RuntimeProvider({ children }) {
37
39
  setPropertiesValueMap: (valueMap) => {
38
40
  setPropertiesValueMap(Object.assign(Object.assign({}, propertiesValueMap), valueMap));
39
41
  },
40
- }), [setCurrentMessageTaskId, currentMessageTaskId, propertiesValueMap, setPropertiesValueMap]);
42
+ isMobile,
43
+ }), [setCurrentMessageTaskId, currentMessageTaskId, propertiesValueMap, setPropertiesValueMap, isMobile]);
41
44
  return _jsx(context.Provider, { value: state, children: children });
42
45
  }
43
46
  export function useV0RuntimeContext() {
@@ -1 +1,7 @@
1
- export { Icon } from '@iconify/react';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Icon as IconifyIcon } from '@iconify/react';
3
+ import { Box } from '@mui/material';
4
+ export function Icon(props) {
5
+ return _jsx(Box, Object.assign({ component: IconifyIcon }, props));
6
+ }
7
+ export default Icon;
@@ -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
  }
@@ -18,6 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
+ import set from 'lodash/set';
21
22
  import { useDeferredValue, useEffect, useRef, useState } from 'react';
22
23
  import { create } from 'zustand';
23
24
  import { immer } from 'zustand/middleware/immer';
@@ -175,6 +176,16 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
175
176
  if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
176
177
  propertiesFromCode = {};
177
178
  m.PROPERTIES_SCHEMA.forEach((data, index) => {
179
+ var _a, _b, _c;
180
+ // @ts-ignore
181
+ (_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) => {
182
+ var _a, _b;
183
+ const { code: localKey } = item;
184
+ if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
185
+ // fallback to en
186
+ set(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
187
+ }
188
+ });
178
189
  propertiesFromCode[data.id] = {
179
190
  index,
180
191
  data,