@okf/ootils 1.26.4 → 1.28.0

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.
@@ -1014,6 +1014,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
1014
1014
  filterKey,
1015
1015
  contentType: element.contentType,
1016
1016
  path: element.valuePath,
1017
+ ...element.comp && { comp: element.comp },
1017
1018
  source: {
1018
1019
  filterType: "tplType",
1019
1020
  contentType: element.contentType,
@@ -1039,6 +1040,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
1039
1040
  filterKey: valuePathFilterKey,
1040
1041
  contentType: element.contentType,
1041
1042
  path: element.valuePath,
1043
+ ...element.comp && { comp: element.comp },
1042
1044
  source: {
1043
1045
  filterType: "tplType",
1044
1046
  contentType: element.contentType,
@@ -1064,6 +1066,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
1064
1066
  filterKey: dateFilterKey,
1065
1067
  contentType: element.contentType,
1066
1068
  path: element.valuePath,
1069
+ ...element.comp && { comp: element.comp },
1067
1070
  source: { filterType: "dateRangeType" },
1068
1071
  target: { filterType: "dateRangeType", valuePath: element.valuePath }
1069
1072
  };
@@ -1081,6 +1084,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
1081
1084
  filterKey: numberFilterKey,
1082
1085
  contentType: element.contentType,
1083
1086
  path: element.valuePath,
1087
+ ...element.comp && { comp: element.comp },
1084
1088
  source: { filterType: "numberRangeType", valuePath: element.valuePath },
1085
1089
  target: { filterType: "numberRangeType", valuePath: element.valuePath }
1086
1090
  };
@@ -1201,6 +1205,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
1201
1205
  filterKey: tagFilterKey,
1202
1206
  contentType: element.tagType,
1203
1207
  path: `tags.${element.tagType}`,
1208
+ ...element.comp && { comp: element.comp },
1204
1209
  source: allProfileTpls.some(
1205
1210
  (tpl) => tpl.kp_content_type === element.tagType
1206
1211
  ) ? {
@@ -1342,6 +1347,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1342
1347
  contentType: tpl.kp_content_type,
1343
1348
  blocks: allBlocks.filter((block) => block.valuePath.startsWith("tags.")).map((block) => ({
1344
1349
  tagType: block.props.tagType,
1350
+ comp: block.comp,
1345
1351
  filterType: "tagType"
1346
1352
  }))
1347
1353
  };
@@ -1369,6 +1375,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1369
1375
  value: block.valuePath,
1370
1376
  saveValueAsString: block.props?.saveValueAsString,
1371
1377
  contentType: tpl.kp_content_type,
1378
+ comp: block.comp,
1372
1379
  filterType: "valuePathType"
1373
1380
  }))
1374
1381
  };
@@ -1383,6 +1390,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1383
1390
  value: block.valuePath,
1384
1391
  saveValueAsString: block.props?.saveValueAsString,
1385
1392
  contentType: tpl.kp_content_type,
1393
+ comp: block.comp,
1386
1394
  block,
1387
1395
  filterType: "split_valuePathType"
1388
1396
  }))
@@ -1397,6 +1405,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1397
1405
  display: block.props?.shortLabel || block.props?.label || block.valuePath,
1398
1406
  value: block.valuePath,
1399
1407
  contentType: tpl.kp_content_type,
1408
+ comp: block.comp,
1400
1409
  filterType: "dateRangeType"
1401
1410
  }))
1402
1411
  };
@@ -1410,6 +1419,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1410
1419
  display: block.props?.shortLabel || block.props?.label || block.valuePath,
1411
1420
  value: block.valuePath,
1412
1421
  contentType: tpl.kp_content_type,
1422
+ comp: block.comp,
1413
1423
  filterType: "numberRangeType"
1414
1424
  }))
1415
1425
  };
@@ -1656,6 +1666,240 @@ var _self_managed_buildAnnoHierarchyConfig = ({
1656
1666
  };
1657
1667
  };
1658
1668
 
1669
+ // src/utils/autoGenFilterConfigsFromTpl/utils/buildTagTypeParentMap.ts
1670
+ var buildTagTypeParentMap = (tagTypesInGroup, allTpls) => {
1671
+ const tagTypeSet = new Set(tagTypesInGroup);
1672
+ const parentMap = /* @__PURE__ */ new Map();
1673
+ for (const tagType of tagTypesInGroup) {
1674
+ const tpl = allTpls.find((t) => t.kp_content_type === tagType);
1675
+ if (!tpl) continue;
1676
+ const blocks = extractAllBlocksFromTpl({ tpl });
1677
+ const tagBlocks = blocks.filter(
1678
+ (block) => block.valuePath?.startsWith("tags.") && block.props?.tagType
1679
+ );
1680
+ for (const block of tagBlocks) {
1681
+ const referencedTagType = block.props.tagType;
1682
+ if (tagTypeSet.has(referencedTagType) && referencedTagType !== tagType) {
1683
+ parentMap.set(tagType, referencedTagType);
1684
+ break;
1685
+ }
1686
+ }
1687
+ }
1688
+ for (const child of parentMap.keys()) {
1689
+ const visited = /* @__PURE__ */ new Set();
1690
+ let current = child;
1691
+ while (current && parentMap.has(current)) {
1692
+ if (visited.has(current)) {
1693
+ parentMap.delete(current);
1694
+ break;
1695
+ }
1696
+ visited.add(current);
1697
+ current = parentMap.get(current);
1698
+ }
1699
+ }
1700
+ return parentMap;
1701
+ };
1702
+ var attachParentFields = (filters, allTpls) => {
1703
+ const tagTypeFilters = filters.filter(
1704
+ (f) => f.source?.filterType === "tagType" && f.source?.tagType
1705
+ );
1706
+ if (tagTypeFilters.length === 0) return filters;
1707
+ const tagTypesInGroup = tagTypeFilters.map((f) => f.source.tagType);
1708
+ const parentMap = buildTagTypeParentMap(tagTypesInGroup, allTpls);
1709
+ if (parentMap.size === 0) return filters;
1710
+ const tagTypeToFilterId = /* @__PURE__ */ new Map();
1711
+ for (const f of tagTypeFilters) {
1712
+ tagTypeToFilterId.set(f.source.tagType, f.filterId);
1713
+ }
1714
+ return filters.map((f) => {
1715
+ if (f.source?.filterType !== "tagType" || !f.source?.tagType) return f;
1716
+ const parentTagType = parentMap.get(f.source.tagType);
1717
+ if (!parentTagType) return f;
1718
+ const parentFilterId = tagTypeToFilterId.get(parentTagType);
1719
+ if (!parentFilterId) return f;
1720
+ return { ...f, parentFilterId };
1721
+ });
1722
+ };
1723
+ var sortFiltersHierarchically = (filters) => {
1724
+ if (filters.length <= 1) return filters;
1725
+ const hasHierarchy = filters.some((f) => f.parentFilterId);
1726
+ if (!hasHierarchy) return filters;
1727
+ const childrenOf = /* @__PURE__ */ new Map();
1728
+ const roots = [];
1729
+ for (const f of filters) {
1730
+ if (!f.parentFilterId) {
1731
+ roots.push(f);
1732
+ } else {
1733
+ const siblings = childrenOf.get(f.parentFilterId) || [];
1734
+ siblings.push(f);
1735
+ childrenOf.set(f.parentFilterId, siblings);
1736
+ }
1737
+ }
1738
+ const sorted = [];
1739
+ const visited = /* @__PURE__ */ new Set();
1740
+ const visit = (filter) => {
1741
+ if (visited.has(filter.filterId)) return;
1742
+ visited.add(filter.filterId);
1743
+ sorted.push(filter);
1744
+ const children = childrenOf.get(filter.filterId) || [];
1745
+ for (const child of children) {
1746
+ visit(child);
1747
+ }
1748
+ };
1749
+ for (const root of roots) {
1750
+ visit(root);
1751
+ }
1752
+ for (const f of filters) {
1753
+ if (!visited.has(f.filterId)) {
1754
+ sorted.push(f);
1755
+ }
1756
+ }
1757
+ return sorted;
1758
+ };
1759
+
1760
+ // src/utils/autoGenFilterConfigsFromTpl/utils/_self_managed_buildDocHierarchyConfig.ts
1761
+ var _self_managed_buildDocHierarchyConfig = ({
1762
+ combinedDocumentBlocks,
1763
+ docRollupBlocks,
1764
+ selectedTpls,
1765
+ allTpls,
1766
+ commonDocumentFilters,
1767
+ flatDocFilters = false
1768
+ }) => {
1769
+ const allGroups = compareAndGroupBlocks(combinedDocumentBlocks);
1770
+ const commonGroup = allGroups.find(
1771
+ (g) => g.contentTypes.length === selectedTpls.length
1772
+ );
1773
+ const commonFilterConfigs = commonGroup ? sortFiltersHierarchically(
1774
+ attachParentFields(
1775
+ buildFilterConfigurations({
1776
+ groups: [commonGroup],
1777
+ type: "tags",
1778
+ selectedTpls,
1779
+ allTpls,
1780
+ isRollup: false,
1781
+ isAnno: false
1782
+ }).flatMap((s) => s.configs),
1783
+ allTpls
1784
+ )
1785
+ ) : [];
1786
+ const multiDatasetGroups = selectedTpls.length >= 2 ? allGroups.filter(
1787
+ (g) => g.contentTypes.length > 1 && g.contentTypes.length < selectedTpls.length
1788
+ ) : [];
1789
+ const sharedAcrossMultiple = multiDatasetGroups.map((group) => {
1790
+ const groupFilterConfigs = sortFiltersHierarchically(
1791
+ attachParentFields(
1792
+ buildFilterConfigurations({
1793
+ groups: [group],
1794
+ type: "tags",
1795
+ selectedTpls,
1796
+ allTpls,
1797
+ isRollup: false,
1798
+ isAnno: false
1799
+ }).flatMap((s) => s.configs),
1800
+ allTpls
1801
+ )
1802
+ );
1803
+ const display = group.contentTypes.map((ct) => {
1804
+ const tplData = allTpls.find(
1805
+ (t) => t.kp_content_type === ct
1806
+ );
1807
+ return tplData?.general?.content?.title || ct;
1808
+ }).join(" + ");
1809
+ return {
1810
+ contentTypes: group.contentTypes,
1811
+ display,
1812
+ filters: groupFilterConfigs
1813
+ };
1814
+ }).filter((g) => g.filters.length > 0);
1815
+ const commonFilterIds = new Set(commonFilterConfigs.map((f) => f.filterId));
1816
+ const perDataset = selectedTpls.map((tpl) => {
1817
+ const tplBlocks = combinedDocumentBlocks.find(
1818
+ (b) => b.contentType === tpl.kp_content_type
1819
+ );
1820
+ const singleTplGroup = [
1821
+ {
1822
+ contentTypes: [tpl.kp_content_type],
1823
+ elements: tplBlocks?.blocks || []
1824
+ }
1825
+ ];
1826
+ const filters = buildFilterConfigurations({
1827
+ groups: singleTplGroup,
1828
+ type: "tags",
1829
+ selectedTpls: [tpl],
1830
+ allTpls,
1831
+ isRollup: false,
1832
+ isAnno: false
1833
+ }).flatMap((s) => s.configs);
1834
+ const filtersWithCommonFlag = filters.map((f) => ({
1835
+ ...f,
1836
+ isSharedFilter: commonFilterIds.has(f.filterId)
1837
+ }));
1838
+ const rollupData = docRollupBlocks?.find(
1839
+ (b) => b.contentType === tpl.kp_content_type
1840
+ );
1841
+ const rollupGroups = rollupData?.blocks?.length ? compareAndGroupBlocks([rollupData]) : [];
1842
+ const rollupConfigs = rollupGroups.length ? buildFilterConfigurations({
1843
+ groups: rollupGroups,
1844
+ type: "tags",
1845
+ selectedTpls: [tpl],
1846
+ allTpls,
1847
+ isRollup: true,
1848
+ isAnno: false
1849
+ }).flatMap((s) => s.configs) : [];
1850
+ const tplData = allTpls.find(
1851
+ (t) => t.kp_content_type === tpl.kp_content_type
1852
+ );
1853
+ const rollupSourceKeys = new Set(
1854
+ rollupConfigs.map((r) => JSON.stringify(r.source))
1855
+ );
1856
+ const dedupedFilters = filtersWithCommonFlag.filter(
1857
+ (f) => !rollupSourceKeys.has(JSON.stringify(f.source))
1858
+ );
1859
+ const combined = [...dedupedFilters, ...rollupConfigs];
1860
+ const combinedWithParents = sortFiltersHierarchically(
1861
+ attachParentFields(combined, allTpls)
1862
+ );
1863
+ const rollupFilterIds = new Set(rollupConfigs.map((r) => r.filterId));
1864
+ const filtersWithParents = combinedWithParents.filter(
1865
+ (f) => !rollupFilterIds.has(f.filterId)
1866
+ );
1867
+ const rollupsWithParents = combinedWithParents.filter(
1868
+ (f) => rollupFilterIds.has(f.filterId)
1869
+ );
1870
+ return {
1871
+ contentType: tpl.kp_content_type,
1872
+ display: tplData?.general?.content?.title || tpl.kp_content_type,
1873
+ filters: filtersWithParents,
1874
+ rollups: rollupsWithParents
1875
+ };
1876
+ });
1877
+ const filteredPerDataset = perDataset.filter(
1878
+ (d) => d.filters.length > 0 || d.rollups.length > 0
1879
+ );
1880
+ if (commonFilterConfigs.length === 0 && sharedAcrossMultiple.length === 0 && filteredPerDataset.every((d) => d.filters.length === 0)) {
1881
+ return null;
1882
+ }
1883
+ const flatCommonDocFilters = commonDocumentFilters.flatMap(
1884
+ (s) => s.configs || [s]
1885
+ );
1886
+ const shouldFlatten = flatDocFilters && selectedTpls.length === 1;
1887
+ return {
1888
+ filterId: "docHierarchy_document_filters",
1889
+ display: "Combined Content Filters",
1890
+ filterKey: "docHierarchyType::doc",
1891
+ source: {
1892
+ filterType: "docHierarchyType",
1893
+ flatDocFilters: shouldFlatten,
1894
+ commonFilters: commonFilterConfigs,
1895
+ sharedAcrossMultiple,
1896
+ commonDocumentFilters: flatCommonDocFilters,
1897
+ perDataset: filteredPerDataset
1898
+ },
1899
+ target: { filterType: "docHierarchyType" }
1900
+ };
1901
+ };
1902
+
1659
1903
  // src/utils/autoGenFilterConfigsFromTpl/utils/TEMP_removeDuplicateFilters.ts
1660
1904
  var TEMP_removeDuplicateFilters = (filterGroups) => {
1661
1905
  return filterGroups.map((group) => {
@@ -1792,7 +2036,25 @@ var autoGenFilterConfigsFromTpl = ({
1792
2036
  ...annotationRollupSections
1793
2037
  ].filter((section) => Array.isArray(section.configs) ? section.configs.length > 0 : true)
1794
2038
  };
1795
- const final_documentTagsFilterConfigs = {
2039
+ const isSMTDocFilterUI = isSelfManagedTenant && filterScopes.includes("doc");
2040
+ const final_documentTagsFilterConfigs = isSMTDocFilterUI ? (() => {
2041
+ const docHierarchyConfig = _self_managed_buildDocHierarchyConfig({
2042
+ combinedDocumentBlocks: extractedBlocks.combinedDocumentBlocks,
2043
+ docRollupBlocks: extractedBlocks.docRollupBlocks,
2044
+ selectedTpls,
2045
+ allTpls,
2046
+ commonDocumentFilters
2047
+ });
2048
+ if (!docHierarchyConfig) return { sectionId: "documentTagsSection", sectionTitle: "Document Filters", configs: [] };
2049
+ return {
2050
+ sectionId: "documentTagsSection",
2051
+ // sectionTitle: 'Document Filters',
2052
+ configs: [{
2053
+ sectionId: "self_managed_consolidated_doc_filters",
2054
+ configs: [docHierarchyConfig]
2055
+ }]
2056
+ };
2057
+ })() : {
1796
2058
  sectionId: "documentTagsSection",
1797
2059
  sectionTitle: "Document Filters",
1798
2060
  configs: [
@@ -1806,12 +2068,47 @@ var autoGenFilterConfigsFromTpl = ({
1806
2068
  ].filter(Boolean);
1807
2069
  return result;
1808
2070
  };
2071
+
2072
+ // src/utils/genCleanCamelCaseId.ts
2073
+ var genCleanCamelCaseId = (id) => {
2074
+ if (!id || typeof id !== "string") return id;
2075
+ const isAlreadyClean = /^\p{Ll}[\p{L}\p{N}]*$/u.test(id) || /^a\d[\p{L}\p{N}]*$/u.test(id);
2076
+ if (isAlreadyClean) return id;
2077
+ const words = id.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
2078
+ if (words.length === 0) return "a";
2079
+ const result = words.map((word, i) => {
2080
+ const lower = word.toLowerCase();
2081
+ return i === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
2082
+ }).join("");
2083
+ return /^\d/.test(result) ? "a" + result : result;
2084
+ };
2085
+
2086
+ // src/utils/genCleanIdForContentTypeAndValuePaths.ts
2087
+ var CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
2088
+ function genShortId(length = 4) {
2089
+ let result = "";
2090
+ for (let i = 0; i < length; i++) {
2091
+ result += CHARS[Math.floor(Math.random() * CHARS.length)];
2092
+ }
2093
+ return result;
2094
+ }
2095
+ var genCleanIdForContentTypeAndValuePaths = (text, maxLength = 10, shortIdLength = 4) => {
2096
+ if (!text || typeof text !== "string") return text;
2097
+ let cleaned = text.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
2098
+ if (!cleaned) {
2099
+ throw new Error(`[genCleanIdForContentTypeAndValuePaths] Input "${text}" contains no alphanumeric characters`);
2100
+ }
2101
+ if (/^\d/.test(cleaned)) cleaned = "a" + cleaned;
2102
+ const truncated = cleaned.slice(0, maxLength);
2103
+ return `${truncated}_${genShortId(shortIdLength)}`;
2104
+ };
1809
2105
  export {
1810
2106
  BASE_BULLMQ_CONFIG,
1811
2107
  FILTER_IDS,
1812
2108
  TEMP_removeDuplicateFilters,
1813
2109
  UI_CONTENT,
1814
2110
  _self_managed_buildAnnoHierarchyConfig,
2111
+ _self_managed_buildDocHierarchyConfig,
1815
2112
  _self_managed_getFixedAnnoRollupBlocks,
1816
2113
  _self_managed_getFixedAnnoTagBlock,
1817
2114
  autoGenFilterConfigsFromTpl,
@@ -1820,6 +2117,8 @@ export {
1820
2117
  deleteVal,
1821
2118
  extractAllBlocksFromTpl,
1822
2119
  extractAndOrganizeBlocks,
2120
+ genCleanCamelCaseId,
2121
+ genCleanIdForContentTypeAndValuePaths,
1823
2122
  genTagId,
1824
2123
  generateFilterKey,
1825
2124
  getFilterKeyForBlock,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.26.4",
6
+ "version": "1.28.0",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",