Skip to content

Commit 0d245e8

Browse files
committed
fix: support clab-ui self-imports when installed from registry
1 parent 4e7da8a commit 0d245e8

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ui/package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
{
22
"name": "@srl-labs/clab-ui",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"private": false,
55
"type": "module",
66
"main": "src/index.ts",
77
"types": "src/index.ts",
8+
"exports": {
9+
".": "./src/index.ts",
10+
"./theme": "./src/theme/index.ts",
11+
"./explorer": "./src/explorer/index.ts",
12+
"./inspect": "./src/inspect/index.ts",
13+
"./core/parsing": "./src/core/parsing/index.ts",
14+
"./core/schema": "./src/core/schema/index.ts",
15+
"./core/types": "./src/core/types/index.ts",
16+
"./core/utilities": "./src/core/utilities/index.ts",
17+
"./core/*": "./src/core/*.ts",
18+
"./components/context-menu/ContextMenu": "./src/components/context-menu/ContextMenu.tsx",
19+
"./*": "./src/*"
20+
},
821
"publishConfig": {
922
"registry": "https://npm.pkg.github.com",
1023
"access": "public"

packages/ui/src/components/panels/bulk-link/bulkLinkUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Utility functions for bulk link creation
33
* Uses React Flow nodes/edges arrays for graph queries.
44
*/
5-
import { FilterUtils } from "../../../../../../src/helpers/filterUtils";
6-
import { isSpecialEndpointId } from "@srl-labs/clab-ui/core/utilities/LinkTypes";
7-
import type { TopoNode, TopoEdge } from "@srl-labs/clab-ui/core/types/graph";
5+
import { FilterUtils } from "../../../utils/filterUtils";
6+
import { isSpecialEndpointId } from "../../../core/utilities/LinkTypes";
7+
import type { TopoNode, TopoEdge } from "../../../core/types/graph";
88
import { hasEdgeBetween as hasEdgeBetweenUtil } from "../../../utils/graphQueryUtils";
99
import { allocateEndpoint, type EndpointAllocator } from "../../../utils/endpointAllocator";
1010

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export class FilterUtils {
2+
static createFilter(filterText: string) {
3+
if (!filterText) {
4+
return () => true;
5+
}
6+
7+
const regex = this.tryCreateRegExp(filterText);
8+
if (regex) {
9+
return (value: string) => regex.test(value);
10+
}
11+
12+
const searchText = filterText.toLowerCase();
13+
return (value: string) => value.toLowerCase().includes(searchText);
14+
}
15+
16+
static tryCreateRegExp(filterText: string, flags = "i"): RegExp | null {
17+
if (!filterText) {
18+
return null;
19+
}
20+
21+
const processedPattern = this.convertUserFriendlyPattern(filterText);
22+
23+
try {
24+
return new RegExp(processedPattern, flags);
25+
} catch {
26+
return null;
27+
}
28+
}
29+
30+
private static convertUserFriendlyPattern(pattern: string): string {
31+
if (this.looksLikeRegex(pattern)) {
32+
return pattern;
33+
}
34+
const hasWildcards = /[*?#]/.test(pattern);
35+
36+
let converted = pattern
37+
.replace(/\*/g, ".*")
38+
.replace(/\?/g, ".")
39+
.replace(/#/g, "\\d+");
40+
41+
if (hasWildcards) {
42+
converted = `^${converted}$`;
43+
}
44+
45+
return converted;
46+
}
47+
48+
private static looksLikeRegex(pattern: string): boolean {
49+
return (
50+
pattern.includes("\\") ||
51+
pattern.includes("[") ||
52+
pattern.includes("(") ||
53+
pattern.includes("|") ||
54+
pattern.includes("^") ||
55+
pattern.includes("$") ||
56+
pattern.includes(".*") ||
57+
pattern.includes(".+")
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)