@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
|
@@ -3,19 +3,20 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* External dependencies
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { escape as escapeString, find, get, uniqBy } from 'lodash';
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
12
|
-
import {
|
|
13
|
-
import { FormTokenField, withFilters
|
|
14
|
-
import {
|
|
12
|
+
import { useEffect, useMemo, useState } from '@wordpress/element';
|
|
13
|
+
import { FormTokenField, withFilters } from '@wordpress/components';
|
|
14
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
15
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
16
|
-
import {
|
|
16
|
+
import { useDebounce } from '@wordpress/compose';
|
|
17
17
|
import apiFetch from '@wordpress/api-fetch';
|
|
18
18
|
import { addQueryArgs } from '@wordpress/url';
|
|
19
|
+
import { speak } from '@wordpress/a11y';
|
|
19
20
|
/**
|
|
20
21
|
* Internal dependencies
|
|
21
22
|
*/
|
|
@@ -23,6 +24,14 @@ import { addQueryArgs } from '@wordpress/url';
|
|
|
23
24
|
import { store as editorStore } from '../../store';
|
|
24
25
|
import { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';
|
|
25
26
|
import MostUsedTerms from './most-used-terms';
|
|
27
|
+
/**
|
|
28
|
+
* Shared reference to an empty array for cases where it is important to avoid
|
|
29
|
+
* returning a new array reference on every invocation.
|
|
30
|
+
*
|
|
31
|
+
* @type {Array<any>}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const EMPTY_ARRAY = [];
|
|
26
35
|
/**
|
|
27
36
|
* Module constants
|
|
28
37
|
*/
|
|
@@ -32,254 +41,188 @@ const DEFAULT_QUERY = {
|
|
|
32
41
|
per_page: MAX_TERMS_SUGGESTIONS,
|
|
33
42
|
orderby: 'count',
|
|
34
43
|
order: 'desc',
|
|
35
|
-
_fields: 'id,name,
|
|
44
|
+
_fields: 'id,name',
|
|
45
|
+
context: 'view'
|
|
36
46
|
};
|
|
37
47
|
|
|
38
48
|
const isSameTermName = (termA, termB) => unescapeString(termA).toLowerCase() === unescapeString(termB).toLowerCase();
|
|
39
49
|
|
|
40
50
|
const termNamesToIds = (names, terms) => {
|
|
41
51
|
return names.map(termName => find(terms, term => isSameTermName(term.name, termName)).id);
|
|
42
|
-
};
|
|
52
|
+
}; // Tries to create a term or fetch it if it already exists.
|
|
43
53
|
|
|
44
|
-
class FlatTermSelector extends Component {
|
|
45
|
-
constructor() {
|
|
46
|
-
super(...arguments);
|
|
47
|
-
this.onChange = this.onChange.bind(this);
|
|
48
|
-
this.searchTerms = debounce(this.searchTerms.bind(this), 500);
|
|
49
|
-
this.findOrCreateTerm = this.findOrCreateTerm.bind(this);
|
|
50
|
-
this.appendTerm = this.appendTerm.bind(this);
|
|
51
|
-
this.state = {
|
|
52
|
-
loading: !isEmpty(this.props.terms),
|
|
53
|
-
availableTerms: [],
|
|
54
|
-
selectedTerms: []
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
componentDidMount() {
|
|
59
|
-
if (!isEmpty(this.props.terms)) {
|
|
60
|
-
this.initRequest = this.fetchTerms({
|
|
61
|
-
include: this.props.terms.join(','),
|
|
62
|
-
per_page: -1
|
|
63
|
-
});
|
|
64
|
-
this.initRequest.then(() => {
|
|
65
|
-
this.setState({
|
|
66
|
-
loading: false
|
|
67
|
-
});
|
|
68
|
-
}, xhr => {
|
|
69
|
-
if (xhr.statusText === 'abort') {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
function findOrCreateTerm(termName, restBase) {
|
|
56
|
+
const escapedTermName = escapeString(termName);
|
|
57
|
+
return apiFetch({
|
|
58
|
+
path: `/wp/v2/${restBase}`,
|
|
59
|
+
method: 'POST',
|
|
60
|
+
data: {
|
|
61
|
+
name: escapedTermName
|
|
62
|
+
}
|
|
63
|
+
}).catch(error => {
|
|
64
|
+
const errorCode = error.code;
|
|
65
|
+
|
|
66
|
+
if (errorCode === 'term_exists') {
|
|
67
|
+
// If the terms exist, fetch it instead of creating a new one.
|
|
68
|
+
const addRequest = apiFetch({
|
|
69
|
+
path: addQueryArgs(`/wp/v2/${restBase}`, { ...DEFAULT_QUERY,
|
|
70
|
+
search: escapedTermName
|
|
71
|
+
})
|
|
72
|
+
}).then(unescapeTerms);
|
|
73
|
+
return addRequest.then(searchResult => {
|
|
74
|
+
return find(searchResult, result => isSameTermName(result.name, termName));
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
componentWillUnmount() {
|
|
81
|
-
invoke(this.initRequest, ['abort']);
|
|
82
|
-
invoke(this.searchRequest, ['abort']);
|
|
83
|
-
}
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}
|
|
78
|
+
return Promise.reject(error);
|
|
79
|
+
}).then(unescapeTerm);
|
|
80
|
+
}
|
|
90
81
|
|
|
91
|
-
|
|
82
|
+
function FlatTermSelector(_ref) {
|
|
83
|
+
let {
|
|
84
|
+
slug
|
|
85
|
+
} = _ref;
|
|
86
|
+
const [values, setValues] = useState([]);
|
|
87
|
+
const [search, setSearch] = useState('');
|
|
88
|
+
const debouncedSearch = useDebounce(setSearch, 500);
|
|
89
|
+
const {
|
|
90
|
+
terms,
|
|
91
|
+
termIds,
|
|
92
|
+
taxonomy,
|
|
93
|
+
hasAssignAction,
|
|
94
|
+
hasCreateAction,
|
|
95
|
+
hasResolvedTerms
|
|
96
|
+
} = useSelect(select => {
|
|
92
97
|
const {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this.setState(state => ({
|
|
103
|
-
availableTerms: state.availableTerms.concat(terms.filter(term => !find(state.availableTerms, availableTerm => availableTerm.id === term.id)))
|
|
104
|
-
}));
|
|
105
|
-
this.updateSelectedTerms(this.props.terms);
|
|
106
|
-
});
|
|
107
|
-
return request;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
updateSelectedTerms(terms = []) {
|
|
111
|
-
const selectedTerms = terms.reduce((accumulator, termId) => {
|
|
112
|
-
const termObject = find(this.state.availableTerms, term => term.id === termId);
|
|
98
|
+
getCurrentPost,
|
|
99
|
+
getEditedPostAttribute
|
|
100
|
+
} = select(editorStore);
|
|
101
|
+
const {
|
|
102
|
+
getEntityRecords,
|
|
103
|
+
getTaxonomy,
|
|
104
|
+
hasFinishedResolution
|
|
105
|
+
} = select(coreStore);
|
|
106
|
+
const post = getCurrentPost();
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
accumulator.push(termObject.name);
|
|
116
|
-
}
|
|
108
|
+
const _taxonomy = getTaxonomy(slug);
|
|
117
109
|
|
|
118
|
-
|
|
119
|
-
}, []);
|
|
120
|
-
this.setState({
|
|
121
|
-
selectedTerms
|
|
122
|
-
});
|
|
123
|
-
}
|
|
110
|
+
const _termIds = _taxonomy ? getEditedPostAttribute(_taxonomy.rest_base) : EMPTY_ARRAY;
|
|
124
111
|
|
|
125
|
-
|
|
112
|
+
const query = { ...DEFAULT_QUERY,
|
|
113
|
+
include: _termIds.join(','),
|
|
114
|
+
per_page: -1
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
hasCreateAction: _taxonomy ? get(post, ['_links', 'wp:action-create-' + _taxonomy.rest_base], false) : false,
|
|
118
|
+
hasAssignAction: _taxonomy ? get(post, ['_links', 'wp:action-assign-' + _taxonomy.rest_base], false) : false,
|
|
119
|
+
taxonomy: _taxonomy,
|
|
120
|
+
termIds: _termIds,
|
|
121
|
+
terms: _termIds.length ? getEntityRecords('taxonomy', slug, query) : EMPTY_ARRAY,
|
|
122
|
+
hasResolvedTerms: hasFinishedResolution('getEntityRecords', ['taxonomy', slug, query])
|
|
123
|
+
};
|
|
124
|
+
}, [slug]);
|
|
125
|
+
const {
|
|
126
|
+
searchResults
|
|
127
|
+
} = useSelect(select => {
|
|
126
128
|
const {
|
|
127
|
-
|
|
128
|
-
} =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
getEntityRecords
|
|
130
|
+
} = select(coreStore);
|
|
131
|
+
return {
|
|
132
|
+
searchResults: !!search ? getEntityRecords('taxonomy', slug, { ...DEFAULT_QUERY,
|
|
133
|
+
search
|
|
134
|
+
}) : EMPTY_ARRAY
|
|
135
|
+
};
|
|
136
|
+
}, [search]); // Update terms state only after the selectors are resolved.
|
|
137
|
+
// We're using this to avoid terms temporarily disappearing on slow networks
|
|
138
|
+
// while core data makes REST API requests.
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (hasResolvedTerms) {
|
|
142
|
+
const newValues = terms.map(term => unescapeString(term.name));
|
|
143
|
+
setValues(newValues);
|
|
144
|
+
}
|
|
145
|
+
}, [terms, hasResolvedTerms]);
|
|
146
|
+
const suggestions = useMemo(() => {
|
|
147
|
+
return (searchResults !== null && searchResults !== void 0 ? searchResults : []).map(term => unescapeString(term.name));
|
|
148
|
+
}, [searchResults]);
|
|
149
|
+
const {
|
|
150
|
+
editPost
|
|
151
|
+
} = useDispatch(editorStore);
|
|
139
152
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
path: addQueryArgs(`/wp/v2/${taxonomy.rest_base}`, { ...DEFAULT_QUERY,
|
|
144
|
-
search: termNameEscaped
|
|
145
|
-
})
|
|
146
|
-
}).then(unescapeTerms);
|
|
147
|
-
return this.addRequest.then(searchResult => {
|
|
148
|
-
return find(searchResult, result => isSameTermName(result.name, termName));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
153
|
+
if (!hasAssignAction) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
151
156
|
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
function onUpdateTerms(newTermIds) {
|
|
158
|
+
editPost({
|
|
159
|
+
[taxonomy.rest_base]: newTermIds
|
|
160
|
+
});
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
onChange(termNames) {
|
|
163
|
+
function onChange(termNames) {
|
|
164
|
+
const availableTerms = [...terms, ...(searchResults !== null && searchResults !== void 0 ? searchResults : [])];
|
|
157
165
|
const uniqueTerms = uniqBy(termNames, term => term.toLowerCase());
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
const newTermNames = uniqueTerms.filter(termName => !find(availableTerms, term => isSameTermName(term.name, termName))); // Optimistically update term values.
|
|
167
|
+
// The selector will always re-fetch terms later.
|
|
168
|
+
|
|
169
|
+
setValues(uniqueTerms);
|
|
162
170
|
|
|
163
171
|
if (newTermNames.length === 0) {
|
|
164
|
-
return
|
|
172
|
+
return onUpdateTerms(termNamesToIds(uniqueTerms, availableTerms));
|
|
165
173
|
}
|
|
166
174
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.setState({
|
|
170
|
-
availableTerms: newAvailableTerms
|
|
171
|
-
});
|
|
172
|
-
return this.props.onUpdateTerms(termNamesToIds(uniqueTerms, newAvailableTerms), this.props.taxonomy.rest_base);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
searchTerms(search = '') {
|
|
177
|
-
invoke(this.searchRequest, ['abort']);
|
|
178
|
-
|
|
179
|
-
if (search.length >= 3) {
|
|
180
|
-
this.searchRequest = this.fetchTerms({
|
|
181
|
-
search
|
|
182
|
-
});
|
|
175
|
+
if (!hasCreateAction) {
|
|
176
|
+
return;
|
|
183
177
|
}
|
|
184
|
-
}
|
|
185
178
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
onUpdateTerms,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
slug,
|
|
192
|
-
speak
|
|
193
|
-
} = this.props;
|
|
179
|
+
Promise.all(newTermNames.map(termName => findOrCreateTerm(termName, taxonomy.rest_base))).then(newTerms => {
|
|
180
|
+
const newAvailableTerms = availableTerms.concat(newTerms);
|
|
181
|
+
return onUpdateTerms(termNamesToIds(uniqueTerms, newAvailableTerms));
|
|
182
|
+
});
|
|
183
|
+
}
|
|
194
184
|
|
|
195
|
-
|
|
185
|
+
function appendTerm(newTerm) {
|
|
186
|
+
if (termIds.includes(newTerm.id)) {
|
|
196
187
|
return;
|
|
197
188
|
}
|
|
198
189
|
|
|
199
|
-
const
|
|
190
|
+
const newTermIds = [...termIds, newTerm.id];
|
|
200
191
|
const termAddedMessage = sprintf(
|
|
201
192
|
/* translators: %s: term name. */
|
|
202
193
|
_x('%s added', 'term'), get(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? __('Tag') : __('Term')));
|
|
203
194
|
speak(termAddedMessage, 'assertive');
|
|
204
|
-
|
|
205
|
-
availableTerms: [...this.state.availableTerms, newTerm]
|
|
206
|
-
});
|
|
207
|
-
onUpdateTerms(newTerms, taxonomy.rest_base);
|
|
195
|
+
onUpdateTerms(newTermIds);
|
|
208
196
|
}
|
|
209
197
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
198
|
+
const newTermLabel = get(taxonomy, ['labels', 'add_new_item'], slug === 'post_tag' ? __('Add new tag') : __('Add new Term'));
|
|
199
|
+
const singularName = get(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? __('Tag') : __('Term'));
|
|
200
|
+
const termAddedLabel = sprintf(
|
|
201
|
+
/* translators: %s: term name. */
|
|
202
|
+
_x('%s added', 'term'), singularName);
|
|
203
|
+
const termRemovedLabel = sprintf(
|
|
204
|
+
/* translators: %s: term name. */
|
|
205
|
+
_x('%s removed', 'term'), singularName);
|
|
206
|
+
const removeTermLabel = sprintf(
|
|
207
|
+
/* translators: %s: term name. */
|
|
208
|
+
_x('Remove %s', 'term'), singularName);
|
|
209
|
+
return createElement(Fragment, null, createElement(FormTokenField, {
|
|
210
|
+
value: values,
|
|
211
|
+
suggestions: suggestions,
|
|
212
|
+
onChange: onChange,
|
|
213
|
+
onInputChange: debouncedSearch,
|
|
214
|
+
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
215
|
+
label: newTermLabel,
|
|
216
|
+
messages: {
|
|
217
|
+
added: termAddedLabel,
|
|
218
|
+
removed: termRemovedLabel,
|
|
219
|
+
remove: removeTermLabel
|
|
219
220
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
selectedTerms
|
|
225
|
-
} = this.state;
|
|
226
|
-
const termNames = availableTerms.map(term => term.name);
|
|
227
|
-
const newTermLabel = get(taxonomy, ['labels', 'add_new_item'], slug === 'post_tag' ? __('Add new tag') : __('Add new Term'));
|
|
228
|
-
const singularName = get(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? __('Tag') : __('Term'));
|
|
229
|
-
const termAddedLabel = sprintf(
|
|
230
|
-
/* translators: %s: term name. */
|
|
231
|
-
_x('%s added', 'term'), singularName);
|
|
232
|
-
const termRemovedLabel = sprintf(
|
|
233
|
-
/* translators: %s: term name. */
|
|
234
|
-
_x('%s removed', 'term'), singularName);
|
|
235
|
-
const removeTermLabel = sprintf(
|
|
236
|
-
/* translators: %s: term name. */
|
|
237
|
-
_x('Remove %s', 'term'), singularName);
|
|
238
|
-
return createElement(Fragment, null, createElement(FormTokenField, {
|
|
239
|
-
value: selectedTerms,
|
|
240
|
-
suggestions: termNames,
|
|
241
|
-
onChange: this.onChange,
|
|
242
|
-
onInputChange: this.searchTerms,
|
|
243
|
-
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
244
|
-
disabled: loading,
|
|
245
|
-
label: newTermLabel,
|
|
246
|
-
messages: {
|
|
247
|
-
added: termAddedLabel,
|
|
248
|
-
removed: termRemovedLabel,
|
|
249
|
-
remove: removeTermLabel
|
|
250
|
-
}
|
|
251
|
-
}), createElement(MostUsedTerms, {
|
|
252
|
-
taxonomy: taxonomy,
|
|
253
|
-
onSelect: this.appendTerm
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
|
|
221
|
+
}), createElement(MostUsedTerms, {
|
|
222
|
+
taxonomy: taxonomy,
|
|
223
|
+
onSelect: appendTerm
|
|
224
|
+
}));
|
|
257
225
|
}
|
|
258
226
|
|
|
259
|
-
export default
|
|
260
|
-
slug
|
|
261
|
-
}) => {
|
|
262
|
-
const {
|
|
263
|
-
getCurrentPost
|
|
264
|
-
} = select(editorStore);
|
|
265
|
-
const {
|
|
266
|
-
getTaxonomy
|
|
267
|
-
} = select(coreStore);
|
|
268
|
-
const taxonomy = getTaxonomy(slug);
|
|
269
|
-
return {
|
|
270
|
-
hasCreateAction: taxonomy ? get(getCurrentPost(), ['_links', 'wp:action-create-' + taxonomy.rest_base], false) : false,
|
|
271
|
-
hasAssignAction: taxonomy ? get(getCurrentPost(), ['_links', 'wp:action-assign-' + taxonomy.rest_base], false) : false,
|
|
272
|
-
terms: taxonomy ? select(editorStore).getEditedPostAttribute(taxonomy.rest_base) : [],
|
|
273
|
-
taxonomy
|
|
274
|
-
};
|
|
275
|
-
}), withDispatch(dispatch => {
|
|
276
|
-
return {
|
|
277
|
-
onUpdateTerms(terms, restBase) {
|
|
278
|
-
dispatch(editorStore).editPost({
|
|
279
|
-
[restBase]: terms
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
};
|
|
284
|
-
}), withSpokenMessages, withFilters('editor.PostTaxonomyType'))(FlatTermSelector);
|
|
227
|
+
export default withFilters('editor.PostTaxonomyType')(FlatTermSelector);
|
|
285
228
|
//# sourceMappingURL=flat-term-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"names":["debounce","escape","escapeString","find","get","invoke","isEmpty","uniqBy","__","_x","sprintf","Component","FormTokenField","withFilters","withSpokenMessages","withSelect","withDispatch","store","coreStore","compose","apiFetch","addQueryArgs","editorStore","unescapeString","unescapeTerm","unescapeTerms","MostUsedTerms","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","orderby","order","_fields","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","term","name","id","FlatTermSelector","constructor","arguments","onChange","bind","searchTerms","findOrCreateTerm","appendTerm","state","loading","props","availableTerms","selectedTerms","componentDidMount","initRequest","fetchTerms","include","join","then","setState","xhr","statusText","componentWillUnmount","searchRequest","componentDidUpdate","prevProps","updateSelectedTerms","params","taxonomy","query","request","path","rest_base","concat","filter","availableTerm","reduce","accumulator","termId","termObject","push","termNameEscaped","method","data","catch","error","errorCode","code","addRequest","search","searchResult","result","Promise","reject","termNames","uniqueTerms","newTermNames","length","onUpdateTerms","all","newTerms","newAvailableTerms","newTerm","slug","speak","includes","termAddedMessage","render","hasAssignAction","newTermLabel","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","added","removed","remove","select","getCurrentPost","getTaxonomy","hasCreateAction","getEditedPostAttribute","dispatch","restBase","editPost"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,QADD,EAECC,MAAM,IAAIC,YAFX,EAGCC,IAHD,EAICC,GAJD,EAKCC,MALD,EAMCC,OAND,E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ASyF,QAAT,EAAoB;AAChCD,MAAAA,QAAQ,CAAEzG,WAAF,CAAR,CAAwB2G,QAAxB,CAAkC;AAAE,SAAED,QAAF,GAAczF;AAAhB,OAAlC;AACA;;AAHK,GAAP;AAKA,CANW,CA5BS,EAmCrBzB,kBAnCqB,EAoCrBD,WAAW,CAAE,yBAAF,CApCU,CAAP,CAqCZgC,gBArCY,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tdebounce,\n\tescape as escapeString,\n\tfind,\n\tget,\n\tinvoke,\n\tisEmpty,\n\tuniqBy,\n} from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { Component } from '@wordpress/element';\nimport {\n\tFormTokenField,\n\twithFilters,\n\twithSpokenMessages,\n} from '@wordpress/components';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { compose } from '@wordpress/compose';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\torderby: 'count',\n\torder: 'desc',\n\t_fields: 'id,name,count',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tfind( terms, ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\nclass FlatTermSelector extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.onChange = this.onChange.bind( this );\n\t\tthis.searchTerms = debounce( this.searchTerms.bind( this ), 500 );\n\t\tthis.findOrCreateTerm = this.findOrCreateTerm.bind( this );\n\t\tthis.appendTerm = this.appendTerm.bind( this );\n\t\tthis.state = {\n\t\t\tloading: ! isEmpty( this.props.terms ),\n\t\t\tavailableTerms: [],\n\t\t\tselectedTerms: [],\n\t\t};\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( ! isEmpty( this.props.terms ) ) {\n\t\t\tthis.initRequest = this.fetchTerms( {\n\t\t\t\tinclude: this.props.terms.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\t\t\tthis.initRequest.then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.setState( { loading: false } );\n\t\t\t\t},\n\t\t\t\t( xhr ) => {\n\t\t\t\t\tif ( xhr.statusText === 'abort' ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\tloading: false,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n\n\tcomponentWillUnmount() {\n\t\tinvoke( this.initRequest, [ 'abort' ] );\n\t\tinvoke( this.searchRequest, [ 'abort' ] );\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tif ( prevProps.terms !== this.props.terms ) {\n\t\t\tthis.updateSelectedTerms( this.props.terms );\n\t\t}\n\t}\n\n\tfetchTerms( params = {} ) {\n\t\tconst { taxonomy } = this.props;\n\t\tconst query = { ...DEFAULT_QUERY, ...params };\n\t\tconst request = apiFetch( {\n\t\t\tpath: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, query ),\n\t\t} );\n\t\trequest.then( unescapeTerms ).then( ( terms ) => {\n\t\t\tthis.setState( ( state ) => ( {\n\t\t\t\tavailableTerms: state.availableTerms.concat(\n\t\t\t\t\tterms.filter(\n\t\t\t\t\t\t( term ) =>\n\t\t\t\t\t\t\t! find(\n\t\t\t\t\t\t\t\tstate.availableTerms,\n\t\t\t\t\t\t\t\t( availableTerm ) =>\n\t\t\t\t\t\t\t\t\tavailableTerm.id === term.id\n\t\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t\t} ) );\n\t\t\tthis.updateSelectedTerms( this.props.terms );\n\t\t} );\n\n\t\treturn request;\n\t}\n\n\tupdateSelectedTerms( terms = [] ) {\n\t\tconst selectedTerms = terms.reduce( ( accumulator, termId ) => {\n\t\t\tconst termObject = find(\n\t\t\t\tthis.state.availableTerms,\n\t\t\t\t( term ) => term.id === termId\n\t\t\t);\n\t\t\tif ( termObject ) {\n\t\t\t\taccumulator.push( termObject.name );\n\t\t\t}\n\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tthis.setState( {\n\t\t\tselectedTerms,\n\t\t} );\n\t}\n\n\tfindOrCreateTerm( termName ) {\n\t\tconst { taxonomy } = this.props;\n\t\tconst termNameEscaped = escapeString( termName );\n\t\t// Tries to create a term or fetch it if it already exists.\n\t\treturn apiFetch( {\n\t\t\tpath: `/wp/v2/${ taxonomy.rest_base }`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { name: termNameEscaped },\n\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tconst errorCode = error.code;\n\t\t\t\tif ( errorCode === 'term_exists' ) {\n\t\t\t\t\t// If the terms exist, fetch it instead of creating a new one.\n\t\t\t\t\tthis.addRequest = apiFetch( {\n\t\t\t\t\t\tpath: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch: termNameEscaped,\n\t\t\t\t\t\t} ),\n\t\t\t\t\t} ).then( unescapeTerms );\n\t\t\t\t\treturn this.addRequest.then( ( searchResult ) => {\n\t\t\t\t\t\treturn find( searchResult, ( result ) =>\n\t\t\t\t\t\t\tisSameTermName( result.name, termName )\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn Promise.reject( error );\n\t\t\t} )\n\t\t\t.then( unescapeTerm );\n\t}\n\n\tonChange( termNames ) {\n\t\tconst uniqueTerms = uniqBy( termNames, ( term ) => term.toLowerCase() );\n\t\tthis.setState( { selectedTerms: uniqueTerms } );\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! find( this.state.availableTerms, ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn this.props.onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, this.state.availableTerms ),\n\t\t\t\tthis.props.taxonomy.rest_base\n\t\t\t);\n\t\t}\n\t\tPromise.all( newTermNames.map( this.findOrCreateTerm ) ).then(\n\t\t\t( newTerms ) => {\n\t\t\t\tconst newAvailableTerms = this.state.availableTerms.concat(\n\t\t\t\t\tnewTerms\n\t\t\t\t);\n\t\t\t\tthis.setState( { availableTerms: newAvailableTerms } );\n\t\t\t\treturn this.props.onUpdateTerms(\n\t\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms ),\n\t\t\t\t\tthis.props.taxonomy.rest_base\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\t}\n\n\tsearchTerms( search = '' ) {\n\t\tinvoke( this.searchRequest, [ 'abort' ] );\n\t\tif ( search.length >= 3 ) {\n\t\t\tthis.searchRequest = this.fetchTerms( { search } );\n\t\t}\n\t}\n\n\tappendTerm( newTerm ) {\n\t\tconst { onUpdateTerms, taxonomy, terms = [], slug, speak } = this.props;\n\n\t\tif ( terms.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTerms = [ ...terms, newTerm.id ];\n\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\tget(\n\t\t\t\ttaxonomy,\n\t\t\t\t[ 'labels', 'singular_name' ],\n\t\t\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t\t\t)\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\n\t\tthis.setState( {\n\t\t\tavailableTerms: [ ...this.state.availableTerms, newTerm ],\n\t\t} );\n\n\t\tonUpdateTerms( newTerms, taxonomy.rest_base );\n\t}\n\n\trender() {\n\t\tconst { slug, taxonomy, hasAssignAction } = this.props;\n\n\t\tif ( ! hasAssignAction ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { loading, availableTerms, selectedTerms } = this.state;\n\t\tconst termNames = availableTerms.map( ( term ) => term.name );\n\t\tconst newTermLabel = get(\n\t\t\ttaxonomy,\n\t\t\t[ 'labels', 'add_new_item' ],\n\t\t\tslug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' )\n\t\t);\n\t\tconst singularName = get(\n\t\t\ttaxonomy,\n\t\t\t[ 'labels', 'singular_name' ],\n\t\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t\t);\n\t\tconst termAddedLabel = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\tsingularName\n\t\t);\n\t\tconst termRemovedLabel = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s removed', 'term' ),\n\t\t\tsingularName\n\t\t);\n\t\tconst removeTermLabel = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( 'Remove %s', 'term' ),\n\t\t\tsingularName\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<FormTokenField\n\t\t\t\t\tvalue={ selectedTerms }\n\t\t\t\t\tsuggestions={ termNames }\n\t\t\t\t\tonChange={ this.onChange }\n\t\t\t\t\tonInputChange={ this.searchTerms }\n\t\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\t\tdisabled={ loading }\n\t\t\t\t\tlabel={ newTermLabel }\n\t\t\t\t\tmessages={ {\n\t\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<MostUsedTerms\n\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\tonSelect={ this.appendTerm }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n}\n\nexport default compose(\n\twithSelect( ( select, { slug } ) => {\n\t\tconst { getCurrentPost } = select( editorStore );\n\t\tconst { getTaxonomy } = select( coreStore );\n\t\tconst taxonomy = getTaxonomy( slug );\n\t\treturn {\n\t\t\thasCreateAction: taxonomy\n\t\t\t\t? get(\n\t\t\t\t\t\tgetCurrentPost(),\n\t\t\t\t\t\t[ '_links', 'wp:action-create-' + taxonomy.rest_base ],\n\t\t\t\t\t\tfalse\n\t\t\t\t )\n\t\t\t\t: false,\n\t\t\thasAssignAction: taxonomy\n\t\t\t\t? get(\n\t\t\t\t\t\tgetCurrentPost(),\n\t\t\t\t\t\t[ '_links', 'wp:action-assign-' + taxonomy.rest_base ],\n\t\t\t\t\t\tfalse\n\t\t\t\t )\n\t\t\t\t: false,\n\t\t\tterms: taxonomy\n\t\t\t\t? select( editorStore ).getEditedPostAttribute(\n\t\t\t\t\t\ttaxonomy.rest_base\n\t\t\t\t )\n\t\t\t\t: [],\n\t\t\ttaxonomy,\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\treturn {\n\t\t\tonUpdateTerms( terms, restBase ) {\n\t\t\t\tdispatch( editorStore ).editPost( { [ restBase ]: terms } );\n\t\t\t},\n\t\t};\n\t} ),\n\twithSpokenMessages,\n\twithFilters( 'editor.PostTaxonomyType' )\n)( FlatTermSelector );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"names":["escape","escapeString","find","get","uniqBy","__","_x","sprintf","useEffect","useMemo","useState","FormTokenField","withFilters","useSelect","useDispatch","store","coreStore","useDebounce","apiFetch","addQueryArgs","speak","editorStore","unescapeString","unescapeTerm","unescapeTerms","MostUsedTerms","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","orderby","order","_fields","context","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","term","name","id","findOrCreateTerm","restBase","escapedTermName","path","method","data","catch","error","errorCode","code","addRequest","search","then","searchResult","result","Promise","reject","FlatTermSelector","slug","values","setValues","setSearch","debouncedSearch","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","getCurrentPost","getEditedPostAttribute","getEntityRecords","getTaxonomy","hasFinishedResolution","post","_taxonomy","_termIds","rest_base","query","include","join","length","searchResults","newValues","suggestions","editPost","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","newTermNames","filter","all","newTerms","newAvailableTerms","concat","appendTerm","newTerm","includes","termAddedMessage","newTermLabel","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","added","removed","remove"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAM,IAAIC,YAAnB,EAAiCC,IAAjC,EAAuCC,GAAvC,EAA4CC,MAA5C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SAASC,SAAT,EAAoBC,OAApB,EAA6BC,QAA7B,QAA6C,oBAA7C;AACA,SAASC,cAAT,EAAyBC,WAAzB,QAA4C,uBAA5C;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,WAAT,QAA4B,oBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASL,KAAK,IAAIM,WAAlB,QAAqC,aAArC;AACA,SAASC,cAAT,EAAyBC,YAAzB,EAAuCC,aAAvC,QAA4D,mBAA5D;AACA,OAAOC,aAAP,MAA0B,mBAA1B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f","sourcesContent":["/**\n * External dependencies\n */\nimport { escape as escapeString, find, get, uniqBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, withFilters } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\torderby: 'count',\n\torder: 'desc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tfind( terms, ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\n// Tries to create a term or fetch it if it already exists.\nfunction findOrCreateTerm( termName, restBase ) {\n\tconst escapedTermName = escapeString( termName );\n\n\treturn apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }`,\n\t\tmethod: 'POST',\n\t\tdata: { name: escapedTermName },\n\t} )\n\t\t.catch( ( error ) => {\n\t\t\tconst errorCode = error.code;\n\t\t\tif ( errorCode === 'term_exists' ) {\n\t\t\t\t// If the terms exist, fetch it instead of creating a new one.\n\t\t\t\tconst addRequest = apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( `/wp/v2/${ restBase }`, {\n\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\tsearch: escapedTermName,\n\t\t\t\t\t} ),\n\t\t\t\t} ).then( unescapeTerms );\n\n\t\t\t\treturn addRequest.then( ( searchResult ) => {\n\t\t\t\t\treturn find( searchResult, ( result ) =>\n\t\t\t\t\t\tisSameTermName( result.name, termName )\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn Promise.reject( error );\n\t\t} )\n\t\t.then( unescapeTerm );\n}\n\nfunction FlatTermSelector( { slug } ) {\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttermIds,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPost, getEditedPostAttribute } = select(\n\t\t\t\teditorStore\n\t\t\t);\n\t\t\tconst {\n\t\t\t\tgetEntityRecords,\n\t\t\t\tgetTaxonomy,\n\t\t\t\thasFinishedResolution,\n\t\t\t} = select( coreStore );\n\t\t\tconst post = getCurrentPost();\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds = _taxonomy\n\t\t\t\t? getEditedPostAttribute( _taxonomy.rest_base )\n\t\t\t\t: EMPTY_ARRAY;\n\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = terms.map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditPost( { [ taxonomy.rest_base ]: newTermIds } );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [ ...terms, ...( searchResults ?? [] ) ];\n\t\tconst uniqueTerms = uniqBy( termNames, ( term ) => term.toLowerCase() );\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! find( availableTerms, ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( termName, taxonomy.rest_base )\n\t\t\t)\n\t\t).then( ( newTerms ) => {\n\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t);\n\t\t} );\n\t}\n\n\tfunction appendTerm( newTerm ) {\n\t\tif ( termIds.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTermIds = [ ...termIds, newTerm.id ];\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\tget(\n\t\t\t\ttaxonomy,\n\t\t\t\t[ 'labels', 'singular_name' ],\n\t\t\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t\t\t)\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\t\tonUpdateTerms( newTermIds );\n\t}\n\n\tconst newTermLabel = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'add_new_item' ],\n\t\tslug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' )\n\t);\n\tconst singularName = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'singular_name' ],\n\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t);\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<FormTokenField\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ newTermLabel }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />\n\t\t</>\n\t);\n}\n\nexport default withFilters( 'editor.PostTaxonomyType' )( FlatTermSelector );\n"]}
|
|
@@ -137,9 +137,10 @@ export function getFilterMatcher(filterValue) {
|
|
|
137
137
|
* @return {WPElement} Hierarchical term selector component.
|
|
138
138
|
*/
|
|
139
139
|
|
|
140
|
-
function HierarchicalTermSelector({
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
function HierarchicalTermSelector(_ref) {
|
|
141
|
+
let {
|
|
142
|
+
slug
|
|
143
|
+
} = _ref;
|
|
143
144
|
const [adding, setAdding] = useState(false);
|
|
144
145
|
const [formName, setFormName] = useState('');
|
|
145
146
|
/**
|