mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-22 22:59:41 +02:00
feature/improve-parser-ux (#789)
* cleanup console.logs * default to panels open * feat(frontend): ✨ add ingredient on enter * feat(frontend): ✨ automatically trigger parser on navigation * feat(frontend): ✨ prompt user before leaving when in editor * add deep copy utility * improve flow of parser * add tooltip and match disable with disableAmount * force admin users to have advanced access Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
788e176b16
commit
c1ba8dcd86
10 changed files with 462 additions and 140 deletions
|
@ -8,3 +8,49 @@ export function uuid4() {
|
|||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/28876300/deep-copying-array-of-nested-objects-in-javascript
|
||||
const toString = Object.prototype.toString;
|
||||
export function deepCopy(obj: any) {
|
||||
let rv;
|
||||
|
||||
switch (typeof obj) {
|
||||
case "object":
|
||||
if (obj === null) {
|
||||
// null => null
|
||||
rv = null;
|
||||
} else {
|
||||
switch (toString.call(obj)) {
|
||||
case "[object Array]":
|
||||
// It's an array, create a new array with
|
||||
// deep copies of the entries
|
||||
rv = obj.map(deepCopy);
|
||||
break;
|
||||
case "[object Date]":
|
||||
// Clone the date
|
||||
rv = new Date(obj);
|
||||
break;
|
||||
case "[object RegExp]":
|
||||
// Clone the RegExp
|
||||
rv = new RegExp(obj);
|
||||
break;
|
||||
// ...probably a few others
|
||||
default:
|
||||
// Some other kind of object, deep-copy its
|
||||
// properties into a new object
|
||||
rv = Object.keys(obj).reduce(function (prev, key) {
|
||||
// @ts-ignore
|
||||
prev[key] = deepCopy(obj[key]);
|
||||
return prev;
|
||||
}, {});
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// It's a primitive, copy via assignment
|
||||
rv = obj;
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue