@wordpress/block-editor
Version:
62 lines (60 loc) • 2.12 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/utils/object.js
var object_exports = {};
__export(object_exports, {
getValueFromObjectPath: () => getValueFromObjectPath,
setImmutably: () => setImmutably,
uniqByProperty: () => uniqByProperty
});
module.exports = __toCommonJS(object_exports);
function setImmutably(object, path, value) {
path = Array.isArray(path) ? [...path] : [path];
object = Array.isArray(object) ? [...object] : { ...object };
const leaf = path.pop();
let prev = object;
for (const key of path) {
const lvl = prev[key];
prev = prev[key] = Array.isArray(lvl) ? [...lvl] : { ...lvl };
}
prev[leaf] = value;
return object;
}
var getValueFromObjectPath = (object, path, defaultValue) => {
const arrayPath = Array.isArray(path) ? path : path.split(".");
let value = object;
arrayPath.forEach((fieldName) => {
value = value?.[fieldName];
});
return value ?? defaultValue;
};
function uniqByProperty(array, property) {
const seen = /* @__PURE__ */ new Set();
return array.filter((item) => {
const value = item[property];
return seen.has(value) ? false : seen.add(value);
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getValueFromObjectPath,
setImmutably,
uniqByProperty
});
//# sourceMappingURL=object.js.map