mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
activator for formview and datagridcore
This commit is contained in:
parent
54cf6ad411
commit
d236782795
@ -1,10 +1,5 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
let lastFocusedDataGrid = null;
|
const getCurrentDataGrid = () => getActiveComponent('DataGridCore');
|
||||||
const getCurrentDataGrid = () =>
|
|
||||||
lastFocusedDataGrid?.getTabId && lastFocusedDataGrid?.getTabId() == getActiveTabId() ? lastFocusedDataGrid : null;
|
|
||||||
export function clearLastFocusedDataGrid() {
|
|
||||||
lastFocusedDataGrid = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.refresh',
|
id: 'dataGrid.refresh',
|
||||||
@ -224,11 +219,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { changeSetContainsChanges, GridDisplay } from 'dbgate-datalib';
|
import { GridDisplay } from 'dbgate-datalib';
|
||||||
import { get_current_component } from 'svelte/internal';
|
import { get_current_component } from 'svelte/internal';
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { writable, get, derived } from 'svelte/store';
|
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import ColumnHeaderControl from './ColumnHeaderControl.svelte';
|
import ColumnHeaderControl from './ColumnHeaderControl.svelte';
|
||||||
import DataGridRow from './DataGridRow.svelte';
|
import DataGridRow from './DataGridRow.svelte';
|
||||||
@ -252,19 +246,18 @@
|
|||||||
import DataFilterControl from './DataFilterControl.svelte';
|
import DataFilterControl from './DataFilterControl.svelte';
|
||||||
import createReducer from '../utility/createReducer';
|
import createReducer from '../utility/createReducer';
|
||||||
import keycodes from '../utility/keycodes';
|
import keycodes from '../utility/keycodes';
|
||||||
import { activeTabId, getActiveTabId, nullStore, selectedCellsCallback } from '../stores';
|
import { selectedCellsCallback } from '../stores';
|
||||||
import memberStore from '../utility/memberStore';
|
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import { copyTextToClipboard } from '../utility/clipboard';
|
import { copyTextToClipboard } from '../utility/clipboard';
|
||||||
import invalidateCommands from '../commands/invalidateCommands';
|
import invalidateCommands from '../commands/invalidateCommands';
|
||||||
import createRef from '../utility/createRef';
|
import createRef from '../utility/createRef';
|
||||||
import { clearLastFocusedFormView } from '../formview/FormView.svelte';
|
|
||||||
import openReferenceForm, { openPrimaryKeyForm } from '../formview/openReferenceForm';
|
import openReferenceForm, { openPrimaryKeyForm } from '../formview/openReferenceForm';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
import { dataGridRowHeight } from './DataGridRowHeightMeter.svelte';
|
import { dataGridRowHeight } from './DataGridRowHeightMeter.svelte';
|
||||||
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
||||||
import { editJsonRowDocument } from '../jsonview/CollectionJsonRow.svelte';
|
import { editJsonRowDocument } from '../jsonview/CollectionJsonRow.svelte';
|
||||||
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
|
|
||||||
export let onLoadNextData = undefined;
|
export let onLoadNextData = undefined;
|
||||||
export let grider = undefined;
|
export let grider = undefined;
|
||||||
@ -293,9 +286,9 @@
|
|||||||
export let selectedCellsPublished = () => [];
|
export let selectedCellsPublished = () => [];
|
||||||
// export let generalAllowSave = false;
|
// export let generalAllowSave = false;
|
||||||
|
|
||||||
|
export const activator = createActivator('DataGridCore', false, 'FormView');
|
||||||
|
|
||||||
const wheelRowCount = 5;
|
const wheelRowCount = 5;
|
||||||
const instance = get_current_component();
|
|
||||||
const tabid = getContext('tabid');
|
|
||||||
const tabVisible: any = getContext('tabVisible');
|
const tabVisible: any = getContext('tabVisible');
|
||||||
|
|
||||||
let containerHeight = 0;
|
let containerHeight = 0;
|
||||||
@ -1099,8 +1092,7 @@
|
|||||||
bind:this={domFocusField}
|
bind:this={domFocusField}
|
||||||
on:keydown={handleGridKeyDown}
|
on:keydown={handleGridKeyDown}
|
||||||
on:focus={() => {
|
on:focus={() => {
|
||||||
lastFocusedDataGrid = instance;
|
activator.activate();
|
||||||
clearLastFocusedFormView();
|
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
}}
|
}}
|
||||||
on:paste={handlePaste}
|
on:paste={handlePaste}
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
let lastFocusedFormView = null;
|
const getCurrentDataForm = () => getActiveComponent('FormView');
|
||||||
const getCurrentDataForm = () =>
|
|
||||||
lastFocusedFormView?.getTabId && lastFocusedFormView?.getTabId() == getActiveTabId() ? lastFocusedFormView : null;
|
|
||||||
export function clearLastFocusedFormView() {
|
|
||||||
lastFocusedFormView = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataForm.switchToTable',
|
id: 'dataForm.switchToTable',
|
||||||
@ -160,7 +155,6 @@
|
|||||||
|
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import DataGridCell from '../datagrid/DataGridCell.svelte';
|
import DataGridCell from '../datagrid/DataGridCell.svelte';
|
||||||
import { clearLastFocusedDataGrid } from '../datagrid/DataGridCore.svelte';
|
|
||||||
import { dataGridRowHeight } from '../datagrid/DataGridRowHeightMeter.svelte';
|
import { dataGridRowHeight } from '../datagrid/DataGridRowHeightMeter.svelte';
|
||||||
import InplaceEditor from '../datagrid/InplaceEditor.svelte';
|
import InplaceEditor from '../datagrid/InplaceEditor.svelte';
|
||||||
import { cellFromEvent } from '../datagrid/selection';
|
import { cellFromEvent } from '../datagrid/selection';
|
||||||
@ -169,10 +163,10 @@
|
|||||||
import { plusExpandIcon } from '../icons/expandIcons';
|
import { plusExpandIcon } from '../icons/expandIcons';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
|
||||||
import { getActiveTabId } from '../stores';
|
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import { copyTextToClipboard } from '../utility/clipboard';
|
import { copyTextToClipboard } from '../utility/clipboard';
|
||||||
import contextMenu from '../utility/contextMenu';
|
import contextMenu from '../utility/contextMenu';
|
||||||
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
import createReducer from '../utility/createReducer';
|
import createReducer from '../utility/createReducer';
|
||||||
import keycodes from '../utility/keycodes';
|
import keycodes from '../utility/keycodes';
|
||||||
import resizeObserver from '../utility/resizeObserver';
|
import resizeObserver from '../utility/resizeObserver';
|
||||||
@ -196,7 +190,6 @@
|
|||||||
let currentCell = [0, 0];
|
let currentCell = [0, 0];
|
||||||
|
|
||||||
const instance = get_current_component();
|
const instance = get_current_component();
|
||||||
const tabid = getContext('tabid');
|
|
||||||
const tabVisible: any = getContext('tabVisible');
|
const tabVisible: any = getContext('tabVisible');
|
||||||
const domCells = {};
|
const domCells = {};
|
||||||
|
|
||||||
@ -221,10 +214,6 @@
|
|||||||
return `Row: ${(rowCountBefore + 1).toLocaleString()} / ${allRowCount.toLocaleString()}`;
|
return `Row: ${(rowCountBefore + 1).toLocaleString()} / ${allRowCount.toLocaleString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTabId() {
|
|
||||||
return tabid;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFormer() {
|
export function getFormer() {
|
||||||
return former;
|
return former;
|
||||||
}
|
}
|
||||||
@ -276,6 +265,8 @@
|
|||||||
formDisplay.addFilterColumn(getCellColumn(currentCell));
|
formDisplay.addFilterColumn(getCellColumn(currentCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const activator = createActivator('FormView', false, 'DataGridCore');
|
||||||
|
|
||||||
const handleTableMouseDown = event => {
|
const handleTableMouseDown = event => {
|
||||||
if (event.target.closest('.buttonLike')) return;
|
if (event.target.closest('.buttonLike')) return;
|
||||||
if (event.target.closest('.resizeHandleControl')) return;
|
if (event.target.closest('.resizeHandleControl')) return;
|
||||||
@ -519,8 +510,7 @@
|
|||||||
class="focus-field"
|
class="focus-field"
|
||||||
bind:this={domFocusField}
|
bind:this={domFocusField}
|
||||||
on:focus={() => {
|
on:focus={() => {
|
||||||
lastFocusedFormView = instance;
|
activator.activate();
|
||||||
clearLastFocusedDataGrid();
|
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
}}
|
}}
|
||||||
on:keydown={handleKeyDown}
|
on:keydown={handleKeyDown}
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
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(name, activateOnTabVisible) {
|
export default function createActivator(
|
||||||
|
name: string,
|
||||||
|
activateOnTabVisible: boolean,
|
||||||
|
mutualExclusive: string | string[] = []
|
||||||
|
) {
|
||||||
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');
|
||||||
@ -28,6 +33,9 @@ export default function createActivator(name, activateOnTabVisible) {
|
|||||||
|
|
||||||
const activate = () => {
|
const activate = () => {
|
||||||
lastActiveDictionary[name] = instance;
|
lastActiveDictionary[name] = instance;
|
||||||
|
for (const comp of getAsArray(mutualExclusive)) {
|
||||||
|
delete lastActiveDictionary[comp];
|
||||||
|
}
|
||||||
if (parentActivatorInstance) {
|
if (parentActivatorInstance) {
|
||||||
parentActivatorInstance.activator.activate();
|
parentActivatorInstance.activator.activate();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user