@wordpress/fields 0.24.1-next.ff1cebbba.0 → 0.25.1
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 +2 -0
- package/build/actions/duplicate-post.js +10 -12
- package/build/actions/duplicate-post.js.map +3 -3
- package/build/actions/reorder-page.js +19 -19
- package/build/actions/reorder-page.js.map +3 -3
- package/build/fields/author/index.js +15 -1
- package/build/fields/author/index.js.map +3 -3
- package/build-module/actions/duplicate-post.js +12 -13
- package/build-module/actions/duplicate-post.js.map +2 -2
- package/build-module/actions/reorder-page.js +21 -20
- package/build-module/actions/reorder-page.js.map +2 -2
- package/build-module/fields/author/index.js +15 -1
- package/build-module/fields/author/index.js.map +2 -2
- package/build-types/actions/duplicate-post.d.ts +15 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts +12 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/build-types/fields/author/index.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/actions/duplicate-post.tsx +28 -13
- package/src/actions/reorder-page.tsx +43 -20
- package/src/fields/author/index.tsx +21 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -27,14 +27,8 @@ var import_core_data = require("@wordpress/core-data");
|
|
|
27
27
|
var import_i18n = require("@wordpress/i18n");
|
|
28
28
|
var import_notices = require("@wordpress/notices");
|
|
29
29
|
var import_element = require("@wordpress/element");
|
|
30
|
-
var import_dataviews = require("@wordpress/dataviews");
|
|
31
30
|
var import_components = require("@wordpress/components");
|
|
32
|
-
var import_fields = require("../fields");
|
|
33
31
|
var import_utils = require("./utils");
|
|
34
|
-
const fields = [import_fields.titleField];
|
|
35
|
-
const formDuplicateAction = {
|
|
36
|
-
fields: ["title"]
|
|
37
|
-
};
|
|
38
32
|
const duplicatePost = {
|
|
39
33
|
id: "duplicate-post",
|
|
40
34
|
label: (0, import_i18n._x)("Duplicate", "action label"),
|
|
@@ -121,15 +115,19 @@ const duplicatePost = {
|
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
117
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: createPage, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 3, children: [
|
|
118
|
+
item.type === "wp_registered_template" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: (0, import_i18n.__)(
|
|
119
|
+
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
120
|
+
) }),
|
|
124
121
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
|
-
|
|
122
|
+
import_components.__experimentalInputControl,
|
|
126
123
|
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
__next40pxDefaultSize: true,
|
|
125
|
+
label: (0, import_i18n.__)("Title"),
|
|
126
|
+
placeholder: (0, import_i18n.__)("No title"),
|
|
127
|
+
value: (0, import_utils.getItemTitle)(item),
|
|
128
|
+
onChange: (value) => setItem((prev) => ({
|
|
131
129
|
...prev,
|
|
132
|
-
|
|
130
|
+
title: value || (0, import_i18n.__)("No title")
|
|
133
131
|
}))
|
|
134
132
|
}
|
|
135
133
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/duplicate-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } 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 { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\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\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\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 duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t{ item.type === 'wp_registered_template' && (\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\tvalue={ getItemTitle( item ) }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\ttitle: value || __( 'No title' ),\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\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\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\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 * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwJM;AArJN,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAgC;AAChC,qBAAsC;AACtC,qBAAyB;AACzB,wBAKO;AAMP,mBAA6B;AAgB7B,MAAM,gBAAoC;AAAA,EACzC,IAAI;AAAA,EACJ,WAAO,gBAAI,aAAa,cAAe;AAAA,EACvC,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa,CAAE,EAAE,OAAO,YAAY,kBAAkB,MAAO;AAC5D,UAAM,CAAE,MAAM,OAAQ,QAAI,yBAAsB;AAAA,MAC/C,GAAG,MAAO,CAAE;AAAA,MACZ,W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;AAAA,YAEnB,8BAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,MAAK;AAAA,YACL,QAAS;AAAA,YACT,iBAAgB;AAAA,YAChB,uBAAqB;AAAA,YAEnB,8BAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
|
+
"names": ["coreStore", "noticesStore", "VStack", "InputControl", "HStack"]
|
|
7
7
|
}
|
|
@@ -27,30 +27,27 @@ var import_core_data = require("@wordpress/core-data");
|
|
|
27
27
|
var import_i18n = require("@wordpress/i18n");
|
|
28
28
|
var import_notices = require("@wordpress/notices");
|
|
29
29
|
var import_element = require("@wordpress/element");
|
|
30
|
-
var import_dataviews = require("@wordpress/dataviews");
|
|
31
30
|
var import_components = require("@wordpress/components");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fields: ["menu_order"]
|
|
36
|
-
};
|
|
31
|
+
function isItemValid(item) {
|
|
32
|
+
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order) && item.menu_order > 0;
|
|
33
|
+
}
|
|
37
34
|
function ReorderModal({
|
|
38
35
|
items,
|
|
39
36
|
closeModal,
|
|
40
37
|
onActionPerformed
|
|
41
38
|
}) {
|
|
42
39
|
const [item, setItem] = (0, import_element.useState)(items[0]);
|
|
43
|
-
const orderInput = item.menu_order;
|
|
44
40
|
const { editEntityRecord, saveEditedEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
|
|
45
41
|
const { createSuccessNotice, createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
42
|
+
const isValid = isItemValid(item);
|
|
46
43
|
async function onOrder(event) {
|
|
47
44
|
event.preventDefault();
|
|
48
|
-
if (!
|
|
45
|
+
if (!isValid) {
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
48
|
try {
|
|
52
49
|
await editEntityRecord("postType", item.type, item.id, {
|
|
53
|
-
menu_order:
|
|
50
|
+
menu_order: item.menu_order
|
|
54
51
|
});
|
|
55
52
|
closeModal?.();
|
|
56
53
|
await saveEditedEntityRecord("postType", item.type, item.id, {
|
|
@@ -68,21 +65,24 @@ function ReorderModal({
|
|
|
68
65
|
});
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
const isSaveDisabled = !(0, import_dataviews.isItemValid)(item, fields, formOrderAction);
|
|
72
68
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: onOrder, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [
|
|
73
69
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: (0, import_i18n.__)(
|
|
74
70
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
75
71
|
) }),
|
|
76
72
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
77
|
-
|
|
73
|
+
import_components.__experimentalInputControl,
|
|
78
74
|
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
__next40pxDefaultSize: true,
|
|
76
|
+
label: (0, import_i18n.__)("Order"),
|
|
77
|
+
type: "number",
|
|
78
|
+
value: typeof item.menu_order === "number" && Number.isInteger(item.menu_order) ? String(item.menu_order) : "",
|
|
79
|
+
onChange: (value) => {
|
|
80
|
+
const parsed = parseInt(value, 10);
|
|
81
|
+
setItem({
|
|
82
|
+
...item,
|
|
83
|
+
menu_order: isNaN(parsed) ? void 0 : parsed
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
87
|
),
|
|
88
88
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
|
|
@@ -104,7 +104,7 @@ function ReorderModal({
|
|
|
104
104
|
variant: "primary",
|
|
105
105
|
type: "submit",
|
|
106
106
|
accessibleWhenDisabled: true,
|
|
107
|
-
disabled:
|
|
107
|
+
disabled: !isValid,
|
|
108
108
|
children: (0, import_i18n.__)("Save")
|
|
109
109
|
}
|
|
110
110
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
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\titem.menu_order > 0\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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0FI;AAvFJ,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAmB;AACnB,qBAAsC;AACtC,qBAAyB;AACzB,wBAKO;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K,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW,IAC/B,OAAQ,KAAK,UAAW,IACxB;AAAA,QAEJ,UAAW,CAAE,UAAW;AACvB,gBAAM,SAAS,SAAU,OAAiB,EAAG;AAC7C,kBAAS;AAAA,YACR,GAAG;AAAA,YACH,YAAY,MAAO,MAAO,IAAI,SAAY;AAAA,UAC3C,CAAE;AAAA,QACH;AAAA;AAAA,IACD;AAAA,IACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,SAAU,MAAM;AACf,yBAAa;AAAA,UACd;AAAA,UAEE,8BAAI,QAAS;AAAA;AAAA,MAChB;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,wBAAsB;AAAA,UACtB,UAAW,CAAE;AAAA,UAEX,8BAAI,MAAO;AAAA;AAAA,MACd;AAAA,OACD;AAAA,KACD,GACD;AAEF;AAEA,MAAM,cAAkC;AAAA,EACvC,IAAI;AAAA,EACJ,WAAO,gBAAI,OAAQ;AAAA,EACnB,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa;AACd;AAKA,IAAO,uBAAQ;",
|
|
6
|
+
"names": ["coreStore", "noticesStore", "VStack", "InputControl", "HStack"]
|
|
7
7
|
}
|
|
@@ -32,12 +32,26 @@ __export(author_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(author_exports);
|
|
34
34
|
var import_i18n = require("@wordpress/i18n");
|
|
35
|
+
var import_data = require("@wordpress/data");
|
|
36
|
+
var import_core_data = require("@wordpress/core-data");
|
|
35
37
|
var import_author_view = __toESM(require("./author-view"));
|
|
36
38
|
const authorField = {
|
|
37
39
|
label: (0, import_i18n.__)("Author"),
|
|
38
40
|
id: "author",
|
|
39
41
|
type: "integer",
|
|
40
|
-
|
|
42
|
+
getElements: async () => {
|
|
43
|
+
const authors = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecords(
|
|
44
|
+
"root",
|
|
45
|
+
"user",
|
|
46
|
+
{
|
|
47
|
+
per_page: -1
|
|
48
|
+
}
|
|
49
|
+
) ?? [];
|
|
50
|
+
return authors.map(({ id, name }) => ({
|
|
51
|
+
value: id,
|
|
52
|
+
label: name
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
41
55
|
render: import_author_view.default,
|
|
42
56
|
sort: (a, b, direction) => {
|
|
43
57
|
const nameA = a._embedded?.author?.[0]?.name || "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/author/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;
|
|
6
|
-
"names": ["AuthorView"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;AACnB,kBAA8B;AAC9B,uBAAuC;AAMvC,yBAAuB;AAOvB,MAAM,cAAmD;AAAA,EACxD,WAAO,gBAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,aAAa,YAAY;AACxB,UAAM,UACH,UAAM,2BAAe,iBAAAA,KAAc,EAAE;AAAA,MACtC;AAAA,MACA;AAAA,MACA;AAAA,QACC,UAAU;AAAA,MACX;AAAA,IACD,KAAO,CAAC;AACT,WAAO,QAAQ,IAAK,CAAE,EAAE,IAAI,KAAK,OAAS;AAAA,MACzC,OAAO;AAAA,MACP,OAAO;AAAA,IACR,EAAI;AAAA,EACL;AAAA,EACA,QAAQ,mBAAAC;AAAA,EACR,MAAM,CAAE,GAAG,GAAG,cAAe;AAC5B,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAClD,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAElD,WAAO,cAAc,QAClB,MAAM,cAAe,KAAM,IAC3B,MAAM,cAAe,KAAM;AAAA,EAC/B;AAAA,EAEA,UAAU;AAAA,IACT,WAAW,CAAE,SAAS,QAAS;AAAA,EAChC;AACD;AAKA,IAAO,iBAAQ;",
|
|
6
|
+
"names": ["coreDataStore", "AuthorView"]
|
|
7
7
|
}
|
|
@@ -4,18 +4,13 @@ import { store as coreStore } from "@wordpress/core-data";
|
|
|
4
4
|
import { __, sprintf, _x } from "@wordpress/i18n";
|
|
5
5
|
import { store as noticesStore } from "@wordpress/notices";
|
|
6
6
|
import { useState } from "@wordpress/element";
|
|
7
|
-
import { DataForm } from "@wordpress/dataviews";
|
|
8
7
|
import {
|
|
9
8
|
Button,
|
|
10
9
|
__experimentalHStack as HStack,
|
|
11
|
-
__experimentalVStack as VStack
|
|
10
|
+
__experimentalVStack as VStack,
|
|
11
|
+
__experimentalInputControl as InputControl
|
|
12
12
|
} from "@wordpress/components";
|
|
13
|
-
import { titleField } from "../fields";
|
|
14
13
|
import { getItemTitle } from "./utils";
|
|
15
|
-
const fields = [titleField];
|
|
16
|
-
const formDuplicateAction = {
|
|
17
|
-
fields: ["title"]
|
|
18
|
-
};
|
|
19
14
|
const duplicatePost = {
|
|
20
15
|
id: "duplicate-post",
|
|
21
16
|
label: _x("Duplicate", "action label"),
|
|
@@ -102,15 +97,19 @@ const duplicatePost = {
|
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
return /* @__PURE__ */ jsx("form", { onSubmit: createPage, children: /* @__PURE__ */ jsxs(VStack, { spacing: 3, children: [
|
|
100
|
+
item.type === "wp_registered_template" && /* @__PURE__ */ jsx("div", { children: __(
|
|
101
|
+
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
102
|
+
) }),
|
|
105
103
|
/* @__PURE__ */ jsx(
|
|
106
|
-
|
|
104
|
+
InputControl,
|
|
107
105
|
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
__next40pxDefaultSize: true,
|
|
107
|
+
label: __("Title"),
|
|
108
|
+
placeholder: __("No title"),
|
|
109
|
+
value: getItemTitle(item),
|
|
110
|
+
onChange: (value) => setItem((prev) => ({
|
|
112
111
|
...prev,
|
|
113
|
-
|
|
112
|
+
title: value || __("No title")
|
|
114
113
|
}))
|
|
115
114
|
}
|
|
116
115
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/duplicate-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } 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 { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\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\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\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 duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t{ item.type === 'wp_registered_template' && (\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\tvalue={ getItemTitle( item ) }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\ttitle: value || __( 'No title' ),\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\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\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\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AAAA,QACP,CAAE;AAAA,MACH,UAAE;AACD,0BAAmB,KAAM;AACzB,qBAAa;AAAA,MACd;AAAA,IACD;AAEA,WACC,oBAAC,UAAK,UAAW,YAChB,+BAAC,UAAO,SAAU,GACf;AAAA,WAAK,SAAS,4BACf,oBAAC,SACE;AAAA,QACD;AAAA,MACD,GACD;AAAA,MAED;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,OAAQ,GAAI,OAAQ;AAAA,UACpB,aAAc,GAAI,UAAW;AAAA,UAC7B,OAAQ,aAAc,IAAK;AAAA,UAC3B,UAAW,CAAE,UACZ,QAAS,CAAE,UAAY;AAAA,YACtB,GAAG;AAAA,YACH,OAAO,SAAS,GAAI,UAAW;AAAA,UAChC,EAAI;AAAA;AAAA,MAEN;AAAA,MACA,qBAAC,UAAO,SAAU,GAAI,SAAQ,OAC7B;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,SAAU;AAAA,YACV,uBAAqB;AAAA,YAEnB,aAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,MAAK;AAAA,YACL,QAAS;AAAA,YACT,iBAAgB;AAAA,YAChB,uBAAqB;AAAA,YAEnB,aAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,34 +4,32 @@ import { store as coreStore } from "@wordpress/core-data";
|
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
5
|
import { store as noticesStore } from "@wordpress/notices";
|
|
6
6
|
import { useState } from "@wordpress/element";
|
|
7
|
-
import { DataForm, isItemValid } from "@wordpress/dataviews";
|
|
8
7
|
import {
|
|
9
8
|
Button,
|
|
10
9
|
__experimentalHStack as HStack,
|
|
11
|
-
__experimentalVStack as VStack
|
|
10
|
+
__experimentalVStack as VStack,
|
|
11
|
+
__experimentalInputControl as InputControl
|
|
12
12
|
} from "@wordpress/components";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fields: ["menu_order"]
|
|
17
|
-
};
|
|
13
|
+
function isItemValid(item) {
|
|
14
|
+
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order) && item.menu_order > 0;
|
|
15
|
+
}
|
|
18
16
|
function ReorderModal({
|
|
19
17
|
items,
|
|
20
18
|
closeModal,
|
|
21
19
|
onActionPerformed
|
|
22
20
|
}) {
|
|
23
21
|
const [item, setItem] = useState(items[0]);
|
|
24
|
-
const orderInput = item.menu_order;
|
|
25
22
|
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
|
|
26
23
|
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
24
|
+
const isValid = isItemValid(item);
|
|
27
25
|
async function onOrder(event) {
|
|
28
26
|
event.preventDefault();
|
|
29
|
-
if (!
|
|
27
|
+
if (!isValid) {
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
30
|
try {
|
|
33
31
|
await editEntityRecord("postType", item.type, item.id, {
|
|
34
|
-
menu_order:
|
|
32
|
+
menu_order: item.menu_order
|
|
35
33
|
});
|
|
36
34
|
closeModal?.();
|
|
37
35
|
await saveEditedEntityRecord("postType", item.type, item.id, {
|
|
@@ -49,21 +47,24 @@ function ReorderModal({
|
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
|
|
53
50
|
return /* @__PURE__ */ jsx("form", { onSubmit: onOrder, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
54
51
|
/* @__PURE__ */ jsx("div", { children: __(
|
|
55
52
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
56
53
|
) }),
|
|
57
54
|
/* @__PURE__ */ jsx(
|
|
58
|
-
|
|
55
|
+
InputControl,
|
|
59
56
|
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
__next40pxDefaultSize: true,
|
|
58
|
+
label: __("Order"),
|
|
59
|
+
type: "number",
|
|
60
|
+
value: typeof item.menu_order === "number" && Number.isInteger(item.menu_order) ? String(item.menu_order) : "",
|
|
61
|
+
onChange: (value) => {
|
|
62
|
+
const parsed = parseInt(value, 10);
|
|
63
|
+
setItem({
|
|
64
|
+
...item,
|
|
65
|
+
menu_order: isNaN(parsed) ? void 0 : parsed
|
|
66
|
+
});
|
|
67
|
+
}
|
|
67
68
|
}
|
|
68
69
|
),
|
|
69
70
|
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
@@ -85,7 +86,7 @@ function ReorderModal({
|
|
|
85
86
|
variant: "primary",
|
|
86
87
|
type: "submit",
|
|
87
88
|
accessibleWhenDisabled: true,
|
|
88
|
-
disabled:
|
|
89
|
+
disabled: !isValid,
|
|
89
90
|
children: __("Save")
|
|
90
91
|
}
|
|
91
92
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": "
|
|
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\titem.menu_order > 0\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": "AA0FI,cAuBA,YAvBA;AAvFJ,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;AAqBP,SAAS,YAAa,MAA0B;AAC/C,SACC,OAAO,KAAK,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW,KAClC,KAAK,aAAa;AAEpB;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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;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa;AACd;AAKA,IAAO,uBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { resolveSelect } from "@wordpress/data";
|
|
3
|
+
import { store as coreDataStore } from "@wordpress/core-data";
|
|
2
4
|
import AuthorView from "./author-view";
|
|
3
5
|
const authorField = {
|
|
4
6
|
label: __("Author"),
|
|
5
7
|
id: "author",
|
|
6
8
|
type: "integer",
|
|
7
|
-
|
|
9
|
+
getElements: async () => {
|
|
10
|
+
const authors = await resolveSelect(coreDataStore).getEntityRecords(
|
|
11
|
+
"root",
|
|
12
|
+
"user",
|
|
13
|
+
{
|
|
14
|
+
per_page: -1
|
|
15
|
+
}
|
|
16
|
+
) ?? [];
|
|
17
|
+
return authors.map(({ id, name }) => ({
|
|
18
|
+
value: id,
|
|
19
|
+
label: name
|
|
20
|
+
}));
|
|
21
|
+
},
|
|
8
22
|
render: AuthorView,
|
|
9
23
|
sort: (a, b, direction) => {
|
|
10
24
|
const nameA = a._embedded?.author?.[0]?.name || "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/author/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\
|
|
5
|
-
"mappings": "AAIA,SAAS,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,UAAU;AACnB,SAAS,qBAAqB;AAC9B,SAAS,SAAS,qBAAqB;AAMvC,OAAO,gBAAgB;AAOvB,MAAM,cAAmD;AAAA,EACxD,OAAO,GAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,aAAa,YAAY;AACxB,UAAM,UACH,MAAM,cAAe,aAAc,EAAE;AAAA,MACtC;AAAA,MACA;AAAA,MACA;AAAA,QACC,UAAU;AAAA,MACX;AAAA,IACD,KAAO,CAAC;AACT,WAAO,QAAQ,IAAK,CAAE,EAAE,IAAI,KAAK,OAAS;AAAA,MACzC,OAAO;AAAA,MACP,OAAO;AAAA,IACR,EAAI;AAAA,EACL;AAAA,EACA,QAAQ;AAAA,EACR,MAAM,CAAE,GAAG,GAAG,cAAe;AAC5B,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAClD,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAElD,WAAO,cAAc,QAClB,MAAM,cAAe,KAAM,IAC3B,MAAM,cAAe,KAAM;AAAA,EAC/B;AAAA,EAEA,UAAU;AAAA,IACT,WAAW,CAAE,SAAS,QAAS;AAAA,EAChC;AACD;AAKA,IAAO,iBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
2
4
|
import type { BasePost } from '../types';
|
|
5
|
+
interface RenderModalProps<Item> {
|
|
6
|
+
items: Item[];
|
|
7
|
+
closeModal?: () => void;
|
|
8
|
+
onActionPerformed?: (items: Item[]) => void;
|
|
9
|
+
}
|
|
10
|
+
interface Action<Item> {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
isEligible?: (item: Item) => boolean;
|
|
14
|
+
modalFocusOnMount?: string;
|
|
15
|
+
RenderModal: (props: RenderModalProps<Item>) => JSX.Element;
|
|
16
|
+
}
|
|
3
17
|
declare const duplicatePost: Action<BasePost>;
|
|
4
18
|
/**
|
|
5
19
|
* Duplicate action for BasePost.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"AAeA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAGxD,UAAU,gBAAgB,CAAE,IAAI;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,iBAAiB,CAAC,EAAE,CAAE,KAAK,EAAE,IAAI,EAAE,KAAM,IAAI,CAAC;CAC9C;AAED,UAAU,MAAM,CAAE,IAAI;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,OAAO,CAAC;IACvC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,CAAE,KAAK,EAAE,gBAAgB,CAAE,IAAI,CAAE,KAAM,GAAG,CAAC,OAAO,CAAC;CAChE;AAED,QAAA,MAAM,aAAa,EAAE,MAAM,CAAE,QAAQ,CA6JpC,CAAC;AAEF;;GAEG;AACH,eAAe,aAAa,CAAC"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import type { Action } from '@wordpress/dataviews';
|
|
2
1
|
/**
|
|
3
2
|
* Internal dependencies
|
|
4
3
|
*/
|
|
5
4
|
import type { BasePost } from '../types';
|
|
5
|
+
interface RenderModalProps<Item> {
|
|
6
|
+
items: Item[];
|
|
7
|
+
closeModal?: () => void;
|
|
8
|
+
onActionPerformed?: (items: Item[]) => void;
|
|
9
|
+
}
|
|
10
|
+
interface Action<Item> {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
isEligible?: (item: Item) => boolean;
|
|
14
|
+
modalFocusOnMount?: string;
|
|
15
|
+
RenderModal: (props: RenderModalProps<Item>) => JSX.Element;
|
|
16
|
+
}
|
|
6
17
|
declare const reorderPage: Action<BasePost>;
|
|
7
18
|
/**
|
|
8
19
|
* Reorder action for BasePost.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"AAeA;;GAEG;AACH,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAExD,UAAU,gBAAgB,CAAE,IAAI;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,iBAAiB,CAAC,EAAE,CAAE,KAAK,EAAE,IAAI,EAAE,KAAM,IAAI,CAAC;CAC9C;AAED,UAAU,MAAM,CAAE,IAAI;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,OAAO,CAAC;IACvC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,CAAE,KAAK,EAAE,gBAAgB,CAAE,IAAI,CAAE,KAAM,GAAG,CAAC,OAAO,CAAC;CAChE;AA0GD,QAAA,MAAM,WAAW,EAAE,MAAM,CAAE,QAAQ,CAQlC,CAAC;AAEF;;GAEG;AACH,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/author/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/author/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAKlD;;GAEG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAQ9D,QAAA,MAAM,WAAW,EAAE,KAAK,CAAE,0BAA0B,CA+BnD,CAAC;AAEF;;GAEG;AACH,eAAe,WAAW,CAAC"}
|