isdata-customer-sdk 0.1.99 → 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.
@@ -33087,7 +33087,9 @@ const dify_extractFilenameFromUrl = url => {
33087
33087
  return "downloaded_file"; // URL 解析失败时的默认文件名
33088
33088
  }
33089
33089
  };
33090
- ;// ./src/api/smardaten_i18n/table_i18n.js
33090
+ ;// external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
33091
+ var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue");
33092
+ ;// ./src/api/i18n/smardaten_i18n/table_i18n.js
33091
33093
 
33092
33094
  const check = element => {
33093
33095
  const checkResult = {
@@ -33158,7 +33160,7 @@ const check = element => {
33158
33160
  }
33159
33161
  };
33160
33162
  let tempHTMLMatch = {
33161
- isScriptOldValue: true,
33163
+ isScriptAction: true,
33162
33164
  scriptFunction: scriptFunction
33163
33165
  };
33164
33166
  checkResult.result = true;
@@ -33207,7 +33209,7 @@ const check = element => {
33207
33209
  }
33208
33210
  };
33209
33211
  let tempHTMLMatch = {
33210
- isScriptOldValue: true,
33212
+ isScriptAction: true,
33211
33213
  scriptFunction: scriptFunction
33212
33214
  };
33213
33215
  checkResult.result = true;
@@ -33275,7 +33277,7 @@ const check = element => {
33275
33277
  }
33276
33278
  return checkResult;
33277
33279
  };
33278
- ;// ./src/api/smardaten_i18n/catalog_i18n.js
33280
+ ;// ./src/api/i18n/smardaten_i18n/catalog_i18n.js
33279
33281
 
33280
33282
  const catalog_i18n_check = element => {
33281
33283
  const checkResult = {
@@ -33309,7 +33311,7 @@ const catalog_i18n_check = element => {
33309
33311
  };
33310
33312
  let tempHTMLMatch = {
33311
33313
  oldValue: oldValue,
33312
- isScriptOldValue: true,
33314
+ isScriptAction: true,
33313
33315
  scriptFunction: scriptFunction
33314
33316
  };
33315
33317
  checkResult.result = true;
@@ -33318,7 +33320,94 @@ const catalog_i18n_check = element => {
33318
33320
  }
33319
33321
  return checkResult;
33320
33322
  };
33321
- ;// ./src/api/i18n.js
33323
+ ;// ./src/api/i18n/commom_i18n/common_i18n.js
33324
+
33325
+ const common_i18n_check = element => {
33326
+ const checkResult = {
33327
+ result: false,
33328
+ innerHTMLMatch: null
33329
+ };
33330
+ // 检查目录列表 名称 列
33331
+ if (element.tagName === 'BUTTON') {
33332
+ let innerHTML = element.innerHTML;
33333
+ let oldValue = innerHTML;
33334
+ console.log("检查 button 元素:", innerHTML);
33335
+ let scriptFunction = (appID, lang) => {
33336
+ for (let i = 0; i < element.childNodes.length; i++) {
33337
+ let scriptNodeItem = element.childNodes[i];
33338
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33339
+ let text = element.getAttribute("oldValue");
33340
+ let isTextMatch = checkTextFormat(text);
33341
+ if (!isTextMatch) {
33342
+ element.appendChild(scriptNodeItem);
33343
+ } else {
33344
+ element.removeChild(scriptNodeItem);
33345
+ let key = isTextMatch.key;
33346
+ let textNode = document.createTextNode(i18n(key, appID, lang) || key);
33347
+ element.appendChild(textNode);
33348
+ }
33349
+ } else {
33350
+ element.appendChild(scriptNodeItem);
33351
+ }
33352
+ }
33353
+ };
33354
+ let tempHTMLMatch = {
33355
+ oldValue: oldValue,
33356
+ isScriptAction: true,
33357
+ scriptFunction: scriptFunction
33358
+ };
33359
+ checkResult.result = true;
33360
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33361
+ return checkResult;
33362
+ }
33363
+ return checkResult;
33364
+ };
33365
+ ;// ./src/api/i18n/commom_i18n/attribute_i18n.js
33366
+
33367
+ const attribute_i18n_check = element => {
33368
+ const checkResult = {
33369
+ result: false,
33370
+ innerHTMLMatch: null
33371
+ };
33372
+ const checkAttributes = ["placeholder", "title"];
33373
+ for (let i = 0; i < checkAttributes.length; i++) {
33374
+ let attr = checkAttributes[i];
33375
+ let attrValue = element.getAttribute(attr) || element[attr];
33376
+ const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
33377
+ if (attrMatch) {
33378
+ console.log("检查元素属性 i18n 元素:", attr, attrValue);
33379
+ element.setAttribute(`old${attr}Value`, attrValue);
33380
+ checkResult.result = true;
33381
+ }
33382
+ }
33383
+ let scriptFunction = (appID, lang) => {
33384
+ for (let i = 0; i < checkAttributes.length; i++) {
33385
+ let attr = checkAttributes[i];
33386
+ const oldAttrValue = element.getAttribute(`old${attr}Value`);
33387
+ if (oldAttrValue) {
33388
+ // 创建正则表达式匹配所有 $L{...} 格式
33389
+ const regex = /\$L\{([^}]+)\}/g;
33390
+ // 替换所有 $L{...} 占位符为翻译文本
33391
+ let newAttrValue = oldAttrValue;
33392
+ let match;
33393
+ while ((match = regex.exec(oldAttrValue)) !== null) {
33394
+ const fullMatch = match[0];
33395
+ const attrKey = match[1];
33396
+ const translation = i18n(attrKey, appID, lang);
33397
+ newAttrValue = newAttrValue.replace(fullMatch, translation);
33398
+ }
33399
+ // 更新元素的placeholder属性
33400
+ element.setAttribute(attr, newAttrValue);
33401
+ }
33402
+ }
33403
+ };
33404
+ checkResult.scriptFunction = scriptFunction;
33405
+ return checkResult;
33406
+ };
33407
+ ;// ./src/api/i18n/i18n.js
33408
+
33409
+
33410
+
33322
33411
 
33323
33412
 
33324
33413
 
@@ -33390,41 +33479,20 @@ function generateUniqueId() {
33390
33479
  * @param {*} element
33391
33480
  * @returns
33392
33481
  */
33393
- function checkPlatformElement(element) {
33394
- const checkResult = {
33482
+ function checkPlatformElementContent(element) {
33483
+ const checkContentResult = {
33395
33484
  result: false,
33396
33485
  innerHTMLMatch: null
33397
33486
  };
33398
- let checkArr = [check, catalog_i18n_check];
33487
+ let checkArr = [check, catalog_i18n_check, common_i18n_check];
33399
33488
  for (let i = 0; i < checkArr.length; i++) {
33400
33489
  let checkFunc = checkArr[i];
33401
- let checkResult = checkFunc(element);
33402
- if (checkResult.result) {
33403
- return checkResult;
33490
+ let checkContentResult = checkFunc(element);
33491
+ if (checkContentResult.result) {
33492
+ return checkContentResult;
33404
33493
  }
33405
33494
  }
33406
- return checkResult;
33407
- }
33408
- function checkParantNodeNeedFiller(element) {
33409
- const filterTags = ["BUTTON"];
33410
- for (let tag of filterTags) {
33411
- if (element.tagName === tag) {
33412
- return false;
33413
- }
33414
- }
33415
- //当为目录列表时catalog_name_content
33416
- //当为表格单元格时ant-table-cell
33417
- //当为分页总数时total_pag_num
33418
- //当为分页每页条数选择时ant-pagination-options-quick-jumper
33419
- //当为分页下拉选择时ant-select-selection-item
33420
- //当为分页下拉选项时ant-select-item-option-content
33421
- 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"];
33422
- for (let cls of classes) {
33423
- if (element.classList.contains(cls)) {
33424
- return false;
33425
- }
33426
- }
33427
- return true;
33495
+ return checkContentResult;
33428
33496
  }
33429
33497
 
33430
33498
  // 处理DOM元素的函数
@@ -33439,33 +33507,32 @@ function processElement(element) {
33439
33507
  for (let i = 0; i < children.length; i++) {
33440
33508
  processElement(children[i]);
33441
33509
  }
33442
-
33443
- // 检查父亲性质节点是否需要被过滤
33444
- const isParentNodeNeedFilter = checkParantNodeNeedFiller(element);
33445
- if (isParentNodeNeedFilter) {
33446
- return false;
33447
- }
33448
33510
  }
33449
- // element.setAttribute("i18nProcessed", "true"); // 标记元素已被处理
33450
- // 检查placeholder是否匹配
33451
- const placeholder = element.getAttribute("placeholder") || element.placeholder;
33452
- const placeholderMatch = placeholder ? checkTextFormat(placeholder) : null;
33453
- const title = element.getAttribute("title") || element.title;
33454
- const titleMatch = title ? checkTextFormat(title) : null;
33455
33511
 
33456
33512
  // 检查innerHTML是否匹配(仅对没有子元素的元素)
33457
33513
  let innerHTMLMatch = null;
33458
- const innerHTML = element.innerHTML;
33459
- innerHTMLMatch = checkTextFormat(innerHTML);
33514
+ const attrCheckResult = attribute_i18n_check(element);
33515
+ if (attrCheckResult.result) {
33516
+ console.log("检查到属性匹配元素:", element);
33517
+ }
33460
33518
 
33461
33519
  //检查是否是smardaten平台元素
33462
- const checkResult = checkPlatformElement(element);
33463
- if (checkResult.result) {
33464
- innerHTMLMatch = checkResult.innerHTMLMatch;
33520
+ const checkContentResult = checkPlatformElementContent(element);
33521
+ if (checkContentResult.result) {
33522
+ innerHTMLMatch = checkContentResult.innerHTMLMatch;
33523
+ element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33524
+ } else {
33525
+ if (!hasChildren) {
33526
+ const innerHTML = element.innerHTML;
33527
+ innerHTMLMatch = checkTextFormat(innerHTML);
33528
+ if (innerHTMLMatch) {
33529
+ element.setAttribute("oldValue", element.innerHTML);
33530
+ }
33531
+ }
33465
33532
  }
33466
33533
 
33467
33534
  // 如果没有匹配的内容,则不处理
33468
- if (!placeholderMatch && !innerHTMLMatch && !checkResult.result && !titleMatch) {
33535
+ if (!innerHTMLMatch && !checkContentResult.result && !attrCheckResult.result) {
33469
33536
  return false;
33470
33537
  }
33471
33538
  let elementId = element.getAttribute("localDomID");
@@ -33474,36 +33541,14 @@ function processElement(element) {
33474
33541
  }
33475
33542
  element.setAttribute("localDomID", elementId);
33476
33543
 
33477
- // console.log("处理元素:", element, {
33478
- // placeholderMatch,
33479
- // valueMatch,
33480
- // innerHTMLMatch,
33481
- // });
33482
- // 处理placeholder
33483
- if (placeholderMatch) {
33484
- element.setAttribute("oldPlaceholderValue", placeholder);
33485
- }
33486
- if (titleMatch) {
33487
- element.setAttribute("oldTitleValue", title);
33488
- }
33489
-
33490
- // 处理innerHTML(仅对没有子元素的元素)
33491
- if (!hasChildren && innerHTMLMatch) {
33492
- element.setAttribute("oldValue", element.innerHTML);
33493
- }
33494
- if (checkResult.result) {
33495
- element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33496
- }
33497
-
33498
33544
  // 添加到Map缓存
33499
33545
  window.i18nElementsMap.set(elementId, {
33500
33546
  dom: element,
33501
33547
  id: elementId,
33502
- oldValue: innerHTMLMatch ? element.innerHTML : null,
33503
- oldPlaceholderValue: placeholderMatch ? placeholder : null,
33504
- oldTitleValue: titleMatch ? title : null,
33505
- isScriptOldValue: innerHTMLMatch ? innerHTMLMatch.isScriptOldValue || false : false,
33506
- scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null
33548
+ isScriptAction: innerHTMLMatch ? innerHTMLMatch.isScriptAction || false : false,
33549
+ scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null,
33550
+ isAttibuteAction: attrCheckResult.result,
33551
+ attrFunction: attrCheckResult.scriptFunction || null
33507
33552
  });
33508
33553
  applyTranslation(element);
33509
33554
  return true;
@@ -33537,66 +33582,31 @@ const applyTranslation = async element => {
33537
33582
  const elementId = element.getAttribute("localDomID");
33538
33583
  const cachedItem = window.i18nElementsMap.get(elementId);
33539
33584
  if (!cachedItem) return;
33540
- // 处理placeholder(如果是input元素)
33541
- if (cachedItem.oldPlaceholderValue) {
33542
- const oldPlaceholderValue = element.getAttribute("oldPlaceholderValue");
33543
- if (oldPlaceholderValue) {
33585
+ // 处理属性
33586
+ if (cachedItem.isAttibuteAction) {
33587
+ cachedItem.attrFunction(appID, lang);
33588
+ }
33589
+ // 处理innerHTML
33590
+ if (cachedItem.isScriptAction) {
33591
+ cachedItem.scriptFunction(appID, lang);
33592
+ } else {
33593
+ const oldValue = element.getAttribute("oldValue");
33594
+ if (oldValue) {
33544
33595
  // 创建正则表达式匹配所有 $L{...} 格式
33545
33596
  const regex = /\$L\{([^}]+)\}/g;
33546
33597
  // 替换所有 $L{...} 占位符为翻译文本
33547
- let newPlaceholderValue = oldPlaceholderValue;
33598
+ let newValue = oldValue;
33548
33599
  let match;
33549
- while ((match = regex.exec(oldPlaceholderValue)) !== null) {
33600
+ while ((match = regex.exec(oldValue)) !== null) {
33550
33601
  const fullMatch = match[0];
33551
33602
  const placeholderKey = match[1];
33552
33603
  const translation = i18n(placeholderKey, appID, lang);
33553
- newPlaceholderValue = newPlaceholderValue.replace(fullMatch, translation);
33554
- }
33555
- // 更新元素的placeholder属性
33556
- element.setAttribute("placeholder", newPlaceholderValue);
33557
- }
33558
- }
33559
- if (cachedItem.oldTitleValue) {
33560
- const oldTitleValue = element.getAttribute("oldTitleValue");
33561
- if (oldTitleValue) {
33562
- // 创建正则表达式匹配所有 $L{...} 格式
33563
- const regex = /\$L\{([^}]+)\}/g;
33564
- // 替换所有 $L{...} 占位符为翻译文本
33565
- let newTitleValue = oldTitleValue;
33566
- let match;
33567
- while ((match = regex.exec(oldTitleValue)) !== null) {
33568
- const fullMatch = match[0];
33569
- const titleKey = match[1];
33570
- const translation = i18n(titleKey, appID, lang);
33571
- newTitleValue = newTitleValue.replace(fullMatch, translation);
33572
- // 更新元素的title属性
33573
- element.setAttribute("title", newTitleValue);
33574
- }
33575
- }
33576
- }
33577
- // console.log("更新innerHTML翻译:", element);
33578
- if (cachedItem.isScriptOldValue) {
33579
- cachedItem.scriptFunction(appID, lang);
33580
- } else {
33581
- if (cachedItem.oldValue) {
33582
- const oldValue = element.getAttribute("oldValue");
33583
- if (oldValue) {
33584
- // 创建正则表达式匹配所有 $L{...} 格式
33585
- const regex = /\$L\{([^}]+)\}/g;
33586
- // 替换所有 $L{...} 占位符为翻译文本
33587
- let newValue = oldValue;
33588
- let match;
33589
- while ((match = regex.exec(oldValue)) !== null) {
33590
- const fullMatch = match[0];
33591
- const placeholderKey = match[1];
33592
- const translation = i18n(placeholderKey, appID, lang);
33593
- newValue = newValue.replace(fullMatch, translation);
33594
- }
33595
- nextTick(() => {
33596
- // 更新元素的innerHTML
33597
- element.innerHTML = newValue;
33598
- });
33604
+ newValue = newValue.replace(fullMatch, translation);
33599
33605
  }
33606
+ (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.nextTick)(() => {
33607
+ // 更新元素的innerHTML
33608
+ element.innerHTML = newValue;
33609
+ });
33600
33610
  }
33601
33611
  }
33602
33612
  };