@blocklet/pages-kit 0.2.227 → 0.2.229

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.
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.call = void 0;
13
+ const utils_1 = require("./utils");
14
+ function call(input) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const prefix = (0, utils_1.getComponentMountPoint)('pages-kit');
17
+ return fetch((0, utils_1.joinURL)(prefix, '/api/call'), {
18
+ method: 'POST',
19
+ headers: Object.assign(Object.assign({}, input.headers), { 'Content-Type': 'application/json' }),
20
+ body: JSON.stringify(input),
21
+ });
22
+ });
23
+ }
24
+ exports.call = call;
@@ -1,33 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Typography = exports.Container = exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = void 0;
3
+ exports.ListItemSecondaryAction = exports.ListItemIcon = exports.ListSubheader = exports.ListItemButton = exports.ListItemAvatar = exports.ListItem = exports.List = exports.Typography = exports.Container = exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = exports.Avatar = exports.useTheme = exports.createTheme = exports.ThemeProvider = void 0;
4
4
  var material_1 = require("@mui/material");
5
+ Object.defineProperty(exports, "ThemeProvider", { enumerable: true, get: function () { return material_1.ThemeProvider; } });
6
+ Object.defineProperty(exports, "createTheme", { enumerable: true, get: function () { return material_1.createTheme; } });
7
+ Object.defineProperty(exports, "useTheme", { enumerable: true, get: function () { return material_1.useTheme; } });
8
+ Object.defineProperty(exports, "Avatar", { enumerable: true, get: function () { return material_1.Avatar; } });
5
9
  Object.defineProperty(exports, "Autocomplete", { enumerable: true, get: function () { return material_1.Autocomplete; } });
6
- var material_2 = require("@mui/material");
7
- Object.defineProperty(exports, "Box", { enumerable: true, get: function () { return material_2.Box; } });
8
- var material_3 = require("@mui/material");
9
- Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return material_3.Button; } });
10
- var material_4 = require("@mui/material");
11
- Object.defineProperty(exports, "ClickAwayListener", { enumerable: true, get: function () { return material_4.ClickAwayListener; } });
12
- var material_5 = require("@mui/material");
13
- Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return material_5.Dialog; } });
14
- var material_6 = require("@mui/material");
15
- Object.defineProperty(exports, "DialogActions", { enumerable: true, get: function () { return material_6.DialogActions; } });
16
- var material_7 = require("@mui/material");
17
- Object.defineProperty(exports, "DialogContent", { enumerable: true, get: function () { return material_7.DialogContent; } });
18
- var material_8 = require("@mui/material");
19
- Object.defineProperty(exports, "DialogTitle", { enumerable: true, get: function () { return material_8.DialogTitle; } });
20
- var material_9 = require("@mui/material");
21
- Object.defineProperty(exports, "Paper", { enumerable: true, get: function () { return material_9.Paper; } });
22
- var material_10 = require("@mui/material");
23
- Object.defineProperty(exports, "Popper", { enumerable: true, get: function () { return material_10.Popper; } });
24
- var material_11 = require("@mui/material");
25
- Object.defineProperty(exports, "Stack", { enumerable: true, get: function () { return material_11.Stack; } });
26
- var material_12 = require("@mui/material");
27
- Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return material_12.Switch; } });
28
- var material_13 = require("@mui/material");
29
- Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return material_13.TextField; } });
30
- var material_14 = require("@mui/material");
31
- Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return material_14.Container; } });
32
- var material_15 = require("@mui/material");
33
- Object.defineProperty(exports, "Typography", { enumerable: true, get: function () { return material_15.Typography; } });
10
+ Object.defineProperty(exports, "Box", { enumerable: true, get: function () { return material_1.Box; } });
11
+ Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return material_1.Button; } });
12
+ Object.defineProperty(exports, "ClickAwayListener", { enumerable: true, get: function () { return material_1.ClickAwayListener; } });
13
+ Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return material_1.Dialog; } });
14
+ Object.defineProperty(exports, "DialogActions", { enumerable: true, get: function () { return material_1.DialogActions; } });
15
+ Object.defineProperty(exports, "DialogContent", { enumerable: true, get: function () { return material_1.DialogContent; } });
16
+ Object.defineProperty(exports, "DialogTitle", { enumerable: true, get: function () { return material_1.DialogTitle; } });
17
+ Object.defineProperty(exports, "Paper", { enumerable: true, get: function () { return material_1.Paper; } });
18
+ Object.defineProperty(exports, "Popper", { enumerable: true, get: function () { return material_1.Popper; } });
19
+ Object.defineProperty(exports, "Stack", { enumerable: true, get: function () { return material_1.Stack; } });
20
+ Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return material_1.Switch; } });
21
+ Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return material_1.TextField; } });
22
+ Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return material_1.Container; } });
23
+ Object.defineProperty(exports, "Typography", { enumerable: true, get: function () { return material_1.Typography; } });
24
+ Object.defineProperty(exports, "List", { enumerable: true, get: function () { return material_1.List; } });
25
+ Object.defineProperty(exports, "ListItem", { enumerable: true, get: function () { return material_1.ListItem; } });
26
+ Object.defineProperty(exports, "ListItemAvatar", { enumerable: true, get: function () { return material_1.ListItemAvatar; } });
27
+ Object.defineProperty(exports, "ListItemButton", { enumerable: true, get: function () { return material_1.ListItemButton; } });
28
+ Object.defineProperty(exports, "ListSubheader", { enumerable: true, get: function () { return material_1.ListSubheader; } });
29
+ Object.defineProperty(exports, "ListItemIcon", { enumerable: true, get: function () { return material_1.ListItemIcon; } });
30
+ Object.defineProperty(exports, "ListItemSecondaryAction", { enumerable: true, get: function () { return material_1.ListItemSecondaryAction; } });
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventSourceParserStream = void 0;
4
+ const eventsource_parser_1 = require("eventsource-parser");
5
+ class EventSourceParserStream extends TransformStream {
6
+ constructor() {
7
+ let parser;
8
+ super({
9
+ start(controller) {
10
+ parser = (0, eventsource_parser_1.createParser)((event) => {
11
+ if (event.type === 'event') {
12
+ try {
13
+ const json = JSON.parse(event.data);
14
+ controller.enqueue(json);
15
+ }
16
+ catch (error) {
17
+ console.error('parse chunk error', { error, data: event.data });
18
+ }
19
+ }
20
+ });
21
+ },
22
+ transform(chunk) {
23
+ parser === null || parser === void 0 ? void 0 : parser.feed(chunk);
24
+ },
25
+ });
26
+ }
27
+ }
28
+ exports.EventSourceParserStream = EventSourceParserStream;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withQuery = exports.joinURL = void 0;
3
+ exports.getComponentMountPoint = exports.getQuery = exports.withQuery = exports.joinURL = void 0;
4
4
  var ufo_1 = require("ufo");
5
5
  Object.defineProperty(exports, "joinURL", { enumerable: true, get: function () { return ufo_1.joinURL; } });
6
6
  Object.defineProperty(exports, "withQuery", { enumerable: true, get: function () { return ufo_1.withQuery; } });
7
+ Object.defineProperty(exports, "getQuery", { enumerable: true, get: function () { return ufo_1.getQuery; } });
8
+ function getComponentMountPoint(name) {
9
+ var _a, _b;
10
+ return (_b = (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.name === name || i.did === name)) === null || _b === void 0 ? void 0 : _b.mountPoint;
11
+ }
12
+ exports.getComponentMountPoint = getComponentMountPoint;
@@ -43,27 +43,14 @@ function ErrorView({ error }) {
43
43
  return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }) }));
44
44
  }
45
45
  function ComponentRenderer(_a) {
46
- var _b;
47
46
  var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
48
47
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
49
48
  throw new Error('Maximum render stack size exceeded');
50
49
  }
51
- if (!((_b = props.dev) === null || _b === void 0 ? void 0 : _b.components)) {
52
- return (0, jsx_runtime_1.jsx)(PreloadRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
53
- }
54
- return (0, jsx_runtime_1.jsx)(DebugRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
55
- }
56
- function PreloadRenderer(props) {
57
- const component = (0, state_1.usePreloadComponent)(props);
58
- if (!component)
59
- return null;
60
- return (0, jsx_runtime_1.jsx)(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
61
- }
62
- function DebugRenderer(props) {
63
- const component = (0, state_1.useTranspileComponent)(props);
50
+ const component = (0, state_1.useComponent)(props);
64
51
  if (!component)
65
52
  return null;
66
- return (0, jsx_runtime_1.jsx)(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
53
+ return ((0, jsx_runtime_1.jsx)(Renderer, Object.assign({ renderCount: renderCount + 1 }, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) })));
67
54
  }
68
55
  function Renderer({ renderCount, Component, locale, props, dev, }) {
69
56
  const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
@@ -43,7 +43,7 @@ var __rest = (this && this.__rest) || function (s, e) {
43
43
  return t;
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.useTranspileComponent = exports.usePreloadComponent = exports.customComponentStates = void 0;
46
+ exports.useComponent = exports.customComponentStates = void 0;
47
47
  const react_1 = require("react");
48
48
  const zustand_1 = require("zustand");
49
49
  const immer_1 = require("zustand/middleware/immer");
@@ -135,13 +135,24 @@ function loadComponents(input) {
135
135
  })) });
136
136
  });
137
137
  }
138
+ function useComponent({ instanceId, componentId, properties, locale, dev }) {
139
+ var _a, _b;
140
+ const transpile = useTranspileComponent({ componentId, locale, properties, dev });
141
+ const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
142
+ const Component = (_a = transpile === null || transpile === void 0 ? void 0 : transpile.Component) !== null && _a !== void 0 ? _a : preload === null || preload === void 0 ? void 0 : preload.Component;
143
+ if (!Component)
144
+ return null;
145
+ const props = (_b = preload === null || preload === void 0 ? void 0 : preload.props) !== null && _b !== void 0 ? _b : transpile === null || transpile === void 0 ? void 0 : transpile.props;
146
+ return { Component, props };
147
+ }
148
+ exports.useComponent = useComponent;
138
149
  const COMPONENT_LOADER_MAP = {};
139
- function usePreloadComponent({ instanceId, componentId, properties: parameters, locale: requestLocale, dev: { mode } = {}, }) {
150
+ function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
140
151
  var _a;
141
152
  const previousRef = (0, react_1.useRef)();
142
- const locale = (0, exports.customComponentStates)((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === requestLocale)) ? requestLocale : undefined; });
153
+ const requestLocale = (0, exports.customComponentStates)((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
143
154
  const defaultLocale = (0, exports.customComponentStates)((s) => s.state.config.defaultLocale);
144
- const realLocale = locale || defaultLocale;
155
+ const realLocale = requestLocale || defaultLocale;
145
156
  const result = (0, exports.customComponentStates)((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
146
157
  if (result) {
147
158
  previousRef.current = result;
@@ -150,16 +161,15 @@ function usePreloadComponent({ instanceId, componentId, properties: parameters,
150
161
  if (realLocale && instanceId) {
151
162
  const key = [instanceId, realLocale].join('-');
152
163
  (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = exports.customComponentStates.getState().loadComponents({
153
- mode,
164
+ mode: dev === null || dev === void 0 ? void 0 : dev.mode,
154
165
  locale: realLocale,
155
- instances: [{ id: instanceId, component: { id: componentId }, properties: parameters }],
166
+ instances: [{ id: instanceId, component: { id: componentId }, properties }],
156
167
  }));
157
168
  if (previousRef.current)
158
169
  return previousRef.current;
159
170
  }
160
171
  return null;
161
172
  }
162
- exports.usePreloadComponent = usePreloadComponent;
163
173
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
164
174
  const [Component, setComponent] = (0, react_1.useState)();
165
175
  const component = (0, property_1.mergeComponent)({
@@ -184,7 +194,6 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
184
194
  props: component.properties,
185
195
  };
186
196
  }
187
- exports.useTranspileComponent = useTranspileComponent;
188
197
  function transpileAndLoadScript(script) {
189
198
  return __awaiter(this, void 0, void 0, function* () {
190
199
  const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
@@ -23,12 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const call = __importStar(require("../builtin/call"));
26
27
  const builtinIconifyReact = __importStar(require("../builtin/iconify/react"));
27
28
  const builtinMuiLab = __importStar(require("../builtin/mui/lab"));
28
29
  const builtinMuiMaterial = __importStar(require("../builtin/mui/material"));
29
30
  const builtinReact = __importStar(require("../builtin/react"));
30
31
  const builtinReactHookForm = __importStar(require("../builtin/react-hook-form"));
31
32
  const reactWrapBalancer = __importStar(require("../builtin/react-wrap-balancer"));
33
+ const stream = __importStar(require("../builtin/stream"));
32
34
  const builtinUtils = __importStar(require("../builtin/utils"));
33
35
  const builtinZustand = __importStar(require("../builtin/zustand"));
34
36
  const builtinZustandMiddlewareImmer = __importStar(require("../builtin/zustand/middleware/immer"));
@@ -46,6 +48,8 @@ function injectGlobalComponents() {
46
48
  '@blocklet/pages-kit/builtin/zustand': builtinZustand,
47
49
  '@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
48
50
  '@blocklet/pages-kit/builtin/react-wrap-balancer': reactWrapBalancer,
51
+ '@blocklet/pages-kit/builtin/call': call,
52
+ '@blocklet/pages-kit/builtin/stream': stream,
49
53
  },
50
54
  require(module) {
51
55
  return win[builtin_1.BuiltinModulesGlobalVariableName].modules[module];
@@ -0,0 +1,20 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getComponentMountPoint, joinURL } from './utils';
11
+ export function call(input) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const prefix = getComponentMountPoint('pages-kit');
14
+ return fetch(joinURL(prefix, '/api/call'), {
15
+ method: 'POST',
16
+ headers: Object.assign(Object.assign({}, input.headers), { 'Content-Type': 'application/json' }),
17
+ body: JSON.stringify(input),
18
+ });
19
+ });
20
+ }
@@ -1,15 +1 @@
1
- export { Autocomplete } from '@mui/material';
2
- export { Box } from '@mui/material';
3
- export { Button } from '@mui/material';
4
- export { ClickAwayListener } from '@mui/material';
5
- export { Dialog } from '@mui/material';
6
- export { DialogActions } from '@mui/material';
7
- export { DialogContent } from '@mui/material';
8
- export { DialogTitle } from '@mui/material';
9
- export { Paper } from '@mui/material';
10
- export { Popper } from '@mui/material';
11
- export { Stack } from '@mui/material';
12
- export { Switch } from '@mui/material';
13
- export { TextField } from '@mui/material';
14
- export { Container } from '@mui/material';
15
- export { Typography } from '@mui/material';
1
+ export { ThemeProvider, createTheme, useTheme, Avatar, Autocomplete, Box, Button, ClickAwayListener, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Popper, Stack, Switch, TextField, Container, Typography, List, ListItem, ListItemAvatar, ListItemButton, ListSubheader, ListItemIcon, ListItemSecondaryAction, } from '@mui/material';
@@ -0,0 +1,24 @@
1
+ import { createParser } from 'eventsource-parser';
2
+ export class EventSourceParserStream extends TransformStream {
3
+ constructor() {
4
+ let parser;
5
+ super({
6
+ start(controller) {
7
+ parser = createParser((event) => {
8
+ if (event.type === 'event') {
9
+ try {
10
+ const json = JSON.parse(event.data);
11
+ controller.enqueue(json);
12
+ }
13
+ catch (error) {
14
+ console.error('parse chunk error', { error, data: event.data });
15
+ }
16
+ }
17
+ });
18
+ },
19
+ transform(chunk) {
20
+ parser === null || parser === void 0 ? void 0 : parser.feed(chunk);
21
+ },
22
+ });
23
+ }
24
+ }
@@ -1 +1,5 @@
1
- export { joinURL, withQuery } from 'ufo';
1
+ export { joinURL, withQuery, getQuery } from 'ufo';
2
+ export function getComponentMountPoint(name) {
3
+ var _a, _b;
4
+ return (_b = (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.name === name || i.did === name)) === null || _b === void 0 ? void 0 : _b.mountPoint;
5
+ }
@@ -14,7 +14,7 @@ import '../../utils/inject-global-components';
14
14
  import { Alert, Box } from '@mui/material';
15
15
  import { ErrorBoundary } from 'react-error-boundary';
16
16
  import { RenderNestedComponent } from '../../utils/property';
17
- import { usePreloadComponent, useTranspileComponent } from './state';
17
+ import { useComponent } from './state';
18
18
  export * from './state';
19
19
  const MAXIMUM_RENDER_STACK_SIZE = 20;
20
20
  export default function CustomComponentRenderer(_a) {
@@ -26,27 +26,14 @@ function ErrorView({ error }) {
26
26
  return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
27
27
  }
28
28
  function ComponentRenderer(_a) {
29
- var _b;
30
29
  var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
31
30
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
32
31
  throw new Error('Maximum render stack size exceeded');
33
32
  }
34
- if (!((_b = props.dev) === null || _b === void 0 ? void 0 : _b.components)) {
35
- return _jsx(PreloadRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
36
- }
37
- return _jsx(DebugRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
38
- }
39
- function PreloadRenderer(props) {
40
- const component = usePreloadComponent(props);
41
- if (!component)
42
- return null;
43
- return _jsx(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
44
- }
45
- function DebugRenderer(props) {
46
- const component = useTranspileComponent(props);
33
+ const component = useComponent(props);
47
34
  if (!component)
48
35
  return null;
49
- return _jsx(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
36
+ return (_jsx(Renderer, Object.assign({ renderCount: renderCount + 1 }, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) })));
50
37
  }
51
38
  function Renderer({ renderCount, Component, locale, props, dev, }) {
52
39
  const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
@@ -109,13 +109,23 @@ function loadComponents(input) {
109
109
  })) });
110
110
  });
111
111
  }
112
+ export function useComponent({ instanceId, componentId, properties, locale, dev }) {
113
+ var _a, _b;
114
+ const transpile = useTranspileComponent({ componentId, locale, properties, dev });
115
+ const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
116
+ const Component = (_a = transpile === null || transpile === void 0 ? void 0 : transpile.Component) !== null && _a !== void 0 ? _a : preload === null || preload === void 0 ? void 0 : preload.Component;
117
+ if (!Component)
118
+ return null;
119
+ const props = (_b = preload === null || preload === void 0 ? void 0 : preload.props) !== null && _b !== void 0 ? _b : transpile === null || transpile === void 0 ? void 0 : transpile.props;
120
+ return { Component, props };
121
+ }
112
122
  const COMPONENT_LOADER_MAP = {};
113
- export function usePreloadComponent({ instanceId, componentId, properties: parameters, locale: requestLocale, dev: { mode } = {}, }) {
123
+ function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
114
124
  var _a;
115
125
  const previousRef = useRef();
116
- const locale = customComponentStates((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === requestLocale)) ? requestLocale : undefined; });
126
+ const requestLocale = customComponentStates((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
117
127
  const defaultLocale = customComponentStates((s) => s.state.config.defaultLocale);
118
- const realLocale = locale || defaultLocale;
128
+ const realLocale = requestLocale || defaultLocale;
119
129
  const result = customComponentStates((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
120
130
  if (result) {
121
131
  previousRef.current = result;
@@ -124,16 +134,16 @@ export function usePreloadComponent({ instanceId, componentId, properties: param
124
134
  if (realLocale && instanceId) {
125
135
  const key = [instanceId, realLocale].join('-');
126
136
  (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = customComponentStates.getState().loadComponents({
127
- mode,
137
+ mode: dev === null || dev === void 0 ? void 0 : dev.mode,
128
138
  locale: realLocale,
129
- instances: [{ id: instanceId, component: { id: componentId }, properties: parameters }],
139
+ instances: [{ id: instanceId, component: { id: componentId }, properties }],
130
140
  }));
131
141
  if (previousRef.current)
132
142
  return previousRef.current;
133
143
  }
134
144
  return null;
135
145
  }
136
- export function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
146
+ function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
137
147
  const [Component, setComponent] = useState();
138
148
  const component = mergeComponent({
139
149
  componentId,
@@ -1,9 +1,11 @@
1
+ import * as call from '../builtin/call';
1
2
  import * as builtinIconifyReact from '../builtin/iconify/react';
2
3
  import * as builtinMuiLab from '../builtin/mui/lab';
3
4
  import * as builtinMuiMaterial from '../builtin/mui/material';
4
5
  import * as builtinReact from '../builtin/react';
5
6
  import * as builtinReactHookForm from '../builtin/react-hook-form';
6
7
  import * as reactWrapBalancer from '../builtin/react-wrap-balancer';
8
+ import * as stream from '../builtin/stream';
7
9
  import * as builtinUtils from '../builtin/utils';
8
10
  import * as builtinZustand from '../builtin/zustand';
9
11
  import * as builtinZustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
@@ -21,6 +23,8 @@ function injectGlobalComponents() {
21
23
  '@blocklet/pages-kit/builtin/zustand': builtinZustand,
22
24
  '@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
23
25
  '@blocklet/pages-kit/builtin/react-wrap-balancer': reactWrapBalancer,
26
+ '@blocklet/pages-kit/builtin/call': call,
27
+ '@blocklet/pages-kit/builtin/stream': stream,
24
28
  },
25
29
  require(module) {
26
30
  return win[BuiltinModulesGlobalVariableName].modules[module];
@@ -0,0 +1,13 @@
1
+ export interface CallInput {
2
+ name: string;
3
+ path: string;
4
+ method: string;
5
+ headers?: {
6
+ [key: string]: any;
7
+ };
8
+ query?: {
9
+ [key: string]: any;
10
+ };
11
+ body?: any;
12
+ }
13
+ export declare function call(input: CallInput): Promise<Response>;
@@ -1,15 +1 @@
1
- export { Autocomplete } from '@mui/material';
2
- export { Box } from '@mui/material';
3
- export { Button } from '@mui/material';
4
- export { ClickAwayListener } from '@mui/material';
5
- export { Dialog } from '@mui/material';
6
- export { DialogActions } from '@mui/material';
7
- export { DialogContent } from '@mui/material';
8
- export { DialogTitle } from '@mui/material';
9
- export { Paper } from '@mui/material';
10
- export { Popper } from '@mui/material';
11
- export { Stack } from '@mui/material';
12
- export { Switch } from '@mui/material';
13
- export { TextField } from '@mui/material';
14
- export { Container } from '@mui/material';
15
- export { Typography } from '@mui/material';
1
+ export { ThemeProvider, createTheme, useTheme, Avatar, Autocomplete, Box, Button, ClickAwayListener, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Popper, Stack, Switch, TextField, Container, Typography, List, ListItem, ListItemAvatar, ListItemButton, ListSubheader, ListItemIcon, ListItemSecondaryAction, } from '@mui/material';
@@ -0,0 +1,3 @@
1
+ export declare class EventSourceParserStream<T> extends TransformStream<any, T> {
2
+ constructor();
3
+ }
@@ -1 +1,2 @@
1
- export { joinURL, withQuery } from 'ufo';
1
+ export { joinURL, withQuery, getQuery } from 'ufo';
2
+ export declare function getComponentMountPoint(name: string): string | undefined;
@@ -136,15 +136,9 @@ export declare const customComponentStates: import("zustand").UseBoundStore<Omit
136
136
  loadComponents: (input: Pick<PreloadComponentsInput, 'mode' | 'locale' | 'instances'>) => Promise<void>;
137
137
  }) => void), shouldReplace?: boolean | undefined): void;
138
138
  }>;
139
- export declare function usePreloadComponent({ instanceId, componentId, properties: parameters, locale: requestLocale, dev: { mode }, }: CustomComponentRendererProps): {
139
+ export declare function useComponent({ instanceId, componentId, properties, locale, dev }: CustomComponentRendererProps): {
140
140
  Component: ComponentType<any>;
141
141
  props?: {
142
142
  [key: string]: any;
143
143
  };
144
144
  } | null;
145
- export declare function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components }, }: CustomComponentRendererProps): {
146
- Component: ComponentType;
147
- props: {
148
- [key: string]: any;
149
- };
150
- } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.227",
3
+ "version": "0.2.229",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -96,6 +96,7 @@
96
96
  "@blocklet/sdk": "^1.16.22",
97
97
  "@iconify/react": "^4.1.1",
98
98
  "axios": "^1.6.7",
99
+ "eventsource-parser": "^1.1.1",
99
100
  "immer": "^10.0.3",
100
101
  "lodash": "^4.17.21",
101
102
  "nanoid": "^3.3.7",