@macrowing/inbiz-codegen 0.0.0-stage → 1.0.1

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 (163) hide show
  1. package/README.md +592 -2
  2. package/bin/inbiz-codegen.mjs +7 -0
  3. package/package.json +32 -4
  4. package/scripts/prepare-templates.mjs +35 -0
  5. package/src/backend/init.mjs +170 -0
  6. package/src/config.mjs +150 -0
  7. package/src/favicon.mjs +100 -0
  8. package/src/generate.mjs +935 -0
  9. package/src/generated-output.mjs +107 -0
  10. package/src/index.mjs +346 -0
  11. package/src/menu/build.mjs +252 -0
  12. package/src/menu/check.mjs +163 -0
  13. package/src/menu/command.mjs +179 -0
  14. package/src/migrate-runtime.mjs +106 -0
  15. package/src/platform/client.mjs +167 -0
  16. package/src/platform/command.mjs +386 -0
  17. package/src/platform/pack.mjs +591 -0
  18. package/src/platform/recover.mjs +236 -0
  19. package/src/platform/startup.mjs +343 -0
  20. package/src/platform/state.mjs +116 -0
  21. package/src/platform/update.mjs +157 -0
  22. package/src/platform/zip.mjs +134 -0
  23. package/src/pull.mjs +284 -0
  24. package/src/scaffold/commands.mjs +349 -0
  25. package/src/scaffold/init.mjs +392 -0
  26. package/src/scaffold/template-files.mjs +40 -0
  27. package/src/scaffold/template-source.mjs +235 -0
  28. package/src/scaffold/template-sync.mjs +335 -0
  29. package/src/transform/heaviness.mjs +380 -0
  30. package/src/transform/preview-props.mjs +108 -0
  31. package/src/transform/published-page-links.mjs +61 -0
  32. package/src/transform/published-script.mjs +110 -0
  33. package/src/transform/registry.mjs +781 -0
  34. package/src/transform/schema-to-jsx.mjs +1708 -0
  35. package/src/util/des.mjs +10 -0
  36. package/templates/README.md +34 -0
  37. package/templates/backend/Directory.Build.props +19 -0
  38. package/templates/backend/Directory.Packages.props +49 -0
  39. package/templates/backend/Macrowing.Scaffold.slnx +13 -0
  40. package/templates/backend/host/Macrowing.Start/Init/app.json +8 -0
  41. package/templates/backend/host/Macrowing.Start/Init/menus.json +4 -0
  42. package/templates/backend/host/Macrowing.Start/Initialization/InitializationDefinition.cs +245 -0
  43. package/templates/backend/host/Macrowing.Start/Initialization/InitializationEndpoints.cs +57 -0
  44. package/templates/backend/host/Macrowing.Start/Initialization/InitializationHostedService.cs +63 -0
  45. package/templates/backend/host/Macrowing.Start/Initialization/InitializationOptions.cs +44 -0
  46. package/templates/backend/host/Macrowing.Start/Initialization/InitializationRunner.cs +294 -0
  47. package/templates/backend/host/Macrowing.Start/Initialization/InitializationState.cs +72 -0
  48. package/templates/backend/host/Macrowing.Start/Initialization/MenuFactory.cs +118 -0
  49. package/templates/backend/host/Macrowing.Start/Initialization/PackageBuilder.cs +317 -0
  50. package/templates/backend/host/Macrowing.Start/Initialization/PlatformAppImporter.cs +371 -0
  51. package/templates/backend/host/Macrowing.Start/Macrowing.Start.csproj +26 -0
  52. package/templates/backend/host/Macrowing.Start/Program.cs +33 -0
  53. package/templates/backend/host/Macrowing.Start/StartModule.cs +67 -0
  54. package/templates/backend/host/Macrowing.Start/appsettings.json +38 -0
  55. package/templates/backend/modules/Macrowing.Generated/Application/GeneratedApplicationAutoMapperProfile.cs +42 -0
  56. package/templates/backend/modules/Macrowing.Generated/Domain/Entities/GeneratedEntityBase.cs +72 -0
  57. package/templates/backend/modules/Macrowing.Generated/Domain/GeneratedConsts.cs +50 -0
  58. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs +55 -0
  59. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContextModelBuilderExtensions.cs +61 -0
  60. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs +32 -0
  61. package/templates/backend/modules/Macrowing.Generated/GeneratedModule.cs +89 -0
  62. package/templates/backend/modules/Macrowing.Generated/Macrowing.Generated.csproj +22 -0
  63. package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsClient.cs +95 -0
  64. package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsModels.cs +81 -0
  65. package/templates/backend/modules/Macrowing.InBiz.SDK/Dictionary/DictionaryClient.cs +44 -0
  66. package/templates/backend/modules/Macrowing.InBiz.SDK/InBizSdkModule.cs +16 -0
  67. package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs +50 -0
  68. package/templates/backend/modules/Macrowing.InBiz.SDK/Localization/LocalizationClient.cs +28 -0
  69. package/templates/backend/modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj +16 -0
  70. package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageClient.cs +99 -0
  71. package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageModels.cs +63 -0
  72. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelClient.cs +131 -0
  73. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelQuery.cs +108 -0
  74. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelWrite.cs +44 -0
  75. package/templates/backend/modules/Macrowing.InBiz.SDK/Permission/PermissionClient.cs +86 -0
  76. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformException.cs +42 -0
  77. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformRegistration.cs +60 -0
  78. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformTransport.cs +96 -0
  79. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizRequestContext.cs +27 -0
  80. package/templates/backend/modules/Macrowing.InBiz.SDK/README.md +117 -0
  81. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs +35 -0
  82. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs +20 -0
  83. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationRequests.cs +105 -0
  84. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationsClient.cs +53 -0
  85. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/README.md +132 -0
  86. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Tracking/WorkFlowTrackingClient.cs +50 -0
  87. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeClient.cs +78 -0
  88. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeModels.cs +34 -0
  89. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowContracts.cs +88 -0
  90. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowRegistration.cs +59 -0
  91. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowTransport.cs +163 -0
  92. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchClient.cs +59 -0
  93. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchModels.cs +76 -0
  94. package/templates/backend/modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj +20 -0
  95. package/templates/backend/modules/Macrowing.OC.SDK/OcSdkModule.cs +18 -0
  96. package/templates/backend/modules/Macrowing.OC.SDK/Protos/README.md +22 -0
  97. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj +14 -0
  98. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformContractTests.cs +288 -0
  99. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformLiveTests.cs +173 -0
  100. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowHttpServer.cs +113 -0
  101. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowLiveTests.cs +269 -0
  102. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowOperationsTests.cs +80 -0
  103. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowQueryTests.cs +163 -0
  104. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowTransportTests.cs +111 -0
  105. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowUpgradeTests.cs +87 -0
  106. package/templates/frontend/components/README.md +39 -0
  107. package/templates/frontend/components/app-components/README.md +33 -0
  108. package/templates/frontend/components/app-components/common/.gitkeep +0 -0
  109. package/templates/frontend/components/app-components/components/.gitkeep +0 -0
  110. package/templates/frontend/components/app-components/package.json +20 -0
  111. package/templates/frontend/mgt/.umirc.ts +574 -0
  112. package/templates/frontend/mgt/package.json +96 -0
  113. package/templates/frontend/mgt/src/app-extends.ts +9 -0
  114. package/templates/frontend/mgt/src/app.tsx +20 -0
  115. package/templates/frontend/mgt/src/config/app.ts +31 -0
  116. package/templates/frontend/mgt/src/layout/header.tsx +14 -0
  117. package/templates/frontend/mgt/src/layout/index.tsx +11 -0
  118. package/templates/frontend/mgt/src/layout/sidebar.tsx +14 -0
  119. package/templates/frontend/mgt/src/locales.ts +8 -0
  120. package/templates/frontend/mgt/src/pages/.gitkeep +0 -0
  121. package/templates/frontend/mgt/src/root.tsx +12 -0
  122. package/templates/frontend/mgt/src/route-view.tsx +3 -0
  123. package/templates/frontend/mgt/src/runtime.ts +21 -0
  124. package/templates/frontend/mgt/src/styles/app.css +1 -0
  125. package/templates/frontend/mgt/src/styles/layout.less +79 -0
  126. package/templates/frontend/mgt/tsconfig.json +65 -0
  127. package/templates/frontend/mgt/typings.d.ts +57 -0
  128. package/templates/frontend/wap/.umirc.ts +574 -0
  129. package/templates/frontend/wap/package.json +73 -0
  130. package/templates/frontend/wap/src/app-extends.ts +9 -0
  131. package/templates/frontend/wap/src/app.tsx +28 -0
  132. package/templates/frontend/wap/src/config/app.ts +31 -0
  133. package/templates/frontend/wap/src/layout/header.tsx +14 -0
  134. package/templates/frontend/wap/src/layout/index.tsx +18 -0
  135. package/templates/frontend/wap/src/layout/sidebar.tsx +14 -0
  136. package/templates/frontend/wap/src/locales.ts +8 -0
  137. package/templates/frontend/wap/src/pages/.gitkeep +0 -0
  138. package/templates/frontend/wap/src/root.tsx +12 -0
  139. package/templates/frontend/wap/src/route-view.tsx +3 -0
  140. package/templates/frontend/wap/src/runtime.ts +21 -0
  141. package/templates/frontend/wap/src/styles/adaptation.less +190 -0
  142. package/templates/frontend/wap/src/styles/app.css +7 -0
  143. package/templates/frontend/wap/src/styles/global.less +81 -0
  144. package/templates/frontend/wap/src/styles/layout.less +92 -0
  145. package/templates/frontend/wap/tsconfig.json +66 -0
  146. package/templates/frontend/wap/typings.d.ts +24 -0
  147. package/templates/frontend/web/.umirc.ts +574 -0
  148. package/templates/frontend/web/package.json +26 -0
  149. package/templates/frontend/web/src/app-extends.ts +9 -0
  150. package/templates/frontend/web/src/app.tsx +25 -0
  151. package/templates/frontend/web/src/config/app.ts +31 -0
  152. package/templates/frontend/web/src/layout/header.tsx +14 -0
  153. package/templates/frontend/web/src/layout/index.tsx +11 -0
  154. package/templates/frontend/web/src/layout/sidebar.tsx +14 -0
  155. package/templates/frontend/web/src/locales.ts +8 -0
  156. package/templates/frontend/web/src/root.tsx +12 -0
  157. package/templates/frontend/web/src/route-view.tsx +3 -0
  158. package/templates/frontend/web/src/runtime.ts +21 -0
  159. package/templates/frontend/web/src/styles/app.css +104 -0
  160. package/templates/frontend/web/src/styles/layout.less +124 -0
  161. package/templates/frontend/web/tsconfig.json +91 -0
  162. package/templates/frontend/web/typings.d.ts +46 -0
  163. package/templates/package.json +14 -0
@@ -0,0 +1,781 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { CODEGEN_ROOT, COMPONENTS_ROOT } from '../config.mjs';
4
+ import { previewImplementationImports, readsPreviewProp } from './preview-props.mjs';
5
+
6
+ /**
7
+ * 组件注册表:x-component 名字 → 组件包里的位置。
8
+ *
9
+ * 扫描组件包真实目录得出,**不硬编码**。理由:
10
+ * InBiz 的组件名由目录名转 PascalCase 得来(见组件库
11
+ * `core/entry/webPreview` 里的 `properCase(path.split('/')[3])`)。
12
+ * 硬编码一张表,组件库一升级就漏;扫描能自动跟上。
13
+ *
14
+ * 扫描根来自 `@macrowing/inbiz-components` 这个 npm 依赖(见 config.mjs 的
15
+ * `COMPONENTS_ROOT`),不指向 codegen 下的源码副本 —— 出码只消费包的公共入口。
16
+ *
17
+ * 匹配的路径形态:
18
+ * components/<域>/<类>/<组件名>/preview/web/index.{tsx,js}
19
+ * components/form/layout/SyncComponents/<组件名>/preview/web/index.{tsx,js}
20
+ */
21
+ const COMPONENTS_PACKAGE_ENTRY = '@macrowing/inbiz-components/components';
22
+
23
+ /**
24
+ * 读取运行时 schema 的容器组件 → runtime 兼容层里有一份按 children 渲染的实现。
25
+ *
26
+ * 这些组件的子节点在平台上是 schema 树里的 properties,出码后一律变成 JSX
27
+ * children,所以组件本身必须换成不依赖 Formily 的等价实现(见 inbiz-runtime/compat)。
28
+ * 键是 kebab-case 文件名,换新组件时同时在这里和 runtime 的 compat 目录里加。
29
+ */
30
+ const COMPAT_CONTAINERS = new Set(['form-sider-layout', 'form-tab']);
31
+ // These use useLayouts or Formily's grid tracker, not mapProperties. The
32
+ // compat host and its members must be resolved together before choosing imports.
33
+ const REQUIRED_COMPAT_CONTAINERS = new Set(['form-grid', 'multiple-column-layout']);
34
+
35
+ /** 目录名 → 组件名:`InbizMenu` / `Table` / `SearchEntry` 这类本身就是 PascalCase */
36
+ function toComponentName(dirName) {
37
+ if (!dirName) return '';
38
+ return dirName.charAt(0).toUpperCase() + dirName.slice(1);
39
+ }
40
+
41
+ /** 应用定制组件根目录:从 iso-web 插件源码复制到出码工程里 */
42
+ export const CUSTOM_ROOT_REL = 'scaffolds/frontend/components/iso-custom/components';
43
+
44
+ /**
45
+ * 定制组件根目录清单:每项 = 扫描目录 + 生成代码里的 import 前缀。
46
+ *
47
+ * 为什么从「一个常量」改成「一张清单」:
48
+ * 定制组件来自不同插件工程(iso-web 的 iso-custom、edoc2-frontend 的 ECM 插件),
49
+ * 它们各自要保留原工程的目录结构 —— 组件源码里的 `@/<dir>/...` 包内引用
50
+ * 是按这个结构写的。放同一个根里必然撞名(两边都有 common/、assets/),
51
+ * 所以一个插件一个根,各配各的别名前缀。
52
+ *
53
+ * 仍然是「扫描目录」而不是硬编码组件名:组件库/插件一升级,新组件自动被扫到。
54
+ * 顺序即优先级 —— 同名组件先扫到的生效,所以老的 iso-custom 排前面,
55
+ * 保持既有产物的 import 路径不变。
56
+ */
57
+ export const CUSTOM_ROOTS = [
58
+ { rel: CUSTOM_ROOT_REL, importPrefix: '@macrowing/iso-custom/components' },
59
+ // edoc2-frontend(ECM 插件,OutId 3a098f32ac12a987d8c8214cc83cdcc3)里
60
+ // 首页 / 文档页 / 搜索页用到的定制组件。见 components/edoc2/README.md。
61
+ { rel: 'scaffolds/frontend/components/edoc2/components', importPrefix: '@macrowing/edoc2/components' },
62
+ ];
63
+
64
+ /**
65
+ * 应用插件登记表:插件 OutId → 插件身份 + 组件源码在插件工程里的相对位置。
66
+ *
67
+ * schema 里的插件组件写成 `Card$3a098f32ac12a987d8c8214cc83cdcc3`,后缀就是
68
+ * iso-web/standard/common/customplugin/customPlugin.json 里的 OutId。出码只扫描
69
+ * 「平台组件库 + 已复制进 iso-custom 的定制组件」两处,插件组件没被复制进来时
70
+ * 必然解析不到 —— 光看一个哈希,没人能判断是「组件本来就该自己实现」还是
71
+ * 「插件源码在隔壁仓库、只是没复制」。这张表补的就是这层身份信息。
72
+ *
73
+ * ⚠️ 这里**只用于诊断**,不参与解析:生成的 import 必须落在本工程内,
74
+ * 指向本工程之外的绝对路径在产物里是坏引用。
75
+ */
76
+ export const APP_PLUGINS = {
77
+ '3a098f32ac12a987d8c8214cc83cdcc3': { name: 'ECM', componentsRel: 'ECM/src/components' },
78
+ 'e0de25ff-dc9e-4681-a61f-3a201b29278f': {
79
+ name: 'Document',
80
+ componentsRel: 'Document/src/components',
81
+ },
82
+ 'f3f5b77e-e688-4337-8ccb-4c54de406c8e': { name: 'iso', componentsRel: 'iso/src/components' },
83
+ };
84
+
85
+ /**
86
+ * 插件源码可能所在的根目录(每个根下面直接是 `<插件名>/src/components`)。
87
+ *
88
+ * 插件工程不在 codegen 的版本库内:iso 插件在 iso-web/plugins 下,ECM 与
89
+ * Document 插件在隔壁的 opencontent 仓库里。硬编码绝对路径会让换机器就失效,
90
+ * 所以按「相对 codegen 的兄弟目录」列出候选,并允许用 INBIZ_PLUGIN_ROOT
91
+ * 显式覆盖(多个根用 path.delimiter 分隔)。找不到只是少一条诊断信息,不影响出码。
92
+ */
93
+ const PLUGIN_ROOT_BASES = [
94
+ process.env.INBIZ_PLUGIN_ROOT,
95
+ // G:/aicode/{inbiz/v8.5/codegen} → G:/aicode/opencontent/ecm/.../plugins
96
+ path.resolve(CODEGEN_ROOT, '../../../opencontent/ecm/ecm-frontend/website/ecm/standard/plugins'),
97
+ // → G:/aicode/inbiz/iso-web/plugins
98
+ path.resolve(CODEGEN_ROOT, '../../iso-web/plugins'),
99
+ ]
100
+ .filter(Boolean)
101
+ .flatMap((base) => String(base).split(path.delimiter).filter(Boolean));
102
+
103
+ /**
104
+ * 同功能替代表:平台侧有一个「同族但不同源」的实现时登记在这里。
105
+ *
106
+ * 为什么需要这张表而不是逐个 if:插件版本与平台版本经常是同一个组件的两份
107
+ * 实现(Document 插件的 ImgUpload 与组件库的 EformImgUpload 连 defaultProps
108
+ * 都对得上)。这类关系是**数据**,一多就散成一堆 if,既看不出全貌,也没法在
109
+ * 报告里逐个说明差异。
110
+ *
111
+ * accepts 是替身真实读取的 props(判定依据写在各条目的 evidence 里)。
112
+ * 生成时会拿 schema 实际传入的 props 与它求差,把丢掉的属性逐条写进报告 ——
113
+ * 替代不能静默丢掉配置,否则界面「看起来在、其实按默认值跑」。
114
+ */
115
+ export const COMPONENT_SUBSTITUTES = {
116
+ ImgUpload: {
117
+ to: 'EformImgUpload',
118
+ // packages/inbiz-components/src/core/components/form/base/EformImgUpload
119
+ // preview/web/index.tsx:31-62(IProps)、designer/schema.ts:20-32(defaultProps)
120
+ accepts: [
121
+ 'value', 'onChange', 'multiple', 'imgSize', 'imgType', 'imgHeight', 'imgWidth',
122
+ 'cutting', 'cuttingLimits', 'storageMode', 'thumbnail', 'placeHolder', 'fixedHeight',
123
+ 'maxNumber', 'required', 'readOnly', 'disabled', 'inbiz', 'emit', 'callBackEvents',
124
+ ],
125
+ // Document 插件的 ImgUpload 多一层「上传到指定目录」,替身没有
126
+ evidence:
127
+ 'plugins/Document/src/components/Base/ImgUpload/preview/web/index.tsx:33-72 ↔ ' +
128
+ 'inbiz-components/.../EformImgUpload/preview/web/index.tsx:31-62',
129
+ },
130
+ FileUpload: {
131
+ to: 'ISOUploadFile',
132
+ // iso-custom/components/basic/ISOUploadFile/preview/shared.tsx:47-76(IProps)
133
+ // designer/schema.ts:16-30(defaultProps)
134
+ accepts: [
135
+ 'value', 'onChange', 'placeholder', 'multiple', 'thumbnail', 'fileMode', 'acceptText',
136
+ 'fileSize', 'fileSizeValue', 'fileSizeUnit', 'repeatStrategy', 'showStrategyModal',
137
+ 'targetFolder', 'customClick', 'readOnly', 'disabled', 'inbiz', 'emit', 'callBackEvents',
138
+ ],
139
+ // 插件版按「文件类型白名单 + 目录权限 + 子目录创建」上传,替身只认 acceptText
140
+ evidence:
141
+ 'plugins/Document/src/components/Base/FileUpload/preview/web/index.tsx:27-58 ↔ ' +
142
+ 'iso-custom/components/basic/ISOUploadFile/preview/shared.tsx:47-76',
143
+ },
144
+ SearchList: {
145
+ to: 'SearchResultEngine',
146
+ // packages/inbiz-components/src/core/components/business/search/SearchResultEngine
147
+ // preview/web/index.tsx:25-73(IConfigItemEngineProps)、designer/schema.ts:22-35
148
+ accepts: [
149
+ 'indexIibraryConfig', 'headerStyle', 'displayRule', 'pageNumber', 'similarSearch',
150
+ 'showBack', 'searchEngineComponent', 'title', 'style', 'boxHeight', 'inbiz', 'emit',
151
+ 'callBackEvents',
152
+ ],
153
+ evidence:
154
+ 'plugins/ECM/src/components/AppLibrary/SearchList/preview/web/index.tsx:15-22 ↔ ' +
155
+ 'inbiz-components/.../SearchResultEngine/preview/web/index.tsx:25-73',
156
+ },
157
+ };
158
+
159
+ /** 按名字取组件,先精确后忽略大小写(组件库存在只差大小写的目录) */
160
+ function lookup(registry, name) {
161
+ if (!name || !registry) return null;
162
+ if (registry.has(name)) return registry.get(name);
163
+ const lower = name.toLowerCase();
164
+ for (const [k, v] of registry) {
165
+ if (k.toLowerCase() === lower) return v;
166
+ }
167
+ return null;
168
+ }
169
+
170
+ /** 拆 `Card$outId.Plugin$outId` → { base, slot, outId } */
171
+ function splitName(rawName) {
172
+ const raw = String(rawName || '').trim();
173
+ if (!raw) return { raw, base: '', slot: '', outId: '' };
174
+ const dotAt = raw.indexOf('.');
175
+ const hostPart = dotAt >= 0 ? raw.slice(0, dotAt) : raw;
176
+ const slotPart = dotAt >= 0 ? raw.slice(dotAt + 1) : '';
177
+ // OutId 可能挂在主体上,也可能挂在插槽上(`X.Plugin$outId`),取第一个非空的
178
+ const outIdOf = (s) => (s.match(/\$([0-9a-zA-Z-]+)$/) || [])[1] || '';
179
+ return {
180
+ raw,
181
+ base: hostPart.replace(INSTANCE_SUFFIX, ''),
182
+ slot: slotPart.replace(INSTANCE_SUFFIX, ''),
183
+ outId: outIdOf(hostPart) || outIdOf(slotPart),
184
+ };
185
+ }
186
+
187
+ /** 在候选根目录里找某个组件的源码目录(只用于诊断,结果缓存) */
188
+ const sourceProbe = new Map();
189
+ function findPluginSourceDir(plugin, componentName) {
190
+ if (!plugin || !componentName) return '';
191
+ const key = plugin.name + '|' + componentName;
192
+ if (sourceProbe.has(key)) return sourceProbe.get(key);
193
+
194
+ const walk = (dir, depth) => {
195
+ let entries;
196
+ try {
197
+ entries = fs.readdirSync(dir, { withFileTypes: true });
198
+ } catch {
199
+ return '';
200
+ }
201
+ for (const e of entries) {
202
+ if (!e.isDirectory()) continue;
203
+ const full = path.join(dir, e.name);
204
+ if (e.name === componentName) {
205
+ // 认「有 preview/web/index.*」的目录,避免撞上同名的内部子目录。
206
+ // 编译包是 index.js,源码包是 index.tsx/ts,两种都要认。
207
+ for (const ext of ['.tsx', '.ts', '.js', '.jsx']) {
208
+ if (fs.existsSync(path.join(full, 'preview/web/index' + ext))) return full;
209
+ }
210
+ }
211
+ if (depth > 0) {
212
+ const hit = walk(full, depth - 1);
213
+ if (hit) return hit;
214
+ }
215
+ }
216
+ return '';
217
+ };
218
+
219
+ let found = '';
220
+ for (const base of PLUGIN_ROOT_BASES) {
221
+ const root = path.join(base, plugin.componentsRel);
222
+ if (!fs.existsSync(root)) continue;
223
+ // 组件目录最深不过三层(域/类/组件名),再深就不是组件了
224
+ found = walk(root, 3);
225
+ if (found) break;
226
+ }
227
+ const out = found.split('\\').join('/');
228
+ sourceProbe.set(key, out);
229
+ return out;
230
+ }
231
+
232
+ /**
233
+ * 说明「这个组件为什么没解析到」。
234
+ *
235
+ * @returns {{ base:string, slot:string, plugin:object|null, sourcePath:string, sourceRel:string }}
236
+ * sourcePath 是本机上的绝对目录(空串表示本机确实没有),只用于报告;
237
+ * sourceRel 是相对插件根的路径,机器无关,可以安全写进生成代码。
238
+ * 绝对路径不能落到产物里:生成文件是提交进版本库的,换台机器重新生成
239
+ * 就会整片 diff 全是本机路径。
240
+ */
241
+ export function explainMissingComponent(rawName) {
242
+ const { base, slot, outId } = splitName(rawName);
243
+ const plugin = outId ? APP_PLUGINS[outId] : null;
244
+ const sourcePath = findPluginSourceDir(plugin, base);
245
+ // 相对路径取「组件根之后」的那一段,保住 FormTab / AppLibrary 这类中间层
246
+ let sourceRel = '';
247
+ if (sourcePath && plugin) {
248
+ const at = sourcePath.indexOf(plugin.componentsRel + '/');
249
+ const rest = at >= 0 ? sourcePath.slice(at + plugin.componentsRel.length + 1) : base;
250
+ sourceRel = `${plugin.componentsRel}/${rest}`;
251
+ }
252
+ return { base, slot, plugin: plugin || null, sourcePath, sourceRel };
253
+ }
254
+
255
+ /**
256
+ * 收集所有 preview/web/index.tsx 的组件。
257
+ *
258
+ * 同时扫描两处:
259
+ * 1. InBiz 组件库(平台内置组件)
260
+ * 2. 各个定制组件根(见 CUSTOM_ROOTS:iso-custom、edoc2)
261
+ * 后者与平台的自定义插件机制一致:schema 里的 `X$<插件OutId>` 指向它。
262
+ */
263
+ export function scanComponents() {
264
+ const map = new Map();
265
+ scanInto(map, COMPONENTS_ROOT, COMPONENTS_PACKAGE_ENTRY, '');
266
+ for (const root of CUSTOM_ROOTS) {
267
+ scanInto(map, path.join(CODEGEN_ROOT, root.rel), root.importPrefix, 'custom-');
268
+ }
269
+ return map;
270
+ }
271
+
272
+ /**
273
+ * 把组件相关的所有源码拼成一份文本,用于能力探测(是否读 emit 等)。
274
+ *
275
+ * 覆盖三处:
276
+ * 1. 组件目录整棵树(`<Name>/preview/web/*.tsx` 的兄弟文件)
277
+ * 2. 组件库共享实现目录 `core/common/<Name>/`
278
+ * 3. 同级的 `core/common/` 下与组件入口同名导入的文件
279
+ * 平台把 emit/inbiz 通过渲染器注入,组件可以把它传给任意深层子组件,
280
+ * 所以判定必须看整棵树,而不是入口那一个文件。
281
+ */
282
+ function collectDirSource(entryFile, dirName, { webOnly = false } = {}) {
283
+ const buf = [];
284
+ const seen = new Set();
285
+
286
+ const readTree = (dir) => {
287
+ if (seen.has(dir)) return;
288
+ seen.add(dir);
289
+ let entries;
290
+ try {
291
+ entries = fs.readdirSync(dir, { withFileTypes: true });
292
+ } catch {
293
+ return;
294
+ }
295
+ for (const e of entries) {
296
+ const full = path.join(dir, e.name);
297
+ if (e.isDirectory()) {
298
+ // 设计器代码不进运行态产物,扫了只会误判
299
+ if (e.name === 'designer' || e.name === 'node_modules' || (webOnly && e.name === 'wap')) continue;
300
+ readTree(full);
301
+ continue;
302
+ }
303
+ if (!/\.(tsx?|jsx?)$/.test(e.name)) continue;
304
+ try {
305
+ buf.push(fs.readFileSync(full, 'utf8'));
306
+ } catch {
307
+ /* 读不到就跳过 */
308
+ }
309
+ }
310
+ };
311
+
312
+ // 组件目录:.../components/<域>/<类>/<Name>/preview/web/index.tsx
313
+ // 从 preview/web 往上两层就是当前组件,不能扫到同类的其他组件。
314
+ readTree(path.resolve(path.dirname(entryFile), '../..'));
315
+ // 共享实现:.../core/common/<Name>/
316
+ readTree(path.resolve(path.dirname(entryFile), '../../../../../../common', dirName));
317
+
318
+ return buf.join('\n');
319
+ }
320
+
321
+ /**
322
+ * 解析相对导入到真实文件。
323
+ *
324
+ * 组件包既有源码形态(`.tsx` / `.ts`),也有 npm 编译产物形态(`.js`)。
325
+ * 只认前两种时,编译包里 `export default X` 转发到同目录实现的那类组件
326
+ * (`PageTopBottomLayout.Contents`、Block 的插槽成员等)追不到实现,
327
+ * 于是「挂在默认导出上的成员」全部识别不到 —— 插槽退化、成员壳子丢失。
328
+ */
329
+ const COMPONENT_CODE_EXTS = ['.tsx', '.ts', '.jsx', '.js'];
330
+
331
+ function resolveComponentFile(base) {
332
+ const candidates = [
333
+ base,
334
+ ...COMPONENT_CODE_EXTS.map((ext) => base + ext),
335
+ ...COMPONENT_CODE_EXTS.map((ext) => path.join(base, 'index' + ext)),
336
+ ];
337
+ for (const candidate of candidates) {
338
+ try {
339
+ if (fs.statSync(candidate).isFile()) return candidate;
340
+ } catch { /* 继续找 */ }
341
+ }
342
+ return null;
343
+ }
344
+
345
+ // A preview can forward its default export to a shared implementation.
346
+ function defaultExportSource(file, source, seen = new Set([file])) {
347
+ const local = source.match(/\bexport\s+default\s+([\w$]+)\s*;?\s*$/)?.[1];
348
+ if (!local) return source;
349
+ // 压缩产物写成 `import o from"../common";export default o;` —— `from` 与引号之间
350
+ // 没有空格。要求 `from\s+` 时这条转发链断掉,默认导出退回 50 字节的 shim,
351
+ // 后面的 attachedProps / namedExports 全部为空。
352
+ const imported = [...source.matchAll(/\bimport\s+([\w$]+)\s+from\s*['"](\.[^'"]+)['"]/g)]
353
+ .find(([, name]) => name === local);
354
+ if (!imported) return source;
355
+ const candidate = resolveComponentFile(path.resolve(path.dirname(file), imported[2]));
356
+ if (!candidate || seen.has(candidate)) return source;
357
+ let implementation;
358
+ try { implementation = fs.readFileSync(candidate, 'utf8'); } catch { return source; }
359
+ seen.add(candidate);
360
+ return defaultExportSource(candidate, implementation, seen);
361
+ }
362
+
363
+ function previewReadsProp(file, source, componentName, prop, seen = new Set()) {
364
+ if (seen.has(file)) return false;
365
+ seen.add(file);
366
+ if (readsPreviewProp(source, prop)) return true;
367
+ for (const specifier of previewImplementationImports(source, componentName)) {
368
+ const candidate = resolveComponentFile(path.resolve(path.dirname(file), specifier));
369
+ if (!candidate) continue;
370
+ let implementation;
371
+ try { implementation = fs.readFileSync(candidate, 'utf8'); } catch { continue; }
372
+ if (previewReadsProp(candidate, implementation, componentName, prop, seen)) return true;
373
+ break;
374
+ }
375
+ return false;
376
+ }
377
+
378
+ function readPreviewCodegen(entryFile, jsxSlots, widgetSlots, componentSlots) {
379
+ const file = path.join(path.dirname(entryFile), 'codegen.json');
380
+ if (!fs.existsSync(file)) return {};
381
+ const { omitProps = [], slotsRequireChildren = [] } = JSON.parse(fs.readFileSync(file, 'utf8'));
382
+ if (!Array.isArray(omitProps) || omitProps.some(prop => typeof prop !== 'string' || !prop.trim())) {
383
+ throw new Error(`Invalid omitProps in ${file}: expected an array of property names`);
384
+ }
385
+ /**
386
+ * 插槽有三种声明形态,`slotsRequireChildren` 三种都要认:
387
+ * 1. `useSlot('X.Y')` → jsxSlots
388
+ * 2. `<RenderDropableWidget/>` → widgetSlots
389
+ * 3. `X.Query.slotName = 'X.Query'`(组件把插槽作为具名导出暴露)
390
+ *
391
+ * 第 3 种正是 AGENTS.md 要求的「有真实实现的插槽用该组件导出的 slotName 注册」。
392
+ * 只校验前两种时,Table 这类用 `Object.assign(Component, { Query, BtnGroup })`
393
+ * 加 `slotName` 静态属性声明插槽的组件,其 codegen.json 会被判非法,
394
+ * 整次注册表扫描直接抛错 —— 出码根本跑不起来。
395
+ */
396
+ if (!Array.isArray(slotsRequireChildren) ||
397
+ slotsRequireChildren.some(slot =>
398
+ !jsxSlots.has(slot) && !widgetSlots.has(slot) && !componentSlots?.has(slot))) {
399
+ throw new Error(`Invalid slotsRequireChildren in ${file}: expected an array of declared slot names`);
400
+ }
401
+ return { omitProps: new Set(omitProps), slotsRequireChildren: new Set(slotsRequireChildren) };
402
+ }
403
+
404
+ function scanInto(map, root, importPrefix, namePrefix) {
405
+ if (!fs.existsSync(root)) return;
406
+
407
+ const walk = (dir) => {
408
+ let entries;
409
+ try {
410
+ entries = fs.readdirSync(dir, { withFileTypes: true });
411
+ } catch {
412
+ return;
413
+ }
414
+ for (const e of entries) {
415
+ const full = path.join(dir, e.name);
416
+ if (e.isDirectory()) {
417
+ walk(full);
418
+ continue;
419
+ }
420
+ if (!/^index\.(tsx?|jsx?)$/.test(e.name)) continue;
421
+ const rel = full.slice(root.length + 1).replace(/\\/g, '/');
422
+ // <A>/<B>/<Name>/preview/web/index.tsx 或 form/layout/SyncComponents/<Name>/preview/web/index.tsx
423
+ // 编译产物形态是 index.js(组件包按 npm 依赖安装)
424
+ const m = rel.match(/^(.*)\/preview\/web\/index\.(?:tsx?|jsx?)$/);
425
+ if (!m) continue;
426
+ // m[1] 是 `/preview/web/index.tsx` 之前的部分,最后一段就是组件目录名
427
+ const dirName = m[1].split('/').pop();
428
+ const componentName = toComponentName(dirName);
429
+ if (!componentName) continue;
430
+ if (map.has(componentName)) continue;
431
+
432
+ // 组件模块不一定具名导出。有的只 `export default X`(如 Message、
433
+ // PersonalInfo),有的两者都有。按源码判断,避免生成 `import { X }`
434
+ // 后在构建期报 "export 'X' was not found"。
435
+ let src = '';
436
+ try {
437
+ src = fs.readFileSync(full, 'utf8');
438
+ } catch {
439
+ /* 读不到就按具名导出处理 */
440
+ }
441
+ const hasNamedExport = new RegExp(
442
+ `export\\s+(?:const|let|var|function|class)\\s+${componentName}\\b`,
443
+ ).test(src) || new RegExp(`export\\s*\\{[^}]*\\b${componentName}\\b`).test(src);
444
+ const hasDefaultExport = /export\s+default\b/.test(src);
445
+ /**
446
+ * 组件是否读 `props.emit`。
447
+ *
448
+ * 平台上 emit 由渲染器注入(与 inbiz 一样),组件里写的是
449
+ * `props.emit('MenuClick', item)` 这种**非可选**调用 —— 缺了就抛
450
+ * "props.emit is not a function",菜单点击直接失效(点了没反应)。
451
+ * 出码后必须显式传入,值取运行时对象的 emit。
452
+ */
453
+ // 注意:只看入口文件会漏。InbizMenu 的 `props?.emit('MenuClick')`
454
+ // 写在 preview/web/inbiz.tsx(入口的兄弟文件),真正的实现还在
455
+ // core/common/InbizMenu/common.tsx(组件库的共享实现目录)。
456
+ // 所以要扫「组件目录 + 同名共享目录」整棵树。
457
+ const previewSource = collectDirSource(full, dirName);
458
+ /**
459
+ * 插槽识别只看真实代码,注释先剥掉。
460
+ *
461
+ * `collectDirSource` 会把整目录的源码拼起来,`.d.ts` 的 JSDoc 也包含在内。
462
+ * 组件库里有一句注释写着「TableTop 内部按字面量 useSlot('Table.Query') 取值」,
463
+ * 于是 `Table.Query` 被当成 jsxSlots 命中 —— 这是**假阳性**:
464
+ * 全包真实的 useSlot 调用为 0。假阳性的后果不是少内容,而是把一个组件
465
+ * 根本没声明的插槽当成「已声明」,生成 <Slots> 并把子节点搬进一个永远不会
466
+ * 被读取的键里,内容静默丢失。只剥块注释,不动字符串与行注释。
467
+ */
468
+ const webSource = collectDirSource(full, dirName, { webOnly: true })
469
+ .replace(/\/\*[\s\S]*?\*\//g, '');
470
+ /**
471
+ * 用语法树判断「组件是否读 props.emit」,不要用 `/props\.emit\(/` 这类文本正则:
472
+ * 压缩产物会把形参改名(`function(e){e.emit('MenuClick')}`),正则一条都匹配不到,
473
+ * 生成代码就不再注入 `emit={inbiz("...").emit}`,菜单点击直接失效(点了没反应)。
474
+ * `readsPreviewProp` 走的是「引用是否指向某个函数形参」的判定,与参数叫什么无关。
475
+ */
476
+ const usesEmit = previewReadsProp(full, src, componentName, 'emit');
477
+ /**
478
+ * 压缩产物会把导入的符号改名:
479
+ * `import{RenderDropableWidget as t,useSlot as r}from"@inbiz/react";`
480
+ * `…_jsx(t,{node:e.plugin,pluginName:"VerticalMenu.Plugin"})…` / `r("Table.Query")`
481
+ *
482
+ * 所以要先从 import/export 语句里解析出「原始名 → 局部名」的映射,再按局部名
483
+ * 匹配调用点。只认原始标识符时,terser 压缩后的包中所有 widget 型插槽都会
484
+ * 静默消失(VerticalMenu.Plugin 整段丢失,页面少一块内容且不报错)。
485
+ */
486
+ const localNamesOf = (original) => {
487
+ const locals = new Set([original]);
488
+ for (const [, clause] of webSource.matchAll(
489
+ /(?:import|export)\s*\{([^}]*)\}\s*from\s*['"][^'"]+['"]/g,
490
+ )) {
491
+ for (const part of clause.split(',')) {
492
+ const [exported, local] = part.trim().split(/\s+as\s+/);
493
+ if (exported === original && local) locals.add(local.trim());
494
+ }
495
+ }
496
+ return `(?:${[...locals].map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})`;
497
+ };
498
+ const dropableName = localNamesOf('RenderDropableWidget');
499
+ const useSlotName = localNamesOf('useSlot');
500
+
501
+ // A literal useSlot call declares a JSX outlet owned by this preview.
502
+ // 只接受 `宿主.成员` 形态的键,避免把压缩后的单字母局部名误当成插槽声明。
503
+ const jsxSlots = new Set(
504
+ Array.from(webSource.matchAll(new RegExp(
505
+ `(?:^|[^\\w$])${useSlotName}\\s*\\(\\s*['"]([\\w$]+\\.[\\w$]+)['"]\\s*\\)`, 'g')),
506
+ (match) => match[1]),
507
+ );
508
+ const widgetSlots = new Set();
509
+ /**
510
+ * 两种写法都要认:
511
+ * - 源码包:`<RenderDropableWidget pluginName={'Block.Content'} />`(JSX)
512
+ * - 编译包:`_jsx(t, { pluginName: 'Block.Content' })`
513
+ * (babel 的 automatic JSX 运行时把 JSX 变成函数调用,属性成了对象字面量)
514
+ * 只认第一种时,换成 npm 编译产物后所有 JSX 型插槽都会消失,
515
+ * 表现为「页面少了一块内容、构建和运行都不报错」。
516
+ */
517
+ for (const [, quote, name] of webSource.matchAll(
518
+ /<RenderDropableWidget\b[^<>]*?\bpluginName\s*=\s*(?:{\s*)?(['"])([^'"]+)\1/g,
519
+ )) void quote, widgetSlots.add(name);
520
+ // 调用名在编译产物里可能是压缩后的别名(`jsx` 被 import 成 `C`),
521
+ // 所以不能按工厂名匹配:只要求「某个函数调用,第一个参数是 RenderDropableWidget
522
+ // 的本地别名,对象字面量里带 pluginName」。源码包的 JSX 写法由上一条覆盖。
523
+ for (const [, quote, name] of webSource.matchAll(new RegExp(
524
+ `(?:^|[^\\w$])[\\w$]+\\s*\\(\\s*(?:[\\w$]+\\.)?${dropableName}\\s*,\\s*\\{[^{}]*?\\bpluginName\\s*:\\s*(['"])([^'"]+)\\1`, 'gm',
525
+ ))) void quote, widgetSlots.add(name);
526
+ // A component can expose its canonical outlet key as a literal static.
527
+ // Consumers may still use the legacy literal or use that static directly.
528
+ //
529
+ // 源码包写 `slotName: 'X.Y' as const`,编译包已把 `as const` 去掉
530
+ // (纯 TS 语法,babel 会擦除),必须两种都认 —— 否则组件包换成 npm
531
+ // 编译产物后,插槽 key 会退化回字符串字面量,生成代码失去具名导出引用。
532
+ const componentSlots = new Set(Array.from(webSource.matchAll(
533
+ /\bslotName:\s*(['"])([\w$.]+)\1(?:\s+as\s+const)?/g,
534
+ ), ([, , name]) => name).filter((name) => name.startsWith(`${componentName}.`)));
535
+ // 源码包与编译包两种形态都要认:编译后是
536
+ // `_jsx(u,{pluginName:n.slotName})` —— JSX 工厂和宿主标识符都被改名,
537
+ // 只认 JSX 写法时这条判据在压缩产物上永远不命中。
538
+ for (const [, member] of webSource.matchAll(
539
+ /<RenderDropableWidget\b[^<>]*?\bpluginName\s*=\s*\{\s*(?:[\w$]+\.)?([\w$]+)\.slotName\s*\}/g,
540
+ )) {
541
+ const name = `${componentName}.${member}`;
542
+ if (componentSlots.has(name)) widgetSlots.add(name);
543
+ }
544
+ for (const [, member] of webSource.matchAll(new RegExp(
545
+ '[\\w$]+\\s*\\(\\s*(?:[\\w$]+\\.)?' + dropableName
546
+ + '\\s*,\\s*\\{[^{}]*?\\bpluginName\\s*:\\s*(?:[\\w$]+\\.)?([\\w$]+)\\.slotName', 'g',
547
+ ))) {
548
+ const name = `${componentName}.${member}`;
549
+ if (componentSlots.has(name)) widgetSlots.add(name);
550
+ }
551
+ const pluginIdSlots = new Set();
552
+ // Plugin previews insert the package OutId between the host and member.
553
+ // 模板字符串本身在压缩后原样保留,但插值里的标识符会被改名
554
+ // (`${pluginId}` → `${e.pluginId}`),所以插值只认「含 pluginId 字样的表达式」,
555
+ // 同时兼容源码 JSX 与编译后的函数调用两种外壳。
556
+ for (const re of [
557
+ /<RenderDropableWidget\b[^<>]*?\bpluginName\s*=\s*\{\s*`([\w$]+)\$\{pluginId\}\.([\w$]+)`\s*\}/g,
558
+ new RegExp('[\\w$]+\\s*\\(\\s*(?:[\\w$]+\\.)?' + dropableName
559
+ + '\\s*,\\s*\\{[^{}]*?\\bpluginName\\s*:\\s*`([\\w$]+)\\$\\{[^}]*pluginId\\}\\.([\\w$]+)`', 'g'),
560
+ ]) {
561
+ for (const [, host, member] of webSource.matchAll(re)) {
562
+ const name = `${host}.${member}`;
563
+ if (!widgetSlots.has(name)) pluginIdSlots.add(name);
564
+ widgetSlots.add(name);
565
+ }
566
+ }
567
+
568
+ const namedExports = new Set(Array.from(src.matchAll(
569
+ /\bexport\s+(?:(?:const|let|var|function|class)\s+|async\s+function\s+)([\w$]+)/g,
570
+ ), ([, name]) => name));
571
+ for (const [, specifiers] of src.matchAll(/\bexport\s*\{([^}]*)\}/g)) {
572
+ for (const specifier of specifiers.split(',')) {
573
+ const name = specifier.trim().match(/^[\w$]+(?:\s+as\s+([\w$]+))?$/);
574
+ if (name) namedExports.add(name[1] || name[0]);
575
+ }
576
+ }
577
+
578
+ /**
579
+ * 组件是否靠 Formily 的运行时 schema 树找自己的子节点。
580
+ *
581
+ * 典型:`useFieldSchema()` + `schema.mapProperties(...)`(FormSiderLayout、
582
+ * FormTab)。平台上这些子节点存在于运行时 schema 里;出码产物是纯 JSX,
583
+ * 子节点作为 children 传入,组件读 schema 就拿到 undefined 直接崩。
584
+ *
585
+ * 这类组件在 runtime 兼容层有一份「按 children 渲染」的等价实现,
586
+ * 生成代码的 import 直接指向它(见 compat/ 下的同名文件)。
587
+ */
588
+ const schemaDriven = /\bmapProperties\s*\(/.test(src) && /\buseFieldSchema\b/.test(src);
589
+
590
+ // 兼容实现按组件名的 kebab-case 命名:FormSiderLayout → form-sider-layout
591
+ const compatName = componentName
592
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
593
+ .toLowerCase();
594
+ const importPath =
595
+ REQUIRED_COMPAT_CONTAINERS.has(compatName) ||
596
+ (schemaDriven && COMPAT_CONTAINERS.has(compatName))
597
+ ? `@inbiz/containers/${compatName}`
598
+ : importPrefix + '/' + m[1] + '/preview/web';
599
+
600
+ /**
601
+ * 挂在默认导出上的属性组件,例如:
602
+ * MultipleColumnLayout['column'] = (props) => props.children
603
+ * FormGrid.column = ...
604
+ * 它们不是模块的具名导出,schema 里写成 `X.column` / `X.layout`,
605
+ * 生成代码必须写成 `<X.column />`(成员表达式),否则会引用到
606
+ * 不存在的标识符(曾经产生 MultipleColumnLayoutLayout is not defined)。
607
+ */
608
+ const attachedProps = new Set();
609
+ const attachedSource = defaultExportSource(full, src);
610
+ /**
611
+ * 成员挂载在**默认导出的本地绑定**上,不是挂在目录名上。
612
+ *
613
+ * 源码:`ModalDesign.Body = ...` / `export default Object.assign(Block, {...})`
614
+ * 压缩:`p.Body = ...` / `export default Object.assign(c, {...})`
615
+ *
616
+ * terser 只保留导出名,默认导出的本地绑定一律压成单字母。用目录名
617
+ * (ModalDesign / FormGrid / FormTab)去匹配时,产物里一个成员都收不到,
618
+ * 于是 `X.TabPane` / `X.Body` / `X.GridColumn` 被当成「不存在的具名导出」,
619
+ * 生成 `<XTabPane>` 或整份默认导入 —— 页签变嵌套容器、栅格列变整块宿主。
620
+ *
621
+ * 导出名是压缩器保留的契约(`export default p` 里的 p 一定可读),
622
+ * 顺着 `export default` 反推出本地名再匹配才稳定。两种写法都留在候选里,
623
+ * 源码包时期照旧可用。
624
+ */
625
+ const defaultLocal = attachedSource.match(
626
+ /\bexport\s+default\s+(?:Object\.assign\(\s*)?([\w$]+)/,
627
+ )?.[1];
628
+ const attachedNames = [...new Set([componentName, defaultLocal].filter(Boolean))]
629
+ .map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
630
+ .join('|');
631
+ const attachedRe = new RegExp(
632
+ `(?:${attachedNames})\\s*(?:\\[\\s*['"]([\\w$]+)['"]\\s*\\]|\\.([\\w$]+))\\s*=`,
633
+ 'g',
634
+ );
635
+ let am;
636
+ const usesInbiz = previewReadsProp(full, src, componentName, 'inbiz');
637
+ while ((am = attachedRe.exec(attachedSource))) {
638
+ const prop = am[1] || am[2];
639
+ if (prop) attachedProps.add(prop);
640
+ }
641
+ /**
642
+ * Compound previews attach their statics to the exported component:
643
+ *
644
+ * 源码:`export default Object.assign(Block, { LeftExtra, RightExtra, Content })`
645
+ * 编译:`export default Object.assign(c,{LeftExtra:l,RightExtra:d,Content:s})`
646
+ *
647
+ * 两种形态都要认。只匹配简写形态 `{A, B}` 时,编译产物里的值带了冒号和
648
+ * 标识符,整条匹配失败,成员一个都收不到 —— `Block.Content` 这类插槽
649
+ * 于是被判成「没有挂载点」,生成代码退化成把内容当普通 children 塞进去,
650
+ * 页面少一层 `<Block.Content>` 壳子,样式与滚动容器随之丢失。
651
+ */
652
+ const exportedStatics = attachedSource.match(
653
+ /\bexport\s+default\s+Object\.assign\(\s*[\w$]+\s*,\s*\{([^{}]*)\}\s*\)/,
654
+ );
655
+ for (const part of (exportedStatics?.[1] || '').split(',')) {
656
+ // 编译形态是 `Name: identifier`,取冒号前的成员名;简写形态直接就是名字
657
+ const prop = part.split(':')[0].trim();
658
+ if (/^[\w$]+$/.test(prop)) attachedProps.add(prop);
659
+ }
660
+
661
+ map.set(componentName, {
662
+ name: componentName,
663
+ // 平台组件按 npm 包的公开 preview 子路径引入,类型与源码一起解析。
664
+ // 读 schema 的容器改为指向 @inbiz/containers/<kebab>(runtime 兼容实现)。
665
+ importPath,
666
+ // 组件入口的绝对路径:重型判定要顺着源码 import 图往下扫
667
+ absPath: full.replace(/\\/g, '/'),
668
+ hasNamedExport,
669
+ hasDefaultExport,
670
+ ...readPreviewCodegen(full, jsxSlots, widgetSlots, componentSlots),
671
+ usesInbiz,
672
+ usesEmit,
673
+ jsxSlots,
674
+ widgetSlots,
675
+ pluginIdSlots,
676
+ componentSlots,
677
+ namedExports,
678
+ // 挂在默认导出上的属性组件名(如 column / layout)
679
+ attachedProps,
680
+ relPath: rel,
681
+ isSync: rel.includes('/SyncComponents/'),
682
+ });
683
+ }
684
+ };
685
+ walk(root);
686
+ }
687
+
688
+ /** 实例后缀:`$3a098f32ac12a987...`、`$f3f5b77e-e688-4337-...` 两种形态 */
689
+ const INSTANCE_SUFFIX = /\$[0-9a-zA-Z-]+$/;
690
+
691
+ /**
692
+ * 把 schema 里的 x-component 解析成「从哪个模块、取哪个导出」。
693
+ *
694
+ * 名字有三种形态:
695
+ * `Html` → 组件库里的组件目录名
696
+ * `SearchEntry$3a098f32ac12...` → 去掉实例后缀
697
+ * `InbizMenu.Plugin$l3v8gzstq1b` → 宿主模块 InbizMenu 里的另一个导出 Plugin
698
+ *
699
+ * 第三点是关键:`X.Plugin` 不是 X 本身,而是同一模块里的具名导出 `Plugin`
700
+ * (见组件库 webPreview.ts:`export const InbizMenu = ...; export const Plugin = ...`)。
701
+ * 当成 X 会产生 `<InbizMenu>` 套 `<InbizMenu>` 的错误代码。
702
+ *
703
+ * @returns {{ name: string, exportName: string, importPath: string, relPath: string } | null}
704
+ * name 是生成代码里的本地标识符,exportName 是模块里的导出名
705
+ */
706
+ export function resolveComponent(registry, rawName) {
707
+ if (!rawName) return null;
708
+
709
+ const raw = String(rawName).trim();
710
+ const dotAt = raw.indexOf('.');
711
+ const hostPart = dotAt >= 0 ? raw.slice(0, dotAt) : raw;
712
+ const slotPart = dotAt >= 0 ? raw.slice(dotAt + 1) : '';
713
+ const host = hostPart.replace(INSTANCE_SUFFIX, '');
714
+ const slot = slotPart.replace(INSTANCE_SUFFIX, '');
715
+
716
+ let entry = lookup(registry, host);
717
+ // 插件组件没被复制进 iso-custom 时,退到同功能替身。
718
+ // 只对「主体」生效:`Card.Plugin` 这种插槽是宿主模块里的另一个导出,
719
+ // 换掉宿主就取不到它,硬替会把 `.Plugin` 变成不存在的成员。
720
+ let substitution = null;
721
+ if (!entry && !slot && COMPONENT_SUBSTITUTES[host]) {
722
+ const sub = COMPONENT_SUBSTITUTES[host];
723
+ const target = lookup(registry, sub.to);
724
+ if (target) {
725
+ entry = target;
726
+ substitution = {
727
+ from: host,
728
+ to: sub.to,
729
+ accepts: sub.accepts,
730
+ evidence: sub.evidence,
731
+ };
732
+ }
733
+ }
734
+ if (!entry) return null;
735
+
736
+ const slotName = `${entry.name}.${slot}`;
737
+ const usesComponentModule = !entry.importPath?.startsWith('@inbiz/containers/');
738
+ const componentSlot = usesComponentModule && entry.componentSlots?.has(slotName);
739
+ // An explicit named export lets editors follow the symbol directly into its
740
+ // implementation, rather than stopping on a host's compound assignment.
741
+ if (slot && usesComponentModule && entry.namedExports?.has(slot) &&
742
+ (componentSlot || entry.attachedProps?.has(slot))) {
743
+ return {
744
+ ...entry,
745
+ name: entry.name + slot,
746
+ exportName: slot,
747
+ hasNamedExport: true,
748
+ ...(componentSlot ? { componentSlot: slotName } : { compoundMember: true }),
749
+ omitProps: undefined,
750
+ widgetSlots: undefined,
751
+ jsxSlots: undefined,
752
+ };
753
+ }
754
+
755
+ // 1) 挂在默认导出上的属性组件:`X.column` / `X.layout`
756
+ // 生成 `<X.column />`(成员表达式),不是新的标识符。
757
+ if (slot && entry.attachedProps?.has(slot)) {
758
+ return {
759
+ ...entry,
760
+ exportName: entry.name,
761
+ memberAccess: slot,
762
+ omitProps: undefined,
763
+ ...(componentSlot ? { componentSlot: slotName } : {}),
764
+ };
765
+ }
766
+
767
+ // 2) 插槽导出(Plugin / Solt ...),本地标识符要加宿主前缀避免重名
768
+ if (slot) {
769
+ const exportName = slot.charAt(0).toUpperCase() + slot.slice(1);
770
+ return {
771
+ ...entry,
772
+ name: entry.name + exportName,
773
+ exportName,
774
+ ...(entry.namedExports?.has(exportName) ? { hasNamedExport: true } : {}),
775
+ omitProps: undefined,
776
+ widgetSlots: undefined,
777
+ jsxSlots: undefined,
778
+ };
779
+ }
780
+ return { ...entry, exportName: entry.name, ...(substitution ? { substitution } : {}) };
781
+ }