@wordpress/fields 0.29.0 → 0.29.1-next.06ee73755.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/CHANGELOG.md +0 -2
- package/LICENSE.md +1 -1
- package/README.md +41 -0
- package/build/actions/{delete-post.js → delete-post.cjs} +4 -4
- package/build/actions/{duplicate-pattern.js → duplicate-pattern.cjs} +2 -2
- package/build/actions/{duplicate-post.js → duplicate-post.cjs} +2 -2
- package/build/actions/{duplicate-template-part.js → duplicate-template-part.cjs} +3 -3
- package/build/actions/{export-pattern.js → export-pattern.cjs} +2 -2
- package/build/actions/{index.js → index.cjs} +14 -14
- package/build/actions/{permanently-delete-post.js → permanently-delete-post.cjs} +2 -2
- package/build/actions/{rename-post.js → rename-post.cjs} +3 -4
- package/build/actions/{rename-post.js.map → rename-post.cjs.map} +2 -2
- package/build/actions/{reorder-page.js → reorder-page.cjs} +2 -2
- package/build/actions/reorder-page.cjs.map +7 -0
- package/build/actions/{reset-post.js → reset-post.cjs} +2 -2
- package/build/actions/{restore-post.js → restore-post.cjs} +2 -2
- package/build/actions/{trash-post.js → trash-post.cjs} +2 -2
- package/build/actions/{utils.js → utils.cjs} +1 -1
- package/build/actions/{view-post-revisions.js → view-post-revisions.cjs} +1 -1
- package/build/actions/{view-post.js → view-post.cjs} +1 -1
- package/build/components/create-template-part-modal/{index.js → index.cjs} +3 -4
- package/build/components/create-template-part-modal/index.cjs.map +7 -0
- package/build/components/create-template-part-modal/{utils.js → utils.cjs} +1 -1
- package/build/components/media-edit/index.cjs +494 -0
- package/build/components/media-edit/index.cjs.map +7 -0
- package/build/fields/author/{author-view.js → author-view.cjs} +1 -1
- package/build/fields/author/{index.js → index.cjs} +2 -2
- package/build/fields/comment-status/{index.js → index.cjs} +1 -1
- package/build/fields/date/{date-view.js → date-view.cjs} +1 -1
- package/build/fields/date/{index.js → index.cjs} +2 -2
- package/build/fields/discussion/{index.js → index.cjs} +1 -1
- package/build/fields/featured-image/{featured-image-view.js → featured-image-view.cjs} +1 -1
- package/build/fields/featured-image/index.cjs +52 -0
- package/build/fields/featured-image/index.cjs.map +7 -0
- package/build/fields/{index.js → index.cjs} +18 -18
- package/build/fields/notes/{index.js → index.cjs} +1 -1
- package/build/fields/order/{index.js → index.cjs} +1 -1
- package/build/fields/page-title/{index.js → index.cjs} +3 -3
- package/build/fields/page-title/{view.js → view.cjs} +3 -3
- package/build/fields/parent/{index.js → index.cjs} +3 -3
- package/build/fields/parent/{parent-edit.js → parent-edit.cjs} +2 -3
- package/build/fields/parent/{parent-edit.js.map → parent-edit.cjs.map} +2 -2
- package/build/fields/parent/{parent-view.js → parent-view.cjs} +2 -2
- package/build/fields/parent/{utils.js → utils.cjs} +1 -1
- package/build/fields/password/{edit.js → edit.cjs} +1 -3
- package/build/fields/password/{edit.js.map → edit.cjs.map} +2 -2
- package/build/fields/password/{index.js → index.cjs} +2 -2
- package/build/fields/pattern-title/{index.js → index.cjs} +3 -3
- package/build/fields/pattern-title/{view.js → view.cjs} +3 -3
- package/build/fields/ping-status/{index.js → index.cjs} +1 -2
- package/build/fields/ping-status/index.cjs.map +7 -0
- package/build/fields/slug/{index.js → index.cjs} +3 -3
- package/build/fields/slug/{slug-edit.js → slug-edit.cjs} +2 -2
- package/build/fields/slug/{slug-view.js → slug-view.cjs} +2 -2
- package/build/fields/slug/{utils.js → utils.cjs} +2 -2
- package/build/fields/status/{index.js → index.cjs} +3 -3
- package/build/fields/status/{status-elements.js → status-elements.cjs} +1 -1
- package/build/fields/status/{status-view.js → status-view.cjs} +2 -2
- package/build/fields/template/{index.js → index.cjs} +2 -2
- package/build/fields/template/{template-edit.js → template-edit.cjs} +3 -3
- package/build/fields/template-title/{index.js → index.cjs} +3 -3
- package/build/fields/title/{index.js → index.cjs} +3 -3
- package/build/fields/title/{view.js → view.cjs} +2 -2
- package/build/{index.js → index.cjs} +10 -7
- package/build/index.cjs.map +7 -0
- package/build/{lock-unlock.js → lock-unlock.cjs} +1 -1
- package/build/mutation/{index.js → index.cjs} +1 -1
- package/build/{types.js → types.cjs} +1 -1
- package/build/types.cjs.map +7 -0
- package/build-module/actions/{delete-post.js → delete-post.mjs} +4 -4
- package/build-module/actions/{duplicate-pattern.js → duplicate-pattern.mjs} +2 -2
- package/build-module/actions/{duplicate-post.js → duplicate-post.mjs} +2 -2
- package/build-module/actions/{duplicate-template-part.js → duplicate-template-part.mjs} +3 -3
- package/build-module/actions/{export-pattern.js → export-pattern.mjs} +2 -2
- package/build-module/actions/index.mjs +30 -0
- package/build-module/actions/{permanently-delete-post.js → permanently-delete-post.mjs} +2 -2
- package/build-module/actions/{rename-post.js → rename-post.mjs} +3 -4
- package/build-module/actions/{rename-post.js.map → rename-post.mjs.map} +2 -2
- package/build-module/actions/{reorder-page.js → reorder-page.mjs} +2 -2
- package/build-module/actions/reorder-page.mjs.map +7 -0
- package/build-module/actions/{reset-post.js → reset-post.mjs} +2 -2
- package/build-module/actions/{restore-post.js → restore-post.mjs} +2 -2
- package/build-module/actions/{trash-post.js → trash-post.mjs} +2 -2
- package/build-module/actions/{utils.js → utils.mjs} +1 -1
- package/build-module/actions/{view-post-revisions.js → view-post-revisions.mjs} +1 -1
- package/build-module/actions/{view-post.js → view-post.mjs} +1 -1
- package/build-module/components/create-template-part-modal/{index.js → index.mjs} +3 -4
- package/build-module/components/create-template-part-modal/index.mjs.map +7 -0
- package/build-module/components/create-template-part-modal/{utils.js → utils.mjs} +1 -1
- package/build-module/components/media-edit/index.mjs +478 -0
- package/build-module/components/media-edit/index.mjs.map +7 -0
- package/build-module/fields/author/{author-view.js → author-view.mjs} +1 -1
- package/build-module/fields/author/{index.js → index.mjs} +2 -2
- package/build-module/fields/comment-status/{index.js → index.mjs} +1 -1
- package/build-module/fields/date/{date-view.js → date-view.mjs} +1 -1
- package/build-module/fields/date/{index.js → index.mjs} +2 -2
- package/build-module/fields/discussion/{index.js → index.mjs} +1 -1
- package/build-module/fields/featured-image/{featured-image-view.js → featured-image-view.mjs} +1 -1
- package/build-module/fields/featured-image/{index.js → index.mjs} +8 -5
- package/build-module/fields/featured-image/index.mjs.map +7 -0
- package/build-module/fields/index.mjs +38 -0
- package/build-module/fields/notes/{index.js → index.mjs} +1 -1
- package/build-module/fields/order/{index.js → index.mjs} +1 -1
- package/build-module/fields/page-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/page-title/{view.js → view.mjs} +3 -3
- package/build-module/fields/parent/{index.js → index.mjs} +3 -3
- package/build-module/fields/parent/{parent-edit.js → parent-edit.mjs} +2 -3
- package/build-module/fields/parent/{parent-edit.js.map → parent-edit.mjs.map} +2 -2
- package/build-module/fields/parent/{parent-view.js → parent-view.mjs} +2 -2
- package/build-module/fields/parent/{utils.js → utils.mjs} +1 -1
- package/build-module/fields/password/{edit.js → edit.mjs} +1 -3
- package/build-module/fields/password/{edit.js.map → edit.mjs.map} +2 -2
- package/build-module/fields/password/{index.js → index.mjs} +2 -2
- package/build-module/fields/pattern-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/pattern-title/{view.js → view.mjs} +3 -3
- package/build-module/fields/ping-status/{index.js → index.mjs} +1 -2
- package/build-module/fields/ping-status/index.mjs.map +7 -0
- package/build-module/fields/slug/{index.js → index.mjs} +3 -3
- package/build-module/fields/slug/{slug-edit.js → slug-edit.mjs} +2 -2
- package/build-module/fields/slug/{slug-view.js → slug-view.mjs} +2 -2
- package/build-module/fields/slug/{utils.js → utils.mjs} +2 -2
- package/build-module/fields/status/{index.js → index.mjs} +3 -3
- package/build-module/fields/status/{status-elements.js → status-elements.mjs} +1 -1
- package/build-module/fields/status/{status-view.js → status-view.mjs} +2 -2
- package/build-module/fields/template/{index.js → index.mjs} +2 -2
- package/build-module/fields/template/{template-edit.js → template-edit.mjs} +3 -3
- package/build-module/fields/template-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/title/{index.js → index.mjs} +3 -3
- package/build-module/fields/title/{view.js → view.mjs} +2 -2
- package/build-module/index.mjs +10 -0
- package/build-module/index.mjs.map +7 -0
- package/build-module/{lock-unlock.js → lock-unlock.mjs} +1 -1
- package/build-module/mutation/{index.js → index.mjs} +1 -1
- package/build-module/types.mjs +1 -0
- package/build-style/style-rtl.css +191 -62
- package/build-style/style.css +191 -62
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/components/media-edit/index.d.ts +42 -0
- package/build-types/components/media-edit/index.d.ts.map +1 -0
- package/build-types/fields/featured-image/index.d.ts +0 -3
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
- package/build-types/fields/password/edit.d.ts.map +1 -1
- package/build-types/fields/ping-status/index.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/types.d.ts +24 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +38 -30
- package/src/actions/rename-post.tsx +0 -1
- package/src/actions/reorder-page.tsx +1 -2
- package/src/components/create-template-part-modal/index.tsx +2 -3
- package/src/components/media-edit/index.tsx +616 -0
- package/src/components/media-edit/style.scss +232 -0
- package/src/fields/featured-image/{index.ts → index.tsx} +5 -2
- package/src/fields/featured-image/style.scss +7 -89
- package/src/fields/parent/parent-edit.tsx +0 -1
- package/src/fields/password/edit.tsx +0 -2
- package/src/fields/ping-status/index.tsx +0 -1
- package/src/index.ts +2 -0
- package/src/style.scss +1 -0
- package/src/types.ts +30 -0
- package/build/actions/reorder-page.js.map +0 -7
- package/build/components/create-template-part-modal/index.js.map +0 -7
- package/build/fields/featured-image/featured-image-edit.js +0 -162
- package/build/fields/featured-image/featured-image-edit.js.map +0 -7
- package/build/fields/featured-image/index.js +0 -39
- package/build/fields/featured-image/index.js.map +0 -7
- package/build/fields/ping-status/index.js.map +0 -7
- package/build/index.js.map +0 -7
- package/build/types.js.map +0 -7
- package/build-module/actions/index.js +0 -30
- package/build-module/actions/reorder-page.js.map +0 -7
- package/build-module/components/create-template-part-modal/index.js.map +0 -7
- package/build-module/fields/featured-image/featured-image-edit.js +0 -140
- package/build-module/fields/featured-image/featured-image-edit.js.map +0 -7
- package/build-module/fields/featured-image/index.js.map +0 -7
- package/build-module/fields/index.js +0 -38
- package/build-module/fields/ping-status/index.js.map +0 -7
- package/build-module/index.js +0 -8
- package/build-module/index.js.map +0 -7
- package/build-module/types.js +0 -1
- package/build-types/fields/featured-image/featured-image-edit.d.ts +0 -7
- package/build-types/fields/featured-image/featured-image-edit.d.ts.map +0 -1
- package/src/fields/featured-image/featured-image-edit.tsx +0 -170
- package/tsconfig.json +0 -31
- package/tsconfig.tsbuildinfo +0 -1
- /package/build/actions/{delete-post.js.map → delete-post.cjs.map} +0 -0
- /package/build/actions/{duplicate-pattern.js.map → duplicate-pattern.cjs.map} +0 -0
- /package/build/actions/{duplicate-post.js.map → duplicate-post.cjs.map} +0 -0
- /package/build/actions/{duplicate-template-part.js.map → duplicate-template-part.cjs.map} +0 -0
- /package/build/actions/{export-pattern.js.map → export-pattern.cjs.map} +0 -0
- /package/build/actions/{index.js.map → index.cjs.map} +0 -0
- /package/build/actions/{permanently-delete-post.js.map → permanently-delete-post.cjs.map} +0 -0
- /package/build/actions/{reset-post.js.map → reset-post.cjs.map} +0 -0
- /package/build/actions/{restore-post.js.map → restore-post.cjs.map} +0 -0
- /package/build/actions/{trash-post.js.map → trash-post.cjs.map} +0 -0
- /package/build/actions/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/actions/{view-post-revisions.js.map → view-post-revisions.cjs.map} +0 -0
- /package/build/actions/{view-post.js.map → view-post.cjs.map} +0 -0
- /package/build/components/create-template-part-modal/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/author/{author-view.js.map → author-view.cjs.map} +0 -0
- /package/build/fields/author/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/comment-status/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/date/{date-view.js.map → date-view.cjs.map} +0 -0
- /package/build/fields/date/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/discussion/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/featured-image/{featured-image-view.js.map → featured-image-view.cjs.map} +0 -0
- /package/build/fields/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/notes/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/order/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/page-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/page-title/{view.js.map → view.cjs.map} +0 -0
- /package/build/fields/parent/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/parent/{parent-view.js.map → parent-view.cjs.map} +0 -0
- /package/build/fields/parent/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/password/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/pattern-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/pattern-title/{view.js.map → view.cjs.map} +0 -0
- /package/build/fields/slug/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/slug/{slug-edit.js.map → slug-edit.cjs.map} +0 -0
- /package/build/fields/slug/{slug-view.js.map → slug-view.cjs.map} +0 -0
- /package/build/fields/slug/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/status/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/status/{status-elements.js.map → status-elements.cjs.map} +0 -0
- /package/build/fields/status/{status-view.js.map → status-view.cjs.map} +0 -0
- /package/build/fields/template/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/template/{template-edit.js.map → template-edit.cjs.map} +0 -0
- /package/build/fields/template-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/title/{view.js.map → view.cjs.map} +0 -0
- /package/build/{lock-unlock.js.map → lock-unlock.cjs.map} +0 -0
- /package/build/mutation/{index.js.map → index.cjs.map} +0 -0
- /package/build-module/actions/{delete-post.js.map → delete-post.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-pattern.js.map → duplicate-pattern.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-post.js.map → duplicate-post.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-template-part.js.map → duplicate-template-part.mjs.map} +0 -0
- /package/build-module/actions/{export-pattern.js.map → export-pattern.mjs.map} +0 -0
- /package/build-module/actions/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/actions/{permanently-delete-post.js.map → permanently-delete-post.mjs.map} +0 -0
- /package/build-module/actions/{reset-post.js.map → reset-post.mjs.map} +0 -0
- /package/build-module/actions/{restore-post.js.map → restore-post.mjs.map} +0 -0
- /package/build-module/actions/{trash-post.js.map → trash-post.mjs.map} +0 -0
- /package/build-module/actions/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/actions/{view-post-revisions.js.map → view-post-revisions.mjs.map} +0 -0
- /package/build-module/actions/{view-post.js.map → view-post.mjs.map} +0 -0
- /package/build-module/components/create-template-part-modal/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/author/{author-view.js.map → author-view.mjs.map} +0 -0
- /package/build-module/fields/author/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/comment-status/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/date/{date-view.js.map → date-view.mjs.map} +0 -0
- /package/build-module/fields/date/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/discussion/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/featured-image/{featured-image-view.js.map → featured-image-view.mjs.map} +0 -0
- /package/build-module/fields/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/notes/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/order/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/page-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/page-title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/fields/parent/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/parent/{parent-view.js.map → parent-view.mjs.map} +0 -0
- /package/build-module/fields/parent/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/password/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/pattern-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/pattern-title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/fields/slug/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/slug/{slug-edit.js.map → slug-edit.mjs.map} +0 -0
- /package/build-module/fields/slug/{slug-view.js.map → slug-view.mjs.map} +0 -0
- /package/build-module/fields/slug/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/status/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/status/{status-elements.js.map → status-elements.mjs.map} +0 -0
- /package/build-module/fields/status/{status-view.js.map → status-view.mjs.map} +0 -0
- /package/build-module/fields/template/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/template/{template-edit.js.map → template-edit.mjs.map} +0 -0
- /package/build-module/fields/template-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/{lock-unlock.js.map → lock-unlock.mjs.map} +0 -0
- /package/build-module/mutation/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/{types.js.map → types.mjs.map} +0 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
Button,
|
|
11
|
+
DropZone,
|
|
12
|
+
Icon,
|
|
13
|
+
Spinner,
|
|
14
|
+
__experimentalText as Text,
|
|
15
|
+
__experimentalTruncate as Truncate,
|
|
16
|
+
__experimentalVStack as VStack,
|
|
17
|
+
BaseControl,
|
|
18
|
+
Tooltip,
|
|
19
|
+
VisuallyHidden,
|
|
20
|
+
} from '@wordpress/components';
|
|
21
|
+
import { isBlobURL, getBlobTypeByURL } from '@wordpress/blob';
|
|
22
|
+
import { store as coreStore, type Attachment } from '@wordpress/core-data';
|
|
23
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
24
|
+
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
25
|
+
import { __ } from '@wordpress/i18n';
|
|
26
|
+
import { archive, audio, video, file, closeSmall } from '@wordpress/icons';
|
|
27
|
+
import {
|
|
28
|
+
MediaUpload,
|
|
29
|
+
uploadMedia,
|
|
30
|
+
privateApis as mediaUtilsPrivateApis,
|
|
31
|
+
} from '@wordpress/media-utils';
|
|
32
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Internal dependencies
|
|
36
|
+
*/
|
|
37
|
+
import { unlock } from '../../lock-unlock';
|
|
38
|
+
import type { MediaEditProps } from '../../types';
|
|
39
|
+
|
|
40
|
+
const { MediaUploadModal } = unlock( mediaUtilsPrivateApis );
|
|
41
|
+
|
|
42
|
+
type BlobItem = {
|
|
43
|
+
id: string;
|
|
44
|
+
source_url: string;
|
|
45
|
+
mime_type: string | undefined;
|
|
46
|
+
alt_text?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Conditional Media component that uses MediaUploadModal when experiment is enabled,
|
|
51
|
+
* otherwise falls back to media-utils MediaUpload.
|
|
52
|
+
*
|
|
53
|
+
* @param root0 Component props.
|
|
54
|
+
* @param root0.render Render prop function that receives { open } object.
|
|
55
|
+
* @param root0.multiple Whether to allow multiple media selections.
|
|
56
|
+
* @return The component.
|
|
57
|
+
*/
|
|
58
|
+
function ConditionalMediaUpload( { render, multiple, ...props }: any ) {
|
|
59
|
+
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
60
|
+
if ( ( window as any ).__experimentalDataViewsMediaModal ) {
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{ render && render( { open: () => setIsModalOpen( true ) } ) }
|
|
64
|
+
{ isModalOpen && (
|
|
65
|
+
<MediaUploadModal
|
|
66
|
+
{ ...props }
|
|
67
|
+
multiple={ multiple }
|
|
68
|
+
isOpen={ isModalOpen }
|
|
69
|
+
onClose={ () => {
|
|
70
|
+
setIsModalOpen( false );
|
|
71
|
+
props.onClose?.();
|
|
72
|
+
} }
|
|
73
|
+
onSelect={ ( media: any ) => {
|
|
74
|
+
setIsModalOpen( false );
|
|
75
|
+
props.onSelect?.( media );
|
|
76
|
+
} }
|
|
77
|
+
/>
|
|
78
|
+
) }
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
// Fallback to media-utils MediaUpload when experiment is disabled.
|
|
83
|
+
return (
|
|
84
|
+
<MediaUpload
|
|
85
|
+
{ ...props }
|
|
86
|
+
render={ render }
|
|
87
|
+
multiple={ multiple ? 'add' : undefined }
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function MediaPickerButton( {
|
|
93
|
+
open,
|
|
94
|
+
children,
|
|
95
|
+
label,
|
|
96
|
+
showTooltip = false,
|
|
97
|
+
onFilesDrop,
|
|
98
|
+
attachment,
|
|
99
|
+
isUploading = false,
|
|
100
|
+
}: {
|
|
101
|
+
open: () => void;
|
|
102
|
+
children: React.ReactNode;
|
|
103
|
+
label: string;
|
|
104
|
+
showTooltip?: boolean;
|
|
105
|
+
onFilesDrop: MediaEditAttachmentsProps[ 'onFilesDrop' ];
|
|
106
|
+
attachment?: MediaEditAttachment;
|
|
107
|
+
isUploading?: boolean;
|
|
108
|
+
} ) {
|
|
109
|
+
const isBlob = attachment && isBlobURL( attachment.source_url );
|
|
110
|
+
const mediaPickerButton = (
|
|
111
|
+
<div
|
|
112
|
+
className="fields__media-edit-picker-button"
|
|
113
|
+
role="button"
|
|
114
|
+
tabIndex={ 0 }
|
|
115
|
+
onClick={ () => {
|
|
116
|
+
if ( ! isUploading ) {
|
|
117
|
+
open();
|
|
118
|
+
}
|
|
119
|
+
} }
|
|
120
|
+
onKeyDown={ ( event ) => {
|
|
121
|
+
if ( isUploading ) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if ( event.key === 'Enter' || event.key === ' ' ) {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
open();
|
|
127
|
+
}
|
|
128
|
+
} }
|
|
129
|
+
aria-label={ label }
|
|
130
|
+
aria-disabled={ isUploading }
|
|
131
|
+
>
|
|
132
|
+
{ children }
|
|
133
|
+
{ isBlob && (
|
|
134
|
+
<span className="fields__media-edit-picker-button-spinner">
|
|
135
|
+
<Spinner />
|
|
136
|
+
</span>
|
|
137
|
+
) }
|
|
138
|
+
{ ! isUploading && (
|
|
139
|
+
<DropZone
|
|
140
|
+
onFilesDrop={ ( files ) =>
|
|
141
|
+
onFilesDrop( files, attachment?.id as number )
|
|
142
|
+
}
|
|
143
|
+
/>
|
|
144
|
+
) }
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
if ( ! showTooltip ) {
|
|
148
|
+
return mediaPickerButton;
|
|
149
|
+
}
|
|
150
|
+
return <Tooltip text={ label }>{ mediaPickerButton }</Tooltip>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const archiveMimeTypes = [
|
|
154
|
+
'application/zip',
|
|
155
|
+
'application/x-zip-compressed',
|
|
156
|
+
'application/x-rar-compressed',
|
|
157
|
+
'application/x-7z-compressed',
|
|
158
|
+
'application/x-tar',
|
|
159
|
+
'application/x-gzip',
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
function MediaTitle( { attachment }: { attachment: Attachment< 'view' > } ) {
|
|
163
|
+
return (
|
|
164
|
+
<Truncate className="fields__media-edit-filename">
|
|
165
|
+
{ attachment.title.rendered }
|
|
166
|
+
</Truncate>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function MediaEditPlaceholder( props: {
|
|
171
|
+
open: () => void;
|
|
172
|
+
label: string;
|
|
173
|
+
onFilesDrop: MediaEditAttachmentsProps[ 'onFilesDrop' ];
|
|
174
|
+
isUploading: boolean;
|
|
175
|
+
} ) {
|
|
176
|
+
return (
|
|
177
|
+
<MediaPickerButton { ...props }>
|
|
178
|
+
<span className="fields__media-edit-placeholder">
|
|
179
|
+
{ props.label }
|
|
180
|
+
</span>
|
|
181
|
+
</MediaPickerButton>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function MediaPreview( { attachment }: { attachment: MediaEditAttachment } ) {
|
|
186
|
+
const url = attachment.source_url;
|
|
187
|
+
const mimeType = attachment.mime_type || '';
|
|
188
|
+
if ( mimeType.startsWith( 'image' ) ) {
|
|
189
|
+
return (
|
|
190
|
+
<img
|
|
191
|
+
className="fields__media-edit-thumbnail"
|
|
192
|
+
alt={ attachment.alt_text || '' }
|
|
193
|
+
src={ url }
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
196
|
+
} else if ( mimeType.startsWith( 'audio' ) ) {
|
|
197
|
+
return <Icon icon={ audio } />;
|
|
198
|
+
} else if ( mimeType.startsWith( 'video' ) ) {
|
|
199
|
+
return <Icon icon={ video } />;
|
|
200
|
+
} else if ( archiveMimeTypes.includes( mimeType ) ) {
|
|
201
|
+
return <Icon icon={ archive } />;
|
|
202
|
+
}
|
|
203
|
+
return <Icon icon={ file } />;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
type MediaEditAttachment = Attachment< 'view' > | BlobItem;
|
|
207
|
+
interface MediaEditAttachmentsProps {
|
|
208
|
+
allItems: Array< MediaEditAttachment > | null;
|
|
209
|
+
addButtonLabel: string;
|
|
210
|
+
multiple?: boolean;
|
|
211
|
+
removeItem: ( itemId: number ) => void;
|
|
212
|
+
open: () => void;
|
|
213
|
+
onFilesDrop: ( files: File[], attachmentId?: number ) => void;
|
|
214
|
+
isUploading: boolean;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function ExpandedMediaEditAttachments( {
|
|
218
|
+
allItems,
|
|
219
|
+
addButtonLabel,
|
|
220
|
+
multiple,
|
|
221
|
+
removeItem,
|
|
222
|
+
open,
|
|
223
|
+
onFilesDrop,
|
|
224
|
+
isUploading,
|
|
225
|
+
}: MediaEditAttachmentsProps ) {
|
|
226
|
+
return (
|
|
227
|
+
<div
|
|
228
|
+
className={ clsx( 'fields__media-edit-expanded', {
|
|
229
|
+
'is-multiple': multiple,
|
|
230
|
+
'is-single': ! multiple,
|
|
231
|
+
'is-empty': ! allItems?.length,
|
|
232
|
+
} ) }
|
|
233
|
+
>
|
|
234
|
+
{ allItems?.map( ( attachment ) => {
|
|
235
|
+
const hasPreviewImage =
|
|
236
|
+
attachment.mime_type?.startsWith( 'image' );
|
|
237
|
+
const isBlob = isBlobURL( attachment.source_url );
|
|
238
|
+
return (
|
|
239
|
+
<div
|
|
240
|
+
key={ attachment.id }
|
|
241
|
+
className={ clsx( 'fields__media-edit-expanded-item', {
|
|
242
|
+
'has-preview-image': hasPreviewImage,
|
|
243
|
+
} ) }
|
|
244
|
+
>
|
|
245
|
+
<MediaPickerButton
|
|
246
|
+
open={ open }
|
|
247
|
+
label={ __( 'Replace' ) }
|
|
248
|
+
showTooltip
|
|
249
|
+
onFilesDrop={ onFilesDrop }
|
|
250
|
+
attachment={ attachment }
|
|
251
|
+
isUploading={ isUploading }
|
|
252
|
+
>
|
|
253
|
+
<div className="fields__media-edit-expanded-preview">
|
|
254
|
+
<VStack
|
|
255
|
+
spacing={ 0 }
|
|
256
|
+
alignment="center"
|
|
257
|
+
justify="center"
|
|
258
|
+
className="fields__media-edit-expanded-preview-stack"
|
|
259
|
+
>
|
|
260
|
+
{ ( ! isBlob || hasPreviewImage ) && (
|
|
261
|
+
<MediaPreview
|
|
262
|
+
attachment={ attachment }
|
|
263
|
+
/>
|
|
264
|
+
) }
|
|
265
|
+
{ ! isBlob &&
|
|
266
|
+
( ! hasPreviewImage ? (
|
|
267
|
+
<MediaTitle
|
|
268
|
+
attachment={
|
|
269
|
+
attachment as Attachment< 'view' >
|
|
270
|
+
}
|
|
271
|
+
/>
|
|
272
|
+
) : (
|
|
273
|
+
<div className="fields__media-edit-expanded-overlay">
|
|
274
|
+
<div className="fields__media-edit-expanded-title">
|
|
275
|
+
<MediaTitle
|
|
276
|
+
attachment={
|
|
277
|
+
attachment as Attachment< 'view' >
|
|
278
|
+
}
|
|
279
|
+
/>
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
) ) }
|
|
283
|
+
</VStack>
|
|
284
|
+
</div>
|
|
285
|
+
</MediaPickerButton>
|
|
286
|
+
{ ! isBlob && (
|
|
287
|
+
<div className="fields__media-edit-expanded-overlay">
|
|
288
|
+
<Button
|
|
289
|
+
__next40pxDefaultSize
|
|
290
|
+
className="fields__media-edit-expanded-remove"
|
|
291
|
+
icon={ closeSmall }
|
|
292
|
+
label={ __( 'Remove' ) }
|
|
293
|
+
size="small"
|
|
294
|
+
disabled={ isUploading }
|
|
295
|
+
accessibleWhenDisabled
|
|
296
|
+
onClick={ (
|
|
297
|
+
event: React.MouseEvent< HTMLButtonElement >
|
|
298
|
+
) => {
|
|
299
|
+
event.stopPropagation();
|
|
300
|
+
removeItem( attachment.id as number );
|
|
301
|
+
} }
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
) }
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
} ) }
|
|
308
|
+
{ ( multiple || ! allItems?.length ) && (
|
|
309
|
+
<MediaEditPlaceholder
|
|
310
|
+
open={ open }
|
|
311
|
+
label={ addButtonLabel }
|
|
312
|
+
onFilesDrop={ onFilesDrop }
|
|
313
|
+
isUploading={ isUploading }
|
|
314
|
+
/>
|
|
315
|
+
) }
|
|
316
|
+
</div>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function CompactMediaEditAttachments( {
|
|
321
|
+
allItems,
|
|
322
|
+
addButtonLabel,
|
|
323
|
+
multiple,
|
|
324
|
+
removeItem,
|
|
325
|
+
open,
|
|
326
|
+
onFilesDrop,
|
|
327
|
+
isUploading,
|
|
328
|
+
}: MediaEditAttachmentsProps ) {
|
|
329
|
+
return (
|
|
330
|
+
<>
|
|
331
|
+
{ !! allItems?.length && (
|
|
332
|
+
<VStack spacing={ 2 }>
|
|
333
|
+
{ allItems.map( ( attachment ) => {
|
|
334
|
+
const isBlob = isBlobURL( attachment.source_url );
|
|
335
|
+
return (
|
|
336
|
+
<div
|
|
337
|
+
key={ attachment.id }
|
|
338
|
+
className="fields__media-edit-compact"
|
|
339
|
+
>
|
|
340
|
+
<MediaPickerButton
|
|
341
|
+
open={ open }
|
|
342
|
+
label={ __( 'Replace' ) }
|
|
343
|
+
showTooltip
|
|
344
|
+
onFilesDrop={ onFilesDrop }
|
|
345
|
+
attachment={ attachment }
|
|
346
|
+
isUploading={ isUploading }
|
|
347
|
+
>
|
|
348
|
+
<>
|
|
349
|
+
<MediaPreview
|
|
350
|
+
attachment={ attachment }
|
|
351
|
+
/>
|
|
352
|
+
{ ! isBlob && (
|
|
353
|
+
<MediaTitle
|
|
354
|
+
attachment={
|
|
355
|
+
attachment as Attachment< 'view' >
|
|
356
|
+
}
|
|
357
|
+
/>
|
|
358
|
+
) }
|
|
359
|
+
</>
|
|
360
|
+
</MediaPickerButton>
|
|
361
|
+
<Button
|
|
362
|
+
__next40pxDefaultSize
|
|
363
|
+
className="fields__media-edit-remove"
|
|
364
|
+
text={ __( 'Remove' ) }
|
|
365
|
+
variant="secondary"
|
|
366
|
+
disabled={ isUploading }
|
|
367
|
+
accessibleWhenDisabled
|
|
368
|
+
onClick={ (
|
|
369
|
+
event: React.MouseEvent< HTMLButtonElement >
|
|
370
|
+
) => {
|
|
371
|
+
event.stopPropagation();
|
|
372
|
+
if (
|
|
373
|
+
typeof attachment.id === 'number'
|
|
374
|
+
) {
|
|
375
|
+
removeItem( attachment.id );
|
|
376
|
+
}
|
|
377
|
+
} }
|
|
378
|
+
/>
|
|
379
|
+
</div>
|
|
380
|
+
);
|
|
381
|
+
} ) }
|
|
382
|
+
</VStack>
|
|
383
|
+
) }
|
|
384
|
+
{ ( multiple || ! allItems?.length ) && (
|
|
385
|
+
<MediaEditPlaceholder
|
|
386
|
+
open={ open }
|
|
387
|
+
label={ addButtonLabel }
|
|
388
|
+
onFilesDrop={ onFilesDrop }
|
|
389
|
+
isUploading={ isUploading }
|
|
390
|
+
/>
|
|
391
|
+
) }
|
|
392
|
+
</>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* A media edit control component that provides a media picker UI with upload functionality
|
|
398
|
+
* for selecting WordPress media attachments. Supports both the traditional WordPress media
|
|
399
|
+
* library and the experimental DataViews media modal.
|
|
400
|
+
*
|
|
401
|
+
* This component is intended to be used as the `Edit` property of a field definition when
|
|
402
|
+
* registering fields with `registerEntityField` from `@wordpress/editor`.
|
|
403
|
+
*
|
|
404
|
+
* @template Item - The type of the item being edited.
|
|
405
|
+
*
|
|
406
|
+
* @param {MediaEditProps<Item>} props - The component props.
|
|
407
|
+
* @param {Item} props.data - The item being edited.
|
|
408
|
+
* @param {Object} props.field - The field configuration with getValue and setValue methods.
|
|
409
|
+
* @param {Function} props.onChange - Callback function when the media selection changes.
|
|
410
|
+
* @param {string[]} [props.allowedTypes] - Array of allowed media types. Default `['image']`.
|
|
411
|
+
* @param {boolean} [props.multiple] - Whether to allow multiple media selections. Default `false`.
|
|
412
|
+
* @param {boolean} [props.hideLabelFromVision] - Whether the label should be hidden from vision.
|
|
413
|
+
* @param {boolean} [props.isExpanded] - Whether to render in an expanded form. Default `false`.
|
|
414
|
+
*
|
|
415
|
+
* @return {JSX.Element} The media edit control component.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```tsx
|
|
419
|
+
* import { MediaEdit } from '@wordpress/fields';
|
|
420
|
+
* import type { DataFormControlProps } from '@wordpress/dataviews';
|
|
421
|
+
*
|
|
422
|
+
* const featuredImageField = {
|
|
423
|
+
* id: 'featured_media',
|
|
424
|
+
* type: 'media',
|
|
425
|
+
* label: 'Featured Image',
|
|
426
|
+
* Edit: (props: DataFormControlProps<MyPostType>) => (
|
|
427
|
+
* <MediaEdit
|
|
428
|
+
* {...props}
|
|
429
|
+
* allowedTypes={['image']}
|
|
430
|
+
* />
|
|
431
|
+
* ),
|
|
432
|
+
* };
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
export default function MediaEdit< Item >( {
|
|
436
|
+
data,
|
|
437
|
+
field,
|
|
438
|
+
onChange,
|
|
439
|
+
hideLabelFromVision,
|
|
440
|
+
allowedTypes = [ 'image' ],
|
|
441
|
+
multiple,
|
|
442
|
+
isExpanded,
|
|
443
|
+
}: MediaEditProps< Item > ) {
|
|
444
|
+
const value = field.getValue( { item: data } );
|
|
445
|
+
const attachments = useSelect(
|
|
446
|
+
( select ) => {
|
|
447
|
+
if ( ! value ) {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
const normalizedValue = Array.isArray( value ) ? value : [ value ];
|
|
451
|
+
const { getEntityRecords } = select( coreStore );
|
|
452
|
+
return getEntityRecords( 'postType', 'attachment', {
|
|
453
|
+
include: normalizedValue,
|
|
454
|
+
} ) as Attachment< 'view' >[] | null;
|
|
455
|
+
},
|
|
456
|
+
[ value ]
|
|
457
|
+
);
|
|
458
|
+
const { createErrorNotice } = useDispatch( noticesStore );
|
|
459
|
+
// Support one upload action at a time for now.
|
|
460
|
+
const [ replacementId, setReplacementId ] = useState< number >();
|
|
461
|
+
const [ blobs, setBlobs ] = useState< string[] >( [] );
|
|
462
|
+
const onChangeControl = useCallback(
|
|
463
|
+
( newValue: number | number[] | undefined ) =>
|
|
464
|
+
onChange( field.setValue( { item: data, value: newValue } ) ),
|
|
465
|
+
[ data, field, onChange ]
|
|
466
|
+
);
|
|
467
|
+
const removeItem = ( itemId: number ) => {
|
|
468
|
+
const currentIds = Array.isArray( value ) ? value : [ value ];
|
|
469
|
+
const newIds = currentIds.filter( ( id ) => id !== itemId );
|
|
470
|
+
onChangeControl( newIds.length ? newIds : undefined );
|
|
471
|
+
};
|
|
472
|
+
const onFilesDrop = useCallback(
|
|
473
|
+
( files: File[], _replacementId?: number ) => {
|
|
474
|
+
uploadMedia( {
|
|
475
|
+
allowedTypes: allowedTypes?.length ? allowedTypes : undefined,
|
|
476
|
+
filesList: files,
|
|
477
|
+
onFileChange( uploadedMedia: any[] ) {
|
|
478
|
+
setReplacementId( _replacementId );
|
|
479
|
+
const { blobItems, uploadedItems } = uploadedMedia.reduce(
|
|
480
|
+
( accumulator, item ) => {
|
|
481
|
+
if ( isBlobURL( item.url ) ) {
|
|
482
|
+
accumulator.blobItems.push( item.url );
|
|
483
|
+
} else {
|
|
484
|
+
accumulator.uploadedItems.push( item.id );
|
|
485
|
+
}
|
|
486
|
+
return accumulator;
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
blobItems: [] as string[],
|
|
490
|
+
uploadedItems: [] as number[],
|
|
491
|
+
}
|
|
492
|
+
);
|
|
493
|
+
setBlobs( blobItems );
|
|
494
|
+
// If all uploads are complete reset the replacementId.
|
|
495
|
+
if ( uploadedItems.length === uploadedMedia.length ) {
|
|
496
|
+
setReplacementId( undefined );
|
|
497
|
+
}
|
|
498
|
+
if ( ! uploadedItems.length ) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if ( ! multiple ) {
|
|
502
|
+
onChangeControl( uploadedItems[ 0 ] );
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if ( ! value ) {
|
|
506
|
+
onChangeControl( uploadedItems );
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const normalizedValue = Array.isArray( value )
|
|
510
|
+
? value
|
|
511
|
+
: [ value ];
|
|
512
|
+
const newIds = [
|
|
513
|
+
...( _replacementId
|
|
514
|
+
? normalizedValue.filter(
|
|
515
|
+
( id: any ) => id !== _replacementId
|
|
516
|
+
)
|
|
517
|
+
: normalizedValue ),
|
|
518
|
+
...uploadedItems,
|
|
519
|
+
];
|
|
520
|
+
onChangeControl( newIds );
|
|
521
|
+
},
|
|
522
|
+
onError( error: Error ) {
|
|
523
|
+
setReplacementId( undefined );
|
|
524
|
+
setBlobs( [] );
|
|
525
|
+
createErrorNotice( error.message, { type: 'snackbar' } );
|
|
526
|
+
},
|
|
527
|
+
multiple: !! multiple,
|
|
528
|
+
} );
|
|
529
|
+
},
|
|
530
|
+
[ allowedTypes, value, multiple, createErrorNotice, onChangeControl ]
|
|
531
|
+
);
|
|
532
|
+
const addButtonLabel =
|
|
533
|
+
field.placeholder ||
|
|
534
|
+
( multiple ? __( 'Choose files' ) : __( 'Choose file' ) );
|
|
535
|
+
// Merge real attachments with any existing blob items that are being uploaded.
|
|
536
|
+
const allItems: Array< MediaEditAttachment > | null = useMemo( () => {
|
|
537
|
+
if ( ! blobs.length ) {
|
|
538
|
+
return attachments;
|
|
539
|
+
}
|
|
540
|
+
const items: Array< MediaEditAttachment > = [
|
|
541
|
+
...( attachments || [] ),
|
|
542
|
+
];
|
|
543
|
+
const blobItems = blobs.map( ( url ) => ( {
|
|
544
|
+
id: url,
|
|
545
|
+
source_url: url,
|
|
546
|
+
mime_type: getBlobTypeByURL( url ),
|
|
547
|
+
} ) );
|
|
548
|
+
const replacementIndex = items.findIndex(
|
|
549
|
+
( a ) => a.id === replacementId
|
|
550
|
+
);
|
|
551
|
+
// Place blobs at the replacement index, when files
|
|
552
|
+
// dropped in existing media item.
|
|
553
|
+
if ( replacementIndex !== -1 ) {
|
|
554
|
+
return [
|
|
555
|
+
...items.slice( 0, replacementIndex ),
|
|
556
|
+
...blobItems,
|
|
557
|
+
...items.slice( replacementIndex + 1 ),
|
|
558
|
+
];
|
|
559
|
+
}
|
|
560
|
+
items.push( ...blobItems );
|
|
561
|
+
return items;
|
|
562
|
+
}, [ attachments, replacementId, blobs ] );
|
|
563
|
+
return (
|
|
564
|
+
<fieldset className="fields__media-edit" data-field-id={ field.id }>
|
|
565
|
+
<ConditionalMediaUpload
|
|
566
|
+
onSelect={ ( selectedMedia: any ) => {
|
|
567
|
+
if ( multiple ) {
|
|
568
|
+
const newIds = Array.isArray( selectedMedia )
|
|
569
|
+
? selectedMedia.map( ( m: any ) => m.id )
|
|
570
|
+
: [ selectedMedia.id ];
|
|
571
|
+
onChangeControl( newIds );
|
|
572
|
+
} else {
|
|
573
|
+
onChangeControl( selectedMedia.id );
|
|
574
|
+
}
|
|
575
|
+
} }
|
|
576
|
+
allowedTypes={ allowedTypes }
|
|
577
|
+
value={ value }
|
|
578
|
+
multiple={ multiple }
|
|
579
|
+
title={ field.label }
|
|
580
|
+
render={ ( { open }: any ) => {
|
|
581
|
+
const AttachmentsComponent = isExpanded
|
|
582
|
+
? ExpandedMediaEditAttachments
|
|
583
|
+
: CompactMediaEditAttachments;
|
|
584
|
+
return (
|
|
585
|
+
<VStack spacing={ 2 }>
|
|
586
|
+
{ field.label &&
|
|
587
|
+
( hideLabelFromVision ? (
|
|
588
|
+
<VisuallyHidden as="legend">
|
|
589
|
+
{ field.label }
|
|
590
|
+
</VisuallyHidden>
|
|
591
|
+
) : (
|
|
592
|
+
<BaseControl.VisualLabel as="legend">
|
|
593
|
+
{ field.label }
|
|
594
|
+
</BaseControl.VisualLabel>
|
|
595
|
+
) ) }
|
|
596
|
+
<AttachmentsComponent
|
|
597
|
+
allItems={ allItems }
|
|
598
|
+
addButtonLabel={ addButtonLabel }
|
|
599
|
+
multiple={ multiple }
|
|
600
|
+
removeItem={ removeItem }
|
|
601
|
+
open={ open }
|
|
602
|
+
onFilesDrop={ onFilesDrop }
|
|
603
|
+
isUploading={ !! blobs.length }
|
|
604
|
+
/>
|
|
605
|
+
{ field.description && (
|
|
606
|
+
<Text variant="muted">
|
|
607
|
+
{ field.description }
|
|
608
|
+
</Text>
|
|
609
|
+
) }
|
|
610
|
+
</VStack>
|
|
611
|
+
);
|
|
612
|
+
} }
|
|
613
|
+
/>
|
|
614
|
+
</fieldset>
|
|
615
|
+
);
|
|
616
|
+
}
|