@steedos-widgets/antd 6.10.52-beta.3 → 6.10.52-beta.30

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
@@ -1,7 +1,7 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  (function (global, factory) {
3
- (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('antd'), require('react-dom'), require('liquidjs')) : typeof define === 'function' && define.amd ? define(['exports', 'react', 'antd', 'react-dom', 'liquidjs'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BuilderAntd = {}, global.React, global.antd, global.ReactDOM, global.liquidjs));
4
- })(this, function (exports, React, antd, reactDom, liquidjs) {
3
+ (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('antd'), require('react-dom'), require('liquidjs'), require('lodash')) : typeof define === 'function' && define.amd ? define(['exports', 'react', 'antd', 'react-dom', 'liquidjs', 'lodash'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BuilderAntd = {}, global.React, global.antd, global.ReactDOM, global.liquidjs, global._));
4
+ })(this, function (exports, React, antd, reactDom, liquidjs, lodash) {
5
5
  var global = window;
6
6
  function _interopDefaultLegacy(e) {
7
7
  return e && _typeof(e) === 'object' && 'default' in e ? e : {
@@ -22,7 +22,26 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
22
22
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
23
  PERFORMANCE OF THIS SOFTWARE.
24
24
  ***************************************************************************** */
25
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
25
26
 
27
+ var _extendStatics = function extendStatics(d, b) {
28
+ _extendStatics = Object.setPrototypeOf || {
29
+ __proto__: []
30
+ } instanceof Array && function (d, b) {
31
+ d.__proto__ = b;
32
+ } || function (d, b) {
33
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
34
+ };
35
+ return _extendStatics(d, b);
36
+ };
37
+ function __extends(d, b) {
38
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
39
+ _extendStatics(d, b);
40
+ function __() {
41
+ this.constructor = d;
42
+ }
43
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
44
+ }
26
45
  var _assign = function __assign() {
27
46
  _assign = Object.assign || function __assign(t) {
28
47
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -297,6 +316,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
297
316
  try {
298
317
  return JSON.parse(cleanStr);
299
318
  } catch (e) {
319
+ console.error(e, cleanStr);
300
320
  try {
301
321
  return new Function("return " + cleanStr)();
302
322
  } catch (e2) {
@@ -341,29 +361,174 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
341
361
  return flattened;
342
362
  }
343
363
  // --- 组件实现 ---
344
- var LiquidComponent = function LiquidComponent(_a) {
345
- var _b;
346
- var template = _a.template,
347
- tpl = _a.tpl,
348
- data = _a.data,
349
- className = _a.className,
350
- $schema = _a.$schema,
351
- amisRender = _a.render,
352
- dispatchEvent = _a.dispatchEvent,
353
- propsPartials = _a.partials;
354
- __rest(_a, ["template", "tpl", "data", "className", "$schema", "render", "dispatchEvent", "partials"]);
355
- var doAction = (_b = data._scoped) === null || _b === void 0 ? void 0 : _b.doAction;
364
+ // --- 错误边界组件 ---
365
+ var ErrorBoundary = /** @class */function (_super) {
366
+ __extends(ErrorBoundary, _super);
367
+ function ErrorBoundary(props) {
368
+ var _this = _super.call(this, props) || this;
369
+ _this.state = {
370
+ hasError: false,
371
+ error: null
372
+ };
373
+ return _this;
374
+ }
375
+ ErrorBoundary.getDerivedStateFromError = function (error) {
376
+ return {
377
+ hasError: true,
378
+ error: error
379
+ };
380
+ };
381
+ ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
382
+ console.error("Liquid Component ErrorBoundary caught error:", error, errorInfo);
383
+ };
384
+ ErrorBoundary.prototype.render = function () {
385
+ if (this.state.hasError) {
386
+ // 如果提供了 fallback 则使用 fallback,否则不显示(静默失败,符合“不影响整体显示”的要求)
387
+ // 但对于顶层错误,可能需要显示。这里用于 amisRender 的局部包裹。
388
+ return this.props.fallback || null;
389
+ }
390
+ return this.props.children;
391
+ };
392
+ return ErrorBoundary;
393
+ }(React__default["default"].Component);
394
+ // --- Portal 渲染器(React.memo 防止不必要的 remount)---
395
+ // amisRender 执行后可能窃取焦点,需要在每次 Portal 渲染后恢复焦点
396
+ var PortalRenderer = React__default["default"].memo(function PortalItem(_a) {
397
+ var _b, _c;
398
+ var portalKey = _a.portalKey,
399
+ schema = _a.schema,
400
+ domNode = _a.domNode,
401
+ amisRenderRef = _a.amisRenderRef,
402
+ dataRef = _a.dataRef;
403
+ // 记录焦点恢复定时器,确保组件卸载时清理
404
+ var focusTimerRef = React.useRef(null);
405
+ // render 阶段捕获当前焦点(在 amisRender 执行前)
406
+ var savedFocusRef = React.useRef({
407
+ element: null,
408
+ selectionStart: null,
409
+ selectionEnd: null
410
+ });
411
+ var active = document.activeElement;
412
+ if (active && active instanceof HTMLElement && active !== document.body) {
413
+ savedFocusRef.current = {
414
+ element: active,
415
+ selectionStart: (_b = active.selectionStart) !== null && _b !== void 0 ? _b : null,
416
+ selectionEnd: (_c = active.selectionEnd) !== null && _c !== void 0 ? _c : null
417
+ };
418
+ }
419
+ // amisRender 执行(可能会窃取焦点)
420
+ var rendered = amisRenderRef.current("partial-".concat(portalKey), schema, {
421
+ data: dataRef.current
422
+ });
423
+ // DOM 更新后恢复焦点(延迟 10ms,等待 amis 内部异步 DOM 操作完成)
424
+ React.useLayoutEffect(function () {
425
+ var _a = savedFocusRef.current,
426
+ element = _a.element,
427
+ selectionStart = _a.selectionStart,
428
+ selectionEnd = _a.selectionEnd;
429
+ if (!element || !(element instanceof HTMLElement)) return;
430
+ // 清理上一次未执行的定时器
431
+ if (focusTimerRef.current) {
432
+ clearTimeout(focusTimerRef.current);
433
+ }
434
+ focusTimerRef.current = setTimeout(function () {
435
+ focusTimerRef.current = null;
436
+ // 焦点已不在原元素上,且原元素仍在 DOM 中
437
+ if (document.activeElement !== element && document.body.contains(element)) {
438
+ element.focus();
439
+ // 恢复光标位置(input/textarea)
440
+ try {
441
+ if (selectionStart !== null && 'setSelectionRange' in element) {
442
+ element.setSelectionRange(selectionStart, selectionEnd !== null && selectionEnd !== void 0 ? selectionEnd : selectionStart);
443
+ }
444
+ } catch (_) {/* 某些 input type 不支持 setSelectionRange */}
445
+ }
446
+ }, 10);
447
+ });
448
+ // 组件卸载时清理定时器
449
+ React.useEffect(function () {
450
+ return function () {
451
+ if (focusTimerRef.current) {
452
+ clearTimeout(focusTimerRef.current);
453
+ }
454
+ };
455
+ }, []);
456
+ return reactDom.createPortal(React__default["default"].createElement(ErrorBoundary, {
457
+ fallback: null
458
+ }, rendered), domNode, portalKey);
459
+ }, function (prev, next) {
460
+ // 仅在 portalKey、DOM 节点或 schema 内容变化时才重新渲染
461
+ return prev.portalKey === next.portalKey && prev.domNode === next.domNode && lodash.isEqual(prev.schema, next.schema);
462
+ });
463
+ // --- 错误显示组件 ---
464
+ var ErrorDisplay = function ErrorDisplay(_a) {
465
+ var error = _a.error;
466
+ var _b = __read(React.useState(false), 2),
467
+ expanded = _b[0],
468
+ setExpanded = _b[1];
469
+ if (!error) return null;
470
+ return React__default["default"].createElement("div", {
471
+ className: "border border-red-500 bg-red-50 text-red-700 p-4 rounded mb-4 text-sm font-mono"
472
+ }, React__default["default"].createElement("div", {
473
+ className: "flex justify-between items-start"
474
+ }, React__default["default"].createElement("div", {
475
+ className: "font-bold"
476
+ }, "Template Render Error"), React__default["default"].createElement("button", {
477
+ onClick: function onClick() {
478
+ return setExpanded(!expanded);
479
+ },
480
+ className: "text-blue-600 hover:underline text-xs ml-4 whitespace-nowrap"
481
+ }, expanded ? 'Hide Details' : 'Show Details')), React__default["default"].createElement("div", {
482
+ className: "mt-1"
483
+ }, error.message), expanded && React__default["default"].createElement("div", {
484
+ className: "mt-2 pt-2 border-t border-red-200 text-xs overflow-auto max-h-60"
485
+ }, React__default["default"].createElement("pre", null, error.stack)));
486
+ };
487
+ var LiquidComponent = function LiquidComponent(props) {
488
+ var _a;
489
+ var template = props.template,
490
+ tpl = props.tpl,
491
+ data = props.data,
492
+ className = props.className,
493
+ $schema = props.$schema,
494
+ amisRender = props.render,
495
+ dispatchEvent = props.dispatchEvent,
496
+ propsPartials = props.partials;
497
+ __rest(props, ["template", "tpl", "data", "className", "$schema", "render", "dispatchEvent", "partials"]);
498
+ var doAction = (_a = data._scoped) === null || _a === void 0 ? void 0 : _a.doAction;
356
499
  // 支持 tpl 作为 template 的别名
357
500
  if (tpl && !template) {
358
501
  template = tpl;
359
502
  }
360
- var _c = __read(React.useState(''), 2),
361
- html = _c[0],
362
- setHtml = _c[1];
363
- var _d = __read(React.useState({}), 2),
364
- mountNodes = _d[0],
365
- setMountNodes = _d[1];
503
+ if (!template) {
504
+ template = props.$schema.template;
505
+ }
506
+ // console.log('template =============>', template, props);
507
+ var _b = __read(React.useState(''), 2),
508
+ html = _b[0],
509
+ setHtml = _b[1];
510
+ var _c = __read(React.useState(null), 2),
511
+ error = _c[0],
512
+ setError = _c[1];
513
+ var _d = __read(React.useState([]), 2),
514
+ parsedTemplates = _d[0],
515
+ setParsedTemplates = _d[1];
516
+ var _e = __read(React.useState({}), 2),
517
+ mountNodes = _e[0],
518
+ setMountNodes = _e[1];
366
519
  var containerRef = React.useRef(null);
520
+ // 焦点保护:跟踪当前聚焦元素,防止 re-render 导致焦点丢失
521
+ var focusInfoRef = React.useRef({
522
+ element: null,
523
+ inContainer: false
524
+ });
525
+ // 防抖的数据状态,用于减少 HTML 重建频率
526
+ // 保持最新 data 的引用,供脚本使用
527
+ var dataRef = React.useRef(data);
528
+ dataRef.current = data;
529
+ // 稳定引用 amisRender,防止因父组件 re-render 产生新函数引用导致 portals 重建
530
+ var amisRenderRef = React.useRef(amisRender);
531
+ amisRenderRef.current = amisRender;
367
532
  // 用于存储脚本清理函数的引用,以便在组件卸载或更新时清理副作用
368
533
  var scriptCleanupsRef = React.useRef([]);
369
534
  var finalPartials = React.useMemo(function () {
@@ -372,6 +537,12 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
372
537
  var partialsRef = React.useRef(finalPartials);
373
538
  partialsRef.current = finalPartials;
374
539
  var inlineSchemasRef = React.useRef({});
540
+ // 深比较稳定的 finalPartials 引用,防止 $schema 每次 render 产生新引用导致 portals 不必要重建
541
+ var stableFinalPartialsRef = React.useRef(finalPartials);
542
+ if (!lodash.isEqual(stableFinalPartialsRef.current, finalPartials)) {
543
+ stableFinalPartialsRef.current = finalPartials;
544
+ }
545
+ var stableFinalPartials = stableFinalPartialsRef.current;
375
546
  // 1. 初始化 Liquid Engine
376
547
  var engine = React.useMemo(function () {
377
548
  var liq = new liquidjs.Liquid({
@@ -414,6 +585,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
414
585
  parse: function parse(tagToken, remainTokens) {
415
586
  var _this = this;
416
587
  this.templates = [];
588
+ this.id = generateId();
417
589
  var stream = liq.parser.parseStream(remainTokens);
418
590
  stream.on('tag:endamis', function () {
419
591
  return stream.stop();
@@ -437,7 +609,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
437
609
  }
438
610
  try {
439
611
  schema = looseJsonParse(rawStr);
440
- id = generateId();
612
+ id = this.id;
441
613
  register = ctx.get(['__registerInlineSchema']);
442
614
  if (!register && ctx.environments) {
443
615
  register = ctx.environments['__registerInlineSchema'];
@@ -449,6 +621,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
449
621
  return [2 /*return*/, ""];
450
622
  }
451
623
  } catch (e) {
624
+ console.error(e);
452
625
  return [2 /*return*/, "<div style=\"color:red\">JSON Parse Error: ".concat(e.message, "</div>")];
453
626
  }
454
627
  return [2 /*return*/];
@@ -458,60 +631,148 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
458
631
  });
459
632
  return liq;
460
633
  }, []);
461
- var dataFingerprint = JSON.stringify(data);
462
- var partialsFingerprint = JSON.stringify(finalPartials);
463
- // 2. Liquid 渲染 HTML
634
+ // 用于处理异步渲染竞态条件的计数器,确保只应用最新一次渲染的结果
635
+ var renderIdRef = React.useRef(0);
636
+ React.useEffect(function () {
637
+ // console.log('template', template)
638
+ var isMounted = true;
639
+ try {
640
+ if (!template) {
641
+ if (isMounted) {
642
+ setParsedTemplates([]);
643
+ setError(null);
644
+ }
645
+ return;
646
+ }
647
+ var tpl_1 = engine.parse(template);
648
+ if (isMounted) {
649
+ setParsedTemplates(tpl_1);
650
+ setError(null);
651
+ }
652
+ } catch (e) {
653
+ console.error("Liquid Parse Error:", e);
654
+ if (isMounted) {
655
+ setError(e);
656
+ setParsedTemplates(null);
657
+ }
658
+ }
659
+ return function () {
660
+ isMounted = false;
661
+ };
662
+ }, [engine, template]);
663
+ // 2. Liquid 渲染 HTML(当模板、partials 或数据变化时重新渲染)
464
664
  React.useEffect(function () {
665
+ // 跳过空模板或未解析的模板(parsedTemplates 为 null、undefined 或空数组时)
666
+ if (!parsedTemplates || parsedTemplates.length === 0) return;
465
667
  var isMounted = true;
466
- inlineSchemasRef.current = {};
668
+ var currentRenderId = ++renderIdRef.current;
467
669
  var contextData = _assign(_assign({}, flattenObjectChain(data)), {
468
670
  __registerInlineSchema: function __registerInlineSchema(id, schema) {
469
671
  inlineSchemasRef.current[id] = schema;
470
672
  }
471
673
  });
472
- engine.parseAndRender(template, contextData).then(function (result) {
473
- if (isMounted) {
674
+ engine.render(parsedTemplates, contextData).then(function (result) {
675
+ // 仅应用最新一次渲染的结果,丢弃过期的异步结果(处理竞态条件)
676
+ if (isMounted && currentRenderId === renderIdRef.current) {
677
+ // 仅在渲染结果真正变化时才更新 state,避免不必要的 DOM 重建
474
678
  setHtml(function (prev) {
475
- return prev !== result ? result : prev;
679
+ return prev === result ? prev : result;
476
680
  });
681
+ setError(null);
477
682
  }
478
683
  })["catch"](function (err) {
479
- if (isMounted) console.error("Liquid Render Error:", err);
684
+ if (isMounted && currentRenderId === renderIdRef.current) {
685
+ console.error("Liquid Render Error:", err);
686
+ setError(err);
687
+ }
480
688
  });
481
689
  return function () {
482
690
  isMounted = false;
483
691
  };
484
- }, [engine, template, dataFingerprint, partialsFingerprint]);
692
+ }, [engine, parsedTemplates, finalPartials, data]); // data 变化时重新渲染模板
485
693
  // 3. Portals 挂载检测
486
694
  React.useEffect(function () {
487
695
  if (!containerRef.current) return;
488
696
  var nodes = {};
489
697
  var elements = containerRef.current.querySelectorAll('[data-amis-partial]');
490
- var hasChanges = false;
491
698
  elements.forEach(function (el) {
492
699
  var key = el.getAttribute('data-amis-partial');
493
- if (key && (inlineSchemasRef.current[key] || partialsRef.current[key])) {
700
+ var hasInlineSchema = key && inlineSchemasRef.current[key];
701
+ var hasPartialSchema = key && partialsRef.current[key];
702
+ if (key && (hasInlineSchema || hasPartialSchema)) {
494
703
  nodes[key] = el;
495
- hasChanges = true;
496
704
  }
497
705
  });
498
- if (hasChanges) setMountNodes(nodes);
706
+ // 每次 html 变化都需要更新 DOM 节点引用,因为 dangerouslySetInnerHTML 会销毁并重建节点
707
+ // 但仅在节点实际变化时更新,避免不必要的 Portal 重新创建
708
+ setMountNodes(function (prev) {
709
+ var prevKeys = Object.keys(prev).sort().join(',');
710
+ var newKeys = Object.keys(nodes).sort().join(',');
711
+ var keysChanged = prevKeys !== newKeys;
712
+ // 仅在 keys 实际变化时更新(新增或删除了 Portal 挂载点)
713
+ if (keysChanged) {
714
+ return nodes;
715
+ }
716
+ // Keys 相同但 html 变了,需要更新 DOM 节点引用(dangerouslySetInnerHTML 销毁重建了节点)
717
+ // 但不能创建新对象,否则会触发 Portal useMemo 重新执行
718
+ // 所以我们更新 prev 对象中的节点引用
719
+ Object.keys(nodes).forEach(function (key) {
720
+ if (prev[key] !== nodes[key]) {
721
+ prev[key] = nodes[key];
722
+ }
723
+ });
724
+ return prev;
725
+ });
726
+ }, [html]);
727
+ // 3.5 阻止容器内原生表单的默认提交行为
728
+ // 防止在 input 中按回车键时触发浏览器默认的表单 submit,导致页面刷新、所有表单值丢失
729
+ React.useEffect(function () {
730
+ var container = containerRef.current;
731
+ if (!container) return;
732
+ // 拦截 form submit 事件(覆盖显式提交和 Enter 键隐式提交)
733
+ var handleSubmit = function handleSubmit(e) {
734
+ e.preventDefault();
735
+ };
736
+ // 拦截 input 中的 Enter 键,防止触发外层 form 的隐式提交
737
+ // (适用于 form 在容器之上的情况,此时 submit 事件无法在容器层拦截)
738
+ var handleKeyDown = function handleKeyDown(e) {
739
+ if (e.key !== 'Enter') return;
740
+ var target = e.target;
741
+ // 仅拦截单行 input,不影响 textarea 的换行行为
742
+ if (target.tagName === 'INPUT') {
743
+ var form = target.closest('form');
744
+ if (form) {
745
+ e.preventDefault();
746
+ }
747
+ }
748
+ };
749
+ container.addEventListener('submit', handleSubmit);
750
+ container.addEventListener('keydown', handleKeyDown);
751
+ return function () {
752
+ container.removeEventListener('submit', handleSubmit);
753
+ container.removeEventListener('keydown', handleKeyDown);
754
+ };
499
755
  }, [html]);
500
756
  // 4. 创建 Portals
757
+ // 使用 PortalRenderer (React.memo) 包裹每个 Portal,确保只有 schema 实际变化的 Portal 才会重新渲染
758
+ // 移除 amisRender 依赖(使用 ref),避免父组件 re-render 导致所有 Portal 被销毁重建
501
759
  var portals = React.useMemo(function () {
502
760
  return Object.keys(mountNodes).map(function (key) {
503
761
  var domNode = mountNodes[key];
504
762
  var schema = inlineSchemasRef.current[key] || partialsRef.current[key];
505
- if (!schema || !domNode) return null;
506
- try {
507
- return reactDom.createPortal(amisRender("partial-".concat(key), schema, {
508
- data: data
509
- }), domNode);
510
- } catch (e) {
763
+ if (!schema || !domNode) {
511
764
  return null;
512
765
  }
766
+ return React__default["default"].createElement(PortalRenderer, {
767
+ key: key,
768
+ portalKey: key,
769
+ schema: schema,
770
+ domNode: domNode,
771
+ amisRenderRef: amisRenderRef,
772
+ dataRef: dataRef
773
+ });
513
774
  });
514
- }, [mountNodes, partialsFingerprint, dataFingerprint, amisRender, data]);
775
+ }, [mountNodes, stableFinalPartials]); // 使用稳定引用,避免不必要的 Portal 重建
515
776
  // ==================================================================================
516
777
  // 5. 核心逻辑:顺序加载器 (等待外部脚本加载完再执行内联脚本)
517
778
  // ==================================================================================
@@ -558,7 +819,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
558
819
  // 标记当前节点已处理,防止下次 render 重复
559
820
  scriptNode.dataset.executed = "true";
560
821
  if (isGlobalLoaded) {
561
- console.log("[Liquid] Script already loaded: ".concat(src));
822
+ // console.log(`[Liquid] Script already loaded: ${src}`);
562
823
  resolve(); // 已存在,直接视为成功
563
824
  return;
564
825
  }
@@ -573,7 +834,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
573
834
  }
574
835
  });
575
836
  newScript.onload = function () {
576
- console.log("[Liquid] Loaded: ".concat(src));
837
+ // console.log(`[Liquid] Loaded: ${src}`);
577
838
  resolve();
578
839
  };
579
840
  newScript.onerror = function () {
@@ -595,7 +856,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
595
856
  var debugName = "steedos-liquid-".concat(Math.random().toString(36).slice(2), ".js");
596
857
  var debuggableCode = code + "\n//# sourceURL=".concat(debugName);
597
858
  var func = new Function('data', 'dom', 'doAction', 'dispatchEvent', debuggableCode);
598
- var cleanupResult = func(data, scriptNode.parentElement, doAction, dispatchEvent);
859
+ // 使用 dataRef.current 获取最新的 data
860
+ var cleanupResult = func(dataRef.current, scriptNode.parentElement, doAction, dispatchEvent);
599
861
  if (typeof cleanupResult === 'function') {
600
862
  scriptCleanupsRef.current.push(cleanupResult);
601
863
  }
@@ -617,14 +879,68 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
617
879
  return cleanup && cleanup();
618
880
  });
619
881
  };
620
- }, [html, dataFingerprint]);
621
- return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", {
622
- className: "liquid-amis-container flex flex-col h-full w-full overflow-hidden ".concat(className || ''),
623
- ref: containerRef,
624
- dangerouslySetInnerHTML: {
625
- __html: html
882
+ }, [html]); // 仅依赖 html 变化,不依赖 data 变化
883
+ // ==================================================================================
884
+ // 6. 焦点保护机制
885
+ // 在 render 阶段捕获当前焦点状态,在 DOM 更新后延迟恢复意外丢失的焦点
886
+ // ==================================================================================
887
+ var outerFocusTimerRef = React.useRef(null);
888
+ if (containerRef.current) {
889
+ var active = document.activeElement;
890
+ focusInfoRef.current = {
891
+ element: active,
892
+ inContainer: !!active && containerRef.current.contains(active)
893
+ };
894
+ } else {
895
+ focusInfoRef.current = {
896
+ element: null,
897
+ inContainer: false
898
+ };
899
+ }
900
+ React.useLayoutEffect(function () {
901
+ var _a = focusInfoRef.current,
902
+ element = _a.element,
903
+ inContainer = _a.inContainer;
904
+ if (!inContainer || !element || !(element instanceof HTMLElement)) return;
905
+ if (outerFocusTimerRef.current) {
906
+ clearTimeout(outerFocusTimerRef.current);
626
907
  }
627
- }), portals);
908
+ outerFocusTimerRef.current = setTimeout(function () {
909
+ outerFocusTimerRef.current = null;
910
+ if (document.activeElement !== element && (document.activeElement === document.body || document.activeElement === null) && document.body.contains(element)) {
911
+ element.focus();
912
+ }
913
+ }, 10);
914
+ });
915
+ // 组件卸载时清理外层焦点定时器
916
+ React.useEffect(function () {
917
+ return function () {
918
+ if (outerFocusTimerRef.current) {
919
+ clearTimeout(outerFocusTimerRef.current);
920
+ }
921
+ };
922
+ }, []);
923
+ // 7. 缓存容器元素,避免 data 变化时 React 对 dangerouslySetInnerHTML div 进行不必要的协调
924
+ var innerHtml = React.useMemo(function () {
925
+ return {
926
+ __html: html
927
+ };
928
+ }, [html]);
929
+ var containerElement = React.useMemo(function () {
930
+ return React__default["default"].createElement("div", {
931
+ className: "liquid-amis-container flex flex-col h-full w-full overflow-hidden ".concat(className || ''),
932
+ ref: containerRef,
933
+ dangerouslySetInnerHTML: innerHtml
934
+ });
935
+ }, [innerHtml, className]);
936
+ if (error) {
937
+ return React__default["default"].createElement("div", {
938
+ className: "liquid-amis-container flex flex-col w-full overflow-auto p-4 ".concat(className || '')
939
+ }, React__default["default"].createElement(ErrorDisplay, {
940
+ error: error
941
+ }));
942
+ }
943
+ return React__default["default"].createElement(React__default["default"].Fragment, null, containerElement, portals);
628
944
  };
629
945
  var Inject = function Inject(props) {
630
946
  var _a = props.assets,
package/dist/assets.json CHANGED
@@ -31,8 +31,8 @@
31
31
  {
32
32
  "package": "@steedos-widgets/antd",
33
33
  "urls": [
34
- "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.3/dist/antd.umd.js",
35
- "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.3/dist/antd.umd.css"
34
+ "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.30/dist/antd.umd.js",
35
+ "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.30/dist/antd.umd.css"
36
36
  ],
37
37
  "library": "BuilderAntd"
38
38
  }
@@ -43,10 +43,10 @@
43
43
  "npm": {
44
44
  "package": "@steedos-widgets/antd"
45
45
  },
46
- "url": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.3/dist/meta.js",
46
+ "url": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.30/dist/meta.js",
47
47
  "urls": {
48
- "default": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.3/dist/meta.js",
49
- "design": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.3/dist/meta.js"
48
+ "default": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.30/dist/meta.js",
49
+ "design": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.30/dist/meta.js"
50
50
  }
51
51
  }
52
52
  ]
package/dist/meta.js CHANGED
@@ -411,6 +411,7 @@
411
411
  tags: [config.group],
412
412
  order: 99,
413
413
  icon: config.amis.icon,
414
+ panelTitle: 'Inject Settings',
414
415
  }
415
416
  } });
416
417
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@steedos-widgets/antd",
3
3
  "private": false,
4
- "version": "6.10.52-beta.3",
4
+ "version": "6.10.52-beta.30",
5
5
  "main": "dist/antd.cjs.js",
6
6
  "module": "dist/antd.esm.js",
7
7
  "unpkg": "dist/antd.umd.js",
@@ -25,11 +25,13 @@
25
25
  "@rollup/plugin-commonjs": "^29.0.0",
26
26
  "@rollup/plugin-node-resolve": "^13.1.3",
27
27
  "@rollup/plugin-typescript": "^8.4.0",
28
+ "@types/lodash": "^4.17.23",
28
29
  "@types/react": "^18.0.8",
29
30
  "@types/react-dom": "^18.0.6",
30
31
  "antd": "^5.29.2",
31
32
  "react": "18.2.0",
32
33
  "react-dom": "18.2.0",
34
+ "rimraf": "^6.1.2",
33
35
  "rollup": "^2.79.2",
34
36
  "rollup-plugin-alias": "^2.2.0",
35
37
  "rollup-plugin-external-globals": "^0.6.1",
@@ -45,10 +47,12 @@
45
47
  "rollup-plugin-svg": "^2.0.0",
46
48
  "rollup-plugin-terser": "^7.0.2",
47
49
  "rollup-plugin-tslib-resolve-id": "^0.0.0",
48
- "rollup-plugin-visualizer": "^5.8.0"
50
+ "rollup-plugin-visualizer": "^5.8.0",
51
+ "typescript": "^5.9.3"
49
52
  },
50
- "gitHead": "47fe298cc8f512c9181a93f94ecd8ca6ba41fd9f",
53
+ "gitHead": "e454ef87f2af5580952c3fe9f3b881df55962f29",
51
54
  "dependencies": {
52
- "liquidjs": "^10.24.0"
55
+ "liquidjs": "^10.24.0",
56
+ "lodash": "^4.17.23"
53
57
  }
54
58
  }