mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 23:05:59 +00:00
context menu tags - can use forward ref
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
loadData();
|
||||
});
|
||||
|
||||
registerMenu({ placeTag: 'switch' });
|
||||
|
||||
const menu = getContextMenu();
|
||||
|
||||
$: grider = new ChangeSetGrider(loadedRows, changeSetState, dispatchChangeSet, display);
|
||||
@@ -58,7 +60,7 @@
|
||||
// $: console.log('GRIDER', grider);
|
||||
</script>
|
||||
|
||||
<div class="flexcol flex1" use:contextMenu={[{ placeTag: 'switch' }, menu]}>
|
||||
<div class="flexcol flex1" use:contextMenu={menu}>
|
||||
<div class="toolbar">
|
||||
<Pager bind:skip bind:limit on:load={() => display.reload()} />
|
||||
</div>
|
||||
|
||||
@@ -31,20 +31,31 @@ export default function contextMenu(node, items = []) {
|
||||
};
|
||||
}
|
||||
|
||||
function doExtractMenuItems(menu, res, tagged) {
|
||||
function doExtractMenuItems(menu, res) {
|
||||
if (_.isFunction(menu)) {
|
||||
doExtractMenuItems(menu(), res, tagged);
|
||||
doExtractMenuItems(menu(), res);
|
||||
} else if (_.isArray(menu)) {
|
||||
for (const item of menu) {
|
||||
doExtractMenuItems(item, res, tagged);
|
||||
doExtractMenuItems(item, res);
|
||||
}
|
||||
} else if (_.isPlainObject(menu)) {
|
||||
if (menu.tag) {
|
||||
tagged.push({
|
||||
...menu,
|
||||
tags: getAsArray(menu.tag),
|
||||
});
|
||||
} else if (menu.placeTag) {
|
||||
res.push(menu);
|
||||
}
|
||||
}
|
||||
|
||||
function processTags(items) {
|
||||
const res = [];
|
||||
const tagged = [];
|
||||
|
||||
for (const menu of items.filter(x => x.tag)) {
|
||||
tagged.push({
|
||||
...menu,
|
||||
tags: getAsArray(menu.tag),
|
||||
});
|
||||
}
|
||||
|
||||
for (const menu of items.filter(x => !x.tag)) {
|
||||
if (menu.placeTag) {
|
||||
const placeTags = getAsArray(menu.placeTag);
|
||||
for (let index = 0; index < tagged.length; ) {
|
||||
const current = tagged[index];
|
||||
@@ -59,15 +70,17 @@ function doExtractMenuItems(menu, res, tagged) {
|
||||
res.push(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function extractMenuItems(menu) {
|
||||
const res = [];
|
||||
const tagged = [];
|
||||
doExtractMenuItems(menu, res, tagged);
|
||||
|
||||
// append tagged, which were not appended by placeTag
|
||||
res.push(...tagged);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export function extractMenuItems(menu) {
|
||||
let res = [];
|
||||
doExtractMenuItems(menu, res);
|
||||
res = processTags(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user