@contember/bindx-dataview 0.1.23 → 0.1.25
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/select/MultiSelect.d.ts.map +1 -1
- package/dist/select/Select.d.ts.map +1 -1
- package/dist/select/SelectEachValue.d.ts +2 -2
- package/dist/select/SelectEachValue.d.ts.map +1 -1
- package/dist/select/selectContext.d.ts +8 -8
- package/dist/select/selectContext.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/select/MultiSelect.tsx +4 -4
- package/src/select/Select.tsx +5 -5
- package/src/select/SelectEachValue.tsx +2 -2
- package/src/select/selectContext.ts +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSelect.d.ts","sourceRoot":"","sources":["../../src/select/MultiSelect.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAA;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MultiSelect.d.ts","sourceRoot":"","sources":["../../src/select/MultiSelect.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAA;AAC5D,OAAO,KAAK,EAAa,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAExE,OAAO,EAMN,KAAK,YAAY,EAEjB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACrD,+CAA+C;IAC/C,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IAC5B,6CAA6C;IAC7C,OAAO,EAAE,SAAS,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACnB;AAED,wBAAgB,WAAW,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,GACV,EAAE,gBAAgB,GAAG,SAAS,CA8C9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/select/Select.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAA;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/select/Select.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAA;AAC5D,OAAO,KAAK,EAAa,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGvE,OAAO,EAMN,KAAK,YAAY,EAEjB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,WAAW,WAAY,SAAQ,YAAY;IAChD,8CAA8C;IAC9C,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC3B,6CAA6C;IAC7C,OAAO,EAAE,SAAS,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACnB;AAED,wBAAgB,MAAM,CAAC,EACtB,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,GACV,EAAE,WAAW,GAAG,SAAS,CA6CzB"}
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
import { type ReactNode } from 'react';
|
|
15
|
-
import type {
|
|
15
|
+
import type { EntityRef } from '@contember/bindx';
|
|
16
16
|
export interface SelectEachValueProps {
|
|
17
|
-
children: (entity:
|
|
17
|
+
children: (entity: EntityRef<object>, index: number) => ReactNode;
|
|
18
18
|
}
|
|
19
19
|
export declare function SelectEachValue({ children }: SelectEachValueProps): ReactNode;
|
|
20
20
|
//# sourceMappingURL=SelectEachValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectEachValue.d.ts","sourceRoot":"","sources":["../../src/select/SelectEachValue.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SelectEachValue.d.ts","sourceRoot":"","sources":["../../src/select/SelectEachValue.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;CACjE;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GAAG,SAAS,CAW7E"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Select context — provides selection state and handlers to descendant components.
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { EntityRef, EntityDef } from '@contember/bindx';
|
|
5
5
|
export type SelectAction = 'select' | 'unselect' | 'toggle';
|
|
6
|
-
export type SelectHandler = (entity:
|
|
6
|
+
export type SelectHandler = (entity: EntityRef<object>, action?: SelectAction) => void;
|
|
7
7
|
export interface SelectEvents {
|
|
8
|
-
onSelect?: (entity:
|
|
9
|
-
onUnselect?: (entity:
|
|
8
|
+
onSelect?: (entity: EntityRef<object>) => void;
|
|
9
|
+
onUnselect?: (entity: EntityRef<object>) => void;
|
|
10
10
|
}
|
|
11
|
-
declare const SelectCurrentEntitiesContext: import("react").Context<readonly
|
|
12
|
-
declare const SelectIsSelectedContext: import("react").Context<((entity:
|
|
11
|
+
declare const SelectCurrentEntitiesContext: import("react").Context<readonly EntityRef<object>[] | null>;
|
|
12
|
+
declare const SelectIsSelectedContext: import("react").Context<((entity: EntityRef<object>) => boolean) | null>;
|
|
13
13
|
declare const SelectHandleSelectContext: import("react").Context<SelectHandler | null>;
|
|
14
14
|
declare const SelectOptionsContext: import("react").Context<EntityDef<Record<string, object>> | null>;
|
|
15
|
-
export declare function useSelectCurrentEntities(): readonly
|
|
16
|
-
export declare function useSelectIsSelected(): (entity:
|
|
15
|
+
export declare function useSelectCurrentEntities(): readonly EntityRef<object>[];
|
|
16
|
+
export declare function useSelectIsSelected(): (entity: EntityRef<object>) => boolean;
|
|
17
17
|
export declare function useSelectHandleSelect(): SelectHandler;
|
|
18
18
|
export declare function useSelectOptions(): EntityDef;
|
|
19
19
|
export { SelectCurrentEntitiesContext, SelectIsSelectedContext, SelectHandleSelectContext, SelectOptionsContext, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectContext.d.ts","sourceRoot":"","sources":["../../src/select/selectContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"selectContext.d.ts","sourceRoot":"","sources":["../../src/select/selectContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAM5D,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAA;AAE3D,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,KAAK,IAAI,CAAA;AAEtF,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IAC9C,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;CAChD;AAMD,QAAA,MAAM,4BAA4B,8DAA2D,CAAA;AAG7F,QAAA,MAAM,uBAAuB,oCAA2B,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,SAAe,CAAA;AAGpG,QAAA,MAAM,yBAAyB,+CAA4C,CAAA;AAG3E,QAAA,MAAM,oBAAoB,mEAAwC,CAAA;AAOlE,wBAAgB,wBAAwB,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,CAMvE;AAED,wBAAgB,mBAAmB,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAM5E;AAED,wBAAgB,qBAAqB,IAAI,aAAa,CAMrD;AAED,wBAAgB,gBAAgB,IAAI,SAAS,CAM5C;AAMD,OAAO,EACN,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,GACpB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/bindx-dataview",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "Headless DataGrid and DataView components for bindx",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"react": ">=18.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@contember/bindx": "0.1.
|
|
19
|
-
"@contember/bindx-react": "0.1.
|
|
18
|
+
"@contember/bindx": "0.1.25",
|
|
19
|
+
"@contember/bindx-react": "0.1.25",
|
|
20
20
|
"@radix-ui/primitive": "^1.1.3",
|
|
21
21
|
"@radix-ui/react-slot": "^1.2.4"
|
|
22
22
|
},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type ReactNode, useCallback, useMemo } from 'react'
|
|
18
|
-
import type {
|
|
18
|
+
import type { EntityRef, EntityDef, HasManyRef } from '@contember/bindx'
|
|
19
19
|
import { useHasMany } from '@contember/bindx-react'
|
|
20
20
|
import {
|
|
21
21
|
SelectCurrentEntitiesContext,
|
|
@@ -50,12 +50,12 @@ export function MultiSelect({
|
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
const entitiesArr = useMemo(
|
|
53
|
-
(): readonly
|
|
53
|
+
(): readonly EntityRef<object>[] => items as EntityRef<object>[],
|
|
54
54
|
[items],
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
const handleSelect = useCallback<SelectHandler>(
|
|
58
|
-
(entity:
|
|
58
|
+
(entity: EntityRef<object>, action: SelectAction = 'toggle') => {
|
|
59
59
|
const isCurrentlySelected = selectedIds.has(entity.id)
|
|
60
60
|
if (action === 'toggle') {
|
|
61
61
|
action = isCurrentlySelected ? 'unselect' : 'select'
|
|
@@ -72,7 +72,7 @@ export function MultiSelect({
|
|
|
72
72
|
)
|
|
73
73
|
|
|
74
74
|
const isSelected = useCallback(
|
|
75
|
-
(entity:
|
|
75
|
+
(entity: EntityRef<object>): boolean => selectedIds.has(entity.id),
|
|
76
76
|
[selectedIds],
|
|
77
77
|
)
|
|
78
78
|
|
package/src/select/Select.tsx
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type ReactNode, useCallback, useMemo } from 'react'
|
|
18
|
-
import type {
|
|
18
|
+
import type { EntityRef, EntityDef, HasOneRef } from '@contember/bindx'
|
|
19
19
|
import { useHasOne } from '@contember/bindx-react'
|
|
20
20
|
import { isPlaceholderId } from '@contember/bindx'
|
|
21
21
|
import {
|
|
@@ -50,13 +50,13 @@ export function Select({
|
|
|
50
50
|
const currentId = isConnected ? entityId : null
|
|
51
51
|
|
|
52
52
|
const entitiesArr = useMemo(
|
|
53
|
-
(): readonly
|
|
54
|
-
isConnected ? [entity as
|
|
53
|
+
(): readonly EntityRef<object>[] =>
|
|
54
|
+
isConnected ? [entity as EntityRef<object>] : [],
|
|
55
55
|
[isConnected, entity],
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
const handleSelect = useCallback<SelectHandler>(
|
|
59
|
-
(selected:
|
|
59
|
+
(selected: EntityRef<object>, action: SelectAction = 'toggle') => {
|
|
60
60
|
if (action === 'toggle') {
|
|
61
61
|
action = selected.id === currentId ? 'unselect' : 'select'
|
|
62
62
|
}
|
|
@@ -72,7 +72,7 @@ export function Select({
|
|
|
72
72
|
)
|
|
73
73
|
|
|
74
74
|
const isSelected = useCallback(
|
|
75
|
-
(entity:
|
|
75
|
+
(entity: EntityRef<object>): boolean => entity.id === currentId,
|
|
76
76
|
[currentId],
|
|
77
77
|
)
|
|
78
78
|
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import React, { type ReactNode } from 'react'
|
|
16
|
-
import type {
|
|
16
|
+
import type { EntityRef } from '@contember/bindx'
|
|
17
17
|
import { useSelectCurrentEntities } from './selectContext.js'
|
|
18
18
|
|
|
19
19
|
export interface SelectEachValueProps {
|
|
20
|
-
children: (entity:
|
|
20
|
+
children: (entity: EntityRef<object>, index: number) => ReactNode
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function SelectEachValue({ children }: SelectEachValueProps): ReactNode {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { createContext, useContext } from 'react'
|
|
6
|
-
import type {
|
|
6
|
+
import type { EntityRef, EntityDef } from '@contember/bindx'
|
|
7
7
|
|
|
8
8
|
// ============================================================================
|
|
9
9
|
// Types
|
|
@@ -11,21 +11,21 @@ import type { EntityAccessor, EntityDef } from '@contember/bindx'
|
|
|
11
11
|
|
|
12
12
|
export type SelectAction = 'select' | 'unselect' | 'toggle'
|
|
13
13
|
|
|
14
|
-
export type SelectHandler = (entity:
|
|
14
|
+
export type SelectHandler = (entity: EntityRef<object>, action?: SelectAction) => void
|
|
15
15
|
|
|
16
16
|
export interface SelectEvents {
|
|
17
|
-
onSelect?: (entity:
|
|
18
|
-
onUnselect?: (entity:
|
|
17
|
+
onSelect?: (entity: EntityRef<object>) => void
|
|
18
|
+
onUnselect?: (entity: EntityRef<object>) => void
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// ============================================================================
|
|
22
22
|
// Contexts
|
|
23
23
|
// ============================================================================
|
|
24
24
|
|
|
25
|
-
const SelectCurrentEntitiesContext = createContext<readonly
|
|
25
|
+
const SelectCurrentEntitiesContext = createContext<readonly EntityRef<object>[] | null>(null)
|
|
26
26
|
SelectCurrentEntitiesContext.displayName = 'SelectCurrentEntitiesContext'
|
|
27
27
|
|
|
28
|
-
const SelectIsSelectedContext = createContext<((entity:
|
|
28
|
+
const SelectIsSelectedContext = createContext<((entity: EntityRef<object>) => boolean) | null>(null)
|
|
29
29
|
SelectIsSelectedContext.displayName = 'SelectIsSelectedContext'
|
|
30
30
|
|
|
31
31
|
const SelectHandleSelectContext = createContext<SelectHandler | null>(null)
|
|
@@ -38,7 +38,7 @@ SelectOptionsContext.displayName = 'SelectOptionsContext'
|
|
|
38
38
|
// Hooks
|
|
39
39
|
// ============================================================================
|
|
40
40
|
|
|
41
|
-
export function useSelectCurrentEntities(): readonly
|
|
41
|
+
export function useSelectCurrentEntities(): readonly EntityRef<object>[] {
|
|
42
42
|
const ctx = useContext(SelectCurrentEntitiesContext)
|
|
43
43
|
if (ctx === null) {
|
|
44
44
|
throw new Error('useSelectCurrentEntities must be used within a Select or MultiSelect')
|
|
@@ -46,7 +46,7 @@ export function useSelectCurrentEntities(): readonly EntityAccessor<object>[] {
|
|
|
46
46
|
return ctx
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function useSelectIsSelected(): (entity:
|
|
49
|
+
export function useSelectIsSelected(): (entity: EntityRef<object>) => boolean {
|
|
50
50
|
const ctx = useContext(SelectIsSelectedContext)
|
|
51
51
|
if (ctx === null) {
|
|
52
52
|
throw new Error('useSelectIsSelected must be used within a Select or MultiSelect')
|