@steedos-widgets/antd 6.10.44 → 6.10.45
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 +73 -55
- package/dist/assets.json +5 -5
- package/dist/meta.js +8 -0
- package/dist/metas/Liquid.d.ts +5 -0
- package/dist/types/metas/Liquid.d.ts +5 -0
- package/package.json +2 -2
package/dist/antd.umd.js
CHANGED
|
@@ -290,27 +290,16 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
290
290
|
var generateId = function generateId() {
|
|
291
291
|
return "amis-inline-".concat(Math.random().toString(36).substr(2, 9));
|
|
292
292
|
};
|
|
293
|
-
/**
|
|
294
|
-
* 宽松 JSON 解析器
|
|
295
|
-
* 允许无引号 Key、单引号 String,并自动修复 HTML 转义字符。
|
|
296
|
-
* 注意:使用 new Function 有安全风险,仅适用于受信任的模板来源。
|
|
297
|
-
*/
|
|
298
293
|
var looseJsonParse = function looseJsonParse(str) {
|
|
299
294
|
if (!str) return null;
|
|
300
|
-
// 1. 基础清洗:修复 HTML 转义
|
|
301
295
|
var cleanStr = str.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
302
|
-
// 2. 清洗隐形字符 (Web 复制粘贴常见问题)
|
|
303
296
|
cleanStr = cleanStr.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u2028\u2029\u202f\u205f\u3000]/g, ' ');
|
|
304
297
|
try {
|
|
305
|
-
// 优先尝试标准 JSON 解析 (性能最好)
|
|
306
298
|
return JSON.parse(cleanStr);
|
|
307
299
|
} catch (e) {
|
|
308
300
|
try {
|
|
309
|
-
// 降级策略: 使用 Function 解析 (支持 {key: 'value'} 写法)
|
|
310
|
-
// 如果你的环境支持,推荐替换为 'json5' 库以获得更安全的解析
|
|
311
301
|
return new Function("return " + cleanStr)();
|
|
312
302
|
} catch (e2) {
|
|
313
|
-
// 抛出原始错误以便上层捕获显示
|
|
314
303
|
throw new Error("JSON Parse Error: ".concat(e.message));
|
|
315
304
|
}
|
|
316
305
|
}
|
|
@@ -330,24 +319,21 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
330
319
|
mountNodes = _c[0],
|
|
331
320
|
setMountNodes = _c[1];
|
|
332
321
|
var containerRef = React.useRef(null);
|
|
333
|
-
//
|
|
322
|
+
// 用于存储脚本清理函数的引用,以便在组件卸载或更新时清理副作用
|
|
323
|
+
var scriptCleanupsRef = React.useRef([]);
|
|
334
324
|
var finalPartials = React.useMemo(function () {
|
|
335
325
|
return _assign(_assign({}, $schema || {}), propsPartials);
|
|
336
326
|
}, [$schema, propsPartials]);
|
|
337
|
-
// 使用 Ref 保持 Partials 最新引用,避免 engine 重建
|
|
338
327
|
var partialsRef = React.useRef(finalPartials);
|
|
339
328
|
partialsRef.current = finalPartials;
|
|
340
|
-
// 存储内联解析出来的 Schema,用于 Portal 渲染
|
|
341
329
|
var inlineSchemasRef = React.useRef({});
|
|
342
|
-
//
|
|
330
|
+
// 1. 初始化 Liquid Engine
|
|
343
331
|
var engine = React.useMemo(function () {
|
|
344
332
|
var liq = new liquidjs.Liquid({
|
|
345
|
-
// 自定义文件系统以支持内存 Partials
|
|
346
333
|
fs: {
|
|
347
334
|
readFileSync: function readFileSync(file) {
|
|
348
335
|
var content = partialsRef.current[file];
|
|
349
336
|
if (_typeof(content) === 'object' && content !== null) {
|
|
350
|
-
// 如果 Partial 是对象,说明是 AMIS Schema,直接占位
|
|
351
337
|
return "<div data-amis-partial=\"".concat(file, "\"></div>");
|
|
352
338
|
}
|
|
353
339
|
return typeof content === 'string' ? content : "[Template '".concat(file, "' not found]");
|
|
@@ -365,7 +351,6 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
365
351
|
resolve: function resolve(root, file) {
|
|
366
352
|
return file;
|
|
367
353
|
},
|
|
368
|
-
sep: '/',
|
|
369
354
|
readFile: function readFile(file) {
|
|
370
355
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
371
356
|
var content;
|
|
@@ -380,7 +365,6 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
380
365
|
}
|
|
381
366
|
}
|
|
382
367
|
});
|
|
383
|
-
// 注册自定义标签 {% amis %}
|
|
384
368
|
liq.registerTag('amis', {
|
|
385
369
|
parse: function parse(tagToken, remainTokens) {
|
|
386
370
|
var _this = this;
|
|
@@ -403,30 +387,24 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
403
387
|
});
|
|
404
388
|
rawStr = chunks.join('').trim();
|
|
405
389
|
if (!rawStr) return [2 /*return*/, ''];
|
|
406
|
-
// 开发者体验优化:检测 [object Object]
|
|
407
390
|
if (rawStr.includes('[object Object]')) {
|
|
408
|
-
return [2 /*return*/, "<div class=\"text-red-500 border border-red-500 p-2 text-sm bg-red-50\"
|
|
391
|
+
return [2 /*return*/, "<div class=\"text-red-500 border border-red-500 p-2 text-sm bg-red-50\">Error: [object Object] detected. Use | json filter.</div>"];
|
|
409
392
|
}
|
|
410
393
|
try {
|
|
411
394
|
schema = looseJsonParse(rawStr);
|
|
412
395
|
id = generateId();
|
|
413
396
|
register = ctx.get(['__registerInlineSchema']);
|
|
414
|
-
// 兼容性处理:防止 Liquid 版本差异导致 get 获取不到
|
|
415
397
|
if (!register && ctx.environments) {
|
|
416
398
|
register = ctx.environments['__registerInlineSchema'];
|
|
417
399
|
}
|
|
418
400
|
if (typeof register === 'function') {
|
|
419
401
|
register(id, schema);
|
|
420
|
-
// 返回占位符 DIV
|
|
421
402
|
return [2 /*return*/, "<div data-amis-partial=\"".concat(id, "\" style=\"display: contents;\"></div>")];
|
|
422
403
|
} else {
|
|
423
|
-
console.warn('LiquidAMIS: __registerInlineSchema hook not found in context.');
|
|
424
404
|
return [2 /*return*/, ""];
|
|
425
405
|
}
|
|
426
406
|
} catch (e) {
|
|
427
|
-
|
|
428
|
-
// 错误 UI
|
|
429
|
-
return [2 /*return*/, "<div style=\"border:2px solid red; background:#fff0f0; padding:8px; font-family:monospace; border-radius: 4px; font-size: 12px;\">\n <strong style=\"color:#d32f2f;\">JSON Parse Failed</strong>\n <div style=\"margin-top:4px; white-space:pre-wrap; background:white; border:1px solid #ddd; padding:4px; color:#333;\">".concat(rawStr.replace(/</g, '<'), "</div>\n <div style=\"color:#d32f2f; margin-top:4px;\">").concat(e.message, "</div>\n </div>")];
|
|
407
|
+
return [2 /*return*/, "<div style=\"color:red\">JSON Parse Error: ".concat(e.message, "</div>")];
|
|
430
408
|
}
|
|
431
409
|
return [2 /*return*/];
|
|
432
410
|
});
|
|
@@ -434,16 +412,14 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
434
412
|
}
|
|
435
413
|
});
|
|
436
414
|
return liq;
|
|
437
|
-
}, []);
|
|
438
|
-
// 用于触发重渲染的指纹
|
|
415
|
+
}, []);
|
|
439
416
|
var dataFingerprint = JSON.stringify(data);
|
|
440
417
|
var partialsFingerprint = JSON.stringify(finalPartials);
|
|
441
|
-
//
|
|
418
|
+
// 2. Liquid 渲染 HTML
|
|
442
419
|
React.useEffect(function () {
|
|
443
420
|
var isMounted = true;
|
|
444
|
-
inlineSchemasRef.current = {};
|
|
421
|
+
inlineSchemasRef.current = {};
|
|
445
422
|
var contextData = _assign(_assign({}, data), {
|
|
446
|
-
// 注入回调函数,允许 Liquid 标签内部向 React 组件回传数据
|
|
447
423
|
__registerInlineSchema: function __registerInlineSchema(id, schema) {
|
|
448
424
|
inlineSchemasRef.current[id] = schema;
|
|
449
425
|
}
|
|
@@ -455,16 +431,13 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
455
431
|
});
|
|
456
432
|
}
|
|
457
433
|
})["catch"](function (err) {
|
|
458
|
-
if (isMounted)
|
|
459
|
-
console.error("Liquid Render Error:", err);
|
|
460
|
-
setHtml("<div style=\"color:red; padding:10px; border:1px solid red;\">Global Render Error: ".concat(err.message, "</div>"));
|
|
461
|
-
}
|
|
434
|
+
if (isMounted) console.error("Liquid Render Error:", err);
|
|
462
435
|
});
|
|
463
436
|
return function () {
|
|
464
437
|
isMounted = false;
|
|
465
438
|
};
|
|
466
439
|
}, [engine, template, dataFingerprint, partialsFingerprint]);
|
|
467
|
-
//
|
|
440
|
+
// 3. Portals 挂载检测
|
|
468
441
|
React.useEffect(function () {
|
|
469
442
|
if (!containerRef.current) return;
|
|
470
443
|
var nodes = {};
|
|
@@ -472,40 +445,85 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
472
445
|
var hasChanges = false;
|
|
473
446
|
elements.forEach(function (el) {
|
|
474
447
|
var key = el.getAttribute('data-amis-partial');
|
|
475
|
-
if (key) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (hasSchema) {
|
|
479
|
-
nodes[key] = el;
|
|
480
|
-
hasChanges = true;
|
|
481
|
-
}
|
|
448
|
+
if (key && (inlineSchemasRef.current[key] || partialsRef.current[key])) {
|
|
449
|
+
nodes[key] = el;
|
|
450
|
+
hasChanges = true;
|
|
482
451
|
}
|
|
483
452
|
});
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
setMountNodes(nodes);
|
|
488
|
-
}
|
|
489
|
-
}, [html]); // 当 HTML 字符串变化后,重新扫描 DOM
|
|
490
|
-
// 5. 创建 React Portals
|
|
453
|
+
if (hasChanges) setMountNodes(nodes);
|
|
454
|
+
}, [html]);
|
|
455
|
+
// 4. 创建 Portals
|
|
491
456
|
var portals = React.useMemo(function () {
|
|
492
457
|
return Object.keys(mountNodes).map(function (key) {
|
|
493
458
|
var domNode = mountNodes[key];
|
|
494
|
-
// 优先取内联 Schema,其次取 Partials 定义的 Schema
|
|
495
459
|
var schema = inlineSchemasRef.current[key] || partialsRef.current[key];
|
|
496
460
|
if (!schema || !domNode) return null;
|
|
497
461
|
try {
|
|
498
|
-
// 使用 createPortal 将 AMIS 组件挂载到 Liquid 生成的 div 中
|
|
499
|
-
// 传递 data 作为 props,确保 AMIS 能获取到数据
|
|
500
462
|
return reactDom.createPortal(amisRender("partial-".concat(key), schema, {
|
|
501
463
|
data: data
|
|
502
464
|
}), domNode);
|
|
503
465
|
} catch (e) {
|
|
504
|
-
console.error("Portal Render Error for key ".concat(key, ":"), e);
|
|
505
466
|
return null;
|
|
506
467
|
}
|
|
507
468
|
});
|
|
508
469
|
}, [mountNodes, partialsFingerprint, dataFingerprint, amisRender, data]);
|
|
470
|
+
// ==================================================================================
|
|
471
|
+
// 5. 核心逻辑:执行脚本 (新增功能)
|
|
472
|
+
// ==================================================================================
|
|
473
|
+
React.useEffect(function () {
|
|
474
|
+
if (!containerRef.current) return;
|
|
475
|
+
// 1. 先清理上一次执行留下的副作用(如果有返回清理函数)
|
|
476
|
+
scriptCleanupsRef.current.forEach(function (cleanup) {
|
|
477
|
+
return cleanup && cleanup();
|
|
478
|
+
});
|
|
479
|
+
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);
|
|
506
|
+
}
|
|
507
|
+
// 标记已执行
|
|
508
|
+
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
|
+
}
|
|
519
|
+
});
|
|
520
|
+
// 组件卸载时清理
|
|
521
|
+
return function () {
|
|
522
|
+
scriptCleanupsRef.current.forEach(function (cleanup) {
|
|
523
|
+
return cleanup && cleanup();
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
}, [html, dataFingerprint]); // 当 HTML 结构变化或数据变化时,重新扫描执行
|
|
509
527
|
return React__default["default"].createElement("div", {
|
|
510
528
|
className: "liquid-amis-container ".concat(className || ''),
|
|
511
529
|
ref: containerRef
|
package/dist/assets.json
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
{
|
|
25
25
|
"package": "@steedos-widgets/antd",
|
|
26
26
|
"urls": [
|
|
27
|
-
"https://unpkg.com/@steedos-widgets/antd@6.10.
|
|
28
|
-
"https://unpkg.com/@steedos-widgets/antd@6.10.
|
|
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"
|
|
29
29
|
],
|
|
30
30
|
"library": "BuilderAntd"
|
|
31
31
|
}
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"npm": {
|
|
37
37
|
"package": "@steedos-widgets/antd"
|
|
38
38
|
},
|
|
39
|
-
"url": "https://unpkg.com/@steedos-widgets/antd@6.10.
|
|
39
|
+
"url": "https://unpkg.com/@steedos-widgets/antd@6.10.45/dist/meta.js",
|
|
40
40
|
"urls": {
|
|
41
|
-
"default": "https://unpkg.com/@steedos-widgets/antd@6.10.
|
|
42
|
-
"design": "https://unpkg.com/@steedos-widgets/antd@6.10.
|
|
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"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
]
|
package/dist/meta.js
CHANGED
|
@@ -288,6 +288,14 @@
|
|
|
288
288
|
tags: [config.group],
|
|
289
289
|
order: 99,
|
|
290
290
|
icon: config.amis.icon,
|
|
291
|
+
// 容器类组件必需字段
|
|
292
|
+
regions: [
|
|
293
|
+
{
|
|
294
|
+
key: 'body',
|
|
295
|
+
label: 'Partials',
|
|
296
|
+
insertPosition: 'inner',
|
|
297
|
+
},
|
|
298
|
+
],
|
|
291
299
|
scaffold: {
|
|
292
300
|
type: config.amis.name,
|
|
293
301
|
template: "Hello {{name}}",
|
package/dist/metas/Liquid.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos-widgets/antd",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "6.10.
|
|
4
|
+
"version": "6.10.45",
|
|
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": "
|
|
50
|
+
"gitHead": "2b9a57e8e07ab9d3027d6efc6c52c50467422991",
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"liquidjs": "^10.24.0"
|
|
53
53
|
}
|