-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(form-builder): inject ArrayFunctions as prop instead of impo…
…rting
- Loading branch information
Showing
10 changed files
with
67 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@sanity/form-builder/src/inputs/arrays/ArrayOfPrimitivesInput/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {default} from './ArrayOfPrimitivesInput' | ||
export * from './ArrayOfPrimitivesInput' |
27 changes: 13 additions & 14 deletions
27
packages/@sanity/form-builder/src/inputs/arrays/common/ArrayFunctions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 27 additions & 20 deletions
47
packages/@sanity/form-builder/src/sanity/inputs/SanityArrayInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
import React from 'react' | ||
import React, {ForwardedRef, forwardRef} from 'react' | ||
import formBuilderConfig from 'config:@sanity/form-builder' | ||
import ArrayFunctions from 'part:@sanity/form-builder/input/array/functions' | ||
import resolveUploader from '../uploads/resolveUploader' | ||
import ArrayInput, {Props} from '../../inputs/arrays/ArrayOfObjectsInput' | ||
import { | ||
ArrayOfPrimitivesInput, | ||
Props as PrimitiveArrayInputProps, | ||
} from '../../inputs/arrays/ArrayOfPrimitivesInput' | ||
|
||
const SUPPORT_DIRECT_UPLOADS = formBuilderConfig?.images?.directUploads | ||
|
||
export default class SanityArray extends React.Component<Props> { | ||
input: any | ||
setInput = (input) => { | ||
this.input = input | ||
} | ||
focus() { | ||
this.input.focus() | ||
} | ||
render() { | ||
return ( | ||
<ArrayInput | ||
ref={this.setInput} | ||
{...this.props} | ||
resolveUploader={resolveUploader} | ||
directUploads={SUPPORT_DIRECT_UPLOADS} | ||
/> | ||
) | ||
} | ||
} | ||
export const SanityArrayInput = forwardRef(function SanityArrayInput( | ||
props: Props, | ||
ref: ForwardedRef<ArrayInput> | ||
) { | ||
return ( | ||
<ArrayInput | ||
{...props} | ||
ref={ref} | ||
resolveUploader={resolveUploader} | ||
ArrayFunctionsImpl={ArrayFunctions} | ||
directUploads={SUPPORT_DIRECT_UPLOADS} | ||
/> | ||
) | ||
}) | ||
|
||
export const SanityArrayOfPrimitivesInput = forwardRef(function SanityArrayOfPrimitivesInput( | ||
props: Omit<PrimitiveArrayInputProps, 'ArrayFunctionsImpl'>, | ||
ref: ForwardedRef<ArrayOfPrimitivesInput> | ||
) { | ||
return <ArrayOfPrimitivesInput {...props} ArrayFunctionsImpl={ArrayFunctions} ref={ref} /> | ||
}) |
9 changes: 3 additions & 6 deletions
9
packages/@sanity/form-builder/src/sanity/uploads/resolveUploader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import {ImageSchemaType, FileSchemaType} from '@sanity/types' | ||
import {SchemaType} from '@sanity/types' | ||
import accept from 'attr-accept' | ||
import * as is from '../../utils/is' | ||
import uploaders from './uploaders' | ||
import {Uploader} from './types' | ||
|
||
export default function resolveUploader( | ||
type: ImageSchemaType | FileSchemaType, | ||
file: File | ||
): Uploader | null { | ||
export default function resolveUploader(type: SchemaType, file: File): Uploader | null { | ||
return uploaders.find((uploader) => { | ||
return ( | ||
is.type(uploader.type, type) && | ||
accept(file, uploader.accepts) && | ||
accept(file, type.options?.accept || '') | ||
accept(file, (type.options as any)?.accept || '') | ||
) | ||
}) | ||
} |