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.umd.js
CHANGED
|
@@ -33116,6 +33116,9 @@ const check = element => {
|
|
|
33116
33116
|
innerHTMLMatch: null
|
|
33117
33117
|
};
|
|
33118
33118
|
const classes = element.classList;
|
|
33119
|
+
if (!classes) {
|
|
33120
|
+
return checkResult;
|
|
33121
|
+
}
|
|
33119
33122
|
// 检查表格头部 序号 和 操作 列
|
|
33120
33123
|
if (classes.contains("ant-table-cell")) {
|
|
33121
33124
|
let innerHTML = element.innerHTML;
|
|
@@ -33317,6 +33320,9 @@ const catalog_i18n_check = element => {
|
|
|
33317
33320
|
innerHTMLMatch: null
|
|
33318
33321
|
};
|
|
33319
33322
|
const classes = element.classList;
|
|
33323
|
+
if (!classes) {
|
|
33324
|
+
return checkResult;
|
|
33325
|
+
}
|
|
33320
33326
|
// 检查目录列表 名称 列
|
|
33321
33327
|
if (classes.contains("catalog_name_content")) {
|
|
33322
33328
|
let innerHTML = element.innerHTML;
|
|
@@ -33354,6 +33360,9 @@ const catalog_i18n_check = element => {
|
|
|
33354
33360
|
};
|
|
33355
33361
|
;// ./src/api/i18n/commom_i18n/common_i18n.js
|
|
33356
33362
|
|
|
33363
|
+
|
|
33364
|
+
|
|
33365
|
+
|
|
33357
33366
|
const common_i18n_check = element => {
|
|
33358
33367
|
const checkResult = {
|
|
33359
33368
|
result: false,
|
|
@@ -33362,33 +33371,46 @@ const common_i18n_check = element => {
|
|
|
33362
33371
|
// 检查目录列表 名称 列
|
|
33363
33372
|
if (element.tagName === 'BUTTON') {
|
|
33364
33373
|
let innerHTML = element.innerHTML;
|
|
33365
|
-
let oldValue =
|
|
33374
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33375
|
+
if (!oldValue) {
|
|
33376
|
+
oldValue = innerHTML;
|
|
33377
|
+
}
|
|
33378
|
+
let firstCheck = checkTextFormat(oldValue);
|
|
33379
|
+
let firstCheckResult = firstCheck ? true : false;
|
|
33366
33380
|
console.log("检查 button 元素:", innerHTML);
|
|
33381
|
+
console.log("检查结果:", firstCheckResult);
|
|
33367
33382
|
let scriptFunction = (appID, lang) => {
|
|
33368
|
-
|
|
33369
|
-
|
|
33383
|
+
let elementsArray = [];
|
|
33384
|
+
element.childNodes.forEach(node => {
|
|
33385
|
+
let scriptNodeItem = node;
|
|
33370
33386
|
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33371
33387
|
let text = element.getAttribute("oldValue");
|
|
33388
|
+
console.log("执行 button 文本节点翻译:", text);
|
|
33372
33389
|
let isTextMatch = checkTextFormat(text);
|
|
33373
33390
|
if (!isTextMatch) {
|
|
33374
|
-
|
|
33391
|
+
elementsArray.push(scriptNodeItem);
|
|
33375
33392
|
} else {
|
|
33376
|
-
|
|
33393
|
+
console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch ? true : false);
|
|
33394
|
+
// element.removeChild(scriptNodeItem);
|
|
33377
33395
|
let key = isTextMatch.key;
|
|
33378
33396
|
let textNode = document.createTextNode(i18n(key, appID, lang) || key);
|
|
33379
|
-
|
|
33397
|
+
elementsArray.push(textNode);
|
|
33380
33398
|
}
|
|
33381
33399
|
} else {
|
|
33382
|
-
|
|
33400
|
+
elementsArray.push(scriptNodeItem);
|
|
33383
33401
|
}
|
|
33384
|
-
}
|
|
33402
|
+
});
|
|
33403
|
+
element.innerHTML = '';
|
|
33404
|
+
elementsArray.forEach(el => {
|
|
33405
|
+
element.appendChild(el);
|
|
33406
|
+
});
|
|
33385
33407
|
};
|
|
33386
33408
|
let tempHTMLMatch = {
|
|
33387
33409
|
oldValue: oldValue,
|
|
33388
33410
|
isScriptAction: true,
|
|
33389
33411
|
scriptFunction: scriptFunction
|
|
33390
33412
|
};
|
|
33391
|
-
checkResult.result =
|
|
33413
|
+
checkResult.result = firstCheckResult;
|
|
33392
33414
|
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33393
33415
|
return checkResult;
|
|
33394
33416
|
}
|
|
@@ -33526,12 +33548,12 @@ function checkPlatformElementContent(element) {
|
|
|
33526
33548
|
}
|
|
33527
33549
|
return checkContentResult;
|
|
33528
33550
|
}
|
|
33529
|
-
|
|
33530
|
-
// 处理DOM元素的函数
|
|
33531
33551
|
function processElement(element) {
|
|
33532
|
-
|
|
33552
|
+
// 仅处理元素节点
|
|
33553
|
+
if (element && element.nodeType != 1) {
|
|
33533
33554
|
return false;
|
|
33534
33555
|
}
|
|
33556
|
+
|
|
33535
33557
|
// 如果元素有子元素,则不处理innerHTML
|
|
33536
33558
|
const hasChildren = hasChildElements(element);
|
|
33537
33559
|
if (hasChildren) {
|
|
@@ -33570,9 +33592,14 @@ function processElement(element) {
|
|
|
33570
33592
|
let elementId = element.getAttribute("localDomID");
|
|
33571
33593
|
if (!elementId) {
|
|
33572
33594
|
elementId = generateUniqueId();
|
|
33595
|
+
} else {
|
|
33596
|
+
// 已经处理过的元素跳过
|
|
33597
|
+
return false;
|
|
33573
33598
|
}
|
|
33574
33599
|
element.setAttribute("localDomID", elementId);
|
|
33575
|
-
|
|
33600
|
+
if (!window.i18nElementsMap) {
|
|
33601
|
+
window.i18nElementsMap = new Map();
|
|
33602
|
+
}
|
|
33576
33603
|
// 添加到Map缓存
|
|
33577
33604
|
window.i18nElementsMap.set(elementId, {
|
|
33578
33605
|
dom: element,
|
|
@@ -33585,8 +33612,8 @@ function processElement(element) {
|
|
|
33585
33612
|
applyTranslation(element);
|
|
33586
33613
|
return true;
|
|
33587
33614
|
}
|
|
33588
|
-
function unProcessElement(
|
|
33589
|
-
if (
|
|
33615
|
+
function unProcessElement(element) {
|
|
33616
|
+
if (element && element.nodeType !== 1) {
|
|
33590
33617
|
return;
|
|
33591
33618
|
}
|
|
33592
33619
|
const hasChildren = hasChildElements(element);
|
|
@@ -33596,7 +33623,7 @@ function unProcessElement(node) {
|
|
|
33596
33623
|
unProcessElement(children[i]);
|
|
33597
33624
|
}
|
|
33598
33625
|
}
|
|
33599
|
-
const localDomID =
|
|
33626
|
+
const localDomID = element.getAttribute("localDomID");
|
|
33600
33627
|
if (localDomID && window.i18nElementsMap.has(localDomID)) {
|
|
33601
33628
|
window.i18nElementsMap.delete(localDomID);
|
|
33602
33629
|
console.log("移除元素缓存:", localDomID);
|
|
@@ -33652,34 +33679,40 @@ const initDomNodeI18NObserver = () => {
|
|
|
33652
33679
|
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33653
33680
|
// 遍历Map,更新每个已处理元素的翻译
|
|
33654
33681
|
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
33682
|
+
console.log("更新元素翻译:", elementId, item.dom);
|
|
33655
33683
|
applyTranslation(item.dom);
|
|
33656
33684
|
}
|
|
33657
33685
|
});
|
|
33658
33686
|
// 创建观察器实例
|
|
33659
33687
|
const observer = new MutationObserver(mutations => {
|
|
33660
33688
|
mutations.forEach(mutation => {
|
|
33661
|
-
|
|
33662
|
-
|
|
33663
|
-
|
|
33664
|
-
|
|
33665
|
-
|
|
33666
|
-
|
|
33689
|
+
if (mutation.type === 'childList') {
|
|
33690
|
+
// 节点添加
|
|
33691
|
+
if (mutation.addedNodes.length > 0) {
|
|
33692
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
33693
|
+
let node = mutation.addedNodes[i];
|
|
33694
|
+
// console.log(`处理新增节点:`,node);
|
|
33695
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
33696
|
+
node = node.parentNode;
|
|
33697
|
+
}
|
|
33698
|
+
processElement(node);
|
|
33699
|
+
}
|
|
33667
33700
|
}
|
|
33668
|
-
|
|
33669
|
-
|
|
33670
|
-
|
|
33671
|
-
|
|
33672
|
-
|
|
33673
|
-
|
|
33701
|
+
// 节点移除
|
|
33702
|
+
if (mutation.removedNodes.length > 0) {
|
|
33703
|
+
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
33704
|
+
let node = mutation.removedNodes[i];
|
|
33705
|
+
// console.log(`处理移除节点:`,node);
|
|
33706
|
+
unProcessElement(node);
|
|
33707
|
+
}
|
|
33674
33708
|
}
|
|
33675
|
-
}
|
|
33676
|
-
if (mutation.type === 'characterData') {
|
|
33709
|
+
} else if (mutation.type === 'characterData') {
|
|
33677
33710
|
// 处理文本变化
|
|
33678
|
-
|
|
33711
|
+
const oldValue = mutation.oldValue;
|
|
33679
33712
|
const targetNode = mutation.target;
|
|
33680
|
-
|
|
33713
|
+
const newValue = targetNode.data;
|
|
33681
33714
|
// 创建日志条目并显示
|
|
33682
|
-
|
|
33715
|
+
console.log(`文本修改: ${oldValue} → ${newValue}`);
|
|
33683
33716
|
const parentElement = targetNode.parentNode;
|
|
33684
33717
|
processElement(parentElement);
|
|
33685
33718
|
}
|