| 1 |
(function(react, _wordpress_i18n, _wordpress_data, _wordpress_core_data, _wordpress_components, _wordpress_plugins, _woocommerce_admin_layout) { |
| 2 |
|
| 3 |
//#region \0rolldown/runtime.js |
| 4 |
var __create = Object.create; |
| 5 |
var __defProp = Object.defineProperty; |
| 6 |
var __name = (target, value) => __defProp(target, "name", { |
| 7 |
value, |
| 8 |
configurable: true |
| 9 |
}); |
| 10 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 11 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 12 |
var __getProtoOf = Object.getPrototypeOf; |
| 13 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 14 |
var __copyProps = (to, from, except, desc) => { |
| 15 |
if (from && typeof from === "object" || typeof from === "function") { |
| 16 |
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { |
| 17 |
key = keys[i]; |
| 18 |
if (!__hasOwnProp.call(to, key) && key !== except) { |
| 19 |
__defProp(to, key, { |
| 20 |
get: ((k) => from[k]).bind(null, key), |
| 21 |
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable |
| 22 |
}); |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
return to; |
| 27 |
}; |
| 28 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { |
| 29 |
value: mod, |
| 30 |
enumerable: true |
| 31 |
}) : target, mod)); |
| 32 |
|
| 33 |
//#endregion |
| 34 |
react = __toESM(react); |
| 35 |
|
| 36 |
//#region node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js |
| 37 |
function _arrayWithHoles(r) { |
| 38 |
if (Array.isArray(r)) return r; |
| 39 |
} |
| 40 |
|
| 41 |
//#endregion |
| 42 |
//#region node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js |
| 43 |
function _iterableToArrayLimit(r, l) { |
| 44 |
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; |
| 45 |
if (null != t) { |
| 46 |
var e; |
| 47 |
var n; |
| 48 |
var i; |
| 49 |
var u; |
| 50 |
var a = []; |
| 51 |
var f = !0; |
| 52 |
var o = !1; |
| 53 |
try { |
| 54 |
if (i = (t = t.call(r)).next, 0 === l) { |
| 55 |
if (Object(t) !== t) return; |
| 56 |
f = !1; |
| 57 |
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); |
| 58 |
} catch (r) { |
| 59 |
o = !0, n = r; |
| 60 |
} finally { |
| 61 |
try { |
| 62 |
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; |
| 63 |
} finally { |
| 64 |
if (o) throw n; |
| 65 |
} |
| 66 |
} |
| 67 |
return a; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
//#endregion |
| 72 |
//#region node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js |
| 73 |
function _arrayLikeToArray(r, a) { |
| 74 |
(null == a || a > r.length) && (a = r.length); |
| 75 |
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; |
| 76 |
return n; |
| 77 |
} |
| 78 |
|
| 79 |
//#endregion |
| 80 |
//#region node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js |
| 81 |
function _unsupportedIterableToArray(r, a) { |
| 82 |
if (r) { |
| 83 |
if ("string" == typeof r) return _arrayLikeToArray(r, a); |
| 84 |
var t = {}.toString.call(r).slice(8, -1); |
| 85 |
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
//#endregion |
| 90 |
//#region node_modules/@babel/runtime/helpers/esm/nonIterableRest.js |
| 91 |
function _nonIterableRest() { |
| 92 |
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 93 |
} |
| 94 |
|
| 95 |
//#endregion |
| 96 |
//#region node_modules/@babel/runtime/helpers/esm/slicedToArray.js |
| 97 |
function _slicedToArray(r, e) { |
| 98 |
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); |
| 99 |
} |
| 100 |
|
| 101 |
//#endregion |
| 102 |
//#region modules/wc-product-editor/assets/js/e-wc-product-editor.js |
| 103 |
function EditWithElementorButton() { |
| 104 |
var _useState2 = _slicedToArray((0, react.useState)(false), 2); |
| 105 |
var isRedirecting = _useState2[0]; |
| 106 |
var setIsRedirecting = _useState2[1]; |
| 107 |
var productId = (0, _wordpress_core_data.useEntityId)("postType", "product"); |
| 108 |
var saveEntityRecord = (0, _wordpress_data.useDispatch)("core").saveEntityRecord; |
| 109 |
var postStatus = (0, _wordpress_data.useSelect)(function(select) { |
| 110 |
var _select$getEditedEnti; |
| 111 |
return (_select$getEditedEnti = select("core").getEditedEntityRecord("postType", "product", productId)) === null || _select$getEditedEnti === void 0 ? void 0 : _select$getEditedEnti.status; |
| 112 |
}, [productId]); |
| 113 |
var isSaving = wp.data.select("core/editor").isSavingPost(); |
| 114 |
(0, react.useEffect)(function() { |
| 115 |
if (isRedirecting && !isSaving) redirectToElementor(); |
| 116 |
}, [isRedirecting, isSaving]); |
| 117 |
var handleClick = function handleClick() { |
| 118 |
if ("auto-draft" === postStatus) saveEntityRecord("postType", "product", { |
| 119 |
id: productId, |
| 120 |
name: "Elementor #".concat(productId), |
| 121 |
status: "draft" |
| 122 |
}).then(function() { |
| 123 |
setIsRedirecting(true); |
| 124 |
}).catch(function() {}); |
| 125 |
else setIsRedirecting(true); |
| 126 |
}; |
| 127 |
var redirectToElementor = function redirectToElementor() { |
| 128 |
window.location.href = getEditUrl(); |
| 129 |
}; |
| 130 |
var getEditUrl = function getEditUrl() { |
| 131 |
var url = new URL(ElementorWCProductEditorSettings.editLink); |
| 132 |
url.searchParams.set("post", productId); |
| 133 |
url.searchParams.set("action", "elementor"); |
| 134 |
return url.toString(); |
| 135 |
}; |
| 136 |
return /*#__PURE__*/ react.default.createElement(_woocommerce_admin_layout.WooHeaderItem, { name: "product" }, /*#__PURE__*/ react.default.createElement(_wordpress_components.Button, { |
| 137 |
variant: "primary", |
| 138 |
onClick: handleClick, |
| 139 |
style: { |
| 140 |
display: "flex", |
| 141 |
alignItems: "center" |
| 142 |
} |
| 143 |
}, /*#__PURE__*/ react.default.createElement("i", { |
| 144 |
className: "eicon-elementor-square", |
| 145 |
"aria-hidden": "true", |
| 146 |
style: { paddingInlineEnd: "8px" } |
| 147 |
}), (0, _wordpress_i18n.__)("Edit with Elementor", "elementor"))); |
| 148 |
} |
| 149 |
(0, _wordpress_plugins.registerPlugin)("elementor-header-item", { |
| 150 |
render: EditWithElementorButton, |
| 151 |
scope: "woocommerce-product-block-editor" |
| 152 |
}); |
| 153 |
|
| 154 |
//#endregion |
| 155 |
})(React, wp.i18n, wp.data, wp.coreData, wp.components, wp.plugins, wc.adminLayout); |
| 156 |
//# sourceMappingURL=e-wc-product-editor.js.map |