isdata-customer-sdk 0.2.5 → 0.2.7
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/index.common.js +66 -33
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +66 -33
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.common.js
CHANGED
|
@@ -33098,6 +33098,9 @@ const check = element => {
|
|
|
33098
33098
|
innerHTMLMatch: null
|
|
33099
33099
|
};
|
|
33100
33100
|
const classes = element.classList;
|
|
33101
|
+
if (!classes) {
|
|
33102
|
+
return checkResult;
|
|
33103
|
+
}
|
|
33101
33104
|
// 检查表格头部 序号 和 操作 列
|
|
33102
33105
|
if (classes.contains("ant-table-cell")) {
|
|
33103
33106
|
let innerHTML = element.innerHTML;
|
|
@@ -33299,6 +33302,9 @@ const catalog_i18n_check = element => {
|
|
|
33299
33302
|
innerHTMLMatch: null
|
|
33300
33303
|
};
|
|
33301
33304
|
const classes = element.classList;
|
|
33305
|
+
if (!classes) {
|
|
33306
|
+
return checkResult;
|
|
33307
|
+
}
|
|
33302
33308
|
// 检查目录列表 名称 列
|
|
33303
33309
|
if (classes.contains("catalog_name_content")) {
|
|
33304
33310
|
let innerHTML = element.innerHTML;
|
|
@@ -33336,6 +33342,9 @@ const catalog_i18n_check = element => {
|
|
|
33336
33342
|
};
|
|
33337
33343
|
;// ./src/api/i18n/commom_i18n/common_i18n.js
|
|
33338
33344
|
|
|
33345
|
+
|
|
33346
|
+
|
|
33347
|
+
|
|
33339
33348
|
const common_i18n_check = element => {
|
|
33340
33349
|
const checkResult = {
|
|
33341
33350
|
result: false,
|
|
@@ -33344,33 +33353,46 @@ const common_i18n_check = element => {
|
|
|
33344
33353
|
// 检查目录列表 名称 列
|
|
33345
33354
|
if (element.tagName === 'BUTTON') {
|
|
33346
33355
|
let innerHTML = element.innerHTML;
|
|
33347
|
-
let oldValue =
|
|
33356
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33357
|
+
if (!oldValue) {
|
|
33358
|
+
oldValue = innerHTML;
|
|
33359
|
+
}
|
|
33360
|
+
let firstCheck = checkTextFormat(oldValue);
|
|
33361
|
+
let firstCheckResult = firstCheck ? true : false;
|
|
33348
33362
|
console.log("检查 button 元素:", innerHTML);
|
|
33363
|
+
console.log("检查结果:", firstCheckResult);
|
|
33349
33364
|
let scriptFunction = (appID, lang) => {
|
|
33350
|
-
|
|
33351
|
-
|
|
33365
|
+
let elementsArray = [];
|
|
33366
|
+
element.childNodes.forEach(node => {
|
|
33367
|
+
let scriptNodeItem = node;
|
|
33352
33368
|
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33353
33369
|
let text = element.getAttribute("oldValue");
|
|
33370
|
+
console.log("执行 button 文本节点翻译:", text);
|
|
33354
33371
|
let isTextMatch = checkTextFormat(text);
|
|
33355
33372
|
if (!isTextMatch) {
|
|
33356
|
-
|
|
33373
|
+
elementsArray.push(scriptNodeItem);
|
|
33357
33374
|
} else {
|
|
33358
|
-
|
|
33375
|
+
console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch ? true : false);
|
|
33376
|
+
// element.removeChild(scriptNodeItem);
|
|
33359
33377
|
let key = isTextMatch.key;
|
|
33360
33378
|
let textNode = document.createTextNode(i18n(key, appID, lang) || key);
|
|
33361
|
-
|
|
33379
|
+
elementsArray.push(textNode);
|
|
33362
33380
|
}
|
|
33363
33381
|
} else {
|
|
33364
|
-
|
|
33382
|
+
elementsArray.push(scriptNodeItem);
|
|
33365
33383
|
}
|
|
33366
|
-
}
|
|
33384
|
+
});
|
|
33385
|
+
element.innerHTML = '';
|
|
33386
|
+
elementsArray.forEach(el => {
|
|
33387
|
+
element.appendChild(el);
|
|
33388
|
+
});
|
|
33367
33389
|
};
|
|
33368
33390
|
let tempHTMLMatch = {
|
|
33369
33391
|
oldValue: oldValue,
|
|
33370
33392
|
isScriptAction: true,
|
|
33371
33393
|
scriptFunction: scriptFunction
|
|
33372
33394
|
};
|
|
33373
|
-
checkResult.result =
|
|
33395
|
+
checkResult.result = firstCheckResult;
|
|
33374
33396
|
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33375
33397
|
return checkResult;
|
|
33376
33398
|
}
|
|
@@ -33508,12 +33530,12 @@ function checkPlatformElementContent(element) {
|
|
|
33508
33530
|
}
|
|
33509
33531
|
return checkContentResult;
|
|
33510
33532
|
}
|
|
33511
|
-
|
|
33512
|
-
// 处理DOM元素的函数
|
|
33513
33533
|
function processElement(element) {
|
|
33514
|
-
|
|
33534
|
+
// 仅处理元素节点
|
|
33535
|
+
if (element && element.nodeType != 1) {
|
|
33515
33536
|
return false;
|
|
33516
33537
|
}
|
|
33538
|
+
|
|
33517
33539
|
// 如果元素有子元素,则不处理innerHTML
|
|
33518
33540
|
const hasChildren = hasChildElements(element);
|
|
33519
33541
|
if (hasChildren) {
|
|
@@ -33552,9 +33574,14 @@ function processElement(element) {
|
|
|
33552
33574
|
let elementId = element.getAttribute("localDomID");
|
|
33553
33575
|
if (!elementId) {
|
|
33554
33576
|
elementId = generateUniqueId();
|
|
33577
|
+
} else {
|
|
33578
|
+
// 已经处理过的元素跳过
|
|
33579
|
+
return false;
|
|
33555
33580
|
}
|
|
33556
33581
|
element.setAttribute("localDomID", elementId);
|
|
33557
|
-
|
|
33582
|
+
if (!window.i18nElementsMap) {
|
|
33583
|
+
window.i18nElementsMap = new Map();
|
|
33584
|
+
}
|
|
33558
33585
|
// 添加到Map缓存
|
|
33559
33586
|
window.i18nElementsMap.set(elementId, {
|
|
33560
33587
|
dom: element,
|
|
@@ -33567,8 +33594,8 @@ function processElement(element) {
|
|
|
33567
33594
|
applyTranslation(element);
|
|
33568
33595
|
return true;
|
|
33569
33596
|
}
|
|
33570
|
-
function unProcessElement(
|
|
33571
|
-
if (
|
|
33597
|
+
function unProcessElement(element) {
|
|
33598
|
+
if (element && element.nodeType !== 1) {
|
|
33572
33599
|
return;
|
|
33573
33600
|
}
|
|
33574
33601
|
const hasChildren = hasChildElements(element);
|
|
@@ -33578,7 +33605,7 @@ function unProcessElement(node) {
|
|
|
33578
33605
|
unProcessElement(children[i]);
|
|
33579
33606
|
}
|
|
33580
33607
|
}
|
|
33581
|
-
const localDomID =
|
|
33608
|
+
const localDomID = element.getAttribute("localDomID");
|
|
33582
33609
|
if (localDomID && window.i18nElementsMap.has(localDomID)) {
|
|
33583
33610
|
window.i18nElementsMap.delete(localDomID);
|
|
33584
33611
|
console.log("移除元素缓存:", localDomID);
|
|
@@ -33634,34 +33661,40 @@ const initDomNodeI18NObserver = () => {
|
|
|
33634
33661
|
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33635
33662
|
// 遍历Map,更新每个已处理元素的翻译
|
|
33636
33663
|
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
33664
|
+
console.log("更新元素翻译:", elementId, item.dom);
|
|
33637
33665
|
applyTranslation(item.dom);
|
|
33638
33666
|
}
|
|
33639
33667
|
});
|
|
33640
33668
|
// 创建观察器实例
|
|
33641
33669
|
const observer = new MutationObserver(mutations => {
|
|
33642
33670
|
mutations.forEach(mutation => {
|
|
33643
|
-
|
|
33644
|
-
|
|
33645
|
-
|
|
33646
|
-
|
|
33647
|
-
|
|
33648
|
-
|
|
33671
|
+
if (mutation.type === 'childList') {
|
|
33672
|
+
// 节点添加
|
|
33673
|
+
if (mutation.addedNodes.length > 0) {
|
|
33674
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
33675
|
+
let node = mutation.addedNodes[i];
|
|
33676
|
+
// console.log(`处理新增节点:`,node);
|
|
33677
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
33678
|
+
node = node.parentNode;
|
|
33679
|
+
}
|
|
33680
|
+
processElement(node);
|
|
33681
|
+
}
|
|
33649
33682
|
}
|
|
33650
|
-
|
|
33651
|
-
|
|
33652
|
-
|
|
33653
|
-
|
|
33654
|
-
|
|
33655
|
-
|
|
33683
|
+
// 节点移除
|
|
33684
|
+
if (mutation.removedNodes.length > 0) {
|
|
33685
|
+
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
33686
|
+
let node = mutation.removedNodes[i];
|
|
33687
|
+
// console.log(`处理移除节点:`,node);
|
|
33688
|
+
unProcessElement(node);
|
|
33689
|
+
}
|
|
33656
33690
|
}
|
|
33657
|
-
}
|
|
33658
|
-
if (mutation.type === 'characterData') {
|
|
33691
|
+
} else if (mutation.type === 'characterData') {
|
|
33659
33692
|
// 处理文本变化
|
|
33660
|
-
|
|
33693
|
+
const oldValue = mutation.oldValue;
|
|
33661
33694
|
const targetNode = mutation.target;
|
|
33662
|
-
|
|
33695
|
+
const newValue = targetNode.data;
|
|
33663
33696
|
// 创建日志条目并显示
|
|
33664
|
-
|
|
33697
|
+
console.log(`文本修改: ${oldValue} → ${newValue}`);
|
|
33665
33698
|
const parentElement = targetNode.parentNode;
|
|
33666
33699
|
processElement(parentElement);
|
|
33667
33700
|
}
|