@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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-sticky/index.js"],"names":["PostSticky","onUpdateSticky","postSticky","select","editorStore","getEditedPostAttribute","dispatch","editPost","sticky"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIO,SAASA,UAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-sticky/index.js"],"names":["PostSticky","onUpdateSticky","postSticky","select","editorStore","getEditedPostAttribute","dispatch","editPost","sticky"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIO,SAASA,UAAT,OAA8D;AAAA,MAAzC;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,UAAU,GAAG;AAA/B,GAAyC;AACpE,SACC,4BAAC,cAAD,QACC,4BAAC,2BAAD;AACC,IAAA,KAAK,EAAG,cAAI,8BAAJ,CADT;AAEC,IAAA,OAAO,EAAGA,UAFX;AAGC,IAAA,QAAQ,EAAG,MAAMD,cAAc,CAAE,CAAEC,UAAJ;AAHhC,IADD,CADD;AASA;;eAEc,sBAAS,CACvB,sBAAcC,MAAF,IAAc;AACzB,SAAO;AACND,IAAAA,UAAU,EAAEC,MAAM,CAAEC,YAAF,CAAN,CAAsBC,sBAAtB,CACX,QADW;AADN,GAAP;AAKA,CAND,CADuB,EAQvB,wBAAgBC,QAAF,IAAgB;AAC7B,SAAO;AACNL,IAAAA,cAAc,CAAEC,UAAF,EAAe;AAC5BI,MAAAA,QAAQ,CAAEF,YAAF,CAAR,CAAwBG,QAAxB,CAAkC;AAAEC,QAAAA,MAAM,EAAEN;AAAV,OAAlC;AACA;;AAHK,GAAP;AAKA,CAND,CARuB,CAAT,EAeVF,UAfU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { CheckboxControl } from '@wordpress/components';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport PostStickyCheck from './check';\nimport { store as editorStore } from '../../store';\n\nexport function PostSticky( { onUpdateSticky, postSticky = false } ) {\n\treturn (\n\t\t<PostStickyCheck>\n\t\t\t<CheckboxControl\n\t\t\t\tlabel={ __( 'Stick to the top of the blog' ) }\n\t\t\t\tchecked={ postSticky }\n\t\t\t\tonChange={ () => onUpdateSticky( ! postSticky ) }\n\t\t\t/>\n\t\t</PostStickyCheck>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\treturn {\n\t\t\tpostSticky: select( editorStore ).getEditedPostAttribute(\n\t\t\t\t'sticky'\n\t\t\t),\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\treturn {\n\t\t\tonUpdateSticky( postSticky ) {\n\t\t\t\tdispatch( editorStore ).editPost( { sticky: postSticky } );\n\t\t\t},\n\t\t};\n\t} ),\n] )( PostSticky );\n"]}
|
|
@@ -24,12 +24,13 @@ var _store = require("../../store");
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
function PostSwitchToDraftButton({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
function PostSwitchToDraftButton(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
isSaving,
|
|
30
|
+
isPublished,
|
|
31
|
+
isScheduled,
|
|
32
|
+
onClick
|
|
33
|
+
} = _ref;
|
|
33
34
|
const isMobileViewport = (0, _compose.useViewportMatch)('small', '<');
|
|
34
35
|
|
|
35
36
|
if (!isPublished && !isScheduled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-switch-to-draft-button/index.js"],"names":["PostSwitchToDraftButton","isSaving","isPublished","isScheduled","onClick","isMobileViewport","onSwitch","alertMessage","window","confirm","select","isSavingPost","isCurrentPostPublished","isCurrentPostScheduled","editorStore","dispatch","editPost","savePost","status"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGA,SAASA,uBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-switch-to-draft-button/index.js"],"names":["PostSwitchToDraftButton","isSaving","isPublished","isScheduled","onClick","isMobileViewport","onSwitch","alertMessage","window","confirm","select","isSavingPost","isCurrentPostPublished","isCurrentPostScheduled","editorStore","dispatch","editPost","savePost","status"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGA,SAASA,uBAAT,OAKI;AAAA,MAL8B;AACjCC,IAAAA,QADiC;AAEjCC,IAAAA,WAFiC;AAGjCC,IAAAA,WAHiC;AAIjCC,IAAAA;AAJiC,GAK9B;AACH,QAAMC,gBAAgB,GAAG,+BAAkB,OAAlB,EAA2B,GAA3B,CAAzB;;AAEA,MAAK,CAAEH,WAAF,IAAiB,CAAEC,WAAxB,EAAsC;AACrC,WAAO,IAAP;AACA;;AAED,QAAMG,QAAQ,GAAG,MAAM;AACtB,QAAIC,YAAJ;;AACA,QAAKL,WAAL,EAAmB;AAClBK,MAAAA,YAAY,GAAG,cACd,+CADc,CAAf;AAGA,KAJD,MAIO,IAAKJ,WAAL,EAAmB;AACzBI,MAAAA,YAAY,GAAG,cACd,gDADc,CAAf;AAGA,KAVqB,CAWtB;;;AACA,QAAKC,MAAM,CAACC,OAAP,CAAgBF,YAAhB,CAAL,EAAsC;AACrCH,MAAAA,OAAO;AACP;AACD,GAfD;;AAiBA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,6BADX;AAEC,IAAA,OAAO,EAAGE,QAFX;AAGC,IAAA,QAAQ,EAAGL,QAHZ;AAIC,IAAA,OAAO,EAAC;AAJT,KAMGI,gBAAgB,GAAG,cAAI,OAAJ,CAAH,GAAmB,cAAI,iBAAJ,CANtC,CADD;AAUA;;eAEc,sBAAS,CACvB,sBAAcK,MAAF,IAAc;AACzB,QAAM;AACLC,IAAAA,YADK;AAELC,IAAAA,sBAFK;AAGLC,IAAAA;AAHK,MAIFH,MAAM,CAAEI,YAAF,CAJV;AAKA,SAAO;AACNb,IAAAA,QAAQ,EAAEU,YAAY,EADhB;AAENT,IAAAA,WAAW,EAAEU,sBAAsB,EAF7B;AAGNT,IAAAA,WAAW,EAAEU,sBAAsB;AAH7B,GAAP;AAKA,CAXD,CADuB,EAavB,wBAAgBE,QAAF,IAAgB;AAC7B,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAyBF,QAAQ,CAAED,YAAF,CAAvC;AACA,SAAO;AACNV,IAAAA,OAAO,EAAE,MAAM;AACdY,MAAAA,QAAQ,CAAE;AAAEE,QAAAA,MAAM,EAAE;AAAV,OAAF,CAAR;AACAD,MAAAA,QAAQ;AACR;AAJK,GAAP;AAMA,CARD,CAbuB,CAAT,EAsBVjB,uBAtBU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose, useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nfunction PostSwitchToDraftButton( {\n\tisSaving,\n\tisPublished,\n\tisScheduled,\n\tonClick,\n} ) {\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\n\tif ( ! isPublished && ! isScheduled ) {\n\t\treturn null;\n\t}\n\n\tconst onSwitch = () => {\n\t\tlet alertMessage;\n\t\tif ( isPublished ) {\n\t\t\talertMessage = __(\n\t\t\t\t'Are you sure you want to unpublish this post?'\n\t\t\t);\n\t\t} else if ( isScheduled ) {\n\t\t\talertMessage = __(\n\t\t\t\t'Are you sure you want to unschedule this post?'\n\t\t\t);\n\t\t}\n\t\t// eslint-disable-next-line no-alert\n\t\tif ( window.confirm( alertMessage ) ) {\n\t\t\tonClick();\n\t\t}\n\t};\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"editor-post-switch-to-draft\"\n\t\t\tonClick={ onSwitch }\n\t\t\tdisabled={ isSaving }\n\t\t\tvariant=\"tertiary\"\n\t\t>\n\t\t\t{ isMobileViewport ? __( 'Draft' ) : __( 'Switch to draft' ) }\n\t\t</Button>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst {\n\t\t\tisSavingPost,\n\t\t\tisCurrentPostPublished,\n\t\t\tisCurrentPostScheduled,\n\t\t} = select( editorStore );\n\t\treturn {\n\t\t\tisSaving: isSavingPost(),\n\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { editPost, savePost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonClick: () => {\n\t\t\t\teditPost( { status: 'draft' } );\n\t\t\t\tsavePost();\n\t\t\t},\n\t\t};\n\t} ),\n] )( PostSwitchToDraftButton );\n"]}
|
|
@@ -27,11 +27,12 @@ var _store = require("../../store");
|
|
|
27
27
|
/**
|
|
28
28
|
* Internal dependencies
|
|
29
29
|
*/
|
|
30
|
-
function PostTaxonomiesCheck({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
function PostTaxonomiesCheck(_ref) {
|
|
31
|
+
let {
|
|
32
|
+
postType,
|
|
33
|
+
taxonomies,
|
|
34
|
+
children
|
|
35
|
+
} = _ref;
|
|
35
36
|
const hasTaxonomies = (0, _lodash.some)(taxonomies, taxonomy => (0, _lodash.includes)(taxonomy.types, postType));
|
|
36
37
|
|
|
37
38
|
if (!hasTaxonomies) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/check.js"],"names":["PostTaxonomiesCheck","postType","taxonomies","children","hasTaxonomies","taxonomy","types","select","editorStore","getCurrentPostType","coreStore","getTaxonomies","per_page"],"mappings":";;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAGO,SAASA,mBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/check.js"],"names":["PostTaxonomiesCheck","postType","taxonomies","children","hasTaxonomies","taxonomy","types","select","editorStore","getCurrentPostType","coreStore","getTaxonomies","per_page"],"mappings":";;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAGO,SAASA,mBAAT,OAAmE;AAAA,MAArC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,UAAZ;AAAwBC,IAAAA;AAAxB,GAAqC;AACzE,QAAMC,aAAa,GAAG,kBAAMF,UAAN,EAAoBG,QAAF,IACvC,sBAAUA,QAAQ,CAACC,KAAnB,EAA0BL,QAA1B,CADqB,CAAtB;;AAGA,MAAK,CAAEG,aAAP,EAAuB;AACtB,WAAO,IAAP;AACA;;AAED,SAAOD,QAAP;AACA;;eAEc,sBAAS,CACvB,sBAAcI,MAAF,IAAc;AACzB,SAAO;AACNN,IAAAA,QAAQ,EAAEM,MAAM,CAAEC,YAAF,CAAN,CAAsBC,kBAAtB,EADJ;AAENP,IAAAA,UAAU,EAAEK,MAAM,CAAEG,eAAF,CAAN,CAAoBC,aAApB,CAAmC;AAAEC,MAAAA,QAAQ,EAAE,CAAC;AAAb,KAAnC;AAFN,GAAP;AAIA,CALD,CADuB,CAAT,EAOVZ,mBAPU,C","sourcesContent":["/**\n * External dependencies\n */\nimport { some, includes } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { withSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function PostTaxonomiesCheck( { postType, taxonomies, children } ) {\n\tconst hasTaxonomies = some( taxonomies, ( taxonomy ) =>\n\t\tincludes( taxonomy.types, postType )\n\t);\n\tif ( ! hasTaxonomies ) {\n\t\treturn null;\n\t}\n\n\treturn children;\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\treturn {\n\t\t\tpostType: select( editorStore ).getCurrentPostType(),\n\t\t\ttaxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t};\n\t} ),\n] )( PostTaxonomiesCheck );\n"]}
|
|
@@ -25,6 +25,8 @@ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
|
25
25
|
|
|
26
26
|
var _url = require("@wordpress/url");
|
|
27
27
|
|
|
28
|
+
var _a11y = require("@wordpress/a11y");
|
|
29
|
+
|
|
28
30
|
var _store = require("../../store");
|
|
29
31
|
|
|
30
32
|
var _terms = require("../../utils/terms");
|
|
@@ -43,264 +45,206 @@ var _mostUsedTerms = _interopRequireDefault(require("./most-used-terms"));
|
|
|
43
45
|
* Internal dependencies
|
|
44
46
|
*/
|
|
45
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Shared reference to an empty array for cases where it is important to avoid
|
|
50
|
+
* returning a new array reference on every invocation.
|
|
51
|
+
*
|
|
52
|
+
* @type {Array<any>}
|
|
53
|
+
*/
|
|
54
|
+
const EMPTY_ARRAY = [];
|
|
46
55
|
/**
|
|
47
56
|
* Module constants
|
|
48
57
|
*/
|
|
58
|
+
|
|
49
59
|
const MAX_TERMS_SUGGESTIONS = 20;
|
|
50
60
|
const DEFAULT_QUERY = {
|
|
51
61
|
per_page: MAX_TERMS_SUGGESTIONS,
|
|
52
62
|
orderby: 'count',
|
|
53
63
|
order: 'desc',
|
|
54
|
-
_fields: 'id,name,
|
|
64
|
+
_fields: 'id,name',
|
|
65
|
+
context: 'view'
|
|
55
66
|
};
|
|
56
67
|
|
|
57
68
|
const isSameTermName = (termA, termB) => (0, _terms.unescapeString)(termA).toLowerCase() === (0, _terms.unescapeString)(termB).toLowerCase();
|
|
58
69
|
|
|
59
70
|
const termNamesToIds = (names, terms) => {
|
|
60
71
|
return names.map(termName => (0, _lodash.find)(terms, term => isSameTermName(term.name, termName)).id);
|
|
61
|
-
};
|
|
72
|
+
}; // Tries to create a term or fetch it if it already exists.
|
|
62
73
|
|
|
63
|
-
class FlatTermSelector extends _element.Component {
|
|
64
|
-
constructor() {
|
|
65
|
-
super(...arguments);
|
|
66
|
-
this.onChange = this.onChange.bind(this);
|
|
67
|
-
this.searchTerms = (0, _lodash.debounce)(this.searchTerms.bind(this), 500);
|
|
68
|
-
this.findOrCreateTerm = this.findOrCreateTerm.bind(this);
|
|
69
|
-
this.appendTerm = this.appendTerm.bind(this);
|
|
70
|
-
this.state = {
|
|
71
|
-
loading: !(0, _lodash.isEmpty)(this.props.terms),
|
|
72
|
-
availableTerms: [],
|
|
73
|
-
selectedTerms: []
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
75
|
+
function findOrCreateTerm(termName, restBase) {
|
|
76
|
+
const escapedTermName = (0, _lodash.escape)(termName);
|
|
77
|
+
return (0, _apiFetch.default)({
|
|
78
|
+
path: `/wp/v2/${restBase}`,
|
|
79
|
+
method: 'POST',
|
|
80
|
+
data: {
|
|
81
|
+
name: escapedTermName
|
|
82
|
+
}
|
|
83
|
+
}).catch(error => {
|
|
84
|
+
const errorCode = error.code;
|
|
85
|
+
|
|
86
|
+
if (errorCode === 'term_exists') {
|
|
87
|
+
// If the terms exist, fetch it instead of creating a new one.
|
|
88
|
+
const addRequest = (0, _apiFetch.default)({
|
|
89
|
+
path: (0, _url.addQueryArgs)(`/wp/v2/${restBase}`, { ...DEFAULT_QUERY,
|
|
90
|
+
search: escapedTermName
|
|
91
|
+
})
|
|
92
|
+
}).then(_terms.unescapeTerms);
|
|
93
|
+
return addRequest.then(searchResult => {
|
|
94
|
+
return (0, _lodash.find)(searchResult, result => isSameTermName(result.name, termName));
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
componentWillUnmount() {
|
|
100
|
-
(0, _lodash.invoke)(this.initRequest, ['abort']);
|
|
101
|
-
(0, _lodash.invoke)(this.searchRequest, ['abort']);
|
|
102
|
-
}
|
|
103
97
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
}
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}).then(_terms.unescapeTerm);
|
|
100
|
+
}
|
|
109
101
|
|
|
110
|
-
|
|
102
|
+
function FlatTermSelector(_ref) {
|
|
103
|
+
let {
|
|
104
|
+
slug
|
|
105
|
+
} = _ref;
|
|
106
|
+
const [values, setValues] = (0, _element.useState)([]);
|
|
107
|
+
const [search, setSearch] = (0, _element.useState)('');
|
|
108
|
+
const debouncedSearch = (0, _compose.useDebounce)(setSearch, 500);
|
|
109
|
+
const {
|
|
110
|
+
terms,
|
|
111
|
+
termIds,
|
|
112
|
+
taxonomy,
|
|
113
|
+
hasAssignAction,
|
|
114
|
+
hasCreateAction,
|
|
115
|
+
hasResolvedTerms
|
|
116
|
+
} = (0, _data.useSelect)(select => {
|
|
111
117
|
const {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
this.setState(state => ({
|
|
122
|
-
availableTerms: state.availableTerms.concat(terms.filter(term => !(0, _lodash.find)(state.availableTerms, availableTerm => availableTerm.id === term.id)))
|
|
123
|
-
}));
|
|
124
|
-
this.updateSelectedTerms(this.props.terms);
|
|
125
|
-
});
|
|
126
|
-
return request;
|
|
127
|
-
}
|
|
118
|
+
getCurrentPost,
|
|
119
|
+
getEditedPostAttribute
|
|
120
|
+
} = select(_store.store);
|
|
121
|
+
const {
|
|
122
|
+
getEntityRecords,
|
|
123
|
+
getTaxonomy,
|
|
124
|
+
hasFinishedResolution
|
|
125
|
+
} = select(_coreData.store);
|
|
126
|
+
const post = getCurrentPost();
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
const selectedTerms = terms.reduce((accumulator, termId) => {
|
|
131
|
-
const termObject = (0, _lodash.find)(this.state.availableTerms, term => term.id === termId);
|
|
128
|
+
const _taxonomy = getTaxonomy(slug);
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
accumulator.push(termObject.name);
|
|
135
|
-
}
|
|
130
|
+
const _termIds = _taxonomy ? getEditedPostAttribute(_taxonomy.rest_base) : EMPTY_ARRAY;
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
const query = { ...DEFAULT_QUERY,
|
|
133
|
+
include: _termIds.join(','),
|
|
134
|
+
per_page: -1
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
hasCreateAction: _taxonomy ? (0, _lodash.get)(post, ['_links', 'wp:action-create-' + _taxonomy.rest_base], false) : false,
|
|
138
|
+
hasAssignAction: _taxonomy ? (0, _lodash.get)(post, ['_links', 'wp:action-assign-' + _taxonomy.rest_base], false) : false,
|
|
139
|
+
taxonomy: _taxonomy,
|
|
140
|
+
termIds: _termIds,
|
|
141
|
+
terms: _termIds.length ? getEntityRecords('taxonomy', slug, query) : EMPTY_ARRAY,
|
|
142
|
+
hasResolvedTerms: hasFinishedResolution('getEntityRecords', ['taxonomy', slug, query])
|
|
143
|
+
};
|
|
144
|
+
}, [slug]);
|
|
145
|
+
const {
|
|
146
|
+
searchResults
|
|
147
|
+
} = (0, _data.useSelect)(select => {
|
|
148
|
+
const {
|
|
149
|
+
getEntityRecords
|
|
150
|
+
} = select(_coreData.store);
|
|
151
|
+
return {
|
|
152
|
+
searchResults: !!search ? getEntityRecords('taxonomy', slug, { ...DEFAULT_QUERY,
|
|
153
|
+
search
|
|
154
|
+
}) : EMPTY_ARRAY
|
|
155
|
+
};
|
|
156
|
+
}, [search]); // Update terms state only after the selectors are resolved.
|
|
157
|
+
// We're using this to avoid terms temporarily disappearing on slow networks
|
|
158
|
+
// while core data makes REST API requests.
|
|
159
|
+
|
|
160
|
+
(0, _element.useEffect)(() => {
|
|
161
|
+
if (hasResolvedTerms) {
|
|
162
|
+
const newValues = terms.map(term => (0, _terms.unescapeString)(term.name));
|
|
163
|
+
setValues(newValues);
|
|
164
|
+
}
|
|
165
|
+
}, [terms, hasResolvedTerms]);
|
|
166
|
+
const suggestions = (0, _element.useMemo)(() => {
|
|
167
|
+
return (searchResults !== null && searchResults !== void 0 ? searchResults : []).map(term => (0, _terms.unescapeString)(term.name));
|
|
168
|
+
}, [searchResults]);
|
|
169
|
+
const {
|
|
170
|
+
editPost
|
|
171
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
172
|
+
|
|
173
|
+
if (!hasAssignAction) {
|
|
174
|
+
return null;
|
|
142
175
|
}
|
|
143
176
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
taxonomy
|
|
147
|
-
}
|
|
148
|
-
const termNameEscaped = (0, _lodash.escape)(termName); // Tries to create a term or fetch it if it already exists.
|
|
149
|
-
|
|
150
|
-
return (0, _apiFetch.default)({
|
|
151
|
-
path: `/wp/v2/${taxonomy.rest_base}`,
|
|
152
|
-
method: 'POST',
|
|
153
|
-
data: {
|
|
154
|
-
name: termNameEscaped
|
|
155
|
-
}
|
|
156
|
-
}).catch(error => {
|
|
157
|
-
const errorCode = error.code;
|
|
158
|
-
|
|
159
|
-
if (errorCode === 'term_exists') {
|
|
160
|
-
// If the terms exist, fetch it instead of creating a new one.
|
|
161
|
-
this.addRequest = (0, _apiFetch.default)({
|
|
162
|
-
path: (0, _url.addQueryArgs)(`/wp/v2/${taxonomy.rest_base}`, { ...DEFAULT_QUERY,
|
|
163
|
-
search: termNameEscaped
|
|
164
|
-
})
|
|
165
|
-
}).then(_terms.unescapeTerms);
|
|
166
|
-
return this.addRequest.then(searchResult => {
|
|
167
|
-
return (0, _lodash.find)(searchResult, result => isSameTermName(result.name, termName));
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return Promise.reject(error);
|
|
172
|
-
}).then(_terms.unescapeTerm);
|
|
177
|
+
function onUpdateTerms(newTermIds) {
|
|
178
|
+
editPost({
|
|
179
|
+
[taxonomy.rest_base]: newTermIds
|
|
180
|
+
});
|
|
173
181
|
}
|
|
174
182
|
|
|
175
|
-
onChange(termNames) {
|
|
183
|
+
function onChange(termNames) {
|
|
184
|
+
const availableTerms = [...terms, ...(searchResults !== null && searchResults !== void 0 ? searchResults : [])];
|
|
176
185
|
const uniqueTerms = (0, _lodash.uniqBy)(termNames, term => term.toLowerCase());
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
const newTermNames = uniqueTerms.filter(termName => !(0, _lodash.find)(availableTerms, term => isSameTermName(term.name, termName))); // Optimistically update term values.
|
|
187
|
+
// The selector will always re-fetch terms later.
|
|
188
|
+
|
|
189
|
+
setValues(uniqueTerms);
|
|
181
190
|
|
|
182
191
|
if (newTermNames.length === 0) {
|
|
183
|
-
return
|
|
192
|
+
return onUpdateTerms(termNamesToIds(uniqueTerms, availableTerms));
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
this.setState({
|
|
189
|
-
availableTerms: newAvailableTerms
|
|
190
|
-
});
|
|
191
|
-
return this.props.onUpdateTerms(termNamesToIds(uniqueTerms, newAvailableTerms), this.props.taxonomy.rest_base);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
searchTerms(search = '') {
|
|
196
|
-
(0, _lodash.invoke)(this.searchRequest, ['abort']);
|
|
197
|
-
|
|
198
|
-
if (search.length >= 3) {
|
|
199
|
-
this.searchRequest = this.fetchTerms({
|
|
200
|
-
search
|
|
201
|
-
});
|
|
195
|
+
if (!hasCreateAction) {
|
|
196
|
+
return;
|
|
202
197
|
}
|
|
198
|
+
|
|
199
|
+
Promise.all(newTermNames.map(termName => findOrCreateTerm(termName, taxonomy.rest_base))).then(newTerms => {
|
|
200
|
+
const newAvailableTerms = availableTerms.concat(newTerms);
|
|
201
|
+
return onUpdateTerms(termNamesToIds(uniqueTerms, newAvailableTerms));
|
|
202
|
+
});
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
appendTerm(newTerm) {
|
|
206
|
-
|
|
207
|
-
onUpdateTerms,
|
|
208
|
-
taxonomy,
|
|
209
|
-
terms = [],
|
|
210
|
-
slug,
|
|
211
|
-
speak
|
|
212
|
-
} = this.props;
|
|
213
|
-
|
|
214
|
-
if (terms.includes(newTerm.id)) {
|
|
205
|
+
function appendTerm(newTerm) {
|
|
206
|
+
if (termIds.includes(newTerm.id)) {
|
|
215
207
|
return;
|
|
216
208
|
}
|
|
217
209
|
|
|
218
|
-
const
|
|
210
|
+
const newTermIds = [...termIds, newTerm.id];
|
|
219
211
|
const termAddedMessage = (0, _i18n.sprintf)(
|
|
220
212
|
/* translators: %s: term name. */
|
|
221
213
|
(0, _i18n._x)('%s added', 'term'), (0, _lodash.get)(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? (0, _i18n.__)('Tag') : (0, _i18n.__)('Term')));
|
|
222
|
-
speak(termAddedMessage, 'assertive');
|
|
223
|
-
|
|
224
|
-
availableTerms: [...this.state.availableTerms, newTerm]
|
|
225
|
-
});
|
|
226
|
-
onUpdateTerms(newTerms, taxonomy.rest_base);
|
|
214
|
+
(0, _a11y.speak)(termAddedMessage, 'assertive');
|
|
215
|
+
onUpdateTerms(newTermIds);
|
|
227
216
|
}
|
|
228
217
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
218
|
+
const newTermLabel = (0, _lodash.get)(taxonomy, ['labels', 'add_new_item'], slug === 'post_tag' ? (0, _i18n.__)('Add new tag') : (0, _i18n.__)('Add new Term'));
|
|
219
|
+
const singularName = (0, _lodash.get)(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? (0, _i18n.__)('Tag') : (0, _i18n.__)('Term'));
|
|
220
|
+
const termAddedLabel = (0, _i18n.sprintf)(
|
|
221
|
+
/* translators: %s: term name. */
|
|
222
|
+
(0, _i18n._x)('%s added', 'term'), singularName);
|
|
223
|
+
const termRemovedLabel = (0, _i18n.sprintf)(
|
|
224
|
+
/* translators: %s: term name. */
|
|
225
|
+
(0, _i18n._x)('%s removed', 'term'), singularName);
|
|
226
|
+
const removeTermLabel = (0, _i18n.sprintf)(
|
|
227
|
+
/* translators: %s: term name. */
|
|
228
|
+
(0, _i18n._x)('Remove %s', 'term'), singularName);
|
|
229
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.FormTokenField, {
|
|
230
|
+
value: values,
|
|
231
|
+
suggestions: suggestions,
|
|
232
|
+
onChange: onChange,
|
|
233
|
+
onInputChange: debouncedSearch,
|
|
234
|
+
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
235
|
+
label: newTermLabel,
|
|
236
|
+
messages: {
|
|
237
|
+
added: termAddedLabel,
|
|
238
|
+
removed: termRemovedLabel,
|
|
239
|
+
remove: removeTermLabel
|
|
238
240
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
selectedTerms
|
|
244
|
-
} = this.state;
|
|
245
|
-
const termNames = availableTerms.map(term => term.name);
|
|
246
|
-
const newTermLabel = (0, _lodash.get)(taxonomy, ['labels', 'add_new_item'], slug === 'post_tag' ? (0, _i18n.__)('Add new tag') : (0, _i18n.__)('Add new Term'));
|
|
247
|
-
const singularName = (0, _lodash.get)(taxonomy, ['labels', 'singular_name'], slug === 'post_tag' ? (0, _i18n.__)('Tag') : (0, _i18n.__)('Term'));
|
|
248
|
-
const termAddedLabel = (0, _i18n.sprintf)(
|
|
249
|
-
/* translators: %s: term name. */
|
|
250
|
-
(0, _i18n._x)('%s added', 'term'), singularName);
|
|
251
|
-
const termRemovedLabel = (0, _i18n.sprintf)(
|
|
252
|
-
/* translators: %s: term name. */
|
|
253
|
-
(0, _i18n._x)('%s removed', 'term'), singularName);
|
|
254
|
-
const removeTermLabel = (0, _i18n.sprintf)(
|
|
255
|
-
/* translators: %s: term name. */
|
|
256
|
-
(0, _i18n._x)('Remove %s', 'term'), singularName);
|
|
257
|
-
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.FormTokenField, {
|
|
258
|
-
value: selectedTerms,
|
|
259
|
-
suggestions: termNames,
|
|
260
|
-
onChange: this.onChange,
|
|
261
|
-
onInputChange: this.searchTerms,
|
|
262
|
-
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
263
|
-
disabled: loading,
|
|
264
|
-
label: newTermLabel,
|
|
265
|
-
messages: {
|
|
266
|
-
added: termAddedLabel,
|
|
267
|
-
removed: termRemovedLabel,
|
|
268
|
-
remove: removeTermLabel
|
|
269
|
-
}
|
|
270
|
-
}), (0, _element.createElement)(_mostUsedTerms.default, {
|
|
271
|
-
taxonomy: taxonomy,
|
|
272
|
-
onSelect: this.appendTerm
|
|
273
|
-
}));
|
|
274
|
-
}
|
|
275
|
-
|
|
241
|
+
}), (0, _element.createElement)(_mostUsedTerms.default, {
|
|
242
|
+
taxonomy: taxonomy,
|
|
243
|
+
onSelect: appendTerm
|
|
244
|
+
}));
|
|
276
245
|
}
|
|
277
246
|
|
|
278
|
-
var _default = (0,
|
|
279
|
-
slug
|
|
280
|
-
}) => {
|
|
281
|
-
const {
|
|
282
|
-
getCurrentPost
|
|
283
|
-
} = select(_store.store);
|
|
284
|
-
const {
|
|
285
|
-
getTaxonomy
|
|
286
|
-
} = select(_coreData.store);
|
|
287
|
-
const taxonomy = getTaxonomy(slug);
|
|
288
|
-
return {
|
|
289
|
-
hasCreateAction: taxonomy ? (0, _lodash.get)(getCurrentPost(), ['_links', 'wp:action-create-' + taxonomy.rest_base], false) : false,
|
|
290
|
-
hasAssignAction: taxonomy ? (0, _lodash.get)(getCurrentPost(), ['_links', 'wp:action-assign-' + taxonomy.rest_base], false) : false,
|
|
291
|
-
terms: taxonomy ? select(_store.store).getEditedPostAttribute(taxonomy.rest_base) : [],
|
|
292
|
-
taxonomy
|
|
293
|
-
};
|
|
294
|
-
}), (0, _data.withDispatch)(dispatch => {
|
|
295
|
-
return {
|
|
296
|
-
onUpdateTerms(terms, restBase) {
|
|
297
|
-
dispatch(_store.store).editPost({
|
|
298
|
-
[restBase]: terms
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
};
|
|
303
|
-
}), _components.withSpokenMessages, (0, _components.withFilters)('editor.PostTaxonomyType'))(FlatTermSelector);
|
|
247
|
+
var _default = (0, _components.withFilters)('editor.PostTaxonomyType')(FlatTermSelector);
|
|
304
248
|
|
|
305
249
|
exports.default = _default;
|
|
306
250
|
//# sourceMappingURL=flat-term-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"names":["MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","orderby","order","_fields","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","term","name","id","FlatTermSelector","Component","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","unescapeTerms","concat","filter","availableTerm","reduce","accumulator","termId","termObject","push","termNameEscaped","method","data","catch","error","errorCode","code","addRequest","search","searchResult","result","Promise","reject","unescapeTerm","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","editorStore","getTaxonomy","coreStore","hasCreateAction","getEditedPostAttribute","dispatch","restBase","editPost","withSpokenMessages"],"mappings":";;;;;;;;;AAiBA;;AAdA;;AAaA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAlCA;AACA;AACA;;AAWA;AACA;AACA;;AAcA;AACA;AACA;;AAKA;AACA;AACA;AACA,MAAMA,qBAAqB,GAAG,EAA9B;AACA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAEF,qBADW;AAErBG,EAAAA,OAAO,EAAE,OAFY;AAGrBC,EAAAA,KAAK,EAAE,MAHc;AAIrBC,EAAAA,OAAO,EAAE;AAJY,CAAtB;;AAOA,MAAMC,cAAc,GAAG,CAAEC,KAAF,EAASC,KAAT,KACtB,2BAAgBD,KAAhB,EAAwBE,WAAxB,OACA,2BAAgBD,KAAhB,EAAwBC,WAAxB,EAFD;;AAIA,MAAMC,cAAc,GAAG,CAAEC,KAAF,EAASC,KAAT,KAAoB;AAC1C,SAAOD,KAAK,CAACE,GAAN,CACJC,QAAF,IACC,kBAAMF,KAAN,EAAeG,IAAF,IA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Cc,EAqCZ1F,gBArCY,C","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":["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","unescapeTerms","searchResult","result","Promise","reject","unescapeTerm","FlatTermSelector","slug","values","setValues","setSearch","debouncedSearch","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","getCurrentPost","getEditedPostAttribute","editorStore","getEntityRecords","getTaxonomy","hasFinishedResolution","coreStore","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":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AACA,MAAMC,qBAAqB,GAAG,EAA9B;AACA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAEF,qBADW;AAErBG,EAAAA,OAAO,EAAE,OAFY;AAGrBC,EAAAA,KAAK,EAAE,MAHc;AAIrBC,EAAAA,OAAO,EAAE,SAJY;AAKrBC,EAAAA,OAAO,EAAE;AALY,CAAtB;;AAQA,MAAMC,cAAc,GAAG,CAAEC,KAAF,EAASC,KAAT,KACtB,2BAAgBD,KAAhB,EAAwBE,WAAxB,OACA,2BAAgBD,KAAhB,EAAwBC,WAAxB,EAFD;;AAIA,MAAMC,cAAc,GAAG,CAAEC,KAAF,EAASC,KAAT,KAAoB;AAC1C,SAAOD,KAAK,CAACE,GAAN,CACJC,QAAF,IACC,kBAAMF,KAAN,EAAeG,IAAF,IAAYT,cAAc,CAAES,IAAI,CAACC,IAAP,EAAaF,QAAb,CAAvC,EAAiEG,EAF5D,CAAP;AAIA,CALD,C,CAOA;;;AACA,SAASC,gBAAT,CAA2BJ,QAA3B,EAAqCK,QAArC,EAAgD;AAC/C,QAAMC,eAAe,GAAG,oBAAcN,QAAd,CAAxB;AAEA,SAAO,uBAAU;AAChBO,IAAAA,IAAI,EAAG,UAAUF,QAAU,EADX;AAEhBG,IAAAA,MAAM,EAAE,MAFQ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qBy } 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"]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
exports.findTerm = findTerm;
|
|
8
8
|
exports.getFilterMatcher = getFilterMatcher;
|
|
9
|
-
exports.
|
|
9
|
+
exports.sortBySelected = sortBySelected;
|
|
10
10
|
|
|
11
11
|
var _element = require("@wordpress/element");
|
|
12
12
|
|
|
@@ -158,9 +158,10 @@ function getFilterMatcher(filterValue) {
|
|
|
158
158
|
*/
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
function HierarchicalTermSelector({
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
function HierarchicalTermSelector(_ref) {
|
|
162
|
+
let {
|
|
163
|
+
slug
|
|
164
|
+
} = _ref;
|
|
164
165
|
const [adding, setAdding] = (0, _element.useState)(false);
|
|
165
166
|
const [formName, setFormName] = (0, _element.useState)('');
|
|
166
167
|
/**
|