@contember/react-select 2.1.0-alpha.9 → 2.1.0-beta.1
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/CLAUDE.md +20 -0
- package/dist/development/index.cjs +2 -2
- package/dist/development/index.js +1 -1
- package/dist/development/src/components/MultiSelect.cjs.map +1 -1
- package/dist/development/src/components/MultiSelect.js.map +1 -1
- package/dist/development/src/components/Select.cjs.map +1 -1
- package/dist/development/src/components/Select.js.map +1 -1
- package/dist/development/src/components/SelectDataView.cjs.map +1 -1
- package/dist/development/src/components/SelectDataView.js.map +1 -1
- package/dist/development/src/components/SelectEachItem.cjs +1 -1
- package/dist/development/src/components/SelectEachItem.cjs.map +1 -1
- package/dist/development/src/components/SelectEachItem.js +1 -1
- package/dist/development/src/components/SelectEachItem.js.map +1 -1
- package/dist/development/src/components/SelectItemTrigger.cjs.map +1 -1
- package/dist/development/src/components/SelectItemTrigger.js.map +1 -1
- package/dist/development/src/components/SelectNewItem.cjs +29 -14
- package/dist/development/src/components/SelectNewItem.cjs.map +1 -1
- package/dist/development/src/components/SelectNewItem.js +29 -14
- package/dist/development/src/components/SelectNewItem.js.map +1 -1
- package/dist/development/src/components/SelectOption.cjs.map +1 -1
- package/dist/development/src/components/SelectOption.js.map +1 -1
- package/dist/development/src/components/SelectPlaceholder.cjs.map +1 -1
- package/dist/development/src/components/SelectPlaceholder.js.map +1 -1
- package/dist/development/src/components/SortableMultiSelect.cjs +70 -67
- package/dist/development/src/components/SortableMultiSelect.cjs.map +1 -1
- package/dist/development/src/components/SortableMultiSelect.js +70 -67
- package/dist/development/src/components/SortableMultiSelect.js.map +1 -1
- package/dist/development/src/contexts.cjs.map +1 -1
- package/dist/development/src/contexts.js.map +1 -1
- package/dist/production/index.cjs +2 -2
- package/dist/production/index.js +1 -1
- package/dist/production/src/components/MultiSelect.cjs.map +1 -1
- package/dist/production/src/components/MultiSelect.js.map +1 -1
- package/dist/production/src/components/Select.cjs.map +1 -1
- package/dist/production/src/components/Select.js.map +1 -1
- package/dist/production/src/components/SelectDataView.cjs.map +1 -1
- package/dist/production/src/components/SelectDataView.js.map +1 -1
- package/dist/production/src/components/SelectEachItem.cjs.map +1 -1
- package/dist/production/src/components/SelectEachItem.js.map +1 -1
- package/dist/production/src/components/SelectItemTrigger.cjs.map +1 -1
- package/dist/production/src/components/SelectItemTrigger.js.map +1 -1
- package/dist/production/src/components/SelectNewItem.cjs +14 -3
- package/dist/production/src/components/SelectNewItem.cjs.map +1 -1
- package/dist/production/src/components/SelectNewItem.js +14 -3
- package/dist/production/src/components/SelectNewItem.js.map +1 -1
- package/dist/production/src/components/SelectOption.cjs.map +1 -1
- package/dist/production/src/components/SelectOption.js.map +1 -1
- package/dist/production/src/components/SelectPlaceholder.cjs.map +1 -1
- package/dist/production/src/components/SelectPlaceholder.js.map +1 -1
- package/dist/production/src/components/SortableMultiSelect.cjs +42 -39
- package/dist/production/src/components/SortableMultiSelect.cjs.map +1 -1
- package/dist/production/src/components/SortableMultiSelect.js +42 -39
- package/dist/production/src/components/SortableMultiSelect.js.map +1 -1
- package/dist/production/src/contexts.cjs.map +1 -1
- package/dist/production/src/contexts.js.map +1 -1
- package/dist/types/components/SelectDataView.d.ts.map +1 -1
- package/dist/types/components/SelectEachItem.d.ts.map +1 -1
- package/dist/types/components/SelectNewItem.d.ts.map +1 -1
- package/dist/types/components/SortableMultiSelect.d.ts.map +1 -1
- package/dist/types/contexts.d.ts +6 -6
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/components/MultiSelect.tsx +1 -2
- package/src/components/Select.tsx +0 -1
- package/src/components/SelectDataView.tsx +1 -1
- package/src/components/SelectEachItem.tsx +0 -1
- package/src/components/SelectItemTrigger.tsx +1 -1
- package/src/components/SelectNewItem.tsx +27 -10
- package/src/components/SortableMultiSelect.tsx +64 -60
- package/src/contexts.ts +0 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/react-select",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.1.0-
|
|
4
|
+
"version": "2.1.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -30,23 +30,23 @@
|
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/contember/
|
|
33
|
+
"url": "git+https://github.com/contember/contember.git",
|
|
34
34
|
"directory": "packages/react-select"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@contember/react-binding": "2.1.0-
|
|
38
|
-
"@contember/react-dataview": "2.1.0-
|
|
39
|
-
"@contember/react-repeater": "2.1.0-
|
|
40
|
-
"@contember/react-utils": "2.1.0-
|
|
41
|
-
"@contember/utilities": "2.1.0-
|
|
42
|
-
"@radix-ui/react-slot": "^1.
|
|
37
|
+
"@contember/react-binding": "2.1.0-beta.1",
|
|
38
|
+
"@contember/react-dataview": "2.1.0-beta.1",
|
|
39
|
+
"@contember/react-repeater": "2.1.0-beta.1",
|
|
40
|
+
"@contember/react-utils": "2.1.0-beta.1",
|
|
41
|
+
"@contember/utilities": "2.1.0-beta.1",
|
|
42
|
+
"@radix-ui/react-slot": "^1.2.4"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"react": "^
|
|
46
|
-
"react-dom": "^
|
|
45
|
+
"react": "^19.2.4",
|
|
46
|
+
"react-dom": "^19.2.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"react": "^
|
|
50
|
-
"react-dom": "^
|
|
49
|
+
"react": "^19.2.4",
|
|
50
|
+
"react-dom": "^19.2.4"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -16,7 +16,7 @@ export const MultiSelect = Component(({ field, children, options, onSelect, onUn
|
|
|
16
16
|
const entities = useEntityList({ field })
|
|
17
17
|
options ??= entities.name
|
|
18
18
|
const entitiesArr = useMemo(() => Array.from(entities), [entities])
|
|
19
|
-
const selectedEntities = useMemo(() => Array.from(entities).map(it => it.id), [entities])
|
|
19
|
+
const selectedEntities = useMemo(() => Array.from(entities).map((it: EntityAccessor) => it.id), [entities])
|
|
20
20
|
|
|
21
21
|
const handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {
|
|
22
22
|
const isSelected = selectedEntities.includes(entity.id)
|
|
@@ -53,4 +53,3 @@ export const MultiSelect = Component(({ field, children, options, onSelect, onUn
|
|
|
53
53
|
</HasMany>
|
|
54
54
|
)
|
|
55
55
|
})
|
|
56
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode, useMemo } from 'react'
|
|
2
2
|
import { useSelectHandleSelect, useSelectOptions } from '../contexts'
|
|
3
|
-
import {
|
|
3
|
+
import { DataView, DataViewFilterHandlerRegistry, DataViewProps } from '@contember/react-dataview'
|
|
4
4
|
|
|
5
5
|
export type SelectDataViewProps =
|
|
6
6
|
& Omit<DataViewProps, 'entities'>
|
|
@@ -2,7 +2,6 @@ import React, { ReactNode } from 'react'
|
|
|
2
2
|
import { useSelectCurrentEntities } from '../contexts'
|
|
3
3
|
import { Entity } from '@contember/react-binding'
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export const SelectEachValue = ({ children }: { children: ReactNode }) => {
|
|
7
6
|
const entities = useSelectCurrentEntities()
|
|
8
7
|
return entities.map(entity => (
|
|
@@ -17,5 +17,5 @@ export const SelectItemTrigger = forwardRef<HTMLElement, SelectItemTriggerProps>
|
|
|
17
17
|
handleSelect?.(entity, action)
|
|
18
18
|
onClickProp?.(e)
|
|
19
19
|
}, [action, entity, handleSelect, onClickProp])
|
|
20
|
-
return <Slot {...props} onClick={onClick}
|
|
20
|
+
return <Slot {...props} onClick={onClick} ref={ref} />
|
|
21
21
|
})
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Entity,
|
|
3
|
+
EntityAccessor,
|
|
4
|
+
EntitySubTree,
|
|
5
|
+
QueryLanguage,
|
|
6
|
+
TreeRootId,
|
|
7
|
+
TreeRootIdProvider,
|
|
8
|
+
useEnvironment,
|
|
9
|
+
useExtendTree,
|
|
10
|
+
useGetEntitySubTree,
|
|
11
|
+
} from '@contember/react-binding'
|
|
2
12
|
import * as React from 'react'
|
|
3
13
|
import { ReactNode, useEffect, useMemo, useState } from 'react'
|
|
4
14
|
import { useSelectOptions } from '../contexts'
|
|
@@ -6,21 +16,28 @@ import { useSelectOptions } from '../contexts'
|
|
|
6
16
|
export const SelectNewItem = ({ children }: { children: ReactNode }) => {
|
|
7
17
|
const options = useSelectOptions()
|
|
8
18
|
const env = useEnvironment()
|
|
9
|
-
const { entityName } = useMemo((
|
|
19
|
+
const { entityName } = useMemo(() => QueryLanguage.desugarQualifiedEntityList({ entities: options }, env), [env, options])
|
|
10
20
|
|
|
11
21
|
const [state, setState] = useState<{ entity: EntityAccessor; treeRootId: TreeRootId } | null>(null)
|
|
12
22
|
const extendTree = useExtendTree()
|
|
13
23
|
const getSubTree = useGetEntitySubTree()
|
|
14
24
|
|
|
15
25
|
useEffect(() => {
|
|
16
|
-
(async () => {
|
|
17
|
-
const treeRootId = await extendTree(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
;(async () => {
|
|
27
|
+
const treeRootId = await extendTree(
|
|
28
|
+
<>
|
|
29
|
+
<EntitySubTree
|
|
30
|
+
entity={{
|
|
31
|
+
entityName,
|
|
32
|
+
}}
|
|
33
|
+
expectedMutation={'none'}
|
|
34
|
+
isUnpersisted
|
|
35
|
+
isCreating
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</EntitySubTree>
|
|
39
|
+
</>,
|
|
40
|
+
)
|
|
24
41
|
if (!treeRootId) {
|
|
25
42
|
return
|
|
26
43
|
}
|
|
@@ -3,9 +3,12 @@ import { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext,
|
|
|
3
3
|
import {
|
|
4
4
|
Component,
|
|
5
5
|
EntityAccessor,
|
|
6
|
+
EntityListSubTreeMarker,
|
|
7
|
+
EntitySubTreeMarker,
|
|
6
8
|
FieldMarker,
|
|
9
|
+
HasManyRelationMarker,
|
|
7
10
|
HasOne,
|
|
8
|
-
|
|
11
|
+
HasOneRelationMarker,
|
|
9
12
|
PlaceholderGenerator,
|
|
10
13
|
QueryLanguage,
|
|
11
14
|
SugaredQualifiedEntityList,
|
|
@@ -28,68 +31,69 @@ export type SortableMultiSelectProps =
|
|
|
28
31
|
}
|
|
29
32
|
& SelectEvents
|
|
30
33
|
|
|
31
|
-
export const SortableMultiSelect = Component(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
export const SortableMultiSelect = Component(
|
|
35
|
+
({ field, children, sortableBy, connectAt, options, onSelect, onUnselect }: SortableMultiSelectProps) => {
|
|
36
|
+
const list = useEntityList({ field })
|
|
37
|
+
const entitiesArr = useMemo(() => Array.from(list), [list])
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const optionsMarker = useMemo(() => {
|
|
40
|
+
const desugared = QueryLanguage.desugarRelativeSingleEntity({ field: connectAt }, list.environment)
|
|
41
|
+
let marker: HasOneRelationMarker | HasManyRelationMarker | EntitySubTreeMarker | EntityListSubTreeMarker = list.getMarker()
|
|
42
|
+
for (let relation of desugared.hasOneRelationPath) {
|
|
43
|
+
const placeholder = PlaceholderGenerator.getHasOneRelationPlaceholder(relation)
|
|
44
|
+
const relationMarker = marker.fields.markers.get(placeholder)
|
|
45
|
+
if (!relationMarker || relationMarker instanceof FieldMarker) {
|
|
46
|
+
throw new Error('Invalid marker')
|
|
47
|
+
}
|
|
48
|
+
marker = relationMarker
|
|
43
49
|
}
|
|
44
|
-
marker
|
|
45
|
-
}
|
|
46
|
-
return marker
|
|
47
|
-
}, [connectAt, list])
|
|
50
|
+
return marker
|
|
51
|
+
}, [connectAt, list])
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
options ??= optionsMarker.environment.getSubTreeNode().entity.name
|
|
50
54
|
|
|
55
|
+
const selectedEntities = useMemo(() => Array.from(list).map((it: EntityAccessor) => it.getEntity({ field: connectAt }).id), [connectAt, list])
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
action
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return selectedEntities.includes(entity.id)
|
|
71
|
-
}, [selectedEntities])
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0} orderBy={false}>
|
|
75
|
-
<SelectCurrentEntitiesContext.Provider value={entitiesArr}>
|
|
76
|
-
<SelectIsSelectedContext.Provider value={isSelected}>
|
|
77
|
-
<SelectHandleSelectContext.Provider value={handler}>
|
|
78
|
-
<SelectOptionsContext.Provider value={options}>
|
|
79
|
-
{children}
|
|
80
|
-
</SelectOptionsContext.Provider>
|
|
81
|
-
</SelectHandleSelectContext.Provider>
|
|
82
|
-
</SelectIsSelectedContext.Provider>
|
|
83
|
-
</SelectCurrentEntitiesContext.Provider>
|
|
84
|
-
</Repeater>
|
|
85
|
-
)
|
|
86
|
-
}, ({ children, field, sortableBy, connectAt }) => {
|
|
87
|
-
return (
|
|
88
|
-
<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0} orderBy={false}>
|
|
89
|
-
<HasOne field={connectAt} expectedMutation="connectOrDisconnect">
|
|
90
|
-
{children}
|
|
91
|
-
</HasOne>
|
|
92
|
-
</Repeater>
|
|
93
|
-
)
|
|
94
|
-
})
|
|
57
|
+
const handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {
|
|
58
|
+
const isSelected = selectedEntities.includes(entity.id)
|
|
59
|
+
if (action === 'toggle') {
|
|
60
|
+
action = isSelected ? 'unselect' : 'select'
|
|
61
|
+
}
|
|
62
|
+
if (action === 'unselect' && isSelected) {
|
|
63
|
+
Array.from(list).find((it: EntityAccessor) => it.getEntity({ field: connectAt }).id === entity.id)?.deleteEntity()
|
|
64
|
+
onUnselect?.(entity)
|
|
65
|
+
} else if (action === 'select' && !isSelected) {
|
|
66
|
+
list.createNewEntity(getEntity => {
|
|
67
|
+
getEntity().connectEntityAtField({ field: connectAt }, entity)
|
|
68
|
+
onSelect?.(entity)
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
const isSelected = useCallback((entity: EntityAccessor) => {
|
|
73
|
+
return selectedEntities.includes(entity.id)
|
|
74
|
+
}, [selectedEntities])
|
|
95
75
|
|
|
76
|
+
return (
|
|
77
|
+
<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>
|
|
78
|
+
<SelectCurrentEntitiesContext.Provider value={entitiesArr}>
|
|
79
|
+
<SelectIsSelectedContext.Provider value={isSelected}>
|
|
80
|
+
<SelectHandleSelectContext.Provider value={handler}>
|
|
81
|
+
<SelectOptionsContext.Provider value={options}>
|
|
82
|
+
{children}
|
|
83
|
+
</SelectOptionsContext.Provider>
|
|
84
|
+
</SelectHandleSelectContext.Provider>
|
|
85
|
+
</SelectIsSelectedContext.Provider>
|
|
86
|
+
</SelectCurrentEntitiesContext.Provider>
|
|
87
|
+
</Repeater>
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
({ children, field, sortableBy, connectAt }) => {
|
|
91
|
+
return (
|
|
92
|
+
<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>
|
|
93
|
+
<HasOne field={connectAt} expectedMutation="connectOrDisconnect">
|
|
94
|
+
{children}
|
|
95
|
+
</HasOne>
|
|
96
|
+
</Repeater>
|
|
97
|
+
)
|
|
98
|
+
},
|
|
99
|
+
)
|
package/src/contexts.ts
CHANGED
|
@@ -7,8 +7,6 @@ const _SelectCurrentEntitiesContext = createRequiredContext<EntityAccessor[]>('S
|
|
|
7
7
|
export const SelectCurrentEntitiesContext = _SelectCurrentEntitiesContext[0]
|
|
8
8
|
export const useSelectCurrentEntities = _SelectCurrentEntitiesContext[1]
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
10
|
const _SelectIsSelectedContext = createRequiredContext<(entity: EntityAccessor) => boolean>('SelectIsSelectedContext')
|
|
13
11
|
/** @internal */
|
|
14
12
|
export const SelectIsSelectedContext = _SelectIsSelectedContext[0]
|