@blocklet/pages-kit 0.4.32 → 0.4.34
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.
- package/lib/cjs/api/call.js +7 -18
- package/lib/cjs/api/pages-kit.js +5 -17
- package/lib/cjs/builtin/async/react-scroll-to-bottom.js +5 -1
- package/lib/cjs/builtin/components/LanguageField/index.js +6 -18
- package/lib/cjs/builtin/iconify/react.js +1 -1
- package/lib/cjs/builtin/page/header.js +8 -5
- package/lib/cjs/builtin/session.js +6 -0
- package/lib/cjs/builtin/stream.js +1 -1
- package/lib/cjs/builtin/utils.js +3 -5
- package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
- package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +2 -14
- package/lib/cjs/components/CustomComponentRenderer/ErrorComponent.js +2 -14
- package/lib/cjs/components/CustomComponentRenderer/index.js +12 -27
- package/lib/cjs/components/CustomComponentRenderer/state.js +121 -151
- package/lib/cjs/components/ResponsiveImage/index.js +3 -16
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/inject-es-module-shims-options.js +1 -2
- package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
- package/lib/cjs/utils/inject-global-components.js +29 -20
- package/lib/cjs/utils/preload.js +1 -15
- package/lib/cjs/utils/property.js +31 -25
- package/lib/cjs/utils/typescript/builtin-module-transformer.js +12 -9
- package/lib/esm/api/call.js +7 -18
- package/lib/esm/api/pages-kit.js +5 -17
- package/lib/esm/builtin/async/react-scroll-to-bottom.js +5 -1
- package/lib/esm/builtin/components/LanguageField/index.js +6 -18
- package/lib/esm/builtin/iconify/react.js +1 -1
- package/lib/esm/builtin/page/header.js +8 -5
- package/lib/esm/builtin/session.js +5 -0
- package/lib/esm/builtin/stream.js +1 -1
- package/lib/esm/builtin/utils.js +3 -5
- package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
- package/lib/esm/components/CustomComponentRenderer/DevProvider.js +2 -14
- package/lib/esm/components/CustomComponentRenderer/ErrorComponent.js +2 -14
- package/lib/esm/components/CustomComponentRenderer/index.js +12 -27
- package/lib/esm/components/CustomComponentRenderer/state.js +121 -151
- package/lib/esm/components/ResponsiveImage/index.js +3 -16
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/inject-es-module-shims-options.js +1 -2
- package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
- package/lib/esm/utils/inject-global-components.js +29 -20
- package/lib/esm/utils/preload.js +1 -15
- package/lib/esm/utils/property.js +30 -25
- package/lib/esm/utils/typescript/builtin-module-transformer.js +10 -8
- package/lib/types/builtin/session.d.ts +13 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/core.d.ts +11 -2
- package/lib/types/utils/property.d.ts +1 -0
- package/lib/types/utils/typescript/builtin-module-transformer.d.ts +1 -0
- 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:
|
|
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
|
|
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 = !!
|
|
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':
|
|
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,
|
|
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(
|
|
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 =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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 {
|
package/lib/cjs/utils/preload.js
CHANGED
|
@@ -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((
|
|
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
|
|
22
|
-
|
|
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(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 (
|
|
43
|
-
script =
|
|
38
|
+
if (component.renderer?.type === 'web-component') {
|
|
39
|
+
script = component.renderer?.script;
|
|
44
40
|
break;
|
|
45
41
|
}
|
|
46
|
-
if (
|
|
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(
|
|
51
|
-
|
|
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,
|
|
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
|
|
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
|
|
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:
|
|
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:
|
|
28
|
+
name: s.importClause?.name?.text,
|
|
26
29
|
members: [],
|
|
27
30
|
namespace: '',
|
|
28
31
|
};
|
|
29
|
-
const 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:
|
|
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)
|
|
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,
|
|
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);
|
package/lib/esm/api/call.js
CHANGED
|
@@ -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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
}
|
package/lib/esm/api/pages-kit.js
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 }]) => (
|
|
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((
|
|
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 =
|
|
32
|
-
return (_jsx(Autocomplete,
|
|
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
|
|
23
|
+
onChange?.(newValue?.en);
|
|
36
24
|
}, renderOption: (props, option) => {
|
|
37
|
-
return (_createElement(MenuItem,
|
|
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,
|
|
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) => (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
package/lib/esm/builtin/utils.js
CHANGED
|
@@ -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
|
|
8
|
+
return globalThis.blocklet?.componentMountPoints.find((i) => i.name === name || i.did === name)?.mountPoint;
|
|
10
9
|
}
|
|
11
10
|
export function getMediaKitAbsoluteUrl(url) {
|
|
12
|
-
|
|
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 =
|
|
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(
|
|
16
|
-
var props = __rest(_a, []);
|
|
4
|
+
export default function BlockletReactComponentRenderer({ ...props }) {
|
|
17
5
|
const url = useMemo(() => {
|
|
18
|
-
|
|
19
|
-
const
|
|
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,
|
|
16
|
+
return _jsx(C, { ...props.props });
|
|
30
17
|
}
|
|
31
18
|
const COMPONENTS_CACHE = {};
|
|
32
19
|
function loadComponent(url) {
|
|
33
|
-
|
|
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(
|
|
16
|
-
|
|
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 = (
|
|
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
|
|
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
|
};
|