@blocklet/pages-kit 0.4.7 → 0.4.9

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,8 +18,10 @@ 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;
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) || '/';
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
+ '/';
23
25
  return axios_1.default.post((0, ufo_1.joinURL)(prefix, '/api/components/preload'), input).then((res) => res.data);
24
26
  });
25
27
  }
@@ -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 }))) }) }));
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 }))) }) }));
49
49
  }
50
50
  const BuiltinComponents = {
51
51
  'blocklet-react-component': BlockletReactComponentRenderer_1.default,
@@ -55,20 +55,25 @@ function ErrorView({ error }) {
55
55
  }
56
56
  function ComponentRenderer(_a) {
57
57
  var _b;
58
- var { renderCount = 0, blockletId, blockletTitle, componentName } = _a, props = __rest(_a, ["renderCount", "blockletId", "blockletTitle", "componentName"]);
58
+ var { renderCount = 0, blockletId, blockletTitle, componentName, renderType = 'view' } = _a, props = __rest(_a, ["renderCount", "blockletId", "blockletTitle", "componentName", "renderType"]);
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)();
64
65
  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 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);
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);
72
77
  }
73
78
  // if the component is not in the dev.components, it means the component is not loaded
74
79
  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,6 +193,7 @@ 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,
196
197
  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 : {})
197
198
  .map(([key, { value }]) => {
198
199
  var _a;
@@ -235,7 +236,7 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
235
236
  }
236
237
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
237
238
  var _a, _b;
238
- const [{ error, Component, propertiesFromCode }, setComponent] = (0, react_1.useState)({});
239
+ const [{ error, Component, EditComponent, propertiesFromCode }, setComponent] = (0, react_1.useState)({});
239
240
  const component = (0, property_1.mergeComponent)({
240
241
  componentId,
241
242
  getComponent: (componentId) => {
@@ -257,7 +258,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
257
258
  .then((m) => {
258
259
  // get properties from code
259
260
  const propertiesFromCode = getPropertiesFromCode(m);
260
- setComponent({ Component: m.default, propertiesFromCode });
261
+ setComponent({ Component: m.default, EditComponent: m.EditComponent || undefined, propertiesFromCode });
261
262
  })
262
263
  .catch((error) => {
263
264
  setComponent({ error });
@@ -267,6 +268,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
267
268
  return {
268
269
  error,
269
270
  Component,
271
+ EditComponent,
270
272
  props: component === null || component === void 0 ? void 0 : component.properties,
271
273
  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,
272
274
  };