feat: added checkbox and other widgets for tkinter
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
|
||||
|
||||
export function removeDuplicateObjects(array, key) {
|
||||
const seen = new Set()
|
||||
|
||||
return array.filter(item => {
|
||||
if (!seen.has(item[key])) {
|
||||
seen.add(item[key])
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
const seen = new Set()
|
||||
|
||||
return array.filter(item => {
|
||||
if (!seen.has(item[key])) {
|
||||
seen.add(item[key])
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -20,5 +20,34 @@ export function removeDuplicateObjects(array, key) {
|
||||
* @returns
|
||||
*/
|
||||
export function capitalize(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||
}
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given the key as a path, removes the widget attribute at the given path
|
||||
* @param {string} path - path to the key, eg: styling.backgroundColor
|
||||
* @param {{}} _object - object with key and value
|
||||
*/
|
||||
export function removeKeyFromObject(path, _object) {
|
||||
const keys = path.split('.')
|
||||
const lastKey = keys.pop()
|
||||
|
||||
// Traverse the state and find the nested object up to the second last key
|
||||
let newAttrs = { ..._object }
|
||||
let nestedObject = newAttrs
|
||||
|
||||
for (const key of keys) {
|
||||
if (nestedObject[key] !== undefined) {
|
||||
nestedObject[key] = { ...nestedObject[key] } // Ensure immutability
|
||||
nestedObject = nestedObject[key]
|
||||
} else {
|
||||
return // Key doesn't exist, so nothing to remove
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the attribute
|
||||
delete nestedObject[lastKey]
|
||||
|
||||
return newAttrs
|
||||
}
|
||||
Reference in New Issue
Block a user