@blocklet/pages-kit 0.6.45 → 0.6.47
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/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/builtin.js +0 -1
- package/lib/cjs/utils/inject-global-components-dump-json.js +0 -45
- package/lib/cjs/utils/inject-global-components.js +1 -2
- package/lib/cjs/utils/typescript/builtin-module-transformer.js +20 -3
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/builtin.js +0 -1
- package/lib/esm/utils/inject-global-components-dump-json.js +0 -45
- package/lib/esm/utils/inject-global-components.js +1 -2
- package/lib/esm/utils/typescript/builtin-module-transformer.js +20 -3
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/builtin.d.ts +0 -1
- package/package.json +8 -14
- package/lib/cjs/builtin/async/ai-runtime.js +0 -17
- package/lib/esm/builtin/async/ai-runtime.js +0 -1
- package/lib/types/builtin/async/ai-runtime.d.ts +0 -1
package/lib/esm/utils/builtin.js
CHANGED
|
@@ -34,7 +34,6 @@ export const BuiltinModules = {
|
|
|
34
34
|
'@blocklet/pages-kit/builtin/async/react-markdown': {},
|
|
35
35
|
'@blocklet/pages-kit/builtin/async/react-syntax-highlighter': {},
|
|
36
36
|
'@blocklet/pages-kit/builtin/async/image-preview': {},
|
|
37
|
-
'@blocklet/pages-kit/builtin/async/ai-runtime': {},
|
|
38
37
|
'@blocklet/pages-kit/builtin/uploader': {},
|
|
39
38
|
'@blocklet/pages-kit/builtin/color-picker': {},
|
|
40
39
|
'@blocklet/pages-kit/builtin/markdown/index': {},
|
|
@@ -1026,51 +1026,6 @@ export default () =>
|
|
|
1026
1026
|
examples: [],
|
|
1027
1027
|
},
|
|
1028
1028
|
},
|
|
1029
|
-
// '@blocklet/pages-kit/builtin/async/ai-runtime'
|
|
1030
|
-
{
|
|
1031
|
-
name: '@blocklet/pages-kit/builtin/async/ai-runtime',
|
|
1032
|
-
description: 'A ai-runtime component for pages-kit builtin package',
|
|
1033
|
-
docs: {
|
|
1034
|
-
components: [
|
|
1035
|
-
'CurrentAgent',
|
|
1036
|
-
'CurrentAgentProvider',
|
|
1037
|
-
'CurrentMessage',
|
|
1038
|
-
'CurrentMessageProvider',
|
|
1039
|
-
'Runtime',
|
|
1040
|
-
'ChatBotButton',
|
|
1041
|
-
'SimplePage',
|
|
1042
|
-
'SimpleChat',
|
|
1043
|
-
'PhotoGallery',
|
|
1044
|
-
'AutoForm',
|
|
1045
|
-
'SimpleOutput',
|
|
1046
|
-
'ChatOutput',
|
|
1047
|
-
'PhotoGalleryItem',
|
|
1048
|
-
],
|
|
1049
|
-
import: "import * as AiRuntime from '@blocklet/pages-kit/builtin/async/ai-runtime'",
|
|
1050
|
-
export: `
|
|
1051
|
-
export * from './contexts/CurrentAgent';
|
|
1052
|
-
export { default as CurrentAgentProvider } from './contexts/CurrentAgent';
|
|
1053
|
-
|
|
1054
|
-
export * from './contexts/CurrentMessage';
|
|
1055
|
-
export { default as CurrentMessageProvider } from './contexts/CurrentMessage';
|
|
1056
|
-
|
|
1057
|
-
export * from './state/runtime';
|
|
1058
|
-
export * from './state/session';
|
|
1059
|
-
|
|
1060
|
-
export { default as Runtime } from './runtime/Runtime';
|
|
1061
|
-
export { default as ChatBotButton } from './runtime/ChatBotButton';
|
|
1062
|
-
|
|
1063
|
-
export { default as SimplePage } from './runtime-components/SimplePage';
|
|
1064
|
-
export { default as SimpleChat } from './runtime-components/SimpleChat';
|
|
1065
|
-
export { default as PhotoGallery } from './runtime-components/PhotoGallery';
|
|
1066
|
-
export { default as AutoForm } from './runtime-components/AutoForm';
|
|
1067
|
-
export { default as SimpleOutput } from './runtime-components/SimpleOutput';
|
|
1068
|
-
export { default as ChatOutput } from './runtime-components/ChatOutput';
|
|
1069
|
-
export { default as PhotoGalleryItem } from './runtime-components/PhotoGalleryItem';
|
|
1070
|
-
`,
|
|
1071
|
-
examples: [],
|
|
1072
|
-
},
|
|
1073
|
-
},
|
|
1074
1029
|
// '@blocklet/pages-kit/builtin/pages-kit'
|
|
1075
1030
|
{
|
|
1076
1031
|
name: '@blocklet/pages-kit/builtin/pages-kit',
|
|
@@ -82,7 +82,6 @@ export function injectGlobalComponents() {
|
|
|
82
82
|
'@blocklet/pages-kit/builtin/async/react-markdown': reactMarkdown,
|
|
83
83
|
'@blocklet/pages-kit/builtin/async/react-syntax-highlighter': reactSyntaxHighlighter,
|
|
84
84
|
'@blocklet/pages-kit/builtin/async/image-preview': imagePreview,
|
|
85
|
-
'@blocklet/pages-kit/builtin/async/ai-runtime': import('../builtin/async/ai-runtime'),
|
|
86
85
|
'@blocklet/pages-kit/builtin/event-bus': eventBus,
|
|
87
86
|
'@blocklet/pages-kit/builtin/zod': zod,
|
|
88
87
|
};
|
|
@@ -209,7 +208,7 @@ export function injectGlobalComponents() {
|
|
|
209
208
|
: [];
|
|
210
209
|
// create module code
|
|
211
210
|
const moduleCode = `// GENERATED FILE. DO NOT EDIT.
|
|
212
|
-
const moduleSource = window['${BuiltinModulesGlobalVariableName}'].modules['${modulePath}'];
|
|
211
|
+
const moduleSource = window['${BuiltinModulesGlobalVariableName}'].modules['${modulePath}'];
|
|
213
212
|
${namedExports.map((name) => `export const ${name} = moduleSource['${name}'];`).join('\n')}
|
|
214
213
|
${defaultExports.map((name) => `export const ${name} = moduleSource.default['${name}'];`).join('\n')}
|
|
215
214
|
export default ${hasDefaultExport ? 'moduleSource.default' : 'moduleSource'};
|
|
@@ -9,7 +9,7 @@ export const isAsyncModule = (moduleSpecifier) => {
|
|
|
9
9
|
if (!moduleSpecifier) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return false;
|
|
13
13
|
};
|
|
14
14
|
// check if the module is a target module
|
|
15
15
|
export const isBuiltinModule = (moduleSpecifier) => {
|
|
@@ -22,8 +22,23 @@ export const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
|
22
22
|
const { factory } = context;
|
|
23
23
|
// 统一的模块导入收集器
|
|
24
24
|
const imports = [];
|
|
25
|
+
// Transform dynamic imports in expressions
|
|
26
|
+
const transformNode = (node) => {
|
|
27
|
+
// Handle import() calls
|
|
28
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
29
|
+
const arg = node.arguments[0];
|
|
30
|
+
if (arg && ts.isStringLiteral(arg) && (isBuiltinModule(arg.text) || isRelativeModule(arg.text))) {
|
|
31
|
+
const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(arg.text)]);
|
|
32
|
+
// For dynamic imports, we don't add await - they should return Promise
|
|
33
|
+
// The calling code (like .then()) will handle the Promise
|
|
34
|
+
return requireCall;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return ts.visitEachChild(node, transformNode, context);
|
|
38
|
+
};
|
|
25
39
|
// filter and collect the import statements that need to be processed
|
|
26
|
-
const statements = file.statements
|
|
40
|
+
const statements = file.statements
|
|
41
|
+
.filter((s) => {
|
|
27
42
|
if (ts.isImportDeclaration(s) &&
|
|
28
43
|
ts.isStringLiteral(s.moduleSpecifier) &&
|
|
29
44
|
(isBuiltinModule(s.moduleSpecifier.text) || isRelativeModule(s.moduleSpecifier.text))) {
|
|
@@ -51,10 +66,12 @@ export const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
|
51
66
|
return false;
|
|
52
67
|
}
|
|
53
68
|
return true;
|
|
54
|
-
})
|
|
69
|
+
})
|
|
70
|
+
.map((statement) => transformNode(statement)); // Transform dynamic imports in remaining statements
|
|
55
71
|
statements.unshift(...imports.flatMap((importInfo) => {
|
|
56
72
|
// call inject-global-components require method
|
|
57
73
|
const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(importInfo.moduleName)]);
|
|
74
|
+
// Only static imports should be async, dynamic imports return Promise
|
|
58
75
|
const isAsync = isRelativeModule(importInfo.moduleName) || isAsyncModule(importInfo.moduleName);
|
|
59
76
|
// create await expression if the module is ../ or ./
|
|
60
77
|
const mod = isAsync ? factory.createAwaitExpression(requireCall) : requireCall;
|