feat: singleton array list widget (#336)

This commit is contained in:
Daniel Lautzenheiser
2023-01-12 14:15:41 -05:00
committed by GitHub
parent a60d53b4ec
commit c5e94ed16d
64 changed files with 1353 additions and 575 deletions

View File

@ -1,12 +1,12 @@
import { useCallback, useEffect, useMemo } from 'react';
import { v4 as uuid } from 'uuid';
import { selectMediaPath } from '@staticcms/core/reducers/mediaLibrary';
import { useAppDispatch, useAppSelector } from '@staticcms/core/store/hooks';
import { openMediaLibrary, removeInsertedMedia } from '@staticcms/core/actions/mediaLibrary';
import { selectMediaPath } from '@staticcms/core/reducers/selectors/mediaLibrary';
import { useAppDispatch, useAppSelector } from '@staticcms/core/store/hooks';
import type { MouseEvent } from 'react';
import type { FileOrImageField, MarkdownField } from '@staticcms/core/interface';
import type { MouseEvent } from 'react';
export default function useMediaInsert<T extends string | string[]>(
value: T,

View File

@ -0,0 +1,101 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import React from 'react';
import type {
BaseField,
Collection,
Config,
Entry,
UnknownField,
WidgetControlProps,
} from '@staticcms/core/interface';
import type { FC } from 'react';
import type { t } from 'react-polyglot';
export interface CreateControlWrapper<V = unknown, F extends BaseField = UnknownField> {
defaultField: F;
control: FC<WidgetControlProps<V, F>>;
label: string;
path: string;
}
const createControlWrapper = <V = unknown, F extends BaseField = UnknownField>({
defaultField,
control: Control,
label: defaultLabel,
path: defaultPath,
}: CreateControlWrapper<V, F>) => {
const ControlWrapper: FC<Partial<WidgetControlProps<V, F>>> = ({
collection = {} as Collection<F>,
config = {} as Config<F>,
entry = {} as Entry,
field = defaultField,
fieldsErrors = {},
submitted = false,
forList = false,
getAsset = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Promise.resolve(null) as any;
},
isDisabled = false,
isFieldDuplicate = () => false,
isFieldHidden = () => false,
label = defaultLabel,
locale = 'en',
mediaPaths = {},
onChange = () => {},
clearMediaControl = () => {},
openMediaLibrary = () => {},
removeInsertedMedia = () => ({
type: 'MEDIA_REMOVE_INSERTED',
payload: {
controlID: '123456',
},
}),
removeMediaControl = () => {},
i18n = undefined,
hasErrors = false,
path = defaultPath,
query = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Promise.resolve('') as any;
},
t = (() => '') as t,
value = undefined,
}) => {
return (
<Control
key="control"
collection={collection}
config={config}
entry={entry}
field={field}
fieldsErrors={fieldsErrors}
submitted={submitted}
forList={forList}
getAsset={getAsset}
isDisabled={isDisabled}
isFieldDuplicate={isFieldDuplicate}
isFieldHidden={isFieldHidden}
label={label}
locale={locale}
mediaPaths={mediaPaths}
onChange={onChange}
clearMediaControl={clearMediaControl}
openMediaLibrary={openMediaLibrary}
removeInsertedMedia={removeInsertedMedia}
removeMediaControl={removeMediaControl}
i18n={i18n}
hasErrors={hasErrors}
path={path}
query={query}
t={t}
value={value}
/>
);
};
return ControlWrapper;
};
export default createControlWrapper;

View File

@ -0,0 +1,17 @@
import type { Entry } from '@staticcms/core/interface';
const mockEntry: Entry = {
collection: 'collection',
slug: 'slug',
path: '',
partial: false,
raw: '',
data: {},
label: 'Entry',
isModification: false,
mediaFiles: [],
author: '',
updatedOn: '',
};
export default mockEntry;