@steedos-widgets/antd 6.10.45 → 6.10.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/dist/antd.umd.js CHANGED
@@ -307,11 +307,16 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
307
307
  // --- 组件实现 ---
308
308
  var LiquidComponent = function LiquidComponent(_a) {
309
309
  var template = _a.template,
310
+ tpl = _a.tpl,
310
311
  data = _a.data,
311
312
  className = _a.className,
312
313
  $schema = _a.$schema,
313
314
  amisRender = _a.render,
314
315
  propsPartials = _a.partials;
316
+ // 支持 tpl 作为 template 的别名
317
+ if (tpl && !template) {
318
+ template = tpl;
319
+ }
315
320
  var _b = __read(React.useState(''), 2),
316
321
  html = _b[0],
317
322
  setHtml = _b[1];
@@ -468,62 +473,111 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
468
473
  });
469
474
  }, [mountNodes, partialsFingerprint, dataFingerprint, amisRender, data]);
470
475
  // ==================================================================================
471
- // 5. 核心逻辑:执行脚本 (新增功能)
476
+ // 5. 核心逻辑:顺序加载器 (等待外部脚本加载完再执行内联脚本)
472
477
  // ==================================================================================
473
478
  React.useEffect(function () {
474
479
  if (!containerRef.current) return;
475
- // 1. 先清理上一次执行留下的副作用(如果有返回清理函数)
480
+ // 清理旧副作用
476
481
  scriptCleanupsRef.current.forEach(function (cleanup) {
477
482
  return cleanup && cleanup();
478
483
  });
479
484
  scriptCleanupsRef.current = [];
480
- // 2. 查找容器内所有的 script 标签
481
- var scripts = containerRef.current.querySelectorAll('script');
482
- scripts.forEach(function (scriptNode) {
483
- var _a;
484
- // 防止重复执行 (虽然每次 html 变动都会重置 DOM,但加上标记更保险)
485
- if (scriptNode.dataset.executed) return;
486
- var code = scriptNode.innerHTML;
487
- if (!code) return;
488
- try {
489
- // --- 构造沙箱环境 ---
490
- // 赋予脚本唯一名字,方便在 Chrome DevTools -> Sources -> Page 面板中调试
491
- // 格式: steedos-script-{随机ID}.js
492
- var debugName = "steedos-liquid-".concat(Math.random().toString(36).slice(2), ".js");
493
- var debuggableCode = code + "\n//# sourceURL=".concat(debugName);
494
- // 构造函数
495
- // 参数1: context (数据域)
496
- // 参数2: dom (当前 script 的父节点,方便局部操作 DOM)
497
- // 参数3: React/Amis 工具 (可选)
498
- var func = new Function('context', 'dom', debuggableCode);
499
- // --- 执行 ---
500
- // 我们将 data 传入,脚本里可以直接用 `context.user.name` 访问
501
- // 我们将 scriptNode.parentElement 传入,脚本可以用 `dom.style.color = 'red'` 操作局部
502
- var cleanupResult = func(data, scriptNode.parentElement);
503
- // 如果脚本返回了一个函数,我们把它作为 cleanup 函数保存
504
- if (typeof cleanupResult === 'function') {
505
- scriptCleanupsRef.current.push(cleanupResult);
485
+ var allScriptNodes = Array.from(containerRef.current.querySelectorAll('script'));
486
+ // 如果没有脚本,直接返回
487
+ if (allScriptNodes.length === 0) return;
488
+ // 1. 分类:找出需要加载的外部脚本 和 需要执行的内联脚本
489
+ var externalNodes = [];
490
+ var inlineNodes = [];
491
+ allScriptNodes.forEach(function (node) {
492
+ if (node.dataset.executed) return; // 跳过已处理的
493
+ if (node.src) {
494
+ externalNodes.push(node);
495
+ } else {
496
+ inlineNodes.push(node);
497
+ }
498
+ });
499
+ // 2. 定义加载外部脚本的函数(返回 Promise)
500
+ var loadExternalScript = function loadExternalScript(scriptNode) {
501
+ return new Promise(function (resolve) {
502
+ var src = scriptNode.getAttribute('src');
503
+ if (!src) {
504
+ resolve();
505
+ return;
506
+ }
507
+ var newScriptUrl = new URL(src, window.location.href).href;
508
+ // --- 查重逻辑:检查全局是否已存在该脚本(排除自身) ---
509
+ var isGlobalLoaded = false;
510
+ var allDocScripts = document.getElementsByTagName('script');
511
+ for (var i = 0; i < allDocScripts.length; i++) {
512
+ var s = allDocScripts[i];
513
+ if (s.src === newScriptUrl && s !== scriptNode) {
514
+ isGlobalLoaded = true;
515
+ break;
516
+ }
506
517
  }
507
- // 标记已执行
518
+ // 标记当前节点已处理,防止下次 render 重复
508
519
  scriptNode.dataset.executed = "true";
509
- } catch (err) {
510
- console.error("Liquid Script Execution Error:", err);
511
- console.warn("Faulty Script:", code);
512
- // 可选:在页面上显式报错
513
- var errorDiv = document.createElement('div');
514
- errorDiv.style.color = 'red';
515
- errorDiv.style.fontSize = '12px';
516
- errorDiv.innerText = "Script Error: ".concat(err.message);
517
- (_a = scriptNode.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(errorDiv, scriptNode.nextSibling);
518
- }
520
+ if (isGlobalLoaded) {
521
+ console.log("[Liquid] Script already loaded: ".concat(src));
522
+ resolve(); // 已存在,直接视为成功
523
+ return;
524
+ }
525
+ // --- 创建新脚本加载 ---
526
+ var newScript = document.createElement('script');
527
+ newScript.src = src;
528
+ newScript.async = false; // 尝试保持顺序,虽然动态插入通常默认 async
529
+ // 复制属性
530
+ Array.from(scriptNode.attributes).forEach(function (attr) {
531
+ if (attr.name !== 'src' && attr.name !== 'data-executed') {
532
+ newScript.setAttribute(attr.name, attr.value);
533
+ }
534
+ });
535
+ newScript.onload = function () {
536
+ console.log("[Liquid] Loaded: ".concat(src));
537
+ resolve();
538
+ };
539
+ newScript.onerror = function () {
540
+ console.error("[Liquid] Failed to load: ".concat(src));
541
+ // 即使失败也 resolve,避免阻塞后续内联脚本执行(或者你可以选择 reject 来阻断)
542
+ resolve();
543
+ };
544
+ document.body.appendChild(newScript);
545
+ });
546
+ };
547
+ // 3. 定义执行内联脚本的函数
548
+ var runInlineScripts = function runInlineScripts() {
549
+ inlineNodes.forEach(function (scriptNode) {
550
+ // 双重检查,防止重入
551
+ if (scriptNode.dataset.executed) return;
552
+ var code = scriptNode.innerHTML;
553
+ if (code) {
554
+ try {
555
+ var debugName = "steedos-liquid-".concat(Math.random().toString(36).slice(2), ".js");
556
+ var debuggableCode = code + "\n//# sourceURL=".concat(debugName);
557
+ var func = new Function('data', 'dom', debuggableCode);
558
+ var cleanupResult = func(data, scriptNode.parentElement);
559
+ if (typeof cleanupResult === 'function') {
560
+ scriptCleanupsRef.current.push(cleanupResult);
561
+ }
562
+ } catch (err) {
563
+ console.error("[Liquid] Inline Script Error:", err);
564
+ }
565
+ }
566
+ scriptNode.dataset.executed = "true";
567
+ });
568
+ };
569
+ // 4. 执行流程:先并行加载所有外部脚本 -> 全部完成后 -> 执行内联脚本
570
+ var loadingPromises = externalNodes.map(loadExternalScript);
571
+ Promise.all(loadingPromises).then(function () {
572
+ // 所有外部脚本(src)都已加载完毕(或失败),现在执行内联代码
573
+ runInlineScripts();
519
574
  });
520
- // 组件卸载时清理
521
575
  return function () {
522
576
  scriptCleanupsRef.current.forEach(function (cleanup) {
523
577
  return cleanup && cleanup();
524
578
  });
525
579
  };
526
- }, [html, dataFingerprint]); // 当 HTML 结构变化或数据变化时,重新扫描执行
580
+ }, [html, dataFingerprint]);
527
581
  return React__default["default"].createElement("div", {
528
582
  className: "liquid-amis-container ".concat(className || ''),
529
583
  ref: containerRef
@@ -21,6 +21,13 @@
21
21
  ],
22
22
  "library": "liquidjs"
23
23
  },
24
+ {
25
+ "package": "sortablejs",
26
+ "urls": [
27
+ "http://127.0.0.1:8080/sortablejs@1.15.6/Sortable.min.js"
28
+ ],
29
+ "library": "Sortable"
30
+ },
24
31
  {
25
32
  "package": "@steedos-widgets/antd",
26
33
  "urls": [
package/dist/assets.json CHANGED
@@ -21,11 +21,18 @@
21
21
  ],
22
22
  "library": "liquidjs"
23
23
  },
24
+ {
25
+ "package": "sortablejs",
26
+ "urls": [
27
+ "https://unpkg.com/sortablejs@1.15.6/Sortable.min.js"
28
+ ],
29
+ "library": "Sortable"
30
+ },
24
31
  {
25
32
  "package": "@steedos-widgets/antd",
26
33
  "urls": [
27
- "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/antd.umd.js",
28
- "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/antd.umd.css"
34
+ "https://unpkg.com/@steedos-widgets/antd@6.10.47/dist/antd.umd.js",
35
+ "https://unpkg.com/@steedos-widgets/antd@6.10.47/dist/antd.umd.css"
29
36
  ],
30
37
  "library": "BuilderAntd"
31
38
  }
@@ -36,10 +43,10 @@
36
43
  "npm": {
37
44
  "package": "@steedos-widgets/antd"
38
45
  },
39
- "url": "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/meta.js",
46
+ "url": "https://unpkg.com/@steedos-widgets/antd@6.10.47/dist/meta.js",
40
47
  "urls": {
41
- "default": "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/meta.js",
42
- "design": "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/meta.js"
48
+ "default": "https://unpkg.com/@steedos-widgets/antd@6.10.47/dist/meta.js",
49
+ "design": "https://unpkg.com/@steedos-widgets/antd@6.10.47/dist/meta.js"
43
50
  }
44
51
  }
45
52
  ]
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  type SchemaObject = Record<string, any>;
3
3
  interface LiquidTemplateProps {
4
4
  template: string;
5
+ tpl: string;
5
6
  data: Record<string, any>;
6
7
  $schema?: Record<string, string | object>;
7
8
  partials?: Record<string, string | object>;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  type SchemaObject = Record<string, any>;
3
3
  interface LiquidTemplateProps {
4
4
  template: string;
5
+ tpl: string;
5
6
  data: Record<string, any>;
6
7
  $schema?: Record<string, string | object>;
7
8
  partials?: Record<string, string | object>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@steedos-widgets/antd",
3
3
  "private": false,
4
- "version": "6.10.45",
4
+ "version": "6.10.47",
5
5
  "main": "dist/antd.cjs.js",
6
6
  "module": "dist/antd.esm.js",
7
7
  "unpkg": "dist/antd.umd.js",
@@ -47,7 +47,7 @@
47
47
  "rollup-plugin-tslib-resolve-id": "^0.0.0",
48
48
  "rollup-plugin-visualizer": "^5.8.0"
49
49
  },
50
- "gitHead": "2b9a57e8e07ab9d3027d6efc6c52c50467422991",
50
+ "gitHead": "77e89d92cc0eed66fb50098dac63845633b1adbb",
51
51
  "dependencies": {
52
52
  "liquidjs": "^10.24.0"
53
53
  }