sliftutils 0.15.0 → 0.16.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 CHANGED
@@ -82,6 +82,10 @@ Coding Styles
82
82
  Never use inline styles, always use the CSS helper.
83
83
 
84
84
  Don't use as any.
85
+
86
+ DO NOT redeclare constants and copy their value. JUST IMPORT THEM!
87
+
88
+ DO NOT redeclare types. JUST IMPORT THEM!
85
89
 
86
90
 
87
91
  General Styling
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
 
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,3 @@
1
+ export declare function matchFilter(filter: {
2
+ value: string;
3
+ }, value: string): boolean;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
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)}>