@wordpress/editor 12.0.1 → 12.0.5
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/build/components/autocompleters/user.js +1 -1
- package/build/components/autosave-monitor/index.js +7 -1
- package/build/components/autosave-monitor/index.js.map +1 -1
- package/build/components/deprecated.js +6 -4
- package/build/components/deprecated.js.map +1 -1
- package/build/components/deprecated.native.js +26 -26
- package/build/components/document-outline/check.js +5 -4
- package/build/components/document-outline/check.js.map +1 -1
- package/build/components/document-outline/index.js +13 -9
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/document-outline/item.js +25 -22
- package/build/components/document-outline/item.js.map +1 -1
- package/build/components/editor-help/help-detail-navigation-screen.native.js +5 -4
- package/build/components/editor-help/help-detail-navigation-screen.native.js.map +1 -1
- package/build/components/editor-help/help-get-support-button.native.js +5 -4
- package/build/components/editor-help/help-get-support-button.native.js.map +1 -1
- package/build/components/editor-help/help-topic-row.native.js +6 -5
- package/build/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build/components/editor-help/index.native.js +23 -18
- package/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/editor-help/view-sections.native.js +16 -13
- package/build/components/editor-help/view-sections.native.js.map +1 -1
- package/build/components/editor-notices/index.js +5 -4
- package/build/components/editor-notices/index.js.map +1 -1
- package/build/components/entities-saved-states/entity-record-item.js +7 -6
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/entities-saved-states/entity-type-list.js +30 -20
- package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build/components/entities-saved-states/index.js +51 -26
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/error-boundary/index.js +5 -4
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/save-shortcut.js +4 -3
- package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
- package/build/components/index.js +22 -22
- package/build/components/index.native.js +4 -4
- package/build/components/page-attributes/check.js +4 -3
- package/build/components/page-attributes/check.js.map +1 -1
- package/build/components/page-attributes/order.js +5 -4
- package/build/components/page-attributes/order.js.map +1 -1
- package/build/components/page-attributes/parent.js +6 -3
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-author/check.js +4 -3
- package/build/components/post-author/check.js.map +1 -1
- package/build/components/post-author/combobox.js +6 -3
- package/build/components/post-author/combobox.js.map +1 -1
- package/build/components/post-comments/index.js +6 -4
- package/build/components/post-comments/index.js.map +1 -1
- package/build/components/post-excerpt/index.js +5 -4
- package/build/components/post-excerpt/index.js.map +1 -1
- package/build/components/post-featured-image/index.js +51 -41
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-format/check.js +5 -4
- package/build/components/post-format/check.js.map +1 -1
- package/build/components/post-format/index.js +1 -1
- package/build/components/post-last-revision/check.js +7 -5
- package/build/components/post-last-revision/check.js.map +1 -1
- package/build/components/post-last-revision/index.js +5 -4
- package/build/components/post-last-revision/index.js.map +1 -1
- package/build/components/post-pending-status/check.js +7 -5
- package/build/components/post-pending-status/check.js.map +1 -1
- package/build/components/post-pending-status/index.js +6 -4
- package/build/components/post-pending-status/index.js.map +1 -1
- package/build/components/post-pingbacks/index.js +6 -4
- package/build/components/post-pingbacks/index.js.map +1 -1
- package/build/components/post-preview-button/index.js +11 -7
- package/build/components/post-preview-button/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +12 -4
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/label.js +15 -12
- package/build/components/post-publish-button/label.js.map +1 -1
- package/build/components/post-publish-panel/index.js +4 -3
- package/build/components/post-publish-panel/index.js.map +1 -1
- package/build/components/post-publish-panel/maybe-post-format-panel.js +11 -8
- package/build/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
- package/build/components/post-publish-panel/maybe-tags-panel.js +7 -4
- package/build/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
- package/build/components/post-publish-panel/postpublish.js +6 -5
- package/build/components/post-publish-panel/postpublish.js.map +1 -1
- package/build/components/post-publish-panel/prepublish.js +4 -3
- package/build/components/post-publish-panel/prepublish.js.map +1 -1
- package/build/components/post-saved-state/index.js +6 -5
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/check.js +6 -4
- package/build/components/post-schedule/check.js.map +1 -1
- package/build/components/post-schedule/index.js +15 -10
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-schedule/label.js +5 -4
- package/build/components/post-schedule/label.js.map +1 -1
- package/build/components/post-slug/check.js +4 -3
- package/build/components/post-slug/check.js.map +1 -1
- package/build/components/post-slug/index.js +6 -5
- package/build/components/post-slug/index.js.map +1 -1
- package/build/components/post-sticky/check.js +7 -5
- package/build/components/post-sticky/check.js.map +1 -1
- package/build/components/post-sticky/index.js +5 -4
- package/build/components/post-sticky/index.js.map +1 -1
- package/build/components/post-switch-to-draft-button/index.js +7 -6
- package/build/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build/components/post-taxonomies/check.js +6 -5
- package/build/components/post-taxonomies/check.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +155 -211
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js +6 -5
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/index.js +6 -5
- package/build/components/post-taxonomies/index.js.map +1 -1
- package/build/components/post-taxonomies/most-used-terms.js +5 -4
- package/build/components/post-taxonomies/most-used-terms.js.map +1 -1
- package/build/components/post-template/index.js +2 -1
- package/build/components/post-template/index.js.map +1 -1
- package/build/components/post-title/index.js +4 -2
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-title/index.native.js +6 -5
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-trash/check.js +8 -6
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-trash/index.js +8 -6
- package/build/components/post-trash/index.js.map +1 -1
- package/build/components/post-type-support-check/index.js +6 -5
- package/build/components/post-type-support-check/index.js.map +1 -1
- package/build/components/post-visibility/check.js +5 -4
- package/build/components/post-visibility/check.js.map +1 -1
- package/build/components/post-visibility/index.js +28 -24
- package/build/components/post-visibility/index.js.map +1 -1
- package/build/components/post-visibility/label.js +5 -3
- package/build/components/post-visibility/label.js.map +1 -1
- package/build/components/provider/index.js +9 -8
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +17 -11
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +1 -1
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/table-of-contents/index.js +33 -26
- package/build/components/table-of-contents/index.js.map +1 -1
- package/build/components/table-of-contents/panel.js +5 -4
- package/build/components/table-of-contents/panel.js.map +1 -1
- package/build/components/template-validation-notice/index.js +6 -4
- package/build/components/template-validation-notice/index.js.map +1 -1
- package/build/components/theme-support-check/index.js +7 -6
- package/build/components/theme-support-check/index.js.map +1 -1
- package/build/hooks/custom-sources-backwards-compatibility.js +12 -8
- package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build/hooks/default-autocompleters.js +2 -1
- package/build/hooks/default-autocompleters.js.map +1 -1
- package/build/index.js +4 -4
- package/build/store/actions.js +51 -30
- package/build/store/actions.js.map +1 -1
- package/build/store/actions.native.js +3 -2
- package/build/store/actions.native.js.map +1 -1
- package/build/store/constants.js +1 -1
- package/build/store/controls.js +10 -9
- package/build/store/controls.js.map +1 -1
- package/build/store/defaults.js +1 -1
- package/build/store/index.js +5 -3
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +52 -22
- package/build/store/reducer.js.map +1 -1
- package/build/store/reducer.native.js +14 -4
- package/build/store/reducer.native.js.map +1 -1
- package/build/store/selectors.js +56 -37
- package/build/store/selectors.js.map +1 -1
- package/build/store/selectors.native.js +1 -1
- package/build/store/utils/notice-builder.js +1 -1
- package/build/utils/index.js +6 -6
- package/build/utils/media-upload/index.js +15 -11
- package/build/utils/media-upload/index.js.map +1 -1
- package/build/utils/url.js +1 -1
- package/build-module/components/autosave-monitor/index.js +7 -1
- package/build-module/components/autosave-monitor/index.js.map +1 -1
- package/build-module/components/deprecated.js +4 -3
- package/build-module/components/deprecated.js.map +1 -1
- package/build-module/components/document-outline/check.js +5 -4
- package/build-module/components/document-outline/check.js.map +1 -1
- package/build-module/components/document-outline/index.js +13 -9
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/document-outline/item.js +25 -22
- package/build-module/components/document-outline/item.js.map +1 -1
- package/build-module/components/editor-help/help-detail-navigation-screen.native.js +5 -4
- package/build-module/components/editor-help/help-detail-navigation-screen.native.js.map +1 -1
- package/build-module/components/editor-help/help-get-support-button.native.js +5 -4
- package/build-module/components/editor-help/help-get-support-button.native.js.map +1 -1
- package/build-module/components/editor-help/help-topic-row.native.js +6 -5
- package/build-module/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build-module/components/editor-help/index.native.js +23 -19
- package/build-module/components/editor-help/index.native.js.map +1 -1
- package/build-module/components/editor-help/view-sections.native.js +15 -12
- package/build-module/components/editor-help/view-sections.native.js.map +1 -1
- package/build-module/components/editor-notices/index.js +5 -4
- package/build-module/components/editor-notices/index.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js +7 -6
- package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-type-list.js +31 -19
- package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +50 -25
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -4
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/save-shortcut.js +4 -3
- package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
- package/build-module/components/page-attributes/check.js +4 -3
- package/build-module/components/page-attributes/check.js.map +1 -1
- package/build-module/components/page-attributes/order.js +5 -4
- package/build-module/components/page-attributes/order.js.map +1 -1
- package/build-module/components/page-attributes/parent.js +5 -2
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-author/check.js +4 -3
- package/build-module/components/post-author/check.js.map +1 -1
- package/build-module/components/post-author/combobox.js +6 -3
- package/build-module/components/post-author/combobox.js.map +1 -1
- package/build-module/components/post-comments/index.js +6 -4
- package/build-module/components/post-comments/index.js.map +1 -1
- package/build-module/components/post-excerpt/index.js +5 -4
- package/build-module/components/post-excerpt/index.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +51 -41
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-format/check.js +5 -4
- package/build-module/components/post-format/check.js.map +1 -1
- package/build-module/components/post-last-revision/check.js +7 -5
- package/build-module/components/post-last-revision/check.js.map +1 -1
- package/build-module/components/post-last-revision/index.js +5 -4
- package/build-module/components/post-last-revision/index.js.map +1 -1
- package/build-module/components/post-pending-status/check.js +7 -5
- package/build-module/components/post-pending-status/check.js.map +1 -1
- package/build-module/components/post-pending-status/index.js +6 -4
- package/build-module/components/post-pending-status/index.js.map +1 -1
- package/build-module/components/post-pingbacks/index.js +6 -4
- package/build-module/components/post-pingbacks/index.js.map +1 -1
- package/build-module/components/post-preview-button/index.js +11 -7
- package/build-module/components/post-preview-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +12 -4
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/label.js +15 -12
- package/build-module/components/post-publish-button/label.js.map +1 -1
- package/build-module/components/post-publish-panel/index.js +4 -3
- package/build-module/components/post-publish-panel/index.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-post-format-panel.js +11 -8
- package/build-module/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-tags-panel.js +7 -4
- package/build-module/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
- package/build-module/components/post-publish-panel/postpublish.js +6 -5
- package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
- package/build-module/components/post-publish-panel/prepublish.js +4 -3
- package/build-module/components/post-publish-panel/prepublish.js.map +1 -1
- package/build-module/components/post-saved-state/index.js +6 -5
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/check.js +6 -4
- package/build-module/components/post-schedule/check.js.map +1 -1
- package/build-module/components/post-schedule/index.js +15 -10
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-schedule/label.js +6 -4
- package/build-module/components/post-schedule/label.js.map +1 -1
- package/build-module/components/post-slug/check.js +4 -3
- package/build-module/components/post-slug/check.js.map +1 -1
- package/build-module/components/post-slug/index.js +6 -5
- package/build-module/components/post-slug/index.js.map +1 -1
- package/build-module/components/post-sticky/check.js +7 -5
- package/build-module/components/post-sticky/check.js.map +1 -1
- package/build-module/components/post-sticky/index.js +5 -4
- package/build-module/components/post-sticky/index.js.map +1 -1
- package/build-module/components/post-switch-to-draft-button/index.js +7 -6
- package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build-module/components/post-taxonomies/check.js +6 -5
- package/build-module/components/post-taxonomies/check.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +157 -214
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js +4 -3
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/index.js +6 -5
- package/build-module/components/post-taxonomies/index.js.map +1 -1
- package/build-module/components/post-taxonomies/most-used-terms.js +5 -4
- package/build-module/components/post-taxonomies/most-used-terms.js.map +1 -1
- package/build-module/components/post-template/index.js +2 -1
- package/build-module/components/post-template/index.js.map +1 -1
- package/build-module/components/post-title/index.js +4 -2
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/index.native.js +6 -5
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-trash/check.js +8 -6
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-trash/index.js +8 -6
- package/build-module/components/post-trash/index.js.map +1 -1
- package/build-module/components/post-type-support-check/index.js +6 -5
- package/build-module/components/post-type-support-check/index.js.map +1 -1
- package/build-module/components/post-visibility/check.js +5 -4
- package/build-module/components/post-visibility/check.js.map +1 -1
- package/build-module/components/post-visibility/index.js +28 -24
- package/build-module/components/post-visibility/index.js.map +1 -1
- package/build-module/components/post-visibility/label.js +5 -3
- package/build-module/components/post-visibility/label.js.map +1 -1
- package/build-module/components/provider/index.js +9 -8
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +13 -9
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +1 -1
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/table-of-contents/index.js +33 -26
- package/build-module/components/table-of-contents/index.js.map +1 -1
- package/build-module/components/table-of-contents/panel.js +5 -4
- package/build-module/components/table-of-contents/panel.js.map +1 -1
- package/build-module/components/template-validation-notice/index.js +6 -4
- package/build-module/components/template-validation-notice/index.js.map +1 -1
- package/build-module/components/theme-support-check/index.js +7 -6
- package/build-module/components/theme-support-check/index.js.map +1 -1
- package/build-module/hooks/custom-sources-backwards-compatibility.js +12 -8
- package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build-module/hooks/default-autocompleters.js +2 -1
- package/build-module/hooks/default-autocompleters.js.map +1 -1
- package/build-module/store/actions.js +27 -12
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/actions.native.js +2 -1
- package/build-module/store/actions.native.js.map +1 -1
- package/build-module/store/controls.js +8 -7
- package/build-module/store/controls.js.map +1 -1
- package/build-module/store/reducer.js +44 -14
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/reducer.native.js +12 -3
- package/build-module/store/reducer.native.js.map +1 -1
- package/build-module/store/selectors.js +7 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/media-upload/index.js +15 -11
- package/build-module/utils/media-upload/index.js.map +1 -1
- package/package.json +31 -31
- package/src/components/autosave-monitor/index.js +5 -0
- package/src/components/autosave-monitor/test/index.js +10 -4
- package/src/components/editor-help/index.native.js +116 -110
- package/src/components/entities-saved-states/entity-type-list.js +29 -10
- package/src/components/entities-saved-states/index.js +38 -8
- package/src/components/post-taxonomies/flat-term-selector.js +220 -254
- package/src/components/post-title/index.js +4 -2
- package/src/components/provider/use-block-editor-settings.js +0 -2
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
debounce,
|
|
6
|
-
escape as escapeString,
|
|
7
|
-
find,
|
|
8
|
-
get,
|
|
9
|
-
invoke,
|
|
10
|
-
isEmpty,
|
|
11
|
-
uniqBy,
|
|
12
|
-
} from 'lodash';
|
|
4
|
+
import { escape as escapeString, find, get, uniqBy } from 'lodash';
|
|
13
5
|
|
|
14
6
|
/**
|
|
15
7
|
* WordPress dependencies
|
|
16
8
|
*/
|
|
17
9
|
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
withFilters,
|
|
22
|
-
withSpokenMessages,
|
|
23
|
-
} from '@wordpress/components';
|
|
24
|
-
import { withSelect, withDispatch } from '@wordpress/data';
|
|
10
|
+
import { useEffect, useMemo, useState } from '@wordpress/element';
|
|
11
|
+
import { FormTokenField, withFilters } from '@wordpress/components';
|
|
12
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
25
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
26
|
-
import {
|
|
14
|
+
import { useDebounce } from '@wordpress/compose';
|
|
27
15
|
import apiFetch from '@wordpress/api-fetch';
|
|
28
16
|
import { addQueryArgs } from '@wordpress/url';
|
|
17
|
+
import { speak } from '@wordpress/a11y';
|
|
29
18
|
|
|
30
19
|
/**
|
|
31
20
|
* Internal dependencies
|
|
@@ -34,6 +23,14 @@ import { store as editorStore } from '../../store';
|
|
|
34
23
|
import { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';
|
|
35
24
|
import MostUsedTerms from './most-used-terms';
|
|
36
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Shared reference to an empty array for cases where it is important to avoid
|
|
28
|
+
* returning a new array reference on every invocation.
|
|
29
|
+
*
|
|
30
|
+
* @type {Array<any>}
|
|
31
|
+
*/
|
|
32
|
+
const EMPTY_ARRAY = [];
|
|
33
|
+
|
|
37
34
|
/**
|
|
38
35
|
* Module constants
|
|
39
36
|
*/
|
|
@@ -42,7 +39,8 @@ const DEFAULT_QUERY = {
|
|
|
42
39
|
per_page: MAX_TERMS_SUGGESTIONS,
|
|
43
40
|
orderby: 'count',
|
|
44
41
|
order: 'desc',
|
|
45
|
-
_fields: 'id,name
|
|
42
|
+
_fields: 'id,name',
|
|
43
|
+
context: 'view',
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
const isSameTermName = ( termA, termB ) =>
|
|
@@ -56,171 +54,195 @@ const termNamesToIds = ( names, terms ) => {
|
|
|
56
54
|
);
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.onChange = this.onChange.bind( this );
|
|
63
|
-
this.searchTerms = debounce( this.searchTerms.bind( this ), 500 );
|
|
64
|
-
this.findOrCreateTerm = this.findOrCreateTerm.bind( this );
|
|
65
|
-
this.appendTerm = this.appendTerm.bind( this );
|
|
66
|
-
this.state = {
|
|
67
|
-
loading: ! isEmpty( this.props.terms ),
|
|
68
|
-
availableTerms: [],
|
|
69
|
-
selectedTerms: [],
|
|
70
|
-
};
|
|
71
|
-
}
|
|
57
|
+
// Tries to create a term or fetch it if it already exists.
|
|
58
|
+
function findOrCreateTerm( termName, restBase ) {
|
|
59
|
+
const escapedTermName = escapeString( termName );
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
return apiFetch( {
|
|
62
|
+
path: `/wp/v2/${ restBase }`,
|
|
63
|
+
method: 'POST',
|
|
64
|
+
data: { name: escapedTermName },
|
|
65
|
+
} )
|
|
66
|
+
.catch( ( error ) => {
|
|
67
|
+
const errorCode = error.code;
|
|
68
|
+
if ( errorCode === 'term_exists' ) {
|
|
69
|
+
// If the terms exist, fetch it instead of creating a new one.
|
|
70
|
+
const addRequest = apiFetch( {
|
|
71
|
+
path: addQueryArgs( `/wp/v2/${ restBase }`, {
|
|
72
|
+
...DEFAULT_QUERY,
|
|
73
|
+
search: escapedTermName,
|
|
74
|
+
} ),
|
|
75
|
+
} ).then( unescapeTerms );
|
|
76
|
+
|
|
77
|
+
return addRequest.then( ( searchResult ) => {
|
|
78
|
+
return find( searchResult, ( result ) =>
|
|
79
|
+
isSameTermName( result.name, termName )
|
|
80
|
+
);
|
|
81
|
+
} );
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return Promise.reject( error );
|
|
85
|
+
} )
|
|
86
|
+
.then( unescapeTerm );
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function FlatTermSelector( { slug } ) {
|
|
90
|
+
const [ values, setValues ] = useState( [] );
|
|
91
|
+
const [ search, setSearch ] = useState( '' );
|
|
92
|
+
const debouncedSearch = useDebounce( setSearch, 500 );
|
|
93
|
+
|
|
94
|
+
const {
|
|
95
|
+
terms,
|
|
96
|
+
termIds,
|
|
97
|
+
taxonomy,
|
|
98
|
+
hasAssignAction,
|
|
99
|
+
hasCreateAction,
|
|
100
|
+
hasResolvedTerms,
|
|
101
|
+
} = useSelect(
|
|
102
|
+
( select ) => {
|
|
103
|
+
const { getCurrentPost, getEditedPostAttribute } = select(
|
|
104
|
+
editorStore
|
|
91
105
|
);
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
const {
|
|
107
|
+
getEntityRecords,
|
|
108
|
+
getTaxonomy,
|
|
109
|
+
hasFinishedResolution,
|
|
110
|
+
} = select( coreStore );
|
|
111
|
+
const post = getCurrentPost();
|
|
112
|
+
const _taxonomy = getTaxonomy( slug );
|
|
113
|
+
const _termIds = _taxonomy
|
|
114
|
+
? getEditedPostAttribute( _taxonomy.rest_base )
|
|
115
|
+
: EMPTY_ARRAY;
|
|
94
116
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
const query = {
|
|
118
|
+
...DEFAULT_QUERY,
|
|
119
|
+
include: _termIds.join( ',' ),
|
|
120
|
+
per_page: -1,
|
|
121
|
+
};
|
|
99
122
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
return {
|
|
124
|
+
hasCreateAction: _taxonomy
|
|
125
|
+
? get(
|
|
126
|
+
post,
|
|
127
|
+
[
|
|
128
|
+
'_links',
|
|
129
|
+
'wp:action-create-' + _taxonomy.rest_base,
|
|
130
|
+
],
|
|
131
|
+
false
|
|
132
|
+
)
|
|
133
|
+
: false,
|
|
134
|
+
hasAssignAction: _taxonomy
|
|
135
|
+
? get(
|
|
136
|
+
post,
|
|
137
|
+
[
|
|
138
|
+
'_links',
|
|
139
|
+
'wp:action-assign-' + _taxonomy.rest_base,
|
|
140
|
+
],
|
|
141
|
+
false
|
|
142
|
+
)
|
|
143
|
+
: false,
|
|
144
|
+
taxonomy: _taxonomy,
|
|
145
|
+
termIds: _termIds,
|
|
146
|
+
terms: _termIds.length
|
|
147
|
+
? getEntityRecords( 'taxonomy', slug, query )
|
|
148
|
+
: EMPTY_ARRAY,
|
|
149
|
+
hasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [
|
|
150
|
+
'taxonomy',
|
|
151
|
+
slug,
|
|
152
|
+
query,
|
|
153
|
+
] ),
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
[ slug ]
|
|
157
|
+
);
|
|
105
158
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const request = apiFetch( {
|
|
110
|
-
path: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, query ),
|
|
111
|
-
} );
|
|
112
|
-
request.then( unescapeTerms ).then( ( terms ) => {
|
|
113
|
-
this.setState( ( state ) => ( {
|
|
114
|
-
availableTerms: state.availableTerms.concat(
|
|
115
|
-
terms.filter(
|
|
116
|
-
( term ) =>
|
|
117
|
-
! find(
|
|
118
|
-
state.availableTerms,
|
|
119
|
-
( availableTerm ) =>
|
|
120
|
-
availableTerm.id === term.id
|
|
121
|
-
)
|
|
122
|
-
)
|
|
123
|
-
),
|
|
124
|
-
} ) );
|
|
125
|
-
this.updateSelectedTerms( this.props.terms );
|
|
126
|
-
} );
|
|
159
|
+
const { searchResults } = useSelect(
|
|
160
|
+
( select ) => {
|
|
161
|
+
const { getEntityRecords } = select( coreStore );
|
|
127
162
|
|
|
128
|
-
|
|
129
|
-
|
|
163
|
+
return {
|
|
164
|
+
searchResults: !! search
|
|
165
|
+
? getEntityRecords( 'taxonomy', slug, {
|
|
166
|
+
...DEFAULT_QUERY,
|
|
167
|
+
search,
|
|
168
|
+
} )
|
|
169
|
+
: EMPTY_ARRAY,
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
[ search ]
|
|
173
|
+
);
|
|
130
174
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
175
|
+
// Update terms state only after the selectors are resolved.
|
|
176
|
+
// We're using this to avoid terms temporarily disappearing on slow networks
|
|
177
|
+
// while core data makes REST API requests.
|
|
178
|
+
useEffect( () => {
|
|
179
|
+
if ( hasResolvedTerms ) {
|
|
180
|
+
const newValues = terms.map( ( term ) =>
|
|
181
|
+
unescapeString( term.name )
|
|
136
182
|
);
|
|
137
|
-
if ( termObject ) {
|
|
138
|
-
accumulator.push( termObject.name );
|
|
139
|
-
}
|
|
140
183
|
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
184
|
+
setValues( newValues );
|
|
185
|
+
}
|
|
186
|
+
}, [ terms, hasResolvedTerms ] );
|
|
187
|
+
|
|
188
|
+
const suggestions = useMemo( () => {
|
|
189
|
+
return ( searchResults ?? [] ).map( ( term ) =>
|
|
190
|
+
unescapeString( term.name )
|
|
191
|
+
);
|
|
192
|
+
}, [ searchResults ] );
|
|
193
|
+
|
|
194
|
+
const { editPost } = useDispatch( editorStore );
|
|
195
|
+
|
|
196
|
+
if ( ! hasAssignAction ) {
|
|
197
|
+
return null;
|
|
146
198
|
}
|
|
147
199
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const termNameEscaped = escapeString( termName );
|
|
151
|
-
// Tries to create a term or fetch it if it already exists.
|
|
152
|
-
return apiFetch( {
|
|
153
|
-
path: `/wp/v2/${ taxonomy.rest_base }`,
|
|
154
|
-
method: 'POST',
|
|
155
|
-
data: { name: termNameEscaped },
|
|
156
|
-
} )
|
|
157
|
-
.catch( ( error ) => {
|
|
158
|
-
const errorCode = error.code;
|
|
159
|
-
if ( errorCode === 'term_exists' ) {
|
|
160
|
-
// If the terms exist, fetch it instead of creating a new one.
|
|
161
|
-
this.addRequest = apiFetch( {
|
|
162
|
-
path: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, {
|
|
163
|
-
...DEFAULT_QUERY,
|
|
164
|
-
search: termNameEscaped,
|
|
165
|
-
} ),
|
|
166
|
-
} ).then( unescapeTerms );
|
|
167
|
-
return this.addRequest.then( ( searchResult ) => {
|
|
168
|
-
return find( searchResult, ( result ) =>
|
|
169
|
-
isSameTermName( result.name, termName )
|
|
170
|
-
);
|
|
171
|
-
} );
|
|
172
|
-
}
|
|
173
|
-
return Promise.reject( error );
|
|
174
|
-
} )
|
|
175
|
-
.then( unescapeTerm );
|
|
200
|
+
function onUpdateTerms( newTermIds ) {
|
|
201
|
+
editPost( { [ taxonomy.rest_base ]: newTermIds } );
|
|
176
202
|
}
|
|
177
203
|
|
|
178
|
-
onChange( termNames ) {
|
|
204
|
+
function onChange( termNames ) {
|
|
205
|
+
const availableTerms = [ ...terms, ...( searchResults ?? [] ) ];
|
|
179
206
|
const uniqueTerms = uniqBy( termNames, ( term ) => term.toLowerCase() );
|
|
180
|
-
this.setState( { selectedTerms: uniqueTerms } );
|
|
181
207
|
const newTermNames = uniqueTerms.filter(
|
|
182
208
|
( termName ) =>
|
|
183
|
-
! find(
|
|
209
|
+
! find( availableTerms, ( term ) =>
|
|
184
210
|
isSameTermName( term.name, termName )
|
|
185
211
|
)
|
|
186
212
|
);
|
|
187
213
|
|
|
214
|
+
// Optimistically update term values.
|
|
215
|
+
// The selector will always re-fetch terms later.
|
|
216
|
+
setValues( uniqueTerms );
|
|
217
|
+
|
|
188
218
|
if ( newTermNames.length === 0 ) {
|
|
189
|
-
return
|
|
190
|
-
termNamesToIds( uniqueTerms,
|
|
191
|
-
this.props.taxonomy.rest_base
|
|
219
|
+
return onUpdateTerms(
|
|
220
|
+
termNamesToIds( uniqueTerms, availableTerms )
|
|
192
221
|
);
|
|
193
222
|
}
|
|
194
|
-
Promise.all( newTermNames.map( this.findOrCreateTerm ) ).then(
|
|
195
|
-
( newTerms ) => {
|
|
196
|
-
const newAvailableTerms = this.state.availableTerms.concat(
|
|
197
|
-
newTerms
|
|
198
|
-
);
|
|
199
|
-
this.setState( { availableTerms: newAvailableTerms } );
|
|
200
|
-
return this.props.onUpdateTerms(
|
|
201
|
-
termNamesToIds( uniqueTerms, newAvailableTerms ),
|
|
202
|
-
this.props.taxonomy.rest_base
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
223
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if ( search.length >= 3 ) {
|
|
211
|
-
this.searchRequest = this.fetchTerms( { search } );
|
|
224
|
+
if ( ! hasCreateAction ) {
|
|
225
|
+
return;
|
|
212
226
|
}
|
|
213
|
-
}
|
|
214
227
|
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
Promise.all(
|
|
229
|
+
newTermNames.map( ( termName ) =>
|
|
230
|
+
findOrCreateTerm( termName, taxonomy.rest_base )
|
|
231
|
+
)
|
|
232
|
+
).then( ( newTerms ) => {
|
|
233
|
+
const newAvailableTerms = availableTerms.concat( newTerms );
|
|
234
|
+
return onUpdateTerms(
|
|
235
|
+
termNamesToIds( uniqueTerms, newAvailableTerms )
|
|
236
|
+
);
|
|
237
|
+
} );
|
|
238
|
+
}
|
|
217
239
|
|
|
218
|
-
|
|
240
|
+
function appendTerm( newTerm ) {
|
|
241
|
+
if ( termIds.includes( newTerm.id ) ) {
|
|
219
242
|
return;
|
|
220
243
|
}
|
|
221
244
|
|
|
222
|
-
const
|
|
223
|
-
|
|
245
|
+
const newTermIds = [ ...termIds, newTerm.id ];
|
|
224
246
|
const termAddedMessage = sprintf(
|
|
225
247
|
/* translators: %s: term name. */
|
|
226
248
|
_x( '%s added', 'term' ),
|
|
@@ -232,109 +254,53 @@ class FlatTermSelector extends Component {
|
|
|
232
254
|
);
|
|
233
255
|
|
|
234
256
|
speak( termAddedMessage, 'assertive' );
|
|
235
|
-
|
|
236
|
-
this.setState( {
|
|
237
|
-
availableTerms: [ ...this.state.availableTerms, newTerm ],
|
|
238
|
-
} );
|
|
239
|
-
|
|
240
|
-
onUpdateTerms( newTerms, taxonomy.rest_base );
|
|
257
|
+
onUpdateTerms( newTermIds );
|
|
241
258
|
}
|
|
242
259
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
/* translators: %s: term name. */
|
|
269
|
-
_x( '%s removed', 'term' ),
|
|
270
|
-
singularName
|
|
271
|
-
);
|
|
272
|
-
const removeTermLabel = sprintf(
|
|
273
|
-
/* translators: %s: term name. */
|
|
274
|
-
_x( 'Remove %s', 'term' ),
|
|
275
|
-
singularName
|
|
276
|
-
);
|
|
260
|
+
const newTermLabel = get(
|
|
261
|
+
taxonomy,
|
|
262
|
+
[ 'labels', 'add_new_item' ],
|
|
263
|
+
slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' )
|
|
264
|
+
);
|
|
265
|
+
const singularName = get(
|
|
266
|
+
taxonomy,
|
|
267
|
+
[ 'labels', 'singular_name' ],
|
|
268
|
+
slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )
|
|
269
|
+
);
|
|
270
|
+
const termAddedLabel = sprintf(
|
|
271
|
+
/* translators: %s: term name. */
|
|
272
|
+
_x( '%s added', 'term' ),
|
|
273
|
+
singularName
|
|
274
|
+
);
|
|
275
|
+
const termRemovedLabel = sprintf(
|
|
276
|
+
/* translators: %s: term name. */
|
|
277
|
+
_x( '%s removed', 'term' ),
|
|
278
|
+
singularName
|
|
279
|
+
);
|
|
280
|
+
const removeTermLabel = sprintf(
|
|
281
|
+
/* translators: %s: term name. */
|
|
282
|
+
_x( 'Remove %s', 'term' ),
|
|
283
|
+
singularName
|
|
284
|
+
);
|
|
277
285
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
onSelect={ this.appendTerm }
|
|
297
|
-
/>
|
|
298
|
-
</>
|
|
299
|
-
);
|
|
300
|
-
}
|
|
286
|
+
return (
|
|
287
|
+
<>
|
|
288
|
+
<FormTokenField
|
|
289
|
+
value={ values }
|
|
290
|
+
suggestions={ suggestions }
|
|
291
|
+
onChange={ onChange }
|
|
292
|
+
onInputChange={ debouncedSearch }
|
|
293
|
+
maxSuggestions={ MAX_TERMS_SUGGESTIONS }
|
|
294
|
+
label={ newTermLabel }
|
|
295
|
+
messages={ {
|
|
296
|
+
added: termAddedLabel,
|
|
297
|
+
removed: termRemovedLabel,
|
|
298
|
+
remove: removeTermLabel,
|
|
299
|
+
} }
|
|
300
|
+
/>
|
|
301
|
+
<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />
|
|
302
|
+
</>
|
|
303
|
+
);
|
|
301
304
|
}
|
|
302
305
|
|
|
303
|
-
export default
|
|
304
|
-
withSelect( ( select, { slug } ) => {
|
|
305
|
-
const { getCurrentPost } = select( editorStore );
|
|
306
|
-
const { getTaxonomy } = select( coreStore );
|
|
307
|
-
const taxonomy = getTaxonomy( slug );
|
|
308
|
-
return {
|
|
309
|
-
hasCreateAction: taxonomy
|
|
310
|
-
? get(
|
|
311
|
-
getCurrentPost(),
|
|
312
|
-
[ '_links', 'wp:action-create-' + taxonomy.rest_base ],
|
|
313
|
-
false
|
|
314
|
-
)
|
|
315
|
-
: false,
|
|
316
|
-
hasAssignAction: taxonomy
|
|
317
|
-
? get(
|
|
318
|
-
getCurrentPost(),
|
|
319
|
-
[ '_links', 'wp:action-assign-' + taxonomy.rest_base ],
|
|
320
|
-
false
|
|
321
|
-
)
|
|
322
|
-
: false,
|
|
323
|
-
terms: taxonomy
|
|
324
|
-
? select( editorStore ).getEditedPostAttribute(
|
|
325
|
-
taxonomy.rest_base
|
|
326
|
-
)
|
|
327
|
-
: [],
|
|
328
|
-
taxonomy,
|
|
329
|
-
};
|
|
330
|
-
} ),
|
|
331
|
-
withDispatch( ( dispatch ) => {
|
|
332
|
-
return {
|
|
333
|
-
onUpdateTerms( terms, restBase ) {
|
|
334
|
-
dispatch( editorStore ).editPost( { [ restBase ]: terms } );
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
} ),
|
|
338
|
-
withSpokenMessages,
|
|
339
|
-
withFilters( 'editor.PostTaxonomyType' )
|
|
340
|
-
)( FlatTermSelector );
|
|
306
|
+
export default withFilters( 'editor.PostTaxonomyType' )( FlatTermSelector );
|
|
@@ -199,7 +199,7 @@ export default function PostTitle() {
|
|
|
199
199
|
preserveWhiteSpace: true,
|
|
200
200
|
} );
|
|
201
201
|
|
|
202
|
-
/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-
|
|
202
|
+
/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
203
203
|
return (
|
|
204
204
|
<PostTypeSupportCheck supportKeys="title">
|
|
205
205
|
<h1
|
|
@@ -207,6 +207,8 @@ export default function PostTitle() {
|
|
|
207
207
|
contentEditable
|
|
208
208
|
className={ className }
|
|
209
209
|
aria-label={ decodedPlaceholder }
|
|
210
|
+
role="textbox"
|
|
211
|
+
aria-multiline="true"
|
|
210
212
|
onFocus={ onSelect }
|
|
211
213
|
onBlur={ onUnselect }
|
|
212
214
|
onKeyDown={ onKeyDown }
|
|
@@ -215,5 +217,5 @@ export default function PostTitle() {
|
|
|
215
217
|
/>
|
|
216
218
|
</PostTypeSupportCheck>
|
|
217
219
|
);
|
|
218
|
-
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-
|
|
220
|
+
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
219
221
|
}
|
|
@@ -94,8 +94,6 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
94
94
|
'__experimentalBlockPatternCategories',
|
|
95
95
|
'__experimentalBlockPatterns',
|
|
96
96
|
'__experimentalFeatures',
|
|
97
|
-
'__experimentalGlobalStylesBaseConfig',
|
|
98
|
-
'__experimentalGlobalStylesUserEntityId',
|
|
99
97
|
'__experimentalPreferredStyleVariations',
|
|
100
98
|
'__experimentalSetIsInserterOpened',
|
|
101
99
|
'__unstableGalleryWithImageBlocks',
|