@wordpress/fields 0.29.0 → 0.29.1-next.79a2f3cdd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -2
- package/LICENSE.md +1 -1
- package/README.md +41 -0
- package/build/actions/{delete-post.js → delete-post.cjs} +4 -4
- package/build/actions/{duplicate-pattern.js → duplicate-pattern.cjs} +2 -2
- package/build/actions/{duplicate-post.js → duplicate-post.cjs} +2 -2
- package/build/actions/{duplicate-template-part.js → duplicate-template-part.cjs} +3 -3
- package/build/actions/{export-pattern.js → export-pattern.cjs} +2 -2
- package/build/actions/{index.js → index.cjs} +14 -14
- package/build/actions/{permanently-delete-post.js → permanently-delete-post.cjs} +2 -2
- package/build/actions/{rename-post.js → rename-post.cjs} +3 -4
- package/build/actions/{rename-post.js.map → rename-post.cjs.map} +2 -2
- package/build/actions/{reorder-page.js → reorder-page.cjs} +2 -2
- package/build/actions/reorder-page.cjs.map +7 -0
- package/build/actions/{reset-post.js → reset-post.cjs} +2 -2
- package/build/actions/{restore-post.js → restore-post.cjs} +2 -2
- package/build/actions/{trash-post.js → trash-post.cjs} +2 -2
- package/build/actions/{utils.js → utils.cjs} +1 -1
- package/build/actions/{view-post-revisions.js → view-post-revisions.cjs} +1 -1
- package/build/actions/{view-post.js → view-post.cjs} +1 -1
- package/build/components/create-template-part-modal/{index.js → index.cjs} +2 -3
- package/build/components/create-template-part-modal/{index.js.map → index.cjs.map} +2 -2
- package/build/components/create-template-part-modal/{utils.js → utils.cjs} +1 -1
- package/build/components/media-edit/index.cjs +333 -0
- package/build/components/media-edit/index.cjs.map +7 -0
- package/build/fields/author/{author-view.js → author-view.cjs} +1 -1
- package/build/fields/author/{index.js → index.cjs} +2 -2
- package/build/fields/comment-status/{index.js → index.cjs} +1 -1
- package/build/fields/date/{date-view.js → date-view.cjs} +1 -1
- package/build/fields/date/{index.js → index.cjs} +2 -2
- package/build/fields/discussion/{index.js → index.cjs} +1 -1
- package/build/fields/featured-image/{featured-image-view.js → featured-image-view.cjs} +1 -1
- package/build/fields/featured-image/index.cjs +52 -0
- package/build/fields/featured-image/index.cjs.map +7 -0
- package/build/fields/{index.js → index.cjs} +18 -18
- package/build/fields/notes/{index.js → index.cjs} +1 -1
- package/build/fields/order/{index.js → index.cjs} +1 -1
- package/build/fields/page-title/{index.js → index.cjs} +3 -3
- package/build/fields/page-title/{view.js → view.cjs} +3 -3
- package/build/fields/parent/{index.js → index.cjs} +3 -3
- package/build/fields/parent/{parent-edit.js → parent-edit.cjs} +2 -3
- package/build/fields/parent/{parent-edit.js.map → parent-edit.cjs.map} +2 -2
- package/build/fields/parent/{parent-view.js → parent-view.cjs} +2 -2
- package/build/fields/parent/{utils.js → utils.cjs} +1 -1
- package/build/fields/password/{edit.js → edit.cjs} +1 -3
- package/build/fields/password/{edit.js.map → edit.cjs.map} +2 -2
- package/build/fields/password/{index.js → index.cjs} +2 -2
- package/build/fields/pattern-title/{index.js → index.cjs} +3 -3
- package/build/fields/pattern-title/{view.js → view.cjs} +3 -3
- package/build/fields/ping-status/{index.js → index.cjs} +1 -2
- package/build/fields/ping-status/index.cjs.map +7 -0
- package/build/fields/slug/{index.js → index.cjs} +3 -3
- package/build/fields/slug/{slug-edit.js → slug-edit.cjs} +2 -2
- package/build/fields/slug/{slug-view.js → slug-view.cjs} +2 -2
- package/build/fields/slug/{utils.js → utils.cjs} +2 -2
- package/build/fields/status/{index.js → index.cjs} +3 -3
- package/build/fields/status/{status-elements.js → status-elements.cjs} +1 -1
- package/build/fields/status/{status-view.js → status-view.cjs} +2 -2
- package/build/fields/template/{index.js → index.cjs} +2 -2
- package/build/fields/template/{template-edit.js → template-edit.cjs} +3 -3
- package/build/fields/template-title/{index.js → index.cjs} +3 -3
- package/build/fields/title/{index.js → index.cjs} +3 -3
- package/build/fields/title/{view.js → view.cjs} +2 -2
- package/build/{index.js → index.cjs} +10 -7
- package/build/index.cjs.map +7 -0
- package/build/{lock-unlock.js → lock-unlock.cjs} +1 -1
- package/build/mutation/{index.js → index.cjs} +1 -1
- package/build/{types.js → types.cjs} +1 -1
- package/build/types.cjs.map +7 -0
- package/build-module/actions/{delete-post.js → delete-post.mjs} +4 -4
- package/build-module/actions/{duplicate-pattern.js → duplicate-pattern.mjs} +2 -2
- package/build-module/actions/{duplicate-post.js → duplicate-post.mjs} +2 -2
- package/build-module/actions/{duplicate-template-part.js → duplicate-template-part.mjs} +3 -3
- package/build-module/actions/{export-pattern.js → export-pattern.mjs} +2 -2
- package/build-module/actions/index.mjs +30 -0
- package/build-module/actions/{permanently-delete-post.js → permanently-delete-post.mjs} +2 -2
- package/build-module/actions/{rename-post.js → rename-post.mjs} +3 -4
- package/build-module/actions/{rename-post.js.map → rename-post.mjs.map} +2 -2
- package/build-module/actions/{reorder-page.js → reorder-page.mjs} +2 -2
- package/build-module/actions/reorder-page.mjs.map +7 -0
- package/build-module/actions/{reset-post.js → reset-post.mjs} +2 -2
- package/build-module/actions/{restore-post.js → restore-post.mjs} +2 -2
- package/build-module/actions/{trash-post.js → trash-post.mjs} +2 -2
- package/build-module/actions/{utils.js → utils.mjs} +1 -1
- package/build-module/actions/{view-post-revisions.js → view-post-revisions.mjs} +1 -1
- package/build-module/actions/{view-post.js → view-post.mjs} +1 -1
- package/build-module/components/create-template-part-modal/{index.js → index.mjs} +2 -3
- package/build-module/components/create-template-part-modal/{index.js.map → index.mjs.map} +2 -2
- package/build-module/components/create-template-part-modal/{utils.js → utils.mjs} +1 -1
- package/build-module/components/media-edit/index.mjs +314 -0
- package/build-module/components/media-edit/index.mjs.map +7 -0
- package/build-module/fields/author/{author-view.js → author-view.mjs} +1 -1
- package/build-module/fields/author/{index.js → index.mjs} +2 -2
- package/build-module/fields/comment-status/{index.js → index.mjs} +1 -1
- package/build-module/fields/date/{date-view.js → date-view.mjs} +1 -1
- package/build-module/fields/date/{index.js → index.mjs} +2 -2
- package/build-module/fields/discussion/{index.js → index.mjs} +1 -1
- package/build-module/fields/featured-image/{featured-image-view.js → featured-image-view.mjs} +1 -1
- package/build-module/fields/featured-image/{index.js → index.mjs} +8 -5
- package/build-module/fields/featured-image/index.mjs.map +7 -0
- package/build-module/fields/index.mjs +38 -0
- package/build-module/fields/notes/{index.js → index.mjs} +1 -1
- package/build-module/fields/order/{index.js → index.mjs} +1 -1
- package/build-module/fields/page-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/page-title/{view.js → view.mjs} +3 -3
- package/build-module/fields/parent/{index.js → index.mjs} +3 -3
- package/build-module/fields/parent/{parent-edit.js → parent-edit.mjs} +2 -3
- package/build-module/fields/parent/{parent-edit.js.map → parent-edit.mjs.map} +2 -2
- package/build-module/fields/parent/{parent-view.js → parent-view.mjs} +2 -2
- package/build-module/fields/parent/{utils.js → utils.mjs} +1 -1
- package/build-module/fields/password/{edit.js → edit.mjs} +1 -3
- package/build-module/fields/password/{edit.js.map → edit.mjs.map} +2 -2
- package/build-module/fields/password/{index.js → index.mjs} +2 -2
- package/build-module/fields/pattern-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/pattern-title/{view.js → view.mjs} +3 -3
- package/build-module/fields/ping-status/{index.js → index.mjs} +1 -2
- package/build-module/fields/ping-status/index.mjs.map +7 -0
- package/build-module/fields/slug/{index.js → index.mjs} +3 -3
- package/build-module/fields/slug/{slug-edit.js → slug-edit.mjs} +2 -2
- package/build-module/fields/slug/{slug-view.js → slug-view.mjs} +2 -2
- package/build-module/fields/slug/{utils.js → utils.mjs} +2 -2
- package/build-module/fields/status/{index.js → index.mjs} +3 -3
- package/build-module/fields/status/{status-elements.js → status-elements.mjs} +1 -1
- package/build-module/fields/status/{status-view.js → status-view.mjs} +2 -2
- package/build-module/fields/template/{index.js → index.mjs} +2 -2
- package/build-module/fields/template/{template-edit.js → template-edit.mjs} +3 -3
- package/build-module/fields/template-title/{index.js → index.mjs} +3 -3
- package/build-module/fields/title/{index.js → index.mjs} +3 -3
- package/build-module/fields/title/{view.js → view.mjs} +2 -2
- package/build-module/index.mjs +10 -0
- package/build-module/index.mjs.map +7 -0
- package/build-module/{lock-unlock.js → lock-unlock.mjs} +1 -1
- package/build-module/mutation/{index.js → index.mjs} +1 -1
- package/build-module/types.mjs +1 -0
- package/build-style/style-rtl.css +154 -64
- package/build-style/style.css +154 -64
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/components/media-edit/index.d.ts +42 -0
- package/build-types/components/media-edit/index.d.ts.map +1 -0
- package/build-types/fields/featured-image/index.d.ts +0 -3
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
- package/build-types/fields/password/edit.d.ts.map +1 -1
- package/build-types/fields/ping-status/index.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/types.d.ts +24 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +38 -30
- package/src/actions/rename-post.tsx +0 -1
- package/src/actions/reorder-page.tsx +1 -2
- package/src/components/create-template-part-modal/index.tsx +0 -1
- package/src/components/media-edit/index.tsx +424 -0
- package/src/components/media-edit/style.scss +189 -0
- package/src/fields/featured-image/{index.ts → index.tsx} +5 -2
- package/src/fields/featured-image/style.scss +7 -89
- package/src/fields/parent/parent-edit.tsx +0 -1
- package/src/fields/password/edit.tsx +0 -2
- package/src/fields/ping-status/index.tsx +0 -1
- package/src/index.ts +2 -0
- package/src/style.scss +1 -0
- package/src/types.ts +30 -0
- package/build/actions/reorder-page.js.map +0 -7
- package/build/fields/featured-image/featured-image-edit.js +0 -162
- package/build/fields/featured-image/featured-image-edit.js.map +0 -7
- package/build/fields/featured-image/index.js +0 -39
- package/build/fields/featured-image/index.js.map +0 -7
- package/build/fields/ping-status/index.js.map +0 -7
- package/build/index.js.map +0 -7
- package/build/types.js.map +0 -7
- package/build-module/actions/index.js +0 -30
- package/build-module/actions/reorder-page.js.map +0 -7
- package/build-module/fields/featured-image/featured-image-edit.js +0 -140
- package/build-module/fields/featured-image/featured-image-edit.js.map +0 -7
- package/build-module/fields/featured-image/index.js.map +0 -7
- package/build-module/fields/index.js +0 -38
- package/build-module/fields/ping-status/index.js.map +0 -7
- package/build-module/index.js +0 -8
- package/build-module/index.js.map +0 -7
- package/build-module/types.js +0 -1
- package/build-types/fields/featured-image/featured-image-edit.d.ts +0 -7
- package/build-types/fields/featured-image/featured-image-edit.d.ts.map +0 -1
- package/src/fields/featured-image/featured-image-edit.tsx +0 -170
- package/tsconfig.json +0 -31
- package/tsconfig.tsbuildinfo +0 -1
- /package/build/actions/{delete-post.js.map → delete-post.cjs.map} +0 -0
- /package/build/actions/{duplicate-pattern.js.map → duplicate-pattern.cjs.map} +0 -0
- /package/build/actions/{duplicate-post.js.map → duplicate-post.cjs.map} +0 -0
- /package/build/actions/{duplicate-template-part.js.map → duplicate-template-part.cjs.map} +0 -0
- /package/build/actions/{export-pattern.js.map → export-pattern.cjs.map} +0 -0
- /package/build/actions/{index.js.map → index.cjs.map} +0 -0
- /package/build/actions/{permanently-delete-post.js.map → permanently-delete-post.cjs.map} +0 -0
- /package/build/actions/{reset-post.js.map → reset-post.cjs.map} +0 -0
- /package/build/actions/{restore-post.js.map → restore-post.cjs.map} +0 -0
- /package/build/actions/{trash-post.js.map → trash-post.cjs.map} +0 -0
- /package/build/actions/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/actions/{view-post-revisions.js.map → view-post-revisions.cjs.map} +0 -0
- /package/build/actions/{view-post.js.map → view-post.cjs.map} +0 -0
- /package/build/components/create-template-part-modal/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/author/{author-view.js.map → author-view.cjs.map} +0 -0
- /package/build/fields/author/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/comment-status/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/date/{date-view.js.map → date-view.cjs.map} +0 -0
- /package/build/fields/date/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/discussion/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/featured-image/{featured-image-view.js.map → featured-image-view.cjs.map} +0 -0
- /package/build/fields/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/notes/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/order/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/page-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/page-title/{view.js.map → view.cjs.map} +0 -0
- /package/build/fields/parent/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/parent/{parent-view.js.map → parent-view.cjs.map} +0 -0
- /package/build/fields/parent/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/password/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/pattern-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/pattern-title/{view.js.map → view.cjs.map} +0 -0
- /package/build/fields/slug/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/slug/{slug-edit.js.map → slug-edit.cjs.map} +0 -0
- /package/build/fields/slug/{slug-view.js.map → slug-view.cjs.map} +0 -0
- /package/build/fields/slug/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/fields/status/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/status/{status-elements.js.map → status-elements.cjs.map} +0 -0
- /package/build/fields/status/{status-view.js.map → status-view.cjs.map} +0 -0
- /package/build/fields/template/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/template/{template-edit.js.map → template-edit.cjs.map} +0 -0
- /package/build/fields/template-title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/title/{index.js.map → index.cjs.map} +0 -0
- /package/build/fields/title/{view.js.map → view.cjs.map} +0 -0
- /package/build/{lock-unlock.js.map → lock-unlock.cjs.map} +0 -0
- /package/build/mutation/{index.js.map → index.cjs.map} +0 -0
- /package/build-module/actions/{delete-post.js.map → delete-post.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-pattern.js.map → duplicate-pattern.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-post.js.map → duplicate-post.mjs.map} +0 -0
- /package/build-module/actions/{duplicate-template-part.js.map → duplicate-template-part.mjs.map} +0 -0
- /package/build-module/actions/{export-pattern.js.map → export-pattern.mjs.map} +0 -0
- /package/build-module/actions/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/actions/{permanently-delete-post.js.map → permanently-delete-post.mjs.map} +0 -0
- /package/build-module/actions/{reset-post.js.map → reset-post.mjs.map} +0 -0
- /package/build-module/actions/{restore-post.js.map → restore-post.mjs.map} +0 -0
- /package/build-module/actions/{trash-post.js.map → trash-post.mjs.map} +0 -0
- /package/build-module/actions/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/actions/{view-post-revisions.js.map → view-post-revisions.mjs.map} +0 -0
- /package/build-module/actions/{view-post.js.map → view-post.mjs.map} +0 -0
- /package/build-module/components/create-template-part-modal/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/author/{author-view.js.map → author-view.mjs.map} +0 -0
- /package/build-module/fields/author/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/comment-status/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/date/{date-view.js.map → date-view.mjs.map} +0 -0
- /package/build-module/fields/date/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/discussion/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/featured-image/{featured-image-view.js.map → featured-image-view.mjs.map} +0 -0
- /package/build-module/fields/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/notes/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/order/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/page-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/page-title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/fields/parent/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/parent/{parent-view.js.map → parent-view.mjs.map} +0 -0
- /package/build-module/fields/parent/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/password/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/pattern-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/pattern-title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/fields/slug/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/slug/{slug-edit.js.map → slug-edit.mjs.map} +0 -0
- /package/build-module/fields/slug/{slug-view.js.map → slug-view.mjs.map} +0 -0
- /package/build-module/fields/slug/{utils.js.map → utils.mjs.map} +0 -0
- /package/build-module/fields/status/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/status/{status-elements.js.map → status-elements.mjs.map} +0 -0
- /package/build-module/fields/status/{status-view.js.map → status-view.mjs.map} +0 -0
- /package/build-module/fields/template/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/template/{template-edit.js.map → template-edit.mjs.map} +0 -0
- /package/build-module/fields/template-title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/title/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/fields/title/{view.js.map → view.mjs.map} +0 -0
- /package/build-module/{lock-unlock.js.map → lock-unlock.mjs.map} +0 -0
- /package/build-module/mutation/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/{types.js.map → types.mjs.map} +0 -0
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
__experimentalVStack as VStack
|
|
12
12
|
} from "@wordpress/components";
|
|
13
13
|
import { store as noticesStore } from "@wordpress/notices";
|
|
14
|
-
import { unlock } from "../lock-unlock";
|
|
14
|
+
import { unlock } from "../lock-unlock.mjs";
|
|
15
15
|
import {
|
|
16
16
|
getItemTitle,
|
|
17
17
|
isTemplateRemovable,
|
|
18
18
|
isTemplate,
|
|
19
19
|
isTemplatePart
|
|
20
|
-
} from "./utils";
|
|
20
|
+
} from "./utils.mjs";
|
|
21
21
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
22
22
|
var { PATTERN_TYPES } = unlock(patternsPrivateApis);
|
|
23
23
|
var renamePost = {
|
|
@@ -76,7 +76,6 @@ var renamePost = {
|
|
|
76
76
|
/* @__PURE__ */ jsx(
|
|
77
77
|
TextControl,
|
|
78
78
|
{
|
|
79
|
-
__nextHasNoMarginBottom: true,
|
|
80
79
|
__next40pxDefaultSize: true,
|
|
81
80
|
label: __("Name"),
|
|
82
81
|
value: title,
|
|
@@ -113,4 +112,4 @@ var rename_post_default = renamePost;
|
|
|
113
112
|
export {
|
|
114
113
|
rename_post_default as default
|
|
115
114
|
};
|
|
116
|
-
//# sourceMappingURL=rename-post.
|
|
115
|
+
//# sourceMappingURL=rename-post.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/rename-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n} from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Non-database template cannot be edited.\n\t\tif (\n\t\t\tpost.type === 'wp_template' &&\n\t\t\ttypeof post.id === 'string' &&\n\t\t\twindow?.__experimentalTemplateActivate\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst specialChecks = [ 'wp_template', 'wp_template_part' ];\n\n\t\tif ( ! window?.__experimentalTemplateActivate ) {\n\t\t\tspecialChecks.push( 'wp_template' );\n\t\t}\n\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif ( ! specialChecks.includes( post.type ) ) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\t// In the case of templates, we can only rename custom templates.\n\t\tif ( isTemplate( post ) && ! window?.__experimentalTemplateActivate ) {\n\t\t\treturn (\n\t\t\t\tisTemplateRemovable( post ) &&\n\t\t\t\tpost.is_custom &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item, '' ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\
|
|
5
|
-
"mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,gBAAgB;AAEzB,SAAS,eAAe,2BAA2B;AACnD;AAAA,EACC;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AAEP,SAAS,SAAS,oBAAoB;AAMtC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA4FF,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n} from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Non-database template cannot be edited.\n\t\tif (\n\t\t\tpost.type === 'wp_template' &&\n\t\t\ttypeof post.id === 'string' &&\n\t\t\twindow?.__experimentalTemplateActivate\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst specialChecks = [ 'wp_template', 'wp_template_part' ];\n\n\t\tif ( ! window?.__experimentalTemplateActivate ) {\n\t\t\tspecialChecks.push( 'wp_template' );\n\t\t}\n\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif ( ! specialChecks.includes( post.type ) ) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\t// In the case of templates, we can only rename custom templates.\n\t\tif ( isTemplate( post ) && ! window?.__experimentalTemplateActivate ) {\n\t\t\treturn (\n\t\t\t\tisTemplateRemovable( post ) &&\n\t\t\t\tpost.is_custom &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item, '' ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Rename action for PostWithPermissions.\n */\nexport default renamePost;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,gBAAgB;AAEzB,SAAS,eAAe,2BAA2B;AACnD;AAAA,EACC;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AAEP,SAAS,SAAS,oBAAoB;AAMtC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA4FF,cAOA,YAPA;AAxFL,IAAM,EAAE,cAAc,IAAI,OAAQ,mBAAoB;AAEtD,IAAM,aAA4C;AAAA,EACjD,IAAI;AAAA,EACJ,OAAO,GAAI,QAAS;AAAA,EACpB,mBAAmB;AAAA,EACnB,WAAY,MAAO;AAClB,QAAK,KAAK,WAAW,SAAU;AAC9B,aAAO;AAAA,IACR;AAGA,QACC,KAAK,SAAS,iBACd,OAAO,KAAK,OAAO,YACnB,QAAQ,gCACP;AACD,aAAO;AAAA,IACR;AAEA,UAAM,gBAAgB,CAAE,eAAe,kBAAmB;AAE1D,QAAK,CAAE,QAAQ,gCAAiC;AAC/C,oBAAc,KAAM,aAAc;AAAA,IACnC;AAGA,QAAK,CAAE,cAAc,SAAU,KAAK,IAAK,GAAI;AAC5C,aAAO,KAAK,aAAa;AAAA,IAC1B;AAGA,QAAK,WAAY,IAAK,KAAK,CAAE,QAAQ,gCAAiC;AACrE,aACC,oBAAqB,IAAK,KAC1B,KAAK,aACL,KAAK,aAAa;AAAA,IAEpB;AAEA,QAAK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B;AAAA,YACrB,SAAQ;AAAA,YACR,SAAU,MAAM;AACf,2BAAa;AAAA,YACd;AAAA,YAEE,aAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,SAAQ;AAAA,YACR,MAAK;AAAA,YAEH,aAAI,MAAO;AAAA;AAAA,QACd;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@wordpress/components";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
function isItemValid(item) {
|
|
15
|
-
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order)
|
|
15
|
+
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order);
|
|
16
16
|
}
|
|
17
17
|
function ReorderModal({
|
|
18
18
|
items,
|
|
@@ -107,4 +107,4 @@ var reorder_page_default = reorderPage;
|
|
|
107
107
|
export {
|
|
108
108
|
reorder_page_default as default
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=reorder-page.
|
|
110
|
+
//# sourceMappingURL=reorder-page.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/actions/reorder-page.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalInputControl as InputControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\n\ninterface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\ninterface Action< Item > {\n\tid: string;\n\tlabel: string;\n\tisEligible?: ( item: Item ) => boolean;\n\tmodalFocusOnMount?: string;\n\tRenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;\n}\n\nfunction isItemValid( item: BasePost ): boolean {\n\treturn (\n\t\ttypeof item.menu_order === 'number' &&\n\t\tNumber.isInteger( item.menu_order )\n\t);\n}\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst isValid = isItemValid( item );\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<InputControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Order' ) }\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\ttypeof item.menu_order === 'number' &&\n\t\t\t\t\t\tNumber.isInteger( item.menu_order )\n\t\t\t\t\t\t\t? String( item.menu_order )\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tconst parsed = parseInt( value as string, 10 ); // absorbs '' and undefined\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\tmenu_order: isNaN( parsed ) ? undefined : parsed,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ ! isValid }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ReorderModal,\n};\n\n/**\n * Reorder action for BasePost.\n */\nexport default reorderPage;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,OACxB;AA4EH,cAuBA,YAvBA;AAvDJ,SAAS,YAAa,MAA0B;AAC/C,SACC,OAAO,KAAK,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW;AAEpC;AAEA,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,MAAO,CAAE,CAAE;AAC/C,QAAM,EAAE,kBAAkB,uBAAuB,IAChD,YAAa,SAAU;AACxB,QAAM,EAAE,qBAAqB,kBAAkB,IAC9C,YAAa,YAAa;AAE3B,QAAM,UAAU,YAAa,IAAK;AAElC,iBAAe,QAAS,OAAyB;AAChD,UAAM,eAAe;AAErB,QAAK,CAAE,SAAU;AAChB;AAAA,IACD;AAEA,QAAI;AACH,YAAM,iBAAkB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QACvD,YAAY,KAAK;AAAA,MAClB,CAAE;AACF,mBAAa;AAEb,YAAM,uBAAwB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QAC7D,cAAc;AAAA,MACf,CAAE;AACF,0BAAqB,GAAI,gBAAiB,GAAG;AAAA,QAC5C,MAAM;AAAA,MACP,CAAE;AACF,0BAAqB,KAAM;AAAA,IAC5B,SAAU,OAAQ;AACjB,YAAM,aAAa;AACnB,YAAM,eACL,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,UACX,GAAI,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
14
|
} from "@wordpress/components";
|
|
15
15
|
import { addQueryArgs } from "@wordpress/url";
|
|
16
16
|
import apiFetch from "@wordpress/api-fetch";
|
|
17
|
-
import { getItemTitle, isTemplateOrTemplatePart } from "./utils";
|
|
17
|
+
import { getItemTitle, isTemplateOrTemplatePart } from "./utils.mjs";
|
|
18
18
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
19
|
var isTemplateRevertable = (templateOrTemplatePart) => {
|
|
20
20
|
if (!templateOrTemplatePart) {
|
|
@@ -236,4 +236,4 @@ var reset_post_default = resetPostAction;
|
|
|
236
236
|
export {
|
|
237
237
|
reset_post_default as default
|
|
238
238
|
};
|
|
239
|
-
//# sourceMappingURL=reset-post.
|
|
239
|
+
//# sourceMappingURL=reset-post.mjs.map
|
|
@@ -3,7 +3,7 @@ import { backup } from "@wordpress/icons";
|
|
|
3
3
|
import { store as coreStore } from "@wordpress/core-data";
|
|
4
4
|
import { __, sprintf } from "@wordpress/i18n";
|
|
5
5
|
import { store as noticesStore } from "@wordpress/notices";
|
|
6
|
-
import { getItemTitle, isTemplateOrTemplatePart } from "./utils";
|
|
6
|
+
import { getItemTitle, isTemplateOrTemplatePart } from "./utils.mjs";
|
|
7
7
|
var restorePost = {
|
|
8
8
|
id: "restore",
|
|
9
9
|
label: __("Restore"),
|
|
@@ -110,4 +110,4 @@ var restore_post_default = restorePost;
|
|
|
110
110
|
export {
|
|
111
111
|
restore_post_default as default
|
|
112
112
|
};
|
|
113
|
-
//# sourceMappingURL=restore-post.
|
|
113
|
+
//# sourceMappingURL=restore-post.mjs.map
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
__experimentalHStack as HStack,
|
|
12
12
|
__experimentalVStack as VStack
|
|
13
13
|
} from "@wordpress/components";
|
|
14
|
-
import { getItemTitle } from "./utils";
|
|
14
|
+
import { getItemTitle } from "./utils.mjs";
|
|
15
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
16
|
var trashPost = {
|
|
17
17
|
id: "move-to-trash",
|
|
@@ -175,4 +175,4 @@ var trash_post_default = trashPost;
|
|
|
175
175
|
export {
|
|
176
176
|
trash_post_default as default
|
|
177
177
|
};
|
|
178
|
-
//# sourceMappingURL=trash-post.
|
|
178
|
+
//# sourceMappingURL=trash-post.mjs.map
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
getCleanTemplatePartSlug,
|
|
28
28
|
getUniqueTemplatePartTitle,
|
|
29
29
|
useExistingTemplateParts
|
|
30
|
-
} from "./utils";
|
|
30
|
+
} from "./utils.mjs";
|
|
31
31
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
32
32
|
function getAreaRadioId(value, instanceId) {
|
|
33
33
|
return `fields-create-template-part-modal__area-option-${value}-${instanceId}`;
|
|
@@ -135,7 +135,6 @@ function CreateTemplatePartModalContents({
|
|
|
135
135
|
TextControl,
|
|
136
136
|
{
|
|
137
137
|
__next40pxDefaultSize: true,
|
|
138
|
-
__nextHasNoMarginBottom: true,
|
|
139
138
|
label: __("Name"),
|
|
140
139
|
value: title,
|
|
141
140
|
onChange: setTitle,
|
|
@@ -247,4 +246,4 @@ export {
|
|
|
247
246
|
CreateTemplatePartModalContents,
|
|
248
247
|
CreateTemplatePartModal as default
|
|
249
248
|
};
|
|
250
|
-
//# sourceMappingURL=index.
|
|
249
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/create-template-part-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\ttableColumnAfter as overlayIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle?: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\n/**\n * Helper function to retrieve the corresponding icon by area name or icon name.\n *\n * @param {string} areaOrIconName The area name (e.g., 'header', 'overlay') or icon name (e.g., 'menu').\n *\n * @return {Object} The corresponding icon.\n */\nconst getTemplatePartIcon = ( areaOrIconName: string ) => {\n\t// Handle area names first\n\tif ( 'header' === areaOrIconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === areaOrIconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === areaOrIconName ) {\n\t\treturn sidebarIcon;\n\t} else if ( 'overlay' === areaOrIconName ) {\n\t\t// TODO: Replace with a proper overlay icon when available.\n\t\t// Using tableColumnAfter as a placeholder.\n\t\treturn overlayIcon;\n\t}\n\t// Handle icon names for backwards compatibility\n\tif ( 'menu' === areaOrIconName ) {\n\t\t// TODO: Replace with a proper overlay icon when available.\n\t\t// Using tableColumnAfter as a placeholder.\n\t\treturn overlayIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getCurrentTheme()?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset className=\"fields-create-template-part-modal__area-fieldset\">\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map(\n\t\t\t\t\t\t\t( item: TemplatePartArea ) => {\n\t\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.description }\n\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AACP,SAAS,qBAAqB;AAE9B,SAAS,SAAS,iBAAiB;AACnC,SAAS,aAAa,iBAAiB;AACvC,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,OACV;AACP,SAAS,SAAS,oBAAoB;AAEtC,SAAS,iBAAiB;AAK1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA6CJ,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\ttableColumnAfter as overlayIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle?: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\n/**\n * Helper function to retrieve the corresponding icon by area name or icon name.\n *\n * @param {string} areaOrIconName The area name (e.g., 'header', 'overlay') or icon name (e.g., 'menu').\n *\n * @return {Object} The corresponding icon.\n */\nconst getTemplatePartIcon = ( areaOrIconName: string ) => {\n\t// Handle area names first\n\tif ( 'header' === areaOrIconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === areaOrIconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === areaOrIconName ) {\n\t\treturn sidebarIcon;\n\t} else if ( 'overlay' === areaOrIconName ) {\n\t\t// TODO: Replace with a proper overlay icon when available.\n\t\t// Using tableColumnAfter as a placeholder.\n\t\treturn overlayIcon;\n\t}\n\t// Handle icon names for backwards compatibility\n\tif ( 'menu' === areaOrIconName ) {\n\t\t// TODO: Replace with a proper overlay icon when available.\n\t\t// Using tableColumnAfter as a placeholder.\n\t\treturn overlayIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getCurrentTheme()?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset className=\"fields-create-template-part-modal__area-fieldset\">\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map(\n\t\t\t\t\t\t\t( item: TemplatePartArea ) => {\n\t\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.description }\n\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AACP,SAAS,qBAAqB;AAE9B,SAAS,SAAS,iBAAiB;AACnC,SAAS,aAAa,iBAAiB;AACvC,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,OACV;AACP,SAAS,SAAS,oBAAoB;AAEtC,SAAS,iBAAiB;AAK1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA6CJ,cA4IM,YA5IN;AA3CH,SAAS,eAAgB,OAAe,YAAqB;AAC5D,SAAO,kDAAmD,KAAM,IAAK,UAAW;AACjF;AACA,SAAS,0BAA2B,OAAe,YAAqB;AACvE,SAAO,8DAA+D,KAAM,IAAK,UAAW;A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,WACD;AAAA,SACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// packages/fields/src/components/media-edit/index.tsx
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Icon,
|
|
6
|
+
__experimentalText as Text,
|
|
7
|
+
__experimentalTruncate as Truncate,
|
|
8
|
+
__experimentalVStack as VStack,
|
|
9
|
+
BaseControl,
|
|
10
|
+
Tooltip,
|
|
11
|
+
VisuallyHidden
|
|
12
|
+
} from "@wordpress/components";
|
|
13
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
14
|
+
import { useSelect } from "@wordpress/data";
|
|
15
|
+
import { useCallback, useState } from "@wordpress/element";
|
|
16
|
+
import { __ } from "@wordpress/i18n";
|
|
17
|
+
import { archive, audio, video, file, closeSmall } from "@wordpress/icons";
|
|
18
|
+
import {
|
|
19
|
+
MediaUpload,
|
|
20
|
+
privateApis as mediaUtilsPrivateApis
|
|
21
|
+
} from "@wordpress/media-utils";
|
|
22
|
+
import { unlock } from "../../lock-unlock.mjs";
|
|
23
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
24
|
+
var { MediaUploadModal } = unlock(mediaUtilsPrivateApis);
|
|
25
|
+
function ConditionalMediaUpload({ render, multiple, ...props }) {
|
|
26
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
27
|
+
if (window.__experimentalDataViewsMediaModal) {
|
|
28
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
|
+
render && render({ open: () => setIsModalOpen(true) }),
|
|
30
|
+
isModalOpen && /* @__PURE__ */ jsx(
|
|
31
|
+
MediaUploadModal,
|
|
32
|
+
{
|
|
33
|
+
...props,
|
|
34
|
+
multiple,
|
|
35
|
+
isOpen: isModalOpen,
|
|
36
|
+
onClose: () => {
|
|
37
|
+
setIsModalOpen(false);
|
|
38
|
+
props.onClose?.();
|
|
39
|
+
},
|
|
40
|
+
onSelect: (media) => {
|
|
41
|
+
setIsModalOpen(false);
|
|
42
|
+
props.onSelect?.(media);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
] });
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ jsx(
|
|
49
|
+
MediaUpload,
|
|
50
|
+
{
|
|
51
|
+
...props,
|
|
52
|
+
render,
|
|
53
|
+
multiple: multiple ? "add" : void 0
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function MediaPickerButton({
|
|
58
|
+
open,
|
|
59
|
+
children,
|
|
60
|
+
label,
|
|
61
|
+
showTooltip = false
|
|
62
|
+
}) {
|
|
63
|
+
const mediaPickerButton = /* @__PURE__ */ jsx(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
className: "fields__media-edit-picker-button",
|
|
67
|
+
role: "button",
|
|
68
|
+
tabIndex: 0,
|
|
69
|
+
onClick: open,
|
|
70
|
+
onKeyDown: (event) => {
|
|
71
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
open();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"aria-label": label,
|
|
77
|
+
children
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
if (!showTooltip) {
|
|
81
|
+
return mediaPickerButton;
|
|
82
|
+
}
|
|
83
|
+
return /* @__PURE__ */ jsx(Tooltip, { text: label, children: mediaPickerButton });
|
|
84
|
+
}
|
|
85
|
+
var archiveMimeTypes = [
|
|
86
|
+
"application/zip",
|
|
87
|
+
"application/x-zip-compressed",
|
|
88
|
+
"application/x-rar-compressed",
|
|
89
|
+
"application/x-7z-compressed",
|
|
90
|
+
"application/x-tar",
|
|
91
|
+
"application/x-gzip"
|
|
92
|
+
];
|
|
93
|
+
function MediaTitle({ attachment }) {
|
|
94
|
+
return /* @__PURE__ */ jsx(Truncate, { className: "fields__media-edit-filename", children: attachment.title.rendered });
|
|
95
|
+
}
|
|
96
|
+
function MediaEditPlaceholder({
|
|
97
|
+
open,
|
|
98
|
+
label
|
|
99
|
+
}) {
|
|
100
|
+
return /* @__PURE__ */ jsx(MediaPickerButton, { open, label, children: /* @__PURE__ */ jsx("span", { className: "fields__media-edit-placeholder", children: label }) });
|
|
101
|
+
}
|
|
102
|
+
function MediaPreview({ attachment }) {
|
|
103
|
+
const url = attachment.source_url;
|
|
104
|
+
const mimeType = attachment.mime_type;
|
|
105
|
+
if (mimeType.startsWith("image/")) {
|
|
106
|
+
return /* @__PURE__ */ jsx(
|
|
107
|
+
"img",
|
|
108
|
+
{
|
|
109
|
+
className: "fields__media-edit-thumbnail",
|
|
110
|
+
alt: attachment.alt_text || "",
|
|
111
|
+
src: url
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
} else if (mimeType.startsWith("audio/")) {
|
|
115
|
+
return /* @__PURE__ */ jsx(Icon, { icon: audio });
|
|
116
|
+
} else if (mimeType.startsWith("video/")) {
|
|
117
|
+
return /* @__PURE__ */ jsx(Icon, { icon: video });
|
|
118
|
+
} else if (archiveMimeTypes.includes(mimeType)) {
|
|
119
|
+
return /* @__PURE__ */ jsx(Icon, { icon: archive });
|
|
120
|
+
}
|
|
121
|
+
return /* @__PURE__ */ jsx(Icon, { icon: file });
|
|
122
|
+
}
|
|
123
|
+
function ExpandedMediaEditAttachments({
|
|
124
|
+
attachments,
|
|
125
|
+
addButtonLabel,
|
|
126
|
+
multiple,
|
|
127
|
+
removeItem,
|
|
128
|
+
open
|
|
129
|
+
}) {
|
|
130
|
+
return /* @__PURE__ */ jsxs(
|
|
131
|
+
"div",
|
|
132
|
+
{
|
|
133
|
+
className: clsx("fields__media-edit-expanded", {
|
|
134
|
+
"is-multiple": multiple,
|
|
135
|
+
"is-single": !multiple,
|
|
136
|
+
"is-empty": !attachments?.length
|
|
137
|
+
}),
|
|
138
|
+
children: [
|
|
139
|
+
attachments?.map((attachment) => {
|
|
140
|
+
const hasPreviewImage = attachment.mime_type.startsWith("image/");
|
|
141
|
+
return /* @__PURE__ */ jsxs(
|
|
142
|
+
"div",
|
|
143
|
+
{
|
|
144
|
+
className: clsx("fields__media-edit-expanded-item", {
|
|
145
|
+
"has-preview-image": hasPreviewImage
|
|
146
|
+
}),
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ jsx(
|
|
149
|
+
MediaPickerButton,
|
|
150
|
+
{
|
|
151
|
+
open,
|
|
152
|
+
label: __("Replace"),
|
|
153
|
+
showTooltip: true,
|
|
154
|
+
children: /* @__PURE__ */ jsx("div", { className: "fields__media-edit-expanded-preview", children: /* @__PURE__ */ jsxs(
|
|
155
|
+
VStack,
|
|
156
|
+
{
|
|
157
|
+
spacing: 0,
|
|
158
|
+
alignment: "center",
|
|
159
|
+
justify: "center",
|
|
160
|
+
className: "fields__media-edit-expanded-preview-stack",
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsx(MediaPreview, { attachment }),
|
|
163
|
+
!hasPreviewImage ? /* @__PURE__ */ jsx(MediaTitle, { attachment }) : /* @__PURE__ */ jsx("div", { className: "fields__media-edit-expanded-title", children: /* @__PURE__ */ jsx(
|
|
164
|
+
MediaTitle,
|
|
165
|
+
{
|
|
166
|
+
attachment
|
|
167
|
+
}
|
|
168
|
+
) })
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
) })
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
/* @__PURE__ */ jsx("div", { className: "fields__media-edit-expanded-overlay", children: /* @__PURE__ */ jsx(
|
|
175
|
+
Button,
|
|
176
|
+
{
|
|
177
|
+
__next40pxDefaultSize: true,
|
|
178
|
+
className: "fields__media-edit-expanded-remove",
|
|
179
|
+
icon: closeSmall,
|
|
180
|
+
label: __("Remove"),
|
|
181
|
+
size: "small",
|
|
182
|
+
onClick: (event) => {
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
removeItem(attachment.id);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
) })
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
attachment.id
|
|
191
|
+
);
|
|
192
|
+
}),
|
|
193
|
+
(multiple || !attachments?.length) && /* @__PURE__ */ jsx(MediaEditPlaceholder, { open, label: addButtonLabel })
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
function CompactMediaEditAttachments({
|
|
199
|
+
attachments,
|
|
200
|
+
addButtonLabel,
|
|
201
|
+
multiple,
|
|
202
|
+
removeItem,
|
|
203
|
+
open
|
|
204
|
+
}) {
|
|
205
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
206
|
+
!!attachments?.length && /* @__PURE__ */ jsx(VStack, { spacing: 2, children: attachments.map((attachment) => /* @__PURE__ */ jsxs(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
className: "fields__media-edit-compact",
|
|
210
|
+
children: [
|
|
211
|
+
/* @__PURE__ */ jsx(
|
|
212
|
+
MediaPickerButton,
|
|
213
|
+
{
|
|
214
|
+
open,
|
|
215
|
+
label: __("Replace"),
|
|
216
|
+
showTooltip: true,
|
|
217
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218
|
+
/* @__PURE__ */ jsx(MediaPreview, { attachment }),
|
|
219
|
+
/* @__PURE__ */ jsx(MediaTitle, { attachment })
|
|
220
|
+
] })
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
/* @__PURE__ */ jsx(
|
|
224
|
+
Button,
|
|
225
|
+
{
|
|
226
|
+
__next40pxDefaultSize: true,
|
|
227
|
+
className: "fields__media-edit-remove",
|
|
228
|
+
text: __("Remove"),
|
|
229
|
+
variant: "secondary",
|
|
230
|
+
onClick: (event) => {
|
|
231
|
+
event.stopPropagation();
|
|
232
|
+
removeItem(attachment.id);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
attachment.id
|
|
239
|
+
)) }),
|
|
240
|
+
(multiple || !attachments?.length) && /* @__PURE__ */ jsx(MediaEditPlaceholder, { open, label: addButtonLabel })
|
|
241
|
+
] });
|
|
242
|
+
}
|
|
243
|
+
function MediaEdit({
|
|
244
|
+
data,
|
|
245
|
+
field,
|
|
246
|
+
onChange,
|
|
247
|
+
hideLabelFromVision,
|
|
248
|
+
allowedTypes = ["image"],
|
|
249
|
+
multiple,
|
|
250
|
+
isExpanded
|
|
251
|
+
}) {
|
|
252
|
+
const value = field.getValue({ item: data });
|
|
253
|
+
const attachments = useSelect(
|
|
254
|
+
(select) => {
|
|
255
|
+
if (!value) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const normalizedValue = Array.isArray(value) ? value : [value];
|
|
259
|
+
const { getEntityRecords } = select(coreStore);
|
|
260
|
+
return getEntityRecords("postType", "attachment", {
|
|
261
|
+
include: normalizedValue
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
[value]
|
|
265
|
+
);
|
|
266
|
+
const onChangeControl = useCallback(
|
|
267
|
+
(newValue) => onChange(field.setValue({ item: data, value: newValue })),
|
|
268
|
+
[data, field, onChange]
|
|
269
|
+
);
|
|
270
|
+
const removeItem = (itemId) => {
|
|
271
|
+
const currentIds = Array.isArray(value) ? value : [value];
|
|
272
|
+
const newIds = currentIds.filter((id) => id !== itemId);
|
|
273
|
+
onChangeControl(newIds.length ? newIds : void 0);
|
|
274
|
+
};
|
|
275
|
+
const addButtonLabel = field.placeholder || (multiple ? __("Choose files") : __("Choose file"));
|
|
276
|
+
return /* @__PURE__ */ jsx("fieldset", { className: "fields__media-edit", "data-field-id": field.id, children: /* @__PURE__ */ jsx(
|
|
277
|
+
ConditionalMediaUpload,
|
|
278
|
+
{
|
|
279
|
+
onSelect: (selectedMedia) => {
|
|
280
|
+
if (multiple) {
|
|
281
|
+
const newIds = Array.isArray(selectedMedia) ? selectedMedia.map((m) => m.id) : [selectedMedia.id];
|
|
282
|
+
onChangeControl(newIds);
|
|
283
|
+
} else {
|
|
284
|
+
onChangeControl(selectedMedia.id);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
allowedTypes,
|
|
288
|
+
value,
|
|
289
|
+
multiple,
|
|
290
|
+
title: field.label,
|
|
291
|
+
render: ({ open }) => {
|
|
292
|
+
const AttachmentsComponent = isExpanded ? ExpandedMediaEditAttachments : CompactMediaEditAttachments;
|
|
293
|
+
return /* @__PURE__ */ jsxs(VStack, { spacing: 2, children: [
|
|
294
|
+
field.label && (hideLabelFromVision ? /* @__PURE__ */ jsx(VisuallyHidden, { as: "legend", children: field.label }) : /* @__PURE__ */ jsx(BaseControl.VisualLabel, { as: "legend", children: field.label })),
|
|
295
|
+
/* @__PURE__ */ jsx(
|
|
296
|
+
AttachmentsComponent,
|
|
297
|
+
{
|
|
298
|
+
attachments,
|
|
299
|
+
addButtonLabel,
|
|
300
|
+
multiple,
|
|
301
|
+
removeItem,
|
|
302
|
+
open
|
|
303
|
+
}
|
|
304
|
+
),
|
|
305
|
+
field.description && /* @__PURE__ */ jsx(Text, { variant: "muted", children: field.description })
|
|
306
|
+
] });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
) });
|
|
310
|
+
}
|
|
311
|
+
export {
|
|
312
|
+
MediaEdit as default
|
|
313
|
+
};
|
|
314
|
+
//# sourceMappingURL=index.mjs.map
|