isdata-customer-sdk 0.2.6 → 0.2.8

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.
@@ -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;
@@ -33524,12 +33530,12 @@ function checkPlatformElementContent(element) {
33524
33530
  }
33525
33531
  return checkContentResult;
33526
33532
  }
33527
-
33528
- // 处理DOM元素的函数
33529
33533
  function processElement(element) {
33530
- if (element.nodeType != 1) {
33534
+ // 仅处理元素节点
33535
+ if (element && element.nodeType != 1) {
33531
33536
  return false;
33532
33537
  }
33538
+
33533
33539
  // 如果元素有子元素,则不处理innerHTML
33534
33540
  const hasChildren = hasChildElements(element);
33535
33541
  if (hasChildren) {
@@ -33568,9 +33574,14 @@ function processElement(element) {
33568
33574
  let elementId = element.getAttribute("localDomID");
33569
33575
  if (!elementId) {
33570
33576
  elementId = generateUniqueId();
33577
+ } else {
33578
+ // 已经处理过的元素跳过
33579
+ return false;
33571
33580
  }
33572
33581
  element.setAttribute("localDomID", elementId);
33573
-
33582
+ if (!window.i18nElementsMap) {
33583
+ window.i18nElementsMap = new Map();
33584
+ }
33574
33585
  // 添加到Map缓存
33575
33586
  window.i18nElementsMap.set(elementId, {
33576
33587
  dom: element,
@@ -33583,18 +33594,18 @@ function processElement(element) {
33583
33594
  applyTranslation(element);
33584
33595
  return true;
33585
33596
  }
33586
- function unProcessElement(node) {
33587
- if (node.nodeType !== 1) {
33597
+ function unProcessElement(element) {
33598
+ if (element && element.nodeType !== 1) {
33588
33599
  return;
33589
33600
  }
33590
- const hasChildren = hasChildElements(element);
33591
- if (hasChildren) {
33592
- let children = element.children;
33593
- for (let i = 0; i < children.length; i++) {
33594
- unProcessElement(children[i]);
33595
- }
33596
- }
33597
- const localDomID = node.getAttribute("localDomID");
33601
+ // const hasChildren = hasChildElements(element);
33602
+ // if (hasChildren) {
33603
+ // let children = element.children;
33604
+ // for (let i = 0; i < children.length; i++) {
33605
+ // unProcessElement(children[i]);
33606
+ // }
33607
+ // }
33608
+ const localDomID = element.getAttribute("localDomID");
33598
33609
  if (localDomID && window.i18nElementsMap.has(localDomID)) {
33599
33610
  window.i18nElementsMap.delete(localDomID);
33600
33611
  console.log("移除元素缓存:", localDomID);
@@ -33650,34 +33661,40 @@ const initDomNodeI18NObserver = () => {
33650
33661
  console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
33651
33662
  // 遍历Map,更新每个已处理元素的翻译
33652
33663
  for (const [elementId, item] of window.i18nElementsMap.entries()) {
33664
+ console.log("更新元素翻译:", elementId, item.dom);
33653
33665
  applyTranslation(item.dom);
33654
33666
  }
33655
33667
  });
33656
33668
  // 创建观察器实例
33657
33669
  const observer = new MutationObserver(mutations => {
33658
33670
  mutations.forEach(mutation => {
33659
- // 节点添加
33660
- if (mutation.addedNodes.length > 0) {
33661
- // console.log("检测到新增节点:", mutation.addedNodes);
33662
- for (let i = 0; i < mutation.addedNodes.length; i++) {
33663
- const node = mutation.addedNodes[i];
33664
- processElement(node);
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
+ }
33665
33682
  }
33666
- }
33667
- // 节点移除
33668
- if (mutation.removedNodes.length > 0) {
33669
- for (let i = 0; i < mutation.removedNodes.length; i++) {
33670
- const node = mutation.removedNodes[i];
33671
- unProcessElement(node);
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
+ }
33672
33690
  }
33673
- }
33674
- if (mutation.type === 'characterData') {
33691
+ } else if (mutation.type === 'characterData') {
33675
33692
  // 处理文本变化
33676
- // const oldValue = mutation.oldValue;
33693
+ const oldValue = mutation.oldValue;
33677
33694
  const targetNode = mutation.target;
33678
- // const newValue = targetNode.data;
33695
+ const newValue = targetNode.data;
33679
33696
  // 创建日志条目并显示
33680
- // console.log(`文本修改: ${oldValue} → ${newValue}`);
33697
+ console.log(`文本修改: ${oldValue} → ${newValue}`);
33681
33698
  const parentElement = targetNode.parentNode;
33682
33699
  processElement(parentElement);
33683
33700
  }