@gingkoo/pandora-metabase 1.0.158-alpha.2 → 1.0.158-alpha.21

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.
Files changed (145) hide show
  1. package/lib/cjs/common/SplitView/index.js +2 -2
  2. package/lib/cjs/components/dialog/column-type-label/index.d.ts +8 -0
  3. package/lib/cjs/components/dialog/column-type-label/index.js +22 -0
  4. package/lib/cjs/components/dialog/column-type-label/index.less +17 -0
  5. package/lib/cjs/components/dialog/custom-column/config.js +2 -2
  6. package/lib/cjs/components/dialog/custom-column/expression-editor.js +1 -1
  7. package/lib/cjs/components/dialog/custom-column/expressions/suggest.js +2 -2
  8. package/lib/cjs/components/dialog/custom-column/expressions/tokenizer.js +2 -2
  9. package/lib/cjs/components/dialog/custom-column/index.js +2 -2
  10. package/lib/cjs/components/dialog/custom-column/tokenized-expression.js +6 -6
  11. package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +8 -8
  12. package/lib/cjs/components/dialog/custom-editor/index.js +4 -4
  13. package/lib/cjs/components/dialog/expression/date-format-picker.js +1 -1
  14. package/lib/cjs/components/dialog/expression/index.js +4 -4
  15. package/lib/cjs/components/dialog/formula/index.js +55 -14
  16. package/lib/cjs/components/dialog/formula/index.less +7 -0
  17. package/lib/cjs/components/dialog/formula/utils.js +5 -1
  18. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +3 -4
  19. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +138 -214
  20. package/lib/cjs/components/dialog/formula-list/LogicGroup.js +55 -39
  21. package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -0
  22. package/lib/cjs/components/dialog/formula-list/index.js +414 -321
  23. package/lib/cjs/components/dialog/formula-list/index.less +1012 -1105
  24. package/lib/cjs/components/dialog/formula-list/utils.d.ts +16 -2
  25. package/lib/cjs/components/dialog/formula-list/utils.js +650 -131
  26. package/lib/cjs/components/dialog/select-column/index.js +10 -4
  27. package/lib/cjs/components/dialog/select-column/index.less +6 -1
  28. package/lib/cjs/components/dialog/select-column-multiple/index.js +12 -9
  29. package/lib/cjs/components/dialog/select-column-multiple/index.less +10 -0
  30. package/lib/cjs/components/dialog/select-join-column/index.js +9 -5
  31. package/lib/cjs/components/dialog/select-join-column/index.less +10 -0
  32. package/lib/cjs/components/dialog/select-join-column-multiple/index.js +10 -6
  33. package/lib/cjs/components/dialog/select-join-column-multiple/index.less +10 -0
  34. package/lib/cjs/components/dialog/select-permission-table/index.js +1 -1
  35. package/lib/cjs/components/dialog/select-summarize/index.js +2 -2
  36. package/lib/cjs/components/dialog/select-table/index.js +5 -5
  37. package/lib/cjs/components/icons.js +1 -1
  38. package/lib/cjs/components/metabase/index.js +129 -60
  39. package/lib/cjs/components/metabase/index.less +28 -29
  40. package/lib/cjs/components/modules/components/Wrapper.js +2 -2
  41. package/lib/cjs/components/modules/components/header.d.ts +2 -1
  42. package/lib/cjs/components/modules/components/header.js +7 -3
  43. package/lib/cjs/components/modules/components/item-wrapper.js +1 -1
  44. package/lib/cjs/components/modules/components/meta-icon.js +3 -5
  45. package/lib/cjs/components/modules/custom-column.js +7 -4
  46. package/lib/cjs/components/modules/filter.js +2 -2
  47. package/lib/cjs/components/modules/join-data.js +100 -21
  48. package/lib/cjs/components/modules/sort.js +6 -3
  49. package/lib/cjs/components/modules/summarize/group-by.js +10 -6
  50. package/lib/cjs/components/modules/summarize/select-index.js +12 -5
  51. package/lib/cjs/components/modules/table-data.js +50 -16
  52. package/lib/cjs/components/popup.js +7 -7
  53. package/lib/cjs/components/right-click-menu.js +3 -3
  54. package/lib/cjs/components/sql-syntax-confirm.d.ts +14 -0
  55. package/lib/cjs/components/sql-syntax-confirm.js +149 -0
  56. package/lib/cjs/enum.d.ts +1 -0
  57. package/lib/cjs/enum.js +16 -0
  58. package/lib/cjs/hooks/patch.js +1 -1
  59. package/lib/cjs/hooks/patch2.js +1 -1
  60. package/lib/cjs/hooks/use-state.js +118 -111
  61. package/lib/cjs/hooks/winsize.js +1 -1
  62. package/lib/cjs/index.d.ts +4 -2
  63. package/lib/cjs/index.js +14 -6
  64. package/lib/cjs/locale/en.js +35 -0
  65. package/lib/cjs/locale/zh.js +35 -0
  66. package/lib/cjs/prompt.d.ts +3 -0
  67. package/lib/cjs/prompt.js +262 -0
  68. package/lib/cjs/store/enum.d.ts +50 -0
  69. package/lib/cjs/store/enum.js +56 -2
  70. package/lib/cjs/store/helper.js +2 -2
  71. package/lib/cjs/store/types.d.ts +9 -52
  72. package/lib/cjs/store/types.js +25 -54
  73. package/lib/cjs/types.d.ts +6 -0
  74. package/lib/cjs/utils/event.js +3 -3
  75. package/lib/cjs/utils/helper.js +1 -1
  76. package/lib/cjs/utils/keydown.js +2 -2
  77. package/lib/cjs/utils/selection.js +1 -1
  78. package/lib/cjs/utils/storage.js +2 -2
  79. package/lib/cjs/utils/transformSql.d.ts +44 -1
  80. package/lib/cjs/utils/transformSql.js +1042 -29
  81. package/lib/cjs/utils.d.ts +3 -1
  82. package/lib/cjs/utils.js +82 -43
  83. package/lib/cjs/validate.d.ts +2 -0
  84. package/lib/cjs/validate.js +42 -0
  85. package/lib/es/components/dialog/column-type-label/index.d.ts +8 -0
  86. package/lib/es/components/dialog/column-type-label/index.js +16 -0
  87. package/lib/es/components/dialog/column-type-label/index.less +17 -0
  88. package/lib/es/components/dialog/expression/index.js +1 -1
  89. package/lib/es/components/dialog/formula/index.js +53 -12
  90. package/lib/es/components/dialog/formula/index.less +7 -0
  91. package/lib/es/components/dialog/formula/utils.js +5 -1
  92. package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +3 -4
  93. package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +141 -217
  94. package/lib/es/components/dialog/formula-list/LogicGroup.js +54 -38
  95. package/lib/es/components/dialog/formula-list/index.d.ts +3 -0
  96. package/lib/es/components/dialog/formula-list/index.js +409 -316
  97. package/lib/es/components/dialog/formula-list/index.less +1012 -1105
  98. package/lib/es/components/dialog/formula-list/utils.d.ts +16 -2
  99. package/lib/es/components/dialog/formula-list/utils.js +646 -126
  100. package/lib/es/components/dialog/select-column/index.js +7 -1
  101. package/lib/es/components/dialog/select-column/index.less +6 -1
  102. package/lib/es/components/dialog/select-column-multiple/index.js +9 -6
  103. package/lib/es/components/dialog/select-column-multiple/index.less +10 -0
  104. package/lib/es/components/dialog/select-join-column/index.js +7 -3
  105. package/lib/es/components/dialog/select-join-column/index.less +10 -0
  106. package/lib/es/components/dialog/select-join-column-multiple/index.js +7 -3
  107. package/lib/es/components/dialog/select-join-column-multiple/index.less +10 -0
  108. package/lib/es/components/metabase/index.js +126 -57
  109. package/lib/es/components/metabase/index.less +28 -29
  110. package/lib/es/components/modules/components/header.d.ts +2 -1
  111. package/lib/es/components/modules/components/header.js +6 -2
  112. package/lib/es/components/modules/components/meta-icon.js +2 -4
  113. package/lib/es/components/modules/custom-column.js +4 -1
  114. package/lib/es/components/modules/join-data.js +98 -19
  115. package/lib/es/components/modules/sort.js +4 -1
  116. package/lib/es/components/modules/summarize/group-by.js +5 -1
  117. package/lib/es/components/modules/summarize/select-index.js +8 -1
  118. package/lib/es/components/modules/table-data.js +47 -13
  119. package/lib/es/components/sql-syntax-confirm.d.ts +14 -0
  120. package/lib/es/components/sql-syntax-confirm.js +142 -0
  121. package/lib/es/enum.d.ts +1 -0
  122. package/lib/es/enum.js +1 -0
  123. package/lib/es/hooks/use-state.js +112 -105
  124. package/lib/es/index.d.ts +4 -2
  125. package/lib/es/index.js +8 -6
  126. package/lib/es/locale/en.js +35 -0
  127. package/lib/es/locale/zh.js +35 -0
  128. package/lib/es/prompt.d.ts +3 -0
  129. package/lib/es/prompt.js +3 -0
  130. package/lib/es/store/enum.d.ts +50 -0
  131. package/lib/es/store/enum.js +55 -1
  132. package/lib/es/store/types.d.ts +9 -52
  133. package/lib/es/store/types.js +2 -53
  134. package/lib/es/types.d.ts +6 -0
  135. package/lib/es/utils/transformSql.d.ts +44 -1
  136. package/lib/es/utils/transformSql.js +1038 -25
  137. package/lib/es/utils.d.ts +3 -1
  138. package/lib/es/utils.js +76 -37
  139. package/lib/es/validate.d.ts +2 -0
  140. package/lib/es/validate.js +1 -0
  141. package/package.json +31 -1
  142. package/lib/cjs/components/dialog/diff-viewer/index copy.d.ts +0 -10
  143. package/lib/cjs/components/dialog/diff-viewer/index copy.js +0 -139
  144. package/lib/es/components/dialog/diff-viewer/index copy.d.ts +0 -10
  145. package/lib/es/components/dialog/diff-viewer/index copy.js +0 -132
package/lib/es/utils.d.ts CHANGED
@@ -36,7 +36,9 @@ export declare const normalizeLegacySummarizeForSave: (metas?: MetaListType[]) =
36
36
  export declare const getObjTem: (arr: any[]) => any;
37
37
  export declare const patchData: (metas: MetaListType[], constantList?: any, formulaTemplates?: any) => MetaListType[];
38
38
  export declare function reassembleByUnion(target?: any[]): any[];
39
- export declare const buildSqlQuery: (data: MetaListType[] | undefined, type: string) => string;
39
+ export declare const buildSqlQuery: (data: MetaListType[] | undefined, type: string, db?: "mysql" | "oracle" | "sqlserver") => string;
40
+ export type FieldReferenceError = 'table' | 'field' | null;
41
+ export declare const getFieldReferenceError: (item: AtomsItem | AtomsItem[], data?: DataType[]) => FieldReferenceError;
40
42
  export declare const isError: (item: AtomsItem | AtomsItem[], data?: DataType[]) => boolean;
41
43
  export declare function containsSubset(root: unknown, target: Record<string, unknown>): boolean;
42
44
  export declare const isExistsError: (meta: any[], errorList: any[]) => boolean;
package/lib/es/utils.js CHANGED
@@ -611,6 +611,9 @@ var _getAtomDisplayText = function getAtomDisplayText(item) {
611
611
  if (item.type === AtomsTypeEnum.SELECT) {
612
612
  return getSelectAtomText(item);
613
613
  }
614
+ if (item.type === AtomsTypeEnum.INPUT_STRING && item.val === '') {
615
+ return "''";
616
+ }
614
617
  if (item.type === AtomsTypeEnum.EXISTS || item.type === AtomsTypeEnum.NOT_EXISTS || item.type === AtomsTypeEnum.SUB_QUERY) {
615
618
  return item.quotes || '';
616
619
  }
@@ -1559,6 +1562,7 @@ export function reassembleByUnion() {
1559
1562
  export var buildSqlQuery = function buildSqlQuery() {
1560
1563
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1561
1564
  var type = arguments.length > 1 ? arguments[1] : undefined;
1565
+ var db = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'mysql';
1562
1566
  var typeName = '';
1563
1567
  if (type === AtomsTypeEnum.EXISTS) {
1564
1568
  typeName = 'EXISTS ';
@@ -1567,7 +1571,8 @@ export var buildSqlQuery = function buildSqlQuery() {
1567
1571
  } else if (type === AtomsTypeEnum.SUB_QUERY) {
1568
1572
  typeName = '';
1569
1573
  }
1570
- var _transformSql = transformSql(data),
1574
+ var noFields = type === AtomsTypeEnum.EXISTS || type === AtomsTypeEnum.NOT_EXISTS;
1575
+ var _transformSql = transformSql(data, db, noFields),
1571
1576
  sql = _transformSql.sql;
1572
1577
  return "".concat(typeName, "(").concat(sql, ") ");
1573
1578
  };
@@ -1605,12 +1610,17 @@ var isSameErrorCheckTable = function isSameErrorCheckTable(table, item) {
1605
1610
  return Boolean(itemTableId && tableId && itemTableId === tableId || itemTableAlias && tableAlias && itemTableAlias === tableAlias || item.tableUuid && table.tableUuid && item.tableUuid === table.tableUuid || itemTableName && tableName && itemTableName === tableName);
1606
1611
  };
1607
1612
  var isSameErrorCheckColumn = function isSameErrorCheckColumn(field, item) {
1608
- if (isSameColumnByIdFirst(field, item)) {
1613
+ var fieldIsSummary = Boolean(field === null || field === void 0 ? void 0 : field.summarizeType);
1614
+ var itemIsSummary = Boolean(item === null || item === void 0 ? void 0 : item.summarizeType);
1615
+ if (fieldIsSummary === itemIsSummary && isSameColumnByIdFirst(field, item)) {
1609
1616
  return true;
1610
1617
  }
1611
- if (!(field !== null && field !== void 0 && field.summarizeType)) {
1612
- return false;
1618
+ var fieldName = normalizeIdentityValue((field === null || field === void 0 ? void 0 : field.fieldName) || (field === null || field === void 0 ? void 0 : field.name));
1619
+ var itemName = normalizeIdentityValue((item === null || item === void 0 ? void 0 : item.fieldName) || (item === null || item === void 0 ? void 0 : item.name));
1620
+ if (fieldIsSummary === itemIsSummary && fieldName && itemName && fieldName === itemName) {
1621
+ return true;
1613
1622
  }
1623
+ if (!(field !== null && field !== void 0 && field.summarizeType)) return false;
1614
1624
  var itemValues = [item.fieldId, item.id, item.fieldUuid, item.fieldName, item.fieldAlias].map(normalizeIdentityValue).filter(Boolean);
1615
1625
  var fieldValues = [field.fieldId, field.id, field.fieldUuid, field.fieldName, field.name, field.fieldAlias, field.realName].map(normalizeIdentityValue).filter(Boolean);
1616
1626
  return itemValues.some(function (value) {
@@ -1618,7 +1628,11 @@ var isSameErrorCheckColumn = function isSameErrorCheckColumn(field, item) {
1618
1628
  });
1619
1629
  };
1620
1630
  var getErrorCheckFields = function getErrorCheckFields(item, data) {
1621
- var tables = data.filter(function (table) {
1631
+ var itemTableUuid = normalizeIdentityValue(item.tableUuid);
1632
+ var uuidTables = itemTableUuid ? data.filter(function (table) {
1633
+ return normalizeIdentityValue(table.tableUuid) === itemTableUuid;
1634
+ }) : [];
1635
+ var tables = uuidTables.length ? uuidTables : data.filter(function (table) {
1622
1636
  return isSameErrorCheckTable(table, item);
1623
1637
  });
1624
1638
  if (!tables.length) return null;
@@ -1626,50 +1640,75 @@ var getErrorCheckFields = function getErrorCheckFields(item, data) {
1626
1640
  return table.columns || [];
1627
1641
  });
1628
1642
  };
1629
- var _isError = function isError(item) {
1643
+ var _getFieldReferenceError = function getFieldReferenceError(item) {
1630
1644
  var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1631
1645
  if (!hasLoadedColumnData(data)) {
1632
- return false;
1646
+ return null;
1633
1647
  }
1634
1648
  if (!item) {
1635
- return false;
1649
+ return null;
1636
1650
  }
1637
1651
  if (Array.isArray(item)) {
1638
- return item.some(function (v) {
1639
- return _isError(v, data);
1640
- });
1652
+ var _iterator2 = _createForOfIteratorHelper(item),
1653
+ _step2;
1654
+ try {
1655
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1656
+ var currentItem = _step2.value;
1657
+ var error = _getFieldReferenceError(currentItem, data);
1658
+ if (error) return error;
1659
+ }
1660
+ } catch (err) {
1661
+ _iterator2.e(err);
1662
+ } finally {
1663
+ _iterator2.f();
1664
+ }
1665
+ return null;
1641
1666
  }
1642
1667
  if (item.type === AtomsTypeEnum.FIELD) {
1643
1668
  var _item$tableId = item.tableId,
1644
- tableId = _item$tableId === void 0 ? '' : _item$tableId;
1645
- if (!tableId) {
1646
- return false;
1669
+ tableId = _item$tableId === void 0 ? '' : _item$tableId,
1670
+ _item$tableUuid = item.tableUuid,
1671
+ tableUuid = _item$tableUuid === void 0 ? '' : _item$tableUuid;
1672
+ if (!tableId && !tableUuid) {
1673
+ return null;
1647
1674
  }
1648
1675
  var fields = getErrorCheckFields(item, data);
1649
1676
  if (!fields) {
1650
- return true;
1677
+ return 'table';
1651
1678
  }
1652
1679
  if (!fields.length) {
1653
- return false;
1680
+ return null;
1681
+ }
1682
+ var itemFieldUuid = normalizeIdentityValue(item.fieldUuid);
1683
+ if (itemFieldUuid) {
1684
+ var hasMatchingUuid = fields.some(function (field) {
1685
+ return normalizeIdentityValue(field.fieldUuid) === itemFieldUuid;
1686
+ });
1687
+ if (hasMatchingUuid) return null;
1688
+ return fields.some(function (field) {
1689
+ return isSameErrorCheckColumn(field, item);
1690
+ }) ? null : 'field';
1654
1691
  }
1655
- return !fields.some(function (field) {
1692
+ return fields.some(function (field) {
1656
1693
  return isSameErrorCheckColumn(field, item);
1657
- });
1694
+ }) ? null : 'field';
1658
1695
  }
1659
1696
  if (item.type === AtomsTypeEnum.EXPRESSION) {
1660
- var lhsHasError = _isError(item.lhs, data);
1661
- var rhsHasError = _isError(item.rhs, data);
1662
- return lhsHasError || rhsHasError;
1697
+ return _getFieldReferenceError(item.lhs, data) || _getFieldReferenceError(item.rhs, data);
1663
1698
  }
1664
1699
  if (item.type === AtomsTypeEnum.FORMULA) {
1665
- return _isError(item.args, data);
1700
+ return _getFieldReferenceError(item.args, data);
1666
1701
  }
1667
1702
  if (item.type === AtomsTypeEnum.COLLECTION) {
1668
- return _isError(item.list, data);
1703
+ return _getFieldReferenceError(item.list, data);
1669
1704
  }
1670
- return false;
1705
+ return null;
1706
+ };
1707
+ export { _getFieldReferenceError as getFieldReferenceError };
1708
+ export var isError = function isError(item) {
1709
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1710
+ return Boolean(_getFieldReferenceError(item, data));
1671
1711
  };
1672
- export { _isError as isError };
1673
1712
  function isSubset(sub, obj) {
1674
1713
  var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
1675
1714
  if (sub === obj) return true;
@@ -1704,17 +1743,17 @@ export function containsSubset(root, target) {
1704
1743
  return true;
1705
1744
  }
1706
1745
  if (Array.isArray(current)) {
1707
- var _iterator2 = _createForOfIteratorHelper(current),
1708
- _step2;
1746
+ var _iterator3 = _createForOfIteratorHelper(current),
1747
+ _step3;
1709
1748
  try {
1710
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1711
- var item = _step2.value;
1749
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1750
+ var item = _step3.value;
1712
1751
  if (search(item)) return true;
1713
1752
  }
1714
1753
  } catch (err) {
1715
- _iterator2.e(err);
1754
+ _iterator3.e(err);
1716
1755
  } finally {
1717
- _iterator2.f();
1756
+ _iterator3.f();
1718
1757
  }
1719
1758
  } else {
1720
1759
  for (var key in current) {
@@ -1735,11 +1774,11 @@ export var isExistsError = function isExistsError(meta, errorList) {
1735
1774
  });
1736
1775
  };
1737
1776
  function setNewField(field, data) {
1738
- var _iterator3 = _createForOfIteratorHelper(data),
1739
- _step3;
1777
+ var _iterator4 = _createForOfIteratorHelper(data),
1778
+ _step4;
1740
1779
  try {
1741
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1742
- var table = _step3.value;
1780
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1781
+ var table = _step4.value;
1743
1782
  if (!isSameTableByIdFirst(table, {
1744
1783
  datasourceId: field.datasourceId,
1745
1784
  id: field.tableId,
@@ -1768,9 +1807,9 @@ function setNewField(field, data) {
1768
1807
  break;
1769
1808
  }
1770
1809
  } catch (err) {
1771
- _iterator3.e(err);
1810
+ _iterator4.e(err);
1772
1811
  } finally {
1773
- _iterator3.f();
1812
+ _iterator4.f();
1774
1813
  }
1775
1814
  return field;
1776
1815
  }
@@ -0,0 +1,2 @@
1
+ export { validateMetabaseConfig, validateAtomListSyntax, validateSqlSyntax, validateSql, transformSql, SQL_VALIDATION_I18N_KEYS, } from './utils/transformSql';
2
+ export type { SqlValidationIssue, SqlValidationIssueCode, SqlValidationPathItem, SqlValidationPathType, SqlValidationResult, } from './utils/transformSql';
@@ -0,0 +1 @@
1
+ export { validateMetabaseConfig, validateAtomListSyntax, validateSqlSyntax, validateSql, transformSql, SQL_VALIDATION_I18N_KEYS } from './utils/transformSql';
package/package.json CHANGED
@@ -1,11 +1,39 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.158-alpha.2",
3
+ "version": "1.0.158-alpha.21",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",
7
7
  "unpkg": "lib/umd/index.min.js",
8
8
  "typings": "lib/es/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/es/index.d.ts",
12
+ "import": "./lib/es/index.js",
13
+ "require": "./lib/cjs/index.js",
14
+ "default": "./lib/es/index.js"
15
+ },
16
+ "./validate": {
17
+ "types": "./lib/es/validate.d.ts",
18
+ "require": "./lib/cjs/validate.js",
19
+ "import": "./lib/es/validate.js",
20
+ "default": "./lib/cjs/validate.js"
21
+ },
22
+ "./prompt": {
23
+ "types": "./lib/es/prompt.d.ts",
24
+ "require": "./lib/cjs/prompt.js",
25
+ "import": "./lib/es/prompt.js",
26
+ "default": "./lib/cjs/prompt.js"
27
+ },
28
+ "./enum": {
29
+ "types": "./lib/es/enum.d.ts",
30
+ "import": "./lib/es/enum.js",
31
+ "require": "./lib/cjs/enum.js",
32
+ "default": "./lib/es/enum.js"
33
+ },
34
+ "./lib/es/*": "./lib/es/*",
35
+ "./package.json": "./package.json"
36
+ },
9
37
  "scripts": {
10
38
  "clean": "rimraf lib",
11
39
  "dev": "cd example && yarn dev",
@@ -13,6 +41,7 @@
13
41
  "build:umd": "cross-env BABEL_ENV=esm rollup -c --bundleConfigAsCjs",
14
42
  "build": "npm run clean && npm run build:lib",
15
43
  "prettier": "prettier --write .",
44
+ "test": "node scripts/run-sql-validation-tests.js && node scripts/run-expression-integrity-tests.js",
16
45
  "prepublishOnly": "npm run build"
17
46
  },
18
47
  "files": [
@@ -27,6 +56,7 @@
27
56
  "react-dom": "^17.0.0 || ^18.0.0"
28
57
  },
29
58
  "dependencies": {
59
+ "@babel/runtime": "^7.23.9",
30
60
  "@gingkoo/pandora": "1.2.20-alpha.7",
31
61
  "@gingkoo/pandora-hooks": "1.0.5",
32
62
  "@gingkoo/pandora-icons": "0.0.1-alpha.28",
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import './index.less';
3
- export interface DiffViewerProps {
4
- oldCode: string | undefined;
5
- newCode: string | undefined;
6
- oldFileName?: string;
7
- newFileName?: string;
8
- }
9
- declare const DiffViewer: React.FC<DiffViewerProps>;
10
- export default DiffViewer;
@@ -1,139 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- var _react = require("react");
11
- var _diff = require("diff");
12
- require("./index.less");
13
- var DiffViewer = function DiffViewer(_ref) {
14
- var oldCode = _ref.oldCode,
15
- newCode = _ref.newCode,
16
- _ref$oldFileName = _ref.oldFileName,
17
- oldFileName = _ref$oldFileName === void 0 ? 'old.js' : _ref$oldFileName,
18
- _ref$newFileName = _ref.newFileName,
19
- newFileName = _ref$newFileName === void 0 ? 'new.js' : _ref$newFileName;
20
- var leftRef = (0, _react.useRef)(null);
21
- var rightRef = (0, _react.useRef)(null);
22
- var isSyncing = (0, _react.useRef)(false);
23
- var _useState = (0, _react.useState)('--- (unknown)'),
24
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
25
- oldFileHeader = _useState2[0],
26
- setOldFileHeader = _useState2[1];
27
- var _useState3 = (0, _react.useState)([]),
28
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
29
- hunkHeaders = _useState4[0],
30
- setHunkHeaders = _useState4[1];
31
- (0, _react.useEffect)(function () {
32
- var safeOldStr = typeof oldCode === 'string' ? oldCode : '';
33
- var safeNewStr = typeof newCode === 'string' ? newCode : '';
34
- var patch = (0, _diff.createTwoFilesPatch)(oldFileName, newFileName, safeOldStr, safeNewStr, '', '', {
35
- context: 10
36
- });
37
- var lines = patch.split('\n');
38
- setHunkHeaders(lines.filter(function (l) {
39
- return l.startsWith('@@ ') && l.endsWith(' @@');
40
- }));
41
- }, [oldCode, newCode, oldFileName, newFileName]);
42
- (0, _react.useEffect)(function () {
43
- var safeOld = (typeof oldCode === 'string' ? oldCode : '').split('\n');
44
- var safeNew = (typeof newCode === 'string' ? newCode : '').split('\n');
45
- var maxLines = Math.max(safeOld.length, safeNew.length);
46
- var leftHtml = [];
47
- var rightHtml = [];
48
- for (var i = 0; i < maxLines; i++) {
49
- var _safeOld$i, _safeNew$i;
50
- var oldLine = (_safeOld$i = safeOld[i]) !== null && _safeOld$i !== void 0 ? _safeOld$i : '';
51
- var newLine = (_safeNew$i = safeNew[i]) !== null && _safeNew$i !== void 0 ? _safeNew$i : '';
52
- var diffs = (0, _diff.diffWordsWithSpace)(oldLine, newLine);
53
- var leftContent = '';
54
- var rightContent = '';
55
- var lastToken = diffs[diffs.length - 1];
56
- var ignoreLastTrailingSpace = diffs.length > 0 && (lastToken === null || lastToken === void 0 ? void 0 : lastToken.removed) && /^\s+$/.test(lastToken.value) && oldLine.endsWith(lastToken.value);
57
- for (var j = 0; j < diffs.length; j++) {
58
- var part = diffs[j];
59
- var escaped = escapeHtml(part.value);
60
- if (part.added) {
61
- rightContent += "<span class=\"diff-add\">".concat(escaped, "</span>");
62
- } else if (part.removed) {
63
- if (ignoreLastTrailingSpace && j === diffs.length - 1) {
64
- leftContent += escaped;
65
- } else {
66
- leftContent += "<span class=\"diff-del\">".concat(escaped, "</span>");
67
- }
68
- } else {
69
- leftContent += escaped;
70
- rightContent += escaped;
71
- }
72
- }
73
- if (i >= safeOld.length) leftContent = '&nbsp;';
74
- if (i >= safeNew.length) rightContent = '&nbsp;';
75
- leftHtml.push("<div class=\"diff-line\">".concat(leftContent, "</div>"));
76
- rightHtml.push("<div class=\"diff-line\">".concat(rightContent, "</div>"));
77
- }
78
- var timer = setTimeout(function () {
79
- if (leftRef.current) leftRef.current.innerHTML = leftHtml.join('');
80
- if (rightRef.current) rightRef.current.innerHTML = rightHtml.join('');
81
- }, 0);
82
- return function () {
83
- return clearTimeout(timer);
84
- };
85
- }, [oldCode, newCode]);
86
- (0, _react.useEffect)(function () {
87
- var left = leftRef.current;
88
- var right = rightRef.current;
89
- if (!left || !right) return;
90
- var sync = function sync(src, dst) {
91
- return function () {
92
- if (isSyncing.current) return;
93
- isSyncing.current = true;
94
- dst.scrollTop = src.scrollTop;
95
- dst.scrollLeft = src.scrollLeft;
96
- requestAnimationFrame(function () {
97
- isSyncing.current = false;
98
- });
99
- };
100
- };
101
- var onLeft = sync(left, right);
102
- var onRight = sync(right, left);
103
- left.addEventListener('scroll', onLeft, {
104
- passive: true
105
- });
106
- right.addEventListener('scroll', onRight, {
107
- passive: true
108
- });
109
- return function () {
110
- left.removeEventListener('scroll', onLeft);
111
- right.removeEventListener('scroll', onRight);
112
- };
113
- }, []);
114
- return (0, _jsxRuntime.jsxs)("div", {
115
- className: 'diff-viewer',
116
- children: [hunkHeaders.length > 0 && (0, _jsxRuntime.jsx)("div", {
117
- className: 'diff-hunk-headers',
118
- children: hunkHeaders.map(function (h, i) {
119
- return (0, _jsxRuntime.jsx)("div", {
120
- className: 'hunk-header',
121
- children: h
122
- }, i);
123
- })
124
- }), (0, _jsxRuntime.jsxs)("div", {
125
- className: 'diff-panes',
126
- children: [(0, _jsxRuntime.jsx)("div", {
127
- ref: leftRef,
128
- className: 'diff-pane diff-old'
129
- }), (0, _jsxRuntime.jsx)("div", {
130
- ref: rightRef,
131
- className: 'diff-pane diff-new'
132
- })]
133
- })]
134
- });
135
- };
136
- function escapeHtml(str) {
137
- return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
138
- }
139
- var _default = exports["default"] = DiffViewer;
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import './index.less';
3
- export interface DiffViewerProps {
4
- oldCode: string | undefined;
5
- newCode: string | undefined;
6
- oldFileName?: string;
7
- newFileName?: string;
8
- }
9
- declare const DiffViewer: React.FC<DiffViewerProps>;
10
- export default DiffViewer;
@@ -1,132 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useRef, useState } from 'react';
4
- import { diffWordsWithSpace, createTwoFilesPatch } from 'diff';
5
- import './index.less';
6
- var DiffViewer = function DiffViewer(_ref) {
7
- var oldCode = _ref.oldCode,
8
- newCode = _ref.newCode,
9
- _ref$oldFileName = _ref.oldFileName,
10
- oldFileName = _ref$oldFileName === void 0 ? 'old.js' : _ref$oldFileName,
11
- _ref$newFileName = _ref.newFileName,
12
- newFileName = _ref$newFileName === void 0 ? 'new.js' : _ref$newFileName;
13
- var leftRef = useRef(null);
14
- var rightRef = useRef(null);
15
- var isSyncing = useRef(false);
16
- var _useState = useState('--- (unknown)'),
17
- _useState2 = _slicedToArray(_useState, 2),
18
- oldFileHeader = _useState2[0],
19
- setOldFileHeader = _useState2[1];
20
- var _useState3 = useState([]),
21
- _useState4 = _slicedToArray(_useState3, 2),
22
- hunkHeaders = _useState4[0],
23
- setHunkHeaders = _useState4[1];
24
- useEffect(function () {
25
- var safeOldStr = typeof oldCode === 'string' ? oldCode : '';
26
- var safeNewStr = typeof newCode === 'string' ? newCode : '';
27
- var patch = createTwoFilesPatch(oldFileName, newFileName, safeOldStr, safeNewStr, '', '', {
28
- context: 10
29
- });
30
- var lines = patch.split('\n');
31
- setHunkHeaders(lines.filter(function (l) {
32
- return l.startsWith('@@ ') && l.endsWith(' @@');
33
- }));
34
- }, [oldCode, newCode, oldFileName, newFileName]);
35
- useEffect(function () {
36
- var safeOld = (typeof oldCode === 'string' ? oldCode : '').split('\n');
37
- var safeNew = (typeof newCode === 'string' ? newCode : '').split('\n');
38
- var maxLines = Math.max(safeOld.length, safeNew.length);
39
- var leftHtml = [];
40
- var rightHtml = [];
41
- for (var i = 0; i < maxLines; i++) {
42
- var _safeOld$i, _safeNew$i;
43
- var oldLine = (_safeOld$i = safeOld[i]) !== null && _safeOld$i !== void 0 ? _safeOld$i : '';
44
- var newLine = (_safeNew$i = safeNew[i]) !== null && _safeNew$i !== void 0 ? _safeNew$i : '';
45
- var diffs = diffWordsWithSpace(oldLine, newLine);
46
- var leftContent = '';
47
- var rightContent = '';
48
- var lastToken = diffs[diffs.length - 1];
49
- var ignoreLastTrailingSpace = diffs.length > 0 && (lastToken === null || lastToken === void 0 ? void 0 : lastToken.removed) && /^\s+$/.test(lastToken.value) && oldLine.endsWith(lastToken.value);
50
- for (var j = 0; j < diffs.length; j++) {
51
- var part = diffs[j];
52
- var escaped = escapeHtml(part.value);
53
- if (part.added) {
54
- rightContent += "<span class=\"diff-add\">".concat(escaped, "</span>");
55
- } else if (part.removed) {
56
- if (ignoreLastTrailingSpace && j === diffs.length - 1) {
57
- leftContent += escaped;
58
- } else {
59
- leftContent += "<span class=\"diff-del\">".concat(escaped, "</span>");
60
- }
61
- } else {
62
- leftContent += escaped;
63
- rightContent += escaped;
64
- }
65
- }
66
- if (i >= safeOld.length) leftContent = '&nbsp;';
67
- if (i >= safeNew.length) rightContent = '&nbsp;';
68
- leftHtml.push("<div class=\"diff-line\">".concat(leftContent, "</div>"));
69
- rightHtml.push("<div class=\"diff-line\">".concat(rightContent, "</div>"));
70
- }
71
- var timer = setTimeout(function () {
72
- if (leftRef.current) leftRef.current.innerHTML = leftHtml.join('');
73
- if (rightRef.current) rightRef.current.innerHTML = rightHtml.join('');
74
- }, 0);
75
- return function () {
76
- return clearTimeout(timer);
77
- };
78
- }, [oldCode, newCode]);
79
- useEffect(function () {
80
- var left = leftRef.current;
81
- var right = rightRef.current;
82
- if (!left || !right) return;
83
- var sync = function sync(src, dst) {
84
- return function () {
85
- if (isSyncing.current) return;
86
- isSyncing.current = true;
87
- dst.scrollTop = src.scrollTop;
88
- dst.scrollLeft = src.scrollLeft;
89
- requestAnimationFrame(function () {
90
- isSyncing.current = false;
91
- });
92
- };
93
- };
94
- var onLeft = sync(left, right);
95
- var onRight = sync(right, left);
96
- left.addEventListener('scroll', onLeft, {
97
- passive: true
98
- });
99
- right.addEventListener('scroll', onRight, {
100
- passive: true
101
- });
102
- return function () {
103
- left.removeEventListener('scroll', onLeft);
104
- right.removeEventListener('scroll', onRight);
105
- };
106
- }, []);
107
- return _jsxs("div", {
108
- className: 'diff-viewer',
109
- children: [hunkHeaders.length > 0 && _jsx("div", {
110
- className: 'diff-hunk-headers',
111
- children: hunkHeaders.map(function (h, i) {
112
- return _jsx("div", {
113
- className: 'hunk-header',
114
- children: h
115
- }, i);
116
- })
117
- }), _jsxs("div", {
118
- className: 'diff-panes',
119
- children: [_jsx("div", {
120
- ref: leftRef,
121
- className: 'diff-pane diff-old'
122
- }), _jsx("div", {
123
- ref: rightRef,
124
- className: 'diff-pane diff-new'
125
- })]
126
- })]
127
- });
128
- };
129
- function escapeHtml(str) {
130
- return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
131
- }
132
- export default DiffViewer;