@wordpress/fields 0.27.1-next.16d95556a.0 → 0.28.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 +2 -0
- package/README.md +6 -2
- package/build/actions/rename-post.js +9 -5
- package/build/actions/rename-post.js.map +2 -2
- package/build/actions/reset-post.js +18 -6
- package/build/actions/reset-post.js.map +2 -2
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/fields/author/author-view.js +19 -2
- package/build/fields/author/author-view.js.map +3 -3
- package/build/fields/author/index.js +1 -0
- package/build/fields/author/index.js.map +2 -2
- package/build/fields/date/index.js +3 -1
- package/build/fields/date/index.js.map +2 -2
- package/build/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/actions/rename-post.js +15 -6
- package/build-module/actions/rename-post.js.map +2 -2
- package/build-module/actions/reset-post.js +19 -7
- package/build-module/actions/reset-post.js.map +2 -2
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/fields/author/author-view.js +19 -2
- package/build-module/fields/author/author-view.js.map +2 -2
- package/build-module/fields/author/index.js +1 -0
- package/build-module/fields/author/index.js.map +2 -2
- package/build-module/fields/date/index.js +3 -1
- package/build-module/fields/date/index.js.map +2 -2
- package/build-module/index.js.map +1 -1
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/actions/reset-post.d.ts +7 -2
- package/build-types/actions/reset-post.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts +3 -3
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/fields/author/author-view.d.ts.map +1 -1
- package/build-types/fields/author/index.d.ts.map +1 -1
- package/build-types/fields/date/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/actions/rename-post.tsx +27 -8
- package/src/actions/reset-post.tsx +45 -15
- package/src/components/create-template-part-modal/index.tsx +3 -3
- package/src/fields/author/author-view.tsx +29 -3
- package/src/fields/author/index.tsx +1 -0
- package/src/fields/date/index.tsx +3 -1
- package/src/index.ts +6 -1
- package/src/stories/index.story.tsx +34 -11
- package/src/types.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -36,8 +36,8 @@ A React component that renders a modal for creating a template part. The modal d
|
|
|
36
36
|
|
|
37
37
|
_Parameters_
|
|
38
38
|
|
|
39
|
-
- _props_ `
|
|
40
|
-
- _props.modalTitle_ `{ modalTitle
|
|
39
|
+
- _props_ `{ modalTitle?: string; } & CreateTemplatePartModalContentsProps`: The component props.
|
|
40
|
+
- _props.modalTitle_ `{ modalTitle?: string; } & CreateTemplatePartModalContentsProps[ 'modalTitle' ]`:
|
|
41
41
|
|
|
42
42
|
### dateField
|
|
43
43
|
|
|
@@ -87,6 +87,10 @@ Parent field for BasePost.
|
|
|
87
87
|
|
|
88
88
|
Password field for BasePost.
|
|
89
89
|
|
|
90
|
+
### Pattern
|
|
91
|
+
|
|
92
|
+
Undocumented declaration.
|
|
93
|
+
|
|
90
94
|
### patternTitleField
|
|
91
95
|
|
|
92
96
|
Title for the pattern entity.
|
|
@@ -42,15 +42,19 @@ var renamePost = {
|
|
|
42
42
|
if (post.status === "trash") {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
if (post.type === "wp_template" && typeof post.id === "string") {
|
|
45
|
+
if (post.type === "wp_template" && typeof post.id === "string" && window?.__experimentalTemplateActivate) {
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const specialChecks = ["wp_template", "wp_template_part"];
|
|
49
|
+
if (!window?.__experimentalTemplateActivate) {
|
|
50
|
+
specialChecks.push("wp_template");
|
|
51
|
+
}
|
|
52
|
+
if (!specialChecks.includes(post.type)) {
|
|
52
53
|
return post.permissions?.update;
|
|
53
54
|
}
|
|
55
|
+
if ((0, import_utils.isTemplate)(post) && !window?.__experimentalTemplateActivate) {
|
|
56
|
+
return (0, import_utils.isTemplateRemovable)(post) && post.is_custom && post.permissions?.update;
|
|
57
|
+
}
|
|
54
58
|
if ((0, import_utils.isTemplatePart)(post)) {
|
|
55
59
|
return post.source === "custom" && !post?.has_theme_file && post.permissions?.update;
|
|
56
60
|
}
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAmB;AACnB,qBAAyB;AAEzB,sBAAmD;AACnD,wBAKO;AAEP,qBAAsC;AAMtC,yBAAuB;AACvB,
|
|
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__nextHasNoMarginBottom\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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAmB;AACnB,qBAAyB;AAEzB,sBAAmD;AACnD,wBAKO;AAEP,qBAAsC;AAMtC,yBAAuB;AACvB,mBAKO;AA4FF;AAxFL,IAAM,EAAE,cAAc,QAAI,2BAAQ,gBAAAA,WAAoB;AAEtD,IAAM,aAA4C;AAAA,EACjD,IAAI;AAAA,EACJ,WAAO,gBAAI,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,YAAK,yBAAY,IAAK,KAAK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Q,gBAAI,MAAO;AAAA,UACnB,OAAQ;AAAA,UACR,UAAW;AAAA,UACX,UAAQ;AAAA;AAAA,MACT;AAAA,MACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,SAAQ;AAAA,YACR,SAAU,MAAM;AACf,2BAAa;AAAA,YACd;AAAA,YAEE,8BAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,SAAQ;AAAA,YACR,MAAK;AAAA,YAEH,8BAAI,MAAO;AAAA;AAAA,QACd;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["patternsPrivateApis", "coreStore", "noticesStore", "VStack", "HStack"]
|
|
7
7
|
}
|
|
@@ -165,7 +165,10 @@ var resetPostAction = {
|
|
|
165
165
|
id: "reset-post",
|
|
166
166
|
label: (0, import_i18n.__)("Reset"),
|
|
167
167
|
isEligible: (item) => {
|
|
168
|
-
|
|
168
|
+
if (window?.__experimentalTemplateActivate) {
|
|
169
|
+
return item.type === "wp_template_part" && item?.source === "custom" && item?.has_theme_file;
|
|
170
|
+
}
|
|
171
|
+
return (0, import_utils.isTemplateOrTemplatePart)(item) && item?.source === "custom" && (Boolean(item.type === "wp_template" && item?.plugin) || item?.has_theme_file);
|
|
169
172
|
},
|
|
170
173
|
icon: import_icons.backup,
|
|
171
174
|
supportsBulk: true,
|
|
@@ -203,11 +206,20 @@ var resetPostAction = {
|
|
|
203
206
|
}
|
|
204
207
|
);
|
|
205
208
|
} catch (error) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
let fallbackErrorMessage;
|
|
210
|
+
if (items[0].type === "wp_template") {
|
|
211
|
+
fallbackErrorMessage = items.length === 1 ? (0, import_i18n.__)(
|
|
212
|
+
"An error occurred while reverting the template."
|
|
213
|
+
) : (0, import_i18n.__)(
|
|
214
|
+
"An error occurred while reverting the templates."
|
|
215
|
+
);
|
|
216
|
+
} else {
|
|
217
|
+
fallbackErrorMessage = items.length === 1 ? (0, import_i18n.__)(
|
|
218
|
+
"An error occurred while reverting the template part."
|
|
219
|
+
) : (0, import_i18n.__)(
|
|
220
|
+
"An error occurred while reverting the template parts."
|
|
221
|
+
);
|
|
222
|
+
}
|
|
211
223
|
const typedError = error;
|
|
212
224
|
const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : fallbackErrorMessage;
|
|
213
225
|
createErrorNotice(errorMessage, { type: "snackbar" });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/reset-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { dispatch, select, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from './utils';\nimport type { CoreDataError, TemplatePart } from '../types';\n\nconst isTemplateRevertable = (
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuB;AACvB,kBAA8C;AAC9C,uBAAmC;AACnC,kBAA4B;AAC5B,qBAAsC;AACtC,qBAAyB;AAEzB,oBAAmD;AACnD,wBAKO;AAEP,iBAA6B;AAC7B,uBAAqB;AAKrB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { dispatch, select, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, Template, TemplatePart } from '../types';\n\ndeclare global {\n\tinterface Window {\n\t\t__experimentalTemplateActivate?: boolean;\n\t}\n}\n\nconst isTemplateRevertable = (\n\ttemplateOrTemplatePart: Template | TemplatePart\n) => {\n\tif ( ! templateOrTemplatePart ) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\ttemplateOrTemplatePart.source === 'custom' &&\n\t\t( Boolean( templateOrTemplatePart?.plugin ) ||\n\t\t\ttemplateOrTemplatePart?.has_theme_file )\n\t);\n};\n\n/**\n * Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365\n *\n * @param {Object} template The template to revert.\n * @param {Object} [options]\n * @param {boolean} [options.allowUndo] Whether to allow the user to undo\n * reverting the template. Default true.\n */\nconst revertTemplate = async (\n\ttemplate: TemplatePart | Template,\n\t{ allowUndo = true } = {}\n) => {\n\tconst noticeId = 'edit-site-template-reverted';\n\tdispatch( noticesStore ).removeNotice( noticeId );\n\tif ( ! isTemplateRevertable( template ) ) {\n\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t__( 'This template is not revertable.' ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst templateEntityConfig = select( coreStore ).getEntityConfig(\n\t\t\t'postType',\n\t\t\ttemplate.type\n\t\t);\n\n\t\tif ( ! templateEntityConfig ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileTemplatePath = addQueryArgs(\n\t\t\t`${ templateEntityConfig.baseURL }/${ template.id }`,\n\t\t\t{ context: 'edit', source: template.origin }\n\t\t);\n\n\t\tconst fileTemplate = ( await apiFetch( {\n\t\t\tpath: fileTemplatePath,\n\t\t} ) ) as any;\n\t\tif ( ! fileTemplate ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\tconst edited = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id\n\t\t) as any;\n\n\t\t// We are fixing up the undo level here to make sure we can undo\n\t\t// the revert in the header toolbar correctly.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks, // Required to make the `undo` behave correctly.\n\t\t\t\tblocks: edited.blocks, // Required to revert the blocks in the editor.\n\t\t\t\tsource: 'custom', // required to avoid turning the editor into a dirty state\n\t\t\t},\n\t\t\t{\n\t\t\t\tundoIgnore: true, // Required to merge this edit with the last undo level.\n\t\t\t}\n\t\t);\n\n\t\tconst blocks = parse( fileTemplate?.content?.raw );\n\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\tfileTemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks,\n\t\t\t\tblocks,\n\t\t\t\tsource: 'theme',\n\t\t\t}\n\t\t);\n\n\t\tif ( allowUndo ) {\n\t\t\tconst undoRevert = () => {\n\t\t\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tedited.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: serializeBlocks,\n\t\t\t\t\t\tblocks: edited.blocks,\n\t\t\t\t\t\tsource: 'custom',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tdispatch( noticesStore ).createSuccessNotice(\n\t\t\t\t__( 'Template reset.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: noticeId,\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: undoRevert,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t} catch ( error: any ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'Template revert failed. Please reload.' );\n\n\t\tdispatch( noticesStore ).createErrorNotice( errorMessage, {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t}\n};\n\nconst resetPostAction: Action< Template | TemplatePart > = {\n\tid: 'reset-post',\n\tlabel: __( 'Reset' ),\n\tisEligible: ( item ) => {\n\t\tif ( window?.__experimentalTemplateActivate ) {\n\t\t\treturn (\n\t\t\t\titem.type === 'wp_template_part' &&\n\t\t\t\titem?.source === 'custom' &&\n\t\t\t\titem?.has_theme_file\n\t\t\t);\n\t\t}\n\n\t\t// When experiment is disabled: use wp/6.9 logic for both templates and template parts.\n\t\treturn (\n\t\t\tisTemplateOrTemplatePart( item ) &&\n\t\t\titem?.source === 'custom' &&\n\t\t\t( Boolean( item.type === 'wp_template' && item?.plugin ) ||\n\t\t\t\titem?.has_theme_file )\n\t\t);\n\t},\n\ticon: backup,\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\t\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst onConfirm = async () => {\n\t\t\ttry {\n\t\t\t\tfor ( const template of items ) {\n\t\t\t\t\tawait revertTemplate( template, {\n\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t} );\n\t\t\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\ttemplate.type,\n\t\t\t\t\t\ttemplate.id\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\titems.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: %d: The number of items. */\n\t\t\t\t\t\t\t\t__( '%d items reset.' ),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: The template/part's name. */\n\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'revert-template-action',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet fallbackErrorMessage;\n\t\t\t\tif ( items[ 0 ].type === 'wp_template' ) {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the templates.'\n\t\t\t\t\t\t\t );\n\t\t\t\t} else {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template part.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template parts.'\n\t\t\t\t\t\t\t );\n\t\t\t\t}\n\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: fallbackErrorMessage;\n\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t};\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ __( 'Reset to default and clear all customizations?' ) }\n\t\t\t\t</Text>\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={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\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\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tawait onConfirm();\n\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\n/**\n * Reset action for Template and TemplatePart.\n */\nexport default resetPostAction;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuB;AACvB,kBAA8C;AAC9C,uBAAmC;AACnC,kBAA4B;AAC5B,qBAAsC;AACtC,qBAAyB;AAEzB,oBAAmD;AACnD,wBAKO;AAEP,iBAA6B;AAC7B,uBAAqB;AAKrB,mBAAuD;AA2PnD;AAlPJ,IAAM,uBAAuB,CAC5B,2BACI;AACJ,MAAK,CAAE,wBAAyB;AAC/B,WAAO;AAAA,EACR;AAEA,SACC,uBAAuB,WAAW,aAChC,QAAS,wBAAwB,MAAO,KACzC,wBAAwB;AAE3B;AAUA,IAAM,iBAAiB,OACtB,UACA,EAAE,YAAY,KAAK,IAAI,CAAC,MACpB;AACJ,QAAM,WAAW;AACjB,4BAAU,eAAAA,KAAa,EAAE,aAAc,QAAS;AAChD,MAAK,CAAE,qBAAsB,QAAS,GAAI;AACzC,8BAAU,eAAAA,KAAa,EAAE;AAAA,UACxB,gBAAI,kCAAmC;AAAA,MACvC;AAAA,QACC,MAAM;AAAA,MACP;AAAA,IACD;AACA;AAAA,EACD;AAEA,MAAI;AACH,UAAM,2BAAuB,oBAAQ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,SAAQ;AAAA,YACR,SAAU,YAAY;AACrB,wBAAW,IAAK;AAChB,oBAAM,UAAU;AAChB,kCAAqB,KAAM;AAC3B,wBAAW,KAAM;AACjB,2BAAa;AAAA,YACd;AAAA,YACA;AAAA,YACA,UAAW;AAAA,YACX,wBAAsB;AAAA,YAEpB,8BAAI,OAAQ;AAAA;AAAA,QACf;AAAA,SACD;AAAA,OACD;AAAA,EAEF;AACD;AAKA,IAAO,qBAAQ;",
|
|
6
6
|
"names": ["noticesStore", "coreStore", "apiFetch", "VStack", "Text", "HStack"]
|
|
7
7
|
}
|
|
@@ -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\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
|
|
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\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\nconst getTemplatePartIcon = ( iconName: string ) => {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\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
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAQO;AACP,qBAA8B;AAE9B,uBAAmC;AACnC,kBAAuC;AACvC,qBAAyB;AACzB,kBAAmB;AACnB,mBAMO;AACP,qBAAsC;AAEtC,oBAA0B;AAK1B,mBAIO;AA6CJ;AA3CH,SAAS,eAAgB,OAAe,YAAqB;AAC5D,SAAO,kDAAmD,KAAM,IAAK,UAAW;AACjF;AACA,SAAS,0BAA2B,OAAe,YAAqB;AACvE,SAAO,8DAA+D,KAAM,IAAK,UAAW;AAC7F;AAkBe,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,GAAG;AACJ,GAE2C;AAC1C,QAAM,wBAAoB;AAAA,IACzB,CAAE,WACD,OAAQ,iBAAAA,KAAU,EAAE,YAAa,kBAAmB,GAAG,QAC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AK;AAAA,wBACb,SAAU,SAAS,KAAK;AAAA,wBACxB,UAAW,MAAM;AAChB,kCAAS,KAAK,IAAK;AAAA,wBACpB;AAAA,wBACA,oBAAmB;AAAA,0BAClB,KAAK;AAAA,0BACL;AAAA,wBACD;AAAA;AAAA,oBACD;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA;AAAA,wBACA,WAAU;AAAA;AAAA,oBACX;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,SAAU;AAAA,0BACT,KAAK;AAAA,0BACL;AAAA,wBACD;AAAA,wBACA,WAAU;AAAA,wBAER,eAAK;AAAA;AAAA,oBACR;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,MAAO;AAAA,wBACP,WAAU;AAAA;AAAA,oBACX;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,WAAU;AAAA,wBACV,IAAK;AAAA,0BACJ,KAAK;AAAA,0BACL;AAAA,wBACD;AAAA,wBAEE,eAAK;AAAA;AAAA,oBACR;AAAA;AAAA;AAAA,gBA7CM,KAAK;AAAA,cA8CZ;AAAA,YAEF;AAAA,UACD,GACD;AAAA,WACD;AAAA,QACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,SAAU,MAAM;AACf,2BAAW;AAAA,cACZ;AAAA,cAEE,8BAAI,QAAS;AAAA;AAAA,UAChB;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,iBAAgB,CAAE,SAAS;AAAA,cAC3B,QAAS;AAAA,cAEP;AAAA;AAAA,UACH;AAAA,WACD;AAAA,SACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["coreStore", "headerIcon", "footerIcon", "sidebarIcon", "symbolFilledIcon", "noticesStore", "VStack", "HStack"]
|
|
7
7
|
}
|
|
@@ -38,10 +38,27 @@ var import_i18n = require("@wordpress/i18n");
|
|
|
38
38
|
var import_element = require("@wordpress/element");
|
|
39
39
|
var import_icons = require("@wordpress/icons");
|
|
40
40
|
var import_components = require("@wordpress/components");
|
|
41
|
+
var import_data = require("@wordpress/data");
|
|
42
|
+
var import_core_data = require("@wordpress/core-data");
|
|
41
43
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
44
|
function AuthorView({ item }) {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
+
const authorId = item?.author;
|
|
46
|
+
const embeddedAuthorId = item?._embedded?.author?.[0]?.id;
|
|
47
|
+
const shouldFetch = Boolean(
|
|
48
|
+
authorId && embeddedAuthorId && authorId !== embeddedAuthorId
|
|
49
|
+
);
|
|
50
|
+
const author = (0, import_data.useSelect)(
|
|
51
|
+
(select) => {
|
|
52
|
+
if (!shouldFetch) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const { getEntityRecord } = select(import_core_data.store);
|
|
56
|
+
return authorId ? getEntityRecord("root", "user", authorId) : null;
|
|
57
|
+
},
|
|
58
|
+
[authorId, shouldFetch]
|
|
59
|
+
);
|
|
60
|
+
const text = author?.name || item?._embedded?.author?.[0]?.name;
|
|
61
|
+
const imageUrl = author?.avatar_urls?.[48] || item?._embedded?.author?.[0]?.avatar_urls?.[48];
|
|
45
62
|
const [isImageLoaded, setIsImageLoaded] = (0, import_element.useState)(false);
|
|
46
63
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { alignment: "left", spacing: 0, children: [
|
|
47
64
|
!!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/author/author-view.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport { __experimentalHStack as HStack, Icon } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\n\nfunction AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {\n\tconst text = item?._embedded?.author?.[ 0 ]?.name;\n\tconst imageUrl
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAAmB;AACnB,qBAAyB;AACzB,mBAAkD;AAClD,wBAAqD;
|
|
6
|
-
"names": ["HStack", "clsx", "authorIcon"]
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport { __experimentalHStack as HStack, Icon } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\n\nfunction AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {\n\t// When editing, item.author may differ from _embedded.author (which preserves\n\t// the saved record). Fetch the updated author only when they differ, so the\n\t// view reflects edits while lists preserve original data.\n\tconst authorId = item?.author;\n\tconst embeddedAuthorId = item?._embedded?.author?.[ 0 ]?.id;\n\tconst shouldFetch = Boolean(\n\t\tauthorId && embeddedAuthorId && authorId !== embeddedAuthorId\n\t);\n\tconst author = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! shouldFetch ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\t// This doesn't make extra REST requests because the records are\n\t\t\t// already in the store from the field's getElements function.\n\t\t\treturn authorId\n\t\t\t\t? getEntityRecord( 'root', 'user', authorId )\n\t\t\t\t: null;\n\t\t},\n\t\t[ authorId, shouldFetch ]\n\t);\n\t// Use fetched author if available, otherwise use _embedded.\n\tconst text = author?.name || item?._embedded?.author?.[ 0 ]?.name;\n\tconst imageUrl =\n\t\tauthor?.avatar_urls?.[ 48 ] ||\n\t\titem?._embedded?.author?.[ 0 ]?.avatar_urls?.[ 48 ];\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt={ __( 'Author avatar' ) }\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport default AuthorView;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAAmB;AACnB,qBAAyB;AACzB,mBAAkD;AAClD,wBAAqD;AACrD,kBAA0B;AAC1B,uBAAmC;AAqCjC;AA9BF,SAAS,WAAY,EAAE,KAAK,GAA0C;AAIrE,QAAM,WAAW,MAAM;AACvB,QAAM,mBAAmB,MAAM,WAAW,SAAU,CAAE,GAAG;AACzD,QAAM,cAAc;AAAA,IACnB,YAAY,oBAAoB,aAAa;AAAA,EAC9C;AACA,QAAM,aAAS;AAAA,IACd,CAAE,WAAY;AACb,UAAK,CAAE,aAAc;AACpB,eAAO;AAAA,MACR;AACA,YAAM,EAAE,gBAAgB,IAAI,OAAQ,iBAAAA,KAAU;AAG9C,aAAO,WACJ,gBAAiB,QAAQ,QAAQ,QAAS,IAC1C;AAAA,IACJ;AAAA,IACA,CAAE,UAAU,WAAY;AAAA,EACzB;AAEA,QAAM,OAAO,QAAQ,QAAQ,MAAM,WAAW,SAAU,CAAE,GAAG;AAC7D,QAAM,WACL,QAAQ,cAAe,EAAG,KAC1B,MAAM,WAAW,SAAU,CAAE,GAAG,cAAe,EAAG;AACnD,QAAM,CAAE,eAAe,gBAAiB,QAAI,yBAAU,KAAM;AAC5D,SACC,6CAAC,kBAAAC,sBAAA,EAAO,WAAU,QAAO,SAAU,GAChC;AAAA,KAAC,CAAE,YACJ;AAAA,MAAC;AAAA;AAAA,QACA,eAAY,YAAAC,SAAM,uCAAuC;AAAA,UACxD,aAAa;AAAA,QACd,CAAE;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACA,QAAS,MAAM,iBAAkB,IAAK;AAAA,YACtC,SAAM,gBAAI,eAAgB;AAAA,YAC1B,KAAM;AAAA;AAAA,QACP;AAAA;AAAA,IACD;AAAA,IAEC,CAAE,YACH,4CAAC,SAAI,WAAU,qCACd,sDAAC,0BAAK,MAAO,aAAAC,qBAAa,GAC3B;AAAA,IAED,4CAAC,UAAK,WAAU,qCAAsC,gBAAM;AAAA,KAC7D;AAEF;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": ["coreStore", "HStack", "clsx", "authorIcon"]
|
|
7
7
|
}
|
|
@@ -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';\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,IAAM,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;",
|
|
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\tsetValue: ( { value } ) => ( { author: Number( value ) } ),\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,IAAM,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,UAAU,CAAE,EAAE,MAAM,OAAS,EAAE,QAAQ,OAAQ,KAAM,EAAE;AAAA,EACvD,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
6
|
"names": ["coreDataStore", "AuthorView"]
|
|
7
7
|
}
|
|
@@ -40,7 +40,9 @@ var dateField = {
|
|
|
40
40
|
type: "datetime",
|
|
41
41
|
label: (0, import_i18n.__)("Date"),
|
|
42
42
|
render: import_date_view.default,
|
|
43
|
-
filterBy:
|
|
43
|
+
filterBy: {
|
|
44
|
+
operators: ["before", "after"]
|
|
45
|
+
}
|
|
44
46
|
};
|
|
45
47
|
var date_default = dateField;
|
|
46
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/date/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 { BasePost } from '../../types';\nimport DateView from './date-view';\n\nconst dateField: Field< BasePost > = {\n\tid: 'date',\n\ttype: 'datetime',\n\tlabel: __( 'Date' ),\n\trender: DateView,\n\tfilterBy:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;AAMnB,uBAAqB;AAErB,IAAM,YAA+B;AAAA,EACpC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,MAAO;AAAA,EAClB,QAAQ,iBAAAA;AAAA,EACR,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport DateView from './date-view';\n\nconst dateField: Field< BasePost > = {\n\tid: 'date',\n\ttype: 'datetime',\n\tlabel: __( 'Date' ),\n\trender: DateView,\n\tfilterBy: {\n\t\toperators: [ 'before', 'after' ],\n\t},\n};\n\n/**\n * Date field for BasePost.\n */\nexport default dateField;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;AAMnB,uBAAqB;AAErB,IAAM,YAA+B;AAAA,EACpC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,MAAO;AAAA,EAClB,QAAQ,iBAAAA;AAAA,EACR,UAAU;AAAA,IACT,WAAW,CAAE,UAAU,OAAQ;AAAA,EAChC;AACD;AAKA,IAAO,eAAQ;",
|
|
6
6
|
"names": ["DateView"]
|
|
7
7
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type {
|
|
4
|
+
"sourcesContent": ["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type {\n\tBasePostWithEmbeddedAuthor,\n\tBasePost,\n\tPostType,\n\tPattern,\n} from './types';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,qBAAd;AACA,0BAAc,sBADd;AAEA,wCAAmD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\n/**\n * BasePost interface used for all post types.\n */\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\ninterface FeaturedMedia {\n\ttitle: {\n\t\trendered: string;\n\t};\n\tsource_url: string;\n\tmedia_details: {\n\t\tsizes: Record< string, { width: number; source_url: string } >;\n\t};\n}\n\ninterface EmbeddedFeaturedMedia {\n\t'wp:featuredmedia': FeaturedMedia[];\n}\n\nexport interface BasePostWithEmbeddedFeaturedMedia extends BasePost {\n\t_embedded: EmbeddedFeaturedMedia;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t\teditor?: boolean;\n\t\ttrackbacks?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],
|
|
4
|
+
"sourcesContent": ["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tid: number;\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\n/**\n * BasePost interface used for all post types.\n */\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\ninterface FeaturedMedia {\n\ttitle: {\n\t\trendered: string;\n\t};\n\tsource_url: string;\n\tmedia_details: {\n\t\tsizes: Record< string, { width: number; source_url: string } >;\n\t};\n}\n\ninterface EmbeddedFeaturedMedia {\n\t'wp:featuredmedia': FeaturedMedia[];\n}\n\nexport interface BasePostWithEmbeddedFeaturedMedia extends BasePost {\n\t_embedded: EmbeddedFeaturedMedia;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t\teditor?: boolean;\n\t\ttrackbacks?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,12 @@ import {
|
|
|
12
12
|
} from "@wordpress/components";
|
|
13
13
|
import { store as noticesStore } from "@wordpress/notices";
|
|
14
14
|
import { unlock } from "../lock-unlock";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
getItemTitle,
|
|
17
|
+
isTemplateRemovable,
|
|
18
|
+
isTemplate,
|
|
19
|
+
isTemplatePart
|
|
20
|
+
} from "./utils";
|
|
16
21
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
22
|
var { PATTERN_TYPES } = unlock(patternsPrivateApis);
|
|
18
23
|
var renamePost = {
|
|
@@ -23,15 +28,19 @@ var renamePost = {
|
|
|
23
28
|
if (post.status === "trash") {
|
|
24
29
|
return false;
|
|
25
30
|
}
|
|
26
|
-
if (post.type === "wp_template" && typeof post.id === "string") {
|
|
31
|
+
if (post.type === "wp_template" && typeof post.id === "string" && window?.__experimentalTemplateActivate) {
|
|
27
32
|
return false;
|
|
28
33
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const specialChecks = ["wp_template", "wp_template_part"];
|
|
35
|
+
if (!window?.__experimentalTemplateActivate) {
|
|
36
|
+
specialChecks.push("wp_template");
|
|
37
|
+
}
|
|
38
|
+
if (!specialChecks.includes(post.type)) {
|
|
33
39
|
return post.permissions?.update;
|
|
34
40
|
}
|
|
41
|
+
if (isTemplate(post) && !window?.__experimentalTemplateActivate) {
|
|
42
|
+
return isTemplateRemovable(post) && post.is_custom && post.permissions?.update;
|
|
43
|
+
}
|
|
35
44
|
if (isTemplatePart(post)) {
|
|
36
45
|
return post.source === "custom" && !post?.has_theme_file && post.permissions?.update;
|
|
37
46
|
}
|
|
@@ -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 {
|
|
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,
|
|
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__nextHasNoMarginBottom\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,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AA,UACvD;AAAA,QACD,CAAE;AAEF,iBAAU,EAAG;AACb,qBAAa;AAEb,cAAM,uBAAwB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,UAC7D,cAAc;AAAA,QACf,CAAE;AACF,4BAAqB,GAAI,cAAe,GAAG;AAAA,UAC1C,MAAM;AAAA,QACP,CAAE;AACF,4BAAqB,KAAM;AAAA,MAC5B,SAAU,OAAQ;AACjB,cAAM,aAAa;AACnB,cAAM,eACL,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,UACX,GAAI,2CAA4C;AACpD,0BAAmB,cAAc,EAAE,MAAM,WAAW,CAAE;AAAA,MACvD;AAAA,IACD;AAEA,WACC,oBAAC,UAAK,UAAW,UAChB,+BAAC,UAAO,SAAQ,KACf;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,yBAAuB;AAAA,UACvB,uBAAqB;AAAA,UACrB,OAAQ,GAAI,MAAO;AAAA,UACnB,OAAQ;AAAA,UACR,UAAW;AAAA,UACX,UAAQ;AAAA;AAAA,MACT;AAAA,MACA,qBAAC,UAAO,SAAQ,SACf;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;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
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "@wordpress/components";
|
|
15
15
|
import { addQueryArgs } from "@wordpress/url";
|
|
16
16
|
import apiFetch from "@wordpress/api-fetch";
|
|
17
|
-
import { getItemTitle } from "./utils";
|
|
17
|
+
import { getItemTitle, isTemplateOrTemplatePart } from "./utils";
|
|
18
18
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
19
|
var isTemplateRevertable = (templateOrTemplatePart) => {
|
|
20
20
|
if (!templateOrTemplatePart) {
|
|
@@ -136,7 +136,10 @@ var resetPostAction = {
|
|
|
136
136
|
id: "reset-post",
|
|
137
137
|
label: __("Reset"),
|
|
138
138
|
isEligible: (item) => {
|
|
139
|
-
|
|
139
|
+
if (window?.__experimentalTemplateActivate) {
|
|
140
|
+
return item.type === "wp_template_part" && item?.source === "custom" && item?.has_theme_file;
|
|
141
|
+
}
|
|
142
|
+
return isTemplateOrTemplatePart(item) && item?.source === "custom" && (Boolean(item.type === "wp_template" && item?.plugin) || item?.has_theme_file);
|
|
140
143
|
},
|
|
141
144
|
icon: backup,
|
|
142
145
|
supportsBulk: true,
|
|
@@ -174,11 +177,20 @@ var resetPostAction = {
|
|
|
174
177
|
}
|
|
175
178
|
);
|
|
176
179
|
} catch (error) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
let fallbackErrorMessage;
|
|
181
|
+
if (items[0].type === "wp_template") {
|
|
182
|
+
fallbackErrorMessage = items.length === 1 ? __(
|
|
183
|
+
"An error occurred while reverting the template."
|
|
184
|
+
) : __(
|
|
185
|
+
"An error occurred while reverting the templates."
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
fallbackErrorMessage = items.length === 1 ? __(
|
|
189
|
+
"An error occurred while reverting the template part."
|
|
190
|
+
) : __(
|
|
191
|
+
"An error occurred while reverting the template parts."
|
|
192
|
+
);
|
|
193
|
+
}
|
|
182
194
|
const typedError = error;
|
|
183
195
|
const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : fallbackErrorMessage;
|
|
184
196
|
createErrorNotice(errorMessage, { type: "snackbar" });
|