@neovici/cosmoz-queue 2.11.1 → 2.11.3
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/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/queue/map-actions.d.ts +14 -0
- package/dist/queue/map-actions.d.ts.map +1 -0
- package/dist/queue/map-actions.js +14 -0
- package/dist/queue/use-fetch-actions.d.ts +3 -19
- package/dist/queue/use-fetch-actions.d.ts.map +1 -1
- package/dist/queue/use-fetch-actions.js +15 -10
- package/package.json +1 -1
package/dist/queue/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { default as omnitable } from './omnitable';
|
|
|
10
10
|
export { usePagination } from './pagination';
|
|
11
11
|
export { queue } from './queue';
|
|
12
12
|
export { base, default as renderStyles } from './style';
|
|
13
|
-
export { actions$, default as useFetchActions } from './use-fetch-actions';
|
|
13
|
+
export { actions$, mapActions, noActions, default as useFetchActions, } from './use-fetch-actions';
|
|
14
14
|
export type { Item, Props } from './use-fetch-actions';
|
|
15
15
|
export { useListSSE } from './use-list-sse';
|
|
16
16
|
export { default as useDataNav } from './use-data-nav';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEzC,cAAc,UAAU,CAAC;AAEzB,mBAAmB,SAAS,CAAC;AAC7B,mBAAmB,aAAa,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CA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EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/queue/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { queue } from './queue';
|
|
|
14
14
|
// Styling
|
|
15
15
|
export { base, default as renderStyles } from './style';
|
|
16
16
|
// Fetch actions
|
|
17
|
-
export { actions$, default as useFetchActions } from './use-fetch-actions';
|
|
17
|
+
export { actions$, mapActions, noActions, default as useFetchActions, } from './use-fetch-actions';
|
|
18
18
|
// SSE
|
|
19
19
|
export { useListSSE } from './use-list-sse';
|
|
20
20
|
// Navigation & layout hooks
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Performable } from '../types/performable';
|
|
2
|
+
export interface Data<TAvailableAction> {
|
|
3
|
+
[key: string]: Performable<TAvailableAction>[];
|
|
4
|
+
}
|
|
5
|
+
export type TMapActions<T> = {
|
|
6
|
+
actions: Data<T>;
|
|
7
|
+
actionRows: {
|
|
8
|
+
id: string;
|
|
9
|
+
actions: Performable<T>[];
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export declare const noActions: TMapActions<never>;
|
|
13
|
+
export declare const mapActions: <TAvailableAction>(ids: string[], data?: Data<TAvailableAction>) => TMapActions<TAvailableAction>;
|
|
14
|
+
//# sourceMappingURL=map-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-actions.d.ts","sourceRoot":"","sources":["../../src/queue/map-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,WAAW,IAAI,CAAC,gBAAgB;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;CAC/C;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAA;KAAE,EAAE,CAAC;CACxD,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,WAAW,CAAC,KAAK,CAGxC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,gBAAgB,EAC1C,KAAK,MAAM,EAAE,EACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAC3B,WAAW,CAAC,gBAAgB,CAQ9B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const noActions = {
|
|
2
|
+
actions: {},
|
|
3
|
+
actionRows: [],
|
|
4
|
+
};
|
|
5
|
+
export const mapActions = (ids, data) => {
|
|
6
|
+
if (!data)
|
|
7
|
+
return noActions;
|
|
8
|
+
const acts = { ...data };
|
|
9
|
+
const rows = ids.map((id) => {
|
|
10
|
+
const ac = (acts[id] ??= []);
|
|
11
|
+
return { id, actions: ac };
|
|
12
|
+
});
|
|
13
|
+
return { actions: acts, actionRows: rows };
|
|
14
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
[key: string]: Performable<TAvailableAction>[];
|
|
4
|
-
}
|
|
1
|
+
import { mapActions, TMapActions } from './map-actions';
|
|
2
|
+
export { Data, mapActions, noActions, TMapActions } from './map-actions';
|
|
5
3
|
export interface Item {
|
|
6
4
|
id: string;
|
|
7
5
|
}
|
|
@@ -10,21 +8,7 @@ export interface Props<I extends Item> {
|
|
|
10
8
|
selected: I[];
|
|
11
9
|
api: string;
|
|
12
10
|
}
|
|
13
|
-
declare const
|
|
14
|
-
actions: {
|
|
15
|
-
[key: string]: Performable<TAvailableAction>[];
|
|
16
|
-
};
|
|
17
|
-
actionRows: {
|
|
18
|
-
id: string;
|
|
19
|
-
actions: Performable<TAvailableAction>[];
|
|
20
|
-
}[];
|
|
21
|
-
};
|
|
22
|
-
declare const _default: <I extends Item, TAvailableAction>({ pathLocator, selected, api: url, }: Props<I>) => {
|
|
23
|
-
actions: Data<TAvailableAction>;
|
|
24
|
-
actionRows: {
|
|
25
|
-
id: string;
|
|
26
|
-
actions: Performable<TAvailableAction>[];
|
|
27
|
-
}[];
|
|
11
|
+
declare const _default: <I extends Item, TAvailableAction>({ pathLocator, selected, api: url, }: Props<I>) => TMapActions<TAvailableAction> & {
|
|
28
12
|
actionsFetching: boolean | undefined;
|
|
29
13
|
};
|
|
30
14
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fetch-actions.d.ts","sourceRoot":"","sources":["../../src/queue/use-fetch-actions.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"use-fetch-actions.d.ts","sourceRoot":"","sources":["../../src/queue/use-fetch-actions.ts"],"names":[],"mappings":"AASA,OAAO,EAAQ,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEzE,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,MAAM,CAAC;CACX;AACD,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,IAAI;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ;yBAQe,CAAC,SAAS,IAAI,EAAE,gBAAgB,EAAE,sCAI/C,KAAK,CAAC,CAAC,CAAC,KAAG,WAAW,CAAC,gBAAgB,CAAC,GAAG;IAC7C,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC;CACrC;AAND,wBAgDE;AAEF,eAAO,MAAM,QAAQ,GAAI,gBAAgB,EAAE,iDAMxC;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,aAAa,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,OAAO,CAAC;IAChE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;CACjB;;;;cAiBC,CAAC"}
|
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
import { debounce$ } from '@neovici/cosmoz-utils/promise';
|
|
2
|
-
import { useEffect, useMemo, useState } from '@pionjs/pion';
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from '@pionjs/pion';
|
|
3
3
|
import { jsonPost } from '../util/fetch/fetch';
|
|
4
4
|
import { apiUrl } from '../util/fetch/url';
|
|
5
5
|
import { nothing } from 'lit-html';
|
|
6
6
|
import { guard } from 'lit-html/directives/guard.js';
|
|
7
7
|
import { until } from 'lit-html/directives/until.js';
|
|
8
8
|
import { when } from 'lit-html/directives/when.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const rows = ids.map((id) => {
|
|
12
|
-
const ac = (acts[id] ??= []);
|
|
13
|
-
return { id, actions: ac };
|
|
14
|
-
});
|
|
15
|
-
return { actions: acts, actionRows: rows };
|
|
16
|
-
};
|
|
9
|
+
import { mapActions } from './map-actions';
|
|
10
|
+
export { mapActions, noActions } from './map-actions';
|
|
17
11
|
export default ({ pathLocator, selected, api: url, }) => {
|
|
18
12
|
const [{ fetching: actionsFetching, data }, setApi$] = useState({}), ids = useMemo(() => selected?.map((i) => i.id) ?? [], [selected]), { actions, actionRows } = useMemo(() => mapActions(ids, data), [ids.length, ...ids, data]);
|
|
19
13
|
const post$ = useMemo(() => debounce$(jsonPost, 320), []);
|
|
14
|
+
const reqId = useRef(0);
|
|
20
15
|
useEffect(() => {
|
|
21
16
|
if (ids.length < 1) {
|
|
22
17
|
setApi$({});
|
|
23
18
|
return;
|
|
24
19
|
}
|
|
20
|
+
const thisReq = (reqId.current = reqId.current + 1);
|
|
25
21
|
const ac = new AbortController();
|
|
26
22
|
setApi$(() => ({
|
|
27
23
|
api$: post$(apiUrl(url, { pathLocator }), ids, {
|
|
28
24
|
signal: ac.signal,
|
|
29
|
-
}).then((data) =>
|
|
25
|
+
}).then((data) => {
|
|
26
|
+
if (reqId.current !== thisReq)
|
|
27
|
+
return;
|
|
28
|
+
setApi$((api) => ({ ...api, fetching: false, data }));
|
|
29
|
+
}, (err) => {
|
|
30
|
+
if (err?.name === 'AbortError' || reqId.current !== thisReq)
|
|
31
|
+
return;
|
|
32
|
+
setApi$({ error: err });
|
|
33
|
+
}),
|
|
30
34
|
fetching: true,
|
|
35
|
+
data: undefined,
|
|
31
36
|
}));
|
|
32
37
|
return () => ac.abort();
|
|
33
38
|
}, [ids.length, pathLocator, ...ids]);
|