Skip to content

Commit

Permalink
Improve dictionary action
Browse files Browse the repository at this point in the history
  • Loading branch information
electrikmilk committed Apr 28, 2024
1 parent bf85187 commit cf16706
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
38 changes: 23 additions & 15 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,25 @@ export function renderDictionary(data: Array<DictionaryItem>) {

export function renderTreeItems(data: Array<DictionaryItem>) {
let items: HTMLElement[] = [];
let idx = 0;
for (let item of data) {
idx++;

let children: HTMLElement[] = [];

const key = renderValue(item.Key)
key.classList.add('sp-unstyled-value');
let key = null;
if (item.Key) {
key = renderValue(item.Key, 'Key')
key.classList.add('sp-unstyled-value');
} else {
// @ts-ignore
key = renderElement('div', {className: 'fade'}, renderText(`Item ${idx}`));
}

let values = renderValue(item.Value);
let values = renderValue(item.Value, 'Value');
if (item.Value) {
if (typeof item.Value.Value !== 'object') {
values = renderValue(item.Value.Value);
values = renderValue(item.Value.Value, 'Value');
}
}
values.classList.add('sp-unstyled-value');
Expand All @@ -441,7 +450,7 @@ export function renderTreeItems(data: Array<DictionaryItem>) {
renderElement('div', {className: 'tree-row'},
key,
// @ts-ignore
renderElement('div', {className: 'fade'}, renderText(item.Type)),
renderElement('div', {}, renderText(item.Type)),
values,
),
], ...children));
Expand All @@ -451,18 +460,17 @@ export function renderTreeItems(data: Array<DictionaryItem>) {
}

export function renderTreeItem(contents: HTMLElement[], ...children: HTMLElement[]): HTMLElement {
const toggle = renderClass('treeview-toggle');
toggle.onclick = (e) => {
console.log(e);
};
let itemRoot: HTMLElement[] = [];
if (children.length !== 0) {
itemRoot.push(renderClass('treeview-toggle'));
}

itemRoot.push(renderClass('treeview-item-content',
renderClass('treeview-item-label', ...contents)
));

return renderClass('treeview-item',
renderClass('treeview-item-root',
toggle,
renderClass('treeview-item-content',
renderClass('treeview-item-label', ...contents)
)
),
renderClass('treeview-item-root', ...itemRoot),
renderClass('treeview-item-children', ...children)
);
}
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
purgecss({
content: ['./src/**/*.ts'],
css: ['./src/style.css'],
safelist: [/^c-?\d+/, /^g\d+/]
safelist: [/^c-?\d+/, /^g\d+/, /^treeview.+/]
})
]
}
Expand Down

0 comments on commit cf16706

Please sign in to comment.