sliftutils 0.15.0 → 0.17.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.
- package/.cursorrules +4 -0
- package/index.d.ts +8 -0
- package/misc/getSecret.ts +0 -1
- package/misc/matchFilter.d.ts +3 -0
- package/misc/matchFilter.ts +15 -0
- package/package.json +1 -1
- package/render-utils/Table.d.ts +1 -0
- package/render-utils/Table.tsx +3 -1
- package/web/browser.tsx +18 -0
package/.cursorrules
CHANGED
package/index.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ declare module "sliftutils/misc/getSecret" {
|
|
|
31
31
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
declare module "sliftutils/misc/matchFilter" {
|
|
35
|
+
export declare function matchFilter(filter: {
|
|
36
|
+
value: string;
|
|
37
|
+
}, value: string): boolean;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
declare module "sliftutils/misc/types" {
|
|
35
42
|
export declare function isDefined<T>(value: T | undefined | null): value is T;
|
|
36
43
|
|
|
@@ -310,6 +317,7 @@ declare module "sliftutils/render-utils/Table" {
|
|
|
310
317
|
lineLimit?: number;
|
|
311
318
|
characterLimit?: number;
|
|
312
319
|
excludeEmptyColumns?: boolean;
|
|
320
|
+
rowClassName?: (row: RowT) => string;
|
|
313
321
|
}> {
|
|
314
322
|
state: {
|
|
315
323
|
limit: number;
|
package/misc/getSecret.ts
CHANGED
|
@@ -69,7 +69,6 @@ export const getSecret = cache(async function getSecret(key: string): Promise<st
|
|
|
69
69
|
preact.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 10 } },
|
|
70
70
|
preact.createElement("div", { style: { fontWeight: "bold" } }, `Enter secret for: ${key}`),
|
|
71
71
|
preact.createElement("input", {
|
|
72
|
-
type: "password",
|
|
73
72
|
style: { padding: 10, fontSize: 16 },
|
|
74
73
|
onInput: (e: Event) => {
|
|
75
74
|
state.value = (e.target as HTMLInputElement).value;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function matchFilter(filter: { value: string }, value: string) {
|
|
2
|
+
let filterValue = filter.value.toLowerCase().trim();
|
|
3
|
+
if (!filterValue) return true;
|
|
4
|
+
value = value.toLowerCase().trim();
|
|
5
|
+
return filterValue.split("|").some(part =>
|
|
6
|
+
part.split("&").every(part => {
|
|
7
|
+
part = part.trim();
|
|
8
|
+
if (part.startsWith("!")) {
|
|
9
|
+
part = part.slice(1).trim();
|
|
10
|
+
return !value.includes(part);
|
|
11
|
+
}
|
|
12
|
+
return value.includes(part);
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
}
|
package/package.json
CHANGED
package/render-utils/Table.d.ts
CHANGED
package/render-utils/Table.tsx
CHANGED
|
@@ -32,6 +32,8 @@ export class Table<RowT extends RowType> extends preact.Component<TableType<RowT
|
|
|
32
32
|
characterLimit?: number;
|
|
33
33
|
|
|
34
34
|
excludeEmptyColumns?: boolean;
|
|
35
|
+
|
|
36
|
+
rowClassName?: (row: RowT) => string
|
|
35
37
|
}> {
|
|
36
38
|
state = {
|
|
37
39
|
limit: this.props.initialLimit || 100,
|
|
@@ -65,7 +67,7 @@ export class Table<RowT extends RowType> extends preact.Component<TableType<RowT
|
|
|
65
67
|
</tr>
|
|
66
68
|
{rows.map((row, index) => (
|
|
67
69
|
<tr
|
|
68
|
-
className={(index % 2 === 1 && css.hsla(0, 0, 100, 0.25) || "")}
|
|
70
|
+
className={(this.props.rowClassName?.(row) || "") + (index % 2 === 1 && css.hsla(0, 0, 100, 0.25) || "")}
|
|
69
71
|
>
|
|
70
72
|
<td className={css.center}>{index + 1}</td>
|
|
71
73
|
{Object.entries(columns).filter(x => x[1] !== null).map(([columnName, column]: [string, ColumnType]) => {
|
package/web/browser.tsx
CHANGED
|
@@ -14,6 +14,24 @@ class App extends preact.Component {
|
|
|
14
14
|
count: 0,
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
+
onKeyDown = (e: KeyboardEvent) => {
|
|
18
|
+
// Skip if the current target is an ipnut
|
|
19
|
+
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let hotkeySelector = `[data-hotkey="${e.code}"]`;
|
|
23
|
+
let elements = document.querySelectorAll(hotkeySelector);
|
|
24
|
+
for (let element of elements) {
|
|
25
|
+
(element as HTMLElement).click();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
componentDidMount(): void {
|
|
29
|
+
document.addEventListener("keydown", this.onKeyDown);
|
|
30
|
+
}
|
|
31
|
+
componentWillUnmount(): void {
|
|
32
|
+
document.removeEventListener("keydown", this.onKeyDown);
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
render() {
|
|
18
36
|
return (
|
|
19
37
|
<div className={css.pad2(20)}>
|