isdata-customer-sdk 0.1.100 → 0.2.1

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
@@ -33107,7 +33107,7 @@ const dify_extractFilenameFromUrl = url => {
33107
33107
  };
33108
33108
  // EXTERNAL MODULE: external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
33109
33109
  var external_commonjs_vue_commonjs2_vue_root_Vue_ = __webpack_require__(9274);
33110
- ;// ./src/api/smardaten_i18n/table_i18n.js
33110
+ ;// ./src/api/i18n/smardaten_i18n/table_i18n.js
33111
33111
 
33112
33112
  const check = element => {
33113
33113
  const checkResult = {
@@ -33178,7 +33178,7 @@ const check = element => {
33178
33178
  }
33179
33179
  };
33180
33180
  let tempHTMLMatch = {
33181
- isScriptOldValue: true,
33181
+ isScriptAction: true,
33182
33182
  scriptFunction: scriptFunction
33183
33183
  };
33184
33184
  checkResult.result = true;
@@ -33227,7 +33227,7 @@ const check = element => {
33227
33227
  }
33228
33228
  };
33229
33229
  let tempHTMLMatch = {
33230
- isScriptOldValue: true,
33230
+ isScriptAction: true,
33231
33231
  scriptFunction: scriptFunction
33232
33232
  };
33233
33233
  checkResult.result = true;
@@ -33295,7 +33295,7 @@ const check = element => {
33295
33295
  }
33296
33296
  return checkResult;
33297
33297
  };
33298
- ;// ./src/api/smardaten_i18n/catalog_i18n.js
33298
+ ;// ./src/api/i18n/smardaten_i18n/catalog_i18n.js
33299
33299
 
33300
33300
  const catalog_i18n_check = element => {
33301
33301
  const checkResult = {
@@ -33329,7 +33329,7 @@ const catalog_i18n_check = element => {
33329
33329
  };
33330
33330
  let tempHTMLMatch = {
33331
33331
  oldValue: oldValue,
33332
- isScriptOldValue: true,
33332
+ isScriptAction: true,
33333
33333
  scriptFunction: scriptFunction
33334
33334
  };
33335
33335
  checkResult.result = true;
@@ -33338,7 +33338,93 @@ const catalog_i18n_check = element => {
33338
33338
  }
33339
33339
  return checkResult;
33340
33340
  };
33341
- ;// ./src/api/i18n.js
33341
+ ;// ./src/api/i18n/commom_i18n/common_i18n.js
33342
+
33343
+ const common_i18n_check = element => {
33344
+ const checkResult = {
33345
+ result: false,
33346
+ innerHTMLMatch: null
33347
+ };
33348
+ // 检查目录列表 名称 列
33349
+ if (element.tagName === 'BUTTON') {
33350
+ let innerHTML = element.innerHTML;
33351
+ let oldValue = innerHTML;
33352
+ console.log("检查 button 元素:", innerHTML);
33353
+ let scriptFunction = (appID, lang) => {
33354
+ for (let i = 0; i < element.childNodes.length; i++) {
33355
+ let scriptNodeItem = element.childNodes[i];
33356
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33357
+ let text = element.getAttribute("oldValue");
33358
+ let isTextMatch = checkTextFormat(text);
33359
+ if (!isTextMatch) {
33360
+ element.appendChild(scriptNodeItem);
33361
+ } else {
33362
+ element.removeChild(scriptNodeItem);
33363
+ let key = isTextMatch.key;
33364
+ let textNode = document.createTextNode(i18n(key, appID, lang) || key);
33365
+ element.appendChild(textNode);
33366
+ }
33367
+ } else {
33368
+ element.appendChild(scriptNodeItem);
33369
+ }
33370
+ }
33371
+ };
33372
+ let tempHTMLMatch = {
33373
+ oldValue: oldValue,
33374
+ isScriptAction: true,
33375
+ scriptFunction: scriptFunction
33376
+ };
33377
+ checkResult.result = true;
33378
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33379
+ return checkResult;
33380
+ }
33381
+ return checkResult;
33382
+ };
33383
+ ;// ./src/api/i18n/commom_i18n/attribute_i18n.js
33384
+
33385
+ const attribute_i18n_check = element => {
33386
+ const checkResult = {
33387
+ result: false,
33388
+ innerHTMLMatch: null
33389
+ };
33390
+ const checkAttributes = ["placeholder", "title"];
33391
+ for (let i = 0; i < checkAttributes.length; i++) {
33392
+ let attr = checkAttributes[i];
33393
+ let attrValue = element.getAttribute(attr) || element[attr];
33394
+ const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
33395
+ if (attrMatch) {
33396
+ console.log("检查元素属性 i18n 元素:", attr, attrValue);
33397
+ element.setAttribute(`old${attr}Value`, attrValue);
33398
+ checkResult.result = true;
33399
+ }
33400
+ }
33401
+ let scriptFunction = (appID, lang) => {
33402
+ for (let i = 0; i < checkAttributes.length; i++) {
33403
+ let attr = checkAttributes[i];
33404
+ const oldAttrValue = element.getAttribute(`old${attr}Value`);
33405
+ if (oldAttrValue) {
33406
+ // 创建正则表达式匹配所有 $L{...} 格式
33407
+ const regex = /\$L\{([^}]+)\}/g;
33408
+ // 替换所有 $L{...} 占位符为翻译文本
33409
+ let newAttrValue = oldAttrValue;
33410
+ let match;
33411
+ while ((match = regex.exec(oldAttrValue)) !== null) {
33412
+ const fullMatch = match[0];
33413
+ const attrKey = match[1];
33414
+ const translation = i18n(attrKey, appID, lang);
33415
+ newAttrValue = newAttrValue.replace(fullMatch, translation);
33416
+ }
33417
+ // 更新元素的placeholder属性
33418
+ element.setAttribute(attr, newAttrValue);
33419
+ }
33420
+ }
33421
+ };
33422
+ checkResult.scriptFunction = scriptFunction;
33423
+ return checkResult;
33424
+ };
33425
+ ;// ./src/api/i18n/i18n.js
33426
+
33427
+
33342
33428
 
33343
33429
 
33344
33430
 
@@ -33411,41 +33497,20 @@ function generateUniqueId() {
33411
33497
  * @param {*} element
33412
33498
  * @returns
33413
33499
  */
33414
- function checkPlatformElement(element) {
33415
- const checkResult = {
33500
+ function checkPlatformElementContent(element) {
33501
+ const checkContentResult = {
33416
33502
  result: false,
33417
33503
  innerHTMLMatch: null
33418
33504
  };
33419
- let checkArr = [check, catalog_i18n_check];
33505
+ let checkArr = [check, catalog_i18n_check, common_i18n_check];
33420
33506
  for (let i = 0; i < checkArr.length; i++) {
33421
33507
  let checkFunc = checkArr[i];
33422
- let checkResult = checkFunc(element);
33423
- if (checkResult.result) {
33424
- return checkResult;
33508
+ let checkContentResult = checkFunc(element);
33509
+ if (checkContentResult.result) {
33510
+ return checkContentResult;
33425
33511
  }
33426
33512
  }
33427
- return checkResult;
33428
- }
33429
- function checkParantNodeNeedFiller(element) {
33430
- const filterTags = ["BUTTON"];
33431
- for (let tag of filterTags) {
33432
- if (element.tagName === tag) {
33433
- return false;
33434
- }
33435
- }
33436
- //当为目录列表时catalog_name_content
33437
- //当为表格单元格时ant-table-cell
33438
- //当为分页总数时total_pag_num
33439
- //当为分页每页条数选择时ant-pagination-options-quick-jumper
33440
- //当为分页下拉选择时ant-select-selection-item
33441
- //当为分页下拉选项时ant-select-item-option-content
33442
- const classes = ["catalog_name_content", "ant-table-cell", "total_pag_num", "ant-pagination-options-quick-jumper", "ant-select-selection-item", "ant-select-item-option-content", "catalog_name_content", "catalog_tree_node"];
33443
- for (let cls of classes) {
33444
- if (element.classList.contains(cls)) {
33445
- return false;
33446
- }
33447
- }
33448
- return true;
33513
+ return checkContentResult;
33449
33514
  }
33450
33515
 
33451
33516
  // 处理DOM元素的函数
@@ -33460,33 +33525,32 @@ function processElement(element) {
33460
33525
  for (let i = 0; i < children.length; i++) {
33461
33526
  processElement(children[i]);
33462
33527
  }
33463
-
33464
- // 检查父亲性质节点是否需要被过滤
33465
- const isParentNodeNeedFilter = checkParantNodeNeedFiller(element);
33466
- if (isParentNodeNeedFilter) {
33467
- return false;
33468
- }
33469
33528
  }
33470
- // element.setAttribute("i18nProcessed", "true"); // 标记元素已被处理
33471
- // 检查placeholder是否匹配
33472
- const placeholder = element.getAttribute("placeholder") || element.placeholder;
33473
- const placeholderMatch = placeholder ? checkTextFormat(placeholder) : null;
33474
- const title = element.getAttribute("title") || element.title;
33475
- const titleMatch = title ? checkTextFormat(title) : null;
33476
33529
 
33477
33530
  // 检查innerHTML是否匹配(仅对没有子元素的元素)
33478
33531
  let innerHTMLMatch = null;
33479
- const innerHTML = element.innerHTML;
33480
- innerHTMLMatch = checkTextFormat(innerHTML);
33532
+ const attrCheckResult = attribute_i18n_check(element);
33533
+ if (attrCheckResult.result) {
33534
+ console.log("检查到属性匹配元素:", element);
33535
+ }
33481
33536
 
33482
33537
  //检查是否是smardaten平台元素
33483
- const checkResult = checkPlatformElement(element);
33484
- if (checkResult.result) {
33485
- innerHTMLMatch = checkResult.innerHTMLMatch;
33538
+ const checkContentResult = checkPlatformElementContent(element);
33539
+ if (checkContentResult.result) {
33540
+ innerHTMLMatch = checkContentResult.innerHTMLMatch;
33541
+ element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33542
+ } else {
33543
+ if (!hasChildren) {
33544
+ const innerHTML = element.innerHTML;
33545
+ innerHTMLMatch = checkTextFormat(innerHTML);
33546
+ if (innerHTMLMatch) {
33547
+ element.setAttribute("oldValue", element.innerHTML);
33548
+ }
33549
+ }
33486
33550
  }
33487
33551
 
33488
33552
  // 如果没有匹配的内容,则不处理
33489
- if (!placeholderMatch && !innerHTMLMatch && !checkResult.result && !titleMatch) {
33553
+ if (!innerHTMLMatch && !checkContentResult.result && !attrCheckResult.result) {
33490
33554
  return false;
33491
33555
  }
33492
33556
  let elementId = element.getAttribute("localDomID");
@@ -33495,36 +33559,14 @@ function processElement(element) {
33495
33559
  }
33496
33560
  element.setAttribute("localDomID", elementId);
33497
33561
 
33498
- // console.log("处理元素:", element, {
33499
- // placeholderMatch,
33500
- // valueMatch,
33501
- // innerHTMLMatch,
33502
- // });
33503
- // 处理placeholder
33504
- if (placeholderMatch) {
33505
- element.setAttribute("oldPlaceholderValue", placeholder);
33506
- }
33507
- if (titleMatch) {
33508
- element.setAttribute("oldTitleValue", title);
33509
- }
33510
-
33511
- // 处理innerHTML(仅对没有子元素的元素)
33512
- if (!hasChildren && innerHTMLMatch) {
33513
- element.setAttribute("oldValue", element.innerHTML);
33514
- }
33515
- if (checkResult.result) {
33516
- element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33517
- }
33518
-
33519
33562
  // 添加到Map缓存
33520
33563
  window.i18nElementsMap.set(elementId, {
33521
33564
  dom: element,
33522
33565
  id: elementId,
33523
- oldValue: innerHTMLMatch ? element.innerHTML : null,
33524
- oldPlaceholderValue: placeholderMatch ? placeholder : null,
33525
- oldTitleValue: titleMatch ? title : null,
33526
- isScriptOldValue: innerHTMLMatch ? innerHTMLMatch.isScriptOldValue || false : false,
33527
- scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null
33566
+ isScriptAction: innerHTMLMatch ? innerHTMLMatch.isScriptAction || false : false,
33567
+ scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null,
33568
+ isAttibuteAction: attrCheckResult.result,
33569
+ attrFunction: attrCheckResult.scriptFunction || null
33528
33570
  });
33529
33571
  applyTranslation(element);
33530
33572
  return true;
@@ -33558,66 +33600,31 @@ const applyTranslation = async element => {
33558
33600
  const elementId = element.getAttribute("localDomID");
33559
33601
  const cachedItem = window.i18nElementsMap.get(elementId);
33560
33602
  if (!cachedItem) return;
33561
- // 处理placeholder(如果是input元素)
33562
- if (cachedItem.oldPlaceholderValue) {
33563
- const oldPlaceholderValue = element.getAttribute("oldPlaceholderValue");
33564
- if (oldPlaceholderValue) {
33603
+ // 处理属性
33604
+ if (cachedItem.isAttibuteAction) {
33605
+ cachedItem.attrFunction(appID, lang);
33606
+ }
33607
+ // 处理innerHTML
33608
+ if (cachedItem.isScriptAction) {
33609
+ cachedItem.scriptFunction(appID, lang);
33610
+ } else {
33611
+ const oldValue = element.getAttribute("oldValue");
33612
+ if (oldValue) {
33565
33613
  // 创建正则表达式匹配所有 $L{...} 格式
33566
33614
  const regex = /\$L\{([^}]+)\}/g;
33567
33615
  // 替换所有 $L{...} 占位符为翻译文本
33568
- let newPlaceholderValue = oldPlaceholderValue;
33616
+ let newValue = oldValue;
33569
33617
  let match;
33570
- while ((match = regex.exec(oldPlaceholderValue)) !== null) {
33618
+ while ((match = regex.exec(oldValue)) !== null) {
33571
33619
  const fullMatch = match[0];
33572
33620
  const placeholderKey = match[1];
33573
33621
  const translation = i18n(placeholderKey, appID, lang);
33574
- newPlaceholderValue = newPlaceholderValue.replace(fullMatch, translation);
33575
- }
33576
- // 更新元素的placeholder属性
33577
- element.setAttribute("placeholder", newPlaceholderValue);
33578
- }
33579
- }
33580
- if (cachedItem.oldTitleValue) {
33581
- const oldTitleValue = element.getAttribute("oldTitleValue");
33582
- if (oldTitleValue) {
33583
- // 创建正则表达式匹配所有 $L{...} 格式
33584
- const regex = /\$L\{([^}]+)\}/g;
33585
- // 替换所有 $L{...} 占位符为翻译文本
33586
- let newTitleValue = oldTitleValue;
33587
- let match;
33588
- while ((match = regex.exec(oldTitleValue)) !== null) {
33589
- const fullMatch = match[0];
33590
- const titleKey = match[1];
33591
- const translation = i18n(titleKey, appID, lang);
33592
- newTitleValue = newTitleValue.replace(fullMatch, translation);
33593
- // 更新元素的title属性
33594
- element.setAttribute("title", newTitleValue);
33595
- }
33596
- }
33597
- }
33598
- // console.log("更新innerHTML翻译:", element);
33599
- if (cachedItem.isScriptOldValue) {
33600
- cachedItem.scriptFunction(appID, lang);
33601
- } else {
33602
- if (cachedItem.oldValue) {
33603
- const oldValue = element.getAttribute("oldValue");
33604
- if (oldValue) {
33605
- // 创建正则表达式匹配所有 $L{...} 格式
33606
- const regex = /\$L\{([^}]+)\}/g;
33607
- // 替换所有 $L{...} 占位符为翻译文本
33608
- let newValue = oldValue;
33609
- let match;
33610
- while ((match = regex.exec(oldValue)) !== null) {
33611
- const fullMatch = match[0];
33612
- const placeholderKey = match[1];
33613
- const translation = i18n(placeholderKey, appID, lang);
33614
- newValue = newValue.replace(fullMatch, translation);
33615
- }
33616
- (0,external_commonjs_vue_commonjs2_vue_root_Vue_.nextTick)(() => {
33617
- // 更新元素的innerHTML
33618
- element.innerHTML = newValue;
33619
- });
33622
+ newValue = newValue.replace(fullMatch, translation);
33620
33623
  }
33624
+ (0,external_commonjs_vue_commonjs2_vue_root_Vue_.nextTick)(() => {
33625
+ // 更新元素的innerHTML
33626
+ element.innerHTML = newValue;
33627
+ });
33621
33628
  }
33622
33629
  }
33623
33630
  };