cloud-web-corejs 1.1.0-dev.34 → 1.1.0-dev.36

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 (35) hide show
  1. package/bin/core-resources.js +16 -0
  2. package/docs/child-app/README.md +6 -3
  3. package/docs/child-app/activiti-resources.md +63 -0
  4. package/docs/child-app/generate-prompt.md +7 -1
  5. package/docs/child-app/luckysheet-resources.md +80 -0
  6. package/docs/child-app/public-resources-plan.md +288 -0
  7. package/docs/child-app/resources-implementation.md +101 -0
  8. package/docs/child-app/tinymce-resources.md +88 -0
  9. package/docs/child-app/validation.md +4 -3
  10. package/package.json +10 -2
  11. package/resource-tools/index.js +126 -0
  12. package/src/app-bootstrap.js +7 -2
  13. package/src/components/Tinymce/dynamicLoadScript.js +51 -59
  14. package/src/components/Tinymce/index.vue +382 -339
  15. package/src/components/code-editor/index.vue +361 -343
  16. package/src/components/luckysheet/loadResources.js +64 -0
  17. package/src/components/luckysheet/view.vue +239 -210
  18. package/src/components/onlineTalk/index.vue +2 -2
  19. package/src/components/xform/form-designer/form-widget/field-widget/dropdown-widget.vue +34 -3
  20. package/src/layout/components/Sidebar/default.vue +17 -16
  21. package/src/utils/chunkLoadError.js +24 -0
  22. package/src/utils/featureResources.js +57 -0
  23. package/src/views/bd/setting/form_template/mixins/list.js +7 -6
  24. package/src/views/bd/setting/form_template/mixins/list2.js +412 -411
  25. package/src/views/bd/setting/form_template/mixins/wf_list.js +431 -430
  26. package/src/views/user/form/form_template/list.vue +527 -506
  27. package/src/views/user/wf/wf_manage/wfContentDialog.vue +65 -40
  28. package/src/views/user/wf/wf_obj_config/activiti_wf.vue +134 -133
  29. package/src/views/user/wf/wf_obj_config/list.vue +747 -746
  30. package/src/views/user/wf/wf_obj_config/list_form.vue +374 -373
  31. package/templates/child-app/README.md +2 -0
  32. package/templates/child-app/core-resources.config.js +15 -0
  33. package/templates/child-app/gitignore +1 -0
  34. package/templates/child-app/package.json +5 -0
  35. package/templates/child-app/vue.config.js +2 -1
@@ -0,0 +1,88 @@
1
+ # TinyMCE 可选资源接入
2
+
3
+ 本批沿用现有 TinyMCE 4.9.2,不升级运行库、不删除旧 public,也不把静态资源或新的 TinyMCE 依赖加入 Core 的强制依赖。独立制品暂未发布 registry;使用本地 tarball 验证和交付。
4
+
5
+ ## 来源与体积
6
+
7
+ 逐字节核对原 `public/base/tinymce` 的 86 个文件:
8
+
9
+ | 内容 | 精确来源 | 对比结果 |
10
+ | --- | --- | --- |
11
+ | 主脚本、插件附属文件、lightgray 皮肤 | tinymce-all-in-one@4.9.2 | 40 个文件完全相同 |
12
+ | langs 目录 | tinymce-all-in-one@4.9.5 的 langs(不使用其主脚本) | 46 个文件完全相同 |
13
+ | TinyMCE 原始许可 | tinymce@4.9.2 的 license.txt | 原样随制品保留 |
14
+
15
+ 这个组合不是本次升级造成的;现有仓库本身就是此组合。本地文件有差异或闭包数量变化时,构建脚本会拒绝打包,需要重新审核并修改补丁版本。
16
+
17
+ [上游合并包说明](https://github.com/PanJiaChen/tinymce-all-in-one)说明主脚本已合入插件;因此不能把其余 plugins 目录中没有 plugin.min.js 判断为资源丢失。当前制品保持整个已有闭包,不额外裁剪插件。上游合并包 package.json 声明 MIT;TinyMCE 本体的 LGPL-2.1 声明不能被合并包元数据替代。制品保存官方 LGPL 原文、上游 package.json 信息与来源链接;正式对外发布前仍需审核第三方许可、源码提供与通知义务,本次没有作法律合规认证。
18
+
19
+ 独立制品约 **0.68 MB 压缩 / 2.50 MB 解压**。部署 88 个文件,原始资源共 2,471,058 字节(含两份许可/来源文件)。只提供 `full` profile;关闭 richText 时为 0 个 TinyMCE 文件。Core tarball 不含这批大资源。
20
+
21
+ ## 维护者制作制品
22
+
23
+ 在独立目录安装精确上游版本,不改变 kCode 的依赖声明。例如在 kCode 中:
24
+
25
+ ```bash
26
+ npm install --prefix artifacts/resources/tinymce-source --ignore-scripts --save-exact --no-audit --no-fund tinymce-all-in-one@4.9.2 tinymce-languages@npm:tinymce-all-in-one@4.9.5 tinymce@4.9.2
27
+ npm run build:tinymce-resources -- artifacts/resources/tinymce-source
28
+ ```
29
+
30
+ 产生 `artifacts/resources/cloud-web-corejs-resources-tinymce-4.9.2-core.0.tgz`。保存制品及来源安装目录的 package-lock.json 到团队制品系统;该目录在本工作区被 Git 忽略。构建器不自动联网。原始文件的 SHA-256、目标路径、语言源版本、Core 兼容版本和补丁版本写入 resources.json。
31
+
32
+ ## 子应用启用
33
+
34
+ 先用包含本次修改的 Core tarball 安装/生成应用,再安装 TinyMCE 制品(替换实际路径):
35
+
36
+ ```bash
37
+ npm install --save-dev --save-exact /absolute/path/cloud-web-corejs-resources-tinymce-4.9.2-core.0.tgz
38
+ ```
39
+
40
+ 在已有 `core-resources.config.js` 的 features 中配置,保留其他功能声明:
41
+
42
+ ```js
43
+ richText: {
44
+ package: "cloud-web-corejs-resources-tinymce",
45
+ version: "4.9.2-core.0",
46
+ profile: "full"
47
+ }
48
+ ```
49
+
50
+ ```bash
51
+ npm run resources:prepare
52
+ npm run resources:check
53
+ npm run dev
54
+ npm run build:prod
55
+ ```
56
+
57
+ 旧应用需同步新模板的 ResourcesPlugin、配置和资源准备/校验脚本;不能只加配置文件。应用自有 public 同路径文件会冲突报错,不会被覆盖。未启用却使用组件时显示 richText 缺配置提示;不自动下载安装资源,不改变鉴权和菜单权限。
58
+
59
+ ## 加载与生命周期
60
+
61
+ - 独立运行按 WEB_PREFIX,qiankun 按子应用注入 publicPath 解析主脚本、语言和皮肤地址,显式设置 TinyMCE 的资源基址。
62
+ - 同一应用并发组件共享一次主脚本请求;失败会清理加载状态,组件显示 URL 和重试按钮。HTTP 200 但没有兼容运行库也会失败。
63
+ - 拒绝覆盖不同来源或版本的既存 TinyMCE 全局对象。此保护不是允许多个不同版本共享一个 window 的承诺;多应用同时使用仍需单独验证宿主隔离。
64
+ - 使用组件实际 textarea 作为 target。mounted/activated 去重,卸载或停用后忽略过期回调,只移除本组件编辑器;已加载脚本保留供同应用复用。
65
+ - 包装组件沿用 en/zh/es/ja 映射;其他应用 locale 回退 en。资源保留全部原始语言,但没有扩展应用 i18n 的业务语言体系。
66
+ - `getContent()` 现在返回内容,实例不存在时返回空串;setContent 在销毁后安全跳过。
67
+ - 本批不改既有上传业务接口,也没有验证上传、拼写服务、全部插件组合或生产 CSP。保留旧版本不等于安全升级;正式上线应另行安排版本和安全评估。
68
+
69
+ ## 验证
70
+
71
+ ```bash
72
+ npm run check:resource-tools
73
+ TINYMCE_SOURCE_DIR=/absolute/path/to/upstream-install node build/check-child-app.js --ace --tinymce
74
+ PLAYWRIGHT_MODULE=/absolute/path/to/playwright node build/check-child-browser.js /generated/child --ace --tinymce
75
+ ```
76
+
77
+ 自动测试覆盖 Ace/TinyMCE 组合及独立关闭、第二个功能空清单、加载去重、失败后重试、异源全局拒绝、停用/销毁后的过期回调、资源地址、生产字节完整性等。浏览器脚本覆盖双编辑器、输入/v-model、中文代码插件弹窗、关闭重开、子应用卸载,并同时回归 Ace worker。
78
+
79
+ ## 验收记录(2026-09-15)
80
+
81
+ - 15 项自动测试通过;包括普通入口/详情入口在子组件渲染前注册根实例的两项回归。实际浏览器发现 `$t2` 在首帧读取尚未注册的 `$vueRoot`,已通过提前注册根实例修复,没有用测试桩绕过翻译函数。
82
+ - 新目录安装真实 Core/Ace/TinyMCE tarball,生产构建通过。发现并修复启动顺序问题后重新打包、安装 Core 并构建,最终 105 个文件 / 3,696,063 字节的输出哈希检查通过。
83
+ - 最终产物经真实跨域 qiankun + Chromium 验证:双编辑器、输入/v-model、中文源代码弹窗、关闭重开、卸载全部通过。主脚本仅一次请求,语言/皮肤从子应用目录加载;页面异常、控制台错误和静态资源缺失均为零。
84
+ - 同时回归独立登录页、普通挂载/update/卸载、私有示例列表及 Ace JSON worker 和卸载终止。独立登录页验证不等于独立入口的富文本业务流程验收;独立资源 URL 另有自动测试。
85
+ - 仍有 273 条构建警告,主要为既有 Vue 2 样式默认导出等;未运行完整历史 test:ci,未验收真实账号、上传/拼写服务、全部插件语言组合、生产 CSP 或多个不同子应用同时使用 TinyMCE。
86
+ - 日志、来源锁文件和截图保存在 Git 忽略的 `artifacts/resources/validation-tinymce/`。本轮未修改旧 public、std,未提交、推送或发布 npm。
87
+
88
+ P2 的 TinyMCE 子项已完成上述接入与验收。Luckysheet 和 Activiti 已在后续批次接入;P3 的运行依赖和业务代码拆分尚未实施。
@@ -1,10 +1,10 @@
1
1
  # 子应用模板验收记录
2
2
 
3
- 日期:2026-09-15。环境:Node 22.23.2、npm 10.9.8、Chromium;Core 源码版本标识为 1.1.0-dev.27,使用当前工作区 npm pack 产物,未发布到 npm。
3
+ 日期:2026-09-15。环境:Node 22.23.2、npm 10.9.8、Chromium;Core 源码版本标识为 1.1.0-dev.33,使用当前工作区 npm pack 产物,未发布到 npm。
4
4
 
5
5
  ## 已通过
6
6
 
7
- - Core 资源边界:1223 个发布源码文件、104 个 Core SVG。
7
+ - Core 资源边界:1225 个发布源码文件、104 个 Core SVG。
8
8
  - 发布清单:包含生成器、模板 `.env`、应用文件/素材和提示词,不依赖 std 工作区。
9
9
  - 生成器:拒绝覆盖已有工程,拒绝非法/保留 appCode。
10
10
  - 从 tarball 解包后运行生成器,在仓库外干净安装;生产构建退出码 0,产物约 19 MB。
@@ -14,6 +14,7 @@
14
14
  - 真实 qiankun:两个本地端口跨源加载,未登录态 mount/update/unmount 成功。
15
15
  - 详情承载:私有 `/demo/list` 页面加载成功,内存示例新增/编辑/筛选正常,应用图标可见,URL 未改变,卸载后清空。
16
16
  - 上述生产浏览器用例无 pageerror、无业务静态资源 404;登录及列表截图已人工查看。
17
+ - Activiti 5.17:独立资源制品 324 个文件,默认模板关闭;从 Core tarball 生成的新应用安装制品后生产构建成功。同源浏览器实际加载设计器、stencil 和模型,并验证保存 POST;发现并修复官方 WAR 同样缺失的 `glasspane.png` 引用后无静态资源 404。
17
18
  - `git diff --check` 与新增 Node 脚本语法检查。
18
19
 
19
20
  ## 本轮处理的问题
@@ -27,7 +28,7 @@
27
28
 
28
29
  - 生产构建仍有 273 个警告,主要为 Vue 2 SFC 样式默认导出兼容警告、旧 CSS 语法和资源体积提示;开发构建有 272 个警告。没有隐藏这些警告。所测页面表现正常不代表所有包内页面均已验收。
29
30
  - 最小化的是应用侧文件与接入配置,不是裁剪后的 Core 能力包。开发同步视图上下文仍较大,初次编译需要时间。
30
- - 未验证真实登录、授权菜单派发、已登录页面保活/刷新、业务 API、上传/工作流/打印及并发远程详情实例。
31
+ - 未验证真实登录、授权菜单派发、已登录页面保活/刷新、真实 Activiti 业务后端、上传/打印及并发远程详情实例。
31
32
  - Ace、TinyMCE、Luckysheet、Activiti 等可选静态资源没有包含在模板中,按接入文档按需补齐。
32
33
 
33
34
  重复执行入口:`npm run check:child-app`、`npm run check:child-browser -- <已构建的子应用目录>`。后者需要 Playwright/Chromium,详见接入契约。
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.1.0-dev.34",
4
+ "version": "1.1.0-dev.36",
5
5
  "scripts": {
6
+ "build:ace-resources": "node build/build-ace-resources.js",
7
+ "build:tinymce-resources": "node build/build-tinymce-resources.js",
8
+ "build:luckysheet-resources": "node build/build-luckysheet-resources.js",
9
+ "build:activiti-resources": "node build/build-activiti-resources.js",
10
+ "check:resource-tools": "node --test tests/resources/*.test.js",
11
+ "check:package-size": "node build/check-package-size.js",
6
12
  "create:child": "node bin/create-child-app.js",
7
13
  "check:child-app": "node build/check-child-app.js",
8
14
  "check:child-browser": "node build/check-child-browser.js",
@@ -18,7 +24,7 @@
18
24
  "new": "plop",
19
25
  "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml",
20
26
  "test:unit": "jest --clearCache && vue-cli-service test:unit",
21
- "test:ci": "npm run check:package-resources && npm run check:minimal-consumer && npm run lint && npm run test:unit",
27
+ "test:ci": "npm run check:resource-tools && npm run check:package-resources && npm run check:package-size && npm run check:minimal-consumer && npm run lint && npm run test:unit",
22
28
  "updateCorejs": "npm install cloud-web-corejs --registry https://registry.npmjs.org",
23
29
  "publishDev": "npm publish --tag dev"
24
30
  },
@@ -128,6 +134,8 @@
128
134
  "npm": ">= 3.0.0"
129
135
  },
130
136
  "files": [
137
+ "bin/core-resources.js",
138
+ "resource-tools",
131
139
  "bin/create-child-app.js",
132
140
  "templates/child-app",
133
141
  "docs/child-app",
@@ -0,0 +1,126 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const crypto = require("crypto");
4
+ const hash = data => crypto.createHash("sha256").update(data).digest("hex");
5
+ const fail = message => { throw new Error(`[core-resources] ${message}`); };
6
+ function safePath(root, relative) {
7
+ if (typeof relative !== "string" || !relative || relative.includes("\\") ||
8
+ relative.split("/").some(p => !p || p === "." || p === "..") || path.isAbsolute(relative)) {
9
+ fail(`Unsafe path: ${relative}`);
10
+ }
11
+ const full = path.join(root, relative);
12
+ // Reject symlinks in every existing ancestor, including the destination root.
13
+ for (let current = full; ; current = path.dirname(current)) {
14
+ if (fs.existsSync(current) || (() => { try { return fs.lstatSync(current).isSymbolicLink(); } catch (_) { return false; } })()) {
15
+ if (fs.lstatSync(current).isSymbolicLink()) fail(`Symlink: ${current}`);
16
+ }
17
+ if (path.dirname(current) === current) break;
18
+ }
19
+ return full;
20
+ }
21
+ function readChecked(root, record, key = "file") {
22
+ const full = safePath(root, record[key]);
23
+ if (!fs.existsSync(full) || !fs.statSync(full).isFile()) fail(`Missing file: ${full}`);
24
+ const data = fs.readFileSync(full);
25
+ if (data.length !== record.size || hash(data) !== record.sha256) fail(`Integrity mismatch: ${full}`);
26
+ return data;
27
+ }
28
+ function assertExactTree(root, expected) {
29
+ const found = [];
30
+ function walk(directory, prefix = "") {
31
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
32
+ const relative = prefix + entry.name;
33
+ const full = safePath(root, relative);
34
+ if (entry.isDirectory()) walk(full, relative + "/");
35
+ else if (entry.isFile()) found.push(relative);
36
+ else fail(`Unsupported generated entry: ${relative}`);
37
+ }
38
+ }
39
+ walk(root);
40
+ if (JSON.stringify(found.sort()) !== JSON.stringify([...expected].sort())) fail(`Unexpected generated files: ${root}`);
41
+ }
42
+ function plan(root) {
43
+ const configPath = path.join(root, "core-resources.config.js");
44
+ delete require.cache[configPath];
45
+ const config = require(configPath);
46
+ if (config.schemaVersion !== 1) fail("Unsupported config schemaVersion");
47
+ const runtime = { schemaVersion: 1, features: {} };
48
+ const records = [];
49
+ for (const [feature, option] of Object.entries(config.features || {})) {
50
+ if (!["codeEditor", "richText", "spreadsheet", "workflowDesigner"].includes(feature)) fail(`Unknown feature: ${feature}`);
51
+ if (option === false) continue;
52
+ const upstreamVersions = { codeEditor: "1.11.0", richText: "4.9.2", spreadsheet: "2.1.13", workflowDesigner: "5.17.0" };
53
+ if (!option || typeof option !== "object" || !option.package || !option.version) fail(`${feature}: package/version/profile required`);
54
+ const packageRoot = path.dirname(require.resolve(`${option.package}/package.json`, { paths: [root] }));
55
+ const pkg = JSON.parse(fs.readFileSync(safePath(packageRoot, "package.json")));
56
+ const manifest = JSON.parse(fs.readFileSync(safePath(packageRoot, "resources.json")));
57
+ const coreVersion = require("../package.json").version;
58
+ if (pkg.version !== option.version || manifest.version !== option.version || manifest.schemaVersion !== 1 ||
59
+ manifest.feature !== feature || manifest.compatibleCore !== coreVersion || manifest.upstreamVersion !== upstreamVersions[feature]) {
60
+ fail(`${feature}: incompatible artifact, expected exact version ${option.version} / Core ${coreVersion}`);
61
+ }
62
+ const profile = manifest.profiles[option.profile];
63
+ if (!profile) fail(`${feature}: unknown profile ${option.profile}`);
64
+ safePath(root, manifest.basePath.replace(/\/$/, ""));
65
+ runtime.features[feature] = { version: option.version, profile: option.profile, modes: profile.modes, locales: profile.locales, basePath: manifest.basePath };
66
+ const featureStart = records.length;
67
+ for (const record of manifest.files) {
68
+ // Validate even unselected records, so malformed manifests never pass silently.
69
+ safePath(packageRoot, record.file);
70
+ safePath(root, record.target);
71
+ if (!record.profiles.includes(option.profile)) continue;
72
+ if (records.some(r => r.target === record.target)) fail(`Duplicate target: ${record.target}`);
73
+ const appPath = safePath(path.join(root, "public"), record.target);
74
+ if (fs.existsSync(appPath)) fail(`Application public collision: ${record.target}`);
75
+ records.push({ ...record, data: readChecked(packageRoot, record) });
76
+ }
77
+ if (records.length === featureStart) fail(`${feature}: empty artifact`);
78
+ }
79
+ const snapshot = { runtime, files: records.map(({ target, size, sha256 }) => ({ target, size, sha256 })) };
80
+ return { runtime, records, snapshot, id: hash(JSON.stringify(snapshot)) };
81
+ }
82
+ function prepare(root, checkOnly = false) {
83
+ root = path.resolve(root);
84
+ const result = plan(root);
85
+ const generations = safePath(root, ".core-resources/generations");
86
+ const destination = safePath(generations, result.id);
87
+ if (!fs.existsSync(destination)) {
88
+ if (checkOnly) fail("Resources not prepared; run resources:prepare");
89
+ fs.mkdirSync(generations, { recursive: true });
90
+ const staging = fs.mkdtempSync(path.join(generations, ".stage-"));
91
+ fs.mkdirSync(path.join(staging, "public"));
92
+ for (const record of result.records) {
93
+ const target = safePath(path.join(staging, "public"), record.target);
94
+ fs.mkdirSync(path.dirname(target), { recursive: true });
95
+ fs.writeFileSync(target, record.data, { flag: "wx" });
96
+ }
97
+ fs.writeFileSync(path.join(staging, "ownership.json"), JSON.stringify(result.snapshot));
98
+ fs.renameSync(staging, destination);
99
+ }
100
+ const ownership = safePath(destination, "ownership.json");
101
+ if (fs.readFileSync(ownership, "utf8") !== JSON.stringify(result.snapshot)) fail(`Modified ownership: ${destination}`);
102
+ const directory = safePath(destination, "public");
103
+ assertExactTree(destination, ["ownership.json", ...result.records.map(r => "public/" + r.target)]);
104
+ for (const record of result.records) readChecked(directory, record, "target");
105
+ return { ...result, directory };
106
+ }
107
+ class ResourcesPlugin {
108
+ constructor(root) { this.root = root; }
109
+ apply(compiler) {
110
+ const prepared = prepare(this.root, true);
111
+ new compiler.webpack.DefinePlugin({ __CORE_RESOURCES__: JSON.stringify(prepared.runtime) }).apply(compiler);
112
+ compiler.hooks.thisCompilation.tap("CoreResources", compilation => {
113
+ compilation.hooks.processAssets.tap({ name: "CoreResources", stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS }, () => {
114
+ const current = prepare(this.root, true);
115
+ if (current.id !== prepared.id) fail("Configuration changed; restart dev/build");
116
+ for (const record of current.records) {
117
+ if (compilation.getAsset(record.target)) fail(`Build asset collision: ${record.target}`);
118
+ // Vendor artifacts are already minified and hash-locked. Terser must
119
+ // not rewrite them (or extract license comments into another file).
120
+ compilation.emitAsset(record.target, new compiler.webpack.sources.RawSource(record.data), { minimized: true });
121
+ }
122
+ });
123
+ });
124
+ }
125
+ }
126
+ module.exports = { prepare, plan, safePath, readChecked, ResourcesPlugin };
@@ -306,8 +306,11 @@ function render(props = {}) {
306
306
  store,
307
307
  i18n,
308
308
  render: (h) => h(App),
309
- }).$mount(container ? container.querySelector("#app") : "#app");
309
+ });
310
+ // Synchronous child renders may call global helpers such as $t2.
311
+ // Publish the initialized root before mounting any child component.
310
312
  window.$vueRoot = instance;
313
+ instance.$mount(container ? container.querySelector("#app") : "#app");
311
314
  }
312
315
 
313
316
  /**
@@ -369,7 +372,9 @@ async function mountDetailHost(props = {}) {
369
372
  },
370
373
  });
371
374
  },
372
- }).$mount(mountEl);
375
+ });
376
+ window.$vueRoot = instance;
377
+ instance.$mount(mountEl);
373
378
  // #4 listeners 透传:详情页里父级 v-on="listeners" 那批是详情页直接 this.$emit 的,
374
379
  // 拦截根子组件的 $emit,任意事件都转发给主应用的 onEmit(按名字派回原 option.on)。
375
380
  const child = instance.$children && instance.$children[0];
@@ -1,59 +1,51 @@
1
- let callbacks = []
2
-
3
- function loadedTinymce() {
4
- // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2144
5
- // check is successfully downloaded script
6
- return window.tinymce
7
- }
8
-
9
- const dynamicLoadScript = (src, callback) => {
10
- const existingScript = document.getElementById(src)
11
- const cb = callback || function() {}
12
-
13
- if (!existingScript) {
14
- const script = document.createElement('script')
15
- script.src = src // src url for the third-party library being loaded.
16
- script.id = src
17
- document.body.appendChild(script)
18
- callbacks.push(cb)
19
- const onEnd = 'onload' in script ? stdOnEnd : ieOnEnd
20
- onEnd(script)
21
- }
22
-
23
- if (existingScript && cb) {
24
- if (loadedTinymce()) {
25
- cb(null, existingScript)
26
- } else {
27
- callbacks.push(cb)
28
- }
29
- }
30
-
31
- function stdOnEnd(script) {
32
- script.onload = function() {
33
- // this.onload = null here is necessary
34
- // because even IE9 works not like others
35
- this.onerror = this.onload = null
36
- for (const cb of callbacks) {
37
- cb(null, script)
38
- }
39
- callbacks = null
40
- }
41
- script.onerror = function() {
42
- this.onerror = this.onload = null
43
- cb(new Error('Failed to load ' + src), script)
44
- }
45
- }
46
-
47
- function ieOnEnd(script) {
48
- script.onreadystatechange = function() {
49
- if (this.readyState !== 'complete' && this.readyState !== 'loaded') return
50
- this.onreadystatechange = null
51
- for (const cb of callbacks) {
52
- cb(null, script) // there is no way to catch loading errors in IE8
53
- }
54
- callbacks = null
55
- }
56
- }
57
- }
58
-
59
- export default dynamicLoadScript
1
+ // Requests are shared only within this application's module scope.
2
+ const pending = new Map();
3
+ let loadedSource = "";
4
+
5
+ export function loadTinymce(src) {
6
+ if (pending.has(src)) return pending.get(src);
7
+ if (window.tinymce) {
8
+ const expectedBase = new URL(".", src).href.replace(/\/$/, "");
9
+ const actualBase = new URL(window.tinymce.baseURL || "/", window.location.href).href.replace(/\/$/, "");
10
+ if (String(window.tinymce.majorVersion) !== "4" || String(window.tinymce.minorVersion) !== "9.2"
11
+ || (loadedSource !== src && actualBase !== expectedBase)) {
12
+ return Promise.reject(new Error(`TinyMCE 已存在不同版本或来源的全局实例,拒绝覆盖:${src}`));
13
+ }
14
+ return Promise.resolve(window.tinymce);
15
+ }
16
+ const promise = new Promise((resolve, reject) => {
17
+ const script = document.createElement("script");
18
+ script.src = src;
19
+ script.dataset.coreResource = "richText";
20
+ let settled = false;
21
+ const timer = setTimeout(() => finish(new Error(`TinyMCE 加载超时:${src}`)), 30000);
22
+ function finish(error) {
23
+ if (settled) return;
24
+ settled = true;
25
+ clearTimeout(timer);
26
+ script.onload = script.onerror = null;
27
+ if (error) {
28
+ if (script.parentNode) script.parentNode.removeChild(script);
29
+ reject(error);
30
+ } else {
31
+ loadedSource = src;
32
+ resolve(window.tinymce);
33
+ }
34
+ }
35
+ script.onload = () => {
36
+ if (!window.tinymce || String(window.tinymce.majorVersion) !== "4" || String(window.tinymce.minorVersion) !== "9.2") {
37
+ finish(new Error(`TinyMCE 脚本未提供兼容的 4.9.2 实例:${src}`));
38
+ } else finish();
39
+ };
40
+ script.onerror = () => finish(new Error(`TinyMCE 加载失败:${src}`));
41
+ document.body.appendChild(script);
42
+ });
43
+ pending.set(src, promise);
44
+ const clear = () => pending.delete(src);
45
+ promise.then(clear, clear);
46
+ return promise;
47
+ }
48
+
49
+ export default function load(src, callback) {
50
+ loadTinymce(src).then(() => callback(null), error => callback(error));
51
+ }