| @@ -210,9 +210,9 @@ | ||
| 210 | 210 | const fileContent = await file.text(); |
| 211 | 211 | let parsedContent; |
| 212 | 212 | try { |
| 213 | 213 | parsedContent = JSON.parse(fileContent); |
| 214 | - } catch { | |
| 214 | + } catch (e) { | |
| 215 | 215 | throw new Error("Invalid JSON file"); |
| 216 | 216 | } |
| 217 | 217 | if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") { |
| 218 | 218 | throw new Error("Invalid pattern JSON file"); |
| @@ -885,8 +885,9 @@ | ||
| 885 | 885 | ref: pattern.id |
| 886 | 886 | }); |
| 887 | 887 | replaceBlocks(clientIds, newBlock); |
| 888 | 888 | setEditingPattern2(newBlock.clientId, true); |
| 889 | + closeBlockSettingsMenu(); | |
| 889 | 890 | } |
| 890 | 891 | createSuccessNotice( |
| 891 | 892 | pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ? (0, import_i18n6.sprintf)( |
| 892 | 893 | // translators: %s: the name the user has given to the pattern. |
| @@ -902,9 +903,8 @@ | ||
| 902 | 903 | id: "convert-to-pattern-success" |
| 903 | 904 | } |
| 904 | 905 | ); |
| 905 | 906 | setIsModalOpen(false); |
| 906 | - closeBlockSettingsMenu(); | |
| 907 | 907 | }; |
| 908 | 908 | return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [ |
| 909 | 909 | /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( |
| 910 | 910 | import_components5.MenuItem, |
| @@ -927,9 +927,8 @@ | ||
| 927 | 927 | setIsModalOpen(false); |
| 928 | 928 | }, |
| 929 | 929 | onClose: () => { |
| 930 | 930 | setIsModalOpen(false); |
| 931 | - closeBlockSettingsMenu(); | |
| 932 | 931 | } |
| 933 | 932 | } |
| 934 | 933 | ) |
| 935 | 934 | ] }); |
| @@ -939,15 +938,13 @@ | ||
| 939 | 938 | var import_components6 = __toESM(require_components(), 1); |
| 940 | 939 | var import_i18n7 = __toESM(require_i18n(), 1); |
| 941 | 940 | var import_blocks3 = __toESM(require_blocks(), 1); |
| 942 | 941 | var import_data9 = __toESM(require_data(), 1); |
| 943 | - var import_element7 = __toESM(require_element(), 1); | |
| 944 | 942 | var import_block_editor4 = __toESM(require_block_editor(), 1); |
| 945 | 943 | var import_url = __toESM(require_url(), 1); |
| 946 | 944 | var import_core_data7 = __toESM(require_core_data(), 1); |
| 947 | 945 | var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1); |
| 948 | - function PatternsManageButton({ clientId, onClose }) { | |
| 949 | - const [showConfirmDialog, setShowConfirmDialog] = (0, import_element7.useState)(false); | |
| 946 | + function PatternsManageButton({ clientId }) { | |
| 950 | 947 | const { |
| 951 | 948 | attributes, |
| 952 | 949 | canDetach, |
| 953 | 950 | isVisible, |
| @@ -997,42 +994,29 @@ | ||
| 997 | 994 | ); |
| 998 | 995 | if (!isVisible || !canEdit) { |
| 999 | 996 | return null; |
| 1000 | 997 | } |
| 1001 | - const handleDetach = () => { | |
| 1002 | - if (isSyncedPattern) { | |
| 1003 | - convertSyncedPatternToStatic2(clientId); | |
| 1004 | - } | |
| 1005 | - if (isUnsyncedPattern) { | |
| 1006 | - const { patternName, ...attributesWithoutPatternName } = attributes?.metadata ?? {}; | |
| 1007 | - updateBlockAttributes(clientId, { | |
| 1008 | - metadata: attributesWithoutPatternName | |
| 1009 | - }); | |
| 1010 | - } | |
| 1011 | - onClose?.(); | |
| 1012 | - setShowConfirmDialog(false); | |
| 1013 | - }; | |
| 1014 | 998 | return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [ |
| 1015 | - canDetach && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [ | |
| 1016 | - /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components6.MenuItem, { onClick: () => setShowConfirmDialog(true), children: (0, import_i18n7.__)("Detach") }), | |
| 1017 | - /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( | |
| 1018 | - import_components6.__experimentalConfirmDialog, | |
| 1019 | - { | |
| 1020 | - isOpen: showConfirmDialog, | |
| 1021 | - onConfirm: handleDetach, | |
| 1022 | - onCancel: () => setShowConfirmDialog(false), | |
| 1023 | - confirmButtonText: (0, import_i18n7.__)("Detach"), | |
| 1024 | - size: "medium", | |
| 1025 | - title: (0, import_i18n7.__)("Detach pattern?"), | |
| 1026 | - __experimentalHideHeader: false, | |
| 1027 | - children: isSyncedPattern ? (0, import_i18n7.__)( | |
| 1028 | - "The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here." | |
| 1029 | - ) : (0, import_i18n7.__)( | |
| 1030 | - "Blocks will no longer be associated with this pattern and will be fully editable." | |
| 1031 | - ) | |
| 1032 | - } | |
| 1033 | - ) | |
| 1034 | - ] }), | |
| 999 | + canDetach && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( | |
| 1000 | + import_components6.MenuItem, | |
| 1001 | + { | |
| 1002 | + onClick: () => { | |
| 1003 | + if (isSyncedPattern) { | |
| 1004 | + convertSyncedPatternToStatic2(clientId); | |
| 1005 | + } | |
| 1006 | + if (isUnsyncedPattern) { | |
| 1007 | + const { | |
| 1008 | + patternName, | |
| 1009 | + ...attributesWithoutPatternName | |
| 1010 | + } = attributes?.metadata ?? {}; | |
| 1011 | + updateBlockAttributes(clientId, { | |
| 1012 | + metadata: attributesWithoutPatternName | |
| 1013 | + }); | |
| 1014 | + } | |
| 1015 | + }, | |
| 1016 | + children: isSyncedPattern ? (0, import_i18n7.__)("Disconnect pattern") : (0, import_i18n7.__)("Detach pattern") | |
| 1017 | + } | |
| 1018 | + ), | |
| 1035 | 1019 | /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components6.MenuItem, { href: managePatternsUrl, children: (0, import_i18n7.__)("Manage patterns") }) |
| 1036 | 1020 | ] }); |
| 1037 | 1021 | } |
| 1038 | 1022 | var patterns_manage_button_default = PatternsManageButton; |
| @@ -1051,10 +1035,9 @@ | ||
| 1051 | 1035 | ), |
| 1052 | 1036 | selectedClientIds.length === 1 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( |
| 1053 | 1037 | patterns_manage_button_default, |
| 1054 | 1038 | { |
| 1055 | - clientId: selectedClientIds[0], | |
| 1056 | - onClose | |
| 1039 | + clientId: selectedClientIds[0] | |
| 1057 | 1040 | } |
| 1058 | 1041 | ) |
| 1059 | 1042 | ] }) }); |
| 1060 | 1043 | } |
| @@ -1062,9 +1045,9 @@ | ||
| 1062 | 1045 | // packages/patterns/build-module/components/rename-pattern-category-modal.mjs |
| 1063 | 1046 | var import_components7 = __toESM(require_components(), 1); |
| 1064 | 1047 | var import_core_data8 = __toESM(require_core_data(), 1); |
| 1065 | 1048 | var import_data10 = __toESM(require_data(), 1); |
| 1066 | - var import_element8 = __toESM(require_element(), 1); | |
| 1049 | + var import_element7 = __toESM(require_element(), 1); | |
| 1067 | 1050 | var import_html_entities3 = __toESM(require_html_entities(), 1); |
| 1068 | 1051 | var import_i18n8 = __toESM(require_i18n(), 1); |
| 1069 | 1052 | var import_notices5 = __toESM(require_notices(), 1); |
| 1070 | 1053 | var import_a11y = __toESM(require_a11y(), 1); |
| @@ -1076,13 +1059,13 @@ | ||
| 1076 | 1059 | onError, |
| 1077 | 1060 | onSuccess, |
| 1078 | 1061 | ...props |
| 1079 | 1062 | }) { |
| 1080 | - const id = (0, import_element8.useId)(); | |
| 1081 | - const textControlRef = (0, import_element8.useRef)(); | |
| 1082 | - const [name, setName] = (0, import_element8.useState)((0, import_html_entities3.decodeEntities)(category.name)); | |
| 1083 | - const [isSaving, setIsSaving] = (0, import_element8.useState)(false); | |
| 1084 | - const [validationMessage, setValidationMessage] = (0, import_element8.useState)(false); | |
| 1063 | + const id = (0, import_element7.useId)(); | |
| 1064 | + const textControlRef = (0, import_element7.useRef)(); | |
| 1065 | + const [name, setName] = (0, import_element7.useState)((0, import_html_entities3.decodeEntities)(category.name)); | |
| 1066 | + const [isSaving, setIsSaving] = (0, import_element7.useState)(false); | |
| 1067 | + const [validationMessage, setValidationMessage] = (0, import_element7.useState)(false); | |
| 1085 | 1068 | const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-${id}` : void 0; |
| 1086 | 1069 | const { saveEntityRecord, invalidateResolution } = (0, import_data10.useDispatch)(import_core_data8.store); |
| 1087 | 1070 | const { createErrorNotice, createSuccessNotice } = (0, import_data10.useDispatch)(import_notices5.store); |
| 1088 | 1071 | const onChange = (newName) => { |
| @@ -1203,9 +1186,9 @@ | ||
| 1203 | 1186 | ); |
| 1204 | 1187 | } |
| 1205 | 1188 | |
| 1206 | 1189 | // packages/patterns/build-module/components/pattern-overrides-controls.mjs |
| 1207 | - var import_element10 = __toESM(require_element(), 1); | |
| 1190 | + var import_element9 = __toESM(require_element(), 1); | |
| 1208 | 1191 | var import_block_editor6 = __toESM(require_block_editor(), 1); |
| 1209 | 1192 | var import_components9 = __toESM(require_components(), 1); |
| 1210 | 1193 | var import_i18n10 = __toESM(require_i18n(), 1); |
| 1211 | 1194 | |
| @@ -1211,9 +1194,9 @@ | ||
| 1211 | 1194 | |
| 1212 | 1195 | // packages/patterns/build-module/components/allow-overrides-modal.mjs |
| 1213 | 1196 | var import_components8 = __toESM(require_components(), 1); |
| 1214 | 1197 | var import_i18n9 = __toESM(require_i18n(), 1); |
| 1215 | - var import_element9 = __toESM(require_element(), 1); | |
| 1198 | + var import_element8 = __toESM(require_element(), 1); | |
| 1216 | 1199 | var import_a11y2 = __toESM(require_a11y(), 1); |
| 1217 | 1200 | var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1); |
| 1218 | 1201 | function AllowOverridesModal({ |
| 1219 | 1202 | placeholder, |
| @@ -1220,10 +1203,10 @@ | ||
| 1220 | 1203 | initialName = "", |
| 1221 | 1204 | onClose, |
| 1222 | 1205 | onSave |
| 1223 | 1206 | }) { |
| 1224 | - const [editedBlockName, setEditedBlockName] = (0, import_element9.useState)(initialName); | |
| 1225 | - const descriptionId = (0, import_element9.useId)(); | |
| 1207 | + const [editedBlockName, setEditedBlockName] = (0, import_element8.useState)(initialName); | |
| 1208 | + const descriptionId = (0, import_element8.useId)(); | |
| 1226 | 1209 | const isNameValid = !!editedBlockName.trim(); |
| 1227 | 1210 | const handleSubmit = () => { |
| 1228 | 1211 | if (editedBlockName !== initialName) { |
| 1229 | 1212 | const message = (0, import_i18n9.sprintf)( |
| @@ -1298,9 +1281,9 @@ | ||
| 1298 | 1281 | } |
| 1299 | 1282 | ); |
| 1300 | 1283 | } |
| 1301 | 1284 | function DisallowOverridesModal({ onClose, onSave }) { |
| 1302 | - const descriptionId = (0, import_element9.useId)(); | |
| 1285 | + const descriptionId = (0, import_element8.useId)(); | |
| 1303 | 1286 | return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)( |
| 1304 | 1287 | import_components8.Modal, |
| 1305 | 1288 | { |
| 1306 | 1289 | title: (0, import_i18n9.__)("Disable overrides"), |
| @@ -1352,11 +1335,11 @@ | ||
| 1352 | 1335 | attributes, |
| 1353 | 1336 | setAttributes, |
| 1354 | 1337 | name: blockName |
| 1355 | 1338 | }) { |
| 1356 | - const controlId = (0, import_element10.useId)(); | |
| 1357 | - const [showAllowOverridesModal, setShowAllowOverridesModal] = (0, import_element10.useState)(false); | |
| 1358 | - const [showDisallowOverridesModal, setShowDisallowOverridesModal] = (0, import_element10.useState)(false); | |
| 1339 | + const controlId = (0, import_element9.useId)(); | |
| 1340 | + const [showAllowOverridesModal, setShowAllowOverridesModal] = (0, import_element9.useState)(false); | |
| 1341 | + const [showDisallowOverridesModal, setShowDisallowOverridesModal] = (0, import_element9.useState)(false); | |
| 1359 | 1342 | const hasName = !!attributes.metadata?.name; |
| 1360 | 1343 | const defaultBindings = attributes.metadata?.bindings?.__default; |
| 1361 | 1344 | const hasOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE; |
| 1362 | 1345 | const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE; |