@blocklet/pages-kit 0.4.10 → 0.4.11

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.
@@ -18,10 +18,8 @@ const ufo_1 = require("ufo");
18
18
  const PAGES_KIT_DID = 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o';
19
19
  function preloadComponents(input) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
- var _a, _b, _c;
22
- const prefix = ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === PAGES_KIT_DID && i.status === 'running')) === null || _b === void 0 ? void 0 : _b.mountPoint) ||
23
- ((_c = window === null || window === void 0 ? void 0 : window.blocklet) === null || _c === void 0 ? void 0 : _c.prefix) ||
24
- '/';
21
+ var _a, _b;
22
+ const prefix = ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === PAGES_KIT_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint) || '/';
25
23
  return axios_1.default.post((0, ufo_1.joinURL)(prefix, '/api/components/preload'), input).then((res) => res.data);
26
24
  });
27
25
  }
@@ -45,7 +45,7 @@ function CustomComponentRenderer(_a) {
45
45
  var { dev } = _a, props = __rest(_a, ["dev"]);
46
46
  const inheritedDev = (0, DevProvider_1.useDev)();
47
47
  const BuiltinComponent = BuiltinComponents[props.componentId];
48
- return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: (props === null || props === void 0 ? void 0 : props.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, renderType: props.renderType }))) }) }));
48
+ return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: (props === null || props === void 0 ? void 0 : props.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 }))) }) }));
49
49
  }
50
50
  const BuiltinComponents = {
51
51
  'blocklet-react-component': BlockletReactComponentRenderer_1.default,
@@ -55,25 +55,20 @@ function ErrorView({ error }) {
55
55
  }
56
56
  function ComponentRenderer(_a) {
57
57
  var _b;
58
- var { renderCount = 0, blockletId, blockletTitle, componentName, renderType = 'view' } = _a, props = __rest(_a, ["renderCount", "blockletId", "blockletTitle", "componentName", "renderType"]);
58
+ var { renderCount = 0, blockletId, blockletTitle, componentName } = _a, props = __rest(_a, ["renderCount", "blockletId", "blockletTitle", "componentName"]);
59
59
  const dev = (0, DevProvider_1.useDev)();
60
60
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
61
61
  throw new Error('Maximum render stack size exceeded');
62
62
  }
63
63
  const component = (0, state_1.useComponent)(Object.assign(Object.assign({}, props), { dev }));
64
- const ctx = (0, context_1.useCustomComponentRenderer)();
65
64
  if (component === null || component === void 0 ? void 0 : component.error) {
65
+ // throw to outer error boundary
66
66
  throw component.error;
67
67
  }
68
- const renderComponentChildren = (Component) => {
69
- const children = ((0, jsx_runtime_1.jsx)(Renderer, Object.assign({ renderCount: renderCount + 1 }, props, { Component: Component, props: Object.assign(Object.assign({}, component === null || component === void 0 ? void 0 : component.props), props.props) })));
70
- return (ctx === null || ctx === void 0 ? void 0 : ctx.customRendererComponent) ? ((0, jsx_runtime_1.jsx)(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
71
- };
72
- if ((component === null || component === void 0 ? void 0 : component.Component) && renderType === 'view') {
73
- return renderComponentChildren(component.Component);
74
- }
75
- if ((component === null || component === void 0 ? void 0 : component.EditComponent) && renderType === 'setting') {
76
- return renderComponentChildren(component.EditComponent);
68
+ const ctx = (0, context_1.useCustomComponentRenderer)();
69
+ if (component === null || component === void 0 ? void 0 : component.Component) {
70
+ const children = ((0, jsx_runtime_1.jsx)(Renderer, Object.assign({ renderCount: renderCount + 1 }, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) })));
71
+ return (ctx === null || ctx === void 0 ? void 0 : ctx.customRendererComponent) ? ((0, jsx_runtime_1.jsx)(ctx.customRendererComponent, { Component: component.Component, children: children })) : (children);
77
72
  }
78
73
  // if the component is not in the dev.components, it means the component is not loaded
79
74
  if ((dev === null || dev === void 0 ? void 0 : dev.mode) === 'draft' && dev && ((_b = dev.components) === null || _b === void 0 ? void 0 : _b[props.componentId]) === undefined) {
@@ -193,7 +193,6 @@ function useComponent({ instanceId, componentId, properties, locale, dev }) {
193
193
  const componentProperties = (_a = transpile === null || transpile === void 0 ? void 0 : transpile.componentProperties) !== null && _a !== void 0 ? _a : preload === null || preload === void 0 ? void 0 : preload.componentProperties;
194
194
  return {
195
195
  Component: (_b = transpile === null || transpile === void 0 ? void 0 : transpile.Component) !== null && _b !== void 0 ? _b : preload === null || preload === void 0 ? void 0 : preload.Component,
196
- EditComponent: transpile === null || transpile === void 0 ? void 0 : transpile.EditComponent,
197
196
  props: Object.assign(Object.assign({}, ((_c = transpile === null || transpile === void 0 ? void 0 : transpile.props) !== null && _c !== void 0 ? _c : preload === null || preload === void 0 ? void 0 : preload.props)), Object.fromEntries(Object.entries(properties !== null && properties !== void 0 ? properties : {})
198
197
  .map(([key, { value }]) => {
199
198
  var _a;
@@ -236,7 +235,7 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
236
235
  }
237
236
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
238
237
  var _a, _b;
239
- const [{ error, Component, EditComponent, propertiesFromCode }, setComponent] = (0, react_1.useState)({});
238
+ const [{ error, Component, propertiesFromCode }, setComponent] = (0, react_1.useState)({});
240
239
  const component = (0, property_1.mergeComponent)({
241
240
  componentId,
242
241
  getComponent: (componentId) => {
@@ -258,7 +257,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
258
257
  .then((m) => {
259
258
  // get properties from code
260
259
  const propertiesFromCode = getPropertiesFromCode(m);
261
- setComponent({ Component: m.default, EditComponent: m.EditComponent || undefined, propertiesFromCode });
260
+ setComponent({ Component: m.default, propertiesFromCode });
262
261
  })
263
262
  .catch((error) => {
264
263
  setComponent({ error });
@@ -268,7 +267,6 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
268
267
  return {
269
268
  error,
270
269
  Component,
271
- EditComponent,
272
270
  props: component === null || component === void 0 ? void 0 : component.properties,
273
271
  componentProperties: (_b = (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.properties,
274
272
  };