@pallasoft/ps-core-components 2.32.0 → 2.33.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.
@@ -0,0 +1,23 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ export const usePsDebouncedRevalidate = (revalidator, delayMilliseconds) => {
3
+ const latest = useRef(revalidator);
4
+ const timer = useRef(null);
5
+ latest.current = revalidator;
6
+ const fire = useCallback(() => {
7
+ timer.current = null;
8
+ if (latest.current.state !== 'idle') {
9
+ timer.current = setTimeout(fire, delayMilliseconds);
10
+ return;
11
+ }
12
+ void latest.current.revalidate();
13
+ }, [delayMilliseconds]);
14
+ useEffect(() => () => {
15
+ if (timer.current !== null)
16
+ clearTimeout(timer.current);
17
+ }, []);
18
+ return useCallback(() => {
19
+ if (timer.current !== null)
20
+ clearTimeout(timer.current);
21
+ timer.current = setTimeout(fire, delayMilliseconds);
22
+ }, [delayMilliseconds, fire]);
23
+ };
@@ -0,0 +1,34 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export const usePsLive = (input) => {
3
+ const latest = useRef(input);
4
+ const { enabled, open, path } = input;
5
+ const eventKey = input.events.join(',');
6
+ latest.current = input;
7
+ useEffect(() => {
8
+ if (!enabled)
9
+ return;
10
+ let isActive = true;
11
+ let close = null;
12
+ void open({
13
+ events: latest.current.events,
14
+ fetchToken: () => latest.current.fetchToken(),
15
+ onEvent: (name, payload) => latest.current.onEvent(name, payload),
16
+ onResume: () => {
17
+ const { onResume } = latest.current;
18
+ if (onResume !== undefined)
19
+ onResume();
20
+ },
21
+ path,
22
+ }).then((handle) => {
23
+ if (isActive)
24
+ close = () => handle.close();
25
+ else
26
+ handle.close();
27
+ });
28
+ return () => {
29
+ isActive = false;
30
+ if (close !== null)
31
+ close();
32
+ };
33
+ }, [enabled, eventKey, open, path]);
34
+ };
package/dist/esm/index.js CHANGED
@@ -76,6 +76,8 @@ export * from './hooks/use-ps-debounced-value';
76
76
  export * from './hooks/use-ps-change-queue';
77
77
  export * from './interfaces/ps-change-queue-input';
78
78
  export * from './interfaces/ps-change-queue-result';
79
+ export * from './hooks/use-ps-live';
80
+ export * from './hooks/use-ps-debounced-revalidate';
79
81
  export * from './hooks/use-ps-optimistic-rows';
80
82
  export * from './hooks/use-ps-optimistic-fetcher';
81
83
  export * from './hooks/use-ps-optimistic-save';
@@ -88,6 +90,9 @@ export * from './services/ps-optimistic-save-service';
88
90
  export * from './services/ps-client-param-revalidation-service';
89
91
  export * from './interfaces/ps-fetcher-like';
90
92
  export * from './interfaces/ps-fetcher-submit-options';
93
+ export * from './interfaces/ps-live-handle';
94
+ export * from './interfaces/ps-live-input';
95
+ export * from './interfaces/ps-live-open-options';
91
96
  export * from './interfaces/ps-optimistic-fetcher-input';
92
97
  export * from './interfaces/ps-optimistic-fetcher-result';
93
98
  export * from './interfaces/ps-revalidator-like';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { PsRevalidatorLike } from '../interfaces/ps-revalidator-like';
2
+ export declare const usePsDebouncedRevalidate: (revalidator: PsRevalidatorLike, delayMilliseconds: number) => (() => void);
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePsDebouncedRevalidate = void 0;
4
+ const react_1 = require("react");
5
+ const usePsDebouncedRevalidate = (revalidator, delayMilliseconds) => {
6
+ const latest = (0, react_1.useRef)(revalidator);
7
+ const timer = (0, react_1.useRef)(null);
8
+ latest.current = revalidator;
9
+ const fire = (0, react_1.useCallback)(() => {
10
+ timer.current = null;
11
+ if (latest.current.state !== 'idle') {
12
+ timer.current = setTimeout(fire, delayMilliseconds);
13
+ return;
14
+ }
15
+ void latest.current.revalidate();
16
+ }, [delayMilliseconds]);
17
+ (0, react_1.useEffect)(() => () => {
18
+ if (timer.current !== null)
19
+ clearTimeout(timer.current);
20
+ }, []);
21
+ return (0, react_1.useCallback)(() => {
22
+ if (timer.current !== null)
23
+ clearTimeout(timer.current);
24
+ timer.current = setTimeout(fire, delayMilliseconds);
25
+ }, [delayMilliseconds, fire]);
26
+ };
27
+ exports.usePsDebouncedRevalidate = usePsDebouncedRevalidate;
@@ -0,0 +1,2 @@
1
+ import type { PsLiveInput } from '../interfaces/ps-live-input';
2
+ export declare const usePsLive: (input: PsLiveInput) => void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePsLive = void 0;
4
+ const react_1 = require("react");
5
+ const usePsLive = (input) => {
6
+ const latest = (0, react_1.useRef)(input);
7
+ const { enabled, open, path } = input;
8
+ const eventKey = input.events.join(',');
9
+ latest.current = input;
10
+ (0, react_1.useEffect)(() => {
11
+ if (!enabled)
12
+ return;
13
+ let isActive = true;
14
+ let close = null;
15
+ void open({
16
+ events: latest.current.events,
17
+ fetchToken: () => latest.current.fetchToken(),
18
+ onEvent: (name, payload) => latest.current.onEvent(name, payload),
19
+ onResume: () => {
20
+ const { onResume } = latest.current;
21
+ if (onResume !== undefined)
22
+ onResume();
23
+ },
24
+ path,
25
+ }).then((handle) => {
26
+ if (isActive)
27
+ close = () => handle.close();
28
+ else
29
+ handle.close();
30
+ });
31
+ return () => {
32
+ isActive = false;
33
+ if (close !== null)
34
+ close();
35
+ };
36
+ }, [enabled, eventKey, open, path]);
37
+ };
38
+ exports.usePsLive = usePsLive;
package/dist/index.d.ts CHANGED
@@ -76,6 +76,8 @@ export * from './hooks/use-ps-debounced-value';
76
76
  export * from './hooks/use-ps-change-queue';
77
77
  export * from './interfaces/ps-change-queue-input';
78
78
  export * from './interfaces/ps-change-queue-result';
79
+ export * from './hooks/use-ps-live';
80
+ export * from './hooks/use-ps-debounced-revalidate';
79
81
  export * from './hooks/use-ps-optimistic-rows';
80
82
  export * from './hooks/use-ps-optimistic-fetcher';
81
83
  export * from './hooks/use-ps-optimistic-save';
@@ -88,6 +90,9 @@ export * from './services/ps-optimistic-save-service';
88
90
  export * from './services/ps-client-param-revalidation-service';
89
91
  export * from './interfaces/ps-fetcher-like';
90
92
  export * from './interfaces/ps-fetcher-submit-options';
93
+ export * from './interfaces/ps-live-handle';
94
+ export * from './interfaces/ps-live-input';
95
+ export * from './interfaces/ps-live-open-options';
91
96
  export * from './interfaces/ps-optimistic-fetcher-input';
92
97
  export * from './interfaces/ps-optimistic-fetcher-result';
93
98
  export * from './interfaces/ps-revalidator-like';
package/dist/index.js CHANGED
@@ -92,6 +92,8 @@ __exportStar(require("./hooks/use-ps-debounced-value"), exports);
92
92
  __exportStar(require("./hooks/use-ps-change-queue"), exports);
93
93
  __exportStar(require("./interfaces/ps-change-queue-input"), exports);
94
94
  __exportStar(require("./interfaces/ps-change-queue-result"), exports);
95
+ __exportStar(require("./hooks/use-ps-live"), exports);
96
+ __exportStar(require("./hooks/use-ps-debounced-revalidate"), exports);
95
97
  __exportStar(require("./hooks/use-ps-optimistic-rows"), exports);
96
98
  __exportStar(require("./hooks/use-ps-optimistic-fetcher"), exports);
97
99
  __exportStar(require("./hooks/use-ps-optimistic-save"), exports);
@@ -104,6 +106,9 @@ __exportStar(require("./services/ps-optimistic-save-service"), exports);
104
106
  __exportStar(require("./services/ps-client-param-revalidation-service"), exports);
105
107
  __exportStar(require("./interfaces/ps-fetcher-like"), exports);
106
108
  __exportStar(require("./interfaces/ps-fetcher-submit-options"), exports);
109
+ __exportStar(require("./interfaces/ps-live-handle"), exports);
110
+ __exportStar(require("./interfaces/ps-live-input"), exports);
111
+ __exportStar(require("./interfaces/ps-live-open-options"), exports);
107
112
  __exportStar(require("./interfaces/ps-optimistic-fetcher-input"), exports);
108
113
  __exportStar(require("./interfaces/ps-optimistic-fetcher-result"), exports);
109
114
  __exportStar(require("./interfaces/ps-revalidator-like"), exports);
@@ -0,0 +1,3 @@
1
+ export interface PsLiveHandle {
2
+ close: () => void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import type { PsLiveHandle } from './ps-live-handle';
2
+ import type { PsLiveOpenOptions } from './ps-live-open-options';
3
+ export interface PsLiveInput {
4
+ enabled: boolean;
5
+ events: string[];
6
+ fetchToken: () => Promise<string | null>;
7
+ onEvent: (name: string, payload: unknown) => void;
8
+ onResume?: () => void;
9
+ open: (options: PsLiveOpenOptions) => Promise<PsLiveHandle>;
10
+ path: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface PsLiveOpenOptions {
2
+ events: string[];
3
+ fetchToken: () => Promise<string | null>;
4
+ onEvent: (name: string, payload: unknown) => void;
5
+ onResume: () => void;
6
+ path: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-core-components",
3
- "version": "2.32.0",
3
+ "version": "2.33.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",