@wordpress/editor 12.6.0 → 12.7.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 +2 -0
- package/build/components/post-featured-image/index.js +84 -41
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-taxonomies/index.js +7 -1
- package/build/components/post-taxonomies/index.js.map +1 -1
- package/build/components/post-text-editor/index.js +11 -0
- package/build/components/post-text-editor/index.js.map +1 -1
- package/build/components/post-visibility/index.js +132 -167
- package/build/components/post-visibility/index.js.map +1 -1
- package/build/components/post-visibility/label.js +5 -22
- package/build/components/post-visibility/label.js.map +1 -1
- package/build/components/post-visibility/utils.js +14 -13
- package/build/components/post-visibility/utils.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +86 -42
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-taxonomies/index.js +7 -1
- package/build-module/components/post-taxonomies/index.js.map +1 -1
- package/build-module/components/post-text-editor/index.js +12 -1
- package/build-module/components/post-text-editor/index.js.map +1 -1
- package/build-module/components/post-visibility/index.js +132 -166
- package/build-module/components/post-visibility/index.js.map +1 -1
- package/build-module/components/post-visibility/label.js +5 -20
- package/build-module/components/post-visibility/label.js.map +1 -1
- package/build-module/components/post-visibility/utils.js +14 -13
- package/build-module/components/post-visibility/utils.js.map +1 -1
- package/build-style/style-rtl.css +42 -51
- package/build-style/style.css +42 -51
- package/package.json +28 -27
- package/src/components/autosave-monitor/test/index.js +3 -0
- package/src/components/post-featured-image/index.js +102 -69
- package/src/components/post-taxonomies/index.js +3 -1
- package/src/components/post-text-editor/index.js +14 -1
- package/src/components/post-visibility/index.js +130 -150
- package/src/components/post-visibility/label.js +6 -15
- package/src/components/post-visibility/style.scss +25 -20
- package/src/components/post-visibility/utils.js +7 -12
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,8 @@ var _hooks = require("@wordpress/hooks");
|
|
|
17
17
|
|
|
18
18
|
var _components = require("@wordpress/components");
|
|
19
19
|
|
|
20
|
+
var _blob = require("@wordpress/blob");
|
|
21
|
+
|
|
20
22
|
var _compose = require("@wordpress/compose");
|
|
21
23
|
|
|
22
24
|
var _data = require("@wordpress/data");
|
|
@@ -45,6 +47,41 @@ const ALLOWED_MEDIA_TYPES = ['image']; // Used when labels from post type were n
|
|
|
45
47
|
const DEFAULT_FEATURE_IMAGE_LABEL = (0, _i18n.__)('Featured image');
|
|
46
48
|
const DEFAULT_SET_FEATURE_IMAGE_LABEL = (0, _i18n.__)('Set featured image');
|
|
47
49
|
const DEFAULT_REMOVE_FEATURE_IMAGE_LABEL = (0, _i18n.__)('Remove image');
|
|
50
|
+
const instructions = (0, _element.createElement)("p", null, (0, _i18n.__)('To edit the featured image, you need permission to upload media.'));
|
|
51
|
+
|
|
52
|
+
function getMediaDetails(media, postId) {
|
|
53
|
+
if (!media) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const defaultSize = (0, _hooks.applyFilters)('editor.PostFeaturedImage.imageSize', 'large', media.id, postId);
|
|
58
|
+
|
|
59
|
+
if ((0, _lodash.has)(media, ['media_details', 'sizes', defaultSize])) {
|
|
60
|
+
return {
|
|
61
|
+
mediaWidth: media.media_details.sizes[defaultSize].width,
|
|
62
|
+
mediaHeight: media.media_details.sizes[defaultSize].height,
|
|
63
|
+
mediaSourceUrl: media.media_details.sizes[defaultSize].source_url
|
|
64
|
+
};
|
|
65
|
+
} // Use fallbackSize when defaultSize is not available.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const fallbackSize = (0, _hooks.applyFilters)('editor.PostFeaturedImage.imageSize', 'thumbnail', media.id, postId);
|
|
69
|
+
|
|
70
|
+
if ((0, _lodash.has)(media, ['media_details', 'sizes', fallbackSize])) {
|
|
71
|
+
return {
|
|
72
|
+
mediaWidth: media.media_details.sizes[fallbackSize].width,
|
|
73
|
+
mediaHeight: media.media_details.sizes[fallbackSize].height,
|
|
74
|
+
mediaSourceUrl: media.media_details.sizes[fallbackSize].source_url
|
|
75
|
+
};
|
|
76
|
+
} // Use full image size when fallbackSize and defaultSize are not available.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
mediaWidth: media.media_details.width,
|
|
81
|
+
mediaHeight: media.media_details.height,
|
|
82
|
+
mediaSourceUrl: media.source_url
|
|
83
|
+
};
|
|
84
|
+
}
|
|
48
85
|
|
|
49
86
|
function PostFeaturedImage(_ref) {
|
|
50
87
|
var _media$media_details$, _media$media_details$2;
|
|
@@ -53,40 +90,46 @@ function PostFeaturedImage(_ref) {
|
|
|
53
90
|
currentPostId,
|
|
54
91
|
featuredImageId,
|
|
55
92
|
onUpdateImage,
|
|
56
|
-
onDropImage,
|
|
57
93
|
onRemoveImage,
|
|
58
94
|
media,
|
|
59
95
|
postType,
|
|
60
|
-
noticeUI
|
|
96
|
+
noticeUI,
|
|
97
|
+
noticeOperations
|
|
61
98
|
} = _ref;
|
|
99
|
+
const [isLoading, setIsLoading] = (0, _element.useState)(false);
|
|
100
|
+
const mediaUpload = (0, _data.useSelect)(select => {
|
|
101
|
+
return select(_blockEditor.store).getSettings().mediaUpload;
|
|
102
|
+
}, []);
|
|
62
103
|
const postLabel = (0, _lodash.get)(postType, ['labels'], {});
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
const {
|
|
105
|
+
mediaWidth,
|
|
106
|
+
mediaHeight,
|
|
107
|
+
mediaSourceUrl
|
|
108
|
+
} = getMediaDetails(media, currentPostId);
|
|
109
|
+
|
|
110
|
+
function onDropFiles(filesList) {
|
|
111
|
+
mediaUpload({
|
|
112
|
+
allowedTypes: ['image'],
|
|
113
|
+
filesList,
|
|
114
|
+
|
|
115
|
+
onFileChange(_ref2) {
|
|
116
|
+
let [image] = _ref2;
|
|
117
|
+
|
|
118
|
+
if ((0, _blob.isBlobURL)(image === null || image === void 0 ? void 0 : image.url)) {
|
|
119
|
+
setIsLoading(true);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
onUpdateImage(image);
|
|
124
|
+
setIsLoading(false);
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
onError(message) {
|
|
128
|
+
noticeOperations.removeAllNotices();
|
|
129
|
+
noticeOperations.createErrorNotice(message);
|
|
88
130
|
}
|
|
89
|
-
|
|
131
|
+
|
|
132
|
+
});
|
|
90
133
|
}
|
|
91
134
|
|
|
92
135
|
return (0, _element.createElement)(_check.default, null, noticeUI, (0, _element.createElement)("div", {
|
|
@@ -104,10 +147,10 @@ function PostFeaturedImage(_ref) {
|
|
|
104
147
|
unstableFeaturedImageFlow: true,
|
|
105
148
|
allowedTypes: ALLOWED_MEDIA_TYPES,
|
|
106
149
|
modalClass: "editor-post-featured-image__media-modal",
|
|
107
|
-
render:
|
|
150
|
+
render: _ref3 => {
|
|
108
151
|
let {
|
|
109
152
|
open
|
|
110
|
-
} =
|
|
153
|
+
} = _ref3;
|
|
111
154
|
return (0, _element.createElement)("div", {
|
|
112
155
|
className: "editor-post-featured-image__container"
|
|
113
156
|
}, (0, _element.createElement)(_components.Button, {
|
|
@@ -122,27 +165,27 @@ function PostFeaturedImage(_ref) {
|
|
|
122
165
|
}, (0, _element.createElement)("img", {
|
|
123
166
|
src: mediaSourceUrl,
|
|
124
167
|
alt: ""
|
|
125
|
-
})),
|
|
126
|
-
onFilesDrop:
|
|
168
|
+
})), isLoading && (0, _element.createElement)(_components.Spinner, null), !featuredImageId && !isLoading && (postLabel.set_featured_image || DEFAULT_SET_FEATURE_IMAGE_LABEL)), (0, _element.createElement)(_components.DropZone, {
|
|
169
|
+
onFilesDrop: onDropFiles
|
|
127
170
|
}));
|
|
128
171
|
},
|
|
129
172
|
value: featuredImageId
|
|
130
|
-
})), !!featuredImageId &&
|
|
173
|
+
})), !!featuredImageId && (0, _element.createElement)(_blockEditor.MediaUploadCheck, null, media && (0, _element.createElement)(_blockEditor.MediaUpload, {
|
|
131
174
|
title: postLabel.featured_image || DEFAULT_FEATURE_IMAGE_LABEL,
|
|
132
175
|
onSelect: onUpdateImage,
|
|
133
176
|
unstableFeaturedImageFlow: true,
|
|
134
177
|
allowedTypes: ALLOWED_MEDIA_TYPES,
|
|
135
178
|
modalClass: "editor-post-featured-image__media-modal",
|
|
136
|
-
render:
|
|
179
|
+
render: _ref4 => {
|
|
137
180
|
let {
|
|
138
181
|
open
|
|
139
|
-
} =
|
|
182
|
+
} = _ref4;
|
|
140
183
|
return (0, _element.createElement)(_components.Button, {
|
|
141
184
|
onClick: open,
|
|
142
185
|
variant: "secondary"
|
|
143
186
|
}, (0, _i18n.__)('Replace Image'));
|
|
144
187
|
}
|
|
145
|
-
})
|
|
188
|
+
}), (0, _element.createElement)(_components.Button, {
|
|
146
189
|
onClick: onRemoveImage,
|
|
147
190
|
variant: "link",
|
|
148
191
|
isDestructive: true
|
|
@@ -168,13 +211,13 @@ const applyWithSelect = (0, _data.withSelect)(select => {
|
|
|
168
211
|
featuredImageId
|
|
169
212
|
};
|
|
170
213
|
});
|
|
171
|
-
const applyWithDispatch = (0, _data.withDispatch)((dispatch,
|
|
214
|
+
const applyWithDispatch = (0, _data.withDispatch)((dispatch, _ref5, _ref6) => {
|
|
172
215
|
let {
|
|
173
216
|
noticeOperations
|
|
174
|
-
} =
|
|
217
|
+
} = _ref5;
|
|
175
218
|
let {
|
|
176
219
|
select
|
|
177
|
-
} =
|
|
220
|
+
} = _ref6;
|
|
178
221
|
const {
|
|
179
222
|
editPost
|
|
180
223
|
} = dispatch(_store.store);
|
|
@@ -190,8 +233,8 @@ const applyWithDispatch = (0, _data.withDispatch)((dispatch, _ref4, _ref5) => {
|
|
|
190
233
|
allowedTypes: ['image'],
|
|
191
234
|
filesList,
|
|
192
235
|
|
|
193
|
-
onFileChange(
|
|
194
|
-
let [image] =
|
|
236
|
+
onFileChange(_ref7) {
|
|
237
|
+
let [image] = _ref7;
|
|
195
238
|
editPost({
|
|
196
239
|
featured_media: image.id
|
|
197
240
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-featured-image/index.js"],"names":["ALLOWED_MEDIA_TYPES","DEFAULT_FEATURE_IMAGE_LABEL","DEFAULT_SET_FEATURE_IMAGE_LABEL","DEFAULT_REMOVE_FEATURE_IMAGE_LABEL","PostFeaturedImage","currentPostId","featuredImageId","onUpdateImage","onDropImage","onRemoveImage","media","postType","noticeUI","postLabel","instructions","mediaWidth","mediaHeight","mediaSourceUrl","mediaSize","id","media_details","sizes","width","height","source_url","fallbackMediaSize","alt_text","full","file","slug","featured_image","open","set_featured_image","isLoading","remove_featured_image","applyWithSelect","select","getMedia","getPostType","coreStore","getCurrentPostId","getEditedPostAttribute","editorStore","context","applyWithDispatch","dispatch","noticeOperations","editPost","image","featured_media","filesList","blockEditorStore","getSettings","mediaUpload","allowedTypes","onFileChange","onError","message","removeAllNotices","createErrorNotice","withNotices"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,CAAE,OAAF,CAA5B,C,CAEA;;AACA,MAAMC,2BAA2B,GAAG,cAAI,gBAAJ,CAApC;AACA,MAAMC,+BAA+B,GAAG,cAAI,oBAAJ,CAAxC;AACA,MAAMC,kCAAkC,GAAG,cAAI,cAAJ,CAA3C;;AAEA,SAASC,iBAAT,OASI;AAAA;;AAAA,MATwB;AAC3BC,IAAAA,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AAF,CADD;AAEbJ,QAAAA,SAFa;;AAGbK,QAAAA,YAAY,QAAc;AAAA,cAAZ,CAAEP,KAAF,CAAY;AACzBD,UAAAA,QAAQ,CAAE;AAAEE,YAAAA,cAAc,EAAED,KAAK,CAAC7B;AAAxB,WAAF,CAAR;AACA,SALY;;AAMbqC,QAAAA,OAAO,CAAEC,OAAF,EAAY;AAClBX,UAAAA,gBAAgB,CAACY,gBAAjB;AACAZ,UAAAA,gBAAgB,CAACa,iBAAjB,CAAoCF,OAApC;AACA;;AATY,OAFf;AAaA,KAlBK;;AAmBNhD,IAAAA,aAAa,GAAG;AACfsC,MAAAA,QAAQ,CAAE;AAAEE,QAAAA,cAAc,EAAE;AAAlB,OAAF,CAAR;AACA;;AArBK,GAAP;AAuBA,CA1BwB,CAA1B;;eA6Be,sBACdW,uBADc,EAEdzB,eAFc,EAGdS,iBAHc,EAId,6BAAa,0BAAb,CAJc,EAKZxC,iBALY,C","sourcesContent":["/**\n * External dependencies\n */\nimport { has, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { applyFilters } from '@wordpress/hooks';\nimport {\n\tDropZone,\n\tButton,\n\tSpinner,\n\tResponsiveWrapper,\n\twithNotices,\n\twithFilters,\n} from '@wordpress/components';\nimport { compose } from '@wordpress/compose';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport {\n\tMediaUpload,\n\tMediaUploadCheck,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostFeaturedImageCheck from './check';\nimport { store as editorStore } from '../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\n\n// Used when labels from post type were not yet loaded or when they are not present.\nconst DEFAULT_FEATURE_IMAGE_LABEL = __( 'Featured image' );\nconst DEFAULT_SET_FEATURE_IMAGE_LABEL = __( 'Set featured image' );\nconst DEFAULT_REMOVE_FEATURE_IMAGE_LABEL = __( 'Remove image' );\n\nfunction PostFeaturedImage( {\n\tcurrentPostId,\n\tfeaturedImageId,\n\tonUpdateImage,\n\tonDropImage,\n\tonRemoveImage,\n\tmedia,\n\tpostType,\n\tnoticeUI,\n} ) {\n\tconst postLabel = get( postType, [ 'labels' ], {} );\n\tconst instructions = (\n\t\t<p>\n\t\t\t{ __(\n\t\t\t\t'To edit the featured image, you need permission to upload media.'\n\t\t\t) }\n\t\t</p>\n\t);\n\n\tlet mediaWidth, mediaHeight, mediaSourceUrl;\n\tif ( media ) {\n\t\tconst mediaSize = applyFilters(\n\t\t\t'editor.PostFeaturedImage.imageSize',\n\t\t\t'post-thumbnail',\n\t\t\tmedia.id,\n\t\t\tcurrentPostId\n\t\t);\n\t\tif ( has( media, [ 'media_details', 'sizes', mediaSize ] ) ) {\n\t\t\t// Use mediaSize when available.\n\t\t\tmediaWidth = media.media_details.sizes[ mediaSize ].width;\n\t\t\tmediaHeight = media.media_details.sizes[ mediaSize ].height;\n\t\t\tmediaSourceUrl = media.media_details.sizes[ mediaSize ].source_url;\n\t\t} else {\n\t\t\t// Get fallbackMediaSize if mediaSize is not available.\n\t\t\tconst fallbackMediaSize = applyFilters(\n\t\t\t\t'editor.PostFeaturedImage.imageSize',\n\t\t\t\t'thumbnail',\n\t\t\t\tmedia.id,\n\t\t\t\tcurrentPostId\n\t\t\t);\n\t\t\tif (\n\t\t\t\thas( media, [ 'media_details', 'sizes', fallbackMediaSize ] )\n\t\t\t) {\n\t\t\t\t// Use fallbackMediaSize when mediaSize is not available.\n\t\t\t\tmediaWidth =\n\t\t\t\t\tmedia.media_details.sizes[ fallbackMediaSize ].width;\n\t\t\t\tmediaHeight =\n\t\t\t\t\tmedia.media_details.sizes[ fallbackMediaSize ].height;\n\t\t\t\tmediaSourceUrl =\n\t\t\t\t\tmedia.media_details.sizes[ fallbackMediaSize ].source_url;\n\t\t\t} else {\n\t\t\t\t// Use full image size when mediaFallbackSize and mediaSize are not available.\n\t\t\t\tmediaWidth = media.media_details.width;\n\t\t\t\tmediaHeight = media.media_details.height;\n\t\t\t\tmediaSourceUrl = media.source_url;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn (\n\t\t<PostFeaturedImageCheck>\n\t\t\t{ noticeUI }\n\t\t\t<div className=\"editor-post-featured-image\">\n\t\t\t\t{ media && (\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={ `editor-post-featured-image-${ featuredImageId }-describedby` }\n\t\t\t\t\t\tclassName=\"hidden\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image alt text.\n\t\t\t\t\t\t\t\t__( 'Current image: %s' ),\n\t\t\t\t\t\t\t\tmedia.alt_text\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image filename.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'The current image has no alternative text. The file name is: %s'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tmedia.media_details.sizes?.full?.file ||\n\t\t\t\t\t\t\t\t\tmedia.slug\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<MediaUploadCheck fallback={ instructions }>\n\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tpostLabel.featured_image ||\n\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t<div className=\"editor-post-featured-image__container\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? 'editor-post-featured-image__toggle'\n\t\t\t\t\t\t\t\t\t\t\t: 'editor-post-featured-image__preview'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Edit or update the image' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: `editor-post-featured-image-${ featuredImageId }-describedby`\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ !! featuredImageId && media && (\n\t\t\t\t\t\t\t\t\t\t<ResponsiveWrapper\n\t\t\t\t\t\t\t\t\t\t\tnaturalWidth={ mediaWidth }\n\t\t\t\t\t\t\t\t\t\t\tnaturalHeight={ mediaHeight }\n\t\t\t\t\t\t\t\t\t\t\tisInline\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\t\t\tsrc={ mediaSourceUrl }\n\t\t\t\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</ResponsiveWrapper>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ !! featuredImageId && ! media && (\n\t\t\t\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ ! featuredImageId &&\n\t\t\t\t\t\t\t\t\t\t( postLabel.set_featured_image ||\n\t\t\t\t\t\t\t\t\t\t\tDEFAULT_SET_FEATURE_IMAGE_LABEL ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onDropImage } />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tvalue={ featuredImageId }\n\t\t\t\t\t/>\n\t\t\t\t</MediaUploadCheck>\n\t\t\t\t{ !! featuredImageId && media && ! media.isLoading && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\tpostLabel.featured_image ||\n\t\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<Button onClick={ open } variant=\"secondary\">\n\t\t\t\t\t\t\t\t\t{ __( 'Replace Image' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t\t{ !! featuredImageId && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tonClick={ onRemoveImage }\n\t\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\t\tisDestructive\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ postLabel.remove_featured_image ||\n\t\t\t\t\t\t\t\tDEFAULT_REMOVE_FEATURE_IMAGE_LABEL }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</PostFeaturedImageCheck>\n\t);\n}\n\nconst applyWithSelect = withSelect( ( select ) => {\n\tconst { getMedia, getPostType } = select( coreStore );\n\tconst { getCurrentPostId, getEditedPostAttribute } = select( editorStore );\n\tconst featuredImageId = getEditedPostAttribute( 'featured_media' );\n\n\treturn {\n\t\tmedia: featuredImageId\n\t\t\t? getMedia( featuredImageId, { context: 'view' } )\n\t\t\t: null,\n\t\tcurrentPostId: getCurrentPostId(),\n\t\tpostType: getPostType( getEditedPostAttribute( 'type' ) ),\n\t\tfeaturedImageId,\n\t};\n} );\n\nconst applyWithDispatch = withDispatch(\n\t( dispatch, { noticeOperations }, { select } ) => {\n\t\tconst { editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonUpdateImage( image ) {\n\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t},\n\t\t\tonDropImage( filesList ) {\n\t\t\t\tselect( blockEditorStore )\n\t\t\t\t\t.getSettings()\n\t\t\t\t\t.mediaUpload( {\n\t\t\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\t\t\tfilesList,\n\t\t\t\t\t\tonFileChange( [ image ] ) {\n\t\t\t\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError( message ) {\n\t\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t},\n\t\t\tonRemoveImage() {\n\t\t\t\teditPost( { featured_media: 0 } );\n\t\t\t},\n\t\t};\n\t}\n);\n\nexport default compose(\n\twithNotices,\n\tapplyWithSelect,\n\tapplyWithDispatch,\n\twithFilters( 'editor.PostFeaturedImage' )\n)( PostFeaturedImage );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-featured-image/index.js"],"names":["ALLOWED_MEDIA_TYPES","DEFAULT_FEATURE_IMAGE_LABEL","DEFAULT_SET_FEATURE_IMAGE_LABEL","DEFAULT_REMOVE_FEATURE_IMAGE_LABEL","instructions","getMediaDetails","media","postId","defaultSize","id","mediaWidth","media_details","sizes","width","mediaHeight","height","mediaSourceUrl","source_url","fallbackSize","PostFeaturedImage","currentPostId","featuredImageId","onUpdateImage","onRemoveImage","postType","noticeUI","noticeOperations","isLoading","setIsLoading","mediaUpload","select","blockEditorStore","getSettings","postLabel","onDropFiles","filesList","allowedTypes","onFileChange","image","url","onError","message","removeAllNotices","createErrorNotice","alt_text","full","file","slug","featured_image","open","set_featured_image","remove_featured_image","applyWithSelect","getMedia","getPostType","coreStore","getCurrentPostId","getEditedPostAttribute","editorStore","context","applyWithDispatch","dispatch","editPost","featured_media","onDropImage","withNotices"],"mappings":";;;;;;;;;AAmBA;;AAhBA;;AAKA;;AACA;;AACA;;AAQA;;AAEA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AAjCA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,CAAE,OAAF,CAA5B,C,CAEA;;AACA,MAAMC,2BAA2B,GAAG,cAAI,gBAAJ,CAApC;AACA,MAAMC,+BAA+B,GAAG,cAAI,oBAAJ,CAAxC;AACA,MAAMC,kCAAkC,GAAG,cAAI,cAAJ,CAA3C;AAEA,MAAMC,YAAY,GACjB,uCACG,cACD,kEADC,CADH,CADD;;AAQA,SAASC,eAAT,CAA0BC,KAA1B,EAAiCC,MAAjC,EAA0C;AACzC,MAAK,CAAED,KAAP,EAAe;AACd,WAAO,EAAP;AACA;;AAED,QAAME,WAAW,GAAG,yBACnB,oCADmB,EAEnB,OAFmB,EAGnBF,KAAK,CAACG,EAHa,EAInBF,MAJmB,CAApB;;AAMA,MAAK,iBAAKD,KAAL,EAAY,CAAE,eAAF,EAAmB,OAAnB,EAA4BE,WAA5B,CAAZ,CAAL,EAA+D;AAC9D,WAAO;AACNE,MAAAA,UAAU,EAAEJ,KAAK,CAACK,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f;AAMNpC,IAAAA;AANM,GAAP;AAQA,CAbuB,CAAxB;AAeA,MAAMuC,iBAAiB,GAAG,wBACzB,CAAEC,QAAF,mBAAkD;AAAA,MAAtC;AAAEnC,IAAAA;AAAF,GAAsC;AAAA,MAAhB;AAAEI,IAAAA;AAAF,GAAgB;AACjD,QAAM;AAAEgC,IAAAA;AAAF,MAAeD,QAAQ,CAAEH,YAAF,CAA7B;AACA,SAAO;AACNpC,IAAAA,aAAa,CAAEgB,KAAF,EAAU;AACtBwB,MAAAA,QAAQ,CAAE;AAAEC,QAAAA,cAAc,EAAEzB,KAAK,CAAC7B;AAAxB,OAAF,CAAR;AACA,KAHK;;AAINuD,IAAAA,WAAW,CAAE7B,SAAF,EAAc;AACxBL,MAAAA,MAAM,CAAEC,kBAAF,CAAN,CACEC,WADF,GAEEH,WAFF,CAEe;AACbO,QAAAA,YAAY,EAAE,CAAE,OAAF,CADD;AAEbD,QAAAA,SAFa;;AAGbE,QAAAA,YAAY,QAAc;AAAA,cAAZ,CAAEC,KAAF,CAAY;AACzBwB,UAAAA,QAAQ,CAAE;AAAEC,YAAAA,cAAc,EAAEzB,KAAK,CAAC7B;AAAxB,WAAF,CAAR;AACA,SALY;;AAMb+B,QAAAA,OAAO,CAAEC,OAAF,EAAY;AAClBf,UAAAA,gBAAgB,CAACgB,gBAAjB;AACAhB,UAAAA,gBAAgB,CAACiB,iBAAjB,CAAoCF,OAApC;AACA;;AATY,OAFf;AAaA,KAlBK;;AAmBNlB,IAAAA,aAAa,GAAG;AACfuC,MAAAA,QAAQ,CAAE;AAAEC,QAAAA,cAAc,EAAE;AAAlB,OAAF,CAAR;AACA;;AArBK,GAAP;AAuBA,CA1BwB,CAA1B;;eA6Be,sBACdE,uBADc,EAEdb,eAFc,EAGdQ,iBAHc,EAId,6BAAa,0BAAb,CAJc,EAKZzC,iBALY,C","sourcesContent":["/**\n * External dependencies\n */\nimport { has, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { applyFilters } from '@wordpress/hooks';\nimport {\n\tDropZone,\n\tButton,\n\tSpinner,\n\tResponsiveWrapper,\n\twithNotices,\n\twithFilters,\n} from '@wordpress/components';\nimport { isBlobURL } from '@wordpress/blob';\nimport { useState } from '@wordpress/element';\nimport { compose } from '@wordpress/compose';\nimport { useSelect, withDispatch, withSelect } from '@wordpress/data';\nimport {\n\tMediaUpload,\n\tMediaUploadCheck,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostFeaturedImageCheck from './check';\nimport { store as editorStore } from '../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\n\n// Used when labels from post type were not yet loaded or when they are not present.\nconst DEFAULT_FEATURE_IMAGE_LABEL = __( 'Featured image' );\nconst DEFAULT_SET_FEATURE_IMAGE_LABEL = __( 'Set featured image' );\nconst DEFAULT_REMOVE_FEATURE_IMAGE_LABEL = __( 'Remove image' );\n\nconst instructions = (\n\t<p>\n\t\t{ __(\n\t\t\t'To edit the featured image, you need permission to upload media.'\n\t\t) }\n\t</p>\n);\n\nfunction getMediaDetails( media, postId ) {\n\tif ( ! media ) {\n\t\treturn {};\n\t}\n\n\tconst defaultSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'large',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( has( media, [ 'media_details', 'sizes', defaultSize ] ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ defaultSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ defaultSize ].height,\n\t\t\tmediaSourceUrl: media.media_details.sizes[ defaultSize ].source_url,\n\t\t};\n\t}\n\n\t// Use fallbackSize when defaultSize is not available.\n\tconst fallbackSize = applyFilters(\n\t\t'editor.PostFeaturedImage.imageSize',\n\t\t'thumbnail',\n\t\tmedia.id,\n\t\tpostId\n\t);\n\tif ( has( media, [ 'media_details', 'sizes', fallbackSize ] ) ) {\n\t\treturn {\n\t\t\tmediaWidth: media.media_details.sizes[ fallbackSize ].width,\n\t\t\tmediaHeight: media.media_details.sizes[ fallbackSize ].height,\n\t\t\tmediaSourceUrl:\n\t\t\t\tmedia.media_details.sizes[ fallbackSize ].source_url,\n\t\t};\n\t}\n\n\t// Use full image size when fallbackSize and defaultSize are not available.\n\treturn {\n\t\tmediaWidth: media.media_details.width,\n\t\tmediaHeight: media.media_details.height,\n\t\tmediaSourceUrl: media.source_url,\n\t};\n}\n\nfunction PostFeaturedImage( {\n\tcurrentPostId,\n\tfeaturedImageId,\n\tonUpdateImage,\n\tonRemoveImage,\n\tmedia,\n\tpostType,\n\tnoticeUI,\n\tnoticeOperations,\n} ) {\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst postLabel = get( postType, [ 'labels' ], {} );\n\tconst { mediaWidth, mediaHeight, mediaSourceUrl } = getMediaDetails(\n\t\tmedia,\n\t\tcurrentPostId\n\t);\n\n\tfunction onDropFiles( filesList ) {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\tsetIsLoading( true );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonUpdateImage( image );\n\t\t\t\tsetIsLoading( false );\n\t\t\t},\n\t\t\tonError( message ) {\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<PostFeaturedImageCheck>\n\t\t\t{ noticeUI }\n\t\t\t<div className=\"editor-post-featured-image\">\n\t\t\t\t{ media && (\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={ `editor-post-featured-image-${ featuredImageId }-describedby` }\n\t\t\t\t\t\tclassName=\"hidden\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image alt text.\n\t\t\t\t\t\t\t\t__( 'Current image: %s' ),\n\t\t\t\t\t\t\t\tmedia.alt_text\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! media.alt_text &&\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// Translators: %s: The selected image filename.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'The current image has no alternative text. The file name is: %s'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tmedia.media_details.sizes?.full?.file ||\n\t\t\t\t\t\t\t\t\tmedia.slug\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<MediaUploadCheck fallback={ instructions }>\n\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tpostLabel.featured_image ||\n\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t<div className=\"editor-post-featured-image__container\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? 'editor-post-featured-image__toggle'\n\t\t\t\t\t\t\t\t\t\t\t: 'editor-post-featured-image__preview'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Edit or update the image' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t! featuredImageId\n\t\t\t\t\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t\t\t\t\t: `editor-post-featured-image-${ featuredImageId }-describedby`\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ !! featuredImageId && media && (\n\t\t\t\t\t\t\t\t\t\t<ResponsiveWrapper\n\t\t\t\t\t\t\t\t\t\t\tnaturalWidth={ mediaWidth }\n\t\t\t\t\t\t\t\t\t\t\tnaturalHeight={ mediaHeight }\n\t\t\t\t\t\t\t\t\t\t\tisInline\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\t\t\tsrc={ mediaSourceUrl }\n\t\t\t\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</ResponsiveWrapper>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ isLoading && <Spinner /> }\n\t\t\t\t\t\t\t\t\t{ ! featuredImageId &&\n\t\t\t\t\t\t\t\t\t\t! isLoading &&\n\t\t\t\t\t\t\t\t\t\t( postLabel.set_featured_image ||\n\t\t\t\t\t\t\t\t\t\t\tDEFAULT_SET_FEATURE_IMAGE_LABEL ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onDropFiles } />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tvalue={ featuredImageId }\n\t\t\t\t\t/>\n\t\t\t\t</MediaUploadCheck>\n\t\t\t\t{ !! featuredImageId && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t{ media && (\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\t\tpostLabel.featured_image ||\n\t\t\t\t\t\t\t\t\tDEFAULT_FEATURE_IMAGE_LABEL\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelect={ onUpdateImage }\n\t\t\t\t\t\t\t\tunstableFeaturedImageFlow\n\t\t\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\t\t\tmodalClass=\"editor-post-featured-image__media-modal\"\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Replace Image' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tonClick={ onRemoveImage }\n\t\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\t\tisDestructive\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ postLabel.remove_featured_image ||\n\t\t\t\t\t\t\t\tDEFAULT_REMOVE_FEATURE_IMAGE_LABEL }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</PostFeaturedImageCheck>\n\t);\n}\n\nconst applyWithSelect = withSelect( ( select ) => {\n\tconst { getMedia, getPostType } = select( coreStore );\n\tconst { getCurrentPostId, getEditedPostAttribute } = select( editorStore );\n\tconst featuredImageId = getEditedPostAttribute( 'featured_media' );\n\n\treturn {\n\t\tmedia: featuredImageId\n\t\t\t? getMedia( featuredImageId, { context: 'view' } )\n\t\t\t: null,\n\t\tcurrentPostId: getCurrentPostId(),\n\t\tpostType: getPostType( getEditedPostAttribute( 'type' ) ),\n\t\tfeaturedImageId,\n\t};\n} );\n\nconst applyWithDispatch = withDispatch(\n\t( dispatch, { noticeOperations }, { select } ) => {\n\t\tconst { editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonUpdateImage( image ) {\n\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t},\n\t\t\tonDropImage( filesList ) {\n\t\t\t\tselect( blockEditorStore )\n\t\t\t\t\t.getSettings()\n\t\t\t\t\t.mediaUpload( {\n\t\t\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\t\t\tfilesList,\n\t\t\t\t\t\tonFileChange( [ image ] ) {\n\t\t\t\t\t\t\teditPost( { featured_media: image.id } );\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError( message ) {\n\t\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t},\n\t\t\tonRemoveImage() {\n\t\t\t\teditPost( { featured_media: 0 } );\n\t\t\t},\n\t\t};\n\t}\n);\n\nexport default compose(\n\twithNotices,\n\tapplyWithSelect,\n\tapplyWithDispatch,\n\twithFilters( 'editor.PostFeaturedImage' )\n)( PostFeaturedImage );\n"]}
|
|
@@ -42,7 +42,13 @@ function PostTaxonomies(_ref) {
|
|
|
42
42
|
taxonomyWrapper = _lodash.identity
|
|
43
43
|
} = _ref;
|
|
44
44
|
const availableTaxonomies = (0, _lodash.filter)(taxonomies, taxonomy => (0, _lodash.includes)(taxonomy.types, postType));
|
|
45
|
-
const visibleTaxonomies = (0, _lodash.filter)(availableTaxonomies,
|
|
45
|
+
const visibleTaxonomies = (0, _lodash.filter)(availableTaxonomies, // In some circumstances .visibility can end up as undefined so optional chaining operator required.
|
|
46
|
+
// https://github.com/WordPress/gutenberg/issues/40326
|
|
47
|
+
taxonomy => {
|
|
48
|
+
var _taxonomy$visibility;
|
|
49
|
+
|
|
50
|
+
return (_taxonomy$visibility = taxonomy.visibility) === null || _taxonomy$visibility === void 0 ? void 0 : _taxonomy$visibility.show_ui;
|
|
51
|
+
});
|
|
46
52
|
return visibleTaxonomies.map(taxonomy => {
|
|
47
53
|
const TaxonomyComponent = taxonomy.hierarchical ? _hierarchicalTermSelector.default : _flatTermSelector.default;
|
|
48
54
|
return (0, _element.createElement)(_element.Fragment, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/index.js"],"names":["PostTaxonomies","postType","taxonomies","taxonomyWrapper","identity","availableTaxonomies","taxonomy","types","visibleTaxonomies","visibility","show_ui","map","TaxonomyComponent","hierarchical","HierarchicalTermSelector","FlatTermSelector","slug","select","editorStore","getCurrentPostType","coreStore","getTaxonomies","per_page"],"mappings":";;;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAKO,SAASA,cAAT,OAIH;AAAA,MAJ4B;AAC/BC,IAAAA,QAD+B;AAE/BC,IAAAA,UAF+B;AAG/BC,IAAAA,eAAe,GAAGC;AAHa,GAI5B;AACH,QAAMC,mBAAmB,GAAG,oBAAQH,UAAR,EAAsBI,QAAF,IAC/C,sBAAUA,QAAQ,CAACC,KAAnB,EAA0BN,QAA1B,CAD2B,CAA5B;AAGA,QAAMO,iBAAiB,GAAG,oBACzBH,mBADyB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/index.js"],"names":["PostTaxonomies","postType","taxonomies","taxonomyWrapper","identity","availableTaxonomies","taxonomy","types","visibleTaxonomies","visibility","show_ui","map","TaxonomyComponent","hierarchical","HierarchicalTermSelector","FlatTermSelector","slug","select","editorStore","getCurrentPostType","coreStore","getTaxonomies","per_page"],"mappings":";;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\n\n/**\n * WordPress dependencies\n */\nimport { Fragment } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport HierarchicalTermSelector from './hierarchical-term-selector';\nimport FlatTermSelector from './flat-term-selector';\nimport { store as editorStore } from '../../store';\n\nexport function PostTaxonomies( {\n\tpostType,\n\ttaxonomies,\n\ttaxonomyWrapper = identity,\n} ) {\n\tconst availableTaxonomies = filter( taxonomies, ( taxonomy ) =>\n\t\tincludes( taxonomy.types, postType )\n\t);\n\tconst visibleTaxonomies = filter(\n\t\tavailableTaxonomies,\n\t\t// In some circumstances .visibility can end up as undefined so optional chaining operator required.\n\t\t// https://github.com/WordPress/gutenberg/issues/40326\n\t\t( taxonomy ) => taxonomy.visibility?.show_ui\n\t);\n\treturn visibleTaxonomies.map( ( taxonomy ) => {\n\t\tconst TaxonomyComponent = taxonomy.hierarchical\n\t\t\t? HierarchicalTermSelector\n\t\t\t: FlatTermSelector;\n\t\treturn (\n\t\t\t<Fragment key={ `taxonomy-${ taxonomy.slug }` }>\n\t\t\t\t{ taxonomyWrapper(\n\t\t\t\t\t<TaxonomyComponent slug={ taxonomy.slug } />,\n\t\t\t\t\ttaxonomy\n\t\t\t\t) }\n\t\t\t</Fragment>\n\t\t);\n\t} );\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\treturn {\n\t\t\tpostType: select( editorStore ).getCurrentPostType(),\n\t\t\ttaxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t};\n\t} ),\n] )( PostTaxonomies );\n"]}
|
|
@@ -43,6 +43,7 @@ function PostTextEditor() {
|
|
|
43
43
|
const [value, setValue] = (0, _element.useState)(postContent);
|
|
44
44
|
const [isDirty, setIsDirty] = (0, _element.useState)(false);
|
|
45
45
|
const instanceId = (0, _compose.useInstanceId)(PostTextEditor);
|
|
46
|
+
const valueRef = (0, _element.useRef)();
|
|
46
47
|
|
|
47
48
|
if (!isDirty && value !== postContent) {
|
|
48
49
|
setValue(postContent);
|
|
@@ -83,6 +84,16 @@ function PostTextEditor() {
|
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
|
|
87
|
+
(0, _element.useEffect)(() => {
|
|
88
|
+
valueRef.current = value;
|
|
89
|
+
}, [value]); // Ensure changes aren't lost when component unmounts.
|
|
90
|
+
|
|
91
|
+
(0, _element.useEffect)(() => {
|
|
92
|
+
return () => {
|
|
93
|
+
const blocks = (0, _blocks.parse)(valueRef.current);
|
|
94
|
+
resetEditorBlocks(blocks);
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
86
97
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.VisuallyHidden, {
|
|
87
98
|
as: "label",
|
|
88
99
|
htmlFor: `post-content-${instanceId}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","postContent","select","editorStore","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","onChange","event","newValue","target","content","stopEditing","blocks"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,oBAAtB,EADK,EAEnB,EAFmB,CAApB;AAKA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAkC,uBAAaH,YAAb,CAAxC;AAEA,QAAM,CAAEI,KAAF,EAASC,QAAT,IAAsB,uBAAUP,WAAV,CAA5B;AACA,QAAM,CAAEQ,OAAF,EAAWC,UAAX,IAA0B,uBAAU,KAAV,CAAhC;AACA,QAAMC,UAAU,GAAG,4BAAeX,cAAf,CAAnB;;AAEA,MAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","postContent","select","editorStore","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","valueRef","onChange","event","newValue","target","content","stopEditing","blocks","current"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,oBAAtB,EADK,EAEnB,EAFmB,CAApB;AAKA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAkC,uBAAaH,YAAb,CAAxC;AAEA,QAAM,CAAEI,KAAF,EAASC,QAAT,IAAsB,uBAAUP,WAAV,CAA5B;AACA,QAAM,CAAEQ,OAAF,EAAWC,UAAX,IAA0B,uBAAU,KAAV,CAAhC;AACA,QAAMC,UAAU,GAAG,4BAAeX,cAAf,CAAnB;AACA,QAAMY,QAAQ,GAAG,sBAAjB;;AAEA,MAAK,CAAEH,OAAF,IAAaF,KAAK,KAAKN,WAA5B,EAA0C;AACzCO,IAAAA,QAAQ,CAAEP,WAAF,CAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMY,QAAQ,GAAKC,KAAF,IAAa;AAC7B,UAAMC,QAAQ,GAAGD,KAAK,CAACE,MAAN,CAAaT,KAA9B;AACAF,IAAAA,QAAQ,CAAE;AAAEY,MAAAA,OAAO,EAAEF;AAAX,KAAF,CAAR;AACAP,IAAAA,QAAQ,CAAEO,QAAF,CAAR;AACAL,IAAAA,UAAU,CAAE,IAAF,CAAV;AACA,GALD;AAOA;AACD;AACA;AACA;AACA;;;AACC,QAAMQ,WAAW,GAAG,MAAM;AACzB,QAAKT,OAAL,EAAe;AACd,YAAMU,MAAM,GAAG,mBAAOZ,KAAP,CAAf;AACAD,MAAAA,iBAAiB,CAAEa,MAAF,CAAjB;AACAT,MAAAA,UAAU,CAAE,KAAF,CAAV;AACA;AACD,GAND;;AAQA,0BAAW,MAAM;AAChBE,IAAAA,QAAQ,CAACQ,OAAT,GAAmBb,KAAnB;AACA,GAFD,EAEG,CAAEA,KAAF,CAFH,EAhDwC,CAoDxC;;AACA,0BAAW,MAAM;AAChB,WAAO,MAAM;AACZ,YAAMY,MAAM,GAAG,mBAAOP,QAAQ,CAACQ,OAAhB,CAAf;AACAd,MAAAA,iBAAiB,CAAEa,MAAF,CAAjB;AACA,KAHD;AAIA,GALD,EAKG,EALH;AAOA,SACC,qDACC,4BAAC,0BAAD;AACC,IAAA,EAAE,EAAC,OADJ;AAEC,IAAA,OAAO,EAAI,gBAAgBR,UAAY;AAFxC,KAIG,cAAI,mBAAJ,CAJH,CADD,EAOC,4BAAC,8BAAD;AACC,IAAA,YAAY,EAAC,KADd;AAEC,IAAA,GAAG,EAAC,MAFL;AAGC,IAAA,KAAK,EAAGJ,KAHT;AAIC,IAAA,QAAQ,EAAGM,QAJZ;AAKC,IAAA,MAAM,EAAGK,WALV;AAMC,IAAA,SAAS,EAAC,yBANX;AAOC,IAAA,EAAE,EAAI,gBAAgBP,UAAY,EAPnC;AAQC,IAAA,WAAW,EAAG,cAAI,iCAAJ;AARf,IAPD,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst postContent = useSelect(\n\t\t( select ) => select( editorStore ).getEditedPostContent(),\n\t\t[]\n\t);\n\n\tconst { editPost, resetEditorBlocks } = useDispatch( editorStore );\n\n\tconst [ value, setValue ] = useState( postContent );\n\tconst [ isDirty, setIsDirty ] = useState( false );\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst valueRef = useRef();\n\n\tif ( ! isDirty && value !== postContent ) {\n\t\tsetValue( postContent );\n\t}\n\n\t/**\n\t * Handles a textarea change event to notify the onChange prop callback and\n\t * reflect the new value in the component's own state. This marks the start\n\t * of the user's edits, if not already changed, preventing future props\n\t * changes to value from replacing the rendered value. This is expected to\n\t * be followed by a reset to dirty state via `stopEditing`.\n\t *\n\t * @see stopEditing\n\t *\n\t * @param {Event} event Change event.\n\t */\n\tconst onChange = ( event ) => {\n\t\tconst newValue = event.target.value;\n\t\teditPost( { content: newValue } );\n\t\tsetValue( newValue );\n\t\tsetIsDirty( true );\n\t};\n\n\t/**\n\t * Function called when the user has completed their edits, responsible for\n\t * ensuring that changes, if made, are surfaced to the onPersist prop\n\t * callback and resetting dirty state.\n\t */\n\tconst stopEditing = () => {\n\t\tif ( isDirty ) {\n\t\t\tconst blocks = parse( value );\n\t\t\tresetEditorBlocks( blocks );\n\t\t\tsetIsDirty( false );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tvalueRef.current = value;\n\t}, [ value ] );\n\n\t// Ensure changes aren't lost when component unmounts.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tconst blocks = parse( valueRef.current );\n\t\t\tresetEditorBlocks( blocks );\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonBlur={ stopEditing }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
|