payload 0.14.5-beta.0 → 0.14.9-beta.0
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +13 -13
- package/components/index.js +2 -2
- package/components/styles.css +1 -1
- package/dist/admin/components/elements/Button/index.js +10 -5
- package/dist/admin/components/elements/Button/index.scss +20 -0
- package/dist/admin/components/elements/Button/types.d.ts +1 -0
- package/dist/admin/components/elements/Tooltip/index.scss +1 -0
- package/dist/admin/components/forms/Form/reduceFieldsToValues.d.ts +1 -1
- package/dist/admin/components/forms/Form/reduceFieldsToValues.js +4 -4
- package/dist/admin/components/forms/field-types/RichText/RichText.d.ts +2 -2
- package/dist/admin/components/forms/field-types/RichText/RichText.js +8 -9
- package/dist/admin/components/forms/field-types/RichText/buttons.scss +4 -0
- package/dist/admin/components/forms/field-types/RichText/elements/Button.d.ts +1 -0
- package/dist/admin/components/forms/field-types/RichText/elements/Button.js +1 -1
- package/dist/admin/components/forms/field-types/RichText/elements/ListButton.d.ts +6 -0
- package/dist/admin/components/forms/field-types/RichText/elements/ListButton.js +19 -0
- package/dist/admin/components/forms/field-types/RichText/elements/indent/index.d.ts +9 -0
- package/dist/admin/components/forms/field-types/RichText/elements/indent/index.js +69 -0
- package/dist/admin/components/forms/field-types/RichText/elements/index.d.ts +9 -4
- package/dist/admin/components/forms/field-types/RichText/elements/index.js +4 -1
- package/dist/admin/components/forms/field-types/RichText/elements/isActive.js +6 -3
- package/dist/admin/components/forms/field-types/RichText/elements/isListActive.d.ts +3 -0
- package/dist/admin/components/forms/field-types/RichText/elements/isListActive.js +21 -0
- package/dist/admin/components/forms/field-types/RichText/elements/li/index.d.ts +1 -4
- package/dist/admin/components/forms/field-types/RichText/elements/li/index.js +7 -1
- package/dist/admin/components/forms/field-types/RichText/elements/link/index.d.ts +1 -1
- package/dist/admin/components/forms/field-types/RichText/elements/ol/index.js +2 -2
- package/dist/admin/components/forms/field-types/RichText/elements/toggle.js +2 -1
- package/dist/admin/components/forms/field-types/RichText/elements/ul/index.js +2 -2
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.d.ts +16 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.js +47 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.scss +25 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/SwapUploadModal/index.d.ts +13 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/SwapUploadModal/index.js +96 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/SwapUploadModal/index.scss +25 -0
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/index.d.ts +2 -2
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/index.js +41 -107
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/index.scss +55 -12
- package/dist/admin/components/forms/field-types/RichText/elements/upload/index.d.ts +2 -1
- package/dist/admin/components/forms/field-types/RichText/types.d.ts +4 -0
- package/dist/admin/components/icons/IndentLeft/index.d.ts +4 -0
- package/dist/admin/components/icons/IndentLeft/index.js +8 -0
- package/dist/admin/components/icons/IndentLeft/index.scss +16 -0
- package/dist/admin/components/icons/IndentRight/index.d.ts +4 -0
- package/dist/admin/components/icons/IndentRight/index.js +8 -0
- package/dist/admin/components/icons/IndentRight/index.scss +16 -0
- package/dist/admin/components/icons/Swap/index.d.ts +4 -0
- package/dist/admin/components/icons/Swap/index.js +8 -0
- package/dist/admin/components/icons/Swap/index.scss +12 -0
- package/dist/admin/scss/vars.scss +4 -0
- package/dist/collections/operations/delete.js +8 -2
- package/dist/fields/config/schema.js +6 -1
- package/dist/fields/config/types.d.ts +8 -1
- package/dist/fields/config/types.js +1 -1
- package/dist/fields/richText/defaultValue.d.ts +1 -0
- package/dist/fields/richText/defaultValue.js +2 -1
- package/dist/fields/richText/populate.d.ts +20 -0
- package/dist/fields/richText/populate.js +27 -0
- package/dist/fields/richText/recurseNestedFields.d.ts +16 -0
- package/dist/fields/richText/recurseNestedFields.js +167 -0
- package/dist/fields/richText/relationshipPromise.d.ts +27 -0
- package/dist/fields/richText/relationshipPromise.js +74 -0
- package/dist/fields/traverseFields.js +3 -3
- package/dist/graphql/schema/buildObjectType.js +3 -3
- package/docs/fields/rich-text.mdx +23 -2
- package/package.json +3 -3
- package/dist/fields/richTextRelationshipPromise.d.ts +0 -15
- package/dist/fields/richTextRelationshipPromise.js +0 -79
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useSlate, ReactEditor } from 'slate-react';
|
|
3
|
+
import { Editor, Element, Transforms } from 'slate';
|
|
4
|
+
import IndentLeft from '../../../../../icons/IndentLeft';
|
|
5
|
+
import IndentRight from '../../../../../icons/IndentRight';
|
|
6
|
+
import { baseClass } from '../Button';
|
|
7
|
+
import isElementActive from '../isActive';
|
|
8
|
+
import listTypes from '../listTypes';
|
|
9
|
+
const indentType = 'indent';
|
|
10
|
+
const IndentWithPadding = ({ attributes, children }) => (React.createElement("div", { style: { paddingLeft: 25 }, ...attributes }, children));
|
|
11
|
+
const indent = {
|
|
12
|
+
Button: () => {
|
|
13
|
+
const editor = useSlate();
|
|
14
|
+
const handleIndent = useCallback((e, dir) => {
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
if (editor.blurSelection) {
|
|
17
|
+
Transforms.select(editor, editor.blurSelection);
|
|
18
|
+
}
|
|
19
|
+
if (dir === 'left') {
|
|
20
|
+
Transforms.unwrapNodes(editor, {
|
|
21
|
+
match: (n) => Element.isElement(n) && [indentType, ...listTypes].includes(n.type),
|
|
22
|
+
split: true,
|
|
23
|
+
mode: 'lowest',
|
|
24
|
+
});
|
|
25
|
+
if (isElementActive(editor, 'li')) {
|
|
26
|
+
const [, parentLocation] = Editor.parent(editor, editor.selection);
|
|
27
|
+
const [, parentDepth] = parentLocation;
|
|
28
|
+
if (parentDepth > 0 || parentDepth === 0) {
|
|
29
|
+
Transforms.unwrapNodes(editor, {
|
|
30
|
+
match: (n) => Element.isElement(n) && n.type === 'li',
|
|
31
|
+
split: true,
|
|
32
|
+
mode: 'lowest',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Transforms.unsetNodes(editor, ['type']);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (dir === 'right') {
|
|
41
|
+
const isCurrentlyOL = isElementActive(editor, 'ol');
|
|
42
|
+
const isCurrentlyUL = isElementActive(editor, 'ul');
|
|
43
|
+
if (isCurrentlyOL || isCurrentlyUL) {
|
|
44
|
+
Transforms.wrapNodes(editor, {
|
|
45
|
+
type: 'li',
|
|
46
|
+
children: [],
|
|
47
|
+
});
|
|
48
|
+
Transforms.wrapNodes(editor, { type: isCurrentlyOL ? 'ol' : 'ul', children: [{ text: ' ' }] });
|
|
49
|
+
Transforms.setNodes(editor, { type: 'li' });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
Transforms.wrapNodes(editor, { type: indentType, children: [] });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
ReactEditor.focus(editor);
|
|
56
|
+
}, [editor]);
|
|
57
|
+
const canDeIndent = isElementActive(editor, 'li') || isElementActive(editor, indentType);
|
|
58
|
+
return (React.createElement(React.Fragment, null,
|
|
59
|
+
React.createElement("button", { type: "button", className: [
|
|
60
|
+
baseClass,
|
|
61
|
+
!canDeIndent && `${baseClass}--disabled`,
|
|
62
|
+
].filter(Boolean).join(' '), onClick: canDeIndent ? (e) => handleIndent(e, 'left') : undefined },
|
|
63
|
+
React.createElement(IndentLeft, null)),
|
|
64
|
+
React.createElement("button", { type: "button", className: baseClass, onClick: (e) => handleIndent(e, 'right') },
|
|
65
|
+
React.createElement(IndentRight, null))));
|
|
66
|
+
},
|
|
67
|
+
Element: IndentWithPadding,
|
|
68
|
+
};
|
|
69
|
+
export default indent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const
|
|
2
|
+
declare const elements: {
|
|
3
3
|
h1: {
|
|
4
4
|
Button: () => JSX.Element;
|
|
5
5
|
Element: ({ attributes, children }: {
|
|
@@ -49,7 +49,7 @@ declare const _default: {
|
|
|
49
49
|
children: any;
|
|
50
50
|
element: any;
|
|
51
51
|
}) => JSX.Element;
|
|
52
|
-
plugins: ((incomingEditor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor) => import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor)[];
|
|
52
|
+
plugins: ((incomingEditor: import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor & import("../types").BlurSelectionEditor) => import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor & import("../types").BlurSelectionEditor)[];
|
|
53
53
|
};
|
|
54
54
|
ol: {
|
|
55
55
|
Button: () => JSX.Element;
|
|
@@ -66,6 +66,10 @@ declare const _default: {
|
|
|
66
66
|
}) => JSX.Element;
|
|
67
67
|
};
|
|
68
68
|
li: {
|
|
69
|
+
Element: (props: any) => JSX.Element;
|
|
70
|
+
};
|
|
71
|
+
indent: {
|
|
72
|
+
Button: () => JSX.Element;
|
|
69
73
|
Element: ({ attributes, children }: {
|
|
70
74
|
attributes: any;
|
|
71
75
|
children: any;
|
|
@@ -82,13 +86,14 @@ declare const _default: {
|
|
|
82
86
|
Button: import("react").FC<{
|
|
83
87
|
path: string;
|
|
84
88
|
}>;
|
|
85
|
-
Element: ({ attributes, children, element, path }: {
|
|
89
|
+
Element: ({ attributes, children, element, path, fieldProps }: {
|
|
86
90
|
attributes: any;
|
|
87
91
|
children: any;
|
|
88
92
|
element: any;
|
|
89
93
|
path: any;
|
|
94
|
+
fieldProps: any;
|
|
90
95
|
}) => JSX.Element;
|
|
91
96
|
plugins: ((incomingEditor: any) => any)[];
|
|
92
97
|
};
|
|
93
98
|
};
|
|
94
|
-
export default
|
|
99
|
+
export default elements;
|
|
@@ -8,9 +8,10 @@ import link from './link';
|
|
|
8
8
|
import ol from './ol';
|
|
9
9
|
import ul from './ul';
|
|
10
10
|
import li from './li';
|
|
11
|
+
import indent from './indent';
|
|
11
12
|
import relationship from './relationship';
|
|
12
13
|
import upload from './upload';
|
|
13
|
-
|
|
14
|
+
const elements = {
|
|
14
15
|
h1,
|
|
15
16
|
h2,
|
|
16
17
|
h3,
|
|
@@ -21,6 +22,8 @@ export default {
|
|
|
21
22
|
ol,
|
|
22
23
|
ul,
|
|
23
24
|
li,
|
|
25
|
+
indent,
|
|
24
26
|
relationship,
|
|
25
27
|
upload,
|
|
26
28
|
};
|
|
29
|
+
export default elements;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Editor, Element } from 'slate';
|
|
2
2
|
const isElementActive = (editor, format) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
if (!editor.selection)
|
|
4
|
+
return false;
|
|
5
|
+
const [match] = Array.from(Editor.nodes(editor, {
|
|
6
|
+
at: Editor.unhangRange(editor, editor.selection),
|
|
7
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === format,
|
|
8
|
+
}));
|
|
6
9
|
return !!match;
|
|
7
10
|
};
|
|
8
11
|
export default isElementActive;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Editor, Element } from 'slate';
|
|
2
|
+
const isListActive = (editor, format) => {
|
|
3
|
+
if (!editor.selection
|
|
4
|
+
// If focus or anchor is at root of editor,
|
|
5
|
+
// Return false - as Editor.parent will fail
|
|
6
|
+
|| editor.selection.focus.path[1] === 0
|
|
7
|
+
// || editor.selection.focus.path.length === 0
|
|
8
|
+
|| editor.selection.anchor.path[1] === 0
|
|
9
|
+
// || editor.selection.anchor.path.length === 0
|
|
10
|
+
)
|
|
11
|
+
return false;
|
|
12
|
+
const parentLI = Editor.parent(editor, editor.selection);
|
|
13
|
+
if (parentLI[1].length > 0) {
|
|
14
|
+
const ancestor = Editor.above(editor, {
|
|
15
|
+
at: parentLI[1],
|
|
16
|
+
});
|
|
17
|
+
return Element.isElement(ancestor[0]) && ancestor[0].type === format;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
export default isListActive;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import listTypes from '../listTypes';
|
|
3
|
+
const LI = (props) => {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const { attributes, element, children } = props;
|
|
6
|
+
const disableListStyle = element.children.length >= 1 && listTypes.includes((_b = (_a = element.children) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type);
|
|
7
|
+
return (React.createElement("li", { style: { listStyle: disableListStyle ? 'none' : undefined }, ...attributes }, children));
|
|
8
|
+
};
|
|
3
9
|
export default {
|
|
4
10
|
Element: LI,
|
|
5
11
|
};
|
|
@@ -8,6 +8,6 @@ declare const link: {
|
|
|
8
8
|
children: any;
|
|
9
9
|
element: any;
|
|
10
10
|
}) => JSX.Element;
|
|
11
|
-
plugins: ((incomingEditor: import("slate").BaseEditor & ReactEditor & import("slate-history").HistoryEditor) => import("slate").BaseEditor & ReactEditor & import("slate-history").HistoryEditor)[];
|
|
11
|
+
plugins: ((incomingEditor: import("slate").BaseEditor & ReactEditor & import("slate-history").HistoryEditor & import("../../types").BlurSelectionEditor) => import("slate").BaseEditor & ReactEditor & import("slate-history").HistoryEditor & import("../../types").BlurSelectionEditor)[];
|
|
12
12
|
};
|
|
13
13
|
export default link;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import ListButton from '../ListButton';
|
|
3
3
|
import OLIcon from '../../../../../icons/OrderedList';
|
|
4
4
|
const OL = ({ attributes, children }) => (React.createElement("ol", { ...attributes }, children));
|
|
5
5
|
const ol = {
|
|
6
|
-
Button: () => (React.createElement(
|
|
6
|
+
Button: () => (React.createElement(ListButton, { format: "ol" },
|
|
7
7
|
React.createElement(OLIcon, null))),
|
|
8
8
|
Element: OL,
|
|
9
9
|
};
|
|
@@ -7,7 +7,7 @@ const toggleElement = (editor, format) => {
|
|
|
7
7
|
const isList = listTypes.includes(format);
|
|
8
8
|
let type = format;
|
|
9
9
|
if (isActive) {
|
|
10
|
-
type =
|
|
10
|
+
type = undefined;
|
|
11
11
|
}
|
|
12
12
|
else if (isList) {
|
|
13
13
|
type = 'li';
|
|
@@ -18,6 +18,7 @@ const toggleElement = (editor, format) => {
|
|
|
18
18
|
Transforms.unwrapNodes(editor, {
|
|
19
19
|
match: (n) => Element.isElement(n) && listTypes.includes(n.type),
|
|
20
20
|
split: true,
|
|
21
|
+
mode: 'lowest',
|
|
21
22
|
});
|
|
22
23
|
Transforms.setNodes(editor, { type });
|
|
23
24
|
if (!isActive && isList) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import ElementButton from '../Button';
|
|
3
2
|
import ULIcon from '../../../../../icons/UnorderedList';
|
|
3
|
+
import ListButton from '../ListButton';
|
|
4
4
|
const UL = ({ attributes, children }) => (React.createElement("ul", { ...attributes }, children));
|
|
5
5
|
const ul = {
|
|
6
|
-
Button: () => (React.createElement(
|
|
6
|
+
Button: () => (React.createElement(ListButton, { format: "ul" },
|
|
7
7
|
React.createElement(ULIcon, null))),
|
|
8
8
|
Element: UL,
|
|
9
9
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Element } from 'slate';
|
|
3
|
+
import { SanitizedCollectionConfig } from '../../../../../../../../../collections/config/types';
|
|
4
|
+
import { Field } from '../../../../../../../../../fields/config/types';
|
|
5
|
+
import './index.scss';
|
|
6
|
+
declare type Props = {
|
|
7
|
+
slug: string;
|
|
8
|
+
closeModal: () => void;
|
|
9
|
+
relatedCollectionConfig: SanitizedCollectionConfig;
|
|
10
|
+
fieldSchema: Field[];
|
|
11
|
+
element: Element & {
|
|
12
|
+
fields: Field[];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const EditModal: React.FC<Props>;
|
|
16
|
+
export {};
|
package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { Transforms } from 'slate';
|
|
3
|
+
import { ReactEditor, useSlateStatic } from 'slate-react';
|
|
4
|
+
import { Modal } from '@faceless-ui/modal';
|
|
5
|
+
import buildStateFromSchema from '../../../../../../Form/buildStateFromSchema';
|
|
6
|
+
import MinimalTemplate from '../../../../../../../templates/Minimal';
|
|
7
|
+
import Button from '../../../../../../../elements/Button';
|
|
8
|
+
import RenderFields from '../../../../../../RenderFields';
|
|
9
|
+
import fieldTypes from '../../../../..';
|
|
10
|
+
import Form from '../../../../../../Form';
|
|
11
|
+
import reduceFieldsToValues from '../../../../../../Form/reduceFieldsToValues';
|
|
12
|
+
import Submit from '../../../../../../Submit';
|
|
13
|
+
import './index.scss';
|
|
14
|
+
const baseClass = 'edit-upload-modal';
|
|
15
|
+
export const EditModal = ({ slug, closeModal, relatedCollectionConfig, fieldSchema, element }) => {
|
|
16
|
+
const editor = useSlateStatic();
|
|
17
|
+
const [initialState, setInitialState] = useState({});
|
|
18
|
+
const handleUpdateEditData = useCallback((fields) => {
|
|
19
|
+
const newNode = {
|
|
20
|
+
fields: reduceFieldsToValues(fields, true),
|
|
21
|
+
};
|
|
22
|
+
const elementPath = ReactEditor.findPath(editor, element);
|
|
23
|
+
Transforms.setNodes(editor, newNode, { at: elementPath });
|
|
24
|
+
closeModal();
|
|
25
|
+
}, [closeModal, editor, element]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const awaitInitialState = async () => {
|
|
28
|
+
const state = await buildStateFromSchema(fieldSchema, element === null || element === void 0 ? void 0 : element.fields);
|
|
29
|
+
setInitialState(state);
|
|
30
|
+
};
|
|
31
|
+
awaitInitialState();
|
|
32
|
+
}, [fieldSchema, element.fields]);
|
|
33
|
+
return (React.createElement(Modal, { slug: slug, className: baseClass },
|
|
34
|
+
React.createElement(MinimalTemplate, { width: "normal" },
|
|
35
|
+
React.createElement("header", { className: `${baseClass}__header` },
|
|
36
|
+
React.createElement("h1", null,
|
|
37
|
+
"Edit",
|
|
38
|
+
' ',
|
|
39
|
+
relatedCollectionConfig.labels.singular,
|
|
40
|
+
' ',
|
|
41
|
+
"data"),
|
|
42
|
+
React.createElement(Button, { icon: "x", round: true, buttonStyle: "icon-label", onClick: closeModal })),
|
|
43
|
+
React.createElement("div", null,
|
|
44
|
+
React.createElement(Form, { onSubmit: handleUpdateEditData, initialState: initialState },
|
|
45
|
+
React.createElement(RenderFields, { readOnly: false, fieldTypes: fieldTypes, fieldSchema: fieldSchema }),
|
|
46
|
+
React.createElement(Submit, null, "Save changes"))))));
|
|
47
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@import '../../../../../../../../scss/styles.scss';
|
|
2
|
+
|
|
3
|
+
.edit-upload-modal {
|
|
4
|
+
@include blur-bg;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
|
|
8
|
+
.template-minimal {
|
|
9
|
+
padding-top: base(4);
|
|
10
|
+
align-items: flex-start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&__header {
|
|
14
|
+
margin-bottom: $baseline;
|
|
15
|
+
display: flex;
|
|
16
|
+
|
|
17
|
+
h1 {
|
|
18
|
+
margin: 0 auto 0 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.btn {
|
|
22
|
+
margin: 0 0 0 $baseline;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Element } from 'slate';
|
|
3
|
+
import { SanitizedCollectionConfig } from '../../../../../../../../../collections/config/types';
|
|
4
|
+
import './index.scss';
|
|
5
|
+
declare type Props = {
|
|
6
|
+
slug: string;
|
|
7
|
+
element: Element;
|
|
8
|
+
closeModal: () => void;
|
|
9
|
+
setRelatedCollectionConfig: (collectionConfig: SanitizedCollectionConfig) => void;
|
|
10
|
+
relatedCollectionConfig: SanitizedCollectionConfig;
|
|
11
|
+
};
|
|
12
|
+
export declare const SwapUploadModal: React.FC<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Modal } from '@faceless-ui/modal';
|
|
3
|
+
import { useConfig } from '@payloadcms/config-provider';
|
|
4
|
+
import { Transforms } from 'slate';
|
|
5
|
+
import { ReactEditor, useSlateStatic } from 'slate-react';
|
|
6
|
+
import usePayloadAPI from '../../../../../../../../hooks/usePayloadAPI';
|
|
7
|
+
import MinimalTemplate from '../../../../../../../templates/Minimal';
|
|
8
|
+
import Button from '../../../../../../../elements/Button';
|
|
9
|
+
import Label from '../../../../../../Label';
|
|
10
|
+
import ReactSelect from '../../../../../../../elements/ReactSelect';
|
|
11
|
+
import ListControls from '../../../../../../../elements/ListControls';
|
|
12
|
+
import UploadGallery from '../../../../../../../elements/UploadGallery';
|
|
13
|
+
import Paginator from '../../../../../../../elements/Paginator';
|
|
14
|
+
import PerPage from '../../../../../../../elements/PerPage';
|
|
15
|
+
import formatFields from '../../../../../../../views/collections/List/formatFields';
|
|
16
|
+
import './index.scss';
|
|
17
|
+
const baseClass = 'swap-upload-modal';
|
|
18
|
+
export const SwapUploadModal = ({ closeModal, element, setRelatedCollectionConfig, relatedCollectionConfig, slug }) => {
|
|
19
|
+
const { collections, serverURL, routes: { api } } = useConfig();
|
|
20
|
+
const editor = useSlateStatic();
|
|
21
|
+
const [modalCollection, setModalCollection] = React.useState(relatedCollectionConfig);
|
|
22
|
+
const [modalCollectionOption, setModalCollectionOption] = React.useState({ label: relatedCollectionConfig.labels.singular, value: relatedCollectionConfig.slug });
|
|
23
|
+
const [availableCollections] = React.useState(() => collections.filter(({ admin: { enableRichTextRelationship }, upload }) => (Boolean(upload) && enableRichTextRelationship)));
|
|
24
|
+
const [fields, setFields] = React.useState(() => formatFields(modalCollection));
|
|
25
|
+
const [limit, setLimit] = React.useState();
|
|
26
|
+
const [sort, setSort] = React.useState(null);
|
|
27
|
+
const [where, setWhere] = React.useState(null);
|
|
28
|
+
const [page, setPage] = React.useState(null);
|
|
29
|
+
const moreThanOneAvailableCollection = availableCollections.length > 1;
|
|
30
|
+
const apiURL = `${serverURL}${api}/${modalCollection.slug}`;
|
|
31
|
+
const [{ data }, { setParams }] = usePayloadAPI(apiURL, {});
|
|
32
|
+
const handleUpdateUpload = React.useCallback((doc) => {
|
|
33
|
+
const newNode = {
|
|
34
|
+
type: 'upload',
|
|
35
|
+
value: { id: doc.id },
|
|
36
|
+
relationTo: modalCollection.slug,
|
|
37
|
+
children: [
|
|
38
|
+
{ text: ' ' },
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
const elementPath = ReactEditor.findPath(editor, element);
|
|
42
|
+
Transforms.setNodes(editor, newNode, { at: elementPath });
|
|
43
|
+
closeModal();
|
|
44
|
+
}, [closeModal, editor, element, modalCollection]);
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
const params = {};
|
|
47
|
+
if (page)
|
|
48
|
+
params.page = page;
|
|
49
|
+
if (where)
|
|
50
|
+
params.where = where;
|
|
51
|
+
if (sort)
|
|
52
|
+
params.sort = sort;
|
|
53
|
+
if (limit)
|
|
54
|
+
params.limit = limit;
|
|
55
|
+
setParams(params);
|
|
56
|
+
}, [setParams, page, sort, where, limit]);
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
setFields(formatFields(modalCollection));
|
|
59
|
+
setLimit(modalCollection.admin.pagination.defaultLimit);
|
|
60
|
+
}, [modalCollection]);
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setModalCollection(collections.find(({ slug: collectionSlug }) => modalCollectionOption.value === collectionSlug));
|
|
63
|
+
}, [modalCollectionOption, collections]);
|
|
64
|
+
return (React.createElement(Modal, { className: baseClass, slug: slug },
|
|
65
|
+
React.createElement(MinimalTemplate, { width: "wide" },
|
|
66
|
+
React.createElement("header", { className: `${baseClass}__header` },
|
|
67
|
+
React.createElement("h1", null,
|
|
68
|
+
"Choose",
|
|
69
|
+
' ',
|
|
70
|
+
modalCollection.labels.singular),
|
|
71
|
+
React.createElement(Button, { icon: "x", round: true, buttonStyle: "icon-label", iconStyle: "with-border", onClick: closeModal })),
|
|
72
|
+
moreThanOneAvailableCollection && (React.createElement("div", { className: `${baseClass}__select-collection-wrap` },
|
|
73
|
+
React.createElement(Label, { label: "Select a Collection to Browse" }),
|
|
74
|
+
React.createElement(ReactSelect, { className: `${baseClass}__select-collection`, value: modalCollectionOption, onChange: setModalCollectionOption, options: availableCollections.map((coll) => ({ label: coll.labels.singular, value: coll.slug })) }))),
|
|
75
|
+
React.createElement(ListControls, { collection: {
|
|
76
|
+
...modalCollection,
|
|
77
|
+
fields,
|
|
78
|
+
}, enableColumns: false, enableSort: true, modifySearchQuery: false, handleSortChange: setSort, handleWhereChange: setWhere }),
|
|
79
|
+
React.createElement(UploadGallery, { docs: data === null || data === void 0 ? void 0 : data.docs, collection: modalCollection, onCardClick: (doc) => {
|
|
80
|
+
handleUpdateUpload(doc);
|
|
81
|
+
setRelatedCollectionConfig(modalCollection);
|
|
82
|
+
closeModal();
|
|
83
|
+
} }),
|
|
84
|
+
React.createElement("div", { className: `${baseClass}__page-controls` },
|
|
85
|
+
React.createElement(Paginator, { limit: data.limit, totalPages: data.totalPages, page: data.page, hasPrevPage: data.hasPrevPage, hasNextPage: data.hasNextPage, prevPage: data.prevPage, nextPage: data.nextPage, numberOfNeighbors: 1, onChange: setPage, disableHistoryChange: true }),
|
|
86
|
+
(data === null || data === void 0 ? void 0 : data.totalDocs) > 0 && (React.createElement(React.Fragment, null,
|
|
87
|
+
React.createElement("div", { className: `${baseClass}__page-info` },
|
|
88
|
+
data.page,
|
|
89
|
+
"-",
|
|
90
|
+
data.totalPages > 1 ? data.limit : data.totalDocs,
|
|
91
|
+
' ',
|
|
92
|
+
"of",
|
|
93
|
+
' ',
|
|
94
|
+
data.totalDocs),
|
|
95
|
+
React.createElement(PerPage, { collection: modalCollection, limit: limit, modifySearchParams: false, handleChange: setLimit })))))));
|
|
96
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@import '../../../../../../../../scss/styles.scss';
|
|
2
|
+
|
|
3
|
+
.swap-upload-modal {
|
|
4
|
+
@include blur-bg;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
|
|
8
|
+
.template-minimal {
|
|
9
|
+
padding-top: base(4);
|
|
10
|
+
align-items: flex-start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&__header {
|
|
14
|
+
margin-bottom: $baseline;
|
|
15
|
+
display: flex;
|
|
16
|
+
|
|
17
|
+
h1 {
|
|
18
|
+
margin: 0 auto 0 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.btn {
|
|
22
|
+
margin: 0 0 0 $baseline;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import './index.scss';
|
|
3
|
-
|
|
4
|
-
declare const Element: ({ attributes, children, element, path }: {
|
|
3
|
+
declare const Element: ({ attributes, children, element, path, fieldProps }: {
|
|
5
4
|
attributes: any;
|
|
6
5
|
children: any;
|
|
7
6
|
element: any;
|
|
8
7
|
path: any;
|
|
8
|
+
fieldProps: any;
|
|
9
9
|
}) => JSX.Element;
|
|
10
10
|
export default Element;
|