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.
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;
@@ -33542,12 +33548,12 @@ function checkPlatformElementContent(element) {
33542
33548
  }
33543
33549
  return checkContentResult;
33544
33550
  }
33545
-
33546
- // 处理DOM元素的函数
33547
33551
  function processElement(element) {
33548
- if (element.nodeType != 1) {
33552
+ // 仅处理元素节点
33553
+ if (element && element.nodeType != 1) {
33549
33554
  return false;
33550
33555
  }
33556
+
33551
33557
  // 如果元素有子元素,则不处理innerHTML
33552
33558
  const hasChildren = hasChildElements(element);
33553
33559
  if (hasChildren) {
@@ -33586,9 +33592,14 @@ function processElement(element) {
33586
33592
  let elementId = element.getAttribute("localDomID");
33587
33593
  if (!elementId) {
33588
33594
  elementId = generateUniqueId();
33595
+ } else {
33596
+ // 已经处理过的元素跳过
33597
+ return false;
33589
33598
  }
33590
33599
  element.setAttribute("localDomID", elementId);
33591
-
33600
+ if (!window.i18nElementsMap) {
33601
+ window.i18nElementsMap = new Map();
33602
+ }
33592
33603
  // 添加到Map缓存
33593
33604
  window.i18nElementsMap.set(elementId, {
33594
33605
  dom: element,
@@ -33601,18 +33612,18 @@ function processElement(element) {
33601
33612
  applyTranslation(element);
33602
33613
  return true;
33603
33614
  }
33604
- function unProcessElement(node) {
33605
- if (node.nodeType !== 1) {
33615
+ function unProcessElement(element) {
33616
+ if (element && element.nodeType !== 1) {
33606
33617
  return;
33607
33618
  }
33608
- const hasChildren = hasChildElements(element);
33609
- if (hasChildren) {
33610
- let children = element.children;
33611
- for (let i = 0; i < children.length; i++) {
33612
- unProcessElement(children[i]);
33613
- }
33614
- }
33615
- const localDomID = node.getAttribute("localDomID");
33619
+ // const hasChildren = hasChildElements(element);
33620
+ // if (hasChildren) {
33621
+ // let children = element.children;
33622
+ // for (let i = 0; i < children.length; i++) {
33623
+ // unProcessElement(children[i]);
33624
+ // }
33625
+ // }
33626
+ const localDomID = element.getAttribute("localDomID");
33616
33627
  if (localDomID && window.i18nElementsMap.has(localDomID)) {
33617
33628
  window.i18nElementsMap.delete(localDomID);
33618
33629
  console.log("移除元素缓存:", localDomID);
@@ -33668,34 +33679,40 @@ const initDomNodeI18NObserver = () => {
33668
33679
  console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
33669
33680
  // 遍历Map,更新每个已处理元素的翻译
33670
33681
  for (const [elementId, item] of window.i18nElementsMap.entries()) {
33682
+ console.log("更新元素翻译:", elementId, item.dom);
33671
33683
  applyTranslation(item.dom);
33672
33684
  }
33673
33685
  });
33674
33686
  // 创建观察器实例
33675
33687
  const observer = new MutationObserver(mutations => {
33676
33688
  mutations.forEach(mutation => {
33677
- // 节点添加
33678
- if (mutation.addedNodes.length > 0) {
33679
- // console.log("检测到新增节点:", mutation.addedNodes);
33680
- for (let i = 0; i < mutation.addedNodes.length; i++) {
33681
- const node = mutation.addedNodes[i];
33682
- processElement(node);
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
+ }
33683
33700
  }
33684
- }
33685
- // 节点移除
33686
- if (mutation.removedNodes.length > 0) {
33687
- for (let i = 0; i < mutation.removedNodes.length; i++) {
33688
- const node = mutation.removedNodes[i];
33689
- unProcessElement(node);
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
+ }
33690
33708
  }
33691
- }
33692
- if (mutation.type === 'characterData') {
33709
+ } else if (mutation.type === 'characterData') {
33693
33710
  // 处理文本变化
33694
- // const oldValue = mutation.oldValue;
33711
+ const oldValue = mutation.oldValue;
33695
33712
  const targetNode = mutation.target;
33696
- // const newValue = targetNode.data;
33713
+ const newValue = targetNode.data;
33697
33714
  // 创建日志条目并显示
33698
- // console.log(`文本修改: ${oldValue} → ${newValue}`);
33715
+ console.log(`文本修改: ${oldValue} → ${newValue}`);
33699
33716
  const parentElement = targetNode.parentNode;
33700
33717
  processElement(parentElement);
33701
33718
  }