@wordpress/editor 14.13.0 → 14.13.1-next.a9f418477.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -28
- package/build/bindings/post-meta.js +2 -3
- package/build/bindings/post-meta.js.map +1 -1
- package/build/components/autocompleters/user.js +1 -3
- package/build/components/autocompleters/user.js.map +1 -1
- package/build/components/collab-sidebar/constants.js +2 -1
- package/build/components/collab-sidebar/constants.js.map +1 -1
- package/build/components/collab-sidebar/index.js +108 -43
- package/build/components/collab-sidebar/index.js.map +1 -1
- package/build/components/collab-sidebar/utils.js +32 -0
- package/build/components/collab-sidebar/utils.js.map +1 -1
- package/build/components/document-bar/index.js +3 -1
- package/build/components/document-bar/index.js.map +1 -1
- package/build/components/entities-saved-states/index.js +6 -6
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/error-boundary/index.js +26 -13
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/header/index.js +5 -2
- package/build/components/header/index.js.map +1 -1
- package/build/components/index.js +10 -26
- package/build/components/index.js.map +1 -1
- package/build/components/post-actions/actions.js +29 -2
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +1 -1
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-actions/set-as-homepage.js +170 -0
- package/build/components/post-actions/set-as-homepage.js.map +1 -0
- package/build/components/post-author/constants.js +1 -1
- package/build/components/post-author/constants.js.map +1 -1
- package/build/components/post-author/hook.js +1 -0
- package/build/components/post-author/hook.js.map +1 -1
- package/build/components/post-card-panel/index.js +1 -3
- package/build/components/post-card-panel/index.js.map +1 -1
- package/build/components/post-fields/index.js +3 -3
- package/build/components/post-fields/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +4 -2
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/post-publish-button-or-toggle.js +32 -37
- package/build/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/post-publish-panel/maybe-upload-media.js +0 -1
- package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build/components/post-publish-panel/media-util.js +0 -1
- package/build/components/post-publish-panel/media-util.js.map +1 -1
- package/build/components/post-publish-panel/postpublish.js +103 -117
- package/build/components/post-publish-panel/postpublish.js.map +1 -1
- package/build/components/post-publish-panel/prepublish.js +1 -1
- package/build/components/post-publish-panel/prepublish.js.map +1 -1
- package/build/components/post-trash/check.js +4 -4
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-url/index.js +2 -1
- package/build/components/post-url/index.js.map +1 -1
- package/build/components/provider/index.js +9 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/save-publish-panels/index.js +3 -1
- package/build/components/save-publish-panels/index.js.map +1 -1
- package/build/components/template-part-menu-items/convert-to-template-part.js +2 -3
- package/build/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
- package/build/components/visual-editor/index.js +2 -1
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/dataviews/store/private-actions.js +17 -9
- package/build/dataviews/store/private-actions.js.map +1 -1
- package/build/private-apis.js +2 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/constants.js +0 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/private-actions.js +0 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/selectors.js +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build/utils/pageTypeBadge.js +3 -10
- package/build/utils/pageTypeBadge.js.map +1 -1
- package/build-module/bindings/post-meta.js +2 -3
- package/build-module/bindings/post-meta.js.map +1 -1
- package/build-module/components/autocompleters/user.js +1 -3
- package/build-module/components/autocompleters/user.js.map +1 -1
- package/build-module/components/collab-sidebar/constants.js +1 -0
- package/build-module/components/collab-sidebar/constants.js.map +1 -1
- package/build-module/components/collab-sidebar/index.js +111 -46
- package/build-module/components/collab-sidebar/index.js.map +1 -1
- package/build-module/components/collab-sidebar/utils.js +31 -0
- package/build-module/components/collab-sidebar/utils.js.map +1 -1
- package/build-module/components/document-bar/index.js +3 -1
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +6 -6
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +28 -15
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/header/index.js +5 -2
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/index.js +0 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/post-actions/actions.js +29 -2
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +1 -1
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-actions/set-as-homepage.js +162 -0
- package/build-module/components/post-actions/set-as-homepage.js.map +1 -0
- package/build-module/components/post-author/constants.js +1 -1
- package/build-module/components/post-author/constants.js.map +1 -1
- package/build-module/components/post-author/hook.js +1 -0
- package/build-module/components/post-author/hook.js.map +1 -1
- package/build-module/components/post-card-panel/index.js +1 -3
- package/build-module/components/post-card-panel/index.js.map +1 -1
- package/build-module/components/post-fields/index.js +3 -3
- package/build-module/components/post-fields/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +4 -2
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js +34 -38
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js +0 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build-module/components/post-publish-panel/media-util.js +0 -1
- package/build-module/components/post-publish-panel/media-util.js.map +1 -1
- package/build-module/components/post-publish-panel/postpublish.js +104 -118
- package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
- package/build-module/components/post-publish-panel/prepublish.js +1 -1
- package/build-module/components/post-publish-panel/prepublish.js.map +1 -1
- package/build-module/components/post-trash/check.js +4 -4
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-url/index.js +2 -1
- package/build-module/components/post-url/index.js.map +1 -1
- package/build-module/components/provider/index.js +10 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/save-publish-panels/index.js +3 -1
- package/build-module/components/save-publish-panels/index.js.map +1 -1
- package/build-module/components/template-part-menu-items/convert-to-template-part.js +1 -1
- package/build-module/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
- package/build-module/components/visual-editor/index.js +2 -1
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/dataviews/store/private-actions.js +17 -9
- package/build-module/dataviews/store/private-actions.js.map +1 -1
- package/build-module/private-apis.js +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/constants.js +0 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/private-actions.js +0 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/pageTypeBadge.js +3 -10
- package/build-module/utils/pageTypeBadge.js.map +1 -1
- package/build-style/style-rtl.css +41 -64
- package/build-style/style.css +41 -64
- package/build-types/bindings/post-meta.d.ts.map +1 -1
- package/build-types/components/autocompleters/user.d.ts +7 -3
- package/build-types/components/autocompleters/user.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/constants.d.ts +1 -0
- package/build-types/components/collab-sidebar/constants.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/utils.d.ts +10 -0
- package/build-types/components/collab-sidebar/utils.d.ts.map +1 -1
- package/build-types/components/document-bar/index.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/index.d.ts +5 -5
- package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
- package/build-types/components/error-boundary/index.d.ts.map +1 -1
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/index.d.ts +0 -2
- package/build-types/components/index.d.ts.map +1 -1
- package/build-types/components/keyboard-shortcut-help-modal/shortcut.d.ts +1 -1
- package/build-types/components/media-categories/index.d.ts.map +1 -1
- package/build-types/components/pattern-duplicate-modal/index.d.ts.map +1 -1
- package/build-types/components/pattern-rename-modal/index.d.ts.map +1 -1
- package/build-types/components/post-actions/actions.d.ts +1 -1
- package/build-types/components/post-actions/actions.d.ts.map +1 -1
- package/build-types/components/post-actions/set-as-homepage.d.ts +10 -0
- package/build-types/components/post-actions/set-as-homepage.d.ts.map +1 -0
- package/build-types/components/post-author/hook.d.ts.map +1 -1
- package/build-types/components/post-card-panel/index.d.ts.map +1 -1
- package/build-types/components/post-fields/index.d.ts +3 -1
- package/build-types/components/post-fields/index.d.ts.map +1 -1
- package/build-types/components/post-publish-button/index.d.ts.map +1 -1
- package/build-types/components/post-publish-button/post-publish-button-or-toggle.d.ts +1 -13
- package/build-types/components/post-publish-button/post-publish-button-or-toggle.d.ts.map +1 -1
- package/build-types/components/post-publish-panel/postpublish.d.ts +4 -2
- package/build-types/components/post-publish-panel/postpublish.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/flat-term-selector.d.ts +4 -4
- package/build-types/components/post-taxonomies/flat-term-selector.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts +4 -4
- package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts.map +1 -1
- package/build-types/components/post-title/constants.d.ts.map +1 -1
- package/build-types/components/post-trash/check.d.ts +6 -6
- package/build-types/components/post-trash/check.d.ts.map +1 -1
- package/build-types/components/post-url/index.d.ts +5 -2
- package/build-types/components/post-url/index.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/save-publish-panels/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/dataviews/api.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/dataviews/store/reducer.d.ts +1 -1
- package/build-types/hooks/custom-sources-backwards-compatibility.d.ts.map +1 -1
- package/build-types/hooks/pattern-overrides.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -2
- package/build-types/store/actions.d.ts +7 -9
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts +1 -1
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +1 -1
- package/build-types/store/selectors.d.ts +2 -2
- package/build-types/store/selectors.d.ts.map +1 -1
- package/build-types/utils/pageTypeBadge.d.ts +3 -1
- package/build-types/utils/pageTypeBadge.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/bindings/post-meta.js +2 -5
- package/src/components/autocompleters/user.js +1 -3
- package/src/components/collab-sidebar/constants.js +1 -0
- package/src/components/collab-sidebar/index.js +115 -47
- package/src/components/collab-sidebar/style.scss +13 -0
- package/src/components/collab-sidebar/utils.js +36 -0
- package/src/components/document-bar/index.js +3 -1
- package/src/components/editor-interface/style.scss +2 -1
- package/src/components/entities-saved-states/index.js +6 -9
- package/src/components/error-boundary/index.js +30 -16
- package/src/components/error-boundary/style.scss +5 -1
- package/src/components/header/index.js +17 -5
- package/src/components/header/style.scss +1 -1
- package/src/components/index.js +0 -2
- package/src/components/post-actions/actions.js +38 -2
- package/src/components/post-actions/index.js +1 -1
- package/src/components/post-actions/set-as-homepage.js +183 -0
- package/src/components/post-author/constants.js +1 -1
- package/src/components/post-author/hook.js +1 -0
- package/src/components/post-card-panel/index.js +1 -3
- package/src/components/post-card-panel/style.scss +1 -0
- package/src/components/post-fields/index.ts +5 -3
- package/src/components/post-publish-button/index.js +2 -0
- package/src/components/post-publish-button/post-publish-button-or-toggle.js +38 -40
- package/src/components/post-publish-button/test/post-publish-button-or-toggle.js +24 -9
- package/src/components/post-publish-panel/postpublish.js +114 -124
- package/src/components/post-publish-panel/prepublish.js +1 -1
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +2 -2
- package/src/components/post-trash/check.js +4 -4
- package/src/components/post-url/index.js +2 -1
- package/src/components/provider/index.js +17 -3
- package/src/components/save-publish-panels/index.js +5 -1
- package/src/components/template-part-menu-items/convert-to-template-part.js +1 -1
- package/src/components/visual-editor/index.js +1 -0
- package/src/components/visual-editor/style.scss +29 -6
- package/src/dataviews/store/private-actions.ts +36 -20
- package/src/private-apis.js +1 -1
- package/src/store/selectors.js +1 -1
- package/src/style.scss +0 -2
- package/src/utils/pageTypeBadge.js +3 -8
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/create-template-part-modal/index.js +0 -170
- package/build/components/create-template-part-modal/index.js.map +0 -1
- package/build/components/create-template-part-modal/utils.js +0 -64
- package/build/components/create-template-part-modal/utils.js.map +0 -1
- package/build/components/post-slug/check.js +0 -29
- package/build/components/post-slug/check.js.map +0 -1
- package/build/components/post-slug/index.js +0 -79
- package/build/components/post-slug/index.js.map +0 -1
- package/build/components/post-slug/panel.js +0 -30
- package/build/components/post-slug/panel.js.map +0 -1
- package/build/dataviews/actions/duplicate-template-part.js +0 -67
- package/build/dataviews/actions/duplicate-template-part.js.map +0 -1
- package/build/dataviews/actions/utils.js +0 -58
- package/build/dataviews/actions/utils.js.map +0 -1
- package/build/dataviews/types.js +0 -6
- package/build/dataviews/types.js.map +0 -1
- package/build-module/components/create-template-part-modal/index.js +0 -162
- package/build-module/components/create-template-part-modal/index.js.map +0 -1
- package/build-module/components/create-template-part-modal/utils.js +0 -54
- package/build-module/components/create-template-part-modal/utils.js.map +0 -1
- package/build-module/components/post-slug/check.js +0 -23
- package/build-module/components/post-slug/check.js.map +0 -1
- package/build-module/components/post-slug/index.js +0 -71
- package/build-module/components/post-slug/index.js.map +0 -1
- package/build-module/components/post-slug/panel.js +0 -21
- package/build-module/components/post-slug/panel.js.map +0 -1
- package/build-module/dataviews/actions/duplicate-template-part.js +0 -58
- package/build-module/dataviews/actions/duplicate-template-part.js.map +0 -1
- package/build-module/dataviews/actions/utils.js +0 -47
- package/build-module/dataviews/actions/utils.js.map +0 -1
- package/build-module/dataviews/types.js +0 -2
- package/build-module/dataviews/types.js.map +0 -1
- package/build-types/components/create-template-part-modal/index.d.ts +0 -14
- package/build-types/components/create-template-part-modal/index.d.ts.map +0 -1
- package/build-types/components/create-template-part-modal/utils.d.ts +0 -4
- package/build-types/components/create-template-part-modal/utils.d.ts.map +0 -1
- package/build-types/components/post-slug/check.d.ts +0 -12
- package/build-types/components/post-slug/check.d.ts.map +0 -1
- package/build-types/components/post-slug/index.d.ts +0 -7
- package/build-types/components/post-slug/index.d.ts.map +0 -1
- package/build-types/components/post-slug/panel.d.ts +0 -3
- package/build-types/components/post-slug/panel.d.ts.map +0 -1
- package/build-types/dataviews/actions/duplicate-template-part.d.ts +0 -5
- package/build-types/dataviews/actions/duplicate-template-part.d.ts.map +0 -1
- package/build-types/dataviews/actions/utils.d.ts +0 -13
- package/build-types/dataviews/actions/utils.d.ts.map +0 -1
- package/build-types/dataviews/types.d.ts +0 -92
- package/build-types/dataviews/types.d.ts.map +0 -1
- package/src/components/create-template-part-modal/index.js +0 -210
- package/src/components/create-template-part-modal/style.scss +0 -63
- package/src/components/create-template-part-modal/test/utils.js +0 -60
- package/src/components/create-template-part-modal/utils.js +0 -67
- package/src/components/post-slug/check.js +0 -20
- package/src/components/post-slug/index.js +0 -73
- package/src/components/post-slug/panel.js +0 -22
- package/src/components/post-slug/style.scss +0 -5
- package/src/components/post-slug/test/index.js +0 -53
- package/src/dataviews/actions/duplicate-template-part.tsx +0 -70
- package/src/dataviews/actions/utils.ts +0 -64
- package/src/dataviews/types.ts +0 -85
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/dataviews/actions/utils.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE7D,wBAAgB,UAAU,CAAE,IAAI,EAAE,IAAI,GAAI,IAAI,IAAI,QAAQ,CAEzD;AAED,wBAAgB,cAAc,CAAE,IAAI,EAAE,IAAI,GAAI,IAAI,IAAI,YAAY,CAEjE;AAED,wBAAgB,wBAAwB,CACvC,CAAC,EAAE,IAAI,GACL,CAAC,IAAI,QAAQ,GAAG,YAAY,CAE9B;AAED,wBAAgB,YAAY,CAAE,IAAI,EAAE,IAAI,UAWvC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAE,QAAQ,EAAE,QAAQ,GAAG,YAAY,WAcrE"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
type PostStatus = 'published' | 'draft' | 'pending' | 'private' | 'future' | 'auto-draft' | 'trash';
|
|
2
|
-
export interface CommonPost {
|
|
3
|
-
status?: PostStatus;
|
|
4
|
-
title: string | {
|
|
5
|
-
rendered: string;
|
|
6
|
-
} | {
|
|
7
|
-
raw: string;
|
|
8
|
-
};
|
|
9
|
-
content: string | {
|
|
10
|
-
raw: string;
|
|
11
|
-
rendered: string;
|
|
12
|
-
};
|
|
13
|
-
type: string;
|
|
14
|
-
id: string | number;
|
|
15
|
-
blocks?: Object[];
|
|
16
|
-
_links?: Links;
|
|
17
|
-
}
|
|
18
|
-
interface Links {
|
|
19
|
-
'predecessor-version'?: {
|
|
20
|
-
href: string;
|
|
21
|
-
id: number;
|
|
22
|
-
}[];
|
|
23
|
-
'version-history'?: {
|
|
24
|
-
href: string;
|
|
25
|
-
count: number;
|
|
26
|
-
}[];
|
|
27
|
-
[key: string]: {
|
|
28
|
-
href: string;
|
|
29
|
-
}[] | undefined;
|
|
30
|
-
}
|
|
31
|
-
export interface BasePost extends CommonPost {
|
|
32
|
-
comment_status?: 'open' | 'closed';
|
|
33
|
-
excerpt?: string | {
|
|
34
|
-
raw: string;
|
|
35
|
-
rendered: string;
|
|
36
|
-
};
|
|
37
|
-
meta?: Record<string, any>;
|
|
38
|
-
parent?: number;
|
|
39
|
-
password?: string;
|
|
40
|
-
template?: string;
|
|
41
|
-
format?: string;
|
|
42
|
-
featured_media?: number;
|
|
43
|
-
menu_order?: number;
|
|
44
|
-
ping_status?: 'open' | 'closed';
|
|
45
|
-
link?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface Template extends CommonPost {
|
|
48
|
-
type: 'wp_template';
|
|
49
|
-
is_custom: boolean;
|
|
50
|
-
source: string;
|
|
51
|
-
origin: string;
|
|
52
|
-
plugin?: string;
|
|
53
|
-
has_theme_file: boolean;
|
|
54
|
-
id: string;
|
|
55
|
-
}
|
|
56
|
-
export interface TemplatePart extends CommonPost {
|
|
57
|
-
type: 'wp_template_part';
|
|
58
|
-
source: string;
|
|
59
|
-
origin: string;
|
|
60
|
-
has_theme_file: boolean;
|
|
61
|
-
id: string;
|
|
62
|
-
area: string;
|
|
63
|
-
}
|
|
64
|
-
export interface Pattern extends CommonPost {
|
|
65
|
-
slug: string;
|
|
66
|
-
title: {
|
|
67
|
-
raw: string;
|
|
68
|
-
};
|
|
69
|
-
wp_pattern_sync_status: string;
|
|
70
|
-
}
|
|
71
|
-
export type Post = Template | TemplatePart | Pattern | BasePost;
|
|
72
|
-
export type PostWithPermissions = Post & {
|
|
73
|
-
permissions: {
|
|
74
|
-
delete: boolean;
|
|
75
|
-
update: boolean;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
export interface PostType {
|
|
79
|
-
slug: string;
|
|
80
|
-
viewable: boolean;
|
|
81
|
-
supports?: {
|
|
82
|
-
'page-attributes'?: boolean;
|
|
83
|
-
title?: boolean;
|
|
84
|
-
revisions?: boolean;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export type CoreDataError = {
|
|
88
|
-
message?: string;
|
|
89
|
-
code?: string;
|
|
90
|
-
};
|
|
91
|
-
export {};
|
|
92
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dataviews/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
Icon,
|
|
7
|
-
BaseControl,
|
|
8
|
-
TextControl,
|
|
9
|
-
Flex,
|
|
10
|
-
FlexItem,
|
|
11
|
-
FlexBlock,
|
|
12
|
-
Button,
|
|
13
|
-
Modal,
|
|
14
|
-
__experimentalRadioGroup as RadioGroup,
|
|
15
|
-
__experimentalRadio as Radio,
|
|
16
|
-
__experimentalHStack as HStack,
|
|
17
|
-
__experimentalVStack as VStack,
|
|
18
|
-
} from '@wordpress/components';
|
|
19
|
-
import { __ } from '@wordpress/i18n';
|
|
20
|
-
import { useState } from '@wordpress/element';
|
|
21
|
-
import { useInstanceId } from '@wordpress/compose';
|
|
22
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
23
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
24
|
-
import { check } from '@wordpress/icons';
|
|
25
|
-
import { serialize } from '@wordpress/blocks';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Internal dependencies
|
|
29
|
-
*/
|
|
30
|
-
import {
|
|
31
|
-
TEMPLATE_PART_POST_TYPE,
|
|
32
|
-
TEMPLATE_PART_AREA_DEFAULT_CATEGORY,
|
|
33
|
-
} from '../../store/constants';
|
|
34
|
-
import {
|
|
35
|
-
useExistingTemplateParts,
|
|
36
|
-
getUniqueTemplatePartTitle,
|
|
37
|
-
getCleanTemplatePartSlug,
|
|
38
|
-
} from './utils';
|
|
39
|
-
|
|
40
|
-
export default function CreateTemplatePartModal( {
|
|
41
|
-
modalTitle,
|
|
42
|
-
...restProps
|
|
43
|
-
} ) {
|
|
44
|
-
const defaultModalTitle = useSelect(
|
|
45
|
-
( select ) =>
|
|
46
|
-
select( coreStore ).getPostType( TEMPLATE_PART_POST_TYPE )?.labels
|
|
47
|
-
?.add_new_item,
|
|
48
|
-
[]
|
|
49
|
-
);
|
|
50
|
-
return (
|
|
51
|
-
<Modal
|
|
52
|
-
title={ modalTitle || defaultModalTitle }
|
|
53
|
-
onRequestClose={ restProps.closeModal }
|
|
54
|
-
overlayClassName="editor-create-template-part-modal"
|
|
55
|
-
focusOnMount="firstContentElement"
|
|
56
|
-
size="medium"
|
|
57
|
-
>
|
|
58
|
-
<CreateTemplatePartModalContents { ...restProps } />
|
|
59
|
-
</Modal>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function CreateTemplatePartModalContents( {
|
|
64
|
-
defaultArea = TEMPLATE_PART_AREA_DEFAULT_CATEGORY,
|
|
65
|
-
blocks = [],
|
|
66
|
-
confirmLabel = __( 'Add' ),
|
|
67
|
-
closeModal,
|
|
68
|
-
onCreate,
|
|
69
|
-
onError,
|
|
70
|
-
defaultTitle = '',
|
|
71
|
-
} ) {
|
|
72
|
-
const { createErrorNotice } = useDispatch( noticesStore );
|
|
73
|
-
const { saveEntityRecord } = useDispatch( coreStore );
|
|
74
|
-
const existingTemplateParts = useExistingTemplateParts();
|
|
75
|
-
|
|
76
|
-
const [ title, setTitle ] = useState( defaultTitle );
|
|
77
|
-
const [ area, setArea ] = useState( defaultArea );
|
|
78
|
-
const [ isSubmitting, setIsSubmitting ] = useState( false );
|
|
79
|
-
const instanceId = useInstanceId( CreateTemplatePartModal );
|
|
80
|
-
|
|
81
|
-
const templatePartAreas = useSelect(
|
|
82
|
-
( select ) =>
|
|
83
|
-
select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
|
|
84
|
-
?.default_template_part_areas || [],
|
|
85
|
-
[]
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
async function createTemplatePart() {
|
|
89
|
-
if ( ! title || isSubmitting ) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
setIsSubmitting( true );
|
|
95
|
-
const uniqueTitle = getUniqueTemplatePartTitle(
|
|
96
|
-
title,
|
|
97
|
-
existingTemplateParts
|
|
98
|
-
);
|
|
99
|
-
const cleanSlug = getCleanTemplatePartSlug( uniqueTitle );
|
|
100
|
-
|
|
101
|
-
const templatePart = await saveEntityRecord(
|
|
102
|
-
'postType',
|
|
103
|
-
TEMPLATE_PART_POST_TYPE,
|
|
104
|
-
{
|
|
105
|
-
slug: cleanSlug,
|
|
106
|
-
title: uniqueTitle,
|
|
107
|
-
content: serialize( blocks ),
|
|
108
|
-
area,
|
|
109
|
-
},
|
|
110
|
-
{ throwOnError: true }
|
|
111
|
-
);
|
|
112
|
-
await onCreate( templatePart );
|
|
113
|
-
|
|
114
|
-
// TODO: Add a success notice?
|
|
115
|
-
} catch ( error ) {
|
|
116
|
-
const errorMessage =
|
|
117
|
-
error.message && error.code !== 'unknown_error'
|
|
118
|
-
? error.message
|
|
119
|
-
: __(
|
|
120
|
-
'An error occurred while creating the template part.'
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
124
|
-
|
|
125
|
-
onError?.();
|
|
126
|
-
} finally {
|
|
127
|
-
setIsSubmitting( false );
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return (
|
|
131
|
-
<form
|
|
132
|
-
onSubmit={ async ( event ) => {
|
|
133
|
-
event.preventDefault();
|
|
134
|
-
await createTemplatePart();
|
|
135
|
-
} }
|
|
136
|
-
>
|
|
137
|
-
<VStack spacing="4">
|
|
138
|
-
<TextControl
|
|
139
|
-
__next40pxDefaultSize
|
|
140
|
-
__nextHasNoMarginBottom
|
|
141
|
-
label={ __( 'Name' ) }
|
|
142
|
-
value={ title }
|
|
143
|
-
onChange={ setTitle }
|
|
144
|
-
required
|
|
145
|
-
/>
|
|
146
|
-
<BaseControl
|
|
147
|
-
__nextHasNoMarginBottom
|
|
148
|
-
label={ __( 'Area' ) }
|
|
149
|
-
id={ `editor-create-template-part-modal__area-selection-${ instanceId }` }
|
|
150
|
-
className="editor-create-template-part-modal__area-base-control"
|
|
151
|
-
>
|
|
152
|
-
<RadioGroup
|
|
153
|
-
label={ __( 'Area' ) }
|
|
154
|
-
className="editor-create-template-part-modal__area-radio-group"
|
|
155
|
-
id={ `editor-create-template-part-modal__area-selection-${ instanceId }` }
|
|
156
|
-
onChange={ setArea }
|
|
157
|
-
checked={ area }
|
|
158
|
-
>
|
|
159
|
-
{ templatePartAreas.map(
|
|
160
|
-
( { icon, label, area: value, description } ) => (
|
|
161
|
-
<Radio
|
|
162
|
-
__next40pxDefaultSize
|
|
163
|
-
key={ label }
|
|
164
|
-
value={ value }
|
|
165
|
-
className="editor-create-template-part-modal__area-radio"
|
|
166
|
-
>
|
|
167
|
-
<Flex align="start" justify="start">
|
|
168
|
-
<FlexItem>
|
|
169
|
-
<Icon icon={ icon } />
|
|
170
|
-
</FlexItem>
|
|
171
|
-
<FlexBlock className="editor-create-template-part-modal__option-label">
|
|
172
|
-
{ label }
|
|
173
|
-
<div>{ description }</div>
|
|
174
|
-
</FlexBlock>
|
|
175
|
-
|
|
176
|
-
<FlexItem className="editor-create-template-part-modal__checkbox">
|
|
177
|
-
{ area === value && (
|
|
178
|
-
<Icon icon={ check } />
|
|
179
|
-
) }
|
|
180
|
-
</FlexItem>
|
|
181
|
-
</Flex>
|
|
182
|
-
</Radio>
|
|
183
|
-
)
|
|
184
|
-
) }
|
|
185
|
-
</RadioGroup>
|
|
186
|
-
</BaseControl>
|
|
187
|
-
<HStack justify="right">
|
|
188
|
-
<Button
|
|
189
|
-
__next40pxDefaultSize
|
|
190
|
-
variant="tertiary"
|
|
191
|
-
onClick={ () => {
|
|
192
|
-
closeModal();
|
|
193
|
-
} }
|
|
194
|
-
>
|
|
195
|
-
{ __( 'Cancel' ) }
|
|
196
|
-
</Button>
|
|
197
|
-
<Button
|
|
198
|
-
__next40pxDefaultSize
|
|
199
|
-
variant="primary"
|
|
200
|
-
type="submit"
|
|
201
|
-
aria-disabled={ ! title || isSubmitting }
|
|
202
|
-
isBusy={ isSubmitting }
|
|
203
|
-
>
|
|
204
|
-
{ confirmLabel }
|
|
205
|
-
</Button>
|
|
206
|
-
</HStack>
|
|
207
|
-
</VStack>
|
|
208
|
-
</form>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
.editor-create-template-part-modal {
|
|
2
|
-
z-index: z-index(".editor-create-template-part-modal");
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.editor-create-template-part-modal__area-radio-group {
|
|
6
|
-
width: 100%;
|
|
7
|
-
border: $border-width solid $gray-700;
|
|
8
|
-
border-radius: $radius-small;
|
|
9
|
-
|
|
10
|
-
.components-button.editor-create-template-part-modal__area-radio {
|
|
11
|
-
display: block;
|
|
12
|
-
width: 100%;
|
|
13
|
-
height: 100%;
|
|
14
|
-
text-align: left;
|
|
15
|
-
padding: $grid-unit-15;
|
|
16
|
-
|
|
17
|
-
&,
|
|
18
|
-
&.is-secondary:hover,
|
|
19
|
-
&.is-primary:hover {
|
|
20
|
-
margin: 0;
|
|
21
|
-
background-color: inherit;
|
|
22
|
-
border-bottom: $border-width solid $gray-700;
|
|
23
|
-
border-radius: 0;
|
|
24
|
-
|
|
25
|
-
&:not(:focus) {
|
|
26
|
-
box-shadow: none;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&:focus {
|
|
30
|
-
border-bottom: $border-width solid $white;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&:last-of-type {
|
|
34
|
-
border-bottom: none;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
&:not(:hover),
|
|
39
|
-
&[aria-checked="true"] {
|
|
40
|
-
color: $gray-900;
|
|
41
|
-
cursor: auto;
|
|
42
|
-
|
|
43
|
-
.editor-create-template-part-modal__option-label div {
|
|
44
|
-
color: $gray-600;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.editor-create-template-part-modal__option-label {
|
|
49
|
-
padding-top: $grid-unit-05;
|
|
50
|
-
white-space: normal;
|
|
51
|
-
|
|
52
|
-
div {
|
|
53
|
-
padding-top: $grid-unit-05;
|
|
54
|
-
font-size: $helptext-font-size;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.editor-create-template-part-modal__checkbox {
|
|
59
|
-
margin-left: auto;
|
|
60
|
-
min-width: $grid-unit-30;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { getUniqueTemplatePartTitle, getCleanTemplatePartSlug } from '../utils';
|
|
5
|
-
|
|
6
|
-
describe( 'getUniqueTemplatePartTitle', () => {
|
|
7
|
-
it( 'should return the title if it is unique', () => {
|
|
8
|
-
const title = 'My Template Part';
|
|
9
|
-
const templateParts = [
|
|
10
|
-
{
|
|
11
|
-
title: {
|
|
12
|
-
rendered: 'Template Part With Another Title',
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
expect( getUniqueTemplatePartTitle( title, templateParts ) ).toBe(
|
|
18
|
-
title
|
|
19
|
-
);
|
|
20
|
-
} );
|
|
21
|
-
|
|
22
|
-
it( 'should return the title with a suffix if it is not unique', () => {
|
|
23
|
-
const title = 'My Template Part';
|
|
24
|
-
const templateParts = [
|
|
25
|
-
{
|
|
26
|
-
title: {
|
|
27
|
-
rendered: 'My Template Part',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
title: {
|
|
32
|
-
rendered: 'My Template Part 2',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
expect( getUniqueTemplatePartTitle( title, templateParts ) ).toBe(
|
|
38
|
-
'My Template Part 3'
|
|
39
|
-
);
|
|
40
|
-
} );
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
|
-
describe( 'getCleanTemplatePartSlug', () => {
|
|
44
|
-
it( 'should return a slug with only latin chars', () => {
|
|
45
|
-
const title = 'Myɶ Template Partɮ';
|
|
46
|
-
expect( getCleanTemplatePartSlug( title ) ).toBe( 'my-template-part' );
|
|
47
|
-
} );
|
|
48
|
-
|
|
49
|
-
it( 'should return a slug with only latin chars and numbers', () => {
|
|
50
|
-
const title = 'My Template Part 2';
|
|
51
|
-
expect( getCleanTemplatePartSlug( title ) ).toBe(
|
|
52
|
-
'my-template-part-2'
|
|
53
|
-
);
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'should default the slug to wp-custom-part', () => {
|
|
57
|
-
const title = '';
|
|
58
|
-
expect( getCleanTemplatePartSlug( title ) ).toBe( 'wp-custom-part' );
|
|
59
|
-
} );
|
|
60
|
-
} );
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { paramCase as kebabCase } from 'change-case';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useSelect } from '@wordpress/data';
|
|
10
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import { TEMPLATE_PART_POST_TYPE } from '../../store/constants';
|
|
16
|
-
|
|
17
|
-
export const useExistingTemplateParts = () => {
|
|
18
|
-
return useSelect(
|
|
19
|
-
( select ) =>
|
|
20
|
-
select( coreStore ).getEntityRecords(
|
|
21
|
-
'postType',
|
|
22
|
-
TEMPLATE_PART_POST_TYPE,
|
|
23
|
-
{
|
|
24
|
-
per_page: -1,
|
|
25
|
-
}
|
|
26
|
-
),
|
|
27
|
-
[]
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Return a unique template part title based on
|
|
33
|
-
* the given title and existing template parts.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} title The original template part title.
|
|
36
|
-
* @param {Object} templateParts The array of template part entities.
|
|
37
|
-
* @return {string} A unique template part title.
|
|
38
|
-
*/
|
|
39
|
-
export const getUniqueTemplatePartTitle = ( title, templateParts ) => {
|
|
40
|
-
const lowercaseTitle = title.toLowerCase();
|
|
41
|
-
const existingTitles = templateParts.map( ( templatePart ) =>
|
|
42
|
-
templatePart.title.rendered.toLowerCase()
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if ( ! existingTitles.includes( lowercaseTitle ) ) {
|
|
46
|
-
return title;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let suffix = 2;
|
|
50
|
-
while ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {
|
|
51
|
-
suffix++;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return `${ title } ${ suffix }`;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Get a valid slug for a template part.
|
|
59
|
-
* Currently template parts only allow latin chars.
|
|
60
|
-
* The fallback slug will receive suffix by default.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} title The template part title.
|
|
63
|
-
* @return {string} A valid template part slug.
|
|
64
|
-
*/
|
|
65
|
-
export const getCleanTemplatePartSlug = ( title ) => {
|
|
66
|
-
return kebabCase( title ).replace( /[^\w-]+/g, '' ) || 'wp-custom-part';
|
|
67
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import PostTypeSupportCheck from '../post-type-support-check';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Wrapper component that renders its children only if the post type supports the slug.
|
|
8
|
-
*
|
|
9
|
-
* @param {Object} props Props.
|
|
10
|
-
* @param {React.ReactNode} props.children Children to be rendered.
|
|
11
|
-
*
|
|
12
|
-
* @return {React.ReactNode} The rendered component.
|
|
13
|
-
*/
|
|
14
|
-
export default function PostSlugCheck( { children } ) {
|
|
15
|
-
return (
|
|
16
|
-
<PostTypeSupportCheck supportKeys="slug">
|
|
17
|
-
{ children }
|
|
18
|
-
</PostTypeSupportCheck>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
-
import { useState } from '@wordpress/element';
|
|
6
|
-
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';
|
|
8
|
-
import { TextControl } from '@wordpress/components';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
import PostSlugCheck from './check';
|
|
14
|
-
import { store as editorStore } from '../../store';
|
|
15
|
-
|
|
16
|
-
function PostSlugControl() {
|
|
17
|
-
const postSlug = useSelect( ( select ) => {
|
|
18
|
-
return safeDecodeURIComponent(
|
|
19
|
-
select( editorStore ).getEditedPostSlug()
|
|
20
|
-
);
|
|
21
|
-
}, [] );
|
|
22
|
-
const { editPost } = useDispatch( editorStore );
|
|
23
|
-
const [ forceEmptyField, setForceEmptyField ] = useState( false );
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<TextControl
|
|
27
|
-
__next40pxDefaultSize
|
|
28
|
-
__nextHasNoMarginBottom
|
|
29
|
-
label={ __( 'Slug' ) }
|
|
30
|
-
autoComplete="off"
|
|
31
|
-
spellCheck="false"
|
|
32
|
-
value={ forceEmptyField ? '' : postSlug }
|
|
33
|
-
onChange={ ( newValue ) => {
|
|
34
|
-
editPost( { slug: newValue } );
|
|
35
|
-
// When we delete the field the permalink gets
|
|
36
|
-
// reverted to the original value.
|
|
37
|
-
// The forceEmptyField logic allows the user to have
|
|
38
|
-
// the field temporarily empty while typing.
|
|
39
|
-
if ( ! newValue ) {
|
|
40
|
-
if ( ! forceEmptyField ) {
|
|
41
|
-
setForceEmptyField( true );
|
|
42
|
-
}
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if ( forceEmptyField ) {
|
|
46
|
-
setForceEmptyField( false );
|
|
47
|
-
}
|
|
48
|
-
} }
|
|
49
|
-
onBlur={ ( event ) => {
|
|
50
|
-
editPost( {
|
|
51
|
-
slug: cleanForSlug( event.target.value ),
|
|
52
|
-
} );
|
|
53
|
-
if ( forceEmptyField ) {
|
|
54
|
-
setForceEmptyField( false );
|
|
55
|
-
}
|
|
56
|
-
} }
|
|
57
|
-
className="editor-post-slug"
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Renders the PostSlug component. It provide a control for editing the post slug.
|
|
64
|
-
*
|
|
65
|
-
* @return {React.ReactNode} The rendered component.
|
|
66
|
-
*/
|
|
67
|
-
export default function PostSlug() {
|
|
68
|
-
return (
|
|
69
|
-
<PostSlugCheck>
|
|
70
|
-
<PostSlugControl />
|
|
71
|
-
</PostSlugCheck>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { PanelRow } from '@wordpress/components';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import PostSlugForm from './';
|
|
10
|
-
import PostSlugCheck from './check';
|
|
11
|
-
|
|
12
|
-
export function PostSlug() {
|
|
13
|
-
return (
|
|
14
|
-
<PostSlugCheck>
|
|
15
|
-
<PanelRow className="editor-post-slug">
|
|
16
|
-
<PostSlugForm />
|
|
17
|
-
</PanelRow>
|
|
18
|
-
</PostSlugCheck>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default PostSlug;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { act, render, screen } from '@testing-library/react';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import PostSlug from '../';
|
|
16
|
-
|
|
17
|
-
jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
|
|
18
|
-
jest.mock( '@wordpress/data/src/components/use-dispatch/use-dispatch', () =>
|
|
19
|
-
jest.fn()
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe( 'PostSlug', () => {
|
|
23
|
-
it( 'should update slug with sanitized input', async () => {
|
|
24
|
-
const user = userEvent.setup();
|
|
25
|
-
const editPost = jest.fn();
|
|
26
|
-
|
|
27
|
-
useSelect.mockImplementation( ( mapSelect ) =>
|
|
28
|
-
mapSelect( () => ( {
|
|
29
|
-
getPostType: () => ( {
|
|
30
|
-
supports: {
|
|
31
|
-
slug: true,
|
|
32
|
-
},
|
|
33
|
-
} ),
|
|
34
|
-
getEditedPostAttribute: () => 'post',
|
|
35
|
-
getEditedPostSlug: () => '1',
|
|
36
|
-
} ) )
|
|
37
|
-
);
|
|
38
|
-
useDispatch.mockImplementation( () => ( {
|
|
39
|
-
editPost,
|
|
40
|
-
} ) );
|
|
41
|
-
|
|
42
|
-
render( <PostSlug /> );
|
|
43
|
-
|
|
44
|
-
const input = screen.getByRole( 'textbox', { name: 'Slug' } );
|
|
45
|
-
await user.type( input, '2', {
|
|
46
|
-
initialSelectionStart: 0,
|
|
47
|
-
initialSelectionEnd: 1,
|
|
48
|
-
} );
|
|
49
|
-
act( () => input.blur() );
|
|
50
|
-
|
|
51
|
-
expect( editPost ).toHaveBeenCalledWith( { slug: '2' } );
|
|
52
|
-
} );
|
|
53
|
-
} );
|