@contember/bindx-uploader 0.1.14 → 0.1.16
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/components/MultiUploader.d.ts.map +1 -1
- package/dist/internal/hooks/useFillEntity.d.ts +3 -3
- package/dist/internal/hooks/useFillEntity.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/components/MultiUploader.tsx +4 -3
- package/src/extractors/getAudioFileDataExtractor.ts +1 -1
- package/src/extractors/getFileUrlDataExtractor.ts +1 -1
- package/src/extractors/getGenericFileMetadataExtractor.ts +1 -1
- package/src/extractors/getImageFileDataExtractor.ts +1 -1
- package/src/extractors/getVideoFileDataExtractor.ts +1 -1
- package/src/internal/hooks/useFillEntity.ts +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiUploader.d.ts","sourceRoot":"","sources":["../../src/components/MultiUploader.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,KAAK,EAAa,UAAU,EAAqC,MAAM,kBAAkB,CAAA;AAEhG,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"MultiUploader.d.ts","sourceRoot":"","sources":["../../src/components/MultiUploader.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,KAAK,EAAa,UAAU,EAAqC,MAAM,kBAAkB,CAAA;AAEhG,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAoC,MAAM,wBAAwB,CAAA;AAClH,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,aAAa,CAAA;AAa3D,MAAM,WAAW,kBAAkB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE;;OAEG;IACH,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1B;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3B;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EACtE,KAAK,EACL,QAAQ,EACR,QAAQ,GACR,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG,SAAS,CAiGzC;AA+BD,QAAA,MAAM,0BAA0B,EAAoB,OAAO,aAAa,GAAG,iBAAiB,GAAG;IAAE,CAAC,eAAe,CAAC,EAAE,IAAI,CAAA;CAAE,CAAA;AA2B1H,OAAO,EAAE,0BAA0B,IAAI,qBAAqB,EAAE,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { EntityRef,
|
|
1
|
+
import type { EntityRef, HasOneAccessor } from '@contember/bindx';
|
|
2
2
|
import type { FileType, UploaderEvents } from '../../types.js';
|
|
3
3
|
export interface UseFillEntityArgs<TEntity = Record<string, unknown>> extends UploaderEvents {
|
|
4
4
|
/**
|
|
5
5
|
* The entity to fill. Can be:
|
|
6
6
|
* - EntityRef: fill the entity directly
|
|
7
|
-
* -
|
|
7
|
+
* - HasOneAccessor: fill the related entity (disconnect first on upload start)
|
|
8
8
|
*/
|
|
9
|
-
entity: EntityRef<TEntity> |
|
|
9
|
+
entity: EntityRef<TEntity> | HasOneAccessor<TEntity>;
|
|
10
10
|
fileType: FileType<TEntity>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFillEntity.d.ts","sourceRoot":"","sources":["../../../src/internal/hooks/useFillEntity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"useFillEntity.d.ts","sourceRoot":"","sources":["../../../src/internal/hooks/useFillEntity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAoB,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIhF,MAAM,WAAW,iBAAiB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,SAAQ,cAAc;IAC3F;;;;OAIG;IACH,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACpD,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAC3B;AAoBD;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,iCAIpE,iBAAiB,CAAC,OAAO,CAAC,KAAG,cA8C/B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/bindx-uploader",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "File upload components for bindx data binding",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"react": ">=18.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@contember/bindx": "0.1.
|
|
19
|
-
"@contember/bindx-react": "0.1.
|
|
20
|
-
"@contember/bindx-repeater": "0.1.
|
|
18
|
+
"@contember/bindx": "0.1.16",
|
|
19
|
+
"@contember/bindx-react": "0.1.16",
|
|
20
|
+
"@contember/bindx-repeater": "0.1.16",
|
|
21
21
|
"@radix-ui/react-slot": "^1.2.3",
|
|
22
22
|
"react-dropzone": "^14.3.8"
|
|
23
23
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useMemo, useRef, type ReactNode } from 'react'
|
|
2
2
|
import type { EntityRef, HasManyRef, SelectionFieldMeta, SelectionMeta } from '@contember/bindx'
|
|
3
3
|
import { FIELD_REF_META } from '@contember/bindx'
|
|
4
|
-
import { BINDX_COMPONENT, type SelectionProvider, createEmptySelection } from '@contember/bindx-react'
|
|
4
|
+
import { BINDX_COMPONENT, type SelectionProvider, createEmptySelection, useHasMany } from '@contember/bindx-react'
|
|
5
5
|
import type { FileType, UploaderEvents } from '../types.js'
|
|
6
6
|
import {
|
|
7
7
|
MultiUploaderEntityToFileStateMapContext,
|
|
@@ -54,6 +54,7 @@ export function MultiUploader<TEntity extends Record<string, unknown>>({
|
|
|
54
54
|
fileType,
|
|
55
55
|
children,
|
|
56
56
|
}: MultiUploaderProps<TEntity>): ReactNode {
|
|
57
|
+
const fieldAccessor = useHasMany(field)
|
|
57
58
|
// Map file ID -> entity ID
|
|
58
59
|
const fileToEntityMapRef = useRef(new Map<string, string>())
|
|
59
60
|
// Map entity ID -> file ID (for reverse lookup)
|
|
@@ -63,9 +64,9 @@ export function MultiUploader<TEntity extends Record<string, unknown>>({
|
|
|
63
64
|
(fileId: string): EntityRef<unknown> | undefined => {
|
|
64
65
|
const entityId = fileToEntityMapRef.current.get(fileId)
|
|
65
66
|
if (!entityId) return undefined
|
|
66
|
-
return
|
|
67
|
+
return fieldAccessor.items.find((item: { id: string }) => item.id === entityId) as EntityRef<unknown> | undefined
|
|
67
68
|
},
|
|
68
|
-
[
|
|
69
|
+
[fieldAccessor.items],
|
|
69
70
|
)
|
|
70
71
|
|
|
71
72
|
// Create entity for file and track mapping
|
|
@@ -33,7 +33,7 @@ export const getAudioFileDataExtractor = <TEntity extends Record<string, unknown
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
return ({ entity }) => {
|
|
36
|
-
const fields = (entity as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
36
|
+
const fields = ((entity as unknown) as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
37
37
|
|
|
38
38
|
if (durationField) {
|
|
39
39
|
// Round duration for integer fields
|
|
@@ -13,7 +13,7 @@ export const getFileUrlDataExtractor = <TEntity extends Record<string, unknown>>
|
|
|
13
13
|
}: FileUrlDataExtractorProps<TEntity>): FileDataExtractor<TEntity> => ({
|
|
14
14
|
getFieldNames: () => [urlField],
|
|
15
15
|
populateFields: ({ entity, result }) => {
|
|
16
|
-
const fields = (entity as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
16
|
+
const fields = ((entity as unknown) as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
17
17
|
const field = fields[urlField]
|
|
18
18
|
if (field) {
|
|
19
19
|
field.setValue(result.publicUrl ?? null)
|
|
@@ -20,7 +20,7 @@ export const getGenericFileMetadataExtractor = <TEntity extends Record<string, u
|
|
|
20
20
|
getFieldNames: () => [fileNameField, fileSizeField, fileTypeField, lastModifiedField].filter((f): f is FieldName<TEntity> => !!f),
|
|
21
21
|
extractFileData: ({ file }) => {
|
|
22
22
|
return ({ entity }) => {
|
|
23
|
-
const fields = (entity as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
23
|
+
const fields = ((entity as unknown) as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
24
24
|
|
|
25
25
|
if (fileNameField) {
|
|
26
26
|
fields[fileNameField]?.setValue(file.name)
|
|
@@ -37,7 +37,7 @@ export const getImageFileDataExtractor = <TEntity extends Record<string, unknown
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
return ({ entity }) => {
|
|
40
|
-
const fields = (entity as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
40
|
+
const fields = ((entity as unknown) as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
41
41
|
|
|
42
42
|
if (widthField) {
|
|
43
43
|
fields[widthField]?.setValue(result.width ?? null)
|
|
@@ -43,7 +43,7 @@ export const getVideoFileDataExtractor = <TEntity extends Record<string, unknown
|
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
return ({ entity }) => {
|
|
46
|
-
const fields = (entity as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
46
|
+
const fields = ((entity as unknown) as { $fields: Record<string, FieldRef<unknown>> }).$fields
|
|
47
47
|
|
|
48
48
|
if (widthField) {
|
|
49
49
|
fields[widthField]?.setValue(result.width ?? null)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback } from 'react'
|
|
2
|
-
import type { EntityRef,
|
|
2
|
+
import type { EntityRef, HasOneAccessor } from '@contember/bindx'
|
|
3
3
|
import type { FileType, StartUploadEvent, UploaderEvents } from '../../types.js'
|
|
4
4
|
import { resolveAcceptingSingleType } from '../utils/resolveAccept.js'
|
|
5
5
|
import { executeExtractors } from '../utils/executeExtractors.js'
|
|
@@ -8,25 +8,25 @@ export interface UseFillEntityArgs<TEntity = Record<string, unknown>> extends Up
|
|
|
8
8
|
/**
|
|
9
9
|
* The entity to fill. Can be:
|
|
10
10
|
* - EntityRef: fill the entity directly
|
|
11
|
-
* -
|
|
11
|
+
* - HasOneAccessor: fill the related entity (disconnect first on upload start)
|
|
12
12
|
*/
|
|
13
|
-
entity: EntityRef<TEntity> |
|
|
13
|
+
entity: EntityRef<TEntity> | HasOneAccessor<TEntity>
|
|
14
14
|
fileType: FileType<TEntity>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Checks if the entity is a HasOneRef (has $disconnect method)
|
|
19
19
|
*/
|
|
20
|
-
const
|
|
20
|
+
const isHasOneAccessor = <TEntity>(entity: EntityRef<TEntity> | HasOneAccessor<TEntity>): entity is HasOneAccessor<TEntity> => {
|
|
21
21
|
return '$disconnect' in entity && typeof entity.$disconnect === 'function'
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Gets the target entity for filling.
|
|
26
|
-
* For
|
|
26
|
+
* For HasOneAccessor, returns the related entity. For EntityRef, returns the entity itself.
|
|
27
27
|
*/
|
|
28
|
-
const getTargetEntity = <TEntity>(entity: EntityRef<TEntity> |
|
|
29
|
-
if (
|
|
28
|
+
const getTargetEntity = <TEntity>(entity: EntityRef<TEntity> | HasOneAccessor<TEntity>): EntityRef<TEntity> => {
|
|
29
|
+
if (isHasOneAccessor(entity)) {
|
|
30
30
|
return entity.$entity
|
|
31
31
|
}
|
|
32
32
|
return entity
|
|
@@ -54,7 +54,7 @@ export const useFillEntity = <TEntity extends Record<string, unknown>>({
|
|
|
54
54
|
const handleStartUpload = useCallback(
|
|
55
55
|
(event: StartUploadEvent) => {
|
|
56
56
|
// Disconnect existing relation before upload
|
|
57
|
-
if (
|
|
57
|
+
if (isHasOneAccessor(entity)) {
|
|
58
58
|
entity.$disconnect()
|
|
59
59
|
}
|
|
60
60
|
events.onStartUpload?.(event)
|