@neovici/cosmoz-queue 1.0.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/README.md +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/queue/actions/index.d.ts +22 -0
- package/dist/queue/actions/index.d.ts.map +1 -0
- package/dist/queue/actions/index.js +20 -0
- package/dist/queue/icon.d.ts +2 -0
- package/dist/queue/icon.d.ts.map +1 -0
- package/dist/queue/icon.js +12 -0
- package/dist/queue/icons.d.ts +4 -0
- package/dist/queue/icons.d.ts.map +1 -0
- package/dist/queue/icons.js +61 -0
- package/dist/queue/index.d.ts +8 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.js +5 -0
- package/dist/queue/item-click.d.ts +5 -0
- package/dist/queue/item-click.d.ts.map +1 -0
- package/dist/queue/item-click.js +15 -0
- package/dist/queue/list-core/column.d.ts +34 -0
- package/dist/queue/list-core/column.d.ts.map +1 -0
- package/dist/queue/list-core/column.js +10 -0
- package/dist/queue/list-core/index.d.ts +7 -0
- package/dist/queue/list-core/index.d.ts.map +1 -0
- package/dist/queue/list-core/index.js +6 -0
- package/dist/queue/list-core/list-core.d.ts +6 -0
- package/dist/queue/list-core/list-core.d.ts.map +1 -0
- package/dist/queue/list-core/list-core.js +6 -0
- package/dist/queue/list-core/render-generic-actions.d.ts +4 -0
- package/dist/queue/list-core/render-generic-actions.d.ts.map +1 -0
- package/dist/queue/list-core/render-generic-actions.js +14 -0
- package/dist/queue/list-core/render-list-core.d.ts +18 -0
- package/dist/queue/list-core/render-list-core.d.ts.map +1 -0
- package/dist/queue/list-core/render-list-core.js +42 -0
- package/dist/queue/list-core/style.css.d.ts +2 -0
- package/dist/queue/list-core/style.css.d.ts.map +1 -0
- package/dist/queue/list-core/style.css.js +20 -0
- package/dist/queue/list-core/use-inline-actions.d.ts +4 -0
- package/dist/queue/list-core/use-inline-actions.d.ts.map +1 -0
- package/dist/queue/list-core/use-inline-actions.js +10 -0
- package/dist/queue/list-core/use-list-core.d.ts +34 -0
- package/dist/queue/list-core/use-list-core.d.ts.map +1 -0
- package/dist/queue/list-core/use-list-core.js +36 -0
- package/dist/queue/list-core/use-list-state.d.ts +24 -0
- package/dist/queue/list-core/use-list-state.d.ts.map +1 -0
- package/dist/queue/list-core/use-list-state.js +25 -0
- package/dist/queue/list-core/use-more.d.ts +23 -0
- package/dist/queue/list-core/use-more.d.ts.map +1 -0
- package/dist/queue/list-core/use-more.js +41 -0
- package/dist/queue/omnitable.d.ts +19 -0
- package/dist/queue/omnitable.d.ts.map +1 -0
- package/dist/queue/omnitable.js +31 -0
- package/dist/queue/pagination.d.ts +5 -0
- package/dist/queue/pagination.d.ts.map +1 -0
- package/dist/queue/pagination.js +10 -0
- package/dist/queue/queue.d.ts +24 -0
- package/dist/queue/queue.d.ts.map +1 -0
- package/dist/queue/queue.js +58 -0
- package/dist/queue/render.d.ts +74 -0
- package/dist/queue/render.d.ts.map +1 -0
- package/dist/queue/render.js +134 -0
- package/dist/queue/style.d.ts +7 -0
- package/dist/queue/style.d.ts.map +1 -0
- package/dist/queue/style.js +182 -0
- package/dist/queue/test/__snapshots__/render.test.snap.d.ts +2 -0
- package/dist/queue/test/__snapshots__/render.test.snap.d.ts.map +1 -0
- package/dist/queue/test/__snapshots__/render.test.snap.js +64 -0
- package/dist/queue/test/item-click.test.d.ts +2 -0
- package/dist/queue/test/item-click.test.d.ts.map +1 -0
- package/dist/queue/test/item-click.test.js +28 -0
- package/dist/queue/test/render.test.d.ts +2 -0
- package/dist/queue/test/render.test.d.ts.map +1 -0
- package/dist/queue/test/render.test.js +27 -0
- package/dist/queue/test/use-pref.test.d.ts +2 -0
- package/dist/queue/test/use-pref.test.d.ts.map +1 -0
- package/dist/queue/test/use-pref.test.js +16 -0
- package/dist/queue/types.d.ts +10 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/queue/types.js +1 -0
- package/dist/queue/use-async-action.d.ts +15 -0
- package/dist/queue/use-async-action.d.ts.map +1 -0
- package/dist/queue/use-async-action.js +17 -0
- package/dist/queue/use-data-nav.d.ts +20 -0
- package/dist/queue/use-data-nav.d.ts.map +1 -0
- package/dist/queue/use-data-nav.js +59 -0
- package/dist/queue/use-data-service.d.ts +31 -0
- package/dist/queue/use-data-service.d.ts.map +1 -0
- package/dist/queue/use-data-service.js +26 -0
- package/dist/queue/use-fetch-actions.d.ts +42 -0
- package/dist/queue/use-fetch-actions.d.ts.map +1 -0
- package/dist/queue/use-fetch-actions.js +38 -0
- package/dist/queue/use-key-nav.d.ts +8 -0
- package/dist/queue/use-key-nav.d.ts.map +1 -0
- package/dist/queue/use-key-nav.js +49 -0
- package/dist/queue/use-list-sse.d.ts +42 -0
- package/dist/queue/use-list-sse.d.ts.map +1 -0
- package/dist/queue/use-list-sse.js +82 -0
- package/dist/queue/use-list.d.ts +33 -0
- package/dist/queue/use-list.d.ts.map +1 -0
- package/dist/queue/use-list.js +42 -0
- package/dist/queue/use-pref.d.ts +5 -0
- package/dist/queue/use-pref.d.ts.map +1 -0
- package/dist/queue/use-pref.js +11 -0
- package/dist/queue/use-queue.d.ts +132 -0
- package/dist/queue/use-queue.d.ts.map +1 -0
- package/dist/queue/use-queue.js +69 -0
- package/dist/queue/use-split.d.ts +8 -0
- package/dist/queue/use-split.d.ts.map +1 -0
- package/dist/queue/use-split.js +30 -0
- package/dist/queue/use-tabs.d.ts +54 -0
- package/dist/queue/use-tabs.d.ts.map +1 -0
- package/dist/queue/use-tabs.js +31 -0
- package/dist/queue/use-updates.d.ts +9 -0
- package/dist/queue/use-updates.d.ts.map +1 -0
- package/dist/queue/use-updates.js +17 -0
- package/dist/queue/util.d.ts +4 -0
- package/dist/queue/util.d.ts.map +1 -0
- package/dist/queue/util.js +16 -0
- package/dist/types/dialogable.d.ts +39 -0
- package/dist/types/dialogable.d.ts.map +1 -0
- package/dist/types/dialogable.js +5 -0
- package/dist/types/performable.d.ts +5 -0
- package/dist/types/performable.d.ts.map +1 -0
- package/dist/types/performable.js +1 -0
- package/dist/util/dom/active-element.d.ts +3 -0
- package/dist/util/dom/active-element.d.ts.map +1 -0
- package/dist/util/dom/active-element.js +11 -0
- package/dist/util/fetch/fetch.d.ts +41 -0
- package/dist/util/fetch/fetch.d.ts.map +1 -0
- package/dist/util/fetch/fetch.js +74 -0
- package/dist/util/fetch/url.d.ts +30 -0
- package/dist/util/fetch/url.d.ts.map +1 -0
- package/dist/util/fetch/url.js +29 -0
- package/dist/util/path.d.ts +42 -0
- package/dist/util/path.d.ts.map +1 -0
- package/dist/util/path.js +68 -0
- package/dist/util/polymer-property-changed-event.d.ts +6 -0
- package/dist/util/polymer-property-changed-event.d.ts.map +1 -0
- package/dist/util/polymer-property-changed-event.js +27 -0
- package/dist/util/test/path.test.d.ts +2 -0
- package/dist/util/test/path.test.d.ts.map +1 -0
- package/dist/util/test/path.test.js +99 -0
- package/package.json +113 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* @web/test-runner snapshot v1 */
|
|
2
|
+
export const snapshots = {};
|
|
3
|
+
snapshots['queue > render renderNav'] = `<button
|
|
4
|
+
class="button-nav prev"
|
|
5
|
+
disabled=""
|
|
6
|
+
slot="extra"
|
|
7
|
+
>
|
|
8
|
+
</button>
|
|
9
|
+
`;
|
|
10
|
+
/* end snapshot queue > render renderNav */
|
|
11
|
+
snapshots['queue > render renderPagination'] = `<div class="tabn-pagination">
|
|
12
|
+
<button class="button-page page-prev">
|
|
13
|
+
</button>
|
|
14
|
+
<button class="button-page page-next">
|
|
15
|
+
</button>
|
|
16
|
+
</div>
|
|
17
|
+
`;
|
|
18
|
+
/* end snapshot queue > render renderPagination */
|
|
19
|
+
snapshots['queue > render renderNav'] = `<button
|
|
20
|
+
class="button-nav prev"
|
|
21
|
+
disabled=""
|
|
22
|
+
name="Previous item"
|
|
23
|
+
slot="extra"
|
|
24
|
+
>
|
|
25
|
+
</button>
|
|
26
|
+
`;
|
|
27
|
+
/* end snapshot queue > render renderNav */
|
|
28
|
+
snapshots['queue > render renderPagination'] = `<div class="tabn-pagination">
|
|
29
|
+
<button
|
|
30
|
+
class="button-page page-prev"
|
|
31
|
+
name="Previous page"
|
|
32
|
+
>
|
|
33
|
+
</button>
|
|
34
|
+
<button
|
|
35
|
+
class="button-page page-next"
|
|
36
|
+
name="Next page"
|
|
37
|
+
>
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
`;
|
|
41
|
+
/* end snapshot queue > render renderPagination */
|
|
42
|
+
snapshots['queue > render renderNav'] = `<button
|
|
43
|
+
class="button-nav prev"
|
|
44
|
+
disabled=""
|
|
45
|
+
slot="extra"
|
|
46
|
+
title=""
|
|
47
|
+
>
|
|
48
|
+
</button>
|
|
49
|
+
`;
|
|
50
|
+
/* end snapshot queue > render renderNav */
|
|
51
|
+
snapshots['queue > render renderPagination'] = `<div class="tabn-pagination">
|
|
52
|
+
<button
|
|
53
|
+
class="button-page page-prev"
|
|
54
|
+
title=""
|
|
55
|
+
>
|
|
56
|
+
</button>
|
|
57
|
+
<button
|
|
58
|
+
class="button-page page-next"
|
|
59
|
+
title=""
|
|
60
|
+
>
|
|
61
|
+
</button>
|
|
62
|
+
</div>
|
|
63
|
+
`;
|
|
64
|
+
/* end snapshot queue > render renderPagination */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-click.test.d.ts","sourceRoot":"","sources":["../../../src/queue/test/item-click.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { assert, oneEvent } from '@open-wc/testing';
|
|
2
|
+
import { oneDefaultPreventedEvent } from '@open-wc/testing-helpers';
|
|
3
|
+
import { itemClick } from '../item-click';
|
|
4
|
+
suite('item-click', () => {
|
|
5
|
+
test('fires event', async () => {
|
|
6
|
+
const el = document.createElement('div');
|
|
7
|
+
el.addEventListener('click', itemClick({ index: 2, activate: 'queue' }));
|
|
8
|
+
setTimeout(() => el.click());
|
|
9
|
+
const { detail } = await oneEvent(el, 'omnitable-item-click');
|
|
10
|
+
assert.equal(detail.index, 2);
|
|
11
|
+
assert.equal(detail.activate, 'queue');
|
|
12
|
+
});
|
|
13
|
+
test('prevents default', async () => {
|
|
14
|
+
const el = document.createElement('div');
|
|
15
|
+
const ev = new MouseEvent('click');
|
|
16
|
+
el.addEventListener('click', itemClick({ index: 3, activate: 'list' }));
|
|
17
|
+
setTimeout(() => el.dispatchEvent(ev));
|
|
18
|
+
const { detail } = await oneDefaultPreventedEvent(el, 'omnitable-item-click');
|
|
19
|
+
assert.equal(detail.index, 3);
|
|
20
|
+
assert.equal(detail.activate, 'list');
|
|
21
|
+
});
|
|
22
|
+
test('does not fire event', async () => {
|
|
23
|
+
const el = document.createElement('div');
|
|
24
|
+
const ev = new MouseEvent('click', { ctrlKey: true });
|
|
25
|
+
el.addEventListener('click', itemClick({ index: 3, activate: 'list' }));
|
|
26
|
+
setTimeout(() => el.dispatchEvent(ev));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.test.d.ts","sourceRoot":"","sources":["../../../src/queue/test/render.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing';
|
|
2
|
+
import { nothing } from 'lit-html';
|
|
3
|
+
import { spy } from 'sinon';
|
|
4
|
+
import { renderNav, renderPagination } from '../render';
|
|
5
|
+
suite('queue > render', () => {
|
|
6
|
+
test('renderNav', async () => {
|
|
7
|
+
const el = await fixture(renderNav({}));
|
|
8
|
+
await expect(el).dom.to.equalSnapshot();
|
|
9
|
+
});
|
|
10
|
+
test('renderPagination nothing', async () => {
|
|
11
|
+
expect(renderPagination()).to.equal(nothing);
|
|
12
|
+
});
|
|
13
|
+
test('renderPagination', async () => {
|
|
14
|
+
const onPage = spy();
|
|
15
|
+
const el = await fixture(renderPagination({
|
|
16
|
+
totalPages: 10,
|
|
17
|
+
pageNumber: 3,
|
|
18
|
+
onPage,
|
|
19
|
+
}));
|
|
20
|
+
await expect(el).dom.to.equalSnapshot();
|
|
21
|
+
el.querySelector('.page-next')?.click();
|
|
22
|
+
expect(onPage).to.have.been.calledWith(4);
|
|
23
|
+
onPage.resetHistory();
|
|
24
|
+
el.querySelector('.page-prev')?.click();
|
|
25
|
+
expect(onPage).to.have.been.calledWith(2);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pref.test.d.ts","sourceRoot":"","sources":["../../../src/queue/test/use-pref.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { renderHook } from '@neovici/testing';
|
|
2
|
+
import { assert } from '@open-wc/testing';
|
|
3
|
+
import { usePref } from '../use-pref';
|
|
4
|
+
suite('use-pref', () => {
|
|
5
|
+
test('default pref', async () => {
|
|
6
|
+
const { result } = await renderHook(() => usePref('some', 'asdad'));
|
|
7
|
+
assert.equal(result.current[0], 'asdad');
|
|
8
|
+
});
|
|
9
|
+
test('update pref', async () => {
|
|
10
|
+
const { result, nextUpdate } = await renderHook(() => usePref('somethingelse'));
|
|
11
|
+
assert.equal(result.current[0], undefined);
|
|
12
|
+
setTimeout(() => result.current[1]('dads'));
|
|
13
|
+
await nextUpdate();
|
|
14
|
+
assert.equal(result.current[0], 'dads');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/queue/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IAE1B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Rec } from '@neovici/cosmoz-utils/object';
|
|
2
|
+
export interface Ot extends HTMLElement {
|
|
3
|
+
removeItem: <T>(item: T) => void;
|
|
4
|
+
}
|
|
5
|
+
interface Props {
|
|
6
|
+
next?: () => void;
|
|
7
|
+
property?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: ({ next, property }: Props) => {
|
|
10
|
+
listRef: import("@pionjs/pion").Ref<Ot | undefined>;
|
|
11
|
+
remove: <T extends Rec>(item: T) => void;
|
|
12
|
+
onAsyncSimpleAction: (e: CustomEvent) => void;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
15
|
+
//# sourceMappingURL=use-async-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-async-action.d.ts","sourceRoot":"","sources":["../../src/queue/use-async-action.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAExD,MAAM,WAAW,EAAG,SAAQ,WAAW;IACtC,UAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CACjC;AAED,UAAU,KAAK;IACd,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;yBAEe,oBAA2B,KAAK;;aAG5C,CAAC,SAAS,GAAG,QAAQ,CAAC;6BAUnB,WAAW;;AAblB,wBAsBE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef, useCallback } from '@pionjs/pion';
|
|
2
|
+
export default ({ next, property = 'id' }) => {
|
|
3
|
+
const listRef = useRef(undefined), remove = useCallback((item) => {
|
|
4
|
+
next?.();
|
|
5
|
+
listRef.current?.removeItem?.(item);
|
|
6
|
+
}, [next]);
|
|
7
|
+
return {
|
|
8
|
+
listRef,
|
|
9
|
+
remove,
|
|
10
|
+
onAsyncSimpleAction: useCallback((e) => {
|
|
11
|
+
const id = e.detail[property];
|
|
12
|
+
if (id) {
|
|
13
|
+
remove({ id });
|
|
14
|
+
}
|
|
15
|
+
}, [property, remove]),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useHashParam } from '@neovici/cosmoz-router/use-hash-param';
|
|
2
|
+
export interface MapId<I> {
|
|
3
|
+
(i: I): string;
|
|
4
|
+
}
|
|
5
|
+
export interface Opts<I> {
|
|
6
|
+
id: MapId<I>;
|
|
7
|
+
hashParam: Parameters<typeof useHashParam>['0'];
|
|
8
|
+
maintainSelection?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: <I>(items: I[], { id, hashParam, maintainSelection }: Opts<I>) => {
|
|
11
|
+
forward: boolean;
|
|
12
|
+
index: number;
|
|
13
|
+
item: I;
|
|
14
|
+
items: I[];
|
|
15
|
+
setItem: import("@pionjs/pion").StateUpdater<I>;
|
|
16
|
+
prev: (() => void) | undefined;
|
|
17
|
+
next: (() => void) | undefined;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
|
20
|
+
//# sourceMappingURL=use-data-nav.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-data-nav.d.ts","sourceRoot":"","sources":["../../src/queue/use-data-nav.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAQ,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CACf;AAeD,MAAM,WAAW,IAAI,CAAC,CAAC;IACtB,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACb,SAAS,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC;IAChD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC5B;yBAEe,CAAC,EAChB,OAAO,CAAC,EAAE,EACV,sCAA6D,IAAI,CAAC,CAAC,CAAC;;;;;;;;;AAFrE,wBA6DE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from '@pionjs/pion';
|
|
2
|
+
import { identity } from '@neovici/cosmoz-utils/function';
|
|
3
|
+
import { useHashParam, link } from '@neovici/cosmoz-router/use-hash-param';
|
|
4
|
+
import { navigate } from '@neovici/cosmoz-router';
|
|
5
|
+
const useLastValue = (value) => {
|
|
6
|
+
const lastValue = useRef(undefined);
|
|
7
|
+
// eslint-disable-next-line no-void
|
|
8
|
+
useEffect(() => void (lastValue.current = value), [value]);
|
|
9
|
+
return lastValue.current;
|
|
10
|
+
};
|
|
11
|
+
const find = (list, item, id, index) => list.find((i) => id(i) === id(item)) ?? list[index] ?? list[0];
|
|
12
|
+
const findByParam = (list, param, id) => list.find((i) => id(i) === param) ?? list[0];
|
|
13
|
+
export default (items, { id = identity, hashParam, maintainSelection }) => {
|
|
14
|
+
const [item, setItem] = useState(() => items[0]), [param] = useHashParam(hashParam), index = useMemo(() => items.indexOf(item), [items, item]), prevIndex = useLastValue(index), { prev, next } = useMemo(() => {
|
|
15
|
+
const end = items.length - 1;
|
|
16
|
+
return {
|
|
17
|
+
...(index > 0 && {
|
|
18
|
+
prev: () => setItem(items[Math.max(0, Math.min(end, index - 1))]),
|
|
19
|
+
}),
|
|
20
|
+
...(index < end && {
|
|
21
|
+
next: () => setItem(items[Math.max(0, Math.min(end, index + 1))]),
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
}, [items, index]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!item || !hashParam) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
navigate(link(hashParam, id(item)), null, {
|
|
30
|
+
notify: false,
|
|
31
|
+
});
|
|
32
|
+
}, [item]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (items.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setItem((item) => {
|
|
38
|
+
if (!item && param != null) {
|
|
39
|
+
return findByParam(items, param, id);
|
|
40
|
+
}
|
|
41
|
+
if (items.indexOf(item) >= 0) {
|
|
42
|
+
return item;
|
|
43
|
+
}
|
|
44
|
+
if (!item || !maintainSelection) {
|
|
45
|
+
return items[0];
|
|
46
|
+
}
|
|
47
|
+
return find(items, item, id, prevIndex);
|
|
48
|
+
});
|
|
49
|
+
}, [items, param]);
|
|
50
|
+
return {
|
|
51
|
+
forward: index > prevIndex,
|
|
52
|
+
index,
|
|
53
|
+
item,
|
|
54
|
+
items,
|
|
55
|
+
setItem,
|
|
56
|
+
prev,
|
|
57
|
+
next,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Rec } from '@neovici/cosmoz-utils/object';
|
|
2
|
+
interface Item extends Rec {
|
|
3
|
+
id: string;
|
|
4
|
+
}
|
|
5
|
+
interface Update<I extends Item> {
|
|
6
|
+
type: string;
|
|
7
|
+
id: string;
|
|
8
|
+
data: {
|
|
9
|
+
header: I & {
|
|
10
|
+
actions: {
|
|
11
|
+
action: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface Listener<I extends Item> {
|
|
17
|
+
(update: Update<I>): void;
|
|
18
|
+
}
|
|
19
|
+
interface DataService<I extends Item> {
|
|
20
|
+
subscribe: (listener: Listener<I>, ids: string[]) => void;
|
|
21
|
+
unsubscribe: (listener: Listener<I>, ids: string[]) => void;
|
|
22
|
+
}
|
|
23
|
+
interface Opts<I extends Item> {
|
|
24
|
+
items: I[];
|
|
25
|
+
dataService: DataService<I>;
|
|
26
|
+
intendedActions: string[];
|
|
27
|
+
remove: (i: I) => void;
|
|
28
|
+
}
|
|
29
|
+
declare const _default: <I extends Item>(opts: Opts<I>) => void;
|
|
30
|
+
export default _default;
|
|
31
|
+
//# sourceMappingURL=use-data-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-data-service.d.ts","sourceRoot":"","sources":["../../src/queue/use-data-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAEnD,UAAU,IAAK,SAAQ,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;CACX;AACD,UAAU,MAAM,CAAC,CAAC,SAAS,IAAI;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE;QAAE,MAAM,EAAE,CAAC,GAAG;YAAE,OAAO,EAAE;gBAAE,MAAM,EAAE,MAAM,CAAA;aAAE,EAAE,CAAA;SAAE,CAAA;KAAE,CAAC;CACxD;AACD,UAAU,QAAQ,CAAC,CAAC,SAAS,IAAI;IAChC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC1B;AACD,UAAU,WAAW,CAAC,CAAC,SAAS,IAAI;IACnC,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1D,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC5D;AAED,UAAU,IAAI,CAAC,CAAC,SAAS,IAAI;IAC5B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;CACvB;yBAEe,CAAC,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;AAA7C,wBA2BE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect } from '@pionjs/pion';
|
|
2
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
|
+
export default (opts) => {
|
|
4
|
+
const { items, dataService } = opts, meta = useMeta(opts);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const { intendedActions, remove } = meta, onUpdate = (update) => {
|
|
7
|
+
switch (update.type) {
|
|
8
|
+
case 'ITEM_UPDATE': {
|
|
9
|
+
if (!intendedActions) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const header = items.find((i) => i.id === update.id);
|
|
13
|
+
if (!header) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const actions = update.data?.header?.actions ?? header?.actions;
|
|
17
|
+
if (actions?.every((a) => !intendedActions.includes(a.action))) {
|
|
18
|
+
remove(header);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, ids = items?.map((i) => i.id) || [];
|
|
23
|
+
dataService.subscribe(onUpdate, ids);
|
|
24
|
+
return () => dataService.unsubscribe(onUpdate, ids);
|
|
25
|
+
}, [items]);
|
|
26
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Performable } from '../types/performable';
|
|
2
|
+
interface Data<TAvailableAction> {
|
|
3
|
+
[key: string]: Performable<TAvailableAction>[];
|
|
4
|
+
}
|
|
5
|
+
export interface Item {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Props<I extends Item> {
|
|
9
|
+
pathLocator: string;
|
|
10
|
+
selected: I[];
|
|
11
|
+
api: string;
|
|
12
|
+
}
|
|
13
|
+
declare const mapActions: <TAvailableAction>(ids: string[], data?: Data<TAvailableAction>) => {
|
|
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
|
+
}[];
|
|
28
|
+
actionsFetching: boolean | undefined;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
|
31
|
+
export declare const actions$: <TAvailableAction>({ api, pathLocator, ids, renderActions, deps, }: {
|
|
32
|
+
api: string;
|
|
33
|
+
pathLocator: string;
|
|
34
|
+
ids: string[];
|
|
35
|
+
renderActions: (opts: ReturnType<typeof mapActions>) => unknown;
|
|
36
|
+
deps?: unknown[];
|
|
37
|
+
}) => import("lit-html/directive.js").DirectiveResult<{
|
|
38
|
+
new (_partInfo: import("lit-html/directive.js").PartInfo): import("lit-html/directives/guard.js").GuardDirective<import("lit-html/directive.js").DirectiveResult<{
|
|
39
|
+
new (_partInfo: import("lit-html/directive.js").PartInfo): import("lit-html/directives/until.js").UntilDirective<Promise<unknown>>;
|
|
40
|
+
}>>;
|
|
41
|
+
}> | undefined;
|
|
42
|
+
//# sourceMappingURL=use-fetch-actions.d.ts.map
|
|
@@ -0,0 +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,sBAAsB,CAAC;AAEnD,UAAU,IAAI,CAAC,gBAAgB;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;CAC/C;AACD,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;AAQD,QAAA,MAAM,UAAU,GAAI,gBAAgB,EACnC,KAAK,MAAM,EAAE,EACb,OAAO,IAAI,CAAC,gBAAgB,CAAC;;;;;;;;CAQ7B,CAAC;yBAEc,CAAC,SAAS,IAAI,EAAE,gBAAgB,EAAE,sCAI/C,KAAK,CAAC,CAAC,CAAC,KAAG;IACb,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAChC,UAAU,EAAE;QACX,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;KACzC,EAAE,CAAC;IACJ,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC;CACrC;AAXD,wBA4CE;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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { debounce$ } from '@neovici/cosmoz-utils/promise';
|
|
2
|
+
import { useEffect, useMemo, useState } from '@pionjs/pion';
|
|
3
|
+
import { jsonPost } from '../util/fetch/fetch';
|
|
4
|
+
import { apiUrl } from '../util/fetch/url';
|
|
5
|
+
import { nothing } from 'lit-html';
|
|
6
|
+
import { guard } from 'lit-html/directives/guard.js';
|
|
7
|
+
import { until } from 'lit-html/directives/until.js';
|
|
8
|
+
import { when } from 'lit-html/directives/when.js';
|
|
9
|
+
const mapActions = (ids, data) => {
|
|
10
|
+
const acts = { ...data };
|
|
11
|
+
const rows = ids.map((id) => {
|
|
12
|
+
const ac = (acts[id] ??= []);
|
|
13
|
+
return { id, actions: ac };
|
|
14
|
+
});
|
|
15
|
+
return { actions: acts, actionRows: rows };
|
|
16
|
+
};
|
|
17
|
+
export default ({ pathLocator, selected, api: url, }) => {
|
|
18
|
+
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
|
+
const post$ = useMemo(() => debounce$(jsonPost, 320), []);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (ids.length < 1) {
|
|
22
|
+
setApi$({});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const ac = new AbortController();
|
|
26
|
+
setApi$(() => ({
|
|
27
|
+
api$: post$(apiUrl(url, { pathLocator }), ids, {
|
|
28
|
+
signal: ac.signal,
|
|
29
|
+
}).then((data) => setApi$((api) => ({ ...api, fetching: false, data })), (err) => setApi$({ error: err })),
|
|
30
|
+
fetching: true,
|
|
31
|
+
}));
|
|
32
|
+
return () => ac.abort();
|
|
33
|
+
}, [ids.length, pathLocator, ...ids]);
|
|
34
|
+
return { actions, actionRows, actionsFetching };
|
|
35
|
+
};
|
|
36
|
+
export const actions$ = ({ api, pathLocator, ids, renderActions, deps = [], }) => when(ids?.length > 0, () => guard([ids.length, ...ids, pathLocator, ...deps], () => until(jsonPost(apiUrl(api, {
|
|
37
|
+
pathLocator,
|
|
38
|
+
}), ids).then((data) => renderActions(mapActions(ids, data)), () => nothing))));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-key-nav.d.ts","sourceRoot":"","sources":["../../src/queue/use-key-nav.ts"],"names":[],"mappings":"AAKA,KAAK,GAAG,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;yBA8B1B,4BAIb;IACF,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,GAAG,CAAC;CACf;AARD,wBA0CE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useHost } from '@neovici/cosmoz-utils/hooks/use-host';
|
|
2
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
|
+
import { useEffect } from '@pionjs/pion';
|
|
4
|
+
import activeElement from '../util/dom/active-element';
|
|
5
|
+
const keys = (tab, listKeys, queueKeys) => [
|
|
6
|
+
...(['overview', 'split'].includes(tab) ? listKeys : []),
|
|
7
|
+
...(['queue', 'split'].includes(tab) ? queueKeys : []),
|
|
8
|
+
];
|
|
9
|
+
const overlaps = (host) => {
|
|
10
|
+
const root = host.shadowRoot, button = root.querySelector('.button-nav'), bounds = button.getBoundingClientRect();
|
|
11
|
+
return (root
|
|
12
|
+
.elementFromPoint(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2)
|
|
13
|
+
?.closest('.button-nav') !== button);
|
|
14
|
+
};
|
|
15
|
+
const permits = (host) => {
|
|
16
|
+
const active = activeElement();
|
|
17
|
+
return (!active?.isContentEditable &&
|
|
18
|
+
!active?.matches('input, textarea') &&
|
|
19
|
+
!overlaps(host));
|
|
20
|
+
};
|
|
21
|
+
export default ({ next, prev, activeTab, }) => {
|
|
22
|
+
const meta = useMeta({ next, prev, activeTab }), host = useHost();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const handler = (e) => {
|
|
25
|
+
if (e.defaultPrevented) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { key } = e, { next, prev, activeTab } = meta;
|
|
29
|
+
switch (true) {
|
|
30
|
+
case next &&
|
|
31
|
+
keys(activeTab, ['ArrowDown', 'Down'], ['ArrowRight', 'Right']).includes(key) &&
|
|
32
|
+
permits(host):
|
|
33
|
+
{
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
return next();
|
|
36
|
+
}
|
|
37
|
+
case prev &&
|
|
38
|
+
keys(activeTab, ['ArrowUp', 'Up'], ['ArrowLeft', 'Left']).includes(key) &&
|
|
39
|
+
permits(host):
|
|
40
|
+
{
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
return prev();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener('keydown', handler, true);
|
|
47
|
+
return () => document.removeEventListener('keydown', handler, true);
|
|
48
|
+
}, []);
|
|
49
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Rec } from '@neovici/cosmoz-utils/object';
|
|
2
|
+
export interface ListEventHandlersMap {
|
|
3
|
+
'list-item-update': CustomEvent<{
|
|
4
|
+
id: string;
|
|
5
|
+
item: unknown;
|
|
6
|
+
update: (i: unknown) => void;
|
|
7
|
+
}>;
|
|
8
|
+
'list-item-remove': CustomEvent<{
|
|
9
|
+
id: string;
|
|
10
|
+
item: unknown;
|
|
11
|
+
remove: () => void;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
interface Item extends Rec {
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
interface Omnitable<T extends Rec> extends HTMLElement {
|
|
18
|
+
data?: T[];
|
|
19
|
+
replaceItemAtIndex: (index: number, update: T) => void;
|
|
20
|
+
removeItem: (i: T) => void;
|
|
21
|
+
}
|
|
22
|
+
interface List$<I, P> {
|
|
23
|
+
(params: P & {
|
|
24
|
+
objectIds: string[];
|
|
25
|
+
}): PromiseLike<I[] | {
|
|
26
|
+
items: I[];
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
interface Base<I extends Item, P extends Rec> {
|
|
30
|
+
omnitable: Omnitable<I>;
|
|
31
|
+
params: P;
|
|
32
|
+
list$: List$<I, P>;
|
|
33
|
+
idMapper?: <T extends I>(id: string, item: T) => string;
|
|
34
|
+
idProperty?: string;
|
|
35
|
+
}
|
|
36
|
+
interface Opts<I extends Item, P extends Rec> extends Omit<Base<I, P>, 'omnitable'> {
|
|
37
|
+
entity: string;
|
|
38
|
+
omnitable?: Omnitable<I>;
|
|
39
|
+
}
|
|
40
|
+
export declare const useListSSE: <I extends Item, P extends Rec>({ entity, ...thru }: Opts<I, P>) => void;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=use-list-sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-list-sse.d.ts","sourceRoot":"","sources":["../../src/queue/use-list-sse.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAInD,MAAM,WAAW,oBAAoB;IACpC,kBAAkB,EAAE,WAAW,CAAC;QAC/B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,OAAO,CAAC;QACd,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;KAC7B,CAAC,CAAC;IACH,kBAAkB,EAAE,WAAW,CAAC;QAC/B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,OAAO,CAAC;QACd,MAAM,EAAE,MAAM,IAAI,CAAC;KACnB,CAAC,CAAC;CACH;AAED,UAAU,IAAK,SAAQ,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;CACX;AAED,UAAU,SAAS,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,WAAW;IACrD,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IACX,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IACvD,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;CAC3B;AAED,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;IACnB,CAAC,MAAM,EAAE,CAAC,GAAG;QAAE,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,WAAW,CAAC,CAAC,EAAE,GAAG;QAAE,KAAK,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;CACzE;AA4DD,UAAU,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,GAAG;IAC3C,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AA2BD,UAAU,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,GAAG,CAC3C,SAAQ,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CACzB;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,GAAG,EAAE,qBAGvD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAsCZ,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useMemo, useEffect } from '@pionjs/pion';
|
|
2
|
+
import { useHost } from '@neovici/cosmoz-utils/hooks/use-host';
|
|
3
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
4
|
+
import { debounce$ } from '@neovici/cosmoz-utils/promise';
|
|
5
|
+
import { get } from '../util/path';
|
|
6
|
+
const process$ = ({ updates, objectIds, omnitable, host, idProperty, }) => {
|
|
7
|
+
for (const id of objectIds) {
|
|
8
|
+
const update = updates.find((i) => get(i, idProperty) === id), index = omnitable.data?.findIndex((i) => get(i, idProperty) === id) ?? -1;
|
|
9
|
+
if (index < 0) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const item = omnitable.data[index];
|
|
13
|
+
if (update) {
|
|
14
|
+
omnitable.replaceItemAtIndex(index, {
|
|
15
|
+
...item,
|
|
16
|
+
...update,
|
|
17
|
+
});
|
|
18
|
+
host.dispatchEvent(new CustomEvent('list-item-update', {
|
|
19
|
+
bubbles: true,
|
|
20
|
+
composed: true,
|
|
21
|
+
detail: {
|
|
22
|
+
id,
|
|
23
|
+
item,
|
|
24
|
+
update,
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const remove = () => omnitable.removeItem(item);
|
|
30
|
+
if (host.dispatchEvent(new CustomEvent('list-item-remove', {
|
|
31
|
+
bubbles: true,
|
|
32
|
+
composed: true,
|
|
33
|
+
cancelable: true,
|
|
34
|
+
detail: {
|
|
35
|
+
id,
|
|
36
|
+
item,
|
|
37
|
+
remove,
|
|
38
|
+
},
|
|
39
|
+
}))) {
|
|
40
|
+
remove();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const check$$ = async (opts) => {
|
|
46
|
+
const { ids, params, omnitable, list$, idMapper, idProperty = 'id' } = opts, objectIds = [...ids].flatMap((id) => {
|
|
47
|
+
if (idMapper) {
|
|
48
|
+
return (omnitable?.data?.flatMap((i) => {
|
|
49
|
+
const mapped = idMapper(id, i);
|
|
50
|
+
return mapped ? [mapped] : [];
|
|
51
|
+
}) ?? []);
|
|
52
|
+
}
|
|
53
|
+
if (omnitable?.data?.find((i) => get(i, idProperty) === id))
|
|
54
|
+
return [id];
|
|
55
|
+
return [];
|
|
56
|
+
});
|
|
57
|
+
ids.clear();
|
|
58
|
+
const res = await list$({ ...params, objectIds });
|
|
59
|
+
const updates = Array.isArray(res) ? res : res.items ?? [];
|
|
60
|
+
return process$({ ...opts, idProperty, objectIds, updates });
|
|
61
|
+
};
|
|
62
|
+
export const useListSSE = ({ entity, ...thru }) => {
|
|
63
|
+
const host = useHost(), ids = useMemo(() => new Set(), []), meta = useMeta(thru), check$ = useMemo(() => debounce$(() => check$$({
|
|
64
|
+
...meta,
|
|
65
|
+
host,
|
|
66
|
+
ids,
|
|
67
|
+
omnitable: meta.omnitable ??
|
|
68
|
+
host.shadowRoot.querySelector('cosmoz-omnitable'),
|
|
69
|
+
}), 600), []);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
const ev = `cosmoz-${entity}-updated`, evc = `cosmoz-${entity}-check`, onUpdate = (e) => {
|
|
72
|
+
ids.add(e.detail.id);
|
|
73
|
+
check$();
|
|
74
|
+
};
|
|
75
|
+
window.addEventListener(ev, onUpdate);
|
|
76
|
+
host.addEventListener(evc, onUpdate);
|
|
77
|
+
return () => {
|
|
78
|
+
window.removeEventListener(ev, onUpdate);
|
|
79
|
+
host.removeEventListener(evc, onUpdate);
|
|
80
|
+
};
|
|
81
|
+
}, [entity, check$]);
|
|
82
|
+
};
|