@steedos-widgets/antd 6.10.52-beta.1 → 6.10.52-beta.11

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
@@ -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++) {
@@ -341,28 +360,92 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
341
360
  return flattened;
342
361
  }
343
362
  // --- 组件实现 ---
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;
363
+ // --- 错误边界组件 ---
364
+ var ErrorBoundary = /** @class */function (_super) {
365
+ __extends(ErrorBoundary, _super);
366
+ function ErrorBoundary(props) {
367
+ var _this = _super.call(this, props) || this;
368
+ _this.state = {
369
+ hasError: false,
370
+ error: null
371
+ };
372
+ return _this;
373
+ }
374
+ ErrorBoundary.getDerivedStateFromError = function (error) {
375
+ return {
376
+ hasError: true,
377
+ error: error
378
+ };
379
+ };
380
+ ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
381
+ console.error("Liquid Component ErrorBoundary caught error:", error, errorInfo);
382
+ };
383
+ ErrorBoundary.prototype.render = function () {
384
+ if (this.state.hasError) {
385
+ // 如果提供了 fallback 则使用 fallback,否则不显示(静默失败,符合“不影响整体显示”的要求)
386
+ // 但对于顶层错误,可能需要显示。这里用于 amisRender 的局部包裹。
387
+ return this.props.fallback || null;
388
+ }
389
+ return this.props.children;
390
+ };
391
+ return ErrorBoundary;
392
+ }(React__default["default"].Component);
393
+ // --- 错误显示组件 ---
394
+ var ErrorDisplay = function ErrorDisplay(_a) {
395
+ var error = _a.error;
396
+ var _b = __read(React.useState(false), 2),
397
+ expanded = _b[0],
398
+ setExpanded = _b[1];
399
+ if (!error) return null;
400
+ return React__default["default"].createElement("div", {
401
+ className: "border border-red-500 bg-red-50 text-red-700 p-4 rounded mb-4 text-sm font-mono"
402
+ }, React__default["default"].createElement("div", {
403
+ className: "flex justify-between items-start"
404
+ }, React__default["default"].createElement("div", {
405
+ className: "font-bold"
406
+ }, "Template Render Error"), React__default["default"].createElement("button", {
407
+ onClick: function onClick() {
408
+ return setExpanded(!expanded);
409
+ },
410
+ className: "text-blue-600 hover:underline text-xs ml-4 whitespace-nowrap"
411
+ }, expanded ? 'Hide Details' : 'Show Details')), React__default["default"].createElement("div", {
412
+ className: "mt-1"
413
+ }, error.message), expanded && React__default["default"].createElement("div", {
414
+ className: "mt-2 pt-2 border-t border-red-200 text-xs overflow-auto max-h-60"
415
+ }, React__default["default"].createElement("pre", null, error.stack)));
416
+ };
417
+ var LiquidComponent = function LiquidComponent(props) {
418
+ var _a;
419
+ var template = props.template,
420
+ tpl = props.tpl,
421
+ data = props.data,
422
+ className = props.className,
423
+ $schema = props.$schema,
424
+ amisRender = props.render,
425
+ dispatchEvent = props.dispatchEvent,
426
+ propsPartials = props.partials;
427
+ __rest(props, ["template", "tpl", "data", "className", "$schema", "render", "dispatchEvent", "partials"]);
428
+ var doAction = (_a = data._scoped) === null || _a === void 0 ? void 0 : _a.doAction;
356
429
  // 支持 tpl 作为 template 的别名
357
430
  if (tpl && !template) {
358
431
  template = tpl;
359
432
  }
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];
433
+ if (!template) {
434
+ template = props.$schema.template;
435
+ }
436
+ // console.log('template =============>', template, props);
437
+ var _b = __read(React.useState(''), 2),
438
+ html = _b[0],
439
+ setHtml = _b[1];
440
+ var _c = __read(React.useState(null), 2),
441
+ error = _c[0],
442
+ setError = _c[1];
443
+ var _d = __read(React.useState([]), 2),
444
+ parsedTemplates = _d[0],
445
+ setParsedTemplates = _d[1];
446
+ var _e = __read(React.useState({}), 2),
447
+ mountNodes = _e[0],
448
+ setMountNodes = _e[1];
366
449
  var containerRef = React.useRef(null);
367
450
  // 用于存储脚本清理函数的引用,以便在组件卸载或更新时清理副作用
368
451
  var scriptCleanupsRef = React.useRef([]);
@@ -414,6 +497,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
414
497
  parse: function parse(tagToken, remainTokens) {
415
498
  var _this = this;
416
499
  this.templates = [];
500
+ this.id = generateId();
417
501
  var stream = liq.parser.parseStream(remainTokens);
418
502
  stream.on('tag:endamis', function () {
419
503
  return stream.stop();
@@ -437,7 +521,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
437
521
  }
438
522
  try {
439
523
  schema = looseJsonParse(rawStr);
440
- id = generateId();
524
+ id = this.id;
441
525
  register = ctx.get(['__registerInlineSchema']);
442
526
  if (!register && ctx.environments) {
443
527
  register = ctx.environments['__registerInlineSchema'];
@@ -460,8 +544,36 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
460
544
  }, []);
461
545
  var dataFingerprint = JSON.stringify(data);
462
546
  var partialsFingerprint = JSON.stringify(finalPartials);
547
+ React.useEffect(function () {
548
+ // console.log('template', template)
549
+ var isMounted = true;
550
+ try {
551
+ if (!template) {
552
+ if (isMounted) {
553
+ setParsedTemplates([]);
554
+ setError(null);
555
+ }
556
+ return;
557
+ }
558
+ var tpl_1 = engine.parse(template);
559
+ if (isMounted) {
560
+ setParsedTemplates(tpl_1);
561
+ setError(null);
562
+ }
563
+ } catch (e) {
564
+ console.error("Liquid Parse Error:", e);
565
+ if (isMounted) {
566
+ setError(e);
567
+ setParsedTemplates(null);
568
+ }
569
+ }
570
+ return function () {
571
+ isMounted = false;
572
+ };
573
+ }, [engine, template]);
463
574
  // 2. Liquid 渲染 HTML
464
575
  React.useEffect(function () {
576
+ if (!parsedTemplates) return;
465
577
  var isMounted = true;
466
578
  inlineSchemasRef.current = {};
467
579
  var contextData = _assign(_assign({}, flattenObjectChain(data)), {
@@ -469,33 +581,47 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
469
581
  inlineSchemasRef.current[id] = schema;
470
582
  }
471
583
  });
472
- engine.parseAndRender(template, contextData).then(function (result) {
584
+ // console.debug('[Liquid] Start render with context:', parsedTemplates, contextData);
585
+ engine.render(parsedTemplates, contextData).then(function (result) {
473
586
  if (isMounted) {
587
+ // console.debug('[Liquid] Render success, content length:', result?.length, result);
474
588
  setHtml(function (prev) {
475
589
  return prev !== result ? result : prev;
476
590
  });
591
+ setError(null);
477
592
  }
478
593
  })["catch"](function (err) {
479
- if (isMounted) console.error("Liquid Render Error:", err);
594
+ // console.log(`render error: `, template, contextData)
595
+ if (isMounted) {
596
+ console.error("Liquid Render Error:", err);
597
+ setError(err);
598
+ }
480
599
  });
481
600
  return function () {
482
601
  isMounted = false;
483
602
  };
484
- }, [engine, template, dataFingerprint, partialsFingerprint]);
603
+ }, [engine, parsedTemplates, dataFingerprint, partialsFingerprint]);
485
604
  // 3. Portals 挂载检测
486
605
  React.useEffect(function () {
487
606
  if (!containerRef.current) return;
488
607
  var nodes = {};
489
608
  var elements = containerRef.current.querySelectorAll('[data-amis-partial]');
490
- var hasChanges = false;
491
609
  elements.forEach(function (el) {
492
610
  var key = el.getAttribute('data-amis-partial');
493
611
  if (key && (inlineSchemasRef.current[key] || partialsRef.current[key])) {
494
612
  nodes[key] = el;
495
- hasChanges = true;
496
613
  }
497
614
  });
498
- if (hasChanges) setMountNodes(nodes);
615
+ // 只有在节点实际发生变化时才更新,防止死循环
616
+ // 简单的 key 比较
617
+ setMountNodes(function (prev) {
618
+ var prevKeys = Object.keys(prev).sort().join(',');
619
+ var newKeys = Object.keys(nodes).sort().join(',');
620
+ if (prevKeys !== newKeys) return nodes;
621
+ // 如果想要更精确,还得对比 dom 引用,通常 key 变了 dom 也就变了
622
+ // 这里只是为了避免不必要的 set
623
+ return prev;
624
+ });
499
625
  }, [html]);
500
626
  // 4. 创建 Portals
501
627
  var portals = React.useMemo(function () {
@@ -504,9 +630,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
504
630
  var schema = inlineSchemasRef.current[key] || partialsRef.current[key];
505
631
  if (!schema || !domNode) return null;
506
632
  try {
507
- return reactDom.createPortal(amisRender("partial-".concat(key), schema, {
633
+ return reactDom.createPortal(React__default["default"].createElement(ErrorBoundary, {
634
+ fallback: null
635
+ }, amisRender("partial-".concat(key), schema, {
508
636
  data: data
509
- }), domNode);
637
+ })), domNode);
510
638
  } catch (e) {
511
639
  return null;
512
640
  }
@@ -558,7 +686,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
558
686
  // 标记当前节点已处理,防止下次 render 重复
559
687
  scriptNode.dataset.executed = "true";
560
688
  if (isGlobalLoaded) {
561
- console.log("[Liquid] Script already loaded: ".concat(src));
689
+ // console.log(`[Liquid] Script already loaded: ${src}`);
562
690
  resolve(); // 已存在,直接视为成功
563
691
  return;
564
692
  }
@@ -573,7 +701,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
573
701
  }
574
702
  });
575
703
  newScript.onload = function () {
576
- console.log("[Liquid] Loaded: ".concat(src));
704
+ // console.log(`[Liquid] Loaded: ${src}`);
577
705
  resolve();
578
706
  };
579
707
  newScript.onerror = function () {
@@ -618,6 +746,13 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
618
746
  });
619
747
  };
620
748
  }, [html, dataFingerprint]);
749
+ if (error) {
750
+ return React__default["default"].createElement("div", {
751
+ className: "liquid-amis-container flex flex-col w-full overflow-auto p-4 ".concat(className || '')
752
+ }, React__default["default"].createElement(ErrorDisplay, {
753
+ error: error
754
+ }));
755
+ }
621
756
  return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", {
622
757
  className: "liquid-amis-container flex flex-col h-full w-full overflow-hidden ".concat(className || ''),
623
758
  ref: containerRef,
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.1/dist/antd.umd.js",
35
- "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.1/dist/antd.umd.css"
34
+ "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.11/dist/antd.umd.js",
35
+ "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.11/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.1/dist/meta.js",
46
+ "url": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.11/dist/meta.js",
47
47
  "urls": {
48
- "default": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.1/dist/meta.js",
49
- "design": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.1/dist/meta.js"
48
+ "default": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.11/dist/meta.js",
49
+ "design": "https://unpkg.com/@steedos-widgets/antd@6.10.52-beta.11/dist/meta.js"
50
50
  }
51
51
  }
52
52
  ]
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.1",
4
+ "version": "6.10.52-beta.11",
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": "8a2fa16f1c8dd4d4de41c4365d40c9c711da6ccb",
50
+ "gitHead": "762c9da84236c73a0826193eb5c3f2c9d4cc102b",
51
51
  "dependencies": {
52
52
  "liquidjs": "^10.24.0"
53
53
  }