active components - automatic detection of mutual exclusive based of parentship

This commit is contained in:
Jan Prochazka 2021-04-08 07:13:07 +02:00
parent 2db17f9eca
commit b553dbb6b9
3 changed files with 103 additions and 92 deletions

View File

@ -276,7 +276,7 @@
export let selectedCellsPublished = () => []; export let selectedCellsPublished = () => [];
// export let generalAllowSave = false; // export let generalAllowSave = false;
export const activator = createActivator('DataGridCore', false, 'FormView'); export const activator = createActivator('DataGridCore', false);
const wheelRowCount = 5; const wheelRowCount = 5;
const tabVisible: any = getContext('tabVisible'); const tabVisible: any = getContext('tabVisible');

View File

@ -263,7 +263,7 @@
formDisplay.addFilterColumn(getCellColumn(currentCell)); formDisplay.addFilterColumn(getCellColumn(currentCell));
} }
export const activator = createActivator('FormView', false, 'DataGridCore'); export const activator = createActivator('FormView', false);
const handleTableMouseDown = event => { const handleTableMouseDown = event => {
if (event.target.closest('.buttonLike')) return; if (event.target.closest('.buttonLike')) return;
@ -436,9 +436,6 @@
} }
</script> </script>
{#if isLoading}
<LoadingInfo wrapper message="Loading data" />
{:else}
<div class="outer"> <div class="outer">
<div class="wrapper" use:contextMenu={createMenu} bind:clientHeight={wrapperHeight}> <div class="wrapper" use:contextMenu={createMenu} bind:clientHeight={wrapperHeight}>
{#each columnChunks as chunk, chunkIndex} {#each columnChunks as chunk, chunkIndex}
@ -521,6 +518,9 @@
</div> </div>
{/if} {/if}
</div> </div>
{#if isLoading}
<LoadingInfo wrapper message="Loading data" />
{/if} {/if}
<style> <style>

View File

@ -1,15 +1,18 @@
import { getContext } from 'svelte'; import { getContext } from 'svelte';
import { get_current_component, onMount, setContext } from 'svelte/internal'; import { get_current_component, onMount, setContext } from 'svelte/internal';
import invalidateCommands from '../commands/invalidateCommands'; import invalidateCommands from '../commands/invalidateCommands';
import getAsArray from './getAsArray';
const lastActiveDictionary = {}; const lastActiveDictionary = {};
export default function createActivator( function isParent(parent, child) {
name: string, while (child && child.activator) {
activateOnTabVisible: boolean, if (parent == child) return true;
mutualExclusive: string | string[] = [] child = child.activator.parentActivatorInstance;
) { }
return false;
}
export default function createActivator(name: string, activateOnTabVisible: boolean) {
const instance = get_current_component(); const instance = get_current_component();
const tabVisible: any = getContext('tabVisible'); const tabVisible: any = getContext('tabVisible');
const tabid = getContext('tabid'); const tabid = getContext('tabid');
@ -32,13 +35,20 @@ export default function createActivator(
}); });
const activate = () => { const activate = () => {
lastActiveDictionary[name] = instance; const toDelete = [];
for (const comp of getAsArray(mutualExclusive)) { for (const key in lastActiveDictionary) {
delete lastActiveDictionary[comp]; if (isParent(lastActiveDictionary[key], instance)) continue;
if (isParent(instance, lastActiveDictionary[key])) continue;
toDelete.push(key);
} }
for (const del of toDelete) {
delete lastActiveDictionary[del];
}
lastActiveDictionary[name] = instance;
if (parentActivatorInstance) { if (parentActivatorInstance) {
parentActivatorInstance.activator.activate(); parentActivatorInstance.activator.activate();
} }
// console.log('Active components', lastActiveDictionary);
}; };
const getTabVisible = () => tabVisibleValue; const getTabVisible = () => tabVisibleValue;
@ -47,6 +57,7 @@ export default function createActivator(
activate, activate,
tabid, tabid,
getTabVisible, getTabVisible,
parentActivatorInstance,
}; };
} }