@blocklet/pages-kit 0.4.32 → 0.4.33

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 (50) hide show
  1. package/lib/cjs/api/call.js +7 -18
  2. package/lib/cjs/api/pages-kit.js +5 -17
  3. package/lib/cjs/builtin/async/react-scroll-to-bottom.js +5 -1
  4. package/lib/cjs/builtin/components/LanguageField/index.js +6 -18
  5. package/lib/cjs/builtin/iconify/react.js +1 -1
  6. package/lib/cjs/builtin/page/header.js +8 -5
  7. package/lib/cjs/builtin/session.js +6 -0
  8. package/lib/cjs/builtin/stream.js +1 -1
  9. package/lib/cjs/builtin/utils.js +3 -5
  10. package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
  11. package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +2 -14
  12. package/lib/cjs/components/CustomComponentRenderer/ErrorComponent.js +2 -14
  13. package/lib/cjs/components/CustomComponentRenderer/index.js +12 -27
  14. package/lib/cjs/components/CustomComponentRenderer/state.js +121 -151
  15. package/lib/cjs/components/ResponsiveImage/index.js +3 -16
  16. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  17. package/lib/cjs/utils/inject-es-module-shims-options.js +1 -2
  18. package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
  19. package/lib/cjs/utils/inject-global-components.js +29 -20
  20. package/lib/cjs/utils/preload.js +1 -15
  21. package/lib/cjs/utils/property.js +31 -25
  22. package/lib/cjs/utils/typescript/builtin-module-transformer.js +12 -9
  23. package/lib/esm/api/call.js +7 -18
  24. package/lib/esm/api/pages-kit.js +5 -17
  25. package/lib/esm/builtin/async/react-scroll-to-bottom.js +5 -1
  26. package/lib/esm/builtin/components/LanguageField/index.js +6 -18
  27. package/lib/esm/builtin/iconify/react.js +1 -1
  28. package/lib/esm/builtin/page/header.js +8 -5
  29. package/lib/esm/builtin/session.js +5 -0
  30. package/lib/esm/builtin/stream.js +1 -1
  31. package/lib/esm/builtin/utils.js +3 -5
  32. package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
  33. package/lib/esm/components/CustomComponentRenderer/DevProvider.js +2 -14
  34. package/lib/esm/components/CustomComponentRenderer/ErrorComponent.js +2 -14
  35. package/lib/esm/components/CustomComponentRenderer/index.js +12 -27
  36. package/lib/esm/components/CustomComponentRenderer/state.js +121 -151
  37. package/lib/esm/components/ResponsiveImage/index.js +3 -16
  38. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  39. package/lib/esm/utils/inject-es-module-shims-options.js +1 -2
  40. package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
  41. package/lib/esm/utils/inject-global-components.js +29 -20
  42. package/lib/esm/utils/preload.js +1 -15
  43. package/lib/esm/utils/property.js +30 -25
  44. package/lib/esm/utils/typescript/builtin-module-transformer.js +10 -8
  45. package/lib/types/builtin/session.d.ts +13 -0
  46. package/lib/types/tsconfig.tsbuildinfo +1 -1
  47. package/lib/types/types/core.d.ts +11 -2
  48. package/lib/types/utils/property.d.ts +1 -0
  49. package/lib/types/utils/typescript/builtin-module-transformer.d.ts +1 -0
  50. package/package.json +1 -1
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.injectESModulesShimsOptions = injectESModulesShimsOptions;
4
4
  function injectESModulesShimsOptions(options = {}) {
5
- var _a;
6
5
  // if already initialized, return
7
6
  if (window.esmsInitOptions && !options.force) {
8
7
  return;
@@ -10,7 +9,7 @@ function injectESModulesShimsOptions(options = {}) {
10
9
  window.esmsInitOptions = {
11
10
  // Notice: 不要修改 shimMode 的默认值,否则可能会影响到其他 blocklet 的正常使用
12
11
  // default is false, do not enable es-module-shims
13
- shimMode: (_a = options.shimMode) !== null && _a !== void 0 ? _a : false,
12
+ shimMode: options.shimMode ?? false,
14
13
  polyfillEnable: ['css-modules', 'json-modules', 'wasm-modules', 'source-phase'],
15
14
  };
16
15
  }
@@ -1130,7 +1130,7 @@ if (cookie && shouldUpdateKnowledge && aiStudioUrl && datasetId) {
1130
1130
  })
1131
1131
  .then((res) => res.json())
1132
1132
  .then(({ items }) => {
1133
- console.info('items count: ', items === null || items === void 0 ? void 0 : items.length);
1133
+ console.info('items count: ', items?.length);
1134
1134
  const successText = (data) => {
1135
1135
  console.info(`${data.name} success`);
1136
1136
  };
@@ -31,7 +31,6 @@ require("es-module-shims");
31
31
  const react_1 = __importDefault(require("react"));
32
32
  const ufo_1 = require("ufo");
33
33
  const arcblockUx = __importStar(require("../builtin/arcblock/ux"));
34
- const aiRuntime = __importStar(require("../builtin/async/ai-runtime"));
35
34
  const imagePreview = __importStar(require("../builtin/async/image-preview"));
36
35
  const reactMarkdown = __importStar(require("../builtin/async/react-markdown"));
37
36
  const reactScrollToBottom = __importStar(require("../builtin/async/react-scroll-to-bottom"));
@@ -59,14 +58,13 @@ const builtin_1 = require("../types/builtin");
59
58
  const builtin_module_transformer_1 = require("./typescript/builtin-module-transformer");
60
59
  // Initialize ES Module Shims before any imports
61
60
  function injectGlobalComponents() {
62
- var _a;
63
61
  const win = window || {};
64
62
  // if already initialized, return
65
63
  if (win[builtin_1.BuiltinModulesGlobalVariableName]) {
66
64
  return;
67
65
  }
68
- const enableShim = !!((_a = window === null || window === void 0 ? void 0 : window.esmsInitOptions) === null || _a === void 0 ? void 0 : _a.shimMode);
69
- if (!enableShim) {
66
+ const enableShim = !!window?.esmsInitOptions?.shimMode && win.importShim;
67
+ if (!enableShim && win.importShim?.addImportMap) {
70
68
  win.importShim.addImportMap = () => {
71
69
  // avoid addImportMap error
72
70
  };
@@ -99,13 +97,12 @@ function injectGlobalComponents() {
99
97
  '@blocklet/pages-kit/builtin/async/react-markdown': reactMarkdown,
100
98
  '@blocklet/pages-kit/builtin/async/react-syntax-highlighter': reactSyntaxHighlighter,
101
99
  '@blocklet/pages-kit/builtin/async/image-preview': imagePreview,
102
- '@blocklet/pages-kit/builtin/async/ai-runtime': aiRuntime,
100
+ '@blocklet/pages-kit/builtin/async/ai-runtime': Promise.resolve().then(() => __importStar(require('../builtin/async/ai-runtime'))),
103
101
  };
104
102
  // set global variable
105
103
  win[builtin_1.BuiltinModulesGlobalVariableName] = {
106
104
  modules,
107
105
  require(module) {
108
- var _a;
109
106
  // handle builtin module
110
107
  const builtinModule = this.modules[module];
111
108
  if (builtinModule) {
@@ -114,7 +111,7 @@ function injectGlobalComponents() {
114
111
  // handle relative path import
115
112
  if ((0, builtin_module_transformer_1.isRelativeModule)(module)) {
116
113
  const fileName = module.split('/').pop();
117
- const fullUrl = (0, ufo_1.joinURL)(window.location.origin, ((_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.prefix) || '/', 'chunks', fileName);
114
+ const fullUrl = (0, ufo_1.joinURL)(window.location.origin, window?.blocklet?.prefix || '/', 'chunks', fileName);
118
115
  if (enableShim) {
119
116
  const mod = window.importShim(/* @vite-ignore */ fullUrl);
120
117
  return mod;
@@ -126,11 +123,23 @@ function injectGlobalComponents() {
126
123
  },
127
124
  };
128
125
  // create importmap
129
- const setupImportMap = () => {
126
+ const setupImportMap = async () => {
127
+ const modulesResolved = {};
128
+ // 确保 modules 的 value 中的所有 promise 都加载为 es module
129
+ await Promise.all(Object.entries(modules).map(async ([modulePath, moduleContent]) => {
130
+ if (moduleContent instanceof Promise) {
131
+ const mod = await moduleContent;
132
+ modulesResolved[modulePath] = mod;
133
+ // replace the original moduleContent with the resolved module
134
+ win[builtin_1.BuiltinModulesGlobalVariableName].modules[modulePath] = mod;
135
+ return;
136
+ }
137
+ modulesResolved[modulePath] = moduleContent;
138
+ }));
130
139
  // 计算模块的 hash 值作为缓存版本
131
140
  const calculateModulesHash = () => {
132
141
  // 只提取模块路径和导出的键名用于 hash 计算
133
- const moduleStructure = Object.entries(modules).map(([path, mod]) => ({
142
+ const moduleStructure = Object.entries(modulesResolved).map(([path, mod]) => ({
134
143
  path,
135
144
  exports: Object.keys(mod).sort(),
136
145
  }));
@@ -167,21 +176,21 @@ function injectGlobalComponents() {
167
176
  return null; // 缓存无效
168
177
  };
169
178
  // 尝试从缓存获取或重新计算
170
- const imports = getImportsFromCache() ||
171
- Object.entries(modules).reduce((acc, [modulePath, moduleContent]) => {
172
- const namedExports = Object.keys(moduleContent).filter((key) => key !== 'default');
173
- const hasDefaultExport = 'default' in moduleContent;
174
- // create module code
175
- const moduleCode = `// GENERATED FILE. DO NOT EDIT.
179
+ const imports = Object.entries(modulesResolved).reduce((acc, [modulePath, moduleContent]) => {
180
+ const moduleContentResolved = moduleContent;
181
+ const namedExports = Object.keys(moduleContentResolved).filter((key) => key !== 'default');
182
+ const hasDefaultExport = 'default' in moduleContentResolved;
183
+ // create module code
184
+ const moduleCode = `// GENERATED FILE. DO NOT EDIT.
176
185
  const moduleSource = window['${builtin_1.BuiltinModulesGlobalVariableName}'].modules['${modulePath}'];
177
186
  ${namedExports.map((name) => `export const ${name} = moduleSource['${name}'];`).join('\n')}
178
187
  export default ${hasDefaultExport ? 'moduleSource.default' : 'moduleSource'};
179
188
  `;
180
- // create base64 code
181
- const base64Code = btoa(moduleCode);
182
- acc[modulePath] = `data:application/javascript;base64,${base64Code}`;
183
- return acc;
184
- }, {});
189
+ // create base64 code
190
+ const base64Code = btoa(moduleCode);
191
+ acc[modulePath] = `data:application/javascript;base64,${base64Code}`;
192
+ return acc;
193
+ }, {});
185
194
  // 如果是新计算的 imports,保存到缓存
186
195
  if (!getImportsFromCache()) {
187
196
  try {
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.injectPreloadComponents = injectPreloadComponents;
15
4
  const types_1 = require("../types");
@@ -23,10 +12,7 @@ function injectPreloadComponents(data) {
23
12
  throw new Error(`Only support inject script with module ${types_1.PreloadComponentScriptModule.UMD_FN}`);
24
13
  return [componentId, { componentModuleGlobalVariable: script.moduleName, component }];
25
14
  })),
26
- instances: Object.fromEntries(data.instances.map((_a) => {
27
- var { id } = _a, instance = __rest(_a, ["id"]);
28
- return [id, instance];
29
- })),
15
+ instances: Object.fromEntries(data.instances.map(({ id, ...instance }) => [id, instance])),
30
16
  };
31
17
  return {
32
18
  html: `\
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RenderNestedComponent = void 0;
7
7
  exports.componentUMDName = componentUMDName;
8
8
  exports.mergeComponent = mergeComponent;
9
+ exports.safeJSONParse = safeJSONParse;
9
10
  exports.parsePropertyValue = parsePropertyValue;
10
11
  exports.assignNullableFields = assignNullableFields;
11
12
  const js_yaml_1 = __importDefault(require("js-yaml"));
@@ -13,46 +14,43 @@ function componentUMDName({ componentId }) {
13
14
  return `PagesCustomComponent${componentId}`;
14
15
  }
15
16
  function mergeComponent({ componentId, getComponent, locale, defaultLocale, properties: parameters, }) {
16
- var _a, _b, _c, _d, _e, _f, _g;
17
17
  let component = getComponent(componentId);
18
18
  if (!component)
19
19
  return null;
20
20
  let script;
21
- const properties = Object.fromEntries(Object.entries(parameters !== null && parameters !== void 0 ? parameters : {}).map(([id, { value }]) => {
22
- var _a, _b;
23
- const property = (_b = (_a = component === null || component === void 0 ? void 0 : component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
21
+ const properties = Object.fromEntries(Object.entries(parameters ?? {}).map(([id, { value }]) => {
22
+ const property = component?.properties?.[id]?.data;
24
23
  if (!property)
25
24
  return [];
26
25
  // // if key is undefined, use id
27
26
  return [property.key || property.id, parsePropertyValue(property, value, { locale, defaultLocale })];
28
27
  }));
29
28
  while (component) {
30
- assignNullableFields(properties, Object.fromEntries(Object.values((_a = component.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => {
31
- var _a, _b, _c, _d, _e;
32
- return [
33
- // if key is undefined, use id
34
- data.key || data.id,
35
- parsePropertyValue(data, (_c = (_b = (_a = data.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.defaultValue) !== null && _c !== void 0 ? _c : (_e = (_d = data.locales) === null || _d === void 0 ? void 0 : _d[defaultLocale]) === null || _e === void 0 ? void 0 : _e.defaultValue, { locale, defaultLocale }),
36
- ];
37
- })));
38
- if (((_b = component.renderer) === null || _b === void 0 ? void 0 : _b.type) === 'react-component') {
39
- script = (_c = component.renderer) === null || _c === void 0 ? void 0 : _c.script;
29
+ assignNullableFields(properties, Object.fromEntries(Object.values(component.properties ?? {}).map(({ data }) => [
30
+ // if key is undefined, use id
31
+ data.key || data.id,
32
+ parsePropertyValue(data, data.locales?.[locale]?.defaultValue ?? data.locales?.[defaultLocale]?.defaultValue, { locale, defaultLocale }),
33
+ ])));
34
+ if (component.renderer?.type === 'react-component') {
35
+ script = component.renderer?.script;
40
36
  break;
41
37
  }
42
- if (((_d = component.renderer) === null || _d === void 0 ? void 0 : _d.type) === 'web-component') {
43
- script = (_e = component.renderer) === null || _e === void 0 ? void 0 : _e.script;
38
+ if (component.renderer?.type === 'web-component') {
39
+ script = component.renderer?.script;
44
40
  break;
45
41
  }
46
- if (((_f = component.renderer) === null || _f === void 0 ? void 0 : _f.type) === 'component' && component.renderer.componentId) {
42
+ if (component.renderer?.type === 'component' && component.renderer.componentId) {
47
43
  const { componentId } = component.renderer;
48
44
  const next = getComponent(componentId);
49
45
  const nextParameters = component.renderer.properties;
50
- assignNullableFields(properties, Object.fromEntries(Object.entries((_g = next === null || next === void 0 ? void 0 : next.properties) !== null && _g !== void 0 ? _g : {}).map(([id, { data }]) => {
51
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
52
- const locales = (_a = nextParameters === null || nextParameters === void 0 ? void 0 : nextParameters[id]) === null || _a === void 0 ? void 0 : _a.locales;
46
+ assignNullableFields(properties, Object.fromEntries(Object.entries(next?.properties ?? {}).map(([id, { data }]) => {
47
+ const locales = nextParameters?.[id]?.locales;
53
48
  return [
54
49
  data.key,
55
- parsePropertyValue(data, (_h = (_e = (_c = (_b = locales === null || locales === void 0 ? void 0 : locales[locale]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : (_d = locales === null || locales === void 0 ? void 0 : locales[defaultLocale]) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : (_g = (_f = data.locales) === null || _f === void 0 ? void 0 : _f[locale]) === null || _g === void 0 ? void 0 : _g.defaultValue) !== null && _h !== void 0 ? _h : (_k = (_j = data.locales) === null || _j === void 0 ? void 0 : _j[defaultLocale]) === null || _k === void 0 ? void 0 : _k.defaultValue, { locale, defaultLocale }),
50
+ parsePropertyValue(data, locales?.[locale]?.value ??
51
+ locales?.[defaultLocale]?.value ??
52
+ data.locales?.[locale]?.defaultValue ??
53
+ data.locales?.[defaultLocale]?.defaultValue, { locale, defaultLocale }),
56
54
  ];
57
55
  })));
58
56
  component = next;
@@ -66,13 +64,18 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
66
64
  return { script, properties };
67
65
  }
68
66
  exports.RenderNestedComponent = '__RENDER_NESTED_COMPONENT__';
67
+ function safeJSONParse(value) {
68
+ if (typeof value === 'object' && value !== null) {
69
+ return value;
70
+ }
71
+ return JSON.parse(value);
72
+ }
69
73
  function parsePropertyValue(property, value, { locale, defaultLocale }) {
70
- var _a, _b, _c, _d, _e;
71
74
  if (property.type === 'json') {
72
75
  if (!value)
73
76
  return undefined;
74
77
  try {
75
- return JSON.parse(value);
78
+ return safeJSONParse(value);
76
79
  }
77
80
  catch (error) {
78
81
  console.error('parse json value error', error);
@@ -91,14 +94,17 @@ function parsePropertyValue(property, value, { locale, defaultLocale }) {
91
94
  }
92
95
  }
93
96
  if (property.type === 'component') {
94
- const componentId = value === null || value === void 0 ? void 0 : value.componentId;
97
+ const componentId = value?.componentId;
95
98
  if (typeof componentId !== 'string')
96
99
  return undefined;
97
100
  const { locales } = property;
98
101
  return {
99
102
  type: exports.RenderNestedComponent,
100
103
  componentId,
101
- properties: Object.assign(Object.assign({}, ((_c = (_b = (_a = locales === null || locales === void 0 ? void 0 : locales[locale]) === null || _a === void 0 ? void 0 : _a.defaultValue) === null || _b === void 0 ? void 0 : _b.properties) !== null && _c !== void 0 ? _c : (_e = (_d = locales === null || locales === void 0 ? void 0 : locales[defaultLocale]) === null || _d === void 0 ? void 0 : _d.defaultValue) === null || _e === void 0 ? void 0 : _e.properties)), value === null || value === void 0 ? void 0 : value.properties),
104
+ properties: {
105
+ ...(locales?.[locale]?.defaultValue?.properties ?? locales?.[defaultLocale]?.defaultValue?.properties),
106
+ ...value?.properties,
107
+ },
102
108
  };
103
109
  }
104
110
  return value;
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createBuiltinModuleTransformer = exports.isRelativeModule = void 0;
3
+ exports.createBuiltinModuleTransformer = exports.isAwaitModule = exports.isRelativeModule = void 0;
4
4
  const builtin_1 = require("../../types/builtin");
5
5
  const isRelativeModule = (moduleSpecifier) => {
6
6
  return moduleSpecifier.startsWith('./') || moduleSpecifier.startsWith('../');
7
7
  };
8
8
  exports.isRelativeModule = isRelativeModule;
9
+ const isAwaitModule = (moduleSpecifier) => {
10
+ return ['@blocklet/pages-kit/builtin/async/ai-runtime'].includes(moduleSpecifier);
11
+ };
12
+ exports.isAwaitModule = isAwaitModule;
9
13
  const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
10
14
  const { factory } = context;
11
15
  // 统一的模块导入收集器
@@ -16,27 +20,25 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
16
20
  };
17
21
  // filter and collect the import statements that need to be processed
18
22
  const statements = file.statements.filter((s) => {
19
- var _a, _b, _c;
20
23
  if (ts.isImportDeclaration(s) &&
21
24
  ts.isStringLiteral(s.moduleSpecifier) &&
22
25
  isTargetModule(s.moduleSpecifier.text)) {
23
26
  const importInfo = {
24
27
  moduleName: s.moduleSpecifier.text,
25
- name: (_b = (_a = s.importClause) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.text,
28
+ name: s.importClause?.name?.text,
26
29
  members: [],
27
30
  namespace: '',
28
31
  };
29
- const namedBindings = (_c = s.importClause) === null || _c === void 0 ? void 0 : _c.namedBindings;
32
+ const namedBindings = s.importClause?.namedBindings;
30
33
  if (namedBindings) {
31
34
  if (ts.isNamespaceImport(namedBindings)) {
32
35
  importInfo.namespace = namedBindings.name.text;
33
36
  }
34
37
  namedBindings.forEachChild((node) => {
35
- var _a;
36
38
  if (ts.isImportSpecifier(node)) {
37
39
  importInfo.members.push({
38
40
  name: node.name.text,
39
- propertyName: (_a = node.propertyName) === null || _a === void 0 ? void 0 : _a.text,
41
+ propertyName: node.propertyName?.text,
40
42
  });
41
43
  }
42
44
  });
@@ -50,7 +52,9 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
50
52
  // call inject-global-components require method
51
53
  const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(importInfo.moduleName)]);
52
54
  // create await expression if the module is ../ or ./
53
- const mod = (0, exports.isRelativeModule)(importInfo.moduleName) ? factory.createAwaitExpression(requireCall) : requireCall;
55
+ const mod = (0, exports.isRelativeModule)(importInfo.moduleName) || (0, exports.isAwaitModule)(importInfo.moduleName)
56
+ ? factory.createAwaitExpression(requireCall)
57
+ : requireCall;
54
58
  return [
55
59
  importInfo.name
56
60
  ? factory.createVariableStatement([], factory.createVariableDeclarationList([
@@ -65,9 +69,8 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
65
69
  : undefined,
66
70
  // handle named import
67
71
  ...importInfo.members.map((member) => {
68
- var _a;
69
72
  return factory.createVariableStatement([], factory.createVariableDeclarationList([
70
- factory.createVariableDeclaration(factory.createIdentifier(member.name), undefined, undefined, factory.createPropertyAccessExpression(mod, (_a = member.propertyName) !== null && _a !== void 0 ? _a : member.name)),
73
+ factory.createVariableDeclaration(factory.createIdentifier(member.name), undefined, undefined, factory.createPropertyAccessExpression(mod, member.propertyName ?? member.name)),
71
74
  ], ts.NodeFlags.Const));
72
75
  }),
73
76
  ].filter((i) => !!i);
@@ -1,20 +1,9 @@
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
1
  import { call } from '@blocklet/sdk/lib/component';
11
- export function preloadComponents(input) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- return call({
14
- name: 'pages-kit',
15
- method: 'POST',
16
- path: '/api/components/preload',
17
- data: input,
18
- }).then((res) => res.data);
19
- });
2
+ export async function preloadComponents(input) {
3
+ return call({
4
+ name: 'pages-kit',
5
+ method: 'POST',
6
+ path: '/api/components/preload',
7
+ data: input,
8
+ }).then((res) => res.data);
20
9
  }
@@ -1,21 +1,9 @@
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
1
  import axios from 'axios';
11
2
  import { joinURL } from 'ufo';
12
3
  const PAGES_KIT_DID = 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o';
13
- export function preloadComponents(input) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- var _a, _b, _c;
16
- 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) ||
17
- ((_c = window === null || window === void 0 ? void 0 : window.blocklet) === null || _c === void 0 ? void 0 : _c.prefix) ||
18
- '/';
19
- return axios.post(joinURL(prefix, '/api/components/preload'), input).then((res) => res.data);
20
- });
4
+ export async function preloadComponents(input) {
5
+ const prefix = window.blocklet?.componentMountPoints.find((i) => i.did === PAGES_KIT_DID && i.status === 'running')?.mountPoint ||
6
+ window?.blocklet?.prefix ||
7
+ '/';
8
+ return axios.post(joinURL(prefix, '/api/components/preload'), input).then((res) => res.data);
21
9
  }
@@ -5,4 +5,8 @@ export default () => Promise.all([
5
5
  import('react-scroll-to-bottom/lib/esm/hooks/internal/useInternalContext')
6
6
  : // @ts-ignore
7
7
  import('react-scroll-to-bottom/lib/hooks/internal/useInternalContext'),
8
- ]).then(([mod, { default: useInternalContext }]) => (Object.assign(Object.assign({}, mod), { Composer: mod.Composer, useInternalContext })));
8
+ ]).then(([mod, { default: useInternalContext }]) => ({
9
+ ...mod,
10
+ Composer: mod.Composer,
11
+ useInternalContext,
12
+ }));
@@ -1,14 +1,3 @@
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
1
  import { createElement as _createElement } from "react";
13
2
  import { jsx as _jsx } from "react/jsx-runtime";
14
3
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
@@ -25,18 +14,17 @@ const filter = (options, state) => {
25
14
  return true;
26
15
  });
27
16
  };
28
- const LanguageField = forwardRef((_a, ref) => {
29
- var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
17
+ const LanguageField = forwardRef(({ readOnly, parameter, onChange, ...props }, ref) => {
30
18
  const { locale } = useLocaleContext();
31
- const value = (props === null || props === void 0 ? void 0 : props.value) ? languages.find((o) => o.en === props.value) : null;
32
- return (_jsx(Autocomplete, Object.assign({ size: "small", ref: ref }, pick(props, 'autoFocus', 'fullWidth', 'sx', 'className', 'style'), { renderInput: (params) => (_jsx(TextField, Object.assign({}, pick(props, 'inputRef', 'size', 'hiddenLabel', 'helperText', 'error', 'placeholder', 'InputProps', 'inputProps'), params))), options: languages, getOptionKey: (i) => i.en, getOptionLabel: (o) => {
19
+ const value = props?.value ? languages.find((o) => o.en === props.value) : null;
20
+ return (_jsx(Autocomplete, { size: "small", ref: ref, ...pick(props, 'autoFocus', 'fullWidth', 'sx', 'className', 'style'), renderInput: (params) => (_jsx(TextField, { ...pick(props, 'inputRef', 'size', 'hiddenLabel', 'helperText', 'error', 'placeholder', 'InputProps', 'inputProps'), ...params })), options: languages, getOptionKey: (i) => i.en, getOptionLabel: (o) => {
33
21
  return locale === 'zh' ? o.cn : o.en;
34
22
  }, autoHighlight: true, value: value, filterOptions: filter, onChange: (_e, newValue) => {
35
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue === null || newValue === void 0 ? void 0 : newValue.en);
23
+ onChange?.(newValue?.en);
36
24
  }, renderOption: (props, option) => {
37
- return (_createElement(MenuItem, Object.assign({}, props, { key: option.name }),
25
+ return (_createElement(MenuItem, { ...props, key: option.name },
38
26
  _jsx(ListItemIcon, { children: _jsx(option.flag, {}) }),
39
27
  _jsx(ListItemText, { primary: `${option.name} ${locale === 'zh' ? option.cn : option.en} (${option.abbr})` })));
40
- } })));
28
+ } }));
41
29
  });
42
30
  export default LanguageField;
@@ -2,6 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Icon as IconifyIcon } from '@iconify/react';
3
3
  import { Box } from '@mui/material';
4
4
  export function Icon(props) {
5
- return _jsx(Box, Object.assign({ component: IconifyIcon }, props));
5
+ return _jsx(Box, { component: IconifyIcon, ...props });
6
6
  }
7
7
  export default Icon;
@@ -22,12 +22,15 @@ export const useHeaderState = create()(immer((set, get) => ({
22
22
  for (const i of get().stack) {
23
23
  widgets.push(i());
24
24
  }
25
- const r = widgets.reduce((res, i) => (Object.assign(Object.assign(Object.assign({}, res), i), { addons: (exists) => {
26
- var _a, _b, _c, _d;
27
- const a = (_b = (_a = res.addons) === null || _a === void 0 ? void 0 : _a.call(res, exists)) !== null && _b !== void 0 ? _b : exists;
28
- const b = (_d = (_c = i.addons) === null || _c === void 0 ? void 0 : _c.call(i, a)) !== null && _d !== void 0 ? _d : a;
25
+ const r = widgets.reduce((res, i) => ({
26
+ ...res,
27
+ ...i,
28
+ addons: (exists) => {
29
+ const a = res.addons?.(exists) ?? exists;
30
+ const b = i.addons?.(a) ?? a;
29
31
  return b;
30
- } })), {});
32
+ },
33
+ }), {});
31
34
  set((state) => {
32
35
  state.logo = r.logo;
33
36
  state.description = r.description;
@@ -1 +1,6 @@
1
+ import { SessionContext } from '@arcblock/did-connect/lib/Session';
2
+ import { useContext } from 'react';
1
3
  export * from '@arcblock/did-connect/lib/Session';
4
+ export function useSessionContext() {
5
+ return useContext(SessionContext);
6
+ }
@@ -21,7 +21,7 @@ export class EventSourceParserStream extends TransformStream {
21
21
  });
22
22
  },
23
23
  transform(chunk) {
24
- parser === null || parser === void 0 ? void 0 : parser.feed(chunk);
24
+ parser?.feed(chunk);
25
25
  },
26
26
  });
27
27
  }
@@ -1,18 +1,16 @@
1
1
  import { joinURL } from 'ufo';
2
2
  export { joinURL, withQuery, getQuery } from 'ufo';
3
3
  export function getComponentMountPoint(name) {
4
- var _a, _b;
5
4
  if (typeof window === 'undefined') {
6
5
  // eslint-disable-next-line global-require
7
6
  return require('@blocklet/sdk/lib/component').getComponentMountPoint(name);
8
7
  }
9
- 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;
8
+ return globalThis.blocklet?.componentMountPoints.find((i) => i.name === name || i.did === name)?.mountPoint;
10
9
  }
11
10
  export function getMediaKitAbsoluteUrl(url) {
12
- var _a, _b;
13
- const PREFIX = ((_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.prefix) || '/';
11
+ const PREFIX = window.blocklet?.prefix || '/';
14
12
  const IMAGE_BIN_DID = 'z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9';
15
- const IMAGE_BIN_PREFIX = ((_b = blocklet === null || blocklet === void 0 ? void 0 : blocklet.componentMountPoints.find((i) => i.did === IMAGE_BIN_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint) || joinURL(PREFIX, '/image-bin');
13
+ const IMAGE_BIN_PREFIX = blocklet?.componentMountPoints.find((i) => i.did === IMAGE_BIN_DID)?.mountPoint || joinURL(PREFIX, '/image-bin');
16
14
  if (url && url.startsWith('mediakit://')) {
17
15
  return window.location.origin + joinURL(IMAGE_BIN_PREFIX, 'uploads', url.replace('mediakit://', ''));
18
16
  }
@@ -1,23 +1,10 @@
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
1
  import { jsx as _jsx } from "react/jsx-runtime";
13
2
  import React, { useMemo } from 'react';
14
3
  import { getComponentMountPoint, joinURL } from '../../builtin/utils';
15
- export default function BlockletReactComponentRenderer(_a) {
16
- var props = __rest(_a, []);
4
+ export default function BlockletReactComponentRenderer({ ...props }) {
17
5
  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;
6
+ const did = props.properties?.blockletDid?.value;
7
+ const path = props.properties?.componentPath?.value;
21
8
  if (!did || !path)
22
9
  return null;
23
10
  return joinURL(window.location.origin, getComponentMountPoint(did), path);
@@ -26,11 +13,10 @@ export default function BlockletReactComponentRenderer(_a) {
26
13
  throw new Error('Missing required properties `blockletDid` or `componentPath`');
27
14
  }
28
15
  const C = loadComponent(url);
29
- return _jsx(C, Object.assign({}, props.props));
16
+ return _jsx(C, { ...props.props });
30
17
  }
31
18
  const COMPONENTS_CACHE = {};
32
19
  function loadComponent(url) {
33
- var _a;
34
- (_a = COMPONENTS_CACHE[url]) !== null && _a !== void 0 ? _a : (COMPONENTS_CACHE[url] = React.lazy(() => import(/* @vite-ignore */ url)));
20
+ COMPONENTS_CACHE[url] ??= React.lazy(() => import(/* @vite-ignore */ url));
35
21
  return COMPONENTS_CACHE[url];
36
22
  }
@@ -1,20 +1,8 @@
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
1
  import { jsx as _jsx } from "react/jsx-runtime";
13
2
  import { createContext, useContext } from 'react';
14
3
  const devContext = createContext(undefined);
15
- export function DevProvider(_a) {
16
- var { dev } = _a, props = __rest(_a, ["dev"]);
17
- return _jsx(devContext.Provider, Object.assign({ value: dev }, props));
4
+ export function DevProvider({ dev, ...props }) {
5
+ return _jsx(devContext.Provider, { value: dev, ...props });
18
6
  }
19
7
  export function useDev() {
20
8
  return useContext(devContext);
@@ -1,18 +1,6 @@
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
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
2
  import { Box, Typography, Button } from '@mui/material';
14
- export const ComponentError = (_a) => {
15
- var { title = 'Component Failed to Load', message, componentId, componentName, blockletId, blockletTitle, showHints = false, error, resetErrorBoundary } = _a, rest = __rest(_a, ["title", "message", "componentId", "componentName", "blockletId", "blockletTitle", "showHints", "error", "resetErrorBoundary"]);
3
+ export const ComponentError = ({ title = 'Component Failed to Load', message, componentId, componentName, blockletId, blockletTitle, showHints = false, error, resetErrorBoundary, ...rest }) => {
16
4
  // 如果提供了error但没有message,使用error.message
17
5
  const displayMessage = message || (error ? error.message : 'Unknown error');
18
6
  console.warn(rest);
@@ -32,5 +20,5 @@ export const ComponentError = (_a) => {
32
20
  fontSize: '0.75rem',
33
21
  overflow: 'auto',
34
22
  maxHeight: '200px',
35
- }, children: error.stack })), showHints && (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "body2", sx: { color: 'text.secondary' }, children: "Please try the following:" }), _jsxs(Box, { component: "ul", sx: { m: 0, pl: 2 }, children: [componentId && (_jsxs(Typography, { component: "li", variant: "body2", sx: { color: 'text.secondary' }, children: ["Select component", ' ', _jsx(Box, { component: "span", sx: { fontWeight: 500 }, children: componentName !== null && componentName !== void 0 ? componentName : componentId }), ' ', "in settings or create this component."] })), (blockletId || blockletTitle) && (_jsxs(Typography, { component: "li", variant: "body2", sx: { color: 'text.secondary' }, children: ["Contact administrator to install", ' ', _jsx(Box, { component: "span", sx: { fontWeight: 500 }, children: blockletTitle !== null && blockletTitle !== void 0 ? blockletTitle : blockletId }), ' ', "Blocklet"] }))] })] })), resetErrorBoundary && (_jsx(Box, { sx: { mt: 2 }, children: _jsx(Button, { variant: "outlined", color: "error", size: "small", onClick: resetErrorBoundary, children: "Try Again" }) }))] }));
23
+ }, children: error.stack })), showHints && (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "body2", sx: { color: 'text.secondary' }, children: "Please try the following:" }), _jsxs(Box, { component: "ul", sx: { m: 0, pl: 2 }, children: [componentId && (_jsxs(Typography, { component: "li", variant: "body2", sx: { color: 'text.secondary' }, children: ["Select component", ' ', _jsx(Box, { component: "span", sx: { fontWeight: 500 }, children: componentName ?? componentId }), ' ', "in settings or create this component."] })), (blockletId || blockletTitle) && (_jsxs(Typography, { component: "li", variant: "body2", sx: { color: 'text.secondary' }, children: ["Contact administrator to install", ' ', _jsx(Box, { component: "span", sx: { fontWeight: 500 }, children: blockletTitle ?? blockletId }), ' ', "Blocklet"] }))] })] })), resetErrorBoundary && (_jsx(Box, { sx: { mt: 2 }, children: _jsx(Button, { variant: "outlined", color: "error", size: "small", onClick: resetErrorBoundary, children: "Try Again" }) }))] }));
36
24
  };