1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Wired table properties, and other buttons

This commit is contained in:
Dan Brown
2024-08-10 13:14:55 +01:00
parent abbfd42a6c
commit ebf95f637a
9 changed files with 243 additions and 79 deletions

View File

@ -29,4 +29,29 @@ export function formatSizeValue(size: number | string, defaultSuffix: string = '
}
return size;
}
export type StyleMap = Map<string, string>;
/**
* Creates a map from an element's styles.
* Uses direct attribute value string handling since attempting to iterate
* over .style will expand out any shorthand properties (like 'padding') making
* rather than being representative of the actual properties set.
*/
export function extractStyleMapFromElement(element: HTMLElement): StyleMap {
const map: StyleMap = new Map();
const styleText= element.getAttribute('style') || '';
const rules = styleText.split(';');
for (const rule of rules) {
const [name, value] = rule.split(':');
if (!name || !value) {
continue;
}
map.set(name.trim().toLowerCase(), value.trim());
}
return map;
}